def random_walk_uniform_fn(scale=1.0, name=None):

    def _fn(state_parts, seed):
        'Adds a uniform perturbation to the input state.\n\n    Args:\n      state_parts: A list of `Tensor`s of any shape and real dtype representing\n        the state parts of the `current_state` of the Markov chain.\n      seed: `int` or None. The random seed for this `Op`. If `None`, no seed is\n        applied.\n        Default value: `None`.\n\n    Returns:\n      perturbed_state_parts: A Python `list` of The `Tensor`s. Has the same\n        shape and type as the `state_parts`.\n\n    Raises:\n      ValueError: if `scale` does not broadcast with `state_parts`.\n    '
        with tf.compat.v1.name_scope(name, 'random_walk_uniform_fn', values=[state_parts, scale, seed]):
            scales = (scale if mcmc_util.is_list_like(scale) else [scale])
            if (len(scales) == 1):
                scales *= len(state_parts)
            if (len(state_parts) != len(scales)):
                raise ValueError('`scale` must broadcast with `state_parts`.')
            seed_stream = distributions.SeedStream(seed, salt='RandomWalkUniformFn')
            next_state_parts = [tf.random.uniform(minval=(state_part - scale_part), maxval=(state_part + scale_part), shape=tf.shape(input=state_part), dtype=state_part.dtype.base_dtype, seed=seed_stream()) for (scale_part, state_part) in zip(scales, state_parts)]
            return next_state_parts
    return _fn

Returns a callable that adds a random uniform perturbation to the input.

For more details on `random_walk_uniform_fn`, see
`random_walk_normal_fn`. `scale` might
be a `Tensor` or a list of `Tensor`s that should broadcast with state parts
of the `current_state`. The generated uniform perturbation is sampled as a
uniform point on the rectangle `[-scale, scale]`.

Args:
scale: a `Tensor` or Python `list` of `Tensor`s of any shapes and `dtypes`
controlling the upper and lower bound of the uniform proposal
distribution.
name: Python `str` name prefixed to Ops created by this function.
Default value: 'random_walk_uniform_fn'.

Returns:
random_walk_uniform_fn: A callable accepting a Python `list` of `Tensor`s
representing the state parts of the `current_state` and an `int`
representing the random seed used to generate the proposal. The callable
returns the same-type `list` of `Tensor`s as the input and represents the
proposal for the RWM algorithm.


def export_gpx_file(self):
    gpx = create_elem('gpx', GPX_ELEM_ATTRIB)
    if (not self.metadata.bounds):
        self.metadata.bounds = self[:]
    gpx.append(self.metadata.togpx())
    for place in self:
        gpx.append(place.togpx())
    return etree.ElementTree(gpx)

Generate GPX element tree from ``Waypoints`` object.

Returns:
etree.ElementTree: GPX element tree depicting ``Waypoints`` object


def l2_regression_loss(y, target, name=None):
    with tf.name_scope(name, 'l2_regression', [y, target]) as scope:
        y = tf.convert_to_tensor(y, name='y')
        target = tf.convert_to_tensor(target, name='target')
        return tf.sqrt(l2_regression_sq_loss(y, target, name=scope))

Calculates the square root of the SSE between y and target.

Args:
y: the calculated values.
target: the desired values.
name: the name for this op, defaults to l2_regression
Returns:
A tensorflow op.


def random_weights(n, bounds=(0., 1.), total=1.0):

    low = bounds[0]
    high = bounds[1]

    if high < low:
        raise ValueError('Higher bound must be greater or '
                         'equal to lower bound')

    if n * high < total or n * low > total:
        raise ValueError('solution not possible with given n and bounds')

    w = [0] * n
    tgt = -float(total)

    for i in range(n):
        rn = n - i - 1
        rhigh = rn * high
        rlow = rn * low

        lowb = max(-rhigh - tgt, low)
        highb = min(-rlow - tgt, high)

        rw = random.uniform(lowb, highb)
        w[i] = rw

        tgt += rw

    random.shuffle(w)
    return w

Generate pseudo-random weights.

Returns a list of random weights that is of length
n, where each weight is in the range bounds, and
where the weights sum up to total.

Useful for creating random portfolios when benchmarking.

Args:
* n (int): number of random weights
* bounds ((low, high)): bounds for each weight
* total (float): total sum of the weights


def send_message(self):
    start = time.time()
    message = None
    if (not self.initialized):
        message = self.construct_start_message()
        self.initialized = True
    else:
        message = self.construct_end_message()
    self.send_UDP_message(message)
    end = time.time()
    return (end - start)

Send message over UDP.

If tracking is disables, the bytes_sent will always be set to -1

Returns:
(bytes_sent, time_taken)


def debug_object(obj, log_level: int = logging.DEBUG) -> None:

    msgs = ["For {o!r}:".format(o=obj)]
    for attrname in dir(obj):
        attribute = getattr(obj, attrname)
        msgs.append("- {an!r}: {at!r}, of type {t!r}".format(
            an=attrname, at=attribute, t=type(attribute)))
    log.log(log_level, "{}", "\n".join(msgs))

Sends details about a Python to the log, specifically its ``repr()``
representation, and all of its attributes with their name, value, and type.

Args:
obj: object to debug
log_level: log level to use; default is ``logging.DEBUG``


def accepts(self, tp, converter):

        tp = ParameterizedProperty._validate_type_param(tp)
        self.alternatives.append((tp, converter))
        return self

Declare that other types may be converted to this property type.

Args:
tp (Property) :
A type that may be converted automatically to this property
type.

converter (callable) :
A function accepting ``value`` to perform conversion of the
value to this property type.

Returns:
self


def add_curves_from_lasio(self, l, remap=None, funcs=None):

        params = {}
        for field, (sect, code) in LAS_FIELDS['data'].items():
            params[field] = utils.lasio_get(l,
                                            sect,
                                            code,
                                            remap=remap,
                                            funcs=funcs)

        curves = {c.mnemonic: Curve.from_lasio_curve(c, **params)
                  for c in l.curves}

        self.data.update(curves)

        return None

Given a LAS file, add curves from it to the current well instance.
Essentially just wraps ``add_curves_from_lasio()``.

Args:
fname (str): The path of the LAS file to read curves from.
remap (dict): Optional. A dict of 'old': 'new' LAS field names.
funcs (dict): Optional. A dict of 'las field': function() for
implementing a transform before loading. Can be a lambda.

Returns:
None. Works in place.


def distances(self, word, words):

    point = self[word]
    vectors = np.asarray([self[w] for w in words])
    diff = vectors - point
    distances = np.linalg.norm(diff, axis=1)
    return distances

Calculate eucledean pairwise distances between `word` and `words`.

Args:
word (string): single word.
words (list): list of strings.

Returns:
numpy array of the distances.

Note:
L2 metric is used to calculate distances.


def get_cookie_header(queue_item):
    header = []
    path = URLHelper.get_path(queue_item.request.url)
    for cookie in queue_item.request.cookies:
        root_path = ((cookie.path == '') or (cookie.path == '/'))
        if (path.startswith(cookie.path) or root_path):
            header.append(((cookie.name + '=') + cookie.value))
    return '&'.join(header)

Convert a requests cookie jar to a HTTP request cookie header value.

Args:
queue_item (:class:`nyawc.QueueItem`): The parent queue item of the new request.

Returns:
str: The HTTP cookie header value.


def _render(self):

        message = Message()
        message.add(Heading(tr('Problem'), **ORANGE_LEVEL_4_STYLE))
        message.add(Paragraph(tr(
            'The following problem(s) were encountered whilst running the '
            'analysis.')))
        items = BulletedList()
        for p in reversed(self.problems):

            items.add(p)
        message.add(items)

        message.add(Heading(tr('Suggestion'), **GREEN_LEVEL_4_STYLE))
        message.add(Paragraph(tr(
            'You can try the following to resolve the issue:')))
        if len(self.suggestions) < 1:
            suggestions = self.standard_suggestions()
            message.add(suggestions)
        else:
            items = BulletedList()
            for s in reversed(self.suggestions):
                if s is not None:
                    items.add(s)
            message.add(items)

        if len(self.details) > 0:
            items = BulletedList()
            message.add(Heading(
                tr('Details'), **ORANGE_LEVEL_5_STYLE))
            message.add(Paragraph(tr(
                'These additional details were reported when the problem '
                'occurred.')))
            for d in self.details:
                if d is not None:
                    items.add(d)
            message.add(items)

        message.add(Heading(tr(
            'Diagnostics'), **TRACEBACK_STYLE))
        message.add(self.tracebacks)
        return message

Create a Message version of this ErrorMessage

Args:
none

Returns:
the Message instance of this ErrorMessage

Raises:
Errors are propagated


def set_inter_op_parallelism_threads(num_threads):
    context.context().inter_op_parallelism_threads = num_threads

Set number of threads used for parallelism between independent operations.

Determines the number of threads used by independent non-blocking operations.
0 means the system picks an appropriate number.

Args:
num_threads: Number of parallel threads


def create_timer(cb: Callable[[float], None], interval: float,
                 delay_policy: TimerDelayPolicy = TimerDelayPolicy.DEFAULT,
                 loop: Optional[asyncio.BaseEventLoop] = None) -> asyncio.Task:

    if not loop:
        loop = asyncio.get_event_loop()

    async def _timer():
        fired_tasks = []
        try:
            while True:
                if delay_policy == TimerDelayPolicy.CANCEL:
                    for t in fired_tasks:
                        if not t.done():
                            t.cancel()
                            await t
                    fired_tasks.clear()
                else:
                    fired_tasks[:] = [t for t in fired_tasks if not t.done()]
                t = loop.create_task(cb(interval=interval))
                fired_tasks.append(t)
                await asyncio.sleep(interval)
        except asyncio.CancelledError:
            for t in fired_tasks:
                t.cancel()
            await asyncio.gather(*fired_tasks)

    return loop.create_task(_timer())

Schedule a timer with the given callable and the interval in seconds.
The interval value is also passed to the callable.
If the callable takes longer than the timer interval, all accumulated
callable's tasks will be cancelled when the timer is cancelled.

Args:
cb: TODO - fill argument descriptions

Returns:
You can stop the timer by cancelling the returned task.


def dbmin_mean(self, value=None):
    if (value is not None):
        try:
            value = float(value)
        except ValueError:
            raise ValueError('value {} need to be of type float for field `dbmin_mean`'.format(value))
    self._dbmin_mean = value

Corresponds to IDD Field `dbmin_mean`
Mean of extreme annual minimum dry-bulb temperature

Args:
value (float): value for IDD Field `dbmin_mean`
Unit: C
if `value` is None it will not be checked against the
specification and is assumed to be a missing value

Raises:
ValueError: if `value` is not a valid value


def gunzip_file(gz_path, new_path):

  if tf.gfile.Exists(new_path):
    tf.logging.info("File %s already exists, skipping unpacking" % new_path)
    return
  tf.logging.info("Unpacking %s to %s" % (gz_path, new_path))

  mode = stat.S_IRWXU or stat.S_IXGRP or stat.S_IRGRP or stat.S_IROTH
  os.chmod(os.path.dirname(new_path), mode)
  with gzip.open(gz_path, "rb") as gz_file:
    with tf.gfile.GFile(new_path, mode="wb") as new_file:
      for line in gz_file:
        new_file.write(line)

Unzips from gz_path into new_path.

Args:
gz_path: path to the zipped file.
new_path: path to where the file will be unzipped.


def script(experiment, projects):

    benchbuild_c = local[local.path(sys.argv[0])]
    slurm_script = local.cwd / experiment.name + "-" + str(
        CFG['slurm']['script'])

    srun = local["srun"]
    srun_args = []
    if not CFG["slurm"]["multithread"]:
        srun_args.append("--hint=nomultithread")
    if not CFG["slurm"]["turbo"]:
        srun_args.append("--pstate-turbo=off")

    srun = srun[srun_args]
    srun = srun[benchbuild_c["run"]]

    return __save__(slurm_script, srun, experiment, projects)

