def upsert(self, insert_index, val, fn=None):
    fn = (fn or (lambda current, passed: passed))
    self._magnitude = 0
    position = self.position_for_index(insert_index)
    if ((position < len(self.elements)) and (self.elements[position] == insert_index)):
        self.elements[(position + 1)] = fn(self.elements[(position + 1)], val)
    else:
        self.elements.insert(position, val)
        self.elements.insert(position, insert_index)

Inserts or updates an existing index within the vector.

Args:
- insert_index (int): The index at which the element should be
inserted.
- val (int|float): The value to be inserted into the vector.
- fn (callable, optional): An optional callable taking two
arguments, the current value and the passed value to generate
the final inserted value at the position in case of collision.


def _to_snake_case(string):

        sub_string = r'\1_\2'
        string = REGEX_CAMEL_FIRST.sub(sub_string, string)
        return REGEX_CAMEL_SECOND.sub(sub_string, string).lower()

Return a snake cased version of the input string.

Args:
string (str): A camel cased string.

Returns:
str: A snake cased string.


def attention_lm_moe_small():
    hparams = attention_lm_moe_base()
    hparams.num_hidden_layers = 4
    hparams.hidden_size = 512
    hparams.filter_size = 2048
    hparams.moe_num_experts = 128
    hparams.moe_layers = '2'
    return hparams

Cheap model for single-gpu training.

on lm1b_32k:
~312M params
1.6 steps/sec on  [GeForce GTX TITAN X]
After 50K steps on 8 GPUs (synchronous):
eval_log_ppl_per_token = 3.31

Returns:
an hparams object.


def execute_edit(args, root_dir=None):

    EDITOR = os.environ.get('EDITOR', 'vim')

    key = args['key']
    status = command_factory('status')({}, root_dir=root_dir)

    if not isinstance(status['data'], str) and key in status['data']:
        if status['data'][key]['status'] in ['queued', 'stashed']:
            command = status['data'][key]['command']
        else:
            print("Entry is not 'queued' or 'stashed'")
            sys.exit(1)
    else:
        print('No entry with this key')
        sys.exit(1)

    with tempfile.NamedTemporaryFile(suffix=".tmp") as tf:
        tf.write(command.encode('utf-8'))
        tf.flush()
        call([EDITOR, tf.name])

        tf.seek(0)
        edited_command = tf.read().decode('utf-8')

    print_command_factory('edit')({
        'key': key,
        'command': edited_command,
    }, root_dir=root_dir)

Edit a existing queue command in the daemon.

Args:
args['key'] int: The key of the queue entry to be edited
root_dir (string): The path to the root directory the daemon is running in.


def _DepthwiseConv2dNativeBackpropInputGrad(op: ops.Operation, grad):
    return [None, gen_nn_ops.depthwise_conv2d_native_backprop_filter(grad, array_ops.shape(op.inputs[1]), op.inputs[2], dilations=op.get_attr('dilations'), strides=op.get_attr('strides'), padding=op.get_attr('padding'), explicit_paddings=op.get_attr('explicit_paddings'), data_format=op.get_attr('data_format')), gen_nn_ops.depthwise_conv2d_native(grad, op.inputs[1], dilations=op.get_attr('dilations'), strides=op.get_attr('strides'), padding=op.get_attr('padding'), explicit_paddings=op.get_attr('explicit_paddings'), data_format=op.get_attr('data_format'))]

The derivatives for deconvolution.

Args:
op: the Deconvolution op.
grad: the tensor representing the gradient w.r.t. the output

Returns:
the gradients w.r.t. the input and the filter


def get_definition(self, stmt: Statement, sctx: SchemaContext) -> Tuple[(Statement, SchemaContext)]:
    if (stmt.keyword == 'uses'):
        kw = 'grouping'
    elif (stmt.keyword == 'type'):
        kw = 'typedef'
    else:
        raise ValueError("not a 'uses' or 'type' statement")
    (loc, did) = self.resolve_pname(stmt.argument, sctx.text_mid)
    if (did == sctx.text_mid):
        dstmt = stmt.get_definition(loc, kw)
        if dstmt:
            return (dstmt, sctx)
    else:
        dstmt = self.modules[did].statement.find1(kw, loc)
        if dstmt:
            return (dstmt, SchemaContext(sctx.schema_data, sctx.default_ns, did))
    for sid in self.modules[did].submodules:
        dstmt = self.modules[sid].statement.find1(kw, loc)
        if dstmt:
            return (dstmt, SchemaContext(sctx.schema_data, sctx.default_ns, sid))
    raise DefinitionNotFound(kw, stmt.argument)

Find the statement defining a grouping or derived type.

Args:
stmt: YANG "uses" or "type" statement.
sctx: Schema context where the definition is used.

Returns:
A tuple consisting of the definition statement ('grouping' or
'typedef') and schema context of the definition.

Raises:
ValueError: If `stmt` is neither "uses" nor "type" statement.
ModuleNotRegistered: If `mid` is not registered in the data model.
UnknownPrefix: If the prefix specified in the argument of `stmt`
is not declared.
DefinitionNotFound: If the corresponding definition is not found.


def get_windows_if_list(extended=False):

    def _get_mac(x):
        size = x["physical_address_length"]
        if size != 6:
            return ""
        data = bytearray(x["physical_address"])
        return str2mac(bytes(data)[:size])

    def _get_ips(x):
        unicast = x['first_unicast_address']
        anycast = x['first_anycast_address']
        multicast = x['first_multicast_address']

        def _resolve_ips(y):
            if not isinstance(y, list):
                return []
            ips = []
            for ip in y:
                addr = ip['address']['address'].contents
                if addr.si_family == socket.AF_INET6:
                    ip_key = "Ipv6"
                    si_key = "sin6_addr"
                else:
                    ip_key = "Ipv4"
                    si_key = "sin_addr"
                data = getattr(addr, ip_key)
                data = getattr(data, si_key)
                data = bytes(bytearray(data.byte))

                if data:
                    ips.append(inet_ntop(addr.si_family, data))
            return ips

        ips = []
        ips.extend(_resolve_ips(unicast))
        if extended:
            ips.extend(_resolve_ips(anycast))
            ips.extend(_resolve_ips(multicast))
        return ips

    if six.PY2:
        _str_decode = lambda x: x.encode('utf8', errors='ignore')
    else:
        _str_decode = plain_str
    return [
        {
            "name": _str_decode(x["friendly_name"]),
            "win_index": x["interface_index"],
            "description": _str_decode(x["description"]),
            "guid": _str_decode(x["adapter_name"]),
            "mac": _get_mac(x),
            "ipv4_metric": 0 if WINDOWS_XP else x["ipv4_metric"],
            "ipv6_metric": 0 if WINDOWS_XP else x["ipv6_metric"],
            "ips": _get_ips(x)
        } for x in GetAdaptersAddresses()
    ]

Returns windows interfaces through GetAdaptersAddresses.

params:
- extended: include anycast and multicast IPv6 (default False)


def _print_reference(self, reference: message.Message) -> None:
    set_oneof = reference.WhichOneof('reference')
    if self.json_format == _FhirJsonFormat.PURE and set_oneof is not None and (set_oneof != 'uri'):
        standardized_reference = copy.copy(reference)
        new_uri = proto_utils.get_value_at_field(standardized_reference, 'uri')
        proto_utils.set_value_at_field(new_uri, 'value', references.reference_to_string(reference))
        self._print_message(standardized_reference)
    else:
        self._print_message(reference)

Standardizes and prints the provided reference.

Note that "standardization" in the case of PURE FHIR JSON refers to
un-typing the typed-reference prior to printing.

Args:
reference: The reference to print.


def handle(self, connection_id, message_content):

        try:
            request = self._request_proto()
            request.ParseFromString(message_content)
        except DecodeError:
            LOGGER.info('Protobuf %s failed to deserialize', request)
            return self._wrap_result(self._status.INTERNAL_ERROR)

        try:
            response = self._respond(request)
        except _ResponseFailed as e:
            response = e.status

        return self._wrap_result(response)

Handles parsing incoming requests, and wrapping the final response.

Args:
connection_id (str): ZMQ identity sent over ZMQ socket
message_content (bytes): Byte encoded request protobuf to be parsed

Returns:
HandlerResult: result to be sent in response back to client


def _add_value_to_extension(msg: message.Message, extension: message.Message, is_choice_type: bool) -> None:
    if is_choice_type:
        oneofs = msg.DESCRIPTOR.oneofs
        if not oneofs:
            raise fhir_errors.InvalidFhirError(f'Choice type is missing a oneof: {msg.DESCRIPTOR.full_name}')
        value_field_name = msg.WhichOneof(oneofs[0].name)
        if value_field_name is None:
            raise ValueError(f'Choice type has no value set: {msg.DESCRIPTOR.full_name}')
        value_field = msg.DESCRIPTOR.fields_by_name[value_field_name]
        _verify_field_is_proto_message_type(value_field)
        _add_value_to_extension(proto_utils.get_value_at_field(msg, value_field), extension, False)
    else:
        value_field_mapping = _get_value_field_mapping_for_extension(extension)
        value_field = value_field_mapping.get(msg.DESCRIPTOR.full_name)
        if value_field is not None:
            proto_utils.set_value_at_field(cast(Any, extension).value, cast(Any, value_field), msg)
        elif annotation_utils.has_fhir_valueset_url(msg):
            codes.copy_code(msg, cast(Any, extension).value.code)
        elif fhir_types.is_type_or_profile_of_coding(msg):
            codes.copy_coding(msg, cast(Any, extension).value.coding)
        else:
            _add_fields_to_extension(msg, extension)

Adds the fields from msg to a generic Extension.

Attempts are first made to set the "value" field of the generic Extension
based on the type of field set on message. If this fails, checks are made
against the generic Code and Coding types, and finally we fall back to adding
the message's fields as sub-extensions.

Args:
msg: The message whose values to add to extension.
extension: The generic Extension to populate.
is_choice_type: Whether or not the provided message represents a "choice"
type.


def make_time(h=0, m=0, s=0, ms=0, frames=None, fps=None):
    if ((frames is None) and (fps is None)):
        return times_to_ms(h, m, s, ms)
    elif ((frames is not None) and (fps is not None)):
        return frames_to_ms(frames, fps)
    else:
        raise ValueError('Both fps and frames must be specified')

Convert time to milliseconds.

See :func:`pysubs2.time.times_to_ms()`. When both frames and fps are specified,
:func:`pysubs2.time.frames_to_ms()` is called instead.

Raises:
ValueError: Invalid fps, or one of frames/fps is missing.

Example:
>>> make_time(s=1.5)
1500
>>> make_time(frames=50, fps=25)
2000


def has_atomic_move(path):
    try:
        return _pywrap_file_io.HasAtomicMove(compat.path_to_bytes(path))
    except errors.OpError:
        return True

Checks whether the file system supports atomic moves.

Returns whether or not the file system of the given path supports the atomic
move operation for a file or folder.  If atomic move is supported, it is
recommended to use a temp location for writing and then move to the final
location.

Args:
path: string, path to a file

Returns:
True, if the path is on a file system that supports atomic move
False, if the file system does not support atomic move. In such cases
we need to be careful about using moves. In some cases it is safer
not to use temporary locations in this case.


def diff_text1(self, diffs):

    text = []
    for (op, data) in diffs:
      if op != self.DIFF_INSERT:
        text.append(data)
    return "".join(text)

Compute and return the source text (all equalities and deletions).

Args:
diffs: Array of diff tuples.

Returns:
Source text.


