def remove_collisions(self, min_dist=0.5):
    s_f_coords = self.structure.frac_coords
    f_coords = self.extrema_coords
    if (len(f_coords) == 0):
        if (self.extrema_type is None):
            logger.warning('Please run ChargeDensityAnalyzer.get_local_extrema first!')
            return
        new_f_coords = []
        self._update_extrema(new_f_coords, self.extrema_type)
        return new_f_coords
    dist_matrix = self.structure.lattice.get_all_distances(f_coords, s_f_coords)
    all_dist = np.min(dist_matrix, axis=1)
    new_f_coords = []
    for (i, f) in enumerate(f_coords):
        if (all_dist[i] > min_dist):
            new_f_coords.append(f)
    self._update_extrema(new_f_coords, self.extrema_type)
    return new_f_coords

Remove predicted sites that are too close to existing atoms in the
structure.

Args:
min_dist (float): The minimum distance (in Angstrom) that
a predicted site needs to be from existing atoms. A min_dist
with value <= 0 returns all sites without distance checking.


def generate_code(meta, prefix=None, node=False, min=False):

    if isinstance(meta, dict):
        url_prefix, auth_header, resources = parse_meta(meta)
    else:
        url_prefix, auth_header, resources = meta
    if prefix is not None:
        url_prefix = prefix
    core = render_core(url_prefix, auth_header, resources)
    if min:
        filename = 'res.web.min.js'
    else:
        filename = 'res.web.js'
    if node:
        filename = 'res.node.js'
    base = read_file(filename)
    return base.replace('"

Generate res.js

Args:
meta: tuple(url_prefix, auth_header, resources) or metadata of API
Returns:
res.js source code


def create_schema(self, model, waiting_models):

        bucket_name = model._get_bucket_name()
        index_name = "%s_%s" % (settings.DEFAULT_BUCKET_TYPE, bucket_name)
        ins = model(fake_context)
        fields = self.get_schema_fields(ins._collect_index_fields())
        new_schema = self.compile_schema(fields)
        schema = get_schema_from_solr(index_name)
        if not (schema == new_schema):
            try:
                client.create_search_schema(index_name, new_schema)
                print("+ %s (%s) search schema is created." % (model.__name__, index_name))
            except:
                print("+ %s (%s) search schema checking operation is taken to queue." % (
                    model.__name__, index_name))
                waiting_models.append(model)

Creates search schemas.

Args:
model: model to execute
waiting_models: if riak can't return response immediately, model is taken to queue.
After first execution session, method is executed with waiting models and controlled.
And be ensured that all given models are executed properly.

Returns:


def _as_document(self, partition):
    schema = ' '.join((u'{} {} {} {} {}'.format(c.id, c.vid, c.name, c.altname, c.description) for c in partition.table.columns))
    values = ''
    for stat in partition.stats:
        if stat.uvalues:
            values += (' '.join((e[:200] for e in stat.uvalues)) + '\n')

    def resum(g):
        try:
            return str(GVid.parse(g).summarize())
        except KeyError:
            return g
        except ValueError:
            logger.debug("Failed to parse gvid '{}' from partition '{}' grain coverage".format(g, partition.identity.vname))
            return g
    keywords = ((((' '.join(partition.space_coverage) + ' ') + ' '.join([resum(g) for g in partition.grain_coverage if resum(g)])) + ' ') + ' '.join((str(x) for x in partition.time_coverage)))
    doc_field = u('{} {} {} {} {} {}').format(values, schema, ' '.join([u('{}').format(partition.identity.vid), u('{}').format(partition.identity.id_), u('{}').format(partition.identity.name), u('{}').format(partition.identity.vname)]), partition.display.title, partition.display.description, partition.display.sub_description, partition.display.time_description, partition.display.geo_description)
    document = dict(vid=u('{}').format(partition.identity.vid), dataset_vid=u('{}').format(partition.identity.as_dataset().vid), title=u('{}').format(partition.table.description), keywords=u('{}').format(keywords), doc=doc_field)
    return document

Converts given partition to the document indexed by FTS backend.

Args:
partition (orm.Partition): partition to convert.

Returns:
dict with structure matches to BasePartitionIndex._schema.


def _get_bases(type_):

        try:

            class _(type_):

            BaseClass = type_
        except TypeError:
            BaseClass = object

        class MetaClass(_ValidationMeta, BaseClass.__class__):

        return BaseClass, MetaClass

Get the base and meta classes to use in creating a subclass.

Args:
type_: The type to subclass.

Returns:
A tuple containing two values: a base class, and a metaclass.


def write_signatures(self, signatures):

        self.fileobj.seek(self.signature_offset)
        sig_entries = [dict(algorithm_id=id_,
                            size=len(sig),
                            signature=sig)
                       for (id_, sig) in signatures]

        sigs = sigs_header.build(dict(
            filesize=self.filesize,
            count=len(signatures),
            sigs=sig_entries,
        ))
        self.fileobj.write(sigs)
        signatures_len = len(sigs)
        self.additional_offset = self.signature_offset + signatures_len

        if not self.additional_offset == self.fileobj.tell():
            raise IOError('ended up at unexpected offset')

Write signature data to the MAR file.

Args:
signatures (list): list of signature tuples of the form
(algorithm_id, signature_data)


def __init__(self, name, context=None):

    super(Job, self).__init__(name)
    if context is None:
      context = datalab.Context.default()
    self._context = context
    self._api = discovery.build('ml', 'v1', credentials=self._context.credentials)
    if not name.startswith('projects/'):
      name = 'projects/' + self._context.project_id + '/jobs/' + name
    self._name = name
    self._refresh_state()

Initializes an instance of a CloudML Job.

Args:
name: the name of the job. It can be an operation full name
("projects/[project_id]/jobs/[operation_name]") or just [operation_name].
context: an optional Context object providing project_id and credentials.


def parse(self, template):

        self._compile_delimiters()

        start_index = 0
        content_end_index, parsed_section, section_key = None, None, None
        parsed_template = ParsedTemplate()

        states = []

        while True:
            match = self._template_re.search(template, start_index)

            if match is None:
                break

            match_index = match.start()
            end_index = match.end()

            matches = match.groupdict()

            if matches['change'] is not None:
                matches.update(tag='=', tag_key=matches['delims'])
            elif matches['raw'] is not None:
                matches.update(tag='&', tag_key=matches['raw_name'])

            tag_type = matches['tag']
            tag_key = matches['tag_key']
            leading_whitespace = matches['whitespace']

            did_tag_begin_line = match_index == 0 or template[match_index - 1] in END_OF_LINE_CHARACTERS
            did_tag_end_line = end_index == len(template) or template[end_index] in END_OF_LINE_CHARACTERS
            is_tag_interpolating = tag_type in ['', '&']

            if did_tag_begin_line and did_tag_end_line and not is_tag_interpolating:
                if end_index < len(template):
                    end_index += template[end_index] == '\r' and 1 or 0
                if end_index < len(template):
                    end_index += template[end_index] == '\n' and 1 or 0
            elif leading_whitespace:
                match_index += len(leading_whitespace)
                leading_whitespace = ''

            if start_index != match_index:
                parsed_template.add(template[start_index:match_index])

            start_index = end_index

            if tag_type in ('

                state = (tag_type, end_index, section_key, parsed_template)
                states.append(state)

                section_key, parsed_template = tag_key, ParsedTemplate()
                continue

            if tag_type == '/':
                if tag_key != section_key:
                    raise ParsingError("Section end tag mismatch: %s != %s" % (tag_key, section_key))

                parsed_section = parsed_template

                (tag_type, section_start_index, section_key, parsed_template) = states.pop()
                node = self._make_section_node(template, tag_type, tag_key, parsed_section,
                                               section_start_index, match_index)

            else:
                node = self._make_interpolation_node(tag_type, tag_key, leading_whitespace)

            parsed_template.add(node)

        if start_index != len(template):
            parsed_template.add(template[start_index:])

        return parsed_template

Parse a template string starting at some index.

This method uses the current tag delimiter.

Arguments:

template: a unicode string that is the template to parse.

index: the index at which to start parsing.

Returns:

a ParsedTemplate instance.


def write_file_to_zip_with_neutral_metadata(zfile, filename, content):

    info = zipfile.ZipInfo(filename, date_time=(2015, 10, 21, 7, 28, 0))
    info.compress_type = zipfile.ZIP_DEFLATED
    info.comment = "".encode()
    info.create_system = 0
    zfile.writestr(info, content)

Write the string `content` to `filename` in the open ZipFile `zfile`.
Args:
zfile (ZipFile): open ZipFile to write the content into
filename (str): the file path within the zip file to write into
content (str): the content to write into the zip
Returns: None


def leave_swarm(self, force=False):

        url = self._url('/swarm/leave')
        response = self._post(url, params={'force': force})

        if force and response.status_code == http_client.NOT_ACCEPTABLE:
            return True

        if force and response.status_code == http_client.SERVICE_UNAVAILABLE:
            return True
        self._raise_for_status(response)
        return True

Leave a swarm.

Args:
force (bool): Leave the swarm even if this node is a manager.
Default: ``False``

Returns:
``True`` if the request went through.

Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.


def _retrieve_info(self, request):

        info = _metadata.get_service_account_info(
            request,
            service_account=self._service_account_email)

        self._service_account_email = info['email']
        self._scopes = info['scopes']

Retrieve information about the service account.

Updates the scopes and retrieves the full service account email.

Args:
request (google.auth.transport.Request): The object used to make
HTTP requests.


def locked_put(self, credentials):

        entity, _ = self.model_class.objects.get_or_create(
            **{self.key_name: self.key_value})

        setattr(entity, self.property_name, credentials)
        entity.save()

Write a Credentials to the Django datastore.

Args:
credentials: Credentials, the credentials to store.


def __init__(self, *, separator_stride_cls: Type[message.Message], code_cls: Type[message.Message], default_timezone: str) -> None:
    self.separator_stride_cls = separator_stride_cls
    self.code_cls = code_cls
    self.default_timezone = default_timezone

Creates a new instance of primitive_wrappers.Context.

Args:
separator_stride_cls: The Base64BinarySeparatorStride type to use when
parsing/printing Base64Binary FHIR primitives.
code_cls: The Code type to use when parsing/printing profiled-Code
primitives.
default_timezone: The default timezone to use for date/time-like primitive
parsing/printing.


def profile_settings_args(self, ij, required):

        if self.args.permutation_id is not None:
            if 'sqlite3' not in sys.modules:
                print('The sqlite3 module needs to be build-in to Python for this feature.')
                sys.exit(1)
            profile_args = self.profile_settings_args_layout_json(required)
        else:
            profile_args = self.profile_settings_args_install_json(ij, required)
        return profile_args

Return args based on install.json or layout.json params.

Args:
ij (dict): The install.json contents.
required (bool): If True only required args will be returned.

Returns:
dict: Dictionary of required or optional App args.


def validate_user_name(self, user_name, timeout=-1):

        uri = self.URI + '/validateLoginName/' + user_name
        return self._client.create_with_zero_body(uri=uri, timeout=timeout)

Verifies if a userName is already in use.

Args:
user_name:
The userName to be verified.
timeout:
Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation in
OneView, just stops waiting for its completion.

Returns: True if user name is in use, False if it is not.


class _BigTableWriteFn(beam.DoFn):

    def __init__(self, project_id, instance_id, table_id, flush_count, max_row_bytes):

        super().__init__()
        self.beam_options = {'project_id': project_id, 'instance_id': instance_id, 'table_id': table_id, 'flush_count': flush_count, 'max_row_bytes': max_row_bytes}
        self.table = None
        self.batcher = None
        self.service_call_metric = None
        self.written = Metrics.counter(self.__class__, 'Written Row')

    def __getstate__(self):
        return self.beam_options

    def __setstate__(self, options):
        self.beam_options = options
        self.table = None
        self.batcher = None
        self.service_call_metric = None
        self.written = Metrics.counter(self.__class__, 'Written Row')

    def write_mutate_metrics(self, status_list):
        for status in status_list:
            code = status.code if status else None
            grpc_status_string = ServiceCallMetric.bigtable_error_code_to_grpc_status_string(code)
            self.service_call_metric.call(grpc_status_string)

    def start_service_call_metrics(self, project_id, instance_id, table_id):
        resource = resource_identifiers.BigtableTable(project_id, instance_id, table_id)
        labels = {monitoring_infos.SERVICE_LABEL: 'BigTable', monitoring_infos.METHOD_LABEL: 'google.bigtable.v2.MutateRows', monitoring_infos.RESOURCE_LABEL: resource, monitoring_infos.BIGTABLE_PROJECT_ID_LABEL: self.beam_options['project_id'], monitoring_infos.INSTANCE_ID_LABEL: self.beam_options['instance_id'], monitoring_infos.TABLE_ID_LABEL: self.beam_options['table_id']}
        return ServiceCallMetric(request_count_urn=monitoring_infos.API_REQUEST_COUNT_URN, base_labels=labels)

    def start_bundle(self):
        if self.table is None:
            client = Client(project=self.beam_options['project_id'])
            instance = client.instance(self.beam_options['instance_id'])
            self.table = instance.table(self.beam_options['table_id'])
        self.service_call_metric = self.start_service_call_metrics(self.beam_options['project_id'], self.beam_options['instance_id'], self.beam_options['table_id'])
        self.batcher = MutationsBatcher(self.table, batch_completed_callback=self.write_mutate_metrics, flush_count=self.beam_options['flush_count'], max_row_bytes=self.beam_options['max_row_bytes'])

    def process(self, row):
        self.written.inc()
        self.batcher.mutate(row)

    def finish_bundle(self):
        if self.batcher:
            self.batcher.close()
            self.batcher = None
            Lineage.sinks().add('bigtable', self.beam_options['project_id'], self.beam_options['instance_id'], self.beam_options['table_id'])

    def display_data(self):
        return {'projectId': DisplayDataItem(self.beam_options['project_id'], label='Bigtable Project Id'), 'instanceId': DisplayDataItem(self.beam_options['instance_id'], label='Bigtable Instance Id'), 'tableId': DisplayDataItem(self.beam_options['table_id'], label='Bigtable Table Id')}

Creates the connector can call and add_row to the batcher using each
row in beam pipe line
Args:
project_id(str): GCP Project ID
instance_id(str): GCP Instance ID
table_id(str): GCP Table ID
flush_count(int): Max number of rows to flush
max_row_bytes(int) Max number of row mutations size to flush


def from_text_vision_configs(cls, text_config: CLIPTextConfig, vision_config: CLIPVisionConfig, **kwargs):
    return cls(text_config=text_config.to_dict(), vision_config=vision_config.to_dict(), **kwargs)

Instantiate a [`CLIPConfig`] (or a derived class) from clip text model configuration and clip vision model
configuration.

Returns:
[`CLIPConfig`]: An instance of a configuration object


def filter_benchmarks(benchmarks, bench_funcs, base_ver):

    for bm in list(benchmarks):
        func = bench_funcs[bm]
        if getattr(func, '_python2_only', False) and (3, 0) <= base_ver:
            benchmarks.discard(bm)
            logging.info("Skipping Python2-only benchmark %s; "
                         "not compatible with Python %s" % (bm, base_ver))
            continue
    return benchmarks

Filters out benchmarks not supported by both Pythons.

Args:
benchmarks: a set() of benchmark names
bench_funcs: dict mapping benchmark names to functions
python: the interpereter commands (as lists)

Returns:
The filtered set of benchmark names


def resize_to(self, width, height):
    self.driver.resize_window_to(self.handle, width, height)

Resizes the window to the given dimensions.

If this method was called for a window that is not current, then after calling this method
the current window should remain the same as it was before calling this method.

Args:
width (int): The new window width in pixels.
height (int): The new window height in pixels.


def VerifyMessageSignature(self, unused_response_comms, packed_message_list, cipher, cipher_verified, api_version, remote_public_key):
    _ = api_version
    result = rdf_flows.GrrMessage.AuthorizationState.UNAUTHENTICATED
    if (cipher_verified or cipher.VerifyCipherSignature(remote_public_key)):
        stats_collector_instance.Get().IncrementCounter('grr_authenticated_messages')
        result = rdf_flows.GrrMessage.AuthorizationState.AUTHENTICATED
    if (packed_message_list.timestamp != self.timestamp):
        result = rdf_flows.GrrMessage.AuthorizationState.UNAUTHENTICATED
    if (not cipher.cipher_metadata):
        cipher.cipher_metadata = rdf_flows.CipherMetadata(source=packed_message_list.source)
    return result

Verify the message list signature.

This is the way the messages are verified in the client.

In the client we also check that the nonce returned by the server is correct
(the timestamp doubles as a nonce). If the nonce fails we deem the response
unauthenticated since it might have resulted from a replay attack.

Args:
packed_message_list: The PackedMessageList rdfvalue from the server.
cipher: The cipher belonging to the remote end.
cipher_verified: If True, the cipher's signature is not verified again.
api_version: The api version we should use.
remote_public_key: The public key of the source.

Returns:
An rdf_flows.GrrMessage.AuthorizationState.

Raises:
DecryptionError: if the message is corrupt.


def run(func, options, args=(), kwargs={}, host='localhost', port=8000):

    run_stats = run_profilers((func, args, kwargs), options)

    result = None
    for prof in run_stats:
        if not result:
            result = run_stats[prof]['result']
        del run_stats[prof]['result']

    post_data = gzip.compress(
        json.dumps(run_stats).encode('utf-8'))
    urllib.request.urlopen('http:
    return result

Runs profilers on a function.

Args:
func: A Python function.
options: A string with profilers configuration (i.e. 'cmh').
args: func non-keyword arguments.
kwargs: func keyword arguments.
host: Host name to send collected data.
port: Port number to send collected data.

Returns:
A result of func execution.


def calculate_entropy(self, entropy_string):
    total = 0
    for char in entropy_string:
        if char.isalpha():
            prob = self.frequency[char.lower()]
            total += ((- math.log(prob)) / math.log(2))
    logging.debug('Entropy score: {0}'.format(total))
    return total

Calculates the entropy of a string based on known frequency of
English letters.

Args:
entropy_string: A str representing the string to calculate.

Returns:
A negative float with the total entropy of the string (higher
is better).


def _get_group_object(name):
    with salt.utils.winapi.Com():
        nt = win32com.client.Dispatch('AdsNameSpaces')
    return nt.GetObject('', (('WinNT:

A helper function to get a specified group object

Args:

name (str): The name of the object

Returns:
object: The specified group object


def CopyFromDateTimeString(self, time_string):

    date_time_values = self._CopyDateTimeFromString(time_string)

    self._CopyFromDateTimeValues(date_time_values)

Copies time elements from a date and time string.

Args:
time_string (str): date and time value formatted as:
YYYY-MM-DD hh:mm:ss.######[+-]##:##

Where # are numeric digits ranging from 0 to 9 and the seconds
fraction can be either 3 or 6 digits. The time of day, seconds
fraction and time zone offset are optional. The default time zone
is UTC.


def chrome_decrypt(encrypted_value: bytes, key: bytes, init_vector: bytes) \
        -> str:

    encrypted_value = encrypted_value[3:]

    cipher = AES.new(key, AES.MODE_CBC, IV=init_vector)
    decrypted = cipher.decrypt(encrypted_value)

    return clean(decrypted)

Decrypt Chrome/Chromium's encrypted cookies.

Args:
encrypted_value: Encrypted cookie from Chrome/Chromium's cookie file
key: Key to decrypt encrypted_value
init_vector: Initialization vector for decrypting encrypted_value
Returns:
Decrypted value of encrypted_value


def Trim(self, flags):

        logger.info("Trimming!")
        flags = bytearray(flags)
        length = 1 << self.Depth - 1
        while len(flags) < length:
            flags.append(0)

        MerkleTree._TrimNode(self.Root, 0, self.Depth, flags)

Trim the nodes from the tree keeping only the root hash.

Args:
flags: "0000" for trimming, any other value for keeping the nodes.


def _format_output(content, typ):
    if ('csv' in str(typ)):
        return _format_csv(content, delimiter=',')
    if ('tsv' in str(typ)):
        return _format_csv(content, delimiter='\t')
    return content

Tabularize the content according to its type.

Args:
content (str): The content of a metric.
typ (str): The type of metric -- (raw|json|tsv|htsv|csv|hcsv).

Returns:
str: Content in a raw or tabular format.


def _Initialize(self, http, url):

        self.EnsureUninitialized()
        if self.http is None:
            self.__http = http or http_wrapper.GetHttp()
        self.__url = url

Initialize this download by setting self.http and self.url.

We want the user to be able to override self.http by having set
the value in the constructor; in that case, we ignore the provided
http.

Args:
http: An httplib2.Http instance or None.
url: The url for this transfer.

Returns:
None. Initializes self.


def download_image(self, device_label, image_id, file_name):
    response = None
    try:
        response = requests.get(urls.download_image(self._giid, device_label, image_id), headers={'Cookie': 'vid={}'.format(self._vid)}, stream=True)
    except requests.exceptions.RequestException as ex:
        raise RequestError(ex)
    _validate_response(response)
    with open(file_name, 'wb') as image_file:
        for chunk in response.iter_content(chunk_size=1024):
            if chunk:
                image_file.write(chunk)

Download image taken by a smartcam

Args:
device_label (str): device label of camera
image_id (str): image id from image series
file_name (str): path to file


def register_lookup_handler(lookup_type, handler_or_path):
    handler = handler_or_path
    if isinstance(handler_or_path, basestring):
        handler = load_object_from_string(handler_or_path)
    LOOKUP_HANDLERS[lookup_type] = handler
    if (type(handler) != type):
        logger = logging.getLogger(__name__)
        logger.warning(('Registering lookup `%s`: Please upgrade to use the new style of Lookups.' % lookup_type))
        warnings.warn(('Lookup `%s`: Please upgrade to use the new style of Lookups.' % lookup_type), DeprecationWarning, stacklevel=2)

Register a lookup handler.

Args:
lookup_type (str): Name to register the handler under
handler_or_path (OneOf[func, str]): a function or a path to a handler


def _DetermineOperatingSystem(self, searcher):
    find_specs = [file_system_searcher.FindSpec(location='/etc', case_sensitive=False), file_system_searcher.FindSpec(location='/System/Library', case_sensitive=False), file_system_searcher.FindSpec(location='/Windows/System32', case_sensitive=False), file_system_searcher.FindSpec(location='/WINNT/System32', case_sensitive=False), file_system_searcher.FindSpec(location='/WINNT35/System32', case_sensitive=False), file_system_searcher.FindSpec(location='/WTSRV/System32', case_sensitive=False)]
    locations = []
    for path_spec in searcher.Find(find_specs=find_specs):
        relative_path = searcher.GetRelativePath(path_spec)
        if relative_path:
            locations.append(relative_path.lower())
    windows_locations = set(['/windows/system32', '\\windows\\system32', '/winnt/system32', '\\winnt\\system32', '/winnt35/system32', '\\winnt35\\system32', '\\wtsrv\\system32', '/wtsrv/system32'])
    operating_system = definitions.OPERATING_SYSTEM_FAMILY_UNKNOWN
    if windows_locations.intersection(set(locations)):
        operating_system = definitions.OPERATING_SYSTEM_FAMILY_WINDOWS_NT
    elif ('/system/library' in locations):
        operating_system = definitions.OPERATING_SYSTEM_FAMILY_MACOS
    elif ('/etc' in locations):
        operating_system = definitions.OPERATING_SYSTEM_FAMILY_LINUX
    return operating_system

Tries to determine the underlying operating system.

Args:
searcher (dfvfs.FileSystemSearcher): file system searcher.

Returns:
str: operating system for example "Windows". This should be one of
the values in definitions.OPERATING_SYSTEM_FAMILIES.


def inference(self, observed_arr):

        for i in range(len(self.__deconvolution_layer_list)):
            try:
                observed_arr = self.__deconvolution_layer_list[i].forward_propagate(observed_arr)
            except:
                self.__logger.debug("Error raised in Deconvolution layer " + str(i + 1))
                raise

        return observed_arr

Draws samples from the `fake` distribution.

Args:
observed_arr:     `np.ndarray` of observed data points.

Returns:
`np.ndarray` of inferenced.


def load_steps(working_dir=None, steps_dir=None, step_file=None, step_list=None):
    if (steps_dir is not None):
        step_files = glob.glob(os.path.join(steps_dir, '*.cwl'))
    elif (step_file is not None):
        step_files = [step_file]
    elif (step_list is not None):
        step_files = []
        for path in step_list:
            if os.path.isdir(path):
                step_files += glob.glob(os.path.join(path, '*.cwl'))
            else:
                step_files.append(path)
    else:
        step_files = []
    if (working_dir is not None):
        step_files = sort_loading_order(step_files)
    steps = {}
    for f in step_files:
        if (working_dir is not None):
            if ((not (working_dir == os.path.dirname(f))) and (not is_url(f))):
                copied_file = os.path.join(working_dir, os.path.basename(f))
                shutil.copy2(f, copied_file)
                f = copied_file
        try:
            s = Step(f)
            steps[s.name] = s
        except (NotImplementedError, ValidationException, PackedWorkflowException) as e:
            logger.warning(e)
    return steps

Return a dictionary containing Steps read from file.

Args:
steps_dir (str, optional): path to directory containing CWL files.
step_file (str, optional): path or http(s) url to a single CWL file.
step_list (list, optional): a list of directories, urls or local file
paths to CWL files or directories containing CWL files.

Return:
dict containing (name, Step) entries.


def tag_file(filename, artist, title, year=None, genre=None, artwork_url=None, album=None, track_number=None, url=None):
    try:
        audio = EasyMP3(filename)
        audio.tags = None
        audio['artist'] = artist
        audio['title'] = title
        if year:
            audio['date'] = str(year)
        if album:
            audio['album'] = album
        if track_number:
            audio['tracknumber'] = track_number
        if genre:
            audio['genre'] = genre
        if url:
            audio['website'] = url
        audio.save()
        if artwork_url:
            artwork_url = artwork_url.replace('https', 'http')
            mime = 'image/jpeg'
            if ('.jpg' in artwork_url):
                mime = 'image/jpeg'
            if ('.png' in artwork_url):
                mime = 'image/png'
            if ('-large' in artwork_url):
                new_artwork_url = artwork_url.replace('-large', '-t500x500')
                try:
                    image_data = requests.get(new_artwork_url).content
                except Exception as e:
                    image_data = requests.get(artwork_url).content
            else:
                image_data = requests.get(artwork_url).content
            audio = MP3(filename, ID3=OldID3)
            audio.tags.add(APIC(encoding=3, mime=mime, type=3, desc='Cover', data=image_data))
            audio.save()
        if url:
            audio = MP3(filename, ID3=OldID3)
            audio.tags.add(WXXX(encoding=3, url=url))
            audio.save()
        return True
    except Exception as e:
        puts((colored.red('Problem tagging file: ') + colored.white('Is this file a WAV?')))
        return False

Attempt to put ID3 tags on a file.

Args:
artist (str):
title (str):
year (int):
genre (str):
artwork_url (str):
album (str):
track_number (str):
filename (str):
url (str):


def remove_acl(path):

    if (platform.system() == constants.PLATFORM_DARWIN and
            os.path.isfile('/bin/chmod')):
        subprocess.call(['/bin/chmod', '-R', '-N', path])
    elif ((platform.system() == constants.PLATFORM_LINUX) and
            os.path.isfile('/bin/setfacl')):
        subprocess.call(['/bin/setfacl', '-R', '-b', path])

Remove the ACL of the file or folder located on the given path.

Also remove the ACL of any file and folder below the given one,
recursively.

Args:
path (str): Path to the file or folder to remove the ACL for,
recursively.


def __eq__(self, other):

        if other.__class__ is not self.__class__:
            return NotImplemented
        return (
            self._tp__get_typed_properties()
            == other._tp__get_typed_properties()
        )

Test if two objects of the same base class are equal.

If the objects are not of the same class, Python will default to
comparison-by-ID.

Args:
other: The object to compare for equality.

Returns:
True if the objects are equal; else False.


def delete(self, name, **kwargs):

        self.gitlab.http_delete(self.path, query_data={'name': name}, **kwargs)

Delete a Label on the server.

Args:
name: The name of the label
**kwargs: Extra options to send to the server (e.g. sudo)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabDeleteError: If the server cannot perform the request


def AddEventTags(self, event_tags):

    self._RaiseIfNotWritable()

    for event_tag in event_tags:
      self.AddEventTag(event_tag)

Adds event tags.

Args:
event_tags (list[EventTag]): event tags.

Raises:
IOError: when the storage file is closed or read-only or
if the event tags cannot be serialized.
OSError: when the storage file is closed or read-only or
if the event tags cannot be serialized.


def _LastEntryTimestamp(dct, upper_bound_timestamp):
    if (upper_bound_timestamp is None):
        upper_bound = (lambda _: True)
    else:
        upper_bound = (lambda key: (key <= upper_bound_timestamp))
    try:
        return max(filter(upper_bound, iterkeys(dct)))
    except ValueError:
        return None

Searches for greatest timestamp lower than the specified one.

Args:
dct: A dictionary from timestamps to some items.
upper_bound_timestamp: An upper bound for timestamp to be returned.

Returns:
Greatest timestamp that is lower than the specified one. If no such value
exists, `None` is returned.


def df_first_row_to_dict(df):
    if (df is not None):
        return [dict(r) for (i, r) in df.head(1).iterrows()][0]

First DataFrame row to list of dict

Args:
df (pandas.DataFrame): A DataFrame with at least one row

Returns:
A list of dict that looks like:

[{'C1': 'x'}, {'C2': 'y'}, {'C3': 'z'}]

from a DataFrame that looks like:

C1  C2  C3
1   x   y   z

Else if `df` is `None`, returns `None`


def GetCredential(self, path_spec, identifier):

    credentials = self._credentials_per_path_spec.get(path_spec.comparable, {})
    return credentials.get(identifier, None)

Retrieves a specific credential from the key chain.

Args:
path_spec (PathSpec): path specification.
identifier (str): credential identifier.

Returns:
object: credential or None if the credential for the path specification
is not set.


def resize(self, height, width):

        return self.client.api.resize(self.id, height, width)

Resize the tty session.

Args:
height (int): Height of tty session
width (int): Width of tty session

Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.


def pretokenized_tfrecord_dataset(filenames, text2self, eos_included, repeat, batch_size, sequence_length):
    dataset = tf.data.TFRecordDataset(filenames, buffer_size=((64 * 1024) * 1024))
    if repeat:
        dataset = dataset.repeat()
    keys = (['targets'] if text2self else ['inputs', 'targets'])

    def decode_example(serialized_example):
        'Return a dict of Tensors from a serialized tensorflow.Example.'
        data_fields = {}
        data_items_to_decoders = {}
        for k in keys:
            data_fields[k] = tf.VarLenFeature(tf.int64)
            data_items_to_decoders[k] = tf.contrib.slim.tfexample_decoder.Tensor(k)
        decoder = tf.contrib.slim.tfexample_decoder.TFExampleDecoder(data_fields, data_items_to_decoders)
        decode_items = list(sorted(data_items_to_decoders))
        decoded = decoder.decode(serialized_example, items=decode_items)
        if (not eos_included):
            decoded = [tf.concat([v, [1]], 0) for v in decoded]
        return dict(zip(decode_items, decoded))
    dataset = dataset.map(decode_example, num_parallel_calls=tf.data.experimental.AUTOTUNE)
    return pack_and_batch(dataset, batch_size, sequence_length)

Reads tensor2tensor-style data files.

The dataset is defined by sets of TFRecord files of TFExample protos.
There should be a "targets" feature (a 1d tensor of integers)
If not text2self, there should also be an "inputs" feature.
Other features get ignored.

eos_included specifies whether the inputs and targets were written with an
EOS token, as in tensor2tensor

Args:
filenames: a list of strings
text2self: a boolean
eos_included: a boolean
repeat: a boolean
batch_size: an integer
sequence_length: an integer
Returns:
A tf.data.Dataset of batches


def merge(self, options):
    if (not options):
        return _CallSettings(timeout=self.timeout, retry=self.retry, page_descriptor=self.page_descriptor, page_token=self.page_token, bundler=self.bundler, bundle_descriptor=self.bundle_descriptor, kwargs=self.kwargs)
    else:
        if (options.timeout == OPTION_INHERIT):
            timeout = self.timeout
        else:
            timeout = options.timeout
        if (options.retry == OPTION_INHERIT):
            retry = self.retry
        else:
            retry = options.retry
        if (options.page_token == OPTION_INHERIT):
            page_token = self.page_token
        else:
            page_token = options.page_token
        if options.is_bundling:
            bundler = self.bundler
        else:
            bundler = None
        if (options.kwargs == OPTION_INHERIT):
            kwargs = self.kwargs
        else:
            kwargs = self.kwargs.copy()
            kwargs.update(options.kwargs)
        return _CallSettings(timeout=timeout, retry=retry, page_descriptor=self.page_descriptor, page_token=page_token, bundler=bundler, bundle_descriptor=self.bundle_descriptor, kwargs=kwargs)

Returns new _CallSettings merged from this and a CallOptions object.

Note that passing if the CallOptions instance specifies a page_token,
the merged _CallSettings will have ``flatten_pages`` disabled. This
permits toggling per-resource/per-page page streaming.

Args:
options (CallOptions): an instance whose values override
those in this object. If None, ``merge`` returns a copy of this
object

Returns:
CallSettings: The merged settings and options.


def ip_geoloc(ip, hit_api=True):
    from ..logs.models import IPInfoCheck
    try:
        obj = IPInfoCheck.objects.get(ip_address=ip).ip_info
    except IPInfoCheck.DoesNotExist:
        if hit_api:
            try:
                obj = IPInfoCheck.check_ip(ip)
            except RateExceededError:
                return None
        else:
            return None
    return (obj.latitude, obj.longitude)

Get IP geolocation.

Args:
ip (str): IP address to use if no data provided.
hit_api (bool): whether to hit api if info not found.

Returns:
str: latitude and longitude, comma-separated.


def _archive_elements(self):

        try:
            stackfile_key, propertyfile_key = self._craft_s3_keys()

            template_file = self._config.get('environment', {}).get('template', None)
            bucket = self._config.get('environment', {}).get('bucket', None)
            if not os.path.isfile(template_file):
                logging.info("{} is not actually a file".format(template_file))
                return False

            logging.info('Copying parameters to s3:
            temp_file_name = '/tmp/{}'.format((str(uuid.uuid4()))[:8])
            with open(temp_file_name, 'w') as dump_file:
                json.dump(self._parameters, dump_file, indent=4)

            self._s3.upload_file(temp_file_name, bucket, propertyfile_key)

            logging.info('Copying {} to s3:
            self._s3.upload_file(template_file, bucket, stackfile_key)

            self._templateUrl = 'https:
            logging.info("template_url: " + self._templateUrl)
            return True
        except Exception as x:
            logging.error('Exception caught in copy_stuff_to_S3(): {}'.format(x))
            traceback.print_exc(file=sys.stdout)
            return False

Cloud Formation likes to take the template from S3 so here we put the
template into S3. We also store the parameters file that was used in
this run. Note: you can pass anything as the version string but you
should at least consider a version control tag or git commit hash as
the version.

Args:
None

Returns:
True if the stuff lands in S3 or False if the file doesn't
really exist or the upload goes sideways.


def jsonify(data, pretty=False, **kwargs):
    isod = isinstance(data, OrderedDict)
    params = {'for_json': True, 'default': _complex_encode}
    if pretty:
        params['indent'] = 2
        params['sort_keys'] = (False if isod else True)
    params.update(kwargs)
    try:
        return json.dumps(data, ensure_ascii=False, **params)
    except UnicodeDecodeError:
        return json.dumps(data, **params)

Serialize Python objects to JSON with optional 'pretty' formatting

Raises:
TypeError: from :mod:`json` lib
ValueError: from :mod:`json` lib
JSONDecodeError: from :mod:`json` lib


def bearing(self, format='numeric'):

        bearings = []
        for segment in self:
            if len(segment) < 2:
                bearings.append([])
            else:
                bearings.append(segment.bearing(format))
        return bearings

Calculate bearing between locations in segments.

Args:
format (str): Format of the bearing string to return

Returns:
list of list of float: Groups of bearings between points in
segments


def get_all_anchors(stride=None, sizes=None):

    if stride is None:
        stride = cfg.RPN.ANCHOR_STRIDE
    if sizes is None:
        sizes = cfg.RPN.ANCHOR_SIZES

    cell_anchors = generate_anchors(
        stride,
        scales=np.array(sizes, dtype=np.float) / stride,
        ratios=np.array(cfg.RPN.ANCHOR_RATIOS, dtype=np.float))

    max_size = cfg.PREPROC.MAX_SIZE
    field_size = int(np.ceil(max_size / stride))
    shifts = np.arange(0, field_size) * stride
    shift_x, shift_y = np.meshgrid(shifts, shifts)
    shift_x = shift_x.flatten()
    shift_y = shift_y.flatten()
    shifts = np.vstack((shift_x, shift_y, shift_x, shift_y)).transpose()

    K = shifts.shape[0]

    A = cell_anchors.shape[0]
    field_of_anchors = (
        cell_anchors.reshape((1, A, 4)) +
        shifts.reshape((1, K, 4)).transpose((1, 0, 2)))
    field_of_anchors = field_of_anchors.reshape((field_size, field_size, A, 4))

    field_of_anchors = field_of_anchors.astype('float32')
    field_of_anchors[:, :, :, [2, 3]] += 1
    return field_of_anchors

Get all anchors in the largest possible image, shifted, floatbox
Args:
stride (int): the stride of anchors.
sizes (tuple[int]): the sizes (sqrt area) of anchors

Returns:
anchors: SxSxNUM_ANCHORx4, where S == ceil(MAX_SIZE/STRIDE), floatbox
The layout in the NUM_ANCHOR dim is NUM_RATIO x NUM_SIZE.


def __init__(self, module_name, text):

    super(Report, self).__init__()
    self.module_name = module_name
    self.text = text

Initializes the analysis report.
Args:
module_name (str): name of the analysis plugin that generated
the report.
text (str): report text.


def parse_args(bels: list, char_locs: CharLocs, parsed: Parsed, errors: Errors) -> Tuple[(Parsed, Errors)]:
    commas = char_locs['commas']
    for span in parsed:
        if ((parsed[span]['type'] != 'Function') or ('parens_span' not in parsed[span])):
            continue
        (sp, ep) = parsed[span]['parens_span']
        if (ep == (- 1)):
            args_end = (len(bels) - 1)
        else:
            args_end = (ep - 1)
        args = []
        arg_start = (sp + 1)
        each_arg_end_list = sorted(([(end - 1) for end in commas.get(sp, [])] + [args_end]))
        for arg_end in each_arg_end_list:
            while ((arg_start < args_end) and (bels[arg_start] == ' ')):
                arg_start += 1
            trimmed_arg_end = arg_end
            while ((trimmed_arg_end > arg_start) and (bels[trimmed_arg_end] == ' ')):
                trimmed_arg_end -= 1
            if (trimmed_arg_end < arg_start):
                trimmed_arg_end = arg_start
            arg = ''.join(bels[arg_start:(trimmed_arg_end + 1)])
            args.append({'arg': arg, 'span': (arg_start, trimmed_arg_end)})
            arg_start = (arg_end + 2)
        parsed[span]['args'] = args
    return (parsed, errors)

Parse arguments from functions

Args:
bels: BEL string as list of chars
char_locs: char locations for parens, commas and quotes
parsed: function locations
errors: error messages

Returns:
(functions, errors): function and arg locations plus error messages


def _process_active_view_and_verification(self, placement, feed_item):
    if FieldMap.PLACEMENT_ACTIVE_VIEW_AND_VERIFICATION in feed_item:
        if feed_item.get(FieldMap.PLACEMENT_ACTIVE_VIEW_AND_VERIFICATION, None) == 'ON':
            placement['vpaidAdapterChoice'] = 'HTML5'
            placement['videoActiveViewOptOut'] = False
        elif feed_item.get(FieldMap.PLACEMENT_ACTIVE_VIEW_AND_VERIFICATION, None) == 'OFF':
            placement['vpaidAdapterChoice'] = 'DEFAULT'
            placement['videoActiveViewOptOut'] = True
        elif feed_item[FieldMap.PLACEMENT_ACTIVE_VIEW_AND_VERIFICATION] == 'LET_DCM_DECIDE' or feed_item[FieldMap.PLACEMENT_ACTIVE_VIEW_AND_VERIFICATION] == '':
            placement['vpaidAdapterChoice'] = 'DEFAULT'
            placement['videoActiveViewOptOut'] = False
        else:
            raise Exception('%s is not a valid value for the placement Active View and Verification field' % feed_item.get(FieldMap.PLACEMENT_ACTIVE_VIEW_AND_VERIFICATION, None))

Updates / creates active view and verification settings.

This method updates the CM item by setting or creating active view and
verification settings based on the Bulkdozer feed configurations.

Args:
placement: The CM placement object to be updated.
feed_item: The Bulkdozer feed item with the configurations.

Raises:
Exception: In case the values for active view and verification enumeration
is invalid.


def noise_get(
    n: tcod.noise.Noise, f: Sequence[float], typ: int = NOISE_DEFAULT
) -> float:

    return float(lib.TCOD_noise_get_ex(n.noise_c, ffi.new("float[4]", f), typ))

Return the noise value sampled from the ``f`` coordinate.

``f`` should be a tuple or list with a length matching
:any:`Noise.dimensions`.
If ``f`` is shoerter than :any:`Noise.dimensions` the missing coordinates
will be filled with zeros.

Args:
n (Noise): A Noise instance.
f (Sequence[float]): The point to sample the noise from.
typ (int): The noise algorithm to use.

Returns:
float: The sampled noise value.


def __init__(self, query_functions=None):

        super(QueryRequestPayload, self).__init__(enums.Tags.REQUEST_PAYLOAD)

        self._query_functions = None

        self.query_functions = query_functions

Construct a QueryRequestPayload object.

Args:
query_functions (list): A list of QueryFunction enumerations.


def as_operation(self):
    result = encoding.CopyProtoMessage(self._op)
    names = sorted(self._metric_values_by_name_then_sign.keys())
    for name in names:
        mvs = self._metric_values_by_name_then_sign[name]
        result.metricValueSets.append(sc_messages.MetricValueSet(metricName=name, metricValues=mvs.values()))
    return result

Obtains a single `Operation` representing this instances contents.

Returns:
:class:`endpoints_management.gen.servicecontrol_v1_messages.Operation`


def get_vmss_vm(access_token, subscription_id, resource_group, vmss_name, instance_id):

    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/resourceGroups/', resource_group,
                        '/providers/Microsoft.Compute/virtualMachineScaleSets/', vmss_name,
                        '/virtualMachines/', str(instance_id),
                        '?api-version=', COMP_API])
    return do_get(endpoint, access_token)

Get individual VMSS VM details.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
vmss_name (str): Name of the virtual machine scale set.
instance_id (int): VM ID of the scale set VM.

Returns:
HTTP response. JSON body of VMSS VM model view.


def previous_weekday(date):

    weekday = date.weekday()
    if weekday == 0:
        n_days = 3
    elif weekday == 6:
        n_days = 2
    else:
        n_days = 1
    return date - datetime.timedelta(days=n_days)

Returns the last weekday before date

Args:
date (datetime or datetime.date)
Returns:
(datetime or datetime.date)
Raises:
-


def build_eval_session(module_spec, class_count):
    (eval_graph, bottleneck_tensor, resized_input_tensor, wants_quantization) = create_module_graph(module_spec)
    eval_sess = tf.Session(graph=eval_graph)
    with eval_graph.as_default():
        (_, _, bottleneck_input, ground_truth_input, final_tensor) = add_final_retrain_ops(class_count, FLAGS.final_tensor_name, bottleneck_tensor, wants_quantization, is_training=False)
        tf.train.Saver().restore(eval_sess, CHECKPOINT_NAME)
        (evaluation_step, prediction) = add_evaluation_step(final_tensor, ground_truth_input)
    return (eval_sess, resized_input_tensor, bottleneck_input, ground_truth_input, evaluation_step, prediction)

Builds an restored eval session without train operations for exporting.

Args:
module_spec: The hub.ModuleSpec for the image module being used.
class_count: Number of classes

Returns:
Eval session containing the restored eval graph.
The bottleneck input, ground truth, eval step, and prediction tensors.


def add_cookie(self, cookie_dict):
    if (not isinstance(cookie_dict, dict)):
        raise TypeError('Type of the cookie must be a dict.')
    if ((not cookie_dict.get('name', None)) or (not cookie_dict.get('value', None))):
        raise KeyError("Missing required keys, 'name' and 'value' must be provided.")
    self._execute(Command.ADD_COOKIE, {'cookie': cookie_dict})

Set a cookie.

Support:
Web(WebView)

Args:
cookie_dict: A dictionary contain keys: "name", "value",
["path"], ["domain"], ["secure"], ["httpOnly"], ["expiry"].

Returns:
WebElement Object.


def count(self, value):

        if value == self._defaults['count'] and 'count' in self._values:
            del self._values['count']
        else:
            self._values['count'] = value

The count property.

Args:
value (int). the property value.


def bytes_to_long(bytesdata: bytes) -> int:
    assert (len(bytesdata) == 8)
    return sum(((b << (k * 8)) for (k, b) in enumerate(bytesdata)))

Converts an 8-byte sequence to a long integer.

Args:
bytesdata: 8 consecutive bytes, as a ``bytes`` object, in
little-endian format (least significant byte [LSB] first)

Returns:
integer


def PushEventSource(self, event_source):
    if (event_source.file_entry_type == dfvfs_definitions.FILE_ENTRY_TYPE_DIRECTORY):
        weight = 1
    else:
        weight = 100
    heap_values = (weight, time.time(), event_source)
    heapq.heappush(self._heap, heap_values)

Pushes an event source onto the heap.

Args:
event_source (EventSource): event source.


Publicly accessible method for determining the current backend.

Only exists for API compatibility with multi-backend Keras.

Returns:
The string "tensorflow".


def postprocess_docs(self, docs, input_strings, prefix, n_docs, return_tensors=None):

    def cat_input_and_doc(doc_title, doc_text, input_string, prefix):
        if doc_title.startswith('"'):
            doc_title = doc_title[1:]
        if doc_title.endswith('"'):
            doc_title = doc_title[:-1]
        if prefix is None:
            prefix = ''
        out = (prefix + doc_title + self.config.title_sep + doc_text + self.config.doc_sep + input_string).replace('  ', ' ')
        return out
    rag_input_strings = [cat_input_and_doc(docs[i]['title'][j], docs[i]['text'][j], input_strings[i], prefix) for i in range(len(docs)) for j in range(n_docs)]
    contextualized_inputs = self.generator_tokenizer.batch_encode_plus(rag_input_strings, max_length=self.config.max_combined_length, return_tensors=return_tensors, padding='max_length', truncation=True)
    return (contextualized_inputs['input_ids'], contextualized_inputs['attention_mask'])

Postprocessing retrieved `docs` and combining them with `input_strings`.

Args:
docs  (`dict`):
Retrieved documents.
input_strings (`str`):
Input strings decoded by `preprocess_query`.
prefix (`str`):
Prefix added at the beginning of each input, typically used with T5-based models.

Return:
`tuple(tensors)`: a tuple consisting of two elements: contextualized `input_ids` and a compatible
`attention_mask`.


def list(self, path):
    self.__validate_storage_path(path)
    entity = self.api_client.get_entity_by_query(path=path)
    if (entity['entity_type'] not in self.__BROWSABLE_TYPES):
        raise StorageArgumentException('The entity type "{0}" cannot belisted'.format(entity['entity_type']))
    entity_uuid = entity['uuid']
    file_names = []
    more_pages = True
    page_number = 1
    while more_pages:
        response = self.api_client.list_folder_content(entity_uuid, page=page_number, ordering='name')
        more_pages = (response['next'] is not None)
        page_number += 1
        for child in response['results']:
            pattern = ('/{name}' if (child['entity_type'] == 'folder') else '{name}')
            file_names.append(pattern.format(name=child['name']))
    return file_names

List the entities found directly under the given path.

Args:
path (str): The path of the entity to be listed. Must start with a '/'.

Returns:
The list of entity names directly under the given path:

u'/12345/folder_1'

Raises:
StorageArgumentException: Invalid arguments
StorageForbiddenException: Server response code 403
StorageNotFoundException: Server response code 404
StorageException: other 400-600 error codes


def set_scf_initial_guess(self, guess='SAD'):
    availabel_guesses = {'core', 'sad', 'gwh', 'read', 'fragmo'}
    if (guess.lower() not in availabel_guesses):
        raise ValueError((('The guess method ' + guess) + ' is not supported yet'))
    self.params['rem']['scf_guess'] = guess.lower()

Set initial guess method to be used for SCF

Args:
guess: The initial guess method. (str)


def sed(regexpr, repl, force=False, recursive=False, dpath_list=None, fpath_list=None, verbose=None, include_patterns=None, exclude_patterns=[]):
    if (include_patterns is None):
        include_patterns = ['*.py', '*.pyx', '*.pxi', '*.cxx', '*.cpp', '*.hxx', '*.hpp', '*.c', '*.h', '*.html', '*.tex']
    if (dpath_list is None):
        dpath_list = [os.getcwd()]
    if (verbose is None):
        verbose = ut.NOT_QUIET
    if (fpath_list is None):
        greater_exclude_dirs = get_standard_exclude_dnames()
        exclude_dirs = []
        fpath_generator = matching_fpaths(dpath_list, include_patterns, exclude_dirs, greater_exclude_dirs=greater_exclude_dirs, recursive=recursive, exclude_patterns=exclude_patterns)
    else:
        fpath_generator = fpath_list
    if verbose:
        print(('sed-ing %r' % (dpath_list,)))
        print((' * regular expression : %r' % (regexpr,)))
        print((' * replacement        : %r' % (repl,)))
        print((' * include_patterns   : %r' % (include_patterns,)))
        print((' * recursive: %r' % (recursive,)))
        print((' * force: %r' % (force,)))
        from utool import util_str
        print((' * fpath_list: %s' % (util_str.repr3(fpath_list),)))
    regexpr = extend_regex(regexpr)
    num_changed = 0
    num_files_checked = 0
    fpaths_changed = []
    for fpath in fpath_generator:
        num_files_checked += 1
        changed_lines = sedfile(fpath, regexpr, repl, force, verbose=verbose)
        if (changed_lines is not None):
            fpaths_changed.append(fpath)
            num_changed += len(changed_lines)
    import utool as ut
    print(('num_files_checked = %r' % (num_files_checked,)))
    print(('fpaths_changed = %s' % (ut.repr3(sorted(fpaths_changed)),)))
    print(('total lines changed = %r' % (num_changed,)))

Python implementation of sed. NOT FINISHED

searches and replaces text in files

Args:
regexpr (str): regx patterns to find
repl (str): text to replace
force (bool):
recursive (bool):
dpath_list (list): directories to search (defaults to cwd)


def plot_main(pid, return_fig_ax=False):
    global WORKING_DIRECTORY, SNR_CUT
    if isinstance(pid, PlotInput):
        pid = pid.return_dict()
    WORKING_DIRECTORY = '.'
    if ('WORKING_DIRECTORY' not in pid['general'].keys()):
        pid['general']['WORKING_DIRECTORY'] = '.'
    SNR_CUT = 5.0
    if ('SNR_CUT' not in pid['general'].keys()):
        pid['general']['SNR_CUT'] = SNR_CUT
    if ('switch_backend' in pid['general'].keys()):
        plt.switch_backend(pid['general']['switch_backend'])
    running_process = MakePlotProcess(**{**pid, **pid['general'], **pid['plot_info'], **pid['figure']})
    running_process.input_data()
    running_process.setup_figure()
    running_process.create_plots()
    if ('save_figure' in pid['figure'].keys()):
        if (pid['figure']['save_figure'] is True):
            running_process.fig.savefig(((pid['general']['WORKING_DIRECTORY'] + '/') + pid['figure']['output_path']), **pid['figure']['savefig_kwargs'])
    if ('show_figure' in pid['figure'].keys()):
        if (pid['figure']['show_figure'] is True):
            plt.show()
    if (return_fig_ax is True):
        return (running_process.fig, running_process.ax)
    return

Main function for creating these plots.

Reads in plot info dict from json file or dictionary in script.

Args:
return_fig_ax (bool, optional): Return figure and axes objects.

Returns:
2-element tuple containing
- **fig** (*obj*): Figure object for customization outside of those in this program.
- **ax** (*obj*): Axes object for customization outside of those in this program.


def add_node(self, node_id, name, labels):

        node = self.graph_db.get_or_create_indexed_node('Node', 'node_id', node_id, {'node_id': node_id, 'name': name})
        try:
            node.add_labels(*labels)
        except NotImplementedError:
            pass

Add the node with name and labels.

Args:
node_id: Id for the node.
name: Name for the node.
labels: Label for the node.

Raises:
NotImplementedError: When adding labels is not supported.


def filter_by_pattern(self, pattern):

        _filt_values, _filt_datetimes = self._filter_by_pattern(pattern)
        collection = HourlyDiscontinuousCollection(
            self.header.duplicate(), _filt_values, _filt_datetimes)
        collection._validated_a_period = True
        return collection

Filter the Data Collection based on a list of booleans.

Args:
pattern: A list of True/False values.  Typically, this is a list
with a length matching the length of the Data Collections values
but it can also be a pattern to be repeated over the Data Collection.

Return:
A new Data Collection with filtered data


def ensure_exe(exe_name: str, *paths: str):

    if not elib_run.find_executable(exe_name, *paths):
        LOGGER.error('could not find "%s.exe" on this system', exe_name)
        sys.exit(-1)

Makes sure that an executable can be found on the system path.
Will exit the program if the executable cannot be found

Args:
exe_name: name of the executable
paths: optional path(s) to be searched; if not specified, search the whole system


def intify(x):

    if isinstance(x, int):
        return x

    try:
        return int(x, 0)
    except (TypeError, ValueError):
        return None

Ensure ( or coerce ) a value into being an integer or None.

Args:
x (obj):    An object to intify

Returns:
(int):  The int value ( or None )


def _split_op(self, identifier, hs_label=None, dagger=False, args=None):
    if self._isinstance(identifier, 'SymbolicLabelBase'):
        identifier = QnetAsciiDefaultPrinter()._print_SCALAR_TYPES(identifier.expr)
    (name, total_subscript) = self._split_identifier(identifier)
    total_superscript = ''
    if (hs_label not in [None, '']):
        if (self._settings['show_hs_label'] == 'subscript'):
            if (len(total_subscript) == 0):
                total_subscript = (('(' + hs_label) + ')')
            else:
                total_subscript += ((',(' + hs_label) + ')')
        else:
            total_superscript += (('(' + hs_label) + ')')
    if dagger:
        total_superscript += self._dagger_sym
    args_str = ''
    if ((args is not None) and (len(args) > 0)):
        args_str = ((self._parenth_left + ','.join([self.doprint(arg) for arg in args])) + self._parenth_right)
    return (name, total_subscript, total_superscript, args_str)

Return `name`, total `subscript`, total `superscript` and
`arguments` str. All of the returned strings are fully rendered.

Args:
identifier (str or SymbolicLabelBase): A (non-rendered/ascii)
identifier that may include a subscript. The output `name` will
be the `identifier` without any subscript
hs_label (str): The rendered label for the Hilbert space of the
operator, or None. Returned unchanged.
dagger (bool): Flag to indicate whether the operator is daggered.
If True, :attr:`dagger_sym` will be included in the
`superscript` (or  `subscript`, depending on the settings)
args (list or None): List of arguments (expressions). Each element
will be rendered with :meth:`doprint`. The total list of args
will then be joined with commas, enclosed
with :attr:`_parenth_left` and :attr:`parenth_right`, and
returnd as the `arguments` string


def create_attribute_model(self, initial_value=None):

        attr = self.attribute_class(meta=self, value=initial_value)
        return attr

Make an AttributeModel instance of the correct type for this Meta

Args:
initial_value: The initial value the Attribute should take

Returns:
AttributeModel: The created attribute model instance


def build_inputs_with_special_tokens(self, token_ids_0: List[int], token_ids_1: Optional[List[int]]=None) -> List[int]:
    sep = [self.sep_token_id]
    cls = [self.cls_token_id]
    result = cls + token_ids_0 + sep
    if token_ids_1 is not None:
        result += token_ids_1 + sep
    return result

Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
adding special tokens. A CANINE sequence has the following format:

- single sequence: `[CLS] X [SEP]`
- pair of sequences: `[CLS] A [SEP] B [SEP]`

Args:
token_ids_0 (`List[int]`):
List of IDs to which the special tokens will be added.
token_ids_1 (`List[int]`, *optional*):
Optional second list of IDs for sequence pairs.

Returns:
`List[int]`: List of [input IDs](../glossary#input-ids) with the appropriate special tokens.


def _md5sum(file_path):
    md5 = hashlib.md5()
    with open(file_path, 'rb') as md5_file:
        while True:
            data = md5_file.read(((1024 * 1024) * 4))
            if (not data):
                break
            md5.update(data)
    return md5.digest()

Helper function that builds and md5sum from a file in chunks.

Args:
file_path: The path to the file you want an md5sum for.

Returns:
A string containing an md5sum.


def CalculateWaitForRetry(retry_attempt, max_wait=60):

    wait_time = 2 ** retry_attempt
    max_jitter = wait_time / 4.0
    wait_time += random.uniform(-max_jitter, max_jitter)
    return max(1, min(wait_time, max_wait))

Calculates amount of time to wait before a retry attempt.

Wait time grows exponentially with the number of attempts. A
random amount of jitter is added to spread out retry attempts from
different clients.

Args:
retry_attempt: Retry attempt counter.
max_wait: Upper bound for wait time [seconds].

Returns:
Number of seconds to wait before retrying request.


def matrix_rank(a, tol=None, validate_args=False, name=None):
    with ops.name_scope(name or 'matrix_rank'):
        a = ops.convert_to_tensor(a, dtype_hint=dtypes.float32, name='a')
        assertions = _maybe_validate_matrix(a, validate_args)
        if assertions:
            with ops.control_dependencies(assertions):
                a = array_ops.identity(a)
        s = svd(a, compute_uv=False)
        if tol is None:
            if a.shape[-2:].is_fully_defined():
                m = np.max(a.shape[-2:].as_list())
            else:
                m = math_ops.reduce_max(array_ops.shape(a)[-2:])
            eps = np.finfo(a.dtype.as_numpy_dtype).eps
            tol = eps * math_ops.cast(m, a.dtype) * math_ops.reduce_max(s, axis=-1, keepdims=True)
        return math_ops.reduce_sum(math_ops.cast(s > tol, dtypes.int32), axis=-1)

Compute the matrix rank of one or more matrices.

Args:
a: (Batch of) `float`-like matrix-shaped `Tensor`(s) which are to be
pseudo-inverted.
tol: Threshold below which the singular value is counted as 'zero'.
Default value: `None` (i.e., `eps * max(rows, cols) * max(singular_val)`).
validate_args: When `True`, additional assertions might be embedded in the
graph.
Default value: `False` (i.e., no graph assertions are added).
name: Python `str` prefixed to ops created by this function.
Default value: 'matrix_rank'.

Returns:
matrix_rank: (Batch of) `int32` scalars representing the number of non-zero
singular values.


def open_image(fn):
    flags = ((cv2.IMREAD_UNCHANGED + cv2.IMREAD_ANYDEPTH) + cv2.IMREAD_ANYCOLOR)
    if ((not os.path.exists(fn)) and (not str(fn).startswith('http'))):
        raise OSError('No such file or directory: {}'.format(fn))
    elif (os.path.isdir(fn) and (not str(fn).startswith('http'))):
        raise OSError('Is a directory: {}'.format(fn))
    elif isdicom(fn):
        slice = pydicom.read_file(fn)
        if slice.PhotometricInterpretation.startswith('MONOCHROME'):
            im = np.stack(([slice.pixel_array] * 3), (- 1))
            return (im / ((1 << slice.BitsStored) - 1))
        else:
            raise OSError('Unsupported DICOM image with PhotometricInterpretation=={}'.format(slice.PhotometricInterpretation))
    else:
        try:
            if str(fn).startswith('http'):
                req = urllib.urlopen(str(fn))
                image = np.asarray(bytearray(req.read()), dtype='uint8')
                im = (cv2.imdecode(image, flags).astype(np.float32) / 255)
            else:
                im = (cv2.imread(str(fn), flags).astype(np.float32) / 255)
            if (im is None):
                raise OSError(f'File not recognized by opencv: {fn}')
            return cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
        except Exception as e:
            raise OSError('Error handling image at: {}'.format(fn)) from e

Opens an image using OpenCV given the file path.

Arguments:
fn: the file path of the image

Returns:
The image in RGB format as numpy array of floats normalized to range between 0.0 - 1.0


def get_token(wallet: 'Wallet', token_str: str) -> 'NEP5Token.NEP5Token':
    if token_str.startswith('0x'):
        token_str = token_str[2:]
    token = None
    for t in wallet.GetTokens().values():
        if (token_str in [t.symbol, t.ScriptHash.ToString()]):
            token = t
            break
    if (not isinstance(token, NEP5Token.NEP5Token)):
        raise ValueError('The given token argument does not represent a known NEP5 token')
    return token

Try to get a NEP-5 token based on the symbol or script_hash

Args:
wallet: wallet instance
token_str: symbol or script_hash (accepts script hash with or without 0x prefix)
Raises:
ValueError: if token is not found

Returns:
NEP5Token instance if found.


def __getitem__(self, slice_: Tuple[Union[slice, np.ndarray, int], Union[slice, np.ndarray, int]]) -> loompy.LoomView:

		if type(slice_) is not tuple or len(slice_) is not 2:
			raise ValueError("Views require slices along two dimensions")

		rows = slice_[0]
		cols = slice_[1]

		ra = self.ds.ra[rows]
		row_graphs = self.ds.row_graphs[rows]
		ca = self.ds.ca[cols]
		col_graphs = self.ds.col_graphs[cols]
		layers = self.ds.layer[rows, cols]

		return loompy.LoomView(layers, ra, ca, row_graphs, col_graphs, filename=self.ds.filename, file_attrs=self.ds.attrs)

Create a new view by slicing through the loom file or view

Args:
slice_ (2-tuple of slice, int or np.ndarray): 	How to slice the file or view

Returns:
A LoomView object, an in-memory representation of the sliced file


def loads(conditions_string):

  decoder = ConditionDecoder(_audience_condition_deserializer)

  json_decoder = json.JSONDecoder(object_hook=decoder.object_hook)

  condition_structure = json_decoder.decode(conditions_string)
  condition_list = decoder.condition_list

  return (condition_structure, condition_list)

Deserializes the conditions property into its corresponding
components: the condition_structure and the condition_list.

Args:
conditions_string: String defining valid and/or conditions.

Returns:
A tuple of (condition_structure, condition_list).
condition_structure: nested list of operators and placeholders for operands.
condition_list: list of conditions whose index correspond to the values of the placeholders.


def resolve_context(self, verbosity=0, max_fails=(- 1), timestamp=None, callback=None, buf=None, package_load_callback=None):
    package_filter = PackageFilterList.from_pod(self.package_filter)
    context = ResolvedContext(self.request, package_paths=self.packages_path, package_filter=package_filter, verbosity=verbosity, max_fails=max_fails, timestamp=timestamp, buf=buf, callback=callback, package_load_callback=package_load_callback, caching=self.caching)
    if context.success:
        if (self._context and self._context.load_path):
            context.set_load_path(self._context.load_path)
        self._set_context(context)
        self._modified = True
    return context

Update the current context by performing a re-resolve.

The newly resolved context is only applied if it is a successful solve.

Returns:
`ResolvedContext` object, which may be a successful or failed solve.


def update(self, span: typing.Tuple[int, int], line_type: LineType) -> None:

        first_block_line, last_block_line = span
        for i in range(first_block_line, last_block_line + 1):
            try:
                self.__setitem__(i, line_type)
            except ValueError as error:
                raise ValidationError(i + self.fn_offset, 1, 'AAA99 {}'.format(error))

Updates line types for a block's span.

Args:
span: First and last relative line number of a Block.
line_type: The type of line to update to.

Raises:
ValidationError: A special error on collision. This prevents Flake8
from crashing because it is converted to a Flake8 error tuple,
but it indicates to the user that something went wrong with
processing the function.


def save_config(config, logdir=None):
    if logdir:
        with config.unlocked:
            config.logdir = logdir
        message = 'Start a new run and write summaries and checkpoints to {}.'
        tf.logging.info(message.format(config.logdir))
        tf.gfile.MakeDirs(config.logdir)
        config_path = os.path.join(config.logdir, 'config.yaml')
        with tf.gfile.FastGFile(config_path, 'w') as file_:
            yaml.dump(config, file_, default_flow_style=False)
    else:
        message = 'Start a new run without storing summaries and checkpoints since no logging directory was specified.'
        tf.logging.info(message)
    return config

Save a new configuration by name.

If a logging directory is specified, is will be created and the configuration
will be stored there. Otherwise, a log message will be printed.

Args:
config: Configuration object.
logdir: Location for writing summaries and checkpoints if specified.

Returns:
Configuration object.


def create_binary(self, key, value):
    data = None
    if ((key is not None) and (value is not None)):
        try:
            data = self.db.create(key.strip(), json.dumps(base64.b64encode(bytes(value)).decode('utf-8')))
        except TypeError:
            data = self.db.create(key.strip(), json.dumps(base64.b64encode(bytes(value, 'utf-8')).decode('utf-8')))
    else:
        self.tcex.log.warning(u'The key or value field was None.')
    return data

Create method of CRUD operation for binary data.

Args:
key (string): The variable to write to the DB.
value (any): The data to write to the DB.

Returns:
(string): Result of DB write.


def get_class_locals(cls_name: str, allow_methods: bool, ordering, ctx):
    out = collections.OrderedDict()
    if cls_name not in ctx.vm.local_ops:
        return out
    for op in ctx.vm.local_ops[cls_name]:
        local = ctx.vm.annotated_locals[cls_name][op.name]
        if not is_relevant_class_local(local, op.name, allow_methods):
            continue
        if ordering is Ordering.FIRST_ANNOTATE:
            if not op.is_annotate() or op.name in out:
                continue
        else:
            assert ordering is Ordering.LAST_ASSIGN
            if not op.is_assign():
                continue
            elif op.name in out:
                out.move_to_end(op.name)
        out[op.name] = local
    return out

Gets a dictionary of the class's local variables.

Args:
cls_name: The name of an abstract.InterpreterClass.
allow_methods: A bool, whether to allow methods as variables.
ordering: A classgen.Ordering describing the order in which the variables
should appear.
ctx: The abstract context.

Returns:
A collections.OrderedDict of the locals.


def _ImageDimensions(images, dynamic_shape=False):

  if dynamic_shape:
    return array_ops.unpack(array_ops.shape(images))
  else:
    return images.get_shape().as_list()

Returns the dimensions of an image tensor.
Args:
images: 4-D Tensor of shape [batch, height, width, channels]
dynamic_shape: Whether the input image has undertermined shape. If set to
`True`, shape information will be retrieved at run time. Default to
`False`.

Returns:
list of integers [batch, height, width, channels]


def __init__(self, definitions: fhir_package.FhirPackageManager, handler: primitive_handler.PrimitiveHandler, error_reporter: fhir_errors.ErrorReporter, options: Optional[SqlGenerationOptions]=None) -> None:
    self._options = options or SqlGenerationOptions()
    self._context = context.MockFhirPathContext(definitions.iter_structure_definitions())
    self._primitive_handler = handler
    self._bq_interpreter = _bigquery_interpreter.BigQuerySqlInterpreter(value_set_codes_table=self._options.value_set_codes_table, value_set_codes_definitions=self._options.value_set_codes_definitions or definitions)
    self._error_reporter = error_reporter
    self._options.skip_keys.update(_SKIP_KEYS)
    self._ctx: List[expressions.Builder] = []
    self._in_progress: Set[_PathStep] = set()
    self._type_code_to_regex_map: Dict[str, _RegexInfo] = {}
    self._regex_columns_generated = set()
    self._requirement_column_names: Set[str] = set()
    self._visited_element_definitions: Set[Tuple[str, str]] = set()
    self._visited_slices: Set[Tuple[str, str]] = set()

Creates a new instance of `FhirProfileStandardSqlEncoder`.

Args:
definitions: The FHIR resource "graph" for traversal and encoding of
constraints.
handler: Computes primitives with respect to the specification.
error_reporter: A `fhir_errors.ErrorReporter` delegate for error-handling.
options: Defines a list of optional settings that can be used to customize
the behaviour of FhirProfileStandardSqlEncoder.


def brake_on(self):

        data = []
        data.append(0x0A)
        data.append(self.servoid)
        data.append(RAM_WRITE_REQ)
        data.append(TORQUE_CONTROL_RAM)
        data.append(0x01)
        data.append(0x40)
        send_data(data)

Set the Brakes of Herkulex

In braked mode, position control and velocity control
will not work, enable torque before that

Args:
none


def _clone_sequential_model(model, input_tensors=None, layer_fn=_clone_layer):
    if not isinstance(model, Sequential):
        raise ValueError('Expected `model` argument to be a `Sequential` model instance, but got:', model)
    if not callable(layer_fn):
        raise ValueError('Expected `layer_fn` argument to be a callable.')
    layers = []
    layer_map = {}
    for layer in model._flatten_layers(include_self=False, recursive=False):
        if isinstance(layer, InputLayer) and input_tensors is not None:
            continue
        cloned_layer = _clone_layer(layer) if isinstance(layer, InputLayer) else layer_fn(layer)
        layers.append(cloned_layer)
        layer_map[layer] = cloned_layer
    layers, ancillary_layers = _remove_ancillary_layers(model, layer_map, layers)
    if input_tensors is None:
        cloned_model = Sequential(layers=layers, name=model.name)
    elif len(generic_utils.to_list(input_tensors)) != 1:
        raise ValueError('To clone a `Sequential` model, we expect  at most one tensor as part of `input_tensors`.')
    else:
        if isinstance(input_tensors, tuple):
            input_tensors = list(input_tensors)
        x = generic_utils.to_list(input_tensors)[0]
        if backend.is_keras_tensor(x):
            origin_layer = x._keras_history.layer
            if isinstance(origin_layer, InputLayer):
                cloned_model = Sequential(layers=[origin_layer] + layers, name=model.name)
            else:
                raise ValueError('Cannot clone a `Sequential` model on top of a tensor that comes from a Keras layer other than an `InputLayer`. Use the functional API instead.')
        else:
            input_tensor = Input(tensor=x, name='input_wrapper_for_' + str(x.name))
            input_layer = input_tensor._keras_history.layer
            cloned_model = Sequential(layers=[input_layer] + layers, name=model.name)
    if not ancillary_layers:
        return cloned_model
    tensor_map = {}
    for depth, cloned_nodes in cloned_model._nodes_by_depth.items():
        nodes = model._nodes_by_depth[depth]
        for cloned_node, node in zip(cloned_nodes, nodes):
            if isinstance(cloned_node.output_tensors, list):
                for j, output_tensor in enumerate(cloned_node.output_tensors):
                    tensor_map[node.output_tensors[j]] = output_tensor
            else:
                tensor_map[node.output_tensors] = cloned_node.output_tensors
    new_nodes = _make_new_nodes({depth: nodes for depth, nodes in model._nodes_by_depth.items() if depth < 0}, layer_fn, layer_map, tensor_map)
    _insert_ancillary_layers(cloned_model, ancillary_layers, model.metrics_names, new_nodes)
    return cloned_model

Clone a `Sequential` model instance.

Model cloning is similar to calling a model on new inputs,
except that it creates new layers (and thus new weights) instead
of sharing the weights of the existing layers.

Args:
model: Instance of `Sequential`.
input_tensors: optional list of input tensors
to build the model upon. If not provided,
placeholders will be created.
layer_fn: callable to be applied on non-input layers in the model. By
default it clones the layer. Another example is to preserve the layer
to share the weights. This is required when we create a per-replica
copy of the model with distribution strategy; we want the weights to
be shared but still feed inputs separately so we create new input
layers.

Returns:
An instance of `Sequential` reproducing the behavior
of the original model, on top of new inputs tensors,
using newly instantiated weights.

Raises:
ValueError: in case of invalid `model` argument value or `layer_fn`
argument value.


def __init__(self, unkeyed: ModelHandler[ExampleT, PredictionT, ModelT]):
    if len(unkeyed.get_preprocess_fns()) or len(unkeyed.get_postprocess_fns()):
        raise Exception('Cannot make make an unkeyed model handler with pre or postprocessing functions defined into a keyed model handler. All pre/postprocessing functions must be defined on the outer modelhandler.')
    self._unkeyed = unkeyed
    self._env_vars = getattr(unkeyed, '_env_vars', {})

A ModelHandler that takes examples that might have keys and returns
predictions that might have keys.

For example, if the original model is used with RunInference to take a
PCollection[E] to a PCollection[P], this ModelHandler would take either
PCollection[E] to a PCollection[P] or PCollection[tuple[K, E]] to a
PCollection[tuple[K, P]], depending on the whether the elements are
tuples. This pattern makes it possible to associate the outputs with the
inputs based on the key.

Note that you cannot use this ModelHandler if E is a tuple type.
In addition, either all examples should be keyed, or none of them.

Args:
unkeyed: An implementation of ModelHandler that does not require keys.


def split_string(str_src, spliters=None, elim_empty=False):

        if is_string(spliters):
            spliters = [spliters]
        if spliters is None or not spliters:
            spliters = [' ', '\t']
        dest_strs = list()
        src_strs = [str_src]
        while True:
            old_dest_strs = src_strs[:]
            for s in spliters:
                for src_s in src_strs:
                    temp_strs = src_s.split(s)
                    for temp_s in temp_strs:
                        temp_s = temp_s.strip()
                        if temp_s == '' and elim_empty:
                            continue
                        if is_string(temp_s):
                            temp_s = str(temp_s)
                        dest_strs.append(temp_s)
                src_strs = dest_strs[:]
                dest_strs = list()
            if old_dest_strs == src_strs:
                dest_strs = src_strs[:]
                break
        return dest_strs

Split string by split character space(' ') and indent('\t') as default

Examples:
>>> StringClass.split_string('exec -ini test.ini', ' ')
['exec', '-ini', 'test.ini']

Args:
str_src: source string
spliters: e.g. [' ', '\t'], [], ' ', None
elim_empty: Eliminate empty (i.e., '') or not.

Returns:
split sub-strings as list


def to_dict(self, remove_nones=False):

        content = {}

        for key in self._translation:
            if hasattr(self, key):
                content[key] = getattr(self, key)

        content['parent_id'] = self.parent_id
        content['item_id'] = self.item_id
        content['restricted'] = self.restricted
        content['title'] = self.title
        if self.resources != []:
            content['resources'] = [resource.to_dict(remove_nones=remove_nones)
                                    for resource in self.resources]
        content['desc'] = self.desc
        return content

Return the dict representation of the instance.

Args:
remove_nones (bool, optional): Optionally remove dictionary
elements when their value is `None`.

Returns:
dict: a dict representation of the `DidlObject`.


def __init__(self, optimizer, scope='global-optimizer', summary_labels=()):

        super(GlobalOptimizer, self).__init__(optimizer=optimizer, scope=scope, summary_labels=summary_labels)

Creates a new global optimizer instance.

Args:
optimizer: The optimizer which is modified by this meta optimizer.


def on_core_metadata_event(self, event):
    raise NotImplementedError('on_core_metadata_event() is not implemented in the base servicer class')

Callback for core metadata.

Args:
event: The Event proto that carries a JSON string in its
`log_message.message` field.

Returns:
`None` or an `EventReply` proto to be sent back to the client. If `None`,
an `EventReply` proto construct with the default no-arg constructor will
be sent back to the client.


def check(self, uid=None, usage_limits_count=None, cryptographic_usage_mask=None, lease_time=None):
    if (uid is not None):
        if (not isinstance(uid, six.string_types)):
            raise TypeError('The unique identifier must be a string.')
    if (usage_limits_count is not None):
        if (not isinstance(usage_limits_count, six.integer_types)):
            raise TypeError('The usage limits count must be an integer.')
    if (cryptographic_usage_mask is not None):
        if ((not isinstance(cryptographic_usage_mask, list)) or (not all((isinstance(x, enums.CryptographicUsageMask) for x in cryptographic_usage_mask)))):
            raise TypeError('The cryptographic usage mask must be a list of CryptographicUsageMask enumerations.')
    if (lease_time is not None):
        if (not isinstance(lease_time, six.integer_types)):
            raise TypeError('The lease time must be an integer.')
    result = self.proxy.check(uid, usage_limits_count, cryptographic_usage_mask, lease_time)
    status = result.get('result_status')
    if (status == enums.ResultStatus.SUCCESS):
        return result.get('unique_identifier')
    else:
        raise exceptions.KmipOperationFailure(status, result.get('result_reason'), result.get('result_message'))

Check the constraints for a managed object.

Args:
uid (string): The unique ID of the managed object to check.
Optional, defaults to None.
usage_limits_count (int): The number of items that can be secured
with the specified managed object. Optional, defaults to None.
cryptographic_usage_mask (list): A list of CryptographicUsageMask
enumerations specifying the operations possible with the
specified managed object. Optional, defaults to None.
lease_time (int): The number of seconds that can be leased for the
specified managed object. Optional, defaults to None.


def group(self, group_type=None, owner=None, **kwargs):

        group = None
        if not group_type:
            return Group(self.tcex, None, None, owner=owner, **kwargs)

        name = kwargs.pop('name', None)
        group_type = group_type.upper()
        if group_type == 'ADVERSARY':
            group = Adversary(self.tcex, name, owner=owner, **kwargs)
        if group_type == 'CAMPAIGN':
            group = Campaign(self.tcex, name, owner=owner, **kwargs)
        if group_type == 'DOCUMENT':
            group = Document(self.tcex, name, kwargs.pop('file_name', None), owner=owner, **kwargs)
        if group_type == 'EVENT':
            group = Event(self.tcex, name, owner=owner, **kwargs)
        if group_type == 'EMAIL':
            group = Email(
                self.tcex,
                name,
                kwargs.pop('to', None),
                kwargs.pop('from_addr', None),
                kwargs.pop('subject', None),
                kwargs.pop('body', None),
                kwargs.pop('header', None),
                owner=owner,
                **kwargs
            )
        if group_type == 'INCIDENT':
            group = Incident(self.tcex, name, owner=owner, **kwargs)
        if group_type == 'INTRUSION SET':
            group = IntrusionSet(self.tcex, name, owner=owner, **kwargs)
        if group_type == 'REPORT':
            group = Report(self.tcex, name, owner=owner, **kwargs)
        if group_type == 'SIGNATURE':
            group = Signature(
                self.tcex,
                name,
                kwargs.pop('file_name', None),
                kwargs.pop('file_type', None),
                kwargs.pop('file_text', None),
                owner=owner,
                **kwargs
            )
        if group_type == 'THREAT':
            group = Threat(self.tcex, name, owner=owner, **kwargs)
        if group_type == 'TASK':
            group = Task(
                self.tcex,
                name,
                kwargs.pop('status', 'Not Started'),
                kwargs.pop('due_date', None),
                kwargs.pop('reminder_date', None),
                kwargs.pop('escalation_date', None),
                owner=owner,
                **kwargs
            )
        return group

Create the Group TI object.

Args:
owner:
group_type:
**kwargs:

Return:


async def send_event(self, con, name, payload):
    message = dict(type='event', name=name, payload=payload)
    encoded = pack(message)
    (await con.send(encoded))

Send an event to a client connection.

This method will push an event message to the client with the given
name and payload.  You need to have access to the the ``connection``
object for the client, which is only available once the client has
connected and passed to self.prepare_conn(connection).

Args:
con (websockets.Connection): The connection to use to send
the event.
name (str): The name of the event to send.
payload (object): The msgpack-serializable object so send
as the event's payload.


def create_blocking_connection(host):

    return pika.BlockingConnection(
        amqpdaemon.getConParams(
            settings.get_amqp_settings()[host.lower()]["vhost"]
        )
    )

Return properly created blocking connection.

Args:
host (str): Host as it is defined in :func:`.get_amqp_settings`.

Uses :func:`edeposit.amqp.amqpdaemon.getConParams`.


def get_schema_path(schema, resolved=False):

    def _strip_first_path_elem(path):
        "Pass doctests.\n\n        Strip the first element of the given path, returning an empty string if\n        there are no more elements. For example, 'something/other' will end up\n        as 'other', but  passing then 'other' will return ''\n        "
        stripped_path = path.split(os.path.sep, 1)[1:]
        return ''.join(stripped_path)

    def _schema_to_normalized_path(schema):
        "Pass doctests.\n\n        Extracts the path from the url, makes sure to get rid of any '..' in\n        the path and adds the json extension if not there.\n        "
        path = os.path.normpath((os.path.sep + urlsplit(schema).path))
        if path.startswith(os.path.sep):
            path = path[1:]
        if (not path.endswith('.json')):
            path += '.json'
        return path
    path = _schema_to_normalized_path(schema)
    while path:
        if resolved:
            schema_path = os.path.abspath(os.path.join(_resolved_schema_root_path, path))
        else:
            schema_path = os.path.abspath(os.path.join(_schema_root_path, path))
        if os.path.exists(schema_path):
            return os.path.abspath(schema_path)
        path = _strip_first_path_elem(path)
    raise SchemaNotFound(schema=schema)

Retrieve the installed path for the given schema.

Args:
schema(str): relative or absolute url of the schema to validate, for
example, 'records/authors.json' or 'jobs.json', or just the name of the
schema, like 'jobs'.
resolved(bool): if True, the returned path points to a fully resolved
schema, that is to the schema with all `$ref` replaced by their
targets.

Returns:
str: path to the given schema name.

Raises:
SchemaNotFound: if no schema could be found.


def _add_new_ide_controller_helper(ide_controller_label, controller_key, bus_number):
    if (controller_key is None):
        controller_key = randint((- 200), 250)
    ide_spec = vim.vm.device.VirtualDeviceSpec()
    ide_spec.device = vim.vm.device.VirtualIDEController()
    ide_spec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add
    ide_spec.device.key = controller_key
    ide_spec.device.busNumber = bus_number
    ide_spec.device.deviceInfo = vim.Description()
    ide_spec.device.deviceInfo.label = ide_controller_label
    ide_spec.device.deviceInfo.summary = ide_controller_label
    return ide_spec

Helper function for adding new IDE controllers

.. versionadded:: 2016.3.0

Args:
ide_controller_label: label of the IDE controller
controller_key: if not None, the controller key to use; otherwise it is randomly generated
bus_number: bus number

Returns: created device spec for an IDE controller


def noisy_operation(self, operation: 'cirq.Operation') -> 'cirq.OP_TREE':

        if not hasattr(self.noisy_moments, '_not_overridden'):
            return self.noisy_moments([ops.Moment([operation])],
                                      operation.qubits)

        if not hasattr(self.noisy_moment, '_not_overridden'):
            return self.noisy_moment(ops.Moment([operation]), operation.qubits)

        assert False, 'Should be unreachable.'

Adds noise to an individual operation.

Args:
operation: The operation to make noisy.

Returns:
An OP_TREE corresponding to the noisy operations implementing the
noisy version of the given operation.


def decode_jpeg(image_buffer, scope=None):

  with tf.name_scope(values=[image_buffer], name=scope,
                     default_name='decode_jpeg'):

    image = tf.image.decode_jpeg(image_buffer, channels=3)

    image = tf.image.convert_image_dtype(image, dtype=tf.float32)
    return image

Decode a JPEG string into one 3-D float image Tensor.

Args:
image_buffer: scalar string Tensor.
scope: Optional scope for name_scope.
Returns:
3-D float Tensor with values ranging from [0, 1).


def __init__(self, model, ncats, alpha_lambda=1.0, beta_lambda=2.0,
        freeparams=['alpha_lambda', 'beta_lambda']):

        new_max_beta = DiscreteGamma(self.PARAMLIMITS["alpha_lambda"][1],
                self.PARAMLIMITS["beta_lambda"][0], ncats)[-1]
        new_limits = model.PARAMLIMITS
        new_limits["beta"] = (new_limits["beta"][0], new_max_beta)
        model.PARAMLIMITS = new_limits

        super(GammaDistributedBetaModel, self).__init__(model, "beta",
                ncats, alpha_lambda=1.0, beta_lambda=2.0,
                freeparams=['alpha_lambda', 'beta_lambda'])

        assert all([scipy.allclose(new_max_beta, m.PARAMLIMITS["beta"][1])
                for m in self._models]), ("{0}\n{1}".format(
                new_max_beta, '\n'.join([m.PARAMLIMITS["beta"][1]
                for m in self._models])))

Initialize an `GammaDistributedModel` object.

The `lambda_param` is set to "beta".

Args:
`model` `ncats`,`alpha_lambda`, `beta_lambda`, `freeparams`
Meaning described in main class doc string for
`GammaDistributedModel`.


def run(self, dag):
    num_dag_qubits = sum([qreg.size for qreg in dag.qregs.values()])
    if (num_dag_qubits > self.coupling_map.size()):
        raise TranspilerError('Number of qubits greater than device.')
    best_sub = self._best_subset(num_dag_qubits)
    layout = Layout()
    map_iter = 0
    for qreg in dag.qregs.values():
        for i in range(qreg.size):
            layout[(qreg, i)] = int(best_sub[map_iter])
            map_iter += 1
    self.property_set['layout'] = layout

Pick a convenient layout depending on the best matching
qubit connectivity, and set the property `layout`.

Args:
dag (DAGCircuit): DAG to find layout for.

Raises:
TranspilerError: if dag wider than self.coupling_map


def add_observer(self, callback):

        if callback in self._observers:
            raise ValueError('{} is already an observer of {}'
                             .format(callback, self))
        self._observers.append(callback)

Add an observer to this event.

Args:
callback: A function or coroutine callback to call when the event
is fired.

Raises:
ValueError: If the callback has already been added.


def serialize(self):
    return gen_boosted_trees_ops.boosted_trees_serialize_ensemble(self.resource_handle)

Serializes the ensemble into proto and returns the serialized proto.

Returns:
stamp_token: int64 scalar Tensor to denote the stamp of the resource.
serialized_proto: string scalar Tensor of the serialized proto.


def _expand_to_beam_size(tensor, beam_size):

  tensor = tf.expand_dims(tensor, axis=1)
  tile_dims = [1] * tensor.shape.ndims
  tile_dims[1] = beam_size

  return tf.tile(tensor, tile_dims)

Tiles a given tensor by beam_size.

Args:
tensor: tensor to tile [batch_size, ...]
beam_size: How much to tile the tensor by.

Returns:
Tiled tensor [batch_size, beam_size, ...]


def _text_checker(job, interval, _interval_set=False, quiet=False, output=sys.stdout):

    status = job.status()
    msg = status.value
    prev_msg = msg
    msg_len = len(msg)

    if not quiet:
        print('\r%s: %s' % ('Job Status', msg), end='', file=output)
    while status.name not in ['DONE', 'CANCELLED', 'ERROR']:
        time.sleep(interval)
        status = job.status()
        msg = status.value

        if status.name == 'QUEUED':
            msg += ' (%s)' % job.queue_position()
            if not _interval_set:
                interval = max(job.queue_position(), 2)
        else:
            if not _interval_set:
                interval = 2

        if len(msg) < msg_len:
            msg += ' ' * (msg_len - len(msg))
        elif len(msg) > msg_len:
            msg_len = len(msg)

        if msg != prev_msg and not quiet:
            print('\r%s: %s' % ('Job Status', msg), end='', file=output)
            prev_msg = msg
    if not quiet:
        print('', file=output)

A text-based job status checker

Args:
job (BaseJob): The job to check.
interval (int): The interval at which to check.
_interval_set (bool): Was interval time set by user?
quiet (bool): If True, do not print status messages.
output (file): The file like object to write status messages to.
By default this is sys.stdout.


def format_error_message(exception_message, task_exception=False):
    lines = exception_message.split('\n')
    if task_exception:
        lines = (lines[0:1] + lines[3:])
        pass
    return '\n'.join(lines)

Improve the formatting of an exception thrown by a remote function.

This method takes a traceback from an exception and makes it nicer by
removing a few uninformative lines and adding some space to indent the
remaining lines nicely.

Args:
exception_message (str): A message generated by traceback.format_exc().

Returns:
A string of the formatted exception message.


def double_linked_dom(str_or_dom):

    dom = str_or_dom
    if not isinstance(str_or_dom, dhtmlparser.HTMLElement):
        dom = dhtmlparser.parseString(str_or_dom)

    dhtmlparser.makeDoubleLinked(dom)

    return dom

Create double linked DOM from input.

In case of string, parse it, make it double-linked. In case of DOM, just
make it double-linked.

Args:
str_or_dom (str/HTMLelement): String or HTMLelement instance.

Returns:
obj: HTMLelement with parsed, double-linked content from `str_or_dom`.


def get_logger(name):
    logger = logging.getLogger(name)
    logger.addHandler(logging.NullHandler())
    return logger

Gets a logger

Arguments:
name - the name you wish to log as

Returns:
A logger!


def get_restore_path(self, status=None):

        status = self.get_status() if status is None else status
        return config.get_restore_path(status.name.lower())

get_restore_path: get path to restoration file
Args:
status (str): step to get restore file (optional)
Returns: string path to restoration file


def get_gated_grpc_tensors(self, matching_debug_op=None):
    with self._grpc_gated_lock:
        matching_debug_op = (matching_debug_op or 'DebugIdentity')
        if (matching_debug_op not in self._grpc_gated_tensors):
            node_name_to_op_type = dict(((node.name, node.op) for node in self._graph_def.node))
            gated = []
            for node in self._graph_def.node:
                if (node.op == matching_debug_op):
                    for attr_key in node.attr:
                        if ((attr_key == 'gated_grpc') and node.attr[attr_key].b):
                            (node_name, output_slot, _, debug_op) = debug_graphs.parse_debug_node_name(node.name)
                            gated.append((node_name, node_name_to_op_type[node_name], output_slot, debug_op))
                            break
            self._grpc_gated_tensors[matching_debug_op] = gated
        return self._grpc_gated_tensors[matching_debug_op]

Extract all nodes with gated-gRPC debug ops attached.

Uses cached values if available.
This method is thread-safe.

Args:
graph_def: A tf.GraphDef proto.
matching_debug_op: Return tensors and nodes with only matching the
specified debug op name (optional). If `None`, will extract only
`DebugIdentity` debug ops.

Returns:
A list of (node_name, op_type, output_slot, debug_op) tuples.


def _create_output_from_match(self, match_result):
    if isinstance(match_result, dict):
        return LinterOutput(self.name, **match_result)
    return LinterOutput(self.name, *match_result)

Create Result instance from pattern match results.

Args:
match: Pattern match.


def write_var_int(self, value, little_endian=True):

        if not isinstance(value, int):
            raise SDKException(ErrorCode.param_err('%s not int type.' % value))

        if value < 0:
            raise SDKException(ErrorCode.param_err('%d too small.' % value))

        elif value < 0xfd:
            return self.write_byte(value)

        elif value <= 0xffff:
            self.write_byte(0xfd)
            return self.write_uint16(value, little_endian)

        elif value <= 0xFFFFFFFF:
            self.write_byte(0xfe)
            return self.write_uint32(value, little_endian)

        else:
            self.write_byte(0xff)
            return self.write_uint64(value, little_endian)

Write an integer value in a space saving way to the stream.

Args:
value (int):
little_endian (bool): specify the endianness. (Default) Little endian.

Raises:
SDKException: if `value` is not of type int.
SDKException: if `value` is < 0.

Returns:
int: the number of bytes written.