def remove_notification_listener(self, notification_id):
    for v in self.notifications.values():
        toRemove = list(filter((lambda tup: (tup[0] == notification_id)), v))
        if (len(toRemove) > 0):
            v.remove(toRemove[0])
            return True
    return False

Remove a previously added notification callback.

Args:
notification_id: The numeric id passed back from add_notification_listener

Returns:
The function returns boolean true if found and removed, false otherwise.


def verify_cot_cmdln(args=None, event_loop=None):

    args = args or sys.argv[1:]
    parser = argparse.ArgumentParser(
        description=)
    parser.add_argument('task_id', help='the task id to test')
    parser.add_argument('--task-type', help='the task type to test',
                        choices=sorted(get_valid_task_types().keys()), required=True)
    parser.add_argument('--cleanup', help='clean up the temp dir afterwards',
                        dest='cleanup', action='store_true', default=False)
    parser.add_argument('--cot-product', help='the product type to test', default='firefox')
    parser.add_argument('--verify-sigs', help='enable signature verification', action='store_true', default=False)
    opts = parser.parse_args(args)
    tmp = tempfile.mkdtemp()
    log = logging.getLogger('scriptworker')
    log.setLevel(logging.DEBUG)
    logging.basicConfig()
    event_loop = event_loop or asyncio.get_event_loop()
    try:
        event_loop.run_until_complete(_async_verify_cot_cmdln(opts, tmp))
    finally:
        if opts.cleanup:
            rm(tmp)
        else:
            log.info("Artifacts are in {}".format(tmp))

Test the chain of trust from the commandline, for debugging purposes.

Args:
args (list, optional): the commandline args to parse.  If None, use
``sys.argv[1:]`` .  Defaults to None.

event_loop (asyncio.events.AbstractEventLoop): the event loop to use.
If ``None``, use ``asyncio.get_event_loop()``. Defaults to ``None``.


def getter(self):
    if (not hasattr(self, '_getter')):
        if (not self.pypi):
            self._getter = package_getters.LocalFileGetter(self.package, self.save_dir)
        else:
            logger.debug('{0} does not exist as local file trying PyPI.'.format(self.package))
            self._getter = package_getters.PypiDownloader(self.client, self.package, self.version, self.save_dir)
    return self._getter

Returns an instance of proper PackageGetter subclass. Always
returns the same instance.

Returns:
Instance of the proper PackageGetter subclass according to
provided argument.
Raises:
NoSuchSourceException if source to get the package from is unknown
NoSuchPackageException if the package is unknown on PyPI


def load_scout(adapter, config, ped=None, update=False):

    log.info("Check that the panels exists")
    if not check_panels(adapter, config.get('gene_panels', []),
                        config.get('default_gene_panels')):
        raise ConfigError("Some panel(s) does not exist in the database")
    case_obj = adapter.load_case(config, update=update)
    return case_obj

Load a new case from a Scout config.

Args:
adapter(MongoAdapter)
config(dict): loading info
ped(Iterable(str)): Pedigree ingformation
update(bool): If existing case should be updated


def _Ifup(self, interfaces, logger):

    ifup = ['/usr/sbin/wicked', 'ifup', '--timeout', '1']
    try:
      subprocess.check_call(ifup + interfaces)
    except subprocess.CalledProcessError:
      logger.warning('Could not activate interfaces %s.', interfaces)

Activate network interfaces.

Args:
interfaces: list of string, the output device names to enable.
logger: logger object, used to write to SysLog and serial port.


def parse_headers(cls, msg):

        return list(email.parser.Parser().parsestr(msg).items())

Parse HTTP headers.

Args:
msg (str): HTTP message.

Returns:
(List[Tuple[str, str]): List of header tuples.


def flatten(inputs, scope=None):
    if (len(inputs.get_shape()) < 2):
        raise ValueError('Inputs must be have a least 2 dimensions')
    dims = inputs.get_shape()[1:]
    k = dims.num_elements()
    with tf.name_scope(scope, 'Flatten', [inputs]):
        return tf.reshape(inputs, [(- 1), k])

Flattens the input while maintaining the batch_size.

Assumes that the first dimension represents the batch.

Args:
inputs: a tensor of size [batch_size, ...].
scope: Optional scope for name_scope.

Returns:
a flattened tensor with shape [batch_size, k].
Raises:
ValueError: if inputs.shape is wrong.


def write_int32(self, value, little_endian=True):
    if little_endian:
        endian = '<'
    else:
        endian = '>'
    return self.pack(('%si' % endian), value)

Pack the value as a signed integer and write 4 bytes to the stream.

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

Returns:
int: the number of bytes written.


def get_print_tensor_argparser(description):
    ap = argparse.ArgumentParser(description=description, usage=argparse.SUPPRESS)
    ap.add_argument('tensor_name', type=str, help='Name of the tensor, followed by any slicing indices, e.g., hidden1/Wx_plus_b/MatMul:0, hidden1/Wx_plus_b/MatMul:0[1, :]')
    ap.add_argument('-n', '--number', dest='number', type=int, default=-1, help='0-based dump number for the specified tensor. Required for tensor with multiple dumps.')
    ap.add_argument('-r', '--ranges', dest='ranges', type=str, default='', help='Numerical ranges to highlight tensor elements in. Examples: -r 0,1e-8, -r [-0.1,0.1], -r "[[-inf, -0.1], [0.1, inf]]"')
    ap.add_argument('-a', '--all', dest='print_all', action='store_true', help='Print the tensor in its entirety, i.e., do not use ellipses.')
    ap.add_argument('-s', '--numeric_summary', action='store_true', help='Include summary for non-empty tensors of numeric (int*, float*, complex*) and Boolean types.')
    ap.add_argument('-w', '--write_path', type=str, default='', help='Path of the numpy file to write the tensor data to, using numpy.save().')
    return ap

Get an ArgumentParser for a command that prints tensor values.

Examples of such commands include print_tensor and print_feed.

Args:
description: Description of the ArgumentParser.

Returns:
An instance of argparse.ArgumentParser.


def regtuple_to_numeric(items, qregs):

    sizes = [qr.size for qr in qregs.values()]
    reg_idx = np.cumsum([0]+sizes)
    regint = {}
    for ind, qreg in enumerate(qregs.values()):
        regint[qreg] = ind
    out = np.zeros(len(items), dtype=np.int32)
    for idx, val in enumerate(items):
        out[idx] = reg_idx[regint[val[0]]]+val[1]
    return out

Takes (QuantumRegister, int) tuples and converts
them into an integer array.

Args:
items (list): List of tuples of (QuantumRegister, int)
to convert.
qregs (dict): List of )QuantumRegister, int) tuples.
Returns:
ndarray: Array of integers.


def images(cam):
    (yield marv.set_header(title=cam.topic))
    name_template = ('%s-{}.jpg' % cam.topic.replace('/', ':')[1:])
    while True:
        (idx, msg) = (yield marv.pull(cam, enumerate=True))
        if ((msg is None) or (idx >= 20)):
            break
        pytype = get_message_type(cam)
        rosmsg = pytype()
        rosmsg.deserialize(msg.data)
        img = imgmsg_to_cv2(rosmsg, 'rgb8')
        name = name_template.format(idx)
        imgfile = (yield marv.make_file(name))
        cv2.imwrite(imgfile.path, img)
        (yield marv.push(imgfile))

Extract images from input stream to jpg files.

Args:
cam: Input stream of raw rosbag messages.

Returns:
File instances for images of input stream.


def transfer(self, address, messages):
    if (not isinstance(messages, list)):
        raise TypeError('Invalid messages type, should be list of I2C.Message.')
    elif (len(messages) == 0):
        raise ValueError('Invalid messages data, should be non-zero length.')
    cmessages = (_CI2CMessage * len(messages))()
    for i in range(len(messages)):
        if isinstance(messages[i].data, bytes):
            data = messages[i].data
        elif isinstance(messages[i].data, bytearray):
            data = bytes(messages[i].data)
        elif isinstance(messages[i].data, list):
            data = bytes(bytearray(messages[i].data))
        cmessages[i].addr = address
        cmessages[i].flags = (messages[i].flags | (I2C._I2C_M_RD if messages[i].read else 0))
        cmessages[i].len = len(data)
        cmessages[i].buf = ctypes.cast(ctypes.create_string_buffer(data, len(data)), ctypes.POINTER(ctypes.c_ubyte))
    i2c_xfer = _CI2CIocTransfer()
    i2c_xfer.nmsgs = len(cmessages)
    i2c_xfer.msgs = cmessages
    try:
        fcntl.ioctl(self._fd, I2C._I2C_IOC_RDWR, i2c_xfer, False)
    except IOError as e:
        raise I2CError(e.errno, ('I2C transfer: ' + e.strerror))
    for i in range(len(messages)):
        if messages[i].read:
            data = [cmessages[i].buf[j] for j in range(cmessages[i].len)]
            if isinstance(messages[i].data, list):
                messages[i].data = data
            elif isinstance(messages[i].data, bytearray):
                messages[i].data = bytearray(data)
            elif isinstance(messages[i].data, bytes):
                messages[i].data = bytes(bytearray(data))

Transfer `messages` to the specified I2C `address`. Modifies the
`messages` array with the results of any read transactions.

Args:
address (int): I2C address.
messages (list): list of I2C.Message messages.

Raises:
I2CError: if an I/O or OS error occurs.
TypeError: if `messages` type is not list.
ValueError: if `messages` length is zero, or if message data is not valid bytes.


def _example_from_definition(self, prop_spec):

        definition_name = self.get_definition_name_from_ref(prop_spec['$ref'])

        if self.build_one_definition_example(definition_name):
            example_dict = self.definitions_example[definition_name]
            if not isinstance(example_dict, dict):
                return example_dict
            example = dict((example_name, example_value) for example_name, example_value in example_dict.items())
            return example

Get an example from a property specification linked to a definition.

Args:
prop_spec: specification of the property you want an example of.

Returns:
An example.


def make_instance(cls, data):

        schema = cls()

        if not hasattr(schema.Meta, 'model'):
            raise AttributeError("In order to make an instance, a model for "
                                 "the schema must be defined in the Meta "
                                 "class.")

        serialized_data = schema.load(data).data

        return cls.Meta.model(**serialized_data)

Validate the data and create a model instance from the data.

Args:
data (dict): The unserialized data to insert into the new model
instance through it's constructor.

Returns:
peewee.Model|sqlalchemy.Model: The model instance with it's data
inserted into it.

Raises:
AttributeError: This is raised if ``Meta.model`` isn't set on the
schema's definition.


def get_operation_by_name(self, name) -> 'Operation':
    if not isinstance(name, str):
        raise TypeError('Operation names are strings (or similar), not %s.' % type(name).__name__)
    op = cast(Operation, self.as_graph_element(name, allow_tensor=False, allow_operation=True))
    return op

Returns the `Operation` with the given `name`.

This method may be called concurrently from multiple threads.

Args:
name: The name of the `Operation` to return.

Returns:
The `Operation` with the given `name`.

Raises:
TypeError: If `name` is not a string.
KeyError: If `name` does not correspond to an operation in this graph.


def _snake_to_camel(name, strict=False):
    if strict:
        name = name.lower()
    terms = name.split('_')
    return (terms[0] + ''.join([term.capitalize() for term in terms[1:]]))

Converts parameter names from snake_case to camelCase.

Args:
name, str. Snake case.
strict: bool, default True. If True, will set name to lowercase before
converting, otherwise assumes original name is proper camel case.
Set to False if name may already be in camelCase.

Returns:
str: CamelCase.


def get_top_exchanges(fsym, tsym, limit=5):

	url = build_url('exchanges', fsym=fsym, tsym=tsym, limit=limit)
	data = load_data(url)

	return data['Data']