def setup_engines(client=None):

    if not client:
        try:
            client = ipyparallel.Client()
        except:
            raise DistobClusterError(
                u)
    eids = client.ids
    if not eids:
        raise DistobClusterError(
                u'No ipyparallel compute engines are available')
    nengines = len(eids)
    dv = client[eids]
    dv.use_dill()
    with dv.sync_imports(quiet=True):
        import distob

    ars = []
    for i in eids:
        dv.targets = i
        ars.append(dv.apply_async(_remote_setup_engine, i, nengines))
    dv.wait(ars)
    for ar in ars:
        if not ar.successful():
            raise ar.r

    if distob.engine is None:
        distob.engine = ObjectHub(-1, client)

Prepare all iPython engines for distributed object processing.

Args:
client (ipyparallel.Client, optional): If None, will create a client
using the default ipyparallel profile.


def get_atlas_per_gene_mutation_df(self, gene_id):

        g = self.reference_gempro.genes.get_by_id(gene_id)

        single, fingerprint = g.protein.sequence_mutation_summary(alignment_type='seqalign')

        structure_type_suffix = 'NA'
        appender = []

        for k, strains in single.items():

            to_append = {}
            orig_res = k[0]
            resnum = int(k[1])
            mutated_res = k[2]
            num_strains_mutated = len(strains)
            strain_ids = [str(x.split(g.id + '_')[1]) for x in strains]
            to_append['ref_residue'] = orig_res
            to_append['ref_resnum'] = resnum
            to_append['strain_residue'] = mutated_res
            to_append['num_strains_mutated'] = num_strains_mutated
            to_append['strains_mutated'] = ';'.join(strain_ids)
            to_append['at_disulfide_bridge'] = False

            origres_props = ssbio.protein.sequence.properties.residues.residue_biochemical_definition(orig_res)
            mutres_props = ssbio.protein.sequence.properties.residues.residue_biochemical_definition(mutated_res)
            to_append['ref_residue_prop'] = origres_props
            to_append['strain_residue_prop'] = mutres_props

            grantham_s, grantham_txt = ssbio.protein.sequence.properties.residues.grantham_score(orig_res, mutated_res)
            to_append['grantham_score'] = grantham_s
            to_append['grantham_annotation'] = grantham_txt

            to_append.update(g.protein.get_residue_annotations(seq_resnum=resnum, use_representatives=True))

            if g.protein.representative_structure:
                if g.protein.representative_structure.is_experimental:
                    to_append['structure_type'] = 'EXP'
                else:
                    to_append['structure_type'] = 'HOM'

                repchain = g.protein.representative_chain
                repchain_annotations = g.protein.representative_structure.chains.get_by_id(repchain).seq_record.annotations
                if 'SSBOND-biopython' in repchain_annotations:
                    structure_resnum = g.protein.map_seqprop_resnums_to_structprop_resnums(resnums=resnum,
                                                                                use_representatives=True)
                    if resnum in structure_resnum:
                        ssbonds = repchain_annotations['SSBOND-biopython']
                        ssbonds_res = []
                        for x in ssbonds:
                            ssbonds_res.append(x[0])
                            ssbonds_res.append(x[1])

                        if structure_resnum in ssbonds_res:
                            to_append['at_disulfide_bridge'] = True

            appender.append(to_append)

        if not appender:
            return pd.DataFrame()

        cols = ['ref_residue', 'ref_resnum', 'strain_residue', 'num_strains_mutated', 'strains_mutated',
                'ref_residue_prop', 'strain_residue_prop', 'grantham_score', 'grantham_annotation',
                'at_disulfide_bridge',
                'seq_SS-sspro', 'seq_SS-sspro8', 'seq_RSA-accpro', 'seq_RSA-accpro20', 'seq_TM-tmhmm',
                'struct_SS-dssp', 'struct_RSA-dssp', 'struct_ASA-dssp',
                'struct_CA_DEPTH-msms', 'struct_RES_DEPTH-msms',
                'struct_PHI-dssp', 'struct_PSI-dssp',
                'struct_resnum', 'struct_residue'
                'strains_mutated']

        df_gene_summary = pd.DataFrame.from_records(appender, columns=cols)

        df_gene_summary.dropna(axis=1, how='all', inplace=True)

        df_gene_summary.sort_values(by='ref_resnum', inplace=True)
        df_gene_summary = df_gene_summary.set_index('ref_resnum')
        return df_gene_summary

Create a single data frame which summarizes a gene and its mutations.

Args:
gene_id (str): Gene ID in the base model

Returns:
DataFrame: Pandas DataFrame of the results


def loop_until_timeout_or_true(timeout_s, function, sleep_s=1):
    return loop_until_timeout_or_valid(timeout_s, function, (lambda x: x), sleep_s)

Loops until the specified function returns True or a timeout is reached.

Note: The function may return anything which evaluates to implicit True.  This
function will loop calling it as long as it continues to return something
which evaluates to False.  We ensure this method is called at least once
regardless of timeout.

Args:
timeout_s: The number of seconds to wait until a timeout condition is
reached. As a convenience, this accepts None to mean never timeout.  Can
also be passed a PolledTimeout object instead of an integer.
function: The function to call each iteration.
sleep_s: The number of seconds to wait after calling the function.

Returns:
Whatever the function returned last.


def import_laid_out_tensor(mesh, laid_out_tensor, shape, name=None):
    return ImportLaidOutTensorOperation(mesh, laid_out_tensor, convert_to_shape(shape), name=name).outputs[0]

Import a laid_out_tensor.

For expert users.
The input must be laid out appropriately given the eventual MeshImpl,
and layout.

Args:
mesh: a Mesh
laid_out_tensor: a LaidOutTensor
shape: a mtf.Shape
name: an optional string

Returns:
a mtf.Tensor


def content_ratings(self, **kwargs):
    path = self._get_id_path('content_ratings')
    response = self._GET(path, kwargs)
    self._set_attrs_to_values(response)
    return response

Get the content ratings for a TV Series.

Args:
language: (optional) ISO 639 code.
append_to_response: (optional) Comma separated, any collection
method.

Returns:
A dict respresentation of the JSON returned from the API.


def create_output_excerpts(self, test_info):
    dest_path = test_info.output_path
    utils.create_dir(dest_path)
    filename = self._ad.generate_filename(self.OUTPUT_FILE_TYPE, test_info, 'txt')
    excerpt_file_path = os.path.join(dest_path, filename)
    with open(excerpt_file_path, 'w', encoding='utf-8', errors='replace', newline='') as out:
        while self._adb_logcat_file_obj:
            line = self._adb_logcat_file_obj.readline()
            if not line:
                break
            out.write(line)
    self._ad.log.debug('logcat excerpt created at: %s', excerpt_file_path)
    return [excerpt_file_path]

Convenient method for creating excerpts of adb logcat.

This copies logcat lines from self.adb_logcat_file_path to an excerpt
file, starting from the location where the previous excerpt ended.

Call this method at the end of: `setup_class`, `teardown_test`, and
`teardown_class`.

Args:
test_info: `self.current_test_info` in a Mobly test.

Returns:
List of strings, the absolute paths to excerpt files.


def set(self, name, value):

        if name not in self._options:

            self.register(name, self._generator())

        return self._options[name].__set__(self, value)

Set an option value.

Args:
name (str): The name of the option.
value: The value to set the option to.

Raises:
TypeError: If the value is not a string or appropriate native type.
ValueError: If the value is a string but cannot be coerced.

If the name is not registered a new option will be created using the
option generator.


def assign_sub(self, delta, use_locking=False, name=None, read_value=True):
    raise NotImplementedError

Subtracts a value from this variable.

This is essentially a shortcut for `assign_sub(self, delta)`.

Args:
delta: A `Tensor`. The value to subtract from this variable.
use_locking: If `True`, use locking during the operation.
name: The name of the operation to be created
read_value: if True, will return something which evaluates to the new
value of the variable; if False will return the assign op.

Returns:
The updated variable. If `read_value` is false, instead returns None in
Eager mode and the assign op in graph mode.


def all_pairs(sets, similarity_func_name='jaccard', similarity_threshold=0.5):
    if ((not isinstance(sets, list)) or (len(sets) == 0)):
        raise ValueError('Input parameter sets must be a non-empty list.')
    if (similarity_func_name not in _similarity_funcs):
        raise ValueError('Similarity function {} is not supported.'.format(similarity_func_name))
    if ((similarity_threshold < 0) or (similarity_threshold > 1.0)):
        raise ValueError('Similarity threshold must be in the range [0, 1].')
    if (similarity_func_name not in _symmetric_similarity_funcs):
        raise ValueError('The similarity function must be symmetric ({})'.format(', '.join(_symmetric_similarity_funcs)))
    similarity_func = _similarity_funcs[similarity_func_name]
    overlap_threshold_func = _overlap_threshold_funcs[similarity_func_name]
    position_filter_func = _position_filter_funcs[similarity_func_name]
    (sets, _) = _frequency_order_transform(sets)
    index = defaultdict(list)
    logging.debug('Find all pairs with similarities >= {}...'.format(similarity_threshold))
    count = 0
    for x1 in np.argsort([len(s) for s in sets]):
        s1 = sets[x1]
        t = overlap_threshold_func(len(s1), similarity_threshold)
        prefix_size = ((len(s1) - t) + 1)
        prefix = s1[:prefix_size]
        candidates = set([x2 for (p1, token) in enumerate(prefix) for (x2, p2) in index[token] if position_filter_func(s1, sets[x2], p1, p2, similarity_threshold)])
        for x2 in candidates:
            s2 = sets[x2]
            sim = similarity_func(s1, s2)
            if (sim < similarity_threshold):
                continue
            (yield tuple((sorted([x1, x2], reverse=True) + [sim])))
            count += 1
        for (j, token) in enumerate(prefix):
            index[token].append((x1, j))
    logging.debug('{} pairs found.'.format(count))

Find all pairs of sets with similarity greater than a threshold.
This is an implementation of the All-Pair-Binary algorithm in the paper
"Scaling Up All Pairs Similarity Search" by Bayardo et al., with
position filter enhancement.

Args:
sets (list): a list of sets, each entry is an iterable representing a
set.
similarity_func_name (str): the name of the similarity function used;
this function currently supports `"jaccard"` and `"cosine"`.
similarity_threshold (float): the threshold used, must be a float
between 0 and 1.0.

Returns:
pairs (Iterator[tuple]): an iterator of tuples `(x, y, similarity)`
where `x` and `y` are the indices of sets in the input list `sets`.


def size(x):
    if any_symbolic_tensors((x,)):
        return Size().symbolic_call(x)
    return backend.numpy.size(x)

Return the number of elements in a tensor.

Args:
x: Input tensor.

Returns:
Number of elements in `x`.


def GetSubkeyByName(self, name):

    pyregf_key = self._pyregf_key.get_sub_key_by_name(name)
    if not pyregf_key:
      return None

    key_path = key_paths.JoinKeyPath([self._key_path, pyregf_key.name])
    return REGFWinRegistryKey(pyregf_key, key_path=key_path)

Retrieves a subkey by name.

Args:
name (str): name of the subkey.

Returns:
WinRegistryKey: Windows Registry subkey or None if not found.


def topological_sort_operations(operations):
    in_degrees = collections.OrderedDict()
    for op in reversed(operations):
        if op not in in_degrees:
            in_degrees[op] = 0
        for next_op in reversed(_op_dependencies(op)):
            in_degrees[next_op] = in_degrees.get(next_op, 0) + 1
    nexts = []
    for op, in_degree in in_degrees.items():
        if in_degree == 0:
            nexts.append(op)
    order = {}
    next_order = 0
    while nexts:
        op, nexts = (nexts[0], nexts[1:])
        order[op] = next_order
        next_order += 1
        for next_op in reversed(_op_dependencies(op)):
            in_degrees[next_op] -= 1
            if in_degrees[next_op] == 0:
                nexts.append(next_op)
    assert len(order) == len(operations)
    return order