Prepare a slurm script that executes the experiment for a given project.

Args:
experiment: The experiment we want to execute
projects: All projects we generate an array job for.


def __init__(self, channel):

        self.ReadRows = channel.unary_stream(
            "/google.bigtable.v2.Bigtable/ReadRows",
            request_serializer=google_dot_cloud_dot_bigtable__v2_dot_proto_dot_bigtable__pb2.ReadRowsRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_bigtable__v2_dot_proto_dot_bigtable__pb2.ReadRowsResponse.FromString,
        )
        self.SampleRowKeys = channel.unary_stream(
            "/google.bigtable.v2.Bigtable/SampleRowKeys",
            request_serializer=google_dot_cloud_dot_bigtable__v2_dot_proto_dot_bigtable__pb2.SampleRowKeysRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_bigtable__v2_dot_proto_dot_bigtable__pb2.SampleRowKeysResponse.FromString,
        )
        self.MutateRow = channel.unary_unary(
            "/google.bigtable.v2.Bigtable/MutateRow",
            request_serializer=google_dot_cloud_dot_bigtable__v2_dot_proto_dot_bigtable__pb2.MutateRowRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_bigtable__v2_dot_proto_dot_bigtable__pb2.MutateRowResponse.FromString,
        )
        self.MutateRows = channel.unary_stream(
            "/google.bigtable.v2.Bigtable/MutateRows",
            request_serializer=google_dot_cloud_dot_bigtable__v2_dot_proto_dot_bigtable__pb2.MutateRowsRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_bigtable__v2_dot_proto_dot_bigtable__pb2.MutateRowsResponse.FromString,
        )
        self.CheckAndMutateRow = channel.unary_unary(
            "/google.bigtable.v2.Bigtable/CheckAndMutateRow",
            request_serializer=google_dot_cloud_dot_bigtable__v2_dot_proto_dot_bigtable__pb2.CheckAndMutateRowRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_bigtable__v2_dot_proto_dot_bigtable__pb2.CheckAndMutateRowResponse.FromString,
        )
        self.ReadModifyWriteRow = channel.unary_unary(
            "/google.bigtable.v2.Bigtable/ReadModifyWriteRow",
            request_serializer=google_dot_cloud_dot_bigtable__v2_dot_proto_dot_bigtable__pb2.ReadModifyWriteRowRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_bigtable__v2_dot_proto_dot_bigtable__pb2.ReadModifyWriteRowResponse.FromString,
        )

Constructor.

Args:
channel: A grpc.Channel.


def extend(*args):
    if (not args):
        return {}
    first = args[0]
    rest = args[1:]
    out = type(first)(first)
    for each in rest:
        out.update(each)
    return out

shallow dictionary merge

Args:
a: dict to extend
b: dict to apply to a

Returns:
new instance of the same type as _a_, with _a_ and _b_ merged.


def from_config(cls, config):
    config.pop('dtype', None)
    return cls(**config)

Instantiates an initializer from a configuration dictionary.

Example:

```python
initializer = RandomUniform(-1, 1)
config = initializer.get_config()
initializer = RandomUniform.from_config(config)
```

Args:
config: A Python dictionary, the output of `get_config`.

Returns:
A `tf.keras.initializers.Initializer` instance.


def opensearch(self, query, results=10, redirect=True):
    self._check_query(query, 'Query must be specified')
    query_params = {'action': 'opensearch', 'search': query, 'limit': (100 if (results > 100) else results), 'redirects': ('resolve' if redirect else 'return'), 'warningsaserror': True, 'namespace': ''}
    results = self.wiki_request(query_params)
    self._check_error_response(results, query)
    res = list()
    for (i, item) in enumerate(results[1]):
        res.append((item, results[2][i], results[3][i]))
    return res

Execute a MediaWiki opensearch request, similar to search box
suggestions and conforming to the OpenSearch specification

Args:
query (str): Title to search for
results (int): Number of pages within the radius to return
redirect (bool): If **False** return the redirect itself, \
otherwise resolve redirects
Returns:
List: List of results that are stored in a tuple \
(Title, Summary, URL)


def has_same_sumformula(self, other):
    same_atoms = True
    for atom in set(self['atom']):
        own_atom_number = len(self[(self['atom'] == atom)])
        other_atom_number = len(other[(other['atom'] == atom)])
        same_atoms = (own_atom_number == other_atom_number)
        if (not same_atoms):
            break
    return same_atoms

Determines if ``other``  has the same sumformula

Args:
other (molecule):

Returns:
bool:


def get_oauth_data(self, code, client_id, client_secret, state):

        request = self._get_request()
        response = request.post(self.OAUTH_TOKEN_URL, {
            "state": state,
            "code": code,
            "grant_type": "authorization_code",
            "client_id": client_id,
            "client_secret": client_secret
        })
        return HSAccessTokenAuth.from_response(response)

Get Oauth data from HelloSign

Args:

code (str):             Code returned by HelloSign for our callback url

client_id (str):        Client id of the associated app

client_secret (str):    Secret token of the associated app

Returns:
A HSAccessTokenAuth object


def random_int_generator(maxrange):

    try:
        return random.randint(0,maxrange)
    except:
        line, filename, synerror = trace()
        raise ArcRestHelperError({
                    "function": "random_int_generator",
                    "line": line,
                    "filename":  filename,
                    "synerror": synerror,
                                    }
                                    )
    finally:
        pass

Generates a random integer from 0 to `maxrange`, inclusive.

Args:
maxrange (int): The upper range of integers to randomly choose.

Returns:
int: The randomly generated integer from :py:func:`random.randint`.

Examples:
>>> arcresthelper.common.random_int_generator(15)
9


def get_airport_metars_hist(self, iata):
    url = (AIRPORT_BASE.format(iata) + '/weather')
    return self._fr24.get_airport_metars_hist(url)

Retrieve the metar data for past 72 hours. The data will not be parsed to readable format.

Given the IATA code of an airport, this method returns the metar information for last 72 hours.

Args:
iata (str): The IATA code for an airport, e.g. HYD

Returns:
The metar data for the airport

Example::

from pyflightdata import FlightData
f=FlightData()
#optional login
f.login(myemail,mypassword)
f.get_airport_metars_hist('HYD')


def packVersion(major, minor=0, patch=0):

    ret = patch & mask20
    ret = ret | (minor & mask20) << 20
    ret = ret | (major & mask20) << 20 * 2
    return ret

Pack a set of major/minor/patch integers into a single integer for storage.

Args:
major (int): Major version level integer.
minor (int): Minor version level integer.
patch (int): Patch version level integer.

Returns:
int:  System normalized integer value to represent a software version.


def bin_hash160(string):

    intermed = hashlib.sha256(string).digest()
    return hashlib.new('ripemd160', intermed).hexdigest()

Get a hash of the provided message using the ripemd160 algorithm.

Args:
string (str): message to hash.

Returns:
str: hash as a double digit hex string.


def get_coords(variant):

    coordinates = {
        'chrom': None,
        'end_chrom': None,
        'sv_length': None,
        'sv_type': None,
        'pos': None,
        'end': None,
    }
    chrom = variant.CHROM
    if chrom.startswith(('chr', 'CHR', 'Chr')):
        chrom = chrom[3:]
    coordinates['chrom'] = chrom
    end_chrom = chrom

    pos = int(variant.POS)
    alt = variant.ALT[0]

    end_pos = variant.INFO.get('END')
    if end_pos:
        end = int(end_pos)
    else:
        end = int(variant.end)
    coordinates['end'] = end

    sv_type = variant.INFO.get('SVTYPE')
    length = variant.INFO.get('SVLEN')
    if length:
        sv_len = abs(length)
    else:
        sv_len = end - pos

    if sv_type == 'BND':
        other_coordinates = alt.strip('ACGTN[]').split(':')
        end_chrom = other_coordinates[0]
        if end_chrom.startswith(('chr', 'CHR', 'Chr')):
            end_chrom = end_chrom[3:]

        end = int(other_coordinates[1])

        sv_len = float('inf')

    if (sv_len == 0 and alt != '<INS>'):
        sv_len = len(alt)

    if (pos == end) and (sv_len > 0):
        end = pos + sv_len

    position = Position(chrom, pos)
    end_position = Position(end_chrom, end)

    if is_greater(position, end_position):
        end_chrom = position.chrom
        end = position.pos

        chrom = end_position.chrom
        pos = end_position.pos

    coordinates['end_chrom'] = end_chrom
    coordinates['pos'] = pos
    coordinates['end'] = end
    coordinates['sv_length'] = sv_len
    coordinates['sv_type'] = sv_type

    return coordinates

Returns a dictionary with position information

Args:
variant(cyvcf2.Variant)

Returns:
coordinates(dict)


def get_instance(name, cls='system', storage=None, storage_parameters=None, unsecure=None, *args, **kwargs):
    system_parameters = _system_parameters(unsecure=unsecure, storage_parameters=storage_parameters)
    with _MOUNT_LOCK:
        for root in MOUNTED:
            if ((isinstance(root, Pattern) and root.match(name)) or ((not isinstance(root, Pattern)) and name.startswith(root))):
                info = MOUNTED[root]
                stored_parameters = (info.get('system_parameters') or dict())
                if (not system_parameters):
                    same_parameters = True
                    system_parameters = stored_parameters
                elif (system_parameters == stored_parameters):
                    same_parameters = True
                else:
                    same_parameters = False
                    system_parameters.update({key: value for (key, value) in stored_parameters.items() if (key not in system_parameters)})
                break
        else:
            mount_info = mount(storage=storage, name=name, **system_parameters)
            info = mount_info[tuple(mount_info)[0]]
            same_parameters = True
    if (cls == 'system'):
        if same_parameters:
            return info['system_cached']
        else:
            return info['system'](roots=info['roots'], **system_parameters)
    if same_parameters:
        if ('storage_parameters' not in system_parameters):
            system_parameters['storage_parameters'] = dict()
        system_parameters['storage_parameters']['pycosio.system_cached'] = info['system_cached']
    kwargs.update(system_parameters)
    return info[cls](*args, name=name, **kwargs)

Get a cloud object storage instance.

Args:
name (str): File name, path or URL.
cls (str): Type of class to instantiate.
'raw', 'buffered' or 'system'.
storage (str): Storage name.
storage_parameters (dict): Storage configuration parameters.
Generally, client configuration and credentials.
unsecure (bool): If True, disables TLS/SSL to improves
transfer performance. But makes connection unsecure.
Default to False.
args, kwargs: Instance arguments

Returns:
pycosio._core.io_base.ObjectIOBase subclass: Instance


def run_program(self, src, filename, maximum_depth):
    self.filename = filename
    self._maximum_depth = maximum_depth
    src = preprocess.augment_annotations(src)
    src_tree = directors.parse_src(src, self.ctx.python_version)
    code = self.compile_src(src, filename=filename, store_blockgraph=True)
    director = directors.Director(src_tree, self.ctx.errorlog, filename, self.ctx.options.disable)
    self.ctx.errorlog.set_error_filter(director.filter_error)
    self._director = director
    self.ctx.options.set_feature_flags(director.features)
    self._branch_tracker = pattern_matching.BranchTracker(director.matches, self.ctx)
    code = process_blocks.merge_annotations(code, self._director.annotations, self._director.param_annotations)
    visitor = vm_utils.FindIgnoredTypeComments(self._director.type_comments)
    pyc.visit(code, visitor)
    for line in visitor.ignored_lines():
        self.ctx.errorlog.ignored_type_comment(self.filename, line, self._director.type_comments[line])
    if self.ctx.options.debug_constant_folding:
        before = _bytecode_to_string(code)
        code = constant_folding.fold_constants(code)
        after = _bytecode_to_string(code)
        print('\n'.join(difflib.unified_diff(before.splitlines(), after.splitlines())))
    else:
        code = constant_folding.fold_constants(code)
    process_blocks.adjust_returns(code, self._director.block_returns)
    node, f_globals, f_locals, _ = self.run_bytecode(self.ctx.root_node, code)
    logging.info('Done running bytecode, postprocessing globals')
    for annot in itertools.chain.from_iterable(self.late_annotations.values()):
        annot.resolve(node, f_globals, f_locals)
        self.flatten_late_annotation(node, annot, f_globals)
    self.late_annotations = None
    assert not self.frames, 'Frames left over!'
    log.info('Final node: <%d>%s', node.id, node.name)
    return (node, f_globals.members)