Get top exchanges by 24 hour trading volume for the currency pair.

Args:
fsym: FROM symbol.
tsym: TO symbol.
limit: Number of results. Default value returns top 5 exchanges.

Returns:
Function returns a list containing a dictionary for each result:

[{'exchange': ..., 'fromSymbol': ..., 'toSymbole': ...,
'volume24h': ..., 'volume24hTo': ...},
{...},
...]

The list is ordered based on the volume of the FROM currency starting
with the highest value.


def history(self, image):

        res = self._get(self._url("/images/{0}/history", image))
        return self._result(res, True)

Show the history of an image.

Args:
image (str): The image to show history for

Returns:
(str): The history of the image

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


def random(self):
    j = np.searchsorted(self.cumulative_probabilities(), random.random())
    return self.jumps[j]

Select a jump at random with appropriate relative probabilities.

Args:
None

Returns:
(Jump): The randomly selected Jump.


def internal_convert_to_tensor_or_composite(value, dtype=None, name=None, as_ref=False) -> Union[EagerTensor, SymbolicTensor, composite_tensor.CompositeTensor]:
    if isinstance(value, composite_tensor.CompositeTensor):
        value_dtype = getattr(value, 'dtype', None)
        if dtype and (not dtypes.as_dtype(dtype).is_compatible_with(value_dtype)):
            raise ValueError(f'Tensor conversion dtype mismatch. Requested dtype is {dtypes.as_dtype(dtype).name}, Tensor has dtype {value.dtype.name}: {value!r}')
        return value
    else:
        return convert_to_tensor(value, dtype=dtype, name=name, as_ref=as_ref, accepted_result_types=(tensor_lib.Tensor, composite_tensor.CompositeTensor))

Converts the given object to a `Tensor` or `CompositeTensor`.

If `value` is a `CompositeTensor` it is returned unmodified.  Otherwise, it
is converted to a `Tensor` using `convert_to_tensor()`.

Args:
value: A `CompositeTensor`, or an object that can be consumed by
`convert_to_tensor()`.
dtype: (Optional.) The required `DType` of the returned `Tensor` or
`CompositeTensor`.
name: (Optional.) A name to use if a new `Tensor` is created.
as_ref: True if the caller wants the results as ref tensors.

Returns:
A `Tensor` or `CompositeTensor`, based on `value`.

Raises:
ValueError: If `dtype` does not match the element type of `value`.


def configure_logging(verbosity):

    root = logging.getLogger()

    formatter = logging.Formatter('%(asctime)s.%(msecs)03d %(levelname).3s %(name)s %(message)s',
                                  '%y-%m-%d %H:%M:%S')
    handler = logging.StreamHandler()
    handler.setFormatter(formatter)

    loglevels = [logging.CRITICAL, logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG]
    if verbosity >= len(loglevels):
        verbosity = len(loglevels) - 1

    level = loglevels[verbosity]

    root.setLevel(level)
    root.addHandler(handler)

Set up the global logging level.

Args:
verbosity (int): The logging verbosity


def send_post(self, mri, method_name, **params):

        typ, parameters = convert_to_type_tuple_value(serialize_object(params))
        uri = NTURI(typ[2])

        uri = uri.wrap(
            path="%s.%s" % (mri, method_name),
            kws=parameters,
            scheme="pva"
        )
        value = self._ctxt.rpc(mri, uri, timeout=None)
        return convert_value_to_dict(value)

Abstract method to dispatch a Post to the server

Args:
mri (str): The mri of the Block
method_name (str): The name of the Method within the Block
params: The parameters to send

Returns:
The return results from the server


def lsdirs(root='.', **kwargs):
    paths = ls(root=root, **kwargs)
    if isfile(root):
        return []
    return [_path for _path in paths if isdir(path(root, _path))]

Return only subdirectories from a directory listing.

Arguments:

root (str): Path to directory. Can be relative or absolute.
**kwargs: Any additional arguments to be passed to ls().

Returns:

list of str: A list of directory paths.

Raises:

OSError: If root directory does not exist.


def cancel(**kwargs):

    task_list = _query(**kwargs)
    for task in task_list:
        task.status = WorkQueue.CANCELED
        task.finished = datetime.datetime.utcnow()
        db.session.add(task)
    return len(task_list)

Cancels work items based on their criteria.

Args:
**kwargs: Same parameters as the query() method.

Returns:
The number of tasks that were canceled.


def get_other_answers_random(pool, seeded_answers, get_student_item_dict, num_responses):
    ret = []
    pool = {int(k): v for (k, v) in pool.items()}
    seeded = {('seeded' + str(index)): answer for (index, answer) in enumerate(seeded_answers)}
    merged_pool = seeded.keys()
    for key in pool:
        merged_pool += pool[key].keys()
    random.shuffle(merged_pool)
    student_id = get_student_item_dict()['student_id']
    for student in merged_pool:
        if (len(ret) >= num_responses):
            break
        elif (student == student_id):
            continue
        if student.startswith('seeded'):
            option = seeded[student]['answer']
            rationale = seeded[student]['rationale']
        else:
            student_item = get_student_item_dict(student)
            submission = sas_api.get_answers_for_student(student_item)
            rationale = submission.get_rationale(0)
            option = submission.get_vote(0)
        ret.append({'option': option, 'rationale': rationale})
    return {'answers': ret}

Get answers from others with random algorithm, which randomly select answer from the pool.

Student may get three answers for option 1 or one answer for option 1 and two answers for option 2.

Args:
see `get_other_answers`
num_responses (int): the number of responses to be returned. This value may not be
respected if there is not enough answers to return

Returns:
dict: answers based on the selection algorithm


def ratecurve_from_discounting_function(discount_fn, dtype=None):
    dtype = dtype or tf.constant(0.0).dtype
    pseudo_maturity_dates = dates.convert_to_date_tensor([(2020, 1, 1)])
    pseudo_rates = tf.convert_to_tensor([0.0], dtype=dtype)
    pseudo_valuation_date = dates.convert_to_date_tensor((2020, 1, 1))
    return RateCurveFromDiscountingFunction(pseudo_maturity_dates, pseudo_rates, pseudo_valuation_date, discount_fn, dtype)

Returns `RateCurve` object using the supplied function for discounting.

Args:
discount_fn: A python callable which takes a `DateTensor` as an input and
returns the corresponding discount factor as an output.
dtype: `tf.Dtype`. Optional input specifying the dtype of the real tensors
and ops.

Returns:
An object of class `RateCurveFromDiscountingFunction` which uses the
supplied function for discounting.


def _copy(self, filename, destination):

        super(MountedRepository, self)._copy(filename, destination)

Copy a file or folder to the repository.

Will mount if needed.

Args:
filename: Path to copy.
destination: Remote path to copy file to.


def _sign_of(money):

    units = money.units
    nanos = money.nanos
    if units:
        if units > 0:
            return 1
        elif units < 0:
            return -1
    if nanos:
        if nanos > 0:
            return 1
        elif nanos < 0:
            return -1
    return 0

Determines the amount sign of a money instance

Args:
money (:class:`endpoints_management.gen.servicecontrol_v1_messages.Money`): the
instance to test

Return:
int: 1, 0 or -1


def __init__(self, content, css=None, image_root='.'):

        self._md = markdown.Markdown(extensions=[
            'markdown.extensions.tables',
            'markdown.extensions.meta'])
        self._html = None
        self._inline_images = None
        self._convert(content, css, image_root)

Constructor

Args:
content (str): Markdown text
css (str): Custom CSS style. If not set, use default CSS style.
image_root (str): Root directory for inline images.


def every_other(x, name=None):
    with tf.name_scope(name, 'every_other', [x]) as scope:
        x = tf.convert_to_tensor(x, name='x')
        return tf.reshape(tf.slice(tf.reshape(x, [(- 1), 2]), [0, 0], [(- 1), 1]), [(- 1)], name=scope)

Drops every other value from the tensor and returns a 1D tensor.

This is useful if you are running multiple inputs through a model tower
before splitting them and you want to line it up with some other data.

Args:
x: the target tensor.
name: the name for this op, defaults to every_other
Returns:
A tensorflow op.


def iter_packages(self):
    for package in self.repository.iter_packages(self.resource):
        (yield Package(package))

Iterate over the packages within this family, in no particular order.

Returns:
`Package` iterator.


def save_statement(self, statement):
    response = self.lrs.save_statement(statement)
    if (not response):
        raise ClientError('EnterpriseXAPIClient request failed.')

Save xAPI statement.

Arguments:
statement (EnterpriseStatement): xAPI Statement to send to the LRS.

Raises:
ClientError: If xAPI statement fails to save.


def _cosine_function(x, a, b, t_shift):
    (mean_wind, t) = x
    return (((a * mean_wind) * np.cos(((np.pi * (t - t_shift)) / 12))) + (b * mean_wind))

genrates a diurnal course of windspeed accroding to the cosine function

Args:
x: series of euqally distributed windspeed values
a: parameter a for the cosine function
b: parameter b for the cosine function
t_shift: parameter t_shift for the cosine function

Returns:
series including diurnal course of windspeed.


def save(self, filename, image_format='eps', width=8, height=6):
    self.get_plot(width, height).savefig(filename, format=image_format)

Save the plot to an image file.

Args:
filename: Filename to save to.
image_format: Format to save to. Defaults to eps.


def extend_comp_items(self, context_word, new_comp_items):
    if context_word not in self._comp_dict:
        raise KeyError('Context word "%s" has not been registered' % context_word)
    self._comp_dict[context_word].extend(new_comp_items)
    self._comp_dict[context_word] = sorted(self._comp_dict[context_word])

Add a list of completion items to a completion context.

Args:
context_word: A single completion word as a string. The extension will
also apply to all other context words of the same context.
new_comp_items: (list of str) New completion items to add.

Raises:
KeyError: if the context word has not been registered.


def set_active(self, username, active_state):
    if (active_state not in (True, False)):
        raise ValueError('active_state must be True or False')
    user = self.get_user(username)
    if (user is None):
        return None
    if (user['active'] is active_state):
        return True
    user['active'] = active_state
    response = self._put((self.rest_url + '/user'), params={'username': username}, data=json.dumps(user))
    if (response.status_code == 204):
        return True
    return None

Set the active state of a user

Args:
username: The account username
active_state: True or False

Returns:
True: If successful
None: If no user or failure occurred


def __contains__(self, word):

        if not self.case_sensitive:
            word = word.lower()
        current_dict = self.keyword_trie_dict
        len_covered = 0
        for char in word:
            if char in current_dict:
                current_dict = current_dict[char]
                len_covered += 1
            else:
                break
        return self._keyword in current_dict and len_covered == len(word)

To check if word is present in the keyword_trie_dict

Args:
word : string
word that you want to check

Returns:
status : bool
If word is present as it is in keyword_trie_dict then we return True, else False

Examples:
>>> keyword_processor.add_keyword('Big Apple')
>>> 'Big Apple' in keyword_processor
>>> # True


def _get_container_environment(self, **kwargs):

        environment = {}
        environment.update(self.primary_container['Environment'])
        environment['SAGEMAKER_BATCH'] = 'True'
        if 'MaxPayloadInMB' in kwargs:
            environment['SAGEMAKER_MAX_PAYLOAD_IN_MB'] = str(kwargs['MaxPayloadInMB'])

        if 'BatchStrategy' in kwargs:
            if kwargs['BatchStrategy'] == 'SingleRecord':
                strategy_env_value = 'SINGLE_RECORD'
            elif kwargs['BatchStrategy'] == 'MultiRecord':
                strategy_env_value = 'MULTI_RECORD'
            else:
                raise ValueError('Invalid BatchStrategy, must be \'SingleRecord\' or \'MultiRecord\'')
            environment['SAGEMAKER_BATCH_STRATEGY'] = strategy_env_value

        if 'MaxConcurrentTransforms' in kwargs and int(kwargs['MaxConcurrentTransforms']) > 1:
            logger.warning('Local Mode only supports 1 ConcurrentTransform. Setting MaxConcurrentTransforms to 1')
        environment['SAGEMAKER_MAX_CONCURRENT_TRANSFORMS'] = '1'

        if 'Environment' in kwargs:
            environment.update(kwargs['Environment'])
        return environment