Topological sorts a list of operations.

This does a topological sort of the operations in a graph. The edges include
both data dependencies and control dependencies. Note that the edge goes from
an operation to its dependencies.

The sort is intentionally unstable, reversing orders of operations and
dependencies on ties.

Args:
operations: a list of tf.Operation in the same graph.

Returns:
A map from a tf.Operation to its topological order.


def _record_local(self, node, op, name, typ, orig_val=None, final=None):
    if orig_val:
        self.current_local_ops.append(LocalOp(name, LocalOp.Op.ASSIGN))
    if typ:
        self.current_local_ops.append(LocalOp(name, LocalOp.Op.ANNOTATE))
    self._update_annotations_dict(node, op, name, typ, orig_val, self.current_annotated_locals, final=final)

Record a type annotation on a local variable.

This method records three types of local operations:
- An annotation, e.g., `x: int`. In this case, `typ` is PyTDClass(int) and
`orig_val` is None.
- An assignment, e.g., `x = 0`. In this case, `typ` is None and `orig_val`
is Instance(int).
- An annotated assignment, e.g., `x: int = None`. In this case, `typ` is
PyTDClass(int) and `orig_val` is Instance(None).

Args:
node: The current node.
op: The current opcode.
name: The variable name.
typ: The annotation.
orig_val: The original value, if any.
final: Whether the annotation is tagged Final (None to preserve any
existing Final tag when updating an existing annotation).


def queryize(terms, exclude_screen_name=None):

    ors = ' OR '.join('"{}"'.format(x) for x in terms if not x.startswith('-'))
    nots = ' '.join('-"{}"'.format(x[1:]) for x in terms if x.startswith('-'))
    sn = "-from:{}".format(exclude_screen_name) if exclude_screen_name else ''
    return ' '.join((ors, nots, sn))

Create query from list of terms, using OR
but intelligently excluding terms beginning with '-' (Twitter's NOT operator).
Optionally add -from:exclude_screen_name.

>>> helpers.queryize(['apple', 'orange', '-peach'])
u'apple OR orange -peach'

Args:
terms (list): Search terms.
exclude_screen_name (str): A single screen name to exclude from the search.

Returns:
A string ready to be passed to tweepy.API.search


def addSearchers(self, *searchers):

        self._searchers.extend(searchers)

        debug.logger & debug.flagCompiler and debug.logger(
            'current compiled MIBs location(s): %s' % ', '.join([str(x) for x in self._searchers]))

        return self

Add more transformed MIBs repositories.

MibCompiler.compile will invoke each of configured searcher objects
in order of their addition asking each if already transformed MIB
module already exists and is more recent than specified.

Args:
searchers: searcher object(s)

Returns:
reference to itself (can be used for call chaining)


def get(self,identity,params=None, headers=None):

        path = self._sub_url_params('/creditor_bank_accounts/:identity', {

            'identity': identity,
          })

        response = self._perform_request('GET', path, params, headers,
                                         retry_failures=True)
        return self._resource_for(response)

Get a single creditor bank account.

Retrieves the details of an existing creditor bank account.

Args:
identity (string): Unique identifier, beginning with "BA".
params (dict, optional): Query string parameters.

Returns:
ListResponse of CreditorBankAccount instances


def stage_tc_indicator_entity(self, indicator_data):
    path = '@.{value: summary, '
    path += 'type: type, '
    path += 'ownerName: ownerName, '
    path += 'confidence: confidence || `0`, '
    path += 'rating: rating || `0`}'
    return self.path_data(indicator_data, path)

Convert JSON data to TCEntity.

Args:
indicator_data (str): [description]

Returns:
[type]: [description]


def correct_structure(self, atol=1e-08):
    return np.allclose(self.structure.lattice.matrix, self.prim.lattice.matrix, atol=atol)

Determine if the structure matches the standard primitive structure.

The standard primitive will be different between seekpath and pymatgen
high-symmetry paths, but this is handled by the specific subclasses.

Args:
atol (:obj:`float`, optional): Absolute tolerance used to compare
the input structure with the primitive standard structure.

Returns:
bool: ``True`` if the structure is the same as the standard
primitive, otherwise ``False``.


def _OpenParentFile(self, file_system, path_spec, vhdi_file):
    location = getattr(path_spec, 'location', None)
    if (not location):
        raise errors.PathSpecError('Unsupported path specification without location.')
    location_path_segments = file_system.SplitPath(location)
    parent_filename = vhdi_file.parent_filename
    (_, _, parent_filename) = parent_filename.rpartition('\\')
    location_path_segments.pop()
    location_path_segments.append(parent_filename)
    parent_file_location = file_system.JoinPath(location_path_segments)
    kwargs = path_spec_factory.Factory.GetProperties(path_spec)
    kwargs['location'] = parent_file_location
    if (path_spec.parent is not None):
        kwargs['parent'] = path_spec.parent
    parent_file_path_spec = path_spec_factory.Factory.NewPathSpec(path_spec.type_indicator, **kwargs)
    if (not file_system.FileEntryExistsByPathSpec(parent_file_path_spec)):
        return
    file_object = resolver.Resolver.OpenFileObject(parent_file_path_spec, resolver_context=self._resolver_context)
    vhdi_parent_file = pyvhdi.file()
    vhdi_parent_file.open_file_object(file_object)
    if vhdi_parent_file.parent_identifier:
        self._OpenParentFile(file_system, parent_file_path_spec, vhdi_parent_file)
    vhdi_file.set_parent(vhdi_parent_file)
    self._parent_vhdi_files.append(vhdi_parent_file)
    self._sub_file_objects.append(file_object)

Opens the parent file.

Args:
file_system (FileSystem): file system of the VHDI file.
path_spec (PathSpec): path specification of the VHDI file.
vhdi_file (pyvhdi.file): VHDI file.

Raises:
PathSpecError: if the path specification is incorrect.


def update_mapping(mapping: Dict[ops.Qid, LogicalIndex],
                   operations: ops.OP_TREE
                   ) -> None:

    for op in ops.flatten_op_tree(operations):
        if (isinstance(op, ops.GateOperation) and
            isinstance(op.gate, PermutationGate)):
            op.gate.update_mapping(mapping, op.qubits)

Updates a mapping (in place) from qubits to logical indices according to
a set of permutation gates. Any gates other than permutation gates are
ignored.

Args:
mapping: The mapping to update.
operations: The operations to update according to.


def chat(self, id):
    json = self.skype.conn('GET', '{0}/users/ME/conversations/{1}'.format(self.skype.conn.msgsHost, id), auth=SkypeConnection.Auth.RegToken, params={'view': 'msnp24Equivalent'}).json()
    cls = SkypeSingleChat
    if ('threadProperties' in json):
        info = self.skype.conn('GET', '{0}/threads/{1}'.format(self.skype.conn.msgsHost, json.get('id')), auth=SkypeConnection.Auth.RegToken, params={'view': 'msnp24Equivalent'}).json()
        json.update(info)
        cls = SkypeGroupChat
    return self.merge(cls.fromRaw(self.skype, json))

Get a single conversation by identifier.

Args:
id (str): single or group chat identifier


def set_vrf(self, name, vrf, default=False, disable=False):
    commands = [('interface %s' % name)]
    commands.append(self.command_builder('vrf forwarding', vrf, default=default, disable=disable))
    return self.configure(commands)

Applies a VRF to the interface

Note: VRF being applied to interface must already exist in switch
config. Ethernet port must be in routed mode. This functionality
can also be handled in the VRF api.

Args:
name (str): The interface identifier.  It must be a full
interface name (ie Ethernet, not Et)
vrf (str): The vrf name to be applied to the interface
default (bool): Specifies the default value for VRF
disable (bool): Specifies to disable VRF

Returns:
True if the operation succeeds otherwise False is returned


def generate(self, model, outfolder, *, exclude=None):

        with pythonic_names():
            super().generate(model, outfolder)

            check_dependency = self.with_dependencies and model.eResource
            if check_dependency:
                if exclude is None:
                    exclude = set()
                resource = model.eResource

                exclude.add(resource)
                rset = resource.resource_set
                direct_resources = {r for r in rset.resources.values() if r not in exclude}
                for resource in direct_resources:
                    self.generate(resource.contents[0], outfolder, exclude=exclude)

Generate model code.

Args:
model: The meta-model to generate code for.
outfolder: Path to the directoty that will contain the generated code.
exclude: List of referenced resources for which code was already generated
(to prevent regeneration).


def save_to_text_file(monsoon_data, file_path):
    if (not monsoon_data):
        raise MonsoonError('Attempting to write empty Monsoon data to file, abort')
    utils.create_dir(os.path.dirname(file_path))
    with io.open(file_path, 'w', encoding='utf-8') as f:
        for md in monsoon_data:
            f.write(str(md))
            f.write(MonsoonData.delimiter)

Save multiple MonsoonData objects to a text file.

Args:
monsoon_data: A list of MonsoonData objects to write to a text
file.
file_path: The full path of the file to save to, including the file
name.


def should_stop(self):
    return self._coord.should_stop()

Check if the coordinator was told to stop.

See `Coordinator.should_stop()`.

Returns:
True if the coordinator was told to stop, False otherwise.


def VerifyRow(self, parser_mediator, row):

    if len(row) < self.MIN_COLUMNS:
      return False

    try:
      timestamp = self._ConvertToTimestamp(row['date'], row['time'])
    except (ValueError, TypeError):
      return False

    if timestamp is None:
      return False

    try:
      action = int(row['action'], 10)
    except (ValueError, TypeError):
      return False

    if action not in formatter.SCAN_RESULTS:
      return False
    return True

Verifies if a line of the file is in the expected format.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
row (dict[str, str]): fields of a single row, as specified in COLUMNS.

Returns:
bool: True if this is the correct parser, False otherwise.


def from_monitoring_infos(monitoring_info_list, user_metrics_only=False):
    counters = {}
    distributions = {}
    gauges = {}
    string_sets = {}
    bounded_tries = {}
    for mi in monitoring_info_list:
        if user_metrics_only and (not monitoring_infos.is_user_monitoring_info(mi)):
            continue
        try:
            key = _create_metric_key(mi)
        except ValueError as e:
            _LOGGER.debug(str(e))
            continue
        metric_result = monitoring_infos.extract_metric_result_map_value(mi)
        if monitoring_infos.is_counter(mi):
            counters[key] = metric_result
        elif monitoring_infos.is_distribution(mi):
            distributions[key] = metric_result
        elif monitoring_infos.is_gauge(mi):
            gauges[key] = metric_result
        elif monitoring_infos.is_string_set(mi):
            string_sets[key] = metric_result
        elif monitoring_infos.is_bounded_trie(mi):
            bounded_tries[key] = metric_result
    return (counters, distributions, gauges, string_sets, bounded_tries)

Groups MonitoringInfo objects into counters, distributions, gauges and
string sets

Args:
monitoring_info_list: An iterable of MonitoringInfo objects.
user_metrics_only: If true, includes user metrics only.
Returns:
A tuple containing three dictionaries: counters, distributions, gauges and
string set, respectively. Each dictionary contains (MetricKey, metric
result) pairs.


def rank(self, **kwargs):
    axis = kwargs.get('axis', 0)
    numeric_only = (True if axis else kwargs.get('numeric_only', False))
    func = self._prepare_method(pandas.DataFrame.rank, **kwargs)
    new_data = self._map_across_full_axis(axis, func)
    if numeric_only:
        new_columns = self.compute_index(1, new_data, True)
    else:
        new_columns = self.columns
    new_dtypes = pandas.Series([np.float64 for _ in new_columns], index=new_columns)
    return self.__constructor__(new_data, self.index, new_columns, new_dtypes)

Computes numerical rank along axis. Equal values are set to the average.

Returns:
DataManager containing the ranks of the values along an axis.


def TryConsume(self, token):
    if (self.token == token):
        self.NextToken()
        return True
    return False

Tries to consume a given piece of text.

Args:
token: Text to consume.

Returns:
True iff the text was consumed.


def __recognize_list(self, node: yaml.Node, expected_type: Type) -> RecResult:
    logger.debug('Recognizing as a list')
    if (not isinstance(node, yaml.SequenceNode)):
        message = '{}{}Expected a list here.'.format(node.start_mark, os.linesep)
        return ([], message)
    item_type = generic_type_args(expected_type)[0]
    for item in node.value:
        (recognized_types, message) = self.recognize(item, item_type)
        if (len(recognized_types) == 0):
            return ([], message)
        if (len(recognized_types) > 1):
            recognized_types = [List[t] for t in recognized_types]
            return (recognized_types, message)
    return ([expected_type], '')

Recognize a node that we expect to be a list of some kind.

Args:
node: The node to recognize.
expected_type: List[...something...]

Returns
expected_type and the empty string if it was recognized,
[] and an error message otherwise.


def __init__(self, output_path):
    self._output_path = output_path
    self._profile = cProfile.Profile() if self._output_path else None

Initialize.

Args:
output_path: A pathname for the profiler output.  An empty string
indicates that no profiling should be done.


def _to_numpy(a):
    if isinstance(a, ops.EagerTensor):
        return a.numpy()
    if isinstance(a, tensor.Tensor):
        sess = ops.get_default_session()
        return sess.run(a)
    if isinstance(a, indexed_slices.IndexedSlicesValue):
        arr = np.zeros(a.dense_shape)
        assert len(a.values) == len(a.indices), 'IndexedSlicesValue has %s value slices but %s indices\n%s' % (a.values, a.indices, a)
        for values_slice, index in zip(a.values, a.indices):
            assert 0 <= index < len(arr), 'IndexedSlicesValue has invalid index %s\n%s' % (index, a)
            arr[index] += values_slice
        return arr
    return a

Converts Tensors, EagerTensors, and IndexedSlicesValue to numpy arrays.

Args:
a: any value.

Returns:
If a is EagerTensor or Tensor, returns the evaluation of a by calling
numpy() or run(). If a is IndexedSlicesValue, constructs the corresponding
dense numpy array. Otherwise returns a unchanged.


def StartProfiling(self, configuration, identifier):

    if not configuration:
      return

    if configuration.HaveProfileTasks():
      self._tasks_profiler = profilers.TasksProfiler(identifier, configuration)
      self._tasks_profiler.Start()

Starts profiling.

Args:
configuration (ProfilingConfiguration): profiling configuration.
identifier (str): identifier of the profiling session used to create
the sample filename.


def get_geno_marker(self, marker, return_index=False):

        if self._mode != "r":
            raise UnsupportedOperation("not available in 'w' mode")

        if marker not in self._bim.index:
            raise ValueError("{}: marker not in BIM".format(marker))

        seek_index = self._bim.loc[marker, "i"]
        self.seek(seek_index)

        if return_index:
            return self._read_current_marker(), seek_index
        return self._read_current_marker()

Gets the genotypes for a given marker.

Args:
marker (str): The name of the marker.
return_index (bool): Wether to return the marker's index or not.

Returns:
numpy.ndarray: The genotypes of the marker (additive format).


def get_void_volume_surfarea(structure, rad_dict=None, chan_rad=0.3, probe_rad=0.1):
    with ScratchDir('.'):
        name = 'temp_zeo'
        zeo_inp_filename = (name + '.cssr')
        ZeoCssr(structure).write_file(zeo_inp_filename)
        rad_file = None
        if rad_dict:
            rad_file = (name + '.rad')
            with open(rad_file, 'w') as fp:
                for el in rad_dict.keys():
                    fp.write('{0}     {1}'.format(el, rad_dict[el]))
        atmnet = AtomNetwork.read_from_CSSR(zeo_inp_filename, True, rad_file)
        vol_str = volume(atmnet, 0.3, probe_rad, 10000)
        sa_str = surface_area(atmnet, 0.3, probe_rad, 10000)
        vol = None
        sa = None
        for line in vol_str.split('\n'):
            if ('Number_of_pockets' in line):
                fields = line.split()
                if (float(fields[1]) > 1):
                    vol = (- 1.0)
                    break
                if (float(fields[1]) == 0):
                    vol = (- 1.0)
                    break
                vol = float(fields[3])
        for line in sa_str.split('\n'):
            if ('Number_of_pockets' in line):
                fields = line.split()
                if (float(fields[1]) > 1):
                    sa = (- 1.0)
                    break
                if (float(fields[1]) == 0):
                    sa = (- 1.0)
                    break
                sa = float(fields[3])
    if ((not vol) or (not sa)):
        raise ValueError('Error in zeo++ output stream')
    return (vol, sa)

Computes the volume and surface area of isolated void using Zeo++.
Useful to compute the volume and surface area of vacant site.

Args:
structure: pymatgen Structure containing vacancy
rad_dict(optional): Dictionary with short name of elements and their
radii.
chan_rad(optional): Minimum channel Radius.
probe_rad(optional): Probe radius for Monte Carlo sampling.

Returns:
volume: floating number representing the volume of void


def equals(self, actual_seq):

    try:
      expected = dict([(element, None) for element in self._expected_seq])
      actual = dict([(element, None) for element in actual_seq])
    except TypeError:

      expected = list(self._expected_seq)
      actual = list(actual_seq)
      expected.sort()
      actual.sort()
    return expected == actual

Check to see whether actual_seq has same elements as expected_seq.

Args:
actual_seq: sequence

Returns:
bool


def call(self, inputs):
    net = self.encoder_net(tf.cast(inputs, tf.float32))
    return ed.MultivariateNormalDiag(loc=net[(..., :self.latent_size)], scale_diag=tf.nn.softplus(net[(..., self.latent_size:)]), name='latent_code_posterior')

Runs the model forward to return a stochastic encoding.

Args:
inputs: Tensor of shape [1, num_productions, num_production_rules]. It is
a sequence of productions of length `num_productions`. Each production
is a one-hot vector of length `num_production_rules`: it determines
which production rule the production corresponds to.

Returns:
latent_code_posterior: A random variable capturing a sample from the
variational distribution, of shape [1, self.latent_size].


def broadcast_change():
    (_, res) = win32gui.SendMessageTimeout(win32con.HWND_BROADCAST, win32con.WM_SETTINGCHANGE, 0, 0, win32con.SMTO_ABORTIFHUNG, 5000)
    return (not bool(res))

Refresh the windows environment.

.. note::
This will only effect new processes and windows. Services will not see
the change until the system restarts.

Returns:
bool: True if successful, otherwise False

Usage:

.. code-block:: python

import salt.utils.win_reg
winreg.broadcast_change()


def s(self, data, errors='strict'):

        try:
            if data is None or isinstance(data, (int, list, dict)):
                pass
            elif isinstance(data, unicode):
                try:
                    data.decode('utf-8')
                except UnicodeEncodeError:

                    data = str(data.encode('utf-8').strip(), errors=errors)
                    self.log.warning(u'Encoding poorly encoded string ({})'.format(data))
                except AttributeError:
                    pass
            else:
                data = str(data, 'utf-8', errors=errors)
        except NameError:
            pass
        return data

Decode value using correct Python 2/3 method.

This method is intended to replace the :py:meth:`~tcex.tcex.TcEx.to_string` method with
better logic to handle poorly encoded unicode data in Python2 and still work in Python3.

Args:
data (any): Data to ve validated and (de)encoded
errors (string): What method to use when dealing with errors.

Returns:
(string): Return decoded data


def __init__(self, file_entry, bytes_per_sector):

    super(TSKVolume, self).__init__(file_entry.name)
    self._file_entry = file_entry
    self._bytes_per_sector = bytes_per_sector

Initializes a volume.

Args:
file_entry (TSKPartitionFileEntry): a TSK partition file entry.
bytes_per_sector (int): number of bytes per sector.


def connect_to(self, vertex, weight=1):
    for edge in self.edges_out:
        if (vertex == edge.vertex_in):
            return edge
    return Edge(self, vertex, weight)

Connect this vertex to another one.

Args:
vertex (Vertex): vertex to connect to.
weight (int): weight of the edge.

Returns:
Edge: the newly created edge.


def report_error_to_cluster(self, error_code, error_message):
    if self._context_handle:
        pywrap_tfe.TFE_ReportErrorToCluster(self._context_handle, error_code, error_message)
    else:
        raise ValueError('Context is not initialized.')

Report error to other members in a multi-client cluster.

Args:
error_code: a `tf.errors` error code.
error_message: a string. The error message.


def _infer_num_gpus_per_worker(devices):
    if _is_device_list_single_worker(devices):
        return sum((1 for d in devices if _is_gpu_device(d)))
    else:
        device_dict = _group_device_list(devices)
        num_gpus = None
        for _, devices_in_task in device_dict.items():
            for device_in_task in devices_in_task:
                if num_gpus is None:
                    num_gpus = sum((1 for d in device_in_task if _is_gpu_device(d)))
                elif num_gpus != sum((1 for d in device_in_task if _is_gpu_device(d))):
                    raise ValueError('All workers should have the same number of GPUs.')
                for d in device_in_task:
                    d_spec = tf_device.DeviceSpec.from_string(d)
                    if d_spec.device_type == 'GPU' and d_spec.device_index >= num_gpus:
                        raise ValueError('GPU `device_index` on a worker should be consecutive and start from 0.')
        return num_gpus

Infers the number of GPUs on each worker.

Currently to make multi-worker cross device ops work, we need all workers to
have the same number of GPUs.

Args:
devices: a list of device strings, can be either local devices or remote
devices.

Returns:
number of GPUs per worker.

Raises:
ValueError if workers have different number of GPUs or GPU indices are not
consecutive and starting from 0.


def atomic_download(handle, download_fn, module_dir, lock_file_timeout_sec=(10 * 60)):
    lock_file = _lock_filename(module_dir)
    task_uid = uuid.uuid4().hex
    lock_contents = _lock_file_contents(task_uid)
    tmp_dir = _temp_download_dir(module_dir, task_uid)
    try:
        while True:
            try:
                tf_utils.atomic_write_string_to_file(lock_file, lock_contents, overwrite=False)
                if tf_v1.gfile.Exists(module_dir):
                    return module_dir
                break
            except tf.errors.OpError:
                pass
            _wait_for_lock_to_disappear(handle, lock_file, lock_file_timeout_sec)
        logging.info("Downloading TF-Hub Module '%s'.", handle)
        tf_v1.gfile.MakeDirs(tmp_dir)
        download_fn(handle, tmp_dir)
        _write_module_descriptor_file(handle, module_dir)
        try:
            tf_v1.gfile.Rename(tmp_dir, module_dir)
            logging.info("Downloaded TF-Hub Module '%s'.", handle)
        except tf.errors.AlreadyExistsError:
            logging.warning('Module already exists in %s', module_dir)
    finally:
        try:
            tf_v1.gfile.DeleteRecursively(tmp_dir)
        except tf.errors.NotFoundError:
            pass
        try:
            contents = tf_utils.read_file_to_string(lock_file)
        except tf.errors.NotFoundError:
            contents = ''
        if (contents == lock_contents):
            try:
                tf_v1.gfile.Remove(lock_file)
            except tf.errors.NotFoundError:
                pass
    return module_dir

Returns the path to a Module directory for a given TF-Hub Module handle.

Args:
handle: (string) Location of a TF-Hub Module.
download_fn: Callback function that actually performs download. The callback
receives two arguments, handle and the location of a temporary
directory to download the content into.
module_dir: Directory where to download the module files to.
lock_file_timeout_sec: The amount of time we give the current holder of
the lock to make progress in downloading a module.
If no progress is made, the lock is revoked.

Returns:
A string containing the path to a TF-Hub Module directory.

Raises:
ValueError: if the Module is not found.


def _create_L_ind(self, L):
    if issparse(L[0]):
        L = [L_t.todense() for L_t in L]
    L = self._to_numpy(L)
    L_ind = np.ones((self.n, (self.m * self.k)))
    for (yi, y) in enumerate(self.task_graph.feasible_set()):
        for t in range(self.t):
            L_ind[(:, yi::self.k)] *= np.where(np.logical_or((L[t] == y[t]), (L[t] == 0)), 1, 0)
        L_ind[(:, yi::self.k)] *= np.where((sum(L) != 0), 1, 0)
    return L_ind

Convert T label matrices with labels in 0...K_t to a one-hot format

Here we can view e.g. the $(i,j)$ entries of the $T$ label matrices as
a _label vector_ emitted by LF j for data point i.

Args:
L: a T-length list of [n,m] scipy.sparse label matrices with values
in {0,1,...,k}

Returns:
L_ind: An [n,m*k] dense np.ndarray with values in {0,1}

Note that no column is required for 0 (abstain) labels.


def append(self, value, key=''):

        if isinstance(value, type('')) or isinstance(value, type(u'')):
            value = ListItem(value)

        keys = super(ListView, self).append(value, key=key)
        if type(value) in (list, tuple, dict):
            for k in keys:
                if not self.EVENT_ONCLICK in self.children[k].attributes:
                    self.children[k].onclick.connect(self.onselection)
                self.children[k].attributes['selected'] = False
        else:

            if not self.EVENT_ONCLICK in value.attributes:
                value.onclick.connect(self.onselection)
            value.attributes['selected'] = False
        return keys

Appends child items to the ListView. The items are accessible by list.children[key].

Args:
value (ListItem, or iterable of ListItems): The child to be appended. In case of a dictionary,
each item's key is used as 'key' param for the single append.
key (str): The unique string identifier for the child. Ignored in case of iterable 'value'
param.


def ConsumeInteger(self, is_long=False):
    try:
        result = _ParseAbstractInteger(self.token, is_long=is_long)
    except ValueError as e:
        raise self.ParseError(str(e))
    self.NextToken()
    return result

Consumes an integer number.

Args:
is_long: True if the value should be returned as a long integer.
Returns:
The integer parsed.

Raises:
ParseError: If an integer couldn't be consumed.


def _SetValues(self, values):

    def _ToStr(value):

      if isinstance(value, (list, tuple)):
        result = []
        for val in value:
          result.append(str(val))
        return result
      else:
        return str(value)

    if isinstance(values, Row):
      if self._keys != values.header:
        raise TypeError('Attempt to append row with mismatched header.')
      self._values = copy.deepcopy(values.values)

    elif isinstance(values, dict):
      for key in self._keys:
        if key not in values:
          raise TypeError('Dictionary key mismatch with row.')
      for key in self._keys:
        self[key] = _ToStr(values[key])

    elif isinstance(values, list) or isinstance(values, tuple):
      if len(values) != len(self._values):
        raise TypeError('Supplied list length != row length')
      for (index, value) in enumerate(values):
        self._values[index] = _ToStr(value)

    else:
      raise TypeError('Supplied argument must be Row, dict or list, not %s',
                      type(values))

Set values from supplied dictionary or list.

Args:
values: A Row, dict indexed by column name, or list.

Raises:
TypeError: Argument is not a list or dict, or list is not equal row
length or dictionary keys don't match.


def normalize_audio_buffer(buf, volume_percentage, sample_width=2):
    if (sample_width != 2):
        raise Exception('unsupported sample width:', sample_width)
    scale = (math.pow(2, ((1.0 * volume_percentage) / 100)) - 1)
    arr = array.array('h', buf)
    for idx in range(0, len(arr)):
        arr[idx] = int((arr[idx] * scale))
    buf = arr.tostring()
    return buf

Adjusts the loudness of the audio data in the given buffer.

Volume normalization is done by scaling the amplitude of the audio
in the buffer by a scale factor of 2^(volume_percentage/100)-1.
For example, 50% volume scales the amplitude by a factor of 0.414,
and 75% volume scales the amplitude by a factor of 0.681.
For now we only sample_width 2.

Args:
buf: byte string containing audio data to normalize.
volume_percentage: volume setting as an integer percentage (1-100).
sample_width: size of a single sample in bytes.


def google_api_execute(config, auth, api_call, results, errors, append=None):
    try:
        rows = API(config, api_call).execute()
        if results:
            if isinstance(rows, dict):
                rows = [rows]
            elif results.get('bigquery', {}).get('format', 'JSON') == 'CSV':
                rows = [[r] for r in rows]
            if config.verbose:
                print('.', end='', flush=True)
            if append:
                rows = google_api_append(append, api_call['kwargs'], rows)
            yield from map(lambda r: Discovery_To_BigQuery.clean(r), rows)
    except HttpError as e:
        if errors:
            rows = [{'Error': str(e), 'Parameters': [{'Key': k, 'Value': str(v)} for k, v in api_call['kwargs'].items()]}]
            put_rows(config, auth, errors, rows)
            if 'bigquery' in errors:
                errors['bigquery']['disposition'] = 'WRITE_APPEND'
        else:
            raise e

Execute the actual API call and write to the end points defined.

The API call is completely defined at this point.
The results and error definition is optional.

Args:
auth (string): either "user" or "service" to make the API call.
api_call (dict): the JSON for the API call as defined in recipe.
results (dict): defines where the data will be written
errors (dict): defines where the errors will be written
append (dict): optional parameters to append to each row, given as BQ schema

Returns (dict):
None, all data is transfered between API / BigQuery

Raises:
ValueError: If a required key in the recipe is missing.


def symmetric_kl_divergence(predicted, actual):
    epsilon = tf.constant(1e-07, dtype=tf.float32, name='epsilon')
    p = tf.math.maximum(predicted, epsilon)
    q = tf.math.maximum(actual, epsilon)
    kld_1 = tf.math.reduce_sum(tf.math.multiply(p, tf.math.log(tf.math.divide(p, q))))
    kld_2 = tf.math.reduce_sum(tf.math.multiply(q, tf.math.log(tf.math.divide(q, p))))
    return tf.add(kld_1, kld_2)

Calculate symmetric KL-divergence over two classification tensors.

Note that here the classifications do not form a probability distribution.
They are, however normalized to 0..1 and calculating a KL-divergence over them
gives reasonable numerical results.

Shape of the two inputs must be the same at inference time but is otherwise
unconstrained.

Args:
predicted: classification outputs from model
actual: golden classification outputs

Returns:
Single scalar tensor with symmetric KL-divergence between predicted and
actual.


def put_pixel(self, x: int, y: int, color: Tuple[(int, int, int)]) -> None:
    lib.TCOD_image_put_pixel(self.image_c, x, y, color)

Change a pixel on this Image.

Args:
x (int): X pixel of the Image.  Starting from the left at 0.
y (int): Y pixel of the Image.  Starting from the top at 0.
color (Union[Tuple[int, int, int], Sequence[int]]):
An (r, g, b) sequence or Color instance.


def setupSerialPort(loopback, port):
    if loopback:
        testSerial = SerialTestClass()
        serialPort = testSerial.serialPort
    else:
        serialPort = serial.Serial(port, 115200, timeout=0)
    return serialPort

Sets up serial port by connecting to phsyical or software port.

Depending on command line options, this function will either connect to a
SerialTestClass() port for loopback testing or to the specified port from
the command line option. If loopback is True it overrides the physical port
specification.

Args:
loopback: argparse option
port: argparse option

Returns:
serialPort: Pyserial serial port instance


def create_unbroadcast_axis(shape, broadcast_shape):

  return tuple(
      -(1 + i)
      for i in range(len(broadcast_shape))
      if i >= len(shape) or broadcast_shape[-(1 + i)] > shape[-(1 + i)])

Creates the reduction axis for unbroadcasting.

Args:
shape: A list. The shape after the broadcast operation.
broadcast_shape: A list. The original shape the array being unbroadcast
had.
Returns:
A list. The axes along which the array needs to be reduced. These axes will
be distributed evenly into the original shape.


def write_rst(self,
                  prefix: str = "",
                  suffix: str = "",
                  heading_underline_char: str = "=",
                  method: AutodocMethod = None,
                  overwrite: bool = False,
                  mock: bool = False) -> None:

        content = self.rst_content(
            prefix=prefix,
            suffix=suffix,
            heading_underline_char=heading_underline_char,
            method=method
        )
        write_if_allowed(self.target_rst_filename, content,
                         overwrite=overwrite, mock=mock)

Writes the RST file to our destination RST filename, making any
necessary directories.

Args:
prefix: as for :func:`rst_content`
suffix: as for :func:`rst_content`
heading_underline_char: as for :func:`rst_content`
method: as for :func:`rst_content`
overwrite: overwrite the file if it exists already?
mock: pretend to write, but don't


def csv_to_dict(file_name, file_location):

    file = __os.path.join(file_location, file_name)
    try:
        csv_read = open(file, "r")
    except Exception as e:
        LOGGER.critical('Function csv_to_dict Error {error} ignoring any errors'.format(error=e))
        print('Error {error} ignoring any errors'.format(error=e))
        csv_read = open(file, "r", errors='ignore')
    data_row = __csv.DictReader(csv_read, dialect="excel")
    dict_key = 1
    temp_dict = dict()
    for row in data_row:
        temp_dict[dict_key] = row
        dict_key += 1
    csv_read.close()
    return temp_dict

Function to import a csv as a dictionary
Args:
file_name: The name of the csv file
file_location: The location of the file, derive from the os module

Returns: returns a dictionary


def ParseDestList(self, parser_mediator, olecf_item):

    header_map = self._GetDataTypeMap('dest_list_header')

    try:
      header, entry_offset = self._ReadStructureFromFileObject(
          olecf_item, 0, header_map)
    except (ValueError, errors.ParseError) as exception:
      raise errors.UnableToParseFile(
          'Unable to parse DestList header with error: {0!s}'.format(
              exception))

    if header.format_version == 1:
      entry_map = self._GetDataTypeMap('dest_list_entry_v1')
    elif header.format_version in (3, 4):
      entry_map = self._GetDataTypeMap('dest_list_entry_v3')
    else:
      parser_mediator.ProduceExtractionWarning(
          'unsupported format version: {0:d}.'.format(header.format_version))
      return

    while entry_offset < olecf_item.size:
      try:
        entry, entry_data_size = self._ReadStructureFromFileObject(
            olecf_item, entry_offset, entry_map)
      except (ValueError, errors.ParseError) as exception:
        raise errors.UnableToParseFile(
            'Unable to parse DestList entry with error: {0!s}'.format(
                exception))

      display_name = 'DestList entry at offset: 0x{0:08x}'.format(entry_offset)

      try:
        droid_volume_identifier = self._ParseDistributedTrackingIdentifier(
            parser_mediator, entry.droid_volume_identifier, display_name)

      except (TypeError, ValueError) as exception:
        droid_volume_identifier = ''
        parser_mediator.ProduceExtractionWarning(
            'unable to read droid volume identifier with error: {0!s}'.format(
                exception))

      try:
        droid_file_identifier = self._ParseDistributedTrackingIdentifier(
            parser_mediator, entry.droid_file_identifier, display_name)

      except (TypeError, ValueError) as exception:
        droid_file_identifier = ''
        parser_mediator.ProduceExtractionWarning(
            'unable to read droid file identifier with error: {0!s}'.format(
                exception))

      try:
        birth_droid_volume_identifier = (
            self._ParseDistributedTrackingIdentifier(
                parser_mediator, entry.birth_droid_volume_identifier,
                display_name))

      except (TypeError, ValueError) as exception:
        birth_droid_volume_identifier = ''
        parser_mediator.ProduceExtractionWarning((
            'unable to read birth droid volume identifier with error: '
            '{0:s}').format(
                exception))

      try:
        birth_droid_file_identifier = self._ParseDistributedTrackingIdentifier(
            parser_mediator, entry.birth_droid_file_identifier, display_name)

      except (TypeError, ValueError) as exception:
        birth_droid_file_identifier = ''
        parser_mediator.ProduceExtractionWarning((
            'unable to read birth droid file identifier with error: '
            '{0:s}').format(
                exception))

      if entry.last_modification_time == 0:
        date_time = dfdatetime_semantic_time.SemanticTime('Not set')
      else:
        date_time = dfdatetime_filetime.Filetime(
            timestamp=entry.last_modification_time)

      event_data = AutomaticDestinationsDestListEntryEventData()
      event_data.birth_droid_file_identifier = birth_droid_file_identifier
      event_data.birth_droid_volume_identifier = birth_droid_volume_identifier
      event_data.droid_file_identifier = droid_file_identifier
      event_data.droid_volume_identifier = droid_volume_identifier
      event_data.entry_number = entry.entry_number
      event_data.hostname = entry.hostname.rstrip('\x00')
      event_data.offset = entry_offset
      event_data.path = entry.path.rstrip('\x00')
      event_data.pin_status = entry.pin_status

      event = time_events.DateTimeValuesEvent(
          date_time, definitions.TIME_DESCRIPTION_MODIFICATION)
      parser_mediator.ProduceEventWithEventData(event, event_data)

      entry_offset += entry_data_size

Parses the DestList OLECF item.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
olecf_item (pyolecf.item): OLECF item.

Raises:
UnableToParseFile: if the DestList cannot be parsed.


def __init__(self, name, description, *labels):
    super(BoolGauge, self).__init__('BoolGauge', _bool_gauge_methods, len(labels), name, description, *labels)

Creates a new BoolGauge.

Args:
name: name of the new metric.
description: description of the new metric.
*labels: The label list of the new metric.


def timestamp_YmdHMS(value):

    i = int(value)
    S = i
    M = S
    H = M
    d = H
    m = d
    Y = m
    return int(calendar.timegm((
        Y % 10000, m % 100, d % 100, H % 100, M % 100, S % 100, 0, 0, 0)
    ))

Convert timestamp string to time in seconds since epoch.

Timestamps strings like '20130618120000' are able to be converted by this
function.

Args:
value: A timestamp string in the format '%Y%m%d%H%M%S'.

Returns:
The time in seconds since epoch as an integer.

Raises:
ValueError: If timestamp is invalid.

Note: The timezone is assumed to be UTC/GMT.


def _create_in_hdx(self, object_type, id_field_name, name_field_name, file_to_upload=None):
    self.check_required_fields()
    if ((id_field_name in self.data) and self._load_from_hdx(object_type, self.data[id_field_name])):
        logger.warning(('%s exists. Updating %s' % (object_type, self.data[id_field_name])))
        self._merge_hdx_update(object_type, id_field_name, file_to_upload)
    else:
        self._save_to_hdx('create', name_field_name, file_to_upload)

Helper method to check if resource exists in HDX and if so, update it, otherwise create it

Args:
object_type (str): Description of HDX object type (for messages)
id_field_name (str): Name of field containing HDX object identifier
name_field_name (str): Name of field containing HDX object name
file_to_upload (Optional[str]): File to upload to HDX (if url not supplied)

Returns:
None


def verify_cert(signature_chain_url: str) -> Optional[crypto.X509]:

    try:
        certs_chain_get = requests.get(signature_chain_url)
    except requests.exceptions.ConnectionError as e:
        log.error(f'Amazon signature chain get error: {e}')
        return None

    certs_chain_txt = certs_chain_get.text
    certs_chain = extract_certs(certs_chain_txt)

    amazon_cert: crypto.X509 = certs_chain.pop(0)

    sc_url_verification = verify_sc_url(signature_chain_url)
    if not sc_url_verification:
        log.error(f'Amazon signature url {signature_chain_url} was not verified')

    expired_verification = not amazon_cert.has_expired()
    if not expired_verification:
        log.error(f'Amazon certificate ({signature_chain_url}) expired')

    sans_verification = verify_sans(amazon_cert)
    if not sans_verification:
        log.error(f'Subject alternative names verification for ({signature_chain_url}) certificate failed')

    chain_verification = verify_certs_chain(certs_chain, amazon_cert)
    if not chain_verification:
        log.error(f'Certificates chain verification for ({signature_chain_url}) certificate failed')

    result = (sc_url_verification and expired_verification and sans_verification and chain_verification)

    return amazon_cert if result else None

Conducts series of Alexa SSL certificate verifications against Amazon Alexa requirements.

Args:
signature_chain_url: Signature certificate URL from SignatureCertChainUrl HTTP header.
Returns:
result: Amazon certificate if verification was successful, None if not.


def flush(writer=None, name=None):
    del name
    if writer is None:
        writer = _summary_state.writer
        if writer is None:
            return control_flow_ops.no_op()
    if isinstance(writer, SummaryWriter):
        return writer.flush()
    raise ValueError('Invalid argument to flush(): %r' % (writer,))

Forces summary writer to send any buffered data to storage.

This operation blocks until that finishes.

Args:
writer: The `tf.summary.SummaryWriter` to flush. If None, the current
default writer will be used instead; if there is no current writer, this
returns `tf.no_op`.
name: Ignored legacy argument for a name for the operation.

Returns:
The created `tf.Operation`.


def _Stat(self, path, ext_attrs=False):
    local_path = client_utils.CanonicalPathToLocalPath(path)
    result = client_utils.StatEntryFromPath(local_path, self.pathspec, ext_attrs=ext_attrs)
    try:
        result.symlink = utils.SmartUnicode(os.readlink(local_path))
    except (OSError, AttributeError):
        pass
    return result

Returns stat information of a specific path.

Args:
path: A unicode string containing the path.
ext_attrs: Whether the call should also collect extended attributes.

Returns:
a StatResponse proto

Raises:
IOError when call to os.stat() fails


def _ParseLogLine(self, parser_mediator, key, structure):

    time_elements_tuple = self._GetTimeElementsTuple(key, structure)

    try:
      date_time = dfdatetime_time_elements.TimeElementsInMilliseconds(
          time_elements_tuple=time_elements_tuple)
    except ValueError:
      parser_mediator.ProduceExtractionWarning(
          'invalid date time value: {0!s}'.format(structure.date_time))
      return

    self._last_month = time_elements_tuple[1]

    event_data = MacWifiLogEventData()
    event_data.agent = structure.agent

    event_data.function = structure.function.strip()
    event_data.text = structure.text

    if key == 'known_function_logline':
      event_data.action = self._GetAction(
          event_data.function, event_data.text)

    event = time_events.DateTimeValuesEvent(
        date_time, definitions.TIME_DESCRIPTION_ADDED)
    parser_mediator.ProduceEventWithEventData(event, event_data)

Parse a single log line and produce an event object.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
key (str): name of the parsed structure.
structure (pyparsing.ParseResults): structure of tokens derived from
a line of a text file.


def get_distance(self, node):
    delta = ((node.pos[0] - self.pos[0]), (node.pos[1] - self.pos[1]))
    return sqrt(((delta[0] ** 2) + (delta[1] ** 2)))

Get the distance beetween 2 nodes

Args:
node (object): The other node.


def ephemeris(self, **kwargs):

        for orb in self.iter(inclusive=True, **kwargs):
            yield orb

Generator giving the propagation of the orbit at different dates

Args:
start (Date)
stop (Date or timedelta)
step (timedelta)
Yield:
Orbit


def copy_cwl_files(from_dir=CWL_PATH, to_dir=None):
    cwl_files = glob.glob('{}{}*.cwl'.format(from_dir, os.sep))
    if (len(cwl_files) > 0):
        create_dirs(to_dir)
    for fi in cwl_files:
        fo = os.path.join(to_dir, os.path.basename(fi))
        shutil.copy2(fi, fo)
    return len(cwl_files)

Copy cwl files to a directory where the cwl-runner can find them.

Args:
from_dir (str): Path to directory where to copy files from (default:
the cwl directory of nlppln).
to_dir (str): Path to directory where the files should be copied to
(e.g., the CWL working directory).


def _validate_namespace(self, namespace):

        if self._namespace_regex.fullmatch(namespace) is None:
            LOGGER.debug('Invalid namespace: %s', namespace)
            raise _ResponseFailed(self._status.INVALID_ADDRESS)

Validates a namespace, raising a ResponseFailed error if invalid.

Args:
state_root (str): The state_root to validate

Raises:
ResponseFailed: The state_root was invalid, and a status of
INVALID_ROOT will be sent with the response.


class BridgeTowerProcessor(ProcessorMixin):
    attributes = ['image_processor', 'tokenizer']
    image_processor_class = 'BridgeTowerImageProcessor'
    tokenizer_class = ('RobertaTokenizer', 'RobertaTokenizerFast')

    def __init__(self, image_processor, tokenizer):
        super().__init__(image_processor, tokenizer)

    def __call__(self, images, text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]]=None, audio=None, videos=None, **kwargs: Unpack[BridgeTowerProcessorKwargs]) -> BatchEncoding:

        output_kwargs = self._merge_kwargs(BridgeTowerProcessorKwargs, tokenizer_init_kwargs=self.tokenizer.init_kwargs, **kwargs)
        encoding = self.tokenizer(text=text, **output_kwargs['text_kwargs'])
        encoding_image_processor = self.image_processor(images, **output_kwargs['images_kwargs'])
        encoding.update(encoding_image_processor)
        return encoding

    def batch_decode(self, *args, **kwargs):

        return self.tokenizer.batch_decode(*args, **kwargs)

    def decode(self, *args, **kwargs):

        return self.tokenizer.decode(*args, **kwargs)

    @property
    def model_input_names(self):
        tokenizer_input_names = self.tokenizer.model_input_names
        image_processor_input_names = self.image_processor.model_input_names
        return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names))

Constructs a BridgeTower processor which wraps a Roberta tokenizer and BridgeTower image processor into a single
processor.

[`BridgeTowerProcessor`] offers all the functionalities of [`BridgeTowerImageProcessor`] and
[`RobertaTokenizerFast`]. See the docstring of [`~BridgeTowerProcessor.__call__`] and
[`~BridgeTowerProcessor.decode`] for more information.

Args:
image_processor (`BridgeTowerImageProcessor`):
An instance of [`BridgeTowerImageProcessor`]. The image processor is a required input.
tokenizer (`RobertaTokenizerFast`):
An instance of ['RobertaTokenizerFast`]. The tokenizer is a required input.


def update_video(self, video_id, title="", description="", keywords="", access_control=AccessControl.Unlisted):

        if not self.authenticated:
            raise ApiError(_("Authentication is required"))

        entry = self.fetch_video(video_id)

        extension = self._access_control(access_control)
        if extension:
            entry.extension_elements = extension

        if title:
            entry.media.title.text = title

        if description:
            entry.media.description.text = description

        success = Api.yt_service.UpdateVideoEntry(entry)
        return success

Updates the video

Authentication is required

Params:
entry: video entry fetch via 'fetch_video()'
title: string
description: string
keywords: string

Returns:
a video entry on success
None otherwise


def attention_bias_prepend_inputs_full_attention(padding):
    in_target = tf.cumsum(padding, axis=1, exclusive=True)
    target_pos = tf.cumsum(in_target, axis=1)
    illegal_connections = tf.greater(tf.expand_dims(target_pos, 1), tf.expand_dims(target_pos, 2))
    bias = (tf.to_float(illegal_connections) * (- 1000000000.0))
    bias = tf.expand_dims(bias, 1)
    return bias

Create a bias tensor for prepend_mode="prepend_inputs_full_attention".

See prepend_inputs in common_hparams.py.

Produces a bias tensor to be used in self-attention.

This bias tensor allows for full connectivity in the "inputs" part of
the sequence and masked connectivity in the targets part.

Args:
padding: a float `Tensor` with shape [batch, length] with
ones in positions corresponding to padding.  In each row, a single
padding position separates the input part from the target part.

Returns:
a `Tensor` with shape [batch, 1, length, length].


def append(self, value, key=''):

        if type(value) in (list, tuple, dict):
            if type(value)==dict:
                for k in value.keys():
                    self.append(value[k], k)
                return value.keys()
            keys = []
            for child in value:
                keys.append( self.append(child) )
            return keys

        key = str(key)
        if not isinstance(value, Widget):
            raise ValueError('value should be a Widget (otherwise use add_child(key,other)')

        if 'left' in value.style.keys():
            del value.style['left']
        if 'right' in value.style.keys():
            del value.style['right']

        if not 'order' in value.style.keys():
            value.style.update({'position':'static', 'order':'-1'})

        if key.isdigit():
            value.style['order'] = key

        key = value.identifier if key == '' else key
        self.add_child(key, value)

        return key

It allows to add child widgets to this.
The key allows to access the specific child in this way widget.children[key].
The key have to be numeric and determines the children order in the layout.

Args:
value (Widget): Child instance to be appended.
key (str): Unique identifier for the child. If key.isdigit()==True '0' '1'.. the value determines the order
in the layout


def rename(self, name):
    return self.client.api.rename(self.id, name)

Rename this container. Similar to the ``docker rename`` command.

Args:
name (str): New name for the container

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


def parse_document_id(chrom, pos, ref, alt, variant_type, case_id):
    return generate_md5_key([chrom, pos, ref, alt, variant_type, case_id])

Parse the unique document id for a variant.

This will always be unique in the database.

Args:
chrom(str)
pos(str)
ref(str)
alt(str)
variant_type(str): 'clinical' or 'research'
case_id(str): unqiue family id

Returns:
document_id(str): The unique document id in an md5 string


def _fetch(self, method, url=None, post_data=None, parse_data=True, key=None, parameters=None, listener=None, full_return=False):
    headers = self.get_headers()
    headers['Content-Type'] = 'application/json'
    handlers = []
    debuglevel = int(self._settings['debug'])
    handlers.append(urllib2.HTTPHandler(debuglevel=debuglevel))
    if hasattr(httplib, 'HTTPS'):
        handlers.append(urllib2.HTTPSHandler(debuglevel=debuglevel))
    handlers.append(urllib2.HTTPCookieProcessor(cookielib.CookieJar()))
    password_url = self._get_password_url()
    if (password_url and ('Authorization' not in headers)):
        pwd_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
        pwd_manager.add_password(None, password_url, self._settings['user'], self._settings['password'])
        handlers.append(HTTPBasicAuthHandler(pwd_manager))
    opener = urllib2.build_opener(*handlers)
    if (post_data is not None):
        post_data = json.dumps(post_data)
    uri = self._url(url, parameters)
    request = RESTRequest(uri, method=method, headers=headers)
    if (post_data is not None):
        request.add_data(post_data)
    response = None
    try:
        response = opener.open(request)
        body = response.read()
        if (password_url and (password_url not in self._settings['authorizations']) and request.has_header('Authorization')):
            self._settings['authorizations'][password_url] = request.get_header('Authorization')
    except urllib2.HTTPError as e:
        if (e.code == 401):
            raise AuthenticationError(('Access denied while trying to access %s' % uri))
        elif (e.code == 404):
            raise ConnectionError(('URL not found: %s' % uri))
        else:
            raise
    except urllib2.URLError as e:
        raise ConnectionError(('Error while fetching from %s: %s' % (uri, e)))
    finally:
        if response:
            response.close()
        opener.close()
    data = None
    if parse_data:
        if (not key):
            key = string.split(url, '/')[0]
        data = self.parse(body, key)
    if full_return:
        info = (response.info() if response else None)
        status = (int(string.split(info['status'])[0]) if (info and ('status' in info)) else None)
        return {'success': ((status >= 200) and (status < 300)), 'data': data, 'info': info, 'body': body}
    return data

Issue a request.

Args:
method (str): Request method (GET/POST/PUT/DELETE/etc.) If not specified, it will be POST if post_data is not None

Kwargs:
url (str): Destination URL
post_data (str): A string of what to POST
parse_data (bool): If true, parse response data
key (string): If parse_data==True, look for this key when parsing data
parameters (dict): Additional GET parameters to append to the URL
listener (func): callback called when uploading a file
full_return (bool): If set to True, get a full response (with success, data, info, body)

Returns:
dict. Response. If full_return==True, a dict with keys: success, data, info, body, otherwise the parsed data

Raises:
AuthenticationError, ConnectionError, urllib2.HTTPError, ValueError


def getPageType(name, number=False):
    if (not (name in pageNames())):
        return None
    pageType = PyOrigin.Pages(name).GetType()
    if number:
        return str(pageType)
    if (pageType == 1):
        return 'matrix'
    if (pageType == 2):
        return 'book'
    if (pageType == 3):
        return 'graph'
    if (pageType == 4):
        return 'layout'
    if (pageType == 5):
        return 'notes'

Returns the type of the page with that name.
If that name doesn't exist, None is returned.

Args:
name (str): name of the page to get the folder from
number (bool): if True, return numbers (i.e., a graph will be 3)
if False, return words where appropriate (i.e, "graph")

Returns:
string of the type of object the page is


def get_event(self, event_name, event_history=None):

        if event_history is None:
            event_history = event_name + '_history'
        return self._db.rpoplpush(event_name, event_history)

Get an event from the database.

Gets an event from the named event list removing the event and
adding it to the event history.

Args:
event_name (str): Event list key.
event_history (str, optional): Event history list.

Returns:
str: string representation of the event object


def _resolve_grad_captures(body_graph, body_grad_graph, while_op):
    new_capture_inputs = []
    for t in body_grad_graph.external_captures:
        if t.graph == body_graph:
            for i, output in enumerate(t.graph.outputs):
                if output is t:
                    t = while_op.outputs[i]
                    break
            assert t.graph == body_graph.outer_graph
        new_capture_inputs.append(t)
    return new_capture_inputs

Returns the tensors to pass as captured inputs to `body_grad_graph`.

`body_grad_graph` may have external references to:
1. Its outer graph containing the input gradients. These are left as-is.
2. Accumulators captured from the forward-pass graph. These should have been
added as `while_op` outputs after the gradient graph was built. We replace
these with the corresponding output of `while_op`, i.e. a tensor in
`body_graph.outer_graph`. In the case of nested control flow or functions,
the gradient logic handling `body_grad_graph.outer_graph` will make sure
the tensor from `body_graph.outer_graph` is also correctly captured.

Args:
body_graph: FuncGraph. The forward-pass body function.
body_grad_graph: FuncGraph. The body gradients function.
while_op: The forward-pass While Operation calling `body_graph`.

Returns:
A list of input tensors to be passed as the captured inputs to
`body_grad_graph`.


def get_document(project_id, knowledge_base_id, document_id):
    import dialogflow_v2beta1 as dialogflow
    client = dialogflow.DocumentsClient()
    document_path = client.document_path(project_id, knowledge_base_id, document_id)
    response = client.get_document(document_path)
    print('Got Document:')
    print(' - Display Name: {}'.format(response.display_name))
    print(' - Knowledge ID: {}'.format(response.name))
    print(' - MIME Type: {}'.format(response.mime_type))
    print(' - Knowledge Types:')
    for knowledge_type in response.knowledge_types:
        print('    - {}'.format(KNOWLEDGE_TYPES[knowledge_type]))
    print(' - Source: {}\n'.format(response.content_uri))

Gets a Document.

Args:
project_id: The GCP project linked with the agent.
knowledge_base_id: Id of the Knowledge base.
document_id: Id of the Document.


def __init__(self, org=None, course=None, run=None, branch=None, version_guid=None, deprecated=False, **kwargs):

        offering_arg = kwargs.pop('offering', None)
        if offering_arg:
            warnings.warn(
                "offering is deprecated! Use course and run instead.",
                DeprecationWarning,
                stacklevel=2
            )
            course, __, run = offering_arg.partition("/")

        if deprecated:
            for part in (org, course, run):
                self._check_location_part(part, self.INVALID_CHARS_DEPRECATED)

            fields = [org, course]

            if run:
                fields.append(run)
            if branch is not None:
                fields.append(branch)
            if not all(self.DEPRECATED_ALLOWED_ID_RE.match(field) for field in fields):
                raise InvalidKeyError(self.__class__, fields)

        else:
            if version_guid:
                version_guid = self.as_object_id(version_guid)

            for name, value in [['org', org], ['course', course], ['run', run], ['branch', branch]]:
                if not (value is None or self.ALLOWED_ID_RE.match(value)):
                    raise InvalidKeyError(self.__class__,
                                          u"Special characters not allowed in field {}: '{}'".format(name, value))

        super(CourseLocator, self).__init__(
            org=org,
            course=course,
            run=run,
            branch=branch,
            version_guid=version_guid,
            deprecated=deprecated,
            **kwargs
        )

        if self.deprecated and (self.org is None or self.course is None):
            raise InvalidKeyError(self.__class__, "Deprecated strings must set both org and course.")

        if not self.deprecated and self.version_guid is None and \
                (self.org is None or self.course is None or self.run is None):
            raise InvalidKeyError(self.__class__, "Either version_guid or org, course, and run should be set")

Construct a CourseLocator

Args:
version_guid (string or ObjectId): optional unique id for the version
org, course, run (string): the standard definition. Optional only if version_guid given
branch (string): the branch such as 'draft', 'published', 'staged', 'beta'


def get_unstable_entries(self, charge_to_discharge=True):

        list_copy = list(self._unstable_entries)
        return list_copy if charge_to_discharge else list_copy.reverse()

Returns the unstable entries for the electrode.

Args:
charge_to_discharge: Order from most charge to most discharged
state? Defaults to True.

Returns:
A list of unstable entries in the electrode, ordered by amount of
the working ion.


def _check_conversion_params(conversion_params, is_v2=False):
    supported_precision_modes = TrtPrecisionMode.supported_precision_modes()
    if conversion_params.precision_mode not in supported_precision_modes:
        raise ValueError("precision mode '{}' is not supported.It should be one of {}".format(conversion_params.precision_mode, supported_precision_modes))
    if conversion_params.minimum_segment_size <= 0 and conversion_params.minimum_segment_size != -1:
        raise ValueError('minimum segment size should be positive or -1 (to disable main graph conversion).')

Validate the provided TrtConversionParams.

Args:
conversion_params: a TrtConversionParams instance.
is_v2: whether we're getting a RewriterConfig for TF 2.0.

Raises:
TypeError: if any of the parameters are of unexpected type.
ValueError: if any of the parameters are of unexpected value.


def get_results(self, fp=sys.stdout, inline=True, delim=None, fetch=True, qlog=None, arguments=[]):
    result_path = self.meta_data['results_resource']
    conn = Qubole.agent()
    include_header = 'false'
    if (len(arguments) == 1):
        include_header = arguments.pop(0)
        if (include_header not in ('true', 'false')):
            raise ParseError('incude_header can be either true or false')
    r = conn.get(result_path, {'inline': inline, 'include_headers': include_header})
    if r.get('inline'):
        raw_results = r['results']
        encoded_results = raw_results.encode('utf8')
        if (sys.version_info < (3, 0, 0)):
            fp.write(encoded_results)
        else:
            import io
            if isinstance(fp, io.TextIOBase):
                if hasattr(fp, 'buffer'):
                    fp.buffer.write(encoded_results)
                else:
                    fp.write(raw_results)
            elif (isinstance(fp, io.BufferedIOBase) or isinstance(fp, io.RawIOBase)):
                fp.write(encoded_results)
            else:
                pass
    elif fetch:
        storage_credentials = conn.get(Account.credentials_rest_entity_path)
        if (storage_credentials['region_endpoint'] is not None):
            boto_conn = boto.connect_s3(aws_access_key_id=storage_credentials['storage_access_key'], aws_secret_access_key=storage_credentials['storage_secret_key'], security_token=storage_credentials['session_token'], host=storage_credentials['region_endpoint'])
        else:
            boto_conn = boto.connect_s3(aws_access_key_id=storage_credentials['storage_access_key'], aws_secret_access_key=storage_credentials['storage_secret_key'], security_token=storage_credentials['session_token'])
        log.info(('Starting download from result locations: [%s]' % ','.join(r['result_location'])))
        num_result_dir = Command.find(self.id).num_result_dir
        if ((include_header.lower() == 'true') and (qlog is not None)):
            write_headers(qlog, fp)
        for s3_path in r['result_location']:
            _download_to_local(boto_conn, s3_path, fp, num_result_dir, delim=delim)
    else:
        fp.write(','.join(r['result_location']))

Fetches the result for the command represented by this object

get_results will retrieve results of the command and write to stdout by default.
Optionally one can write to a filestream specified in `fp`. The `inline` argument
decides whether the result can be returned as a CRLF separated string. In cases where
the results are greater than 20MB, get_results will attempt to read from s3 and write
to fp. The retrieval of results from s3 can be turned off by the `fetch` argument

Args:
`fp`: a file object to write the results to directly
`inline`: whether or not results are returned inline as CRLF separated string
`fetch`: True to fetch the result even if it is greater than 20MB, False to
only get the result location on s3


def print_result_for_plain_cgi_script_from_tuple(contenttype_headers_content: WSGI_TUPLE_TYPE, status: str='200 OK') -> None:
    (contenttype, headers, content) = contenttype_headers_content
    print_result_for_plain_cgi_script(contenttype, headers, content, status)

Writes HTTP result to stdout.

Args:
contenttype_headers_content:
the tuple ``(contenttype, extraheaders, data)``
status:
HTTP status message (default ``"200 OK``)


def measure_topology(script):

    filter_xml = '  <xmlfilter name="Compute Topological Measures"/>\n'
    util.write_filter(script, filter_xml)
    if isinstance(script, mlx.FilterScript):
        script.parse_topology = True
    return None

Compute a set of topological measures over a mesh

Args:
script: the mlx.FilterScript object or script filename to write
the filter to.

Layer stack:
No impacts

MeshLab versions:
2016.12
1.3.4BETA


def extract_keywords_from_text(index_page, no_items=5):

    index_page = MLStripper.strip_tags(index_page)
    tokenized_index = TextBlob(index_page).lower()

    def to_str(key):
        if isinstance(key, unicode):
            return key.encode("utf-8")

        return key

    present_keywords = [
        KEYWORDS_LOWER[key]
        for key in KEYWORDS_LOWER.keys()
        if len(key) > 3 and key in tokenized_index
    ]

    def to_source_string(key):
        source = "Keyword analysis"
        try:
            return SourceString(key, source)
        except UnicodeEncodeError:
            return SourceString(key.encode("utf-8"), source)

    multi_keywords = [
        to_source_string(key)
        for key in present_keywords
        if tokenized_index.words.count(key) >= 1
    ]

    multi_keywords = sorted(multi_keywords, key=lambda x: len(x), reverse=True)

    if len(multi_keywords) > no_items:
        return multi_keywords[:no_items]

    return multi_keywords

Try to process text on the `index_page` deduce the keywords and then try
to match them on the Aleph's dataset.

Function returns maximally `no_items` items, to prevent spamming the user.

Args:
index_page (str): Content of the page as UTF-8 string
no_items (int, default 5): Number of items to return.

Returns:
list: List of :class:`.SourceString` objects.


def get_wulff_shape(self, material_id):

        from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
        from pymatgen.analysis.wulff import WulffShape, hkl_tuple_to_str

        structure = self.get_structure_by_material_id(material_id)
        surfaces = self.get_surface_data(material_id)["surfaces"]
        lattice = (SpacegroupAnalyzer(structure)
                   .get_conventional_standard_structure().lattice)
        miller_energy_map = {}
        for surf in surfaces:
            miller = tuple(surf["miller_index"])

            if (miller not in miller_energy_map) or surf["is_reconstructed"]:
                miller_energy_map[miller] = surf["surface_energy"]
        millers, energies = zip(*miller_energy_map.items())
        return WulffShape(lattice, millers, energies)

Constructs a Wulff shape for a material.

Args:
material_id (str): Materials Project material_id, e.g. 'mp-123'.
Returns:
pymatgen.analysis.wulff.WulffShape


def _client_receive(self):
    try:
        return self._client.readline()
    except socket.error as e:
        raise errors.Error(self._device, f'Encountered socket error "{e}" reading RPC response') from e

Receives the server's response of an RPC message.

Returns:
Raw bytes of the response.

Raises:
errors.Error: if a socket error occurred during the read.


def get_book_links(links):
    book_links = []
    for link in links:
        data = DOWNER.download((link + '1'))
        dom = dhtmlparser.parseString(data)
        book_links.extend(_parse_book_links(dom))
        max_page = _get_max_page(dom)
        if (max_page == 1):
            continue
        for i in range((max_page - 1)):
            data = DOWNER.download((link + str((i + 2))))
            book_links.extend(_parse_book_links(dhtmlparser.parseString(data)))
    return book_links

Go thru `links` to categories and return list to all publications in all
given categories.

Args:
links (list): List of strings (absolute links to categories).

Returns:
list: List of strings / absolute links to book details.


def print_str(self, string):
    (x, y) = self._cursor
    for char in string:
        if (char == '\n'):
            x = 0
            y += 1
            continue
        if (char == '\r'):
            x = 0
            continue
        (x, y) = self._normalizeCursor(x, y)
        self.draw_char(x, y, char, self._fg, self._bg)
        x += 1
    self._cursor = (x, y)

Print a string at the virtual cursor.

Handles special characters such as '\\n' and '\\r'.
Printing past the bottom of the console will scroll everything upwards
if :any:`set_mode` is set to 'scroll'.

Colors can be set with :any:`set_colors` and the virtual cursor can
be moved with :any:`move`.

Args:
string (Text): The text to print.

.. seealso:: :any:`draw_str`, :any:`move`, :any:`set_colors`,
:any:`set_mode`, :any:`write`, :any:`Window`


def get_first(self, status):
    items = self.get_all(status)
    if items:
        return list(items.items())[0][1]
    return None

Get the first item in the queue that has the given status.

Args:
status (str): return the first item with this status.

Returns:
:class:`nyawc.QueueItem`: The first queue item with the given status.


def FileEntryExistsByPathSpec(self, path_spec):

    location = getattr(path_spec, 'location', None)
    if location is None or not location.startswith(self.LOCATION_ROOT):
      return False

    if len(location) == 1:
      return True

    return self._cpio_archive_file.FileEntryExistsByPath(location[1:])

Determines if a file entry for a path specification exists.

Args:
path_spec (PathSpec): a path specification.

Returns:
bool: True if the file entry exists.


def db_for_write(self, model, **hints):
    try:
        if (model.sf_access == READ_ONLY):
            raise WriteNotSupportedError(('%r is a read-only model.' % model))
    except AttributeError:
        pass
    return None

Prevent write actions on read-only tables.

Raises:
WriteNotSupportedError: If models.sf_access is ``read_only``.


def __init__(
            self,
            epsilon,
            alphabet=None):

        self.bookeeping = None
        self.groups = None
        self.epsilon = epsilon
        if alphabet is None:
            alphabet = createalphabet()
        self.alphabet = alphabet

Initialization Function
Args:
epsilon (str): The epsilon symbol
alphabet (list): The DFA Alphabet
Returns:
None


def run_init_ops(self, sess, tags, import_scope=None):
    meta_graph_def = self.get_meta_graph_def_from_tags(tags)
    with sess.graph.as_default():
        asset_tensors_dictionary = get_asset_tensors(self._export_dir, meta_graph_def, import_scope=import_scope)
        init_op = get_init_op(meta_graph_def, import_scope)
        if init_op is not None:
            sess.run(fetches=[init_op], feed_dict=asset_tensors_dictionary)

Run initialization ops defined in the `MetaGraphDef`.

Args:
sess: tf.compat.v1.Session to restore variable values.
tags: a set of string tags identifying a MetaGraphDef.
import_scope: Optional `string` -- if specified, prepend this string
followed by '/' to all loaded tensor names. This scope is applied to
tensor instances loaded into the passed session, but it is *not* written
through to the static `MetaGraphDef` protocol buffer that is returned.


def update_reminder(self, reminder):

		uri = '/'.join([self.api_uri,
						self.reminders_suffix,
						])

		payload = None
		if  type(reminder) is not StreakReminder:
			return requests.codes.bad_request, None

		payload = reminder.to_dict(rw = True)

		try:
			uri = '/'.join([uri, reminder.attributes['key']])
		except KeyError:
			return requests.codes.bad_request, None

		code, data = self._req('post', uri , json.dumps(payload))

		return code, data

Creates a reminder with the provided attributes.
Args:
reminder		updated reminder of StreakReminder type
return			(status code, reminder dict)


def consult_filters(self, url_info: URLInfo, url_record: URLRecord, is_redirect: bool=False) \
            -> Tuple[bool, str, dict]:

        if not self._url_filter:
            return True, 'nofilters', None

        test_info = self._url_filter.test_info(url_info, url_record)

        verdict = test_info['verdict']

        if verdict:
            reason = 'filters'
        elif is_redirect and self.is_only_span_hosts_failed(test_info):
            verdict = True
            reason = 'redirect'
        else:
            reason = 'filters'

        return verdict, reason, test_info

Consult the URL filter.

Args:
url_record: The URL record.
is_redirect: Whether the request is a redirect and it is
desired that it spans hosts.

Returns
tuple:

1. bool: The verdict
2. str: A short reason string: nofilters, filters, redirect
3. dict: The result from :func:`DemuxURLFilter.test_info`