Run the code and return the CFG nodes.

Args:
src: The program source code.
filename: The filename the source is from.
maximum_depth: Maximum depth to follow call chains.

Returns:
A tuple (CFGNode, set) containing the last CFGNode of the program as
well as all the top-level names defined by it.


def asn(self, as_number, **kwargs):
    indicator_obj = ASN(as_number, **kwargs)
    return self._indicator(indicator_obj)

Add ASN data to Batch object.

Args:
as_number (str): The value for this Indicator.
confidence (str, kwargs): The threat confidence for this Indicator.
date_added (str, kwargs): The date timestamp the Indicator was created.
last_modified (str, kwargs): The date timestamp the Indicator was last modified.
rating (str, kwargs): The threat rating for this Indicator.
xid (str, kwargs): The external id for this Indicator.

Returns:
obj: An instance of ASN.


def unpack(self, buff, item_class, offset=0):

        begin = offset
        limit_buff = len(buff)

        while begin < limit_buff:
            item = item_class()
            item.unpack(buff, begin)
            self.append(item)
            begin += item.get_size()

Unpack the elements of the list.

Args:
buff (bytes): The binary data to be unpacked.
item_class (:obj:`type`): Class of the expected items on this list.
offset (int): If we need to shift the beginning of the data.


def add_paths_argument(cls, group, argname, dest=None, help_=None):

        prefixed = '%s-%s' % (cls.argument_prefix, argname)
        if dest is None:
            dest = prefixed.replace('-', '_')
            final_dest = dest[len(cls.argument_prefix) + 1:]
        else:
            final_dest = dest
            dest = '%s_%s' % (cls.argument_prefix, dest)

        group.add_argument('--%s' % prefixed, action='store', nargs='+',
                           dest=dest, help=help_)
        cls.paths_arguments[dest] = final_dest

Subclasses may call this to expose a paths argument.

Args:
group: arparse.ArgumentGroup, the extension argument group
argname: str, the name of the argument, will be namespaced.
dest: str, similar to the `dest` argument of
`argparse.ArgumentParser.add_argument`, will be namespaced.
help_: str, similar to the `help` argument of
`argparse.ArgumentParser.add_argument`.


def inflate_nd_checker(identifier, definition):

        if isinstance(definition, bool):
            return Checker(name=identifier, passes=definition)
        elif isinstance(definition, dict):
            return Checker(definition.pop('name', identifier), **definition)
        else:
            raise ValueError('%s type is not supported for no-data checkers, '
                             'use bool or dict' % type(definition))

Inflate a no-data checker from a basic definition.

Args:
identifier (str): the no-data checker identifier / name.
definition (bool/dict): a boolean acting as "passes" or a full
dict definition with "passes" and "allow_failure".

Returns:
Checker: a checker instance.

Raises:
ValueError: when the definition type is not bool or dict.


def write_json(data, path, file_name):

    if os.path.exists(path) and not os.path.isdir(path):
        return
    elif not os.path.exists(path):
        mkdir_p(path)
    with open(os.path.join(path, file_name), 'w') as f:
        json_tricks.dump(data, f, indent=4, primitives=True, allow_nan=True)

Write out data to a json file.

Args:
data: A dictionary representation of the data to write out
path: The directory to output the file in
file_name: The name of the file to write out


def __init__(self, metadata,
               registry):

    self.metadata = metadata
    self.fields = stats_utils.FieldDefinitionTuplesFromProtos(
        metadata.fields_defs)
    field_names = [name for name, _ in self.fields]

    if metadata.metric_type == rdf_stats.MetricMetadata.MetricType.COUNTER:
      self.metric = prometheus_client.Counter(
          metadata.varname,
          metadata.docstring,
          labelnames=field_names,
          registry=registry)
    elif metadata.metric_type == rdf_stats.MetricMetadata.MetricType.EVENT:
      bins = metadata.bins or [
          0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.75, 1, 1.5, 2, 2.5, 3, 4, 5, 6, 7, 8,
          9, 10, 15, 20, 50, 100
      ]
      self.metric = prometheus_client.Histogram(
          metadata.varname,
          metadata.docstring,
          labelnames=field_names,
          buckets=bins,
          registry=registry)
    elif metadata.metric_type == rdf_stats.MetricMetadata.MetricType.GAUGE:
      self.metric = prometheus_client.Gauge(
          metadata.varname,
          metadata.docstring,
          labelnames=field_names,
          registry=registry)
    else:
      raise ValueError("Unknown metric type: {!r}".format(metadata.metric_type))

Instantiates a new _Metric.

Args:
metadata: An rdf_stats.MetricMetadata instance describing this _Metric.
registry: A prometheus_client.Registry instance.

Raises:
ValueError: metadata contains an unknown metric_type.


def convert_to_numpy(cls, x):
    return x

Convert a tensor to a NumPy array.

Only called after slicing using `__getitem__`.

Args:
x: the tensor to convert.
Returns: the converted tensor.


def _add_write_pbs(self, write_pbs):

        if self._read_only:
            raise ValueError(_WRITE_READ_ONLY)

        super(Transaction, self)._add_write_pbs(write_pbs)