Get all the Environment variables that will be passed to the container

Certain input fields such as BatchStrategy have different values for the API vs the Environment
variables, such as SingleRecord vs SINGLE_RECORD. This method also handles this conversion.

Args:
**kwargs: existing transform arguments

Returns:
dict: All the environment variables that should be set in the container


def Split(self):
    googlename = self.RepositoryName()
    (project, rest) = os.path.split(googlename)
    return ((project,) + os.path.splitext(rest))

Splits the file into the directory, basename, and extension.

For 'chrome/browser/browser.cc', Split() would
return ('chrome/browser', 'browser', '.cc')

Returns:
A tuple of (directory, basename, extension).


def parse_datetime(s, **kwargs):

    if not s:
        return None
    try:
        ret = dateutil_parser(s, **kwargs)
    except (OverflowError, TypeError, ValueError) as e:
        logger.exception(e, exc_info=True)
        reraise('datetime parsing error from %s' % s, e)
    return ret

Converts a time-string into a valid
:py:class:`~datetime.datetime.DateTime` object.

Args:
s (str): string to be formatted.

``**kwargs`` is passed directly to :func:`.dateutil_parser`.

Returns:
:py:class:`~datetime.datetime.DateTime`


def CreateStorageReaderForFile(cls, path):
    if sqlite_file.SQLiteStorageFile.CheckSupportedFormat(path, check_readable_only=True):
        return sqlite_reader.SQLiteStorageFileReader(path)
    return None

Creates a storage reader based on the file.

Args:
path (str): path to the storage file.

Returns:
StorageReader: a storage reader or None if the storage file cannot be
opened or the storage format is not supported.


def PatternMatch(regex):

    pattern = re.compile(regex)
    return lambda text: -1 if pattern.search(text) is None else 0

Compute the score of a text by determing if a pattern matches.

Example:
>>> fitness = PatternMatch("flag{.*}")
>>> fitness("flag{example}")
0

>>> fitness("junk")
-1

Args:
regex (str): regular expression string to use as a pattern


def __batch_evaluate(self, test_events):
    percentiles = np.zeros(len(test_events))
    all_items = set(self.item_buffer)
    for (i, e) in enumerate(test_events):
        unobserved = all_items
        if (not self.repeat):
            unobserved -= self.rec.users[e.user.index]['known_items']
            unobserved.add(e.item.index)
        candidates = np.asarray(list(unobserved))
        (recos, scores) = self.__recommend(e, candidates)
        pos = np.where((recos == e.item.index))[0][0]
        percentiles[i] = ((pos / (len(recos) - 1)) * 100)
    return np.mean(percentiles)

Evaluate the current model by using the given test events.

Args:
test_events (list of Event): Current model is evaluated by these events.

Returns:
float: Mean Percentile Rank for the test set.


def Open(cls, usb, destination, timeout_ms=None):
    local_id = 1
    msg = cls(command=b'OPEN', arg0=local_id, arg1=0, data=(destination + b'\x00'))
    msg.Send(usb, timeout_ms)
    (cmd, remote_id, their_local_id, _) = cls.Read(usb, [b'CLSE', b'OKAY'], timeout_ms=timeout_ms)
    if (local_id != their_local_id):
        raise InvalidResponseError('Expected the local_id to be {}, got {}'.format(local_id, their_local_id))
    if (cmd == b'CLSE'):
        (cmd, remote_id, their_local_id, _) = cls.Read(usb, [b'CLSE', b'OKAY'], timeout_ms=timeout_ms)
        if (cmd == b'CLSE'):
            return None
    if (cmd != b'OKAY'):
        raise InvalidCommandError('Expected a ready response, got {}'.format(cmd), cmd, (remote_id, their_local_id))
    return _AdbConnection(usb, local_id, remote_id, timeout_ms)

Opens a new connection to the device via an OPEN message.

Not the same as the posix 'open' or any other google3 Open methods.

Args:
usb: USB device handle with BulkRead and BulkWrite methods.
destination: The service:command string.
timeout_ms: Timeout in milliseconds for USB packets.

Raises:
InvalidResponseError: Wrong local_id sent to us.
InvalidCommandError: Didn't get a ready response.

Returns:
The local connection id.


def is_dtensor(tensor) -> bool:
    return _dtensor_device().is_dtensor(tensor)

Check whether the input tensor is a DTensor.

In Python, a DTensor has the same type as a `tf.Tensor`. This method will
let you check and handle the tensor differently if a tf.Tensor is a DTensor.

Args:
tensor: an object to be checked.

Returns:
bool, True if the given tensor is a DTensor.


def _run_contained(task_type, task_id, fn, args, kwargs):
    is_successful = False
    return_value = None
    exc_info = None
    try:
        return_value = fn(*args, **kwargs)
        is_successful = True
        return _ProcessStatusInfo(task_type=task_type, task_id=task_id, is_successful=is_successful, exc_info=exc_info, return_value=return_value)
    except Exception:
        exc_info = sys.exc_info()
        return _ProcessStatusInfo(task_type=task_type, task_id=task_id, is_successful=is_successful, exc_info=exc_info, return_value=return_value)

Runs `fn` with `args` and `kwargs`.

The function returns _ProcessStatusInfo which captures the return value and
the exception.

Args:
task_type: the task type.
task_id: the task index.
fn: the function to be run.
args: optional positional arguments to be supplied in `fn`.
kwargs: optional keyword arguments to be supplied in `fn`.

Returns:
a _ProcessStatusInfo.


def get_dilation_rates(hparams, width):

  allowed_dilations = [[1]*5]
  apply_dilations = hparams.get("latent_apply_dilations", False)
  dilation_rates = hparams.get("latent_dilation_rates", [1, 3])
  if apply_dilations:
    for rate in dilation_rates:

      filter_size = 3 + 2 * rate
      if filter_size <= width:
        curr_dilation = [1, 1, rate+1, rate+1, 1]
        allowed_dilations.append(curr_dilation)
  return allowed_dilations

Get a list of valid dilation rates.

Args:
hparams: HParams.
width: spatial dimension. Ensures that the effective filter size is
not larger than the spatial dimension.
Returns:
allowed_dilations: A list of dilation rates.


class Swin2SRPatchMerging(nn.Module):

    def __init__(self, input_resolution: Tuple[int], dim: int, norm_layer: nn.Module=nn.LayerNorm) -> None:
        super().__init__()
        self.input_resolution = input_resolution
        self.dim = dim
        self.reduction = nn.Linear(4 * dim, 2 * dim, bias=False)
        self.norm = norm_layer(2 * dim)

    def maybe_pad(self, input_feature, height, width):
        should_pad = height % 2 == 1 or width % 2 == 1
        if should_pad:
            pad_values = (0, 0, 0, width % 2, 0, height % 2)
            input_feature = nn.functional.pad(input_feature, pad_values)
        return input_feature

    def forward(self, input_feature: torch.Tensor, input_dimensions: Tuple[int, int]) -> torch.Tensor:
        height, width = input_dimensions
        batch_size, dim, num_channels = input_feature.shape
        input_feature = input_feature.view(batch_size, height, width, num_channels)
        input_feature = self.maybe_pad(input_feature, height, width)
        input_feature_0 = input_feature[:, 0::2, 0::2, :]
        input_feature_1 = input_feature[:, 1::2, 0::2, :]
        input_feature_2 = input_feature[:, 0::2, 1::2, :]
        input_feature_3 = input_feature[:, 1::2, 1::2, :]
        input_feature = torch.cat([input_feature_0, input_feature_1, input_feature_2, input_feature_3], -1)
        input_feature = input_feature.view(batch_size, -1, 4 * num_channels)
        input_feature = self.reduction(input_feature)
        input_feature = self.norm(input_feature)
        return input_feature

Patch Merging Layer.

Args:
input_resolution (`Tuple[int]`):
Resolution of input feature.
dim (`int`):
Number of input channels.
norm_layer (`nn.Module`, *optional*, defaults to `nn.LayerNorm`):
Normalization layer class.


def GetFormattedMessages(self, event):

    event_formatter = self.GetEventFormatter(event)
    if not event_formatter:
      return None, None

    return event_formatter.GetMessages(self._formatter_mediator, event)

Retrieves the formatted messages related to the event.

Args:
event (EventObject): event.

Returns:
tuple: containing:

str: full message string or None if no event formatter was found.
str: short message string or None if no event formatter was found.


def link_contentkey_authorization_policy(access_token, ckap_id, options_id, ams_redirected_rest_endpoint):
    path = '/ContentKeyAuthorizationPolicies'
    full_path = ''.join([path, "('", ckap_id, "')", '/$links/Options'])
    full_path_encoded = urllib.parse.quote(full_path, safe='')
    endpoint = ''.join([ams_rest_endpoint, full_path_encoded])
    uri = ''.join([ams_redirected_rest_endpoint, 'ContentKeyAuthorizationPolicyOptions', "('", options_id, "')"])
    body = (('{"uri": "' + uri) + '"}')
    return do_ams_post(endpoint, full_path_encoded, body, access_token, 'json_only', '1.0;NetFx')

Link Media Service Content Key Authorization Policy.

Args:
access_token (str): A valid Azure authentication token.
ckap_id (str): A Media Service Asset Content Key Authorization Policy ID.
options_id (str): A Media Service Content Key Authorization Policy Options .
ams_redirected_rest_endpoint (str): A Media Service Redirected Endpoint.

Returns:
HTTP response. JSON body.


def make_time(dt, date_parser=parse_date):

    if not dt:
        return datetime.time(0, 0)
    if isinstance(dt, basestring):
        try:
            dt = date_parser(dt)
        except:
            print 'Unable to parse {0}'.format(repr(dt))
            print_exc()
            return datetime.time(0, 0)
    try:
        dt = dt.timetuple()[3:6]
    except:
        dt = tuple(dt)[3:6]
    return datetime.time(*dt)

Ignore date information in a datetime string or object

Arguments:
dt (str or datetime.datetime or atetime.time or numpy.Timestamp): time or date
to be coerced into a `datetime.time` object

Returns:
datetime.time: Time of day portion of a `datetime` string or object

>>> make_time(None)
datetime.time(0, 0)
>>> make_time("11:59 PM")
datetime.time(23, 59)
>>> make_time(datetime.datetime(1999, 12, 31, 23, 59, 59))
datetime.time(23, 59, 59)


def from_int(i):

        point = ECPointAffine.from_int(bitcoin_curve, i)
        return PublicKey.from_point(point)

Generates a public key object from an integer.

Note:
This assumes that the upper 32 bytes of the integer
are the x component of the public key point and the
lower 32 bytes are the y component.

Args:
i (Bignum): A 512-bit integer representing the public
key point on the secp256k1 curve.

Returns:
PublicKey: A PublicKey object.


def channel_ready_future(channel):

    fut = channel._loop.create_future()
    def _set_result(state):
        if not fut.done() and state is _grpc.ChannelConnectivity.READY:
            fut.set_result(None)
    fut.add_done_callback(lambda f: channel.unsubscribe(_set_result))
    channel.subscribe(_set_result, try_to_connect=True)
    return fut

Creates a Future that tracks when a Channel is ready.

Cancelling the Future does not affect the channel's state machine.
It merely decouples the Future from channel state machine.

Args:
channel: A Channel object.

Returns:
A Future object that matures when the channel connectivity is
ChannelConnectivity.READY.


def check_model_type(self, supported_models: Union[List[str], dict]):
    if not isinstance(supported_models, list):
        supported_models_names = []
        if self.task in SUPPORTED_PEFT_TASKS:
            supported_models_names.extend(SUPPORTED_PEFT_TASKS[self.task])
        for _, model_name in supported_models.items():
            if isinstance(model_name, tuple):
                supported_models_names.extend(list(model_name))
            else:
                supported_models_names.append(model_name)
        if hasattr(supported_models, '_model_mapping'):
            for _, model in supported_models._model_mapping._extra_content.items():
                if isinstance(model_name, tuple):
                    supported_models_names.extend([m.__name__ for m in model])
                else:
                    supported_models_names.append(model.__name__)
        supported_models = supported_models_names
    if self.model.__class__.__name__ not in supported_models:
        logger.error(f"The model '{self.model.__class__.__name__}' is not supported for {self.task}. Supported models are {supported_models}.")

Check if the model class is in supported by the pipeline.

Args:
supported_models (`List[str]` or `dict`):
The list of models supported by the pipeline, or a dictionary with model class values.


def discretize(self, contact_id=0, accuracy=0.004, dt=0.001):
    if (not self.event_points):
        return []
    events = []
    action_dt = (accuracy / self.speed)
    dt = (dt or action_dt)
    ep0 = self.event_points[0]
    for _ in range(int((ep0[0] / dt))):
        events.append(['s', dt])
    events.append(['d', ep0[1], contact_id])
    for (i, ep) in enumerate(self.event_points[1:]):
        prev_ts = self.event_points[i][0]
        curr_ts = ep[0]
        p0 = self.event_points[i][1]
        p1 = ep[1]
        if (p0 == p1):
            for _ in range(int(((curr_ts - prev_ts) / dt))):
                events.append(['s', dt])
        else:
            dpoints = track_sampling([p0, p1], accuracy)
            for p in dpoints:
                events.append(['m', p, contact_id])
                for _ in range(int((action_dt / dt))):
                    events.append(['s', dt])
    events.append(['u', contact_id])
    return events

Sample this motion track into discretized motion events.

Args:
contact_id: contact point id
accuracy: motion minimum difference in space
dt: sample time difference


def irreducible_purviews(cm, direction, mechanism, purviews):

    def reducible(purview):

        _from, to = direction.order(mechanism, purview)
        return connectivity.block_reducible(cm, _from, to)

    return [purview for purview in purviews if not reducible(purview)]

Return all purviews which are irreducible for the mechanism.

Args:
cm (np.ndarray): An |N x N| connectivity matrix.
direction (Direction): |CAUSE| or |EFFECT|.
purviews (list[tuple[int]]): The purviews to check.
mechanism (tuple[int]): The mechanism in question.

Returns:
list[tuple[int]]: All purviews in ``purviews`` which are not reducible
over ``mechanism``.

Raises:
ValueError: If ``direction`` is invalid.


def download_file(bucket_name, path, target, sagemaker_session):
    path = path.lstrip('/')
    boto_session = sagemaker_session.boto_session
    s3 = boto_session.resource('s3')
    bucket = s3.Bucket(bucket_name)
    bucket.download_file(path, target)

Download a Single File from S3 into a local path

Args:
bucket_name (str): S3 bucket name
path (str): file path within the bucket
target (str): destination directory for the downloaded file.
sagemaker_session (:class:`sagemaker.session.Session`): a sagemaker session to interact with S3.


def get_pourbaix_entries(self, chemsys):

        from pymatgen.analysis.pourbaix_diagram import PourbaixEntry, IonEntry
        from pymatgen.analysis.phase_diagram import PhaseDiagram
        from pymatgen.core.ion import Ion
        from pymatgen.entries.compatibility import \
            MaterialsProjectAqueousCompatibility

        pbx_entries = []

        url = '/pourbaix_diagram/reference_data/' + '-'.join(chemsys)
        ion_data = self._make_request(url)
        ion_ref_comps = [Composition(d['Reference Solid']) for d in ion_data]
        ion_ref_elts = list(itertools.chain.from_iterable(
            i.elements for i in ion_ref_comps))
        ion_ref_entries = self.get_entries_in_chemsys(
            list(set([str(e) for e in ion_ref_elts] + ['O', 'H'])),
            property_data=['e_above_hull'], compatible_only=False)
        compat = MaterialsProjectAqueousCompatibility("Advanced")
        ion_ref_entries = compat.process_entries(ion_ref_entries)
        ion_ref_pd = PhaseDiagram(ion_ref_entries)

        for n, i_d in enumerate(ion_data):
            ion_entry = IonEntry(Ion.from_formula(i_d['Name']), i_d['Energy'])
            refs = [e for e in ion_ref_entries
                    if e.composition.reduced_formula == i_d['Reference Solid']]
            if not refs:
                raise ValueError("Reference solid not contained in entry list")
            stable_ref = sorted(refs, key=lambda x: x.data['e_above_hull'])[0]
            rf = stable_ref.composition.get_reduced_composition_and_factor()[1]
            solid_diff = ion_ref_pd.get_form_energy(stable_ref) \
                         - i_d['Reference solid energy'] * rf
            elt = i_d['Major_Elements'][0]
            correction_factor = ion_entry.ion.composition[elt] \
                                / stable_ref.composition[elt]
            ion_entry.energy += solid_diff * correction_factor
            pbx_entries.append(PourbaixEntry(ion_entry, 'ion-{}'.format(n)))

        extra_elts = set(ion_ref_elts) - {Element(s) for s in chemsys} \
                     - {Element('H'), Element('O')}
        for entry in ion_ref_entries:
            entry_elts = set(entry.composition.elements)

            if not (entry_elts <= {Element('H'), Element('O')} or \
                            extra_elts.intersection(entry_elts)):

                form_e = ion_ref_pd.get_form_energy(entry)
                new_entry = deepcopy(entry)
                new_entry.uncorrected_energy = form_e
                new_entry.correction = 0.0
                pbx_entry = PourbaixEntry(new_entry)
                pbx_entries.append(pbx_entry)

        return pbx_entries

A helper function to get all entries necessary to generate
a pourbaix diagram from the rest interface.

Args:
chemsys ([str]): A list of elements comprising the chemical
system, e.g. ['Li', 'Fe']


def process_file(pyfile_name):

    print('Processing file: ' + pyfile_name)

    with open(pyfile_name) as fpyfile:
        pyfile_str = fpyfile.readlines()

    file_dict = {'source_file': pyfile_name.replace('\\', '/')}

    if pyfile_str[0].startswith(""):
                comment_str = doc_line[7:]
                extract = extract_code(
                    "'''", comment_str, pyfile_str, line_num)
                function_info['comments'] = extract['current_str']
            file_dict['functions'].append(function_info)
    return file_dict

Process a Python source file with Google style docstring comments.

Reads file header comment, function definitions, function docstrings.
Returns dictionary encapsulation for subsequent writing.

Args:
pyfile_name (str): file name to read.

Returns:
Dictionary object containing summary comment, with a list of entries for each function.


def make_slices(self, tf_tensor, tensor_shape):
    tensor_layout = self.tensor_layout(tensor_shape)
    slice_shape = self.slice_shape(tensor_shape)

    def my_fn(pnum):
        if tensor_layout.is_fully_replicated:
            return tf_tensor
        else:
            slice_begin = self.slice_begin(tensor_shape, pnum)
            return tf.slice(tf_tensor, slice_begin, slice_shape)
    return parallel(([tf_tensor.device] * self.size), my_fn, list(xrange(self.size)))

Turns a single tf.Tensor into a list of slices, one for each processor.

Args:
tf_tensor: tf.Tensor.
tensor_shape: Shape.

Returns:
list of tf.tensor with length self.size.


def manual_variable_initialization(value):
    global _MANUAL_VAR_INIT
    _MANUAL_VAR_INIT = value

Sets the manual variable initialization flag.

This boolean flag determines whether
variables should be initialized
as they are instantiated (default), or if
the user should handle the initialization
(e.g. via `tf.compat.v1.initialize_all_variables()`).

Args:
value: Python boolean.


def load_pkl(filenames):
    if (not isinstance(filenames, (list, tuple))):
        filenames = [filenames]
    times = []
    for name in filenames:
        name = str(name)
        with open(name, 'rb') as file:
            loaded_obj = pickle.load(file)
            if (not isinstance(loaded_obj, Times)):
                raise TypeError('At least one loaded object is not a Times data object.')
            times.append(loaded_obj)
    return (times if (len(times) > 1) else times[0])

Unpickle file contents.

Args:
filenames (str): Can be one or a list or tuple of filenames to retrieve.

Returns:
Times: A single object, or from a collection of filenames, a list of Times objects.

Raises:
TypeError: If any loaded object is not a Times object.


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

        return self.credentials.authorize(
            transport.get_http_object(*args, **kwargs))

Returns an authorized http instance.

Must only be called from within an @oauth_required decorated method, or
from within an @oauth_aware decorated method where has_credentials()
returns True.

Args:
*args: Positional arguments passed to httplib2.Http constructor.
**kwargs: Positional arguments passed to httplib2.Http constructor.


def remove(self, node, dirty=True):

        if node.id in self._children:
            self._children[node.id].parent = None
            del self._children[node.id]
        if dirty:
            self.touch()

Remove the given child node.

Args:
node (gkeepapi.Node): Node to remove.
dirty (bool): Whether this node should be marked dirty.


def fuzzUsufy(fDomains = None, fFuzzStruct = None):

    if fFuzzStruct == None:

        fuzzingStructures = [
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
            "http:
        ]
    else:
        try:
            fuzzingStructures = fFuzzStruct.read().splitlines()
        except:
            print("Usufy could NOT open the following file: " + fFuzzStruct)

    res = {}

    lines = fDomains.read().splitlines()

    for l in lines:
        domain = l.split()[0]
        print("Performing tests for" + domain + "...")

        nick = l.split()[1]

        possibleURL = []

        for struct in fuzzingStructures:

            urlToTry = struct.replace("<DOMAIN>", domain)
            test = urlToTry.replace("<USERNAME>", nick.lower())
            print("Processing "+ test + "...")
            i3Browser = browser.Browser()
            try:
                html = i3Browser.recoverURL(test)
                if nick in html:
                    possibleURL.append(test)
                    print(general.success("\tPossible usufy found!!!\n"))
            except:
                print("The resource could not be downloaded.")

        res[domain] = possibleURL

    print(json.dumps(res, indent = 2))
    return res

Method to guess the usufy path against a list of domains or subdomains.

Args:
-----
fDomains: A list to strings containing the domains and (optionally) a
nick.
fFuzzStruct: A list to strings containing the transforms to be
performed.

Returns:
--------
dict: A dictionary of the form of `{"domain": "url"}`.


def _sum_states(idx, states):
    with ops.name_scope('sum_states'):
        idx = ops.convert_to_tensor(idx, name='idx')
        num_states = _get_dim(states, 2)
        states = array_ops.expand_dims(states, axis=2)
        one_hot = array_ops.one_hot(idx, depth=num_states, on_value=0.0, off_value=math_ops.log(0.0), axis=1)
        return math_ops.reduce_logsumexp(states + one_hot, axis=-1)

Take logsumexp for each unique state out of all label states.

Args:
idx: tensor of shape [batch, label_length] For each sequence, indices into a
set of unique labels as computed by calling unique.
states: tensor of shape [frames, batch, label_length] Log probabilities for
each label state.

Returns:
tensor of shape [frames, batch_size, label_length], log probabilities summed
for each unique label of the sequence.


def get_seconds_description(self):
    return self.get_segment_description(self._expression_parts[0], _('every second'), (lambda s: s), (lambda s: _('every {0} seconds').format(s)), (lambda s: _('seconds {0} through {1} past the minute')), (lambda s: _('at {0} seconds past the minute')))

Generates a description for only the SECONDS portion of the expression

Returns:
The SECONDS description


def get_avatar(from_header, size=64, default="retro"):

    params = OrderedDict([("s", size), ("d", default)])
    query = parse.urlencode(params)
    address = email.utils.parseaddr(from_header)[1]
    value_hash = sha256(address.encode("utf-8")).hexdigest()
    return "https:

Get the avatar URL from the email's From header.

Args:
from_header (str): The email's From header. May contain the sender's full name.

Returns:
str: The URL to that sender's avatar.


def get_subscription(self, subscription_id):
    return self.client._put((self.url + 'subscriptions/{}'.format(subscription_id)), headers=self.get_headers())

Check the basic information associated with the specified subscription.

Args:
subscription_id: Identification of the subscription.

Returns:


def fit(self, X, y):

        self.target_encoders = [None] * X.shape[1]
        self.target_mean = y.mean()

        for i, col in enumerate(X.columns):
            self.target_encoders[i] = self._get_target_encoder(X[col], y)

        return self

Encode categorical columns into average target values.
Args:
X (pandas.DataFrame): categorical columns to encode
y (pandas.Series): the target column
Returns:
X (pandas.DataFrame): encoded columns


def fragment_search(self, fragement: str) -> List[dict]:
    fragement = self.extract_fragment(fragement)
    ilx_rows = self.fragment2rows.get(fragement)
    if (not ilx_rows):
        return None
    else:
        return ilx_rows

Returns the rows in InterLex associated with the fragment

Note:
Pressumed to have duplicate fragements in InterLex
Args:
fragment: The fragment_id of the curie pertaining to the ontology
Returns:
None or List[dict]


def _PrintTasksStatus(self, processing_status):

    if processing_status and processing_status.tasks_status:
      tasks_status = processing_status.tasks_status

      table_view = views.CLITabularTableView(
          column_names=['Tasks:', 'Queued', 'Processing', 'Merging',
                        'Abandoned', 'Total'],
          column_sizes=[15, 7, 15, 15, 15, 0])

      table_view.AddRow([
          '', tasks_status.number_of_queued_tasks,
          tasks_status.number_of_tasks_processing,
          tasks_status.number_of_tasks_pending_merge,
          tasks_status.number_of_abandoned_tasks,
          tasks_status.total_number_of_tasks])

      self._output_writer.Write('\n')
      table_view.Write(self._output_writer)

Prints the status of the tasks.

Args:
processing_status (ProcessingStatus): processing status.


def update(self, **kwargs):
    return self.__class__(self.resource.update(kwargs), self.client, wallet=self.wallet)

Update the Account resource with specified content.

Args:
name (str): Human-readable name for the account

Returns: the updated Account object.


def _create_simulator_trial_result(self,
        params: study.ParamResolver,
        measurements: Dict[str, np.ndarray],
        final_simulator_state: Any) \
        -> 'SimulationTrialResult':

        return SimulationTrialResult(
            params=params,
            measurements=measurements,
            final_simulator_state=final_simulator_state)

This method can be overridden to creation of a trial result.

Args:
params: The ParamResolver for this trial.
measurements: The measurement results for this trial.
final_simulator_state: The final state of the simulator for the
StepResult.

Returns:
The SimulationTrialResult.


def remove_chars(str_, char_list):

    outstr = str_[:]
    for char in char_list:
        outstr = outstr.replace(char, '')
    return outstr

removes all chars in char_list from str_

Args:
str_ (str):
char_list (list):

Returns:
str: outstr

Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_str import *  # NOQA
>>> str_ = '1, 2, 3, 4'
>>> char_list = [',']
>>> result = remove_chars(str_, char_list)
>>> print(result)
1 2 3 4


def _act(self, utterance: str) -> list:

        if self.stateful:
            utterance = [[utterance], [self.key]]
        else:
            utterance = [[utterance]]

        agent_response: list = self.agent(*utterance)

        return agent_response

Infers DeepPavlov agent with raw user input extracted from Alexa request.

Args:
utterance: Raw user input extracted from Alexa request.
Returns:
response: DeepPavlov agent response.


def set_ylim(self, ylim):

        if len(ylim) != 2:
            raise ValueError("ylim must contain two elements")

        if ylim[1] < ylim[0]:
            raise ValueError("Min must be less than Max")

        self.options["min_y"] = ylim[0]
        self.options["max_y"] = ylim[1]

Set y-axis limits.

Accepts a two-element list to set the y-axis limits.

Args:
ylim (list): lower and upper bounds

Raises:
ValueError: ylim must contain two elements
ValueError: Min must be less than max


def _get_kind_name(param_type, is_list):
    if issubclass(param_type, bool):
        typename = 'bool'
    elif issubclass(param_type, six.integer_types):
        typename = 'int64'
    elif issubclass(param_type, (six.string_types, six.binary_type)):
        typename = 'bytes'
    elif issubclass(param_type, float):
        typename = 'float'
    else:
        raise ValueError(('Unsupported parameter type: %s' % str(param_type)))
    suffix = ('list' if is_list else 'value')
    return '_'.join([typename, suffix])

Returns the field name given parameter type and is_list.

Args:
param_type: Data type of the hparam.
is_list: Whether this is a list.

Returns:
A string representation of the field name.

Raises:
ValueError: If parameter type is not recognized.


def backfill_previous_messages(self, reverse=False, limit=10):
    res = self.client.api.get_room_messages(self.room_id, self.prev_batch, direction='b', limit=limit)
    events = res['chunk']
    if (not reverse):
        events = reversed(events)
    for event in events:
        self._put_event(event)

Backfill handling of previous messages.

Args:
reverse (bool): When false messages will be backfilled in their original
order (old to new), otherwise the order will be reversed (new to old).
limit (int): Number of messages to go back.


def generate_custom_cert_name(env='', region='', account='', certificate=None):

    cert_name = None
    template_kwargs = {'account': account, 'name': certificate}

    try:
        rendered_template = get_template(template_file='infrastructure/iam/tlscert_naming.json.j2', **template_kwargs)
        tlscert_dict = json.loads(rendered_template)
    except ForemastTemplateNotFound:
        LOG.info('Unable to find TLS Cert Template...falling back to default logic...')
        return cert_name

    try:
        LOG.info("Attempting to find TLS Cert using TLS Cert Template v1 lookup...")
        cert_name = tlscert_dict[env][certificate]
        LOG.info("Found TLS certificate named %s under %s using TLS Cert Template v1", certificate, env)
    except KeyError:
        LOG.error("Unable to find TLS certificate named %s under %s using v1 TLS Cert Template.", certificate, env)

    tls_services = ['iam', 'acm']
    if cert_name is None and all(service in tlscert_dict for service in tls_services):
        LOG.info("Attempting to find TLS Cert using TLS Cert Template v2 lookup...")
        if certificate in tlscert_dict['iam'][env]:
            cert_name = tlscert_dict['iam'][env][certificate]
            LOG.info("Found IAM TLS certificate named %s under %s using TLS Cert Template v2", certificate, env)
        elif certificate in tlscert_dict['acm'][region][env]:
            cert_name = tlscert_dict['acm'][region][env][certificate]
            LOG.info("Found ACM TLS certificate named %s under %s in %s using TLS Cert Template v2", certificate, env,
                     region)
        else:
            LOG.error(
                "Unable to find TLS certificate named %s under parent keys [ACM, IAM] %s in v2 TLS Cert Template.",
                certificate, env)

    return cert_name

Generate a custom TLS Cert name based on a template.

Args:
env (str): Account environment name
region (str): AWS Region.
account (str): Account number for ARN.
certificate (str): Name of SSL certificate.

Returns:
str: Fully qualified ARN for SSL certificate.
None: Template doesn't exist.


def get_servo_angle(self):

        servoposition =  self.get_servo_position()
        if (self.servomodel==0x06) or (self.servomodel == 0x04):
            return scale(servoposition, 10627, 22129, -159.9, 159.6)
        else:
            return scale(servoposition, 21, 1002, -150, 150)

Gets the current angle of the servo in degrees

Args:
none
Returns:
int : the current servo angle


def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
    super(CreateResponsePayload, self).read(input_buffer, kmip_version=kmip_version)
    local_buffer = utils.BytearrayStream(input_buffer.read(self.length))
    if self.is_tag_next(enums.Tags.OBJECT_TYPE, local_buffer):
        self._object_type = primitives.Enumeration(enums.ObjectType, tag=enums.Tags.OBJECT_TYPE)
        self._object_type.read(local_buffer, kmip_version=kmip_version)
    else:
        raise exceptions.InvalidKmipEncoding('The Create response payload encoding is missing the object type.')
    if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_buffer):
        self._unique_identifier = primitives.TextString(tag=enums.Tags.UNIQUE_IDENTIFIER)
        self._unique_identifier.read(local_buffer, kmip_version=kmip_version)
    else:
        raise exceptions.InvalidKmipEncoding('The Create response payload encoding is missing the unique identifier.')
    if (kmip_version < enums.KMIPVersion.KMIP_2_0):
        if self.is_tag_next(enums.Tags.TEMPLATE_ATTRIBUTE, local_buffer):
            self._template_attribute = objects.TemplateAttribute()
            self._template_attribute.read(local_buffer, kmip_version=kmip_version)
    self.is_oversized(local_buffer)

Read the data encoding the Create response payload and decode it into
its constituent parts.

Args:
input_buffer (stream): A data buffer containing encoded object
data, supporting a read method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.

Raises:
InvalidKmipEncoding: Raised if the object type or unique
identifier is missing from the encoded payload.


def _get_nadir_pixel(earth_mask, sector):
    if (sector == FULL_DISC):
        logger.debug('Computing nadir pixel')
        (rmin, rmax, cmin, cmax) = bbox(earth_mask)
        nadir_row = (rmin + ((rmax - rmin)
        nadir_col = (cmin + ((cmax - cmin)
        return (nadir_row, nadir_col)
    return (None, None)

Find the nadir pixel

Args:
earth_mask: Mask identifying earth and space pixels
sector: Specifies the scanned sector
Returns:
nadir row, nadir column


def _AddShardedSaveOps(self, filename_tensor, per_device):
    if self._write_version == saver_pb2.SaverDef.V2:
        return self._AddShardedSaveOpsForV2(filename_tensor, per_device)
    num_shards = len(per_device)
    sharded_saves = []
    num_shards_tensor = constant_op.constant(num_shards, name='num_shards')
    for shard, (device, saveables) in enumerate(per_device):
        with ops.device(device):
            sharded_filename = self.sharded_filename(filename_tensor, shard, num_shards_tensor)
            sharded_saves.append(self._AddSaveOps(sharded_filename, saveables))
    with ops.control_dependencies([x.op for x in sharded_saves]):
        return gen_io_ops.sharded_filespec(filename_tensor, num_shards_tensor)

Add ops to save the params per shard.

Args:
filename_tensor: a scalar String Tensor.
per_device: A list of (device, BaseSaverBuilder.SaveableObject) pairs, as
returned by _GroupByDevices().

Returns:
An op to save the variables.


def get_resize_output_image_size(image, resolution_max_side: int, input_data_format: Optional[Union[str, ChannelDimension]]=None) -> Tuple[int, int]:
    height, width = get_image_size(image, channel_dim=input_data_format)
    height, width = _resize_output_size_rescale_to_max_len(height, width, max_len=resolution_max_side)
    height, width = _resize_output_size_scale_below_upper_bound(height, width, max_len=MAX_IMAGE_SIZE)
    return (height, width)

Get the output size of the image after resizing given a dictionary specifying the max and min sizes.
Args:
image (`np.ndarray`):
Image to resize.
resolution_max_side (`int`):
The longest edge of the image will be resized to this value. The shortest edge will be resized to keep the
input aspect ratio.
input_data_format (`ChannelDimension` or `str`):
The channel dimension format of the input image.
Returns:
The output size of the image after resizing.


def broadcast_to(self, tensor, destinations):
    assert destinations is not None
    _require_cross_replica_or_default_context_extended(self)
    assert not isinstance(destinations, (list, tuple))
    return self._broadcast_to(tensor, destinations)

Mirror a tensor on one device to all worker devices.

Args:
tensor: A Tensor value to broadcast.
destinations: A mirrored variable or device string specifying the
destination devices to copy `tensor` to.

Returns:
A value mirrored to `destinations` devices.


def _ParameterDecorator(naming_type, testcases):

    def _Apply(obj):
        if isinstance(obj, type):
            _ModifyClass(obj, (list(testcases) if (not isinstance(testcases, collections.Sequence)) else testcases), naming_type)
            return obj
        else:
            return _ParameterizedTestIter(obj, testcases, naming_type)
    if _IsSingletonList(testcases):
        assert _NonStringIterable(testcases[0]), 'Single parameter argument must be a non-string iterable'
        testcases = testcases[0]
    return _Apply

Implementation of the parameterization decorators.

Args:
naming_type: The naming type.
testcases: Testcase parameters.

Returns:
A function for modifying the decorated object.


class StoredResource(object):

    def __init__(self, stored_filename, timestamp_tuple):
        assert not os.path.isabs(stored_filename)
        self.zipinfo = zipfile.ZipInfo(stored_filename, timestamp_tuple)

    def store(self, unused_zip_file):

        raise NotImplementedError

A local resource which can be committed to a par file.

Args:
stored_filename: Relative path to store content under
timestamp_tuple: Stored timestamp, as ZipInfo tuple


def register_path_cls(path_cls_or_uri_prefix):
    global _PATHLIKE_CLS
    if isinstance(path_cls_or_uri_prefix, (str, list, tuple)):

        def register_path_cls_decorator(cls: _T) -> _T:
            if isinstance(path_cls_or_uri_prefix, str):
                _URI_PREFIXES_TO_CLS[path_cls_or_uri_prefix] = cls
            elif isinstance(path_cls_or_uri_prefix, (list, tuple)):
                for uri_prefix in path_cls_or_uri_prefix:
                    _URI_PREFIXES_TO_CLS[uri_prefix] = cls
            return register_path_cls(cls)
        return register_path_cls_decorator
    else:
        _PATHLIKE_CLS = _PATHLIKE_CLS + (path_cls_or_uri_prefix,)
        return path_cls_or_uri_prefix

Register the pathlib-like class.

```python
@epath.register_path_cls('my_path://')
class MyPath(pathlib.PurePosixPath):
...

my_path = epath.Path('my_path://some-path')
assert isinstance(my_path, MyPath)
```

Args:
path_cls_or_uri_prefix: If a uri prefix is given, then passing calling
`tfds.core.as_path('prefix://path')` will call the decorated class.

Returns:
The decorator or decoratorated class


def from_configs(cls, prior_configs: List[JukeboxPriorConfig], vqvae_config: JukeboxVQVAEConfig, **kwargs):
    prior_config_list = [config.to_dict() for config in prior_configs]
    return cls(prior_config_list=prior_config_list, vqvae_config_dict=vqvae_config.to_dict(), **kwargs)

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

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


def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
    super(GetAttributeListRequestPayload, self).read(input_buffer, kmip_version=kmip_version)
    local_buffer = utils.BytearrayStream(input_buffer.read(self.length))
    if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_buffer):
        self._unique_identifier = primitives.TextString(tag=enums.Tags.UNIQUE_IDENTIFIER)
        self._unique_identifier.read(local_buffer, kmip_version=kmip_version)
    else:
        self._unique_identifier = None
    self.is_oversized(local_buffer)

Read the data encoding the GetAttributeList request payload and decode
it into its constituent parts.

Args:
input_buffer (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.


def _ParseMRUListValue(self, registry_key):

    mrulist_value = registry_key.GetValueByName('MRUList')

    if not mrulist_value:
      return None

    mrulist_entries_map = self._GetDataTypeMap('mrulist_entries')

    context = dtfabric_data_maps.DataTypeMapContext(values={
        'data_size': len(mrulist_value.data)})

    return self._ReadStructureFromByteStream(
        mrulist_value.data, 0, mrulist_entries_map, context=context)

Parses the MRUList value in a given Registry key.

Args:
registry_key (dfwinreg.WinRegistryKey): Windows Registry key that contains
the MRUList value.

Returns:
mrulist_entries: MRUList entries or None if not available.


def list_variables(ckpt_dir_or_file):
    reader = load_checkpoint(ckpt_dir_or_file)
    variable_map = reader.get_variable_to_shape_map()
    names = sorted(variable_map.keys())
    result = []
    for name in names:
        result.append((name, variable_map[name]))
    return result

Lists the checkpoint keys and shapes of variables in a checkpoint.

Checkpoint keys are paths in a checkpoint graph.

Example usage:

```python
import tensorflow as tf
import os
ckpt_directory = "/tmp/training_checkpoints/ckpt"
ckpt = tf.train.Checkpoint(optimizer=optimizer, model=model)
manager = tf.train.CheckpointManager(ckpt, ckpt_directory, max_to_keep=3)
train_and_checkpoint(model, manager)
tf.train.list_variables(manager.latest_checkpoint)
```

Args:
ckpt_dir_or_file: Directory with checkpoints file or path to checkpoint.

Returns:
List of tuples `(key, shape)`.


def format_diff_pyxb(a_pyxb, b_pyxb):
    return '\n'.join(difflib.ndiff(serialize_to_xml_str(a_pyxb).splitlines(), serialize_to_xml_str(b_pyxb).splitlines()))

Create a diff between two PyXB objects.

Args:
a_pyxb: PyXB object
b_pyxb: PyXB object

Returns:
str : `Differ`-style delta


def write(data, file_name, worksheet_names=None):

    if re.search(XML_EXT_REGEX, file_name):
        return write_xml(data, file_name, worksheet_names=worksheet_names)
    elif re.search(XLSX_EXT_REGEX, file_name):
        return write_xlsx(data, file_name, worksheet_names=worksheet_names)
    elif re.search(XLS_EXT_REGEX, file_name):
        return write_xls(data, file_name, worksheet_names=worksheet_names)
    elif re.search(CSV_EXT_REGEX, file_name):
        return write_csv(data, file_name)
    else:
        return write_csv(data, file_name)

Writes 2D tables to file.

Args:
data: 2D list of tables/worksheets.
file_name: Name of the output file (determines type).
worksheet_names: A list of worksheet names (optional).


def _cleanup_workflow(config, task_id, args, **kwargs):

    from lightflow.models import Workflow
    if isinstance(args[0], Workflow):
        if config.celery['result_expires'] == 0:
            AsyncResult(task_id).forget()

Cleanup the results of a workflow when it finished.

Connects to the postrun signal of Celery. If the signal was sent by a workflow,
remove the result from the result backend.

Args:
task_id (str): The id of the task.
args (tuple): The arguments the task was started with.
**kwargs: Keyword arguments from the hook.


def replace_all(pcoll, regex, replacement):
    regex = Regex._regex_compile(regex)
    return pcoll | Map(lambda elem: regex.sub(replacement, elem))

Returns the matches if a portion of the line  matches the regex and
replaces all matches with the replacement string.

Args:
regex: the regular expression string or (re.compile) pattern.
replacement: the string to be substituted for each match.


async def getTempCortex(mods=None):
    with s_common.getTempDir() as dirn:
        async with (await Cortex.anit(dirn)) as core:
            if mods:
                for mod in mods:
                    (await core.loadCoreModule(mod))
            async with core.getLocalProxy() as prox:
                (yield prox)

Get a proxy to a cortex backed by a temporary directory.

Args:
mods (list): A list of modules which are loaded into the cortex.

Notes:
The cortex and temporary directory are town down on exit.
This should only be called from synchronous code.

Returns:
Proxy to the cortex.


def sort_by_modified(files_or_folders: list) -> list:

    return sorted(files_or_folders, key=os.path.getmtime, reverse=True)

Sort files or folders by modified time

Args:
files_or_folders: list of files or folders

Returns:
list


def GetAnalyzerInstance(cls, analyzer_name):
    analyzer_name = analyzer_name.lower()
    if (analyzer_name not in cls._analyzer_classes):
        raise KeyError('analyzer class not set for name: {0:s}.'.format(analyzer_name))
    analyzer_class = cls._analyzer_classes[analyzer_name]
    return analyzer_class()

Retrieves an instance of a specific analyzer.

Args:
analyzer_name (str): name of the analyzer to retrieve.

Returns:
BaseAnalyzer: analyzer instance.

Raises:
KeyError: if analyzer class is not set for the corresponding name.


def _add_partition(self, connection, partition):

        logger.debug('Creating foreign table for partition.\n    partition: {}'.format(partition.name))
        with connection.cursor() as cursor:
            postgres_med.add_partition(cursor, partition.datafile, partition.vid)

Creates FDW for the partition.

Args:
connection:
partition (orm.Partition):


def Get(self, request, global_params=None):
    config = self.GetMethodConfig('Get')
    return self._RunMethod(config, request, global_params=global_params)

Returns information about a `BuildTrigger`. This API is experimental.

Args:
request: (CloudbuildProjectsLocationsTriggersGetRequest) input message
global_params: (StandardQueryParameters, default: None) global arguments
Returns:
(BuildTrigger) The response message.


def set_dataset_table(cmd: str) -> None:
    cmd_parts = cmd.split(' ')
    if len(cmd_parts) == 3:
        _, key, val = cmd_parts
        table_dataset_map[key] = val
    else:
        print('Incorrect args. Run .help .set for usage info.')

Set the mapping between a key and a dataset.

Args:
cmd (str): The command string in the format ".set key val"
where key is the identifier and val is the dataset table.


def register_intent_parser(self, intent_parser):

        if hasattr(intent_parser, 'validate') and callable(intent_parser.validate):
            self.intent_parsers.append(intent_parser)
        else:
            raise ValueError("%s is not an intent parser" % str(intent_parser))

"Enforce" the intent parser interface at registration time.

Args:
intent_parser(intent): Intent to be registered.

Raises:
ValueError: on invalid intent


def bourgain_embedding_matrix(distance_matrix):

    distance_matrix = np.array(distance_matrix)
    n = len(distance_matrix)
    if n == 1:
        return distance_matrix
    np.random.seed(123)
    distort_elements = []
    r = range(n)
    k = int(math.ceil(math.log(n) / math.log(2) - 1))
    t = int(math.ceil(math.log(n)))
    counter = 0
    for i in range(0, k + 1):
        for t in range(t):
            s = np.random.choice(r, 2 ** i)
            for j in r:
                d = min([distance_matrix[j][s] for s in s])
                counter += len(s)
                if i == 0 and t == 0:
                    distort_elements.append([d])
                else:
                    distort_elements[j].append(d)
    return rbf_kernel(distort_elements, distort_elements)

Use Bourgain algorithm to embed the neural architectures based on their edit-distance.
Args:
distance_matrix: A matrix of edit-distances.
Returns:
A matrix of distances after embedding.


def save_screenshot(self, filename, quietly = False):

        imgData = self.take_screenshot()
        try:
            with open(filename, "wb") as f:
                f.write(b64decode(imgData.encode('ascii')))
        except IOError as err:
            if not quietly:
                raise err

Save the screenshot to local.

Support:
Android iOS Web(WebView)

Args:
filename(str): The path to save the image.
quietly(bool): If True, omit the IOError when
failed to save the image.

Returns:
WebElement Object.

Raises:
WebDriverException.
IOError.


def multi_get(self, urls, query_params=None, to_json=True):

        return self._multi_request(
            MultiRequest._VERB_GET, urls, query_params,
            data=None, to_json=to_json,
        )

Issue multiple GET requests.

Args:
urls - A string URL or list of string URLs
query_params - None, a dict, or a list of dicts representing the query params
to_json - A boolean, should the responses be returned as JSON blobs
Returns:
a list of dicts if to_json is set of requests.response otherwise.
Raises:
InvalidRequestError - Can not decide how many requests to issue.


class Dropout(keras_layers.Dropout, base.Layer):

    def __init__(self, rate=0.5, noise_shape=None, seed=None, name=None, **kwargs):
        super(Dropout, self).__init__(rate=rate, noise_shape=noise_shape, seed=seed, name=name, **kwargs)

    def call(self, inputs, training=False):
        return super(Dropout, self).call(inputs, training=training)

Applies Dropout to the input.

Dropout consists in randomly setting a fraction `rate` of input units to 0
at each update during training time, which helps prevent overfitting.
The units that are kept are scaled by `1 / (1 - rate)`, so that their
sum is unchanged at training time and inference time.

Args:
rate: The dropout rate, between 0 and 1. E.g. `rate=0.1` would drop out
10% of input units.
noise_shape: 1D tensor of type `int32` representing the shape of the
binary dropout mask that will be multiplied with the input.
For instance, if your inputs have shape
`(batch_size, timesteps, features)`, and you want the dropout mask
to be the same for all timesteps, you can use
`noise_shape=[batch_size, 1, features]`.
seed: A Python integer. Used to create random seeds. See
`tf.compat.v1.set_random_seed`.
for behavior.
name: The name of the layer (string).


def search_officers(self, term, disqualified=False, **kwargs):
    search_type = ('officers' if (not disqualified) else 'disqualified-officers')
    params = kwargs
    params['q'] = term
    baseuri = (self._BASE_URI + 'search/{}'.format(search_type))
    res = self.session.get(baseuri, params=params)
    self.handle_http_error(res)
    return res

Search for officers by name.

Args:
term (str): Officer name to search on.
disqualified (Optional[bool]): True to search for disqualified
officers
kwargs (dict): additional keywords passed into
requests.session.get params keyword.


def git_clone(prettyname: str, url: str, directory: str, branch: str=None, commit: str=None, clone_options: List[str]=None, run_func: Callable[([List[str]], Any)]=None) -> bool:
    run_func = (run_func or subprocess.check_call)
    clone_options = (clone_options or [])
    if os.path.isdir(directory):
        log.info('Not re-cloning {} Git repository: using existing source in {}'.format(prettyname, directory))
        return False
    log.info('Fetching {} source from {} into {}', prettyname, url, directory)
    require_executable(GIT)
    gitargs = ([GIT, 'clone'] + clone_options)
    if branch:
        gitargs += ['--branch', branch]
    gitargs += [url, directory]
    run_func(gitargs)
    if commit:
        log.info('Resetting {} local Git repository to commit {}', prettyname, commit)
        run_func([GIT, '-C', directory, 'reset', '--hard', commit])
    return True

Fetches a Git repository, unless we have it already.

Args:
prettyname: name to display to user
url: URL
directory: destination directory
branch: repository branch
commit: repository commit tag
clone_options: additional options to pass to ``git clone``
run_func: function to use to call an external command

Returns:
did we need to do anything?


def _process_thread(self, client):
    file_list = self.files
    if (not file_list):
        return
    print('Filefinder to collect {0:d} items'.format(len(file_list)))
    flow_action = flows_pb2.FileFinderAction(action_type=flows_pb2.FileFinderAction.DOWNLOAD)
    flow_args = flows_pb2.FileFinderArgs(paths=file_list, action=flow_action)
    flow_id = self._launch_flow(client, 'FileFinder', flow_args)
    self._await_flow(client, flow_id)
    collected_flow_data = self._download_files(client, flow_id)
    if collected_flow_data:
        print('{0!s}: Downloaded: {1:s}'.format(flow_id, collected_flow_data))
        fqdn = client.data.os_info.fqdn.lower()
        self.state.output.append((fqdn, collected_flow_data))

Process a single client.

Args:
client: GRR client object to act on.


def deconstruct(self) -> dict:
    path = ('localized_fields.value.%s' % self.__class__.__name__)
    return (path, [self.__dict__], {})

Deconstructs this value into a primitive type.

Returns:
A dictionary with all the localized values
contained in this instance.


def de_casteljau_one_round(nodes, lambda1, lambda2):
    return np.asfortranarray(((lambda1 * nodes[(:, :(- 1))]) + (lambda2 * nodes[(:, 1:)])))

Perform one round of de Casteljau's algorithm.

.. note::

This is a helper for :func:`_specialize_curve`. It does not have a
Fortran speedup because it is **only** used by a function which has
a Fortran speedup.

The weights are assumed to sum to one.

Args:
nodes (numpy.ndarray): Control points for a curve.
lambda1 (float): First barycentric weight on interval.
lambda2 (float): Second barycentric weight on interval.

Returns:
numpy.ndarray: The nodes for a "blended" curve one degree
lower.


def last_revision(self, mod: YangIdentifier) -> ModuleId:
    revs = [mn for mn in self.modules if (mn[0] == mod)]
    if (not revs):
        raise ModuleNotRegistered(mod)
    return sorted(revs, key=(lambda x: x[1]))[(- 1)]

Return the last revision of a module that's part of the data model.

Args:
mod: Name of a module or submodule.

Raises:
ModuleNotRegistered: If the module `mod` is not present in the
data model.


def _write(self, index, value):
    if isinstance(index, ops.EagerTensor):
        index = index.numpy()
    if index < 0:
        raise errors_impl.OutOfRangeError(None, None, 'Writing to negative indices (index %d) is not allowed.' % index)
    size = len(self._tensor_array)
    if index >= size:
        if not self._dynamic_size:
            raise errors_impl.OutOfRangeError(None, None, 'Tried to write to index %d but array is not resizeable and size is: %d ' % (index, size))
        self._tensor_array.extend((None for _ in range(index - size + 1)))
    if not isinstance(value, ops.EagerTensor):
        value = ops.convert_to_tensor(value, preferred_dtype=self._dtype, name='value')
    if self._dtype != value.dtype:
        raise errors_impl.InvalidArgumentError(None, None, 'TensorArray dtype is %s but Op is trying to write dtype %s ' % (self._dtype.name, value.dtype.name))
    if not self._element_shape.is_compatible_with(value.shape):
        raise ValueError('Incompatible shape for value (%s), expected (%s)' % (value.shape, self._element_shape))
    if self._infer_shape:
        self._element_shape = self._element_shape.merge_with(value.shape)
    self._tensor_array[index] = value

Writes `value` into index named by `index`.

Args:
index: 0-D.  int32 scalar with the index to write to.
value: N-D.  Tensor of type `dtype`.  The `Tensor` to write to `index`.

Raises:
errors_impl.InvalidArgumentError: `value` dtype does not match dtype.
errors_impl.OutOfRangeError: `index` is out of bounds.
ValueError: shape of `value` is not consistent with inferred shape.


def create_position_ids_from_inputs_embeds(self, inputs_embeds):
    input_shape = inputs_embeds.size()[:-1]
    sequence_length = input_shape[1]
    position_ids = torch.arange(self.padding_idx + 1, sequence_length + self.padding_idx + 1, dtype=torch.long, device=inputs_embeds.device)
    return position_ids.unsqueeze(0).expand(input_shape)

We are provided embeddings directly. We cannot infer which are padded so just generate sequential position ids.

Args:
inputs_embeds: torch.Tensor inputs_embeds:

Returns: torch.Tensor


def __init__(self, backend, job_id):

        self._job_id = job_id
        self._backend = backend

Initializes the asynchronous job.

Args:
backend (BaseBackend): the backend used to run the job.
job_id (str): a unique id in the context of the backend used to run
the job.


def setup(self, hosts, files, use_tsk, reason, grr_server_url, grr_username, grr_password, approvers=None, verify=True):
    super(GRRFileCollector, self).setup(reason, grr_server_url, grr_username, grr_password, approvers=approvers, verify=verify)
    if (files is not None):
        self.files = [item.strip() for item in files.strip().split(',')]
    self.hostnames = [item.strip() for item in hosts.strip().split(',')]
    self.use_tsk = use_tsk

Initializes a GRR file collector.

Args:
hosts: Comma-separated list of hostnames to launch the flow on.
files: list of file paths.
use_tsk: toggle for use_tsk flag on GRR flow.
reason: justification for GRR access.
grr_server_url: GRR server URL.
grr_username: GRR username.
grr_password: GRR password.
approvers: list of GRR approval recipients.
verify: boolean, whether to verify the GRR server's x509 certificate.


def shuffle_dataset(filenames, extra_fn=None):

  if outputs_exist(filenames):
    tf.logging.info("Skipping shuffle because output files exist")
    return
  tf.logging.info("Shuffling data...")
  for filename in filenames:
    _shuffle_single(filename, extra_fn=extra_fn)
  tf.logging.info("Data shuffled.")

Shuffles the dataset.

Args:
filenames: a list of strings
extra_fn: an optional function from list of records to list of records
to be called after shuffling a file.


def _copy_deploy_scripts_for_hosts(self, domains):

        with LogTask('Copying any deploy scripts'):
            for host_name, host_spec in domains.iteritems():
                host_metadata = host_spec.get('metadata', {})
                deploy_scripts = self._get_scripts(host_metadata)
                new_scripts = self._copy_delpoy_scripts(deploy_scripts)
                self._set_scripts(
                    host_metadata=host_metadata,
                    scripts=new_scripts,
                )

        return domains

Copy the deploy scripts for all the domains into the prefix scripts dir

Args:
domains(dict): spec with the domains info as when loaded from the
initfile

Returns:
None


def __init__(self, parent=None, **kwargs):

    if not parent:
      raise ValueError('Missing parent value.')

    super(RawPathSpec, self).__init__(parent=parent, **kwargs)

Initializes a path specification.

Note that the RAW path specification must have a parent.

Args:
parent (Optional[PathSpec]): parent path specification.

Raises:
ValueError: when parent is not set.


def pause(self, container):
    url = self._url('/containers/{0}/pause', container)
    res = self._post(url)
    self._raise_for_status(res)

Pauses all processes within a container.

Args:
container (str): The container to pause

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


def send(self, request, stem=None):
    if (stem is not None):
        request.url = ((request.url + '/') + stem.lstrip('/'))
    prepped = self.session.prepare_request(request)
    settings = self.session.merge_environment_settings(url=prepped.url, proxies={}, stream=None, verify=None, cert=None)
    return self.session.send(prepped, **settings)

Prepare and send a request

Arguments:
request: a Request object that is not yet prepared
stem: a path to append to the root URL

Returns:
The response to the request


def _set_extremum_session_metrics(session_group, aggregation_metric, extremum_fn):
    measurements = _measurements(session_group, aggregation_metric)
    ext_session = extremum_fn(measurements, key=operator.attrgetter('metric_value.value')).session_index
    del session_group.metric_values[:]
    session_group.metric_values.MergeFrom(session_group.sessions[ext_session].metric_values)

Sets the metrics for session_group to those of its "extremum session".

The extremum session is the session in session_group with the extremum value
of the metric given by 'aggregation_metric'. The extremum is taken over the
subset of sessions in the group whose 'aggregation_metric' was measured
at the largest training step among the sessions in the group.

Args:
session_group: A SessionGroup protobuffer.
aggregation_metric: A MetricName protobuffer.
extremum_fn: callable. Must be either 'min' or 'max'. Determines the type of
extremum to compute.


def get_country_by_name(self, country_name) -> 'Country':
    VALID_STR.validate(country_name, 'get_country_by_name', exc=ValueError)
    if (country_name not in self._countries_by_name.keys()):
        for country in self.countries:
            if (country.country_name == country_name):
                return country
        raise ValueError(country_name)
    else:
        return self._countries_by_name[country_name]

Gets a country in this coalition by its name

Args:
country_name: country name

Returns: Country


def generate_ast(path):

    if os.path.isfile(path):
        with open(path, 'r') as f:
            try:
                tree = ast.parse(f.read())
                return PytTransformer().visit(tree)
            except SyntaxError:
                global recursive
                if not recursive:
                    _convert_to_3(path)
                    recursive = True
                    return generate_ast(path)
                else:
                    raise SyntaxError('The ast module can not parse the file'
                                      ' and the python 2 to 3 conversion'
                                      ' also failed.')
    raise IOError('Input needs to be a file. Path: ' + path)

Generate an Abstract Syntax Tree using the ast module.

Args:
path(str): The path to the file e.g. example/foo/bar.py


def check_all(self) -> Generator[(AAAError, None, None)]:
    if function_is_noop(self.node):
        return
    self.mark_bl()
    self.mark_def()
    self.act_node = self.load_act_node()
    self.act_block = Block.build_act(self.act_node.node, self.node)
    (act_block_first_line_no, act_block_last_line_no) = self.act_block.get_span(0)
    self.arrange_block = Block.build_arrange(self.node.body, act_block_first_line_no)
    assert self.act_node
    self.assert_block = Block.build_assert(self.node.body, act_block_last_line_no)
    for block in ['arrange', 'act', 'assert']:
        self_block = getattr(self, '{}_block'.format(block))
        try:
            span = self_block.get_span(self.first_line_no)
        except EmptyBlock:
            continue
        self.line_markers.update(span, self_block.line_type)
    (yield from self.line_markers.check_arrange_act_spacing())
    (yield from self.line_markers.check_act_assert_spacing())
    (yield from self.line_markers.check_blank_lines())

Run everything required for checking this function.

Returns:
A generator of errors.

Raises:
ValidationError: A non-recoverable linting error is found.


def validate_config_value(value, possible_values):
    if (value not in possible_values):
        raise Exception(('Invalid config value "%s". Possible values are %s' % (value, ', '.join((e for e in possible_values)))))

Validate a config value to make sure it is one of the possible values.

Args:
value: the config value to validate.
possible_values: the possible values the value can be

Raises:
Exception if the value is not one of possible values.


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

Get the list of upcoming movies. This list refreshes every day.
The maximum number of items this list will include is 100.

Args:
page: (optional) Minimum value of 1.  Expected value is an integer.
language: (optional) ISO 639-1 code.

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


def project_hidden(x, projection_tensors, hidden_size, num_blocks):

  batch_size, latent_dim, _ = common_layers.shape_list(x)
  x = tf.reshape(x, shape=[1, -1, hidden_size])
  x_tiled = tf.reshape(
      tf.tile(x, multiples=[num_blocks, 1, 1]),
      shape=[num_blocks, -1, hidden_size])
  x_projected = tf.matmul(x_tiled, projection_tensors)
  x_projected = tf.transpose(x_projected, perm=[1, 0, 2])
  x_4d = tf.reshape(x_projected, [batch_size, latent_dim, num_blocks, -1])
  return x_4d

Project encoder hidden state under num_blocks using projection tensors.

Args:
x: Encoder hidden state of shape [batch_size, latent_dim,  hidden_size].
projection_tensors: Projection tensors used to project the hidden state.
hidden_size: Dimension of the latent space.
num_blocks: Number of blocks in DVQ.

Returns:
x_projected: Projected states of shape [batch_size, latent_dim, num_blocks,
hidden_size / num_blocks].


def __init__(self, operating_system, architecture):
    self.operating_system = operating_system
    self.architecture = architecture

Constructs a new platform.

Args:
operating_system: OperatingSystem, The OS
architecture: Architecture, The machine architecture.


def prediction_step(self, model: nn.Module, inputs: dict[str, Union[torch.Tensor, Any]], prediction_loss_only: bool, ignore_keys: Optional[list[str]]=None) -> tuple[Optional[torch.Tensor], Optional[torch.Tensor], Optional[torch.Tensor]]:
    has_labels = False if len(self.label_names) == 0 else all((inputs.get(k) is not None for k in self.label_names))
    return_loss = inputs.get('return_loss', None)
    if return_loss is None:
        return_loss = self.can_return_loss
    loss_without_labels = True if len(self.label_names) == 0 and return_loss else False
    inputs = self._prepare_inputs(inputs)
    if ignore_keys is None:
        if hasattr(self.model, 'config'):
            ignore_keys = getattr(self.model.config, 'keys_to_ignore_at_inference', ['past_key_values'])
        else:
            ignore_keys = []
    if has_labels or loss_without_labels:
        labels = nested_detach(tuple((inputs.get(name) for name in self.label_names)))
        if len(labels) == 1:
            labels = labels[0]
    else:
        labels = None
    with torch.no_grad():
        if is_sagemaker_mp_enabled():
            raw_outputs = smp_forward_only(model, inputs)
            if has_labels or loss_without_labels:
                if isinstance(raw_outputs, dict):
                    loss_mb = raw_outputs['loss']
                    logits_mb = tuple((v for k, v in raw_outputs.items() if k not in ignore_keys + ['loss']))
                else:
                    loss_mb = raw_outputs[0]
                    logits_mb = raw_outputs[1:]
                loss = loss_mb.reduce_mean().detach().cpu()
                logits = smp_nested_concat(logits_mb)
            else:
                loss = None
                if isinstance(raw_outputs, dict):
                    logits_mb = tuple((v for k, v in raw_outputs.items() if k not in ignore_keys))
                else:
                    logits_mb = raw_outputs
                logits = smp_nested_concat(logits_mb)
        elif has_labels or loss_without_labels:
            with self.compute_loss_context_manager():
                loss, outputs = self.compute_loss(model, inputs, return_outputs=True)
            loss = loss.detach().mean()
            if isinstance(outputs, dict):
                logits = tuple((v for k, v in outputs.items() if k not in ignore_keys + ['loss']))
            else:
                logits = outputs[1:]
        else:
            loss = None
            with self.compute_loss_context_manager():
                outputs = model(**inputs)
            if isinstance(outputs, dict):
                logits = tuple((v for k, v in outputs.items() if k not in ignore_keys))
            else:
                logits = outputs
            if self.args.past_index >= 0:
                self._past = outputs[self.args.past_index - 1]
    if prediction_loss_only:
        return (loss, None, None)
    logits = nested_detach(logits)
    if len(logits) == 1:
        logits = logits[0]
    return (loss, logits, labels)

Perform an evaluation step on `model` using `inputs`.

Subclass and override to inject custom behavior.

Args:
model (`nn.Module`):
The model to evaluate.
inputs (`Dict[str, Union[torch.Tensor, Any]]`):
The inputs and targets of the model.

The dictionary will be unpacked before being fed to the model. Most models expect the targets under the
argument `labels`. Check your model's documentation for all accepted arguments.
prediction_loss_only (`bool`):
Whether or not to return the loss only.
ignore_keys (`List[str]`, *optional*):
A list of keys in the output of your model (if it is a dictionary) that should be ignored when
gathering predictions.

Return:
Tuple[Optional[torch.Tensor], Optional[torch.Tensor], Optional[torch.Tensor]]: A tuple with the loss,
logits and labels (each being optional).


def request(session, url, rule_payload, **kwargs):
    if isinstance(rule_payload, dict):
        rule_payload = json.dumps(rule_payload)
    logger.debug('sending request')
    result = session.post(url, data=rule_payload, **kwargs)
    return result

Executes a request with the given payload and arguments.

Args:
session (requests.Session): the valid session object
url (str): Valid API endpoint
rule_payload (str or dict): rule package for the POST. If you pass a
dictionary, it will be converted into JSON.


def __init__(self,
               diag_bijector,
               validate_args=False,
               name="transform_diagonal"):

    self._diag_bijector = diag_bijector
    super(TransformDiagonal, self).__init__(
        forward_min_event_ndims=2,
        inverse_min_event_ndims=2,
        validate_args=validate_args,
        dtype=diag_bijector.dtype,
        name=name)

Instantiates the `TransformDiagonal` bijector.

Args:
diag_bijector: `Bijector` instance used to transform the diagonal.
validate_args: Python `bool` indicating whether arguments should be
checked for correctness.
name: Python `str` name given to ops managed by this object.


def clip(x, x_min, x_max):
    if any_symbolic_tensors((x,)):
        return Clip(x_min, x_max).symbolic_call(x)
    return backend.numpy.clip(x, x_min, x_max)

Clip (limit) the values in a tensor.

Given an interval, values outside the interval are clipped to the
interval edges. For example, if an interval of `[0, 1]` is specified,
values smaller than 0 become 0, and values larger than 1 become 1.

Args:
x: Input tensor.
x_min: Minimum value.
x_max: Maximum value.
Returns:
The clipped tensor.


def __x_google_quota_descriptor(self, metric_costs):
    return ({'metricCosts': {metric: cost for (metric, cost) in metric_costs.items()}} if metric_costs else None)

Describes the metric costs for a call.

Args:
metric_costs: Dict of metric definitions to the integer cost value against
that metric.

Returns:
A dict descriptor describing the Quota limits for the endpoint.


def usufyToCsvExport(d, fPath):

    from pyexcel_io import get_data
    try:
        oldData = {"OSRFramework": get_data(fPath) }
    except:

        oldData = {"OSRFramework":[]}

    tabularData = _generateTabularData(d, oldData)

    from pyexcel_io import save_data

    save_data(fPath, tabularData["OSRFramework"])

Workaround to export to a CSV file.

Args:
-----
d: Data to export.
fPath: File path for the output file.


def prod(x, axis=None, keepdims=False):
    return math_ops.reduce_prod(x, axis, keepdims)

Multiplies the values in a tensor, alongside the specified axis.

Args:
x: A tensor or variable.
axis: An integer, the axis to compute the product.
keepdims: A boolean, whether to keep the dimensions or not.
If `keepdims` is `False`, the rank of the tensor is reduced
by 1. If `keepdims` is `True`,
the reduced dimension is retained with length 1.

Returns:
A tensor with the product of elements of `x`.


def GetLocalPath(self, inode, cache, database):
    local_path = cache.GetResults('local_path')
    if (not local_path):
        results = database.Query(self.LOCAL_PATH_CACHE_QUERY)
        cache.CacheQueryResults(results, 'local_path', 'child_inode_number', ('parent_inode_number', 'filename'))
        local_path = cache.GetResults('local_path')
    (parent, path) = local_path.get(inode, [None, None])
    root_value = '%local_sync_root%/'
    if (not path):
        return root_value
    paths = []
    while path:
        paths.append(path)
        (parent, path) = local_path.get(parent, [None, None])
    if (not paths):
        return root_value
    paths.reverse()
    return (root_value + '/'.join(paths))

Return local path for a given inode.

Args:
inode (int): inode number for the file.
cache (SQLiteCache): cache.
database (SQLiteDatabase): database.

Returns:
str: full path, including the filename of the given inode value.