Add `Write`` protobufs to this transaction.

Args:
write_pbs (List[google.cloud.proto.firestore.v1beta1.\
write_pb2.Write]): A list of write protobufs to be added.

Raises:
ValueError: If this transaction is read-only.


def get_mapping_function(function_name, functions_mapping):

    if function_name in functions_mapping:
        return functions_mapping[function_name]

    elif function_name in ["parameterize", "P"]:
        from httprunner import loader
        return loader.load_csv_file

    elif function_name in ["environ", "ENV"]:
        return utils.get_os_environ

    try:

        from httprunner import loader
        built_in_functions = loader.load_builtin_functions()
        return built_in_functions[function_name]
    except KeyError:
        pass

    try:

        item_func = eval(function_name)
        if callable(item_func):

            return item_func
    except (NameError, TypeError):

        raise exceptions.FunctionNotFound("{} is not found.".format(function_name))

get function from functions_mapping,
if not found, then try to check if builtin function.

Args:
variable_name (str): variable name
variables_mapping (dict): variables mapping

Returns:
mapping function object.

Raises:
exceptions.FunctionNotFound: function is neither defined in debugtalk.py nor builtin.


def setup_keyword(dist, _, value):
    if (value is not True):
        return
    dist.entry_points = _ensure_entry_points_is_dict(dist.entry_points)
    for (command, subcommands) in six.iteritems(_get_commands(dist)):
        entry_point = '{command} = rcli.dispatcher:main'.format(command=command)
        entry_points = dist.entry_points.setdefault('console_scripts', [])
        if (entry_point not in entry_points):
            entry_points.append(entry_point)
        dist.entry_points.setdefault('rcli', []).extend(subcommands)

Add autodetected commands as entry points.

Args:
dist: The distutils Distribution object for the project being
installed.
_: The keyword used in the setup function. Unused.
value: The value set to the keyword in the setup function. If the value
is not True, this function will do nothing.


def plot_pie(self, key='wall_time', minfract=0.05, **kwargs):
    timers = self.timers()
    n = len(timers)
    import matplotlib.pyplot as plt
    from matplotlib.gridspec import GridSpec
    fig = plt.gcf()
    gspec = GridSpec(n, 1)
    for (idx, timer) in enumerate(timers):
        ax = plt.subplot(gspec[(idx, 0)])
        ax.set_title(str(timer))
        timer.pie(ax=ax, key=key, minfract=minfract, show=False)
    return fig

Plot pie charts of the different timers.

Args:
key: Keyword used to extract data from timers.
minfract: Don't show sections whose relative weight is less that minfract.

Returns:
`matplotlib` figure


def _RemoveFromPool(self):
    with self.pool.lock:
        if (not self.pool.started):
            return False
        if (len(self.pool) <= self.pool.min_threads):
            return False
        self.pool._RemoveWorker(self.name)
        return True

Remove ourselves from the pool.

Returns:
True if removal was possible, and False if it was not possible.


def partial_derivative_mu(mu, sigma, low, high, data):

        pd_mu = np.sum(data - mu) / sigma ** 2
        pd_mu -= len(data) * ((norm.pdf(low, mu, sigma) - norm.pdf(high, mu, sigma))
                              / (norm.cdf(high, mu, sigma) - norm.cdf(low, mu, sigma)))
        return -pd_mu

The partial derivative with respect to the mean.

Args:
mu (float): the mean of the truncated normal
sigma (float): the std of the truncated normal
low (float): the lower truncation bound
high (float): the upper truncation bound
data (ndarray): the one dimension list of data points for which we want to calculate the likelihood

Returns:
float: the partial derivative evaluated at the given point


def _distance_graph(cls, inputs, clusters, distance_metric):
    assert isinstance(inputs, list)
    if distance_metric == SQUARED_EUCLIDEAN_DISTANCE:
        return cls._compute_euclidean_distance(inputs, clusters)
    elif distance_metric == COSINE_DISTANCE:
        return cls._compute_cosine_distance(inputs, clusters, inputs_normalized=True)
    else:
        assert False, str(distance_metric)

Computes distance between each input and each cluster center.

Args:
inputs: list of input Tensors.
clusters: cluster Tensor.
distance_metric: distance metric used for clustering

Returns:
list of Tensors, where each element corresponds to each element in inputs.
The value is the distance of each row to all the cluster centers.
Currently only Euclidean distance and cosine distance are supported.


def throw(self, exception_class, should_throw):
    return self.__copy_and_set('throws', (self._throws + [(exception_class, should_throw)]))

Defines if the an exception should be thrown after the request is sent

Args:
exception_class (class): The class of the exception to instantiate
should_throw (function): The predicate that should indicate if the exception
should be thrown. This function will be called with the response as a parameter

Returns:
The request builder instance in order to chain calls


def discount_bond_price(self, short_rate: types.RealTensor, times: types.RealTensor, maturities: types.RealTensor, name: str=None) -> types.RealTensor:
    name = name or self._name + '_discount_bond_prices'
    with tf.name_scope(name):
        short_rate = tf.convert_to_tensor(short_rate, self._dtype)
        times = tf.convert_to_tensor(times, self._dtype)
        maturities = tf.convert_to_tensor(maturities, self._dtype)
        input_shape_times = times.shape.as_list()
        times_flat = tf.reshape(times, shape=[-1])
        mean_reversion = self._mean_reversion(times_flat)
        volatility = self._volatility(times_flat)
        y_t = self._compute_yt(times_flat, mean_reversion, volatility)
        mean_reversion = tf.reshape(tf.transpose(mean_reversion), input_shape_times + [self._dim])
        y_t = tf.reshape(tf.transpose(y_t), input_shape_times + [self._dim])
        values = self._bond_reconstitution(times, maturities, mean_reversion, short_rate, y_t)
        return values

Returns zero-coupon bond prices `P(t,T)` conditional on `r(t)`.

Args:
short_rate: A `Tensor` of real dtype and shape `batch_shape + [dim]`
specifying the short rate `r(t)`.
times: A `Tensor` of real dtype and shape `batch_shape`. The time `t`
at which discount bond prices are computed.
maturities: A `Tensor` of real dtype and shape `batch_shape`. The time
to maturity of the discount bonds.
name: Str. The name to give this op.
Default value: `discount_bond_prices`.

Returns:
A `Tensor` of real dtype and the same shape as `batch_shape + [dim]`
containing the price of zero-coupon bonds.


def _add_variable_proxy_methods(var, proxy_tensor):
    proxy_tensor.read_value = (lambda : tf.identity(proxy_tensor))
    proxy_tensor.assign_sub = var.assign_sub
    proxy_tensor.assign = var.assign
    proxy_tensor.initialized_value = var.initialized_value

Proxy methods of underlying variable.

This enables our custom getters to still work with, e.g., batch norm.

Args:
var: Variable to proxy
proxy_tensor: Tensor that is identity of var


def DeserializeFrom(reader):

        ttype = reader.ReadByte()
        tx = None

        from neo.Core.TX.RegisterTransaction import RegisterTransaction
        from neo.Core.TX.IssueTransaction import IssueTransaction
        from neo.Core.TX.ClaimTransaction import ClaimTransaction
        from neo.Core.TX.MinerTransaction import MinerTransaction
        from neo.Core.TX.PublishTransaction import PublishTransaction
        from neo.Core.TX.InvocationTransaction import InvocationTransaction
        from neo.Core.TX.EnrollmentTransaction import EnrollmentTransaction
        from neo.Core.TX.StateTransaction import StateTransaction

        if ttype == int.from_bytes(TransactionType.RegisterTransaction, 'little'):
            tx = RegisterTransaction()
        elif ttype == int.from_bytes(TransactionType.MinerTransaction, 'little'):
            tx = MinerTransaction()
        elif ttype == int.from_bytes(TransactionType.IssueTransaction, 'little'):
            tx = IssueTransaction()
        elif ttype == int.from_bytes(TransactionType.ClaimTransaction, 'little'):
            tx = ClaimTransaction()
        elif ttype == int.from_bytes(TransactionType.PublishTransaction, 'little'):
            tx = PublishTransaction()
        elif ttype == int.from_bytes(TransactionType.InvocationTransaction, 'little'):
            tx = InvocationTransaction()
        elif ttype == int.from_bytes(TransactionType.EnrollmentTransaction, 'little'):
            tx = EnrollmentTransaction()
        elif ttype == int.from_bytes(TransactionType.StateTransaction, 'little'):
            tx = StateTransaction()
        else:
            tx = Transaction()
            tx.Type = ttype

        tx.DeserializeUnsignedWithoutType(reader)

        tx.scripts = []
        byt = reader.ReadVarInt()

        if byt > 0:
            for i in range(0, byt):
                witness = Witness()
                witness.Deserialize(reader)

                tx.scripts.append(witness)

        tx.OnDeserialized()

        return tx

Deserialize full object.

Args:
reader (neo.IO.BinaryReader):

Returns:
Transaction:


def buy(self, product_id, order_type, **kwargs):
    return self.place_order(product_id, 'buy', order_type, **kwargs)

Place a buy order.

This is included to maintain backwards compatibility with older versions
of cbpro-Python. For maximum support from docstrings and function
signatures see the order type-specific functions place_limit_order,
place_market_order, and place_stop_order.

Args:
product_id (str): Product to order (eg. 'BTC-USD')
order_type (str): Order type ('limit', 'market', or 'stop')
**kwargs: Additional arguments can be specified for different order
types.

Returns:
dict: Order details. See `place_order` for example.


def download_image(self, handle, dest):
    with log_utils.LogTask(('Download image %s' % handle), logger=LOGGER):
        self.open_url(url=handle, dest=dest)
    self.extract_image_xz(dest)

Downloads the image from the http server

Args:
handle (str): url from the `self.baseurl` to the remote template
dest (str): Path to store the downloaded url to, must be a file
path

Returns:
None


def discover(package, cls_match_func):

    matched_classes = set()

    for _, module_name, _ in pkgutil.walk_packages(
            package.__path__,
            prefix=package.__name__ + '.',
    ):
        module = __import__(module_name, fromlist=[str('__trash')], level=0)

        for _, imported_class in inspect.getmembers(module, inspect.isclass):

            if imported_class.__module__ != module.__name__:
                continue

            if cls_match_func(imported_class):
                matched_classes.add(imported_class)

    return matched_classes

Returns a set of classes in the directory matched by cls_match_func

Args:
path - A Python package
cls_match_func - Function taking a class and returning true if the
class is to be included in the output.


def _get_row_partition_type_tensor_pairs(rt_input):
    partitions = rt_input._nested_row_partitions
    tail = [_get_row_partition_type_tensor_pairs_tail(x) for x in partitions[1:]]
    if partitions[0]._value_rowids is not None:
        return [('FIRST_DIM_SIZE', partitions[0].nrows()), ('VALUE_ROWIDS', partitions[0].value_rowids())] + tail
    else:
        return [('ROW_SPLITS', partitions[0].row_splits())] + tail

Gets a list of the row partitions for rt_input.

If value_rowids are defined, then they are used. Otherwise, row_splits
are used. If the outermost level has value_rowids defind, then nrows is
also added.

Args:
rt_input: a ragged tensor.

Returns:
A list of (row_partition_type, row_partition_tensor) pairs.


def get_details(self, ids):
    if isinstance(ids, list):
        if (len(ids) > 5):
            ids = ids[:5]
        id_param = (';'.join(ids) + '/')
    else:
        ids = str(ids)
        id_param = (ids + '/')
    (header, content) = self._http_request(id_param)
    resp = json.loads(content)
    if (not self._is_http_response_ok(header)):
        error = resp.get('error_message', 'Unknown Error')
        raise HttpException(header.status, header.reason, error)
    return resp

Locu Venue Details API Call Wrapper

Args:
list of ids : ids of a particular venues to get insights about. Can process up to 5 ids


def __init__(self, scaffold=None, master='', config=None, max_wait_secs=30 * 60):
    self._scaffold = scaffold or Scaffold()
    self._session_manager = None
    self._master = master
    self._config = config
    self._max_wait_secs = max_wait_secs

Initializes a worker session creator.

Args:
scaffold: A `Scaffold` used for gathering or building supportive ops. If
not specified a default one is created. It's used to finalize the graph.
master: `String` representation of the TensorFlow master to use.
config: `ConfigProto` proto used to configure the session.
max_wait_secs: Maximum time to wait for the session to become available.


def stringize(
        self,
        rnf_profile=RnfProfile(),
    ):

        sorted_segments = sorted(self.segments,
         key=lambda x: (
          x.genome_id * (10 ** 23) +
          x.chr_id * (10 ** 21) +
          (x.left + (int(x.left == 0) * x.right - 1)) * (10 ** 11) +
          x.right * (10 ** 1) +
          int(x.direction == "F")
         )
        )

        segments_strings = [x.stringize(rnf_profile) for x in sorted_segments]

        read_tuple_name = "__".join(
            [
                self.prefix,
                format(self.read_tuple_id, 'x').zfill(rnf_profile.read_tuple_id_width),
                ",".join(segments_strings),
                self.suffix,
            ]
        )

        return read_tuple_name

Create RNF representation of this read.

Args:
read_tuple_id_width (int): Maximal expected string length of read tuple ID.
genome_id_width (int): Maximal expected string length of genome ID.
chr_id_width (int): Maximal expected string length of chromosome ID.
coor_width (int): Maximal expected string length of a coordinate.


def implicit_static(cls, for_type=None, for_types=None):

        for type_ in cls.__get_type_args(for_type, for_types):
            implementations = {}
            for function in cls.required():
                method = getattr(type_, function.__name__, None)
                if not callable(method):
                    raise TypeError(
                        "%s.implicit invokation on type %r is missing instance "
                        "method %r."
                        % (cls.__name__, type_, function.__name__))

                implementations[function] = method

            for function in cls.optional():
                method = getattr(type_, function.__name__, None)

                if callable(method):
                    implementations[function] = method

            return cls.implement(for_type=type_,
                                 implementations=implementations)

Automatically generate implementations for a type.

Implement the protocol for the 'for_type' type by dispatching each
member function of the protocol to an instance method of the same name
declared on the type 'for_type'.

Arguments:
for_type: The type to implictly implement the protocol with.

Raises:
TypeError if not all implementations are provided by 'for_type'.


def generate_pb_config(pb_id: str, pb_config: dict=None, workflow_config: dict=None) -> dict:
    if (workflow_config is None):
        workflow_config = dict()
    if (pb_config is None):
        pb_config = dict()
    pb_type = pb_config.get('type', choice(PB_TYPES))
    workflow_id = workflow_config.get('id')
    if (workflow_id is None):
        if (pb_type == 'offline'):
            workflow_id = choice(OFFLINE_WORKFLOWS)
        else:
            workflow_id = choice(REALTIME_WORKFLOWS)
    workflow_version = workflow_config.get('version', generate_version())
    workflow_parameters = workflow_config.get('parameters', dict())
    pb_data = dict(id=pb_id, version=__pb_version__, type=pb_type, priority=pb_config.get('priority', randint(0, 10)), dependencies=pb_config.get('dependencies', []), resources_required=pb_config.get('resources_required', []), workflow=dict(id=workflow_id, version=workflow_version, parameters=workflow_parameters))
    return pb_data

Generate a PB configuration dictionary.

Args:
pb_id (str): Processing Block Id
pb_config (dict, optional) PB configuration.
workflow_config (dict, optional): Workflow configuration

Returns:
dict, PB configuration dictionary.


class InputExample:
    example_id: str
    question: str
    contexts: list[str]
    endings: list[str]
    label: Optional[str]

A single training/test example for multiple choice

Args:
example_id: Unique id for the example.
question: string. The untokenized text of the second sequence (question).
contexts: list of str. The untokenized text of the first sequence (context of corresponding question).
endings: list of str. multiple choice's options. Its length must be equal to contexts' length.
label: (Optional) string. The label of the example. This should be
specified for train and dev examples, but not for test examples.


def training_loop_hparams_from_scoped_overrides(scoped_overrides, trial_id):

  trial_hp_overrides = scoped_overrides.values()

  loop_hp = create_loop_hparams()
  model_hp_name = trial_hp_overrides.get(
      "loop.generative_model_params", loop_hp.generative_model_params)
  model_hp = registry.hparams(model_hp_name).parse(FLAGS.hparams)
  base_algo_params_name = trial_hp_overrides.get(
      "loop.base_algo_params", loop_hp.base_algo_params)
  algo_hp = registry.hparams(base_algo_params_name)

  combined_hp = merge_unscoped_hparams(
      zip(HP_SCOPES, [loop_hp, model_hp, algo_hp]))
  combined_hp.override_from_dict(trial_hp_overrides)

  loop_hp, model_hp, algo_hp = (
      split_scoped_hparams(HP_SCOPES, combined_hp))

  model_hp_name = "model_hp_%s" % str(trial_id)
  dynamic_register_hparams(model_hp_name, model_hp)
  loop_hp.generative_model_params = model_hp_name

  algo_hp_name = "algo_hp_%s" % str(trial_id)
  dynamic_register_hparams(algo_hp_name, algo_hp)
  loop_hp.base_algo_params = algo_hp_name

  return loop_hp

Create HParams suitable for training loop from scoped HParams.

Args:
scoped_overrides: HParams, with keys all scoped by one of HP_SCOPES. These
parameters are overrides for the base HParams created by
create_loop_hparams.
trial_id: str, trial identifier. This is used to register unique HParams
names for the underlying model and ppo HParams.

Returns:
HParams suitable for passing to training_loop.


def _is_apk_install_success(stdout: bytes, stderr: str) -> bool:
    if utils.grep('Failure', stdout):
        return False
    return any([not stderr, stderr == 'Success', 'waiting for device' in stderr])

Checks output of the adb install command and decides if install succeeded.

Args:
stdout: string, the standard out output of an adb install command.
stderr: string, the standard error output of an adb install command.

Returns:
True if the installation succeeded; False otherwise.


def remove_duplicate_sg(security_groups):

    for each_sg, duplicate_sg_name in SECURITYGROUP_REPLACEMENTS.items():
        if each_sg in security_groups and duplicate_sg_name in security_groups:
            LOG.info('Duplicate SG found. Removing %s in favor of %s.', duplicate_sg_name, each_sg)
            security_groups.remove(duplicate_sg_name)

    return security_groups

Removes duplicate Security Groups that share a same name alias

Args:
security_groups (list): A list of security group id to compare against SECURITYGROUP_REPLACEMENTS

Returns:
security_groups (list): A list of security groups with duplicate aliases removed


def running_instances(self, context, process_name):

        handle = (id(context), process_name)
        it = self.processes.get(handle, {}).itervalues()
        entries = [x for x in it if x[0].poll() is None]
        return entries

Get a list of running instances.

Args:
context (`ResolvedContext`): Context the process is running in.
process_name (str): Name of the process.

Returns:
List of (`subprocess.Popen`, start-time) 2-tuples, where start_time
is the epoch time the process was added.


def _FormatSocketUnixToken(self, token_data):
    protocol = bsmtoken.BSM_PROTOCOLS.get(token_data.socket_family, 'UNKNOWN')
    return {'protocols': protocol, 'family': token_data.socket_family, 'path': token_data.socket_path}

Formats an Unix socket token as a dictionary of values.

Args:
token_data (bsm_token_data_sockunix): AUT_SOCKUNIX token data.

Returns:
dict[str, str]: token values.


def GetEntries(self, parser_mediator, match=None, **unused_kwargs):

    backup_alias_map = self._GetDataTypeMap('timemachine_backup_alias')

    destinations = match.get('Destinations', [])
    for destination in destinations:
      backup_alias_data = destination.get('BackupAlias', b'')
      try:
        backup_alias = self._ReadStructureFromByteStream(
            backup_alias_data, 0, backup_alias_map)
        alias = backup_alias.string

      except (ValueError, errors.ParseError) as exception:
        parser_mediator.ProduceExtractionWarning(
            'unable to parse backup alias value with error: {0!s}'.format(
                exception))
        alias = 'Unknown alias'

      destination_identifier = (
          destination.get('DestinationID', None) or 'Unknown device')

      event_data = plist_event.PlistTimeEventData()
      event_data.desc = 'TimeMachine Backup in {0:s} ({1:s})'.format(
          alias, destination_identifier)
      event_data.key = 'item/SnapshotDates'
      event_data.root = '/Destinations'

      snapshot_dates = destination.get('SnapshotDates', [])
      for datetime_value in snapshot_dates:
        event = time_events.PythonDatetimeEvent(
            datetime_value, definitions.TIME_DESCRIPTION_WRITTEN)
        parser_mediator.ProduceEventWithEventData(event, event_data)

Extracts relevant TimeMachine entries.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
match (Optional[dict[str: object]]): keys extracted from PLIST_KEYS.


def _run_graph(self, device, input_shape, variable, num_inputs, axis, grad, num_iters):
    graph = ops.Graph()
    with graph.as_default():
        outputs = build_graph(device, input_shape, variable, num_inputs, axis, grad)
    config = config_pb2.ConfigProto(graph_options=config_pb2.GraphOptions(optimizer_options=config_pb2.OptimizerOptions(opt_level=config_pb2.OptimizerOptions.L0)))
    with session_lib.Session(graph=graph, config=config) as session:
        variables.global_variables_initializer().run()
        _ = session.run(outputs)
        start_time = time.time()
        for _ in range(num_iters):
            _ = session.run(outputs)
        duration = time.time() - start_time
        print('%s shape:%d/%d var: %r
    name_template = 'concat_bench_{device}_input_shape_{shape}_variable_{variable}_num_inputs_{num_inputs}_axis_{axis}_grad_{grad}'
    self.report_benchmark(name=name_template.format(device=device, num_inputs=num_inputs, variable=variable, grad=grad, shape=str(input_shape).replace(' ', ''), axis=str(axis), iters=num_iters))
    return duration

Run the graph and print its execution time.

Args:
device: string, the device to run on.
input_shape: shape of the input tensors.
variable: whether or not the input shape should be fixed
num_inputs: the number of inputs to concat
axis: axis to be concat'ed
grad: if True compute the gradient
num_iters: number of steps to run.

Returns:
The duration of the run in seconds.


def wait_for_boot_completion(self, timeout=DEFAULT_TIMEOUT_BOOT_COMPLETION_SECOND):
    timeout_start = time.time()
    self.adb.wait_for_device(timeout=timeout)
    while (time.time() < (timeout_start + timeout)):
        try:
            if self.is_boot_completed():
                return
        except adb.AdbError:
            pass
        time.sleep(5)
    raise DeviceError(self, 'Booting process timed out')

Waits for Android framework to broadcast ACTION_BOOT_COMPLETED.

This function times out after 15 minutes.

Args:
timeout: float, the number of seconds to wait before timing out.
If not specified, no timeout takes effect.


def Open(self, file_object):

    if not file_object:
      raise ValueError('Missing file-like object.')

    file_object.seek(0, os.SEEK_SET)
    data = file_object.read(len(self._HEADER_SIGNATURE))

    if data != self._HEADER_SIGNATURE:
      file_object.close()
      raise IOError('Unsupported SQLite database signature.')

    with tempfile.NamedTemporaryFile(delete=False) as temp_file:
      self._temp_file_path = temp_file.name
      while data:
        temp_file.write(data)
        data = file_object.read(self._COPY_BUFFER_SIZE)

    self._connection = sqlite3.connect(self._temp_file_path)
    self._connection.text_factory = bytes
    self._cursor = self._connection.cursor()

Opens the database file object.

Args:
file_object (FileIO): file-like object.

Raises:
IOError: if the SQLite database signature does not match.
OSError: if the SQLite database signature does not match.
ValueError: if the file-like object is invalid.


def work_model_factory(*, validator=validators.is_work_model, **kwargs):
    kwargs['ld_type'] = 'AbstractWork'
    return _model_factory(validator=validator, **kwargs)

Generate a Work model.

Expects ``data``, ``validator``, ``model_cls``, and ``ld_context``
as keyword arguments.

Raises:
:exc:`ModelError`: If a non-'AbstractWork' ``ld_type`` keyword
argument is given.


def _get_head_block(self, request):
    if request.head_id:
        if (self._id_regex.fullmatch(request.head_id) is None):
            LOGGER.debug('Invalid head id requested: %s', request.head_id)
            raise _ResponseFailed(self._status.NO_ROOT)
        try:
            return self._block_store[request.head_id]
        except KeyError as e:
            LOGGER.debug('Unable to find block "%s" in store', e)
            raise _ResponseFailed(self._status.NO_ROOT)
    else:
        return self._get_chain_head()

Fetches the request specified head block, or the chain head.

Note:
This method will fail if `_block_store` has not been set

Args:
request (object): The parsed protobuf request object

Returns:
Block: the block object at the head of the requested chain

Raises:
ResponseFailed: Failed to retrieve a head block


def non_deterministic_ints(shape, dtype=dtypes.int64):
    return gen_stateful_random_ops.non_deterministic_ints(shape=shape, dtype=dtype)

Non-deterministically generates some integers.

This op may use some OS-provided source of non-determinism (e.g. an RNG), so
each execution will give different results.

Args:
shape: the shape of the result.
dtype: (optional) the dtype of the result.

Returns:
a tensor whose element values are non-deterministically chosen.


def from_file_obj(cls, fp):
    log.debug('Parsing email from file object')
    try:
        fp.seek(0)
    except IOError:
        pass
    finally:
        s = fp.read()
    return cls.from_string(s)

Init a new object from a file-like object.
Not for Outlook msg.

Args:
fp (file-like object): file-like object of raw email

Returns:
Instance of MailParser


def find_library_windows(cls):

        dll = cls.get_appropriate_windows_sdk_name() + '.dll'
        root = 'C:\\'
        for d in os.listdir(root):
            dir_path = os.path.join(root, d)

            if d.startswith('Program Files') and os.path.isdir(dir_path):
                dir_path = os.path.join(dir_path, 'SEGGER')
                if not os.path.isdir(dir_path):
                    continue

                ds = filter(lambda x: x.startswith('JLink'), os.listdir(dir_path))
                for jlink_dir in ds:

                    lib_path = os.path.join(dir_path, jlink_dir, dll)
                    if os.path.isfile(lib_path):
                        yield lib_path

Loads the SEGGER DLL from the windows installation directory.

On Windows, these are found either under:
- ``C:\\Program Files\\SEGGER\\JLink``
- ``C:\\Program Files (x86)\\SEGGER\\JLink``.

Args:
cls (Library): the ``Library`` class

Returns:
The paths to the J-Link library files in the order that they are
found.


def decrypt(key, ciphertext):
    key = ''.join(key)
    alphabet = string.ascii_letters
    cipher_alphabet = (key.lower() + key.upper())
    return ciphertext.translate(str.maketrans(cipher_alphabet, alphabet))

Decrypt Simple Substitution enciphered ``ciphertext`` using ``key``.

Example:
>>> decrypt("PQSTUVWXYZCODEBRAKINGFHJLM", "XUOOB")
HELLO

Args:
key (iterable): The key to use
ciphertext (str): The text to decrypt

Returns:
Decrypted ciphertext


def upgrade_code(self):
    if (not self.__squid):
        return ''
    have_scan_key = '{0}\\{1}\\{2}'.format(self.__reg_hive, self.__reg_upgradecode_path, self.__reg_32bit)
    if ((not self.__upgrade_codes) or (self.__reg_key_guid not in self.__upgrade_codes)):
        try:
            uc_handle = win32api.RegOpenKeyEx(getattr(win32con, self.__reg_hive), self.__reg_upgradecode_path, 0, (win32con.KEY_READ | self.__reg_32bit_access))
        except pywintypes.error as exc:
            if (exc.winerror == winerror.ERROR_FILE_NOT_FOUND):
                log.warning('Not Found %s\\%s 32bit %s', self.__reg_hive, self.__reg_upgradecode_path, self.__reg_32bit)
                return ''
            raise
        (squid_upgrade_code_all, _, _, suc_pytime) = zip(*win32api.RegEnumKeyEx(uc_handle))
        if ((have_scan_key in self.__upgrade_code_have_scan) and (self.__upgrade_code_have_scan[have_scan_key] == (squid_upgrade_code_all, suc_pytime))):
            log.debug('Scan skipped for upgrade codes, no changes (%s)', have_scan_key)
            return ''
        log.debug('Scan for upgrade codes (%s) for product codes', have_scan_key)
        for upgrade_code_squid in squid_upgrade_code_all:
            upgrade_code_guid = self.__squid_to_guid(upgrade_code_squid)
            pc_handle = win32api.RegOpenKeyEx(uc_handle, upgrade_code_squid, 0, (win32con.KEY_READ | self.__reg_32bit_access))
            (_, pc_val_count, _) = win32api.RegQueryInfoKey(pc_handle)
            for item_index in range(pc_val_count):
                product_code_guid = self.__squid_to_guid(win32api.RegEnumValue(pc_handle, item_index)[0])
                if product_code_guid:
                    self.__upgrade_codes[product_code_guid] = upgrade_code_guid
            win32api.RegCloseKey(pc_handle)
        win32api.RegCloseKey(uc_handle)
        self.__upgrade_code_have_scan[have_scan_key] = (squid_upgrade_code_all, suc_pytime)
    return self.__upgrade_codes.get(self.__reg_key_guid, '')

For installers which follow the Microsoft Installer standard, returns
the ``Upgrade code``.

Returns:
value (str): ``Upgrade code`` GUID for installed software.


def get_arguments(context):
    context.assert_key_has_value(key='pype', caller=__name__)
    pype = context.get_formatted('pype')
    try:
        pipeline_name = pype['name']
        if (pipeline_name is None):
            raise KeyInContextHasNoValueError("pypyr.steps.pype ['pype']['name'] exists but is empty.")
    except KeyError as err:
        raise KeyNotInContextError("pypyr.steps.pype missing 'name' in the 'pype' context item. You need to specify the pipeline name to run another pipeline.") from err
    use_parent_context = pype.get('useParentContext', True)
    pipe_arg = pype.get('pipeArg', None)
    skip_parse = pype.get('skipParse', True)
    raise_error = pype.get('raiseError', True)
    loader = pype.get('loader', None)
    return (pipeline_name, use_parent_context, pipe_arg, skip_parse, raise_error, loader)

Parse arguments for pype from context and assign default values.

Args:
context: pypyr.context.Context. context is mandatory.

Returns:
tuple (pipeline_name, #str
use_parent_context, #bool
pipe_arg, #str
skip_parse, #bool
raise_error #bool
)

Raises:
pypyr.errors.KeyNotInContextError: if ['pype']['name'] is missing.
pypyr.errors.KeyInContextHasNoValueError: if ['pype']['name'] exists but
is None.


def get_protocol_version(protocol=None, target=None):

    target = get_py_internals(target)

    if protocol is None:
        protocol = target['pickle_default_protocol']

    if protocol > cPickle.HIGHEST_PROTOCOL:
        warnings.warn('Downgrading pickle protocol, running python supports up to %d.' % cPickle.HIGHEST_PROTOCOL)
        protocol = cPickle.HIGHEST_PROTOCOL

    target_highest_protocol = target['pickle_highest_protocol']
    if protocol > target_highest_protocol:
        warnings.warn('Downgrading pickle protocol, target python supports up to %d.' % target_highest_protocol)
        protocol = target_highest_protocol

    return protocol

Return a suitable pickle protocol version for a given target.

Arguments:
target: The internals description of the targeted python
version. If this is ``None`` the specification of the currently
running python version will be used.
protocol(None or int): The requested protocol version (or None for the
default of the target python version).

Returns:
int: A suitable pickle protocol version.


def preprocess_input(x, data_format=None):
    return x

A placeholder method for backward compatibility.

The preprocessing logic has been included in the convnext model
implementation. Users are no longer required to call this method to
normalize the input data. This method does nothing and only kept as a
placeholder to align the API surface between old and new version of model.

Args:
x: A floating point `numpy.array` or a tensor.
data_format: Optional data format of the image tensor/array. Defaults to
None, in which case the global setting
`keras.backend.image_data_format()` is used
(unless you changed it, it defaults to `"channels_last"`).{mode}

Returns:
Unchanged `numpy.array` or tensor.


def generate_packer_filename(provider, region, builder):
    filename = '{0}_{1}_{2}.json'.format(provider, region, builder)
    return filename

Generate a filename to be used by packer.

Args:
provider (str): Name of Spinnaker provider.
region (str): Name of provider region to use.
builder (str): Name of builder process type.

Returns:
str: Generated filename based on parameters.


def get_ip_address_country(ip_address, parallel=False):

    def download_country_database(location="GeoLite2-Country.mmdb"):

        if parallel:
            logging.warning("Cannot download GeoIP database in parallel mode")
            return
        url = "https:
              "GeoLite2-Country.tar.gz"

        headers = {"User-Agent": USER_AGENT}
        original_filename = "GeoLite2-Country.mmdb"
        try:
            response = requests.get(url, headers=headers)
            response.raise_for_status()
            tar_bytes = response.content
            tar_file = tarfile.open(fileobj=BytesIO(tar_bytes), mode="r:gz")
            tar_dir = tar_file.getnames()[0]
            tar_path = "{0}/{1}".format(tar_dir, original_filename)
            tar_file.extract(tar_path)
            shutil.move(tar_path, location)
            shutil.rmtree(tar_dir)
        except Exception as e:
            logger.warning("Error downloading {0}: {1}".format(url,
                                                               e.__str__()))

    system_paths = [
        "GeoLite2-Country.mmdb",
        "/usr/local/share/GeoIP/GeoLite2-Country.mmdb",
        "/usr/share/GeoIP/GeoLite2-Country.mmdb",
        "/var/lib/GeoIP/GeoLite2-Country.mmdb",
        "/var/local/lib/GeoIP/GeoLite2-Country.mmdb",
        "C:\\GeoIP\\GeoLite2-Country.mmdb"
    ]

    db_path = None

    for system_path in system_paths:
        if os.path.exists(system_path):
            db_path = system_path
            break

    if db_path is None:
        db_path = os.path.join(tempdir, "GeoLite2-Country.mmdb")
        if not os.path.exists(db_path):
            download_country_database(db_path)
            if not os.path.exists(db_path):
                return None
        else:
            db_age = datetime.now() - datetime.fromtimestamp(
                os.stat(db_path).st_mtime)
            if db_age > timedelta(days=7):
                download_country_database()
        db_path = db_path

    db_reader = geoip2.database.Reader(db_path)

    country = None

    try:
        country = db_reader.country(ip_address).country.iso_code
    except geoip2.errors.AddressNotFoundError:
        pass

    return country

Uses the MaxMind Geolite2 Country database to return the ISO code for the
country associated with the given IPv4 or IPv6 address

Args:
ip_address (str): The IP address to query for
parallel (bool): Parallel processing

Returns:
str: And ISO country code associated with the given IP address


def as_money(self, number, **options):
    if isinstance(number, list):
        return map((lambda val: self.as_money(val, **options)))
    decimal = options.get('decimal')
    number = self.parse(number, decimal)
    if check_type(options, 'dict'):
        options = self.settings['currency'].update(options)
    formats = self._check_currency_format(options['format'])
    use_format = (lambda num: (formats['pos'] if (num > 0) else (formats['neg'] if (num < 0) else formats['zero'])))(number)
    precision = self._change_precision(number, options['precision'])
    thousands = options['thousand']
    decimal = options['decimal']
    formater = self.format(abs(number), precision, thousands, decimal)
    amount = use_format.replace('%s', options['symbol']).replace('%v', formater)
    return amount

Format a number into currency.

Usage: accounting.formatMoney(number, symbol, precision, thousandsSep,
decimalSep, format)
defaults: (0, "$", 2, ",", ".", "%s%v")
Localise by overriding the symbol, precision,
thousand / decimal separators and format
Second param can be an object matching `settings.currency`
which is the easiest way.

Args:
number (TYPE): Description
precision (TYPE): Description
thousand (TYPE): Description
decimal (TYPE): Description

Returns:
name (TYPE): Description


def sun_events(latitude, longitude, date, timezone=0, zenith=None):
    return (sun_rise_set(latitude, longitude, date, 'rise', timezone, zenith), sun_rise_set(latitude, longitude, date, 'set', timezone, zenith))

Convenience function for calculating sunrise and sunset.

Civil twilight starts/ends when the Sun's centre is 6 degrees below
the horizon.

Nautical twilight starts/ends when the Sun's centre is 12 degrees
below the horizon.

Astronomical twilight starts/ends when the Sun's centre is 18 degrees below
the horizon.

Args:
latitude (float): Location's latitude
longitude (float): Location's longitude
date (datetime.date): Calculate rise or set for given date
timezone (int): Offset from UTC in minutes
zenith (str): Calculate rise/set events, or twilight times

Returns:
tuple of datetime.time: The time for the given events in the specified
timezone


def parse_functions(
    bels: list, char_locs: CharLocs, parsed: Parsed, errors: Errors
) -> Tuple[Parsed, Errors]:

    parens = char_locs["parens"]

    if not parens:
        bels_len = len(bels) - 1
        span = (0, bels_len)
        parsed[span] = {
            "name": "".join(bels),
            "type": "Function",
            "span": span,
            "name_span": (span),
            "function_level": "top",
        }
        return parsed, errors

    for sp in sorted(parens):
        ep, function_level = parens[sp]

        if bels[sp - 1] == " ":
            continue

        for i in range(sp - 1, 0, -1):
            if bels[i] in [" ", ",", "("]:
                if i < sp - 1:
                    if ep == -1:
                        span = (i + 1, len(bels) - 1)
                    else:
                        span = (i + 1, ep)

                    parsed[span] = {
                        "name": "".join(bels[i + 1 : sp]),
                        "type": "Function",
                        "span": span,
                        "name_span": (i + 1, sp - 1),
                        "parens_span": (sp, ep),
                        "function_level": function_level,
                    }
                break
        else:
            if ep == -1:
                span = (0, len(bels) - 1)
            else:
                span = (0, ep)

            parsed[span] = {
                "name": "".join(bels[0:sp]),
                "type": "Function",
                "span": span,
                "name_span": (0, sp - 1),
                "parens_span": (sp, ep),
                "function_level": function_level,
            }

    return parsed, errors

Parse functions from BEL using paren, comma, quote character locations

Args:
bels: BEL string as list of chars
char_locs: paren, comma, quote character locations
errors: Any error messages generated during the parse

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


def url(self, pattern, method=None, name=None):

    def _inner(call):
        self._url_manager.add(pattern, method, call, name)
        return call
    return _inner

Decorator to map url pattern to the callable.

Args:
pattern (:obj:`str`): URL pattern to add. This is usually '/'
separated path. Parts of the URL can be parameterised using
curly braces.
Examples: "/", "/path/to/resource", "/resoures/{param}"
method (:obj:`str`, :obj:`list` of :obj:`str`, optional): HTTP
methods for the path specied. By default, GET method is added.
Value can be either a single method, by passing a string, or
multiple methods, by passing a list of strings.
name (:obj:`str`): Name for the pattern that can be used for
reverse matching

Note:
A trailing '/' is always assumed in the pattern.

Example:
>>> @app.url(pattern='/path/to/resource', method='GET')
>>> def function(ctx):
>>>     return 'Hello world'

See Also:
:func:`drongo.managers.url.UrlManager.add`


def _get_colordata(bs, elements, bs_projection):

        contribs = {}
        if bs_projection and bs_projection.lower() == "elements":
            projections = bs.get_projection_on_elements()

        for spin in (Spin.up, Spin.down):
            if spin in bs.bands:
                contribs[spin] = []
                for band_idx in range(bs.nb_bands):
                    colors = []
                    for k_idx in range(len(bs.kpoints)):
                        if bs_projection and bs_projection.lower() == "elements":
                            c = [0, 0, 0]
                            projs = projections[spin][band_idx][k_idx]

                            projs = dict(
                                [(k, v ** 2) for k, v in projs.items()])
                            total = sum(projs.values())
                            if total > 0:
                                for idx, e in enumerate(elements):
                                    c[idx] = math.sqrt(projs[
                                                           e] / total)

                            c = [c[1], c[2],
                                 c[0]]

                        else:
                            c = [0, 0, 0] if spin == Spin.up \
                                else [0, 0,
                                      1]

                        colors.append(c)

                    contribs[spin].append(colors)
                contribs[spin] = np.array(contribs[spin])

        return contribs

Get color data, including projected band structures
Args:
bs: Bandstructure object
elements: elements (in desired order) for setting to blue, red, green
bs_projection: None for no projection, "elements" for element projection

Returns:


def _alter_code(code, **attrs):
    PyCode_New = ctypes.pythonapi.PyCode_New
    PyCode_New.argtypes = (ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.py_object, ctypes.py_object, ctypes.py_object, ctypes.py_object, ctypes.py_object, ctypes.py_object, ctypes.py_object, ctypes.py_object, ctypes.c_int, ctypes.py_object)
    PyCode_New.restype = ctypes.py_object
    args = [[code.co_argcount, 'co_argcount'], [code.co_kwonlyargcount, 'co_kwonlyargcount'], [code.co_nlocals, 'co_nlocals'], [code.co_stacksize, 'co_stacksize'], [code.co_flags, 'co_flags'], [code.co_code, 'co_code'], [code.co_consts, 'co_consts'], [code.co_names, 'co_names'], [code.co_varnames, 'co_varnames'], [code.co_freevars, 'co_freevars'], [code.co_cellvars, 'co_cellvars'], [code.co_filename, 'co_filename'], [code.co_name, 'co_name'], [code.co_firstlineno, 'co_firstlineno'], [code.co_lnotab, 'co_lnotab']]
    for arg in args:
        if (arg[1] in attrs):
            arg[0] = attrs[arg[1]]
    return PyCode_New(args[0][0], args[1][0], args[2][0], args[3][0], args[4][0], args[5][0], args[6][0], args[7][0], args[8][0], args[9][0], args[10][0], args[11][0], args[12][0], args[13][0], args[14][0])

Create a new code object by altering some of ``code`` attributes

Args:
code: code objcect
attrs: a mapping of names of code object attrs to their values


def all_cities():
    cities = []
    fname = pkg_resources.resource_filename(__name__, 'resources/CityPops.csv')
    with open(fname, 'rU') as csvfile:
        reader = csv.reader(csvfile, delimiter=',')
        for row in reader:
            cities.append(row[0])
    cities.sort()
    return cities

Get a list of all Backpage city names.

Returns:
list of city names as Strings


def BuildParamsWithMask(self, graph_fn, dtype, input_shapes, output_shapes, input_mask, output_mask, extra_inputs, extra_outputs):

    def _ValidateShapes(shapes):
        for shape in shapes:
            assert all(shape), f'Shape unspecified: {shape}'
    _ValidateShapes(input_shapes)
    _ValidateShapes(output_shapes)
    assert len(input_mask) == len(input_shapes), f'Inconsistent input_mask and input_shapes: len({input_mask}) != len({input_shapes}).'
    assert len(output_mask) == len(output_shapes), f'Inconsistent output_mask and output_shapes: len({output_mask}) != len({output_shapes}).'
    for extra_in_shape, extra_out_shape in zip(extra_inputs, extra_outputs):
        assert len(input_shapes) == len(extra_in_shape), f'Inconsistent input_shapes and extra_in_shape: len({input_shapes}) != len({extra_in_shape}).'
        assert len(output_shapes) == len(extra_out_shape), f'Inconsistent output_shapes and extra_out_shape: len({output_shapes}) != len({extra_out_shape}).'
    return TfTrtIntegrationTestParams(graph_fn=graph_fn, input_specs=[self._GetTensorSpec(shape, mask, dtype, 'input_%d' % i) for i, (shape, mask) in enumerate(zip(input_shapes, input_mask))], output_specs=[self._GetTensorSpec(shape, mask, dtype, 'output_%d' % i) for i, (shape, mask) in enumerate(zip(output_shapes, output_mask))], input_dims=[input_shapes] + extra_inputs, expected_output_dims=[output_shapes] + extra_outputs)

Build test parameters with static or dynamic input shapes.

To define dynamic shapes give a boolean mask that describes which
dimensions to treat as known. The values in input_mask are interpreted the
following way:
- True: known dim (use the corresponding value from input_shapes)
- False: unknown dim (replace the corresponding value from input_shapes
with None)
For example, to define the first two dimension with unknown size use
input_shapes=[[1,2,1,8]], input_mask=[[False, False, True, True]].

Args:
graph_fn: The function to build the graph.
dtype: The element type.
input_shapes: The input shapes.
output_shapes: The output shapes.
input_mask: The input shape masks.
output_mask: the output shape masks.
extra_inputs: list of additional input shapes
extra_outputs: list of additional outputs shapes

Returns:
The test parameters.


def process_file(filename: str,
                 filetypes: List[str],
                 move_to: str,
                 delete_if_not_specified_file_type: bool,
                 show_zip_output: bool) -> None:

    try:
        reader = CorruptedOpenXmlReader(filename,
                                        show_zip_output=show_zip_output)
        if reader.file_type in filetypes:
            log.info("Found {}: {}", reader.description, filename)
            if move_to:
                dest_file = os.path.join(move_to, os.path.basename(filename))
                _, ext = os.path.splitext(dest_file)
                if ext != reader.suggested_extension():
                    dest_file += reader.suggested_extension()
                reader.move_to(destination_filename=dest_file)
        else:
            log.info("Unrecognized or unwanted contents: " + filename)
            if delete_if_not_specified_file_type:
                log.info("Deleting: " + filename)
                os.remove(filename)
    except Exception as e:

        log.critical("Uncaught error in subprocess: {!r}\n{}", e,
                     traceback.format_exc())
        raise

Deals with an OpenXML, including if it is potentially corrupted.

Args:
filename: filename to process
filetypes: list of filetypes that we care about, e.g.
``['docx', 'pptx', 'xlsx']``.
move_to: move matching files to this directory
delete_if_not_specified_file_type: if ``True``, and the file is **not**
a type specified in ``filetypes``, then delete the file.
show_zip_output: show the output from the external ``zip`` tool?


def get_book_progress(self, asin):
    kbp = self._get_api_call('get_book_progress', ('"%s"' % asin))
    return KindleCloudReaderAPI._kbp_to_progress(kbp)

Returns the progress data available for a book.

NOTE: A summary of the two progress formats can be found in the
docstring for `ReadingProgress`.

Args:
asin: The asin of the book to be queried.

Returns:
A `ReadingProgress` instance corresponding to the book associated with
`asin`.


def add_toolkit(topology, location):

    import streamsx.topology.topology
    assert isinstance(topology, streamsx.topology.topology.Topology)
    tkinfo = dict()
    tkinfo['root'] = os.path.abspath(location)
    topology.graph._spl_toolkits.append(tkinfo)

Add an SPL toolkit to a topology.

Args:
topology(Topology): Topology to include toolkit in.
location(str): Location of the toolkit directory.


def get_obj(self, objpath, metahash, dst_path):

        incachepath = self.path_in_cache(objpath, metahash)
        if not os.path.exists(incachepath):
            raise CacheMiss('%s not in cache.' % incachepath)
        else:
            log.debug('Cache hit! %s~%s', objpath, metahash.hexdigest())
            if not os.path.exists(os.path.dirname(dst_path)):
                os.makedirs(os.path.dirname(dst_path))
            os.link(incachepath, dst_path)

Get object from cache, write it to dst_path.

Args:
objpath: filename relative to buildroot
(example: mini-boot/blahblah/somefile.bin)
metahash: metahash. See targets/base.py
dst_path: Absolute path where the file should be written.
Raises:
CacheMiss: if the item is not in the cache


def is_generator_function(obj):
    CO_GENERATOR = 32
    return bool(((inspect.isfunction(obj) or inspect.ismethod(obj)) and (obj.func_code.co_flags & CO_GENERATOR)))

Return true if the object is a user-defined generator function.

Generator function objects provides same attributes as functions.
See isfunction.__doc__ for attributes listing.

Adapted from Python 2.6.

Args:
obj: an object to test.

Returns:
true if the object is generator function.


def _log_submission(submission, student_item):
    logger.info(u'Created submission uuid={submission_uuid} for (course_id={course_id}, item_id={item_id}, anonymous_student_id={anonymous_student_id})'.format(submission_uuid=submission['uuid'], course_id=student_item['course_id'], item_id=student_item['item_id'], anonymous_student_id=student_item['student_id']))

Log the creation of a submission.

Args:
submission (dict): The serialized submission model.
student_item (dict): The serialized student item model.

Returns:
None


def GetFileEntryByPath(self, path):

    if path is None:
      return None

    file_entry_type, _ = self._paths.get(path, (None, None))
    if not file_entry_type:
      return None

    path_spec = fake_path_spec.FakePathSpec(location=path)
    return fake_file_entry.FakeFileEntry(
        self._resolver_context, self, path_spec,
        file_entry_type=file_entry_type)

Retrieves a file entry for a path.

Args:
path (str): path of the file entry.

Returns:
FakeFileEntry: a file entry or None if not available.


def pmean(tensor, axis_name=None):
    if axis_name != _pmap_config.axis_name():
        raise ValueError('axis_name (%s) is not equal to that of the surrounding pmap (%s)' % (axis_name, _pmap_config.axis_name()))
    devices = _pmap_config.devices()
    if devices is None:
        raise ValueError("Can't retrieve the device list from the surrounding pmap")
    if tpu_devices(devices):
        raise ValueError('pmean for TPU is not supported yet.')
    else:
        return gen_collective_ops.collective_reduce(input=tensor, group_size=len(devices), group_key=_GROUP_KEY, instance_key=_get_instance_key(), merge_op='Add', final_op='Div', subdiv_offsets=(0,))

Mean all-reduction.

Args:
tensor: A tensor.
axis_name: The axis name to reduce. Must equal to that of the surrounding
pmap.

Returns:
The mean of the `tensor` replicas on each participating devices.


def defaults(cls, *options, **kwargs):

        if kwargs and len(kwargs) != 1 and list(kwargs.keys())[0] != 'backend':
            raise Exception('opts.defaults only accepts "backend" keyword argument')

        cls._linemagic(cls._expand_options(merge_options_to_dict(options)), backend=kwargs.get('backend'))

Set default options for a session.

Set default options for a session. whether in a Python script or
a Jupyter notebook.

Args:
*options: Option objects used to specify the defaults.
backend:  The plotting extension the options apply to


def abort_expired_batches(self, request_timeout_ms, cluster):
    expired_batches = []
    to_remove = []
    count = 0
    for tp in list(self._batches.keys()):
        assert (tp in self._tp_locks), 'TopicPartition not in locks dict'
        if (tp in self.muted):
            continue
        with self._tp_locks[tp]:
            dq = self._batches[tp]
            for batch in dq:
                is_full = bool((bool((batch != dq[(- 1)])) or batch.records.is_full()))
                if batch.maybe_expire(request_timeout_ms, self.config['retry_backoff_ms'], self.config['linger_ms'], is_full):
                    expired_batches.append(batch)
                    to_remove.append(batch)
                    count += 1
                    self.deallocate(batch)
                else:
                    break
            if to_remove:
                for batch in to_remove:
                    dq.remove(batch)
                to_remove = []
    if expired_batches:
        log.warning('Expired %d batches in accumulator', count)
    return expired_batches

Abort the batches that have been sitting in RecordAccumulator for
more than the configured request_timeout due to metadata being
unavailable.

Arguments:
request_timeout_ms (int): milliseconds to timeout
cluster (ClusterMetadata): current metadata for kafka cluster

Returns:
list of ProducerBatch that were expired


def on_snapshot(self, proto):
    TargetChange = firestore_pb2.TargetChange
    target_changetype_dispatch = {TargetChange.NO_CHANGE: self._on_snapshot_target_change_no_change, TargetChange.ADD: self._on_snapshot_target_change_add, TargetChange.REMOVE: self._on_snapshot_target_change_remove, TargetChange.RESET: self._on_snapshot_target_change_reset, TargetChange.CURRENT: self._on_snapshot_target_change_current}
    target_change = proto.target_change
    if str(target_change):
        target_change_type = target_change.target_change_type
        _LOGGER.debug(('on_snapshot: target change: ' + str(target_change_type)))
        meth = target_changetype_dispatch.get(target_change_type)
        if (meth is None):
            _LOGGER.info(('on_snapshot: Unknown target change ' + str(target_change_type)))
            self.close(reason=('Unknown target change type: %s ' % str(target_change_type)))
        else:
            try:
                meth(proto)
            except Exception as exc2:
                _LOGGER.debug(('meth(proto) exc: ' + str(exc2)))
                raise
    elif str(proto.document_change):
        _LOGGER.debug('on_snapshot: document change')
        target_ids = (proto.document_change.target_ids or [])
        removed_target_ids = (proto.document_change.removed_target_ids or [])
        changed = False
        removed = False
        if (WATCH_TARGET_ID in target_ids):
            changed = True
        if (WATCH_TARGET_ID in removed_target_ids):
            removed = True
        if changed:
            _LOGGER.debug('on_snapshot: document change: CHANGED')
            document_change = proto.document_change
            document = document_change.document
            data = _helpers.decode_dict(document.fields, self._firestore)
            document_name = document.name
            db_str = self._firestore._database_string
            db_str_documents = (db_str + '/documents/')
            if document_name.startswith(db_str_documents):
                document_name = document_name[len(db_str_documents):]
            document_ref = self._firestore.document(document_name)
            snapshot = self.DocumentSnapshot(reference=document_ref, data=data, exists=True, read_time=None, create_time=document.create_time, update_time=document.update_time)
            self.change_map[document.name] = snapshot
        elif removed:
            _LOGGER.debug('on_snapshot: document change: REMOVED')
            document = proto.document_change.document
            self.change_map[document.name] = ChangeType.REMOVED
    elif str(proto.document_delete):
        _LOGGER.debug('on_snapshot: document change: DELETE')
        name = proto.document_delete.document
        self.change_map[name] = ChangeType.REMOVED
    elif str(proto.document_remove):
        _LOGGER.debug('on_snapshot: document change: REMOVE')
        name = proto.document_remove.document
        self.change_map[name] = ChangeType.REMOVED
    elif proto.filter:
        _LOGGER.debug('on_snapshot: filter update')
        if (proto.filter.count != self._current_size()):
            self._reset_docs()
    else:
        _LOGGER.debug('UNKNOWN TYPE. UHOH')
        self.close(reason=ValueError(('Unknown listen response type: %s' % proto)))

Called everytime there is a response from listen. Collect changes
and 'push' the changes in a batch to the customer when we receive
'current' from the listen response.

Args:
listen_response(`google.cloud.firestore_v1beta1.types.ListenResponse`):
Callback method that receives a object to


def GetLastHealthyElement(self):
    for element in reversed(self.elements):
        if not element.HasError():
            return element
    return self.elements[0]

Returns the last element of the trace that is not an error.

This element will contain the final component indicated by the trace.

Returns:
The last element of the trace that is not an error.


def __init__(self, args):

        self.args = args.args
        self.varargs = args.vararg
        self.kwarg = args.kwarg
        self.kwonlyargs = args.kwonlyargs
        self.defaults = args.defaults
        self.kw_defaults = args.kw_defaults

        self.arguments = list()
        if self.args:
            self.arguments.extend([x.arg for x in self.args])
        if self.varargs:
            self.arguments.extend(self.varargs.arg)
        if self.kwarg:
            self.arguments.extend(self.kwarg.arg)
        if self.kwonlyargs:
            self.arguments.extend([x.arg for x in self.kwonlyargs])

Argument container class.

Args:
args(list(ast.args): The arguments in a function AST node.


def build_cfg(cls, node):

    if not isinstance(node, gast.FunctionDef):
      raise TypeError('input must be a function definition')
    cfg = cls()
    cfg.entry = Node(node.args)
    cfg.head = [cfg.entry]
    cfg.visit_statements(node.body)
    cfg.exit = Node(None)
    cfg.set_head(cfg.exit)
    cfg.backlink(cfg.entry)
    return cfg

Build a CFG for a function.

Args:
node: A function definition the body of which to analyze.

Returns:
A CFG object.

Raises:
TypeError: If the input is not a function definition.


def pairwise_intersection(boxlist1, boxlist2):

    x_min1, y_min1, x_max1, y_max1 = tf.split(boxlist1, 4, axis=1)
    x_min2, y_min2, x_max2, y_max2 = tf.split(boxlist2, 4, axis=1)
    all_pairs_min_ymax = tf.minimum(y_max1, tf.transpose(y_max2))
    all_pairs_max_ymin = tf.maximum(y_min1, tf.transpose(y_min2))
    intersect_heights = tf.maximum(0.0, all_pairs_min_ymax - all_pairs_max_ymin)
    all_pairs_min_xmax = tf.minimum(x_max1, tf.transpose(x_max2))
    all_pairs_max_xmin = tf.maximum(x_min1, tf.transpose(x_min2))
    intersect_widths = tf.maximum(0.0, all_pairs_min_xmax - all_pairs_max_xmin)
    return intersect_heights * intersect_widths

Compute pairwise intersection areas between boxes.

Args:
boxlist1: Nx4 floatbox
boxlist2: Mx4

Returns:
a tensor with shape [N, M] representing pairwise intersections


def transformer_revnet_decoder(decoder_input,
                               encoder_output,
                               decoder_self_attention_bias,
                               encoder_decoder_attention_bias,
                               hparams,
                               name="decoder"):

  def f(x, side_input):

    decoder_self_attention_bias = side_input[0]
    encoder_decoder_attention_bias = side_input[1]
    encoder_output = side_input[2]

    old_hid_size = hparams.hidden_size
    hparams.hidden_size = old_hid_size

    with tf.variable_scope("self_attention"):
      y = common_attention.multihead_attention(
          common_layers.layer_preprocess(
              x, hparams), None, decoder_self_attention_bias,
          hparams.attention_key_channels or hparams.hidden_size,
          hparams.attention_value_channels or hparams.hidden_size,
          hparams.hidden_size, hparams.num_heads, hparams.attention_dropout)
      y = common_layers.layer_postprocess(x, y, hparams)
      if encoder_output is not None:
        with tf.variable_scope("encdec_attention"):
          y = common_attention.multihead_attention(
              common_layers.layer_preprocess(
                  x, hparams), encoder_output, encoder_decoder_attention_bias,
              hparams.attention_key_channels or hparams.hidden_size,
              hparams.attention_value_channels or hparams.hidden_size,
              hparams.hidden_size, hparams.num_heads, hparams.attention_dropout)
          y = common_layers.layer_postprocess(x, y, hparams)
    hparams.hidden_size = old_hid_size
    return y

  def g(x):

    old_hid_size = hparams.hidden_size
    hparams.hidden_size = old_hid_size
    with tf.variable_scope("ffn"):
      y = transformer.transformer_ffn_layer(
          common_layers.layer_preprocess(x, hparams), hparams)
      y = common_layers.layer_postprocess(x, y, hparams)
    hparams.hidden_size = old_hid_size
    return y

  x1, x2 = tf.split(decoder_input, 2, axis=-1)

  with tf.variable_scope(name):
    y1, y2 = tf.contrib.layers.rev_block(
        x1,
        x2,
        f,
        g,
        num_layers=hparams.num_hidden_layers,
        f_side_input=[
            decoder_self_attention_bias, encoder_decoder_attention_bias,
            encoder_output
        ],
        is_training=hparams.mode == tf.estimator.ModeKeys.TRAIN)
    y = tf.concat([y1, y2], axis=-1)
    return common_layers.layer_preprocess(y, hparams)

A stack of transformer layers.

Args:
decoder_input: a Tensor
encoder_output: a Tensor
decoder_self_attention_bias: bias Tensor for self-attention
(see common_attention.attention_bias())
encoder_decoder_attention_bias: bias Tensor for encoder-decoder attention
(see common_attention.attention_bias())
hparams: hyperparameters for model
name: a string

Returns:
y: a Tensors


def gather_available_device_info():
    device_info_list = []
    devices = device_lib.list_local_devices()
    for d in devices:
        device_info = test_log_pb2.AvailableDeviceInfo()
        device_info.name = d.name
        device_info.type = d.device_type
        device_info.memory_limit = d.memory_limit
        device_info.physical_description = d.physical_device_desc
        device_info_list.append(device_info)
    return device_info_list

Gather list of devices available to TensorFlow.

Returns:
A list of test_log_pb2.AvailableDeviceInfo messages.


def restore(self, state):

        own_properties = set(self.get_properties())
        state_properties = set(state)

        to_restore = own_properties.intersection(state_properties)

        for name in to_restore:
            value = state.get(name)

            if name in self._complex_properties:
                value = self._complex_properties[name][1](value)

            setattr(self, name, value)

Restore this state from the output of a previous call to dump().

Only those properties in this object and listed in state will be
updated.  Other properties will not be modified and state may contain
keys that do not correspond with properties in this object.

Args:
state (dict): A serialized representation of this object.


def set(self, **kwargs):
    for (port_name, port_value) in kwargs.items():
        if hasattr(port_value, 'value'):
            port_value = port_value.value
        self.inputs.__setattr__(port_name, port_value)

Set input values on task

Args:
arbitrary_keys: values for the keys

Returns:
None


def matches(x, y, regex_expr=False):

    x = strip_regex(x) if regex_expr and isregex_expr(x) else x

    if PY_3:

        x = x.pattern if isregex(x) else x

        return test_case().assertRegex(y, x) or True

    if isinstance(x, str):
        x = re.compile(x, re.IGNORECASE)

    assert x.match(y) is not None

Tries to match a regular expression value ``x`` against ``y``.
Aliast``unittest.TestCase.assertEqual()``

Arguments:
x (regex|str): regular expression to test.
y (str): value to match.
regex_expr (bool): enables regex string based expression matching.

Raises:
AssertionError: in case of mismatching.

Returns:
bool


def local_reduction_attention(x, block_length, multihead_params):

    @expert_utils.add_name_scope()
    def dot_product_self_local_attention_flattened(q, k, v):
        'Strided block local self-attention.\n\n    No overlap between the blocks.\n\n    Args:\n      q (tf.Tensor): shape [batch, heads, length, depth_k]\n      k (tf.Tensor): shape [batch, heads, length, depth_k]\n      v (tf.Tensor): shape [batch, heads, length, depth_v]\n\n    Returns:\n      tf.Tensor: shape [batch, heads, length, depth_v]\n    '
        (_, num_head, _, depth) = q.get_shape().as_list()

        def pad_and_reshape(x):
            'Split the length dim into [num_block, block_length].'
            length_x = common_layers.shape_list(x)[2]
            x = tf.pad(x, [[0, 0], [0, 0], [0, ((- length_x) % block_length)], [0, 0]])
            x = tf.reshape(x, [common_layers.shape_list(x)[0], num_head, (common_layers.shape_list(x)[2]
            return x
        (q, k, v) = [pad_and_reshape(t) for t in (q, k, v)]
        logits = tf.matmul(q, k, transpose_b=True)
        logits = tf.reshape(logits, [common_layers.shape_list(logits)[0], num_head, common_layers.shape_list(logits)[2], (block_length ** 2)])
        weights = tf.nn.softmax(logits)
        weights = tf.reshape(weights, [common_layers.shape_list(weights)[0], num_head, common_layers.shape_list(weights)[2], block_length, block_length])
        weights = tf.reduce_sum(weights, axis=3, keep_dims=True)
        v_out = tf.matmul(weights, v)
        v_out = tf.squeeze(v_out, axis=3)
        return v_out
    return multihead_attention(x, None, bias=None, output_depth=x.get_shape().as_list()[(- 1)], attention_type=dot_product_self_local_attention_flattened, **multihead_params)

Reduce the length dimension using self attention.

Args:
x (tf.Tensor): float32 of shape [batch, length, depth]
block_length (int): Block length for local attention (Compression factor)
multihead_params (dict): parameters for multihead attention

Returns:
tf.Tensor: Compressed tensor of shape [batch, length // factor, depth]