def reload_napps(self, napps=None):
    if (napps is None):
        napps = []
        api = self._config.get('kytos', 'api')
        endpoint = os.path.join(api, 'api', 'kytos', 'core', 'reload', 'all')
        response = self.make_request(endpoint)
    for napp in napps:
        api = self._config.get('kytos', 'api')
        endpoint = os.path.join(api, 'api', 'kytos', 'core', 'reload', napp[0], napp[1])
        response = self.make_request(endpoint)
    if (response.status_code != 200):
        raise KytosException('Error reloading the napp: Module not founded or could not be imported')
    return response.content

Reload a specific NApp or all Napps.

Args:
napp (list): NApp list to be reload.
Raises:
requests.HTTPError: When there's a server error.


def lookup_id(self, group):
    filter = ['(cn={})'.format(group), '(objectclass=posixGroup)']
    results = self.client.search(filter, ['gidNumber'])
    if (len(results) < 1):
        raise ldap_tools.exceptions.NoGroupsFound('No Groups Returned by LDAP')
    elif (len(results) > 1):
        raise ldap_tools.exceptions.TooManyResults('Multiple groups found. Please narrow your search.')
    else:
        return results[0].gidNumber.value

Lookup GID for the given group.

Args:
group: Name of group whose ID needs to be looked up

Returns:
A bytestring representation of the group ID (gid)
for the group specified

Raises:
ldap_tools.exceptions.NoGroupsFound:
No Groups were returned by LDAP

ldap_tools.exceptions.TooManyResults:
More than one group was returned by LDAP


async def on_message(message):

    server = message.server
    author = message.author
    channel = message.channel
    content = message.content

    data = datatools.get_data()

    if not data["discord"]["servers"][server.id][_data.modulename]["activated"]:
        return

    if server is not None and author != channel.server.me:

        prefix = data["discord"]["servers"][server.id]["prefix"]
        if content.startswith(prefix):

            package = content.split(" ")
            command = package[0][len(prefix):]

            if command == 'gamedeals':
                await client.send_typing(channel)

                posts = api_reddit.get_top10()

                if posts:
                    for post in posts:

                        embed = ui_embed.success(channel, post)
                        await embed.send()
                else:
                    embed = ui_embed.no_results(channel)
                    await embed.send()

The on_message event handler for this module

Args:
message (discord.Message): Input message


def _check_obj_properties(self, pub, name='pub'):
    if (not hasattr(pub, 'indexes')):
        raise InvalidType(("`%s` doesn't have .indexes property!" % name))
    if (not pub.indexes):
        raise InvalidType(('`%s.indexes` is not set!' % name))
    if (not hasattr(pub, 'project_key')):
        raise InvalidType(("`%s` doesn't have .project_key property!" % name))
    if (not pub.project_key):
        raise InvalidType(('`%s.project_key` is not set!' % name))

Make sure, that `pub` has the right interface.

Args:
pub (obj): Instance which will be checked.
name (str): Name of the instance. Used in exception. Default `pub`.

Raises:
InvalidType: When the `pub` is not instance of `obj_type`.


def remove_option(self, section, option):

        try:
            section = self.__getitem__(section)
        except KeyError:
            raise NoSectionError(section) from None
        option = self.optionxform(option)
        existed = option in section.options()
        if existed:
            del section[option]
        return existed

Remove an option.

Args:
section (str): section name
option (str): option name

Returns:
bool: whether the option was actually removed


def interruptWrite(self, endpoint, buffer, timeout = 100):
        r
        return self.dev.write(endpoint, buffer, timeout)

r"""Perform a interrupt write request to the endpoint specified.

Arguments:
endpoint: endpoint number.
buffer: sequence data buffer to write.
This parameter can be any sequence type.
timeout: operation timeout in milliseconds. (default: 100)
Returns the number of bytes written.


def set_record_attn(self, record_attn):

    def _should_record_attn(layer_idx):
        if isinstance(record_attn, bool):
            return record_attn
        return layer_idx in record_attn
    for i, layer in enumerate(self._attn_mods):
        layer.attn.record_attn = _should_record_attn(i)
    if not record_attn:
        self.saved_attn_weights = []

Makes forward prop dump self-attention softmaxes to self.saved_attn_weights.

Args:
record_attn (`Union[bool,set]`):
Either a set of layer indices indicating which layers to store, or a boolean value indicating Whether
to dump all.


def set_timezone(self, timezone: str):

        data = {"timezoneId": timezone}
        return self._restCall("home/setTimezone", body=json.dumps(data))

sets the timezone for the AP. e.g. "Europe/Berlin"
Args:
timezone(str): the new timezone


def _get_oauth2_client_id_and_secret(settings_instance):

    secret_json = getattr(settings_instance,
                          'GOOGLE_OAUTH2_CLIENT_SECRETS_JSON', None)
    if secret_json is not None:
        return _load_client_secrets(secret_json)
    else:
        client_id = getattr(settings_instance, "GOOGLE_OAUTH2_CLIENT_ID",
                            None)
        client_secret = getattr(settings_instance,
                                "GOOGLE_OAUTH2_CLIENT_SECRET", None)
        if client_id is not None and client_secret is not None:
            return client_id, client_secret
        else:
            raise exceptions.ImproperlyConfigured(
                "Must specify either GOOGLE_OAUTH2_CLIENT_SECRETS_JSON, or "
                "both GOOGLE_OAUTH2_CLIENT_ID and "
                "GOOGLE_OAUTH2_CLIENT_SECRET in settings.py")

Initializes client id and client secret based on the settings.

Args:
settings_instance: An instance of ``django.conf.settings``.

Returns:
A 2-tuple, the first item is the client id and the second
item is the client secret.


def main(argv=None):
    if (argv is None):
        argv = sys.argv[1:]
    parser = build_args()
    args = parser.parse_args(args=argv)
    (recipe_name, _ext) = os.path.splitext(os.path.basename(args.recipe))
    rm = RecipeManager()
    rm.add_recipe_folder(os.path.dirname(args.recipe), whitelist=[os.path.basename(args.recipe)])
    recipe = rm.get_recipe(recipe_name)
    if (args.archive is not None):
        print(('Archiving recipe into %s' % args.archive))
        recipe.archive(args.archive)
        return 0
    if args.info:
        print(recipe)
        return 0
    variables = load_variables(args.define, args.config)
    success = 0
    start_time = time.time()
    if (args.loop is None):
        try:
            recipe.run(variables)
            success += 1
        except IOTileException as exc:
            print(('Error running recipe: %s' % str(exc)))
            return 1
    else:
        while True:
            value = input(('Enter value for loop variable %s (return to stop): ' % args.loop))
            if (value == ''):
                break
            local_vars = dict(**variables)
            local_vars[args.loop] = value
            try:
                recipe.run(local_vars)
                success += 1
            except IOTileException as exc:
                print(('--> ERROR processing loop variable %s: %s' % (value, str(exc))))
    end_time = time.time()
    total_time = (end_time - start_time)
    if (success == 0):
        per_time = 0.0
    else:
        per_time = (total_time / success)
    print(('Performed %d runs in %.1f seconds (%.1f seconds / run)' % (success, total_time, per_time)))
    return 0

Main entry point for iotile-ship recipe runner.

This is the iotile-ship command line program.

Args:
argv (list of str): An optional set of command line
parameters.  If not passed, these are taken from
sys.argv.


def clean_headers(headers):

    clean = {}
    try:
        for k, v in six.iteritems(headers):
            if not isinstance(k, six.binary_type):
                k = str(k)
            if not isinstance(v, six.binary_type):
                v = str(v)
            clean[_helpers._to_bytes(k)] = _helpers._to_bytes(v)
    except UnicodeEncodeError:
        from oauth2client.client import NonAsciiHeaderError
        raise NonAsciiHeaderError(k, ': ', v)
    return clean

Forces header keys and values to be strings, i.e not unicode.

The httplib module just concats the header keys and values in a way that
may make the message header a unicode string, which, if it then tries to
contatenate to a binary request body may result in a unicode decode error.

Args:
headers: dict, A dictionary of headers.

Returns:
The same dictionary but with all the keys converted to strings.


def __init__(self, bits: List[int], order: int):
    super().__init__(trainable=False)
    bits = check_bits(bits)
    order = check_order(order)
    indices_list = []
    for i in range(1, order + 1):
        combos = itertools.combinations(range(len(bits)), i)
        indices_list.extend(list(combos))
    self.indices = tf.ragged.stack(indices_list)
    self.num_terms = len(indices_list)

Initializes a Parity layer.

Args:
bits: Unique labels for the bits on which this distribution is supported.
order: Maximum size of bit groups to take the parity of.


def base_name_from_image(image):

    m = re.match("^(.+/)?([^:/]+)(:[^:]+)?$", image)
    algo_name = m.group(2) if m else image
    return algo_name

Extract the base name of the image to use as the 'algorithm name' for the job.

Args:
image (str): Image name.

Returns:
str: Algorithm name, as extracted from the image name.


def when_connected(self):
    if (self._client and (not self._client.is_closed)):
        return defer.succeed(self._client)
    else:
        return self._client_deferred

Retrieve the currently-connected Protocol, or the next one to connect.

Returns:
defer.Deferred: A Deferred that fires with a connected
:class:`FedoraMessagingProtocolV2` instance. This is similar to
the whenConnected method from the Twisted endpoints APIs, which
is sadly isn't available before 16.1.0, which isn't available
in EL7.


def sam2rnf(args):

    rnftools.mishmash.Source.recode_sam_reads(
        sam_fn=args.sam_fn,
        fastq_rnf_fo=args.fq_fo,
        fai_fo=args.fai_fo,
        genome_id=args.genome_id,
        number_of_read_tuples=10**9,
        simulator_name=args.simulator_name,
        allow_unmapped=args.allow_unmapped,
    )

Convert SAM to RNF-based FASTQ with respect to argparse parameters.

Args:
args (...): Arguments parsed by argparse


def infer_annotation(type_comments):

    assert type_comments
    args = {}
    returns = set()
    for comment in type_comments:
        arg_types, return_type = parse_type_comment(comment)
        for i, arg_type in enumerate(arg_types):
            args.setdefault(i, set()).add(arg_type)
        returns.add(return_type)
    combined_args = []
    for i in sorted(args):
        arg_infos = list(args[i])
        kind = argument_kind(arg_infos)
        if kind is None:
            raise InferError('Ambiguous argument kinds:\n' + '\n'.join(type_comments))
        types = [arg.type for arg in arg_infos]
        combined = combine_types(types)
        if str(combined) == 'None':

            combined = UnionType([ClassType('None'), AnyType()])
        if kind != ARG_POS and (len(str(combined)) > 120 or isinstance(combined, UnionType)):

            combined = AnyType()
        combined_args.append(Argument(combined, kind))
    combined_return = combine_types(returns)
    return combined_args, combined_return

Given some type comments, return a single inferred signature.

Args:
type_comments: Strings of form '(arg1, ... argN) -> ret'

Returns: Tuple of (argument types and kinds, return type).


def obtain_all_bond_lengths(sp1, sp2, default_bl=None):
    if isinstance(sp1, Element):
        sp1 = sp1.symbol
    if isinstance(sp2, Element):
        sp2 = sp2.symbol
    syms = tuple(sorted([sp1, sp2]))
    if (syms in bond_lengths):
        return bond_lengths[syms].copy()
    elif (default_bl is not None):
        return {1: default_bl}
    else:
        raise ValueError('No bond data for elements {} - {}'.format(*syms))

Obtain bond lengths for all bond orders from bond length database

Args:
sp1 (Specie): First specie.
sp2 (Specie): Second specie.
default_bl: If a particular type of bond does not exist, use this
bond length as a default value (bond order = 1).
If None, a ValueError will be thrown.

Return:
A dict mapping bond order to bond length in angstrom


def _apply_user_agent(headers, user_agent):
    if (user_agent is not None):
        if ('user-agent' in headers):
            headers['user-agent'] = ((user_agent + ' ') + headers['user-agent'])
        else:
            headers['user-agent'] = user_agent
    return headers

Adds a user-agent to the headers.

Args:
headers: dict, request headers to add / modify user
agent within.
user_agent: str, the user agent to add.

Returns:
dict, the original headers passed in, but modified if the
user agent is not None.


def _GetIdentifierMappings(self, parser_mediator, cache, database):
    identifier_mappings = cache.GetResults('SruDbIdMapTable', default_value={})
    if (not identifier_mappings):
        esedb_table = database.get_table_by_name('SruDbIdMapTable')
        if (not esedb_table):
            parser_mediator.ProduceExtractionWarning('unable to retrieve table: SruDbIdMapTable')
        else:
            identifier_mappings = self._ParseIdentifierMappingsTable(parser_mediator, esedb_table)
        cache.StoreDictInCache('SruDbIdMapTable', identifier_mappings)
    return identifier_mappings

Retrieves the identifier mappings from SruDbIdMapTable table.

In the SRUM database individual tables contain numeric identifiers for
the application ("AppId") and user identifier ("UserId"). A more descriptive
string of these values can be found in the SruDbIdMapTable. For example the
numeric value of 42 mapping to DiagTrack. This method will cache the
mappings of a specific SRUM database.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
cache (ESEDBCache): cache, which contains information about
the identifiers stored in the SruDbIdMapTable table.
database (pyesedb.file): ESE database.

Returns:
dict[int, str]: mapping of numeric identifiers to their string
representation.


def referrer_uri(self, value):

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

The referrer_uri property.

Args:
value (string). the property value.


def can_generate(cls) -> bool:
    if 'GenerationMixin' in str(cls.prepare_inputs_for_generation) and 'GenerationMixin' in str(cls.generate):
        return False
    return True

Returns whether this model can generate sequences with `.generate()`.

Returns:
`bool`: Whether this model can generate sequences with `.generate()`.


def handle(data_type, data, data_id=None, caller=None):
    if (not data_id):
        data_id = data_type
    if (data_id not in _handlers):
        _handlers[data_id] = dict([(h.handle, h) for h in handlers.instantiate_for_data_type(data_type, data_id=data_id)])
    for handler in list(_handlers[data_id].values()):
        try:
            data = handler(data, caller=caller)
        except Exception as inst:
            vodka.log.error(("Data handler '%s' failed with error" % handler))
            vodka.log.error(traceback.format_exc())
    return data

execute all data handlers on the specified data according to data type

Args:
data_type (str): data type handle
data (dict or list): data

Kwargs:
data_id (str): can be used to differentiate between different data
sets of the same data type. If not specified will default to
the data type
caller (object): if specified, holds the object or function that
is trying to handle data

Returns:
dict or list - data after handlers have been executed on it


def get_context_from_cmdln(args, desc="Run scriptworker"):

    context = Context()
    parser = argparse.ArgumentParser(description=desc)
    parser.add_argument(
        "config_path", type=str, nargs="?", default="scriptworker.yaml",
        help="the path to the config file"
    )
    parsed_args = parser.parse_args(args)
    context.config, credentials = create_config(config_path=parsed_args.config_path)
    update_logging_config(context)
    return context, credentials

Create a Context object from args.

Args:
args (list): the commandline args.  Generally sys.argv

Returns:
tuple: ``scriptworker.context.Context`` with populated config, and
credentials frozendict


def get_cert_contents(kwargs):
    paths = {'certificate': kwargs.get('path_to_certificate'), 'private_key': kwargs.get('path_to_private_key'), 'chain': kwargs.get('path_to_chain')}
    for (key, value) in paths.items():
        if (value is not None):
            continue
        path = input(('Path to %s (skip): ' % (key,)))
        if ((path == 'skip') or (not path.strip())):
            continue
        paths[key] = path
    parameters = {'ServerCertificateName': kwargs.get('cert_name')}
    for (key, path) in paths.items():
        if (not path):
            continue
        try:
            contents = path.read()
        except AttributeError:
            with open(utils.full_path(path)) as read_file:
                contents = read_file.read()
        if (key == 'certificate'):
            parameters['CertificateBody'] = contents
        elif (key == 'private_key'):
            parameters['PrivateKey'] = contents
        elif (key == 'chain'):
            parameters['CertificateChain'] = contents
    return parameters

Builds parameters with server cert file contents.

Args:
kwargs(dict): The keyword args passed to ensure_server_cert_exists,
optionally containing the paths to the cert, key and chain files.

Returns:
dict: A dictionary containing the appropriate parameters to supply to
upload_server_certificate. An empty dictionary if there is a
problem.


def _check_or_build_spatial_positions(pos, index_dims, batch_size):
    if pos is None:
        pos = build_linear_positions(index_dims)
        pos = pos[None].expand((batch_size,) + pos.shape)
        pos = torch.reshape(pos, [batch_size, np.prod(index_dims), -1])
    elif pos.shape[-1] != len(index_dims):
        raise ValueError('Spatial features have the wrong number of dimensions.')
    return pos

Checks or builds spatial position features (x, y, ...).

Args:
pos (`torch.FloatTensor`):
None, or an array of position features. If None, position features are built. Otherwise, their size is checked.
index_dims (`List[int]`):
An iterable giving the spatial/index size of the data to be featurized.
batch_size (`int`):
The batch size of the data to be featurized.

Returns:
`torch.FloatTensor` of shape `(batch_size, prod(index_dims))` an array of position features.


def SetDocumentType(self, document_type):
    self._document_type = document_type
    logger.debug('Elasticsearch document type: {0:s}'.format(document_type))

Sets the document type.

Args:
document_type (str): document type.


def get_template(self, template_id):
    request = self._get_request()
    return request.get((self.TEMPLATE_GET_URL + template_id))

Gets a Template which includes a list of Accounts that can access it

Args:

template_id (str): The id of the template to retrieve

Returns:
A Template object


def escape_yaml(raw_str: str) -> str:

    escape_list = [char for char in raw_str if char in ['!', '{', '[']]
    if len(escape_list) == 0:
        return raw_str

    str_quotes = '"'
    i_str_quotes = "'"
    if str_quotes in raw_str and str_quotes not in raw_str[1:-1]:
        return raw_str

    if str_quotes in raw_str[1:-1]:
        raw_str = i_str_quotes + raw_str + i_str_quotes
    else:
        raw_str = str_quotes + raw_str + str_quotes
    return raw_str

Shell-Escape a yaml input string.

Args:
raw_str: The unescaped string.


def __init__(self, session_identifier=None):

    super(Task, self).__init__()
    self.aborted = False
    self.completion_time = None
    self.file_entry_type = None
    self.has_retry = False
    self.identifier = '{0:s}'.format(uuid.uuid4().hex)
    self.last_processing_time = None
    self.merge_priority = None
    self.path_spec = None
    self.session_identifier = session_identifier
    self.start_time = int(time.time() * definitions.MICROSECONDS_PER_SECOND)
    self.storage_file_size = None

Initializes a task attribute container.

Args:
session_identifier (Optional[str]): identifier of the session the task
is part of.


def get_obj_frm_str(obj_str, **kwargs):

    obj_str = obj_str.format(**kwargs)
    args = []
    kwargs = {}
    params = []

    if "(" in obj_str:
        call_args = obj_str[obj_str.find("("):]
        obj_str = obj_str[:obj_str.find("(")]
        call_args = call_args[1:-1]
        if call_args:
            call_args = call_args.split(",")
        else:
            call_args = []
        call_args = [arg.strip() for arg in call_args]

        for arg in call_args:
            if "=" in arg:
                parts = arg.split("=")
                kwargs[parts[0]] = parts[1]
            else:
                args.append(arg)

    if "[" in obj_str:
        params = obj_str[obj_str.find("["):]
        obj_str = obj_str[:obj_str.find("[")]
        params = [part.replace("[", "").replace("]", "")
                  for part in params.split("][")]
    obj = pydoc.locate(obj_str)
    if params:
        for part in params:
            obj = get_attr(obj, part)
    if args or kwargs:
        if kwargs:
            obj = obj.__call__(*args, **kwargs)
        else:
            obj = obj.__call__(*args)
    return obj

Returns a python object from a python object string

args:
obj_str: python object path expamle
"rdfframework.connections.ConnManager[{param1}]"

kwargs:
* kwargs used to format the 'obj_str'


def _get_outer_context_id(self, graph):
    if hasattr(graph, 'outer_graph') and graph.outer_graph:
        return self._get_context_id(graph.outer_graph)
    else:
        return None

Get the ID of the immediate outer context of the input graph.

Args:
graph: The graph (context) in question.

Returns:
If an outer context exists, the immediate outer context name as a string.
If such as outer context does not exist (i.e., `graph` is itself
outermost), `None`.


def write(self, records=None, path=None, fields=None, append=False, gzip=None):
    if (path is None):
        if (not self.is_attached()):
            raise ItsdbError('no path given for detached table')
        else:
            path = self.path
    path = _normalize_table_path(path)
    (dirpath, name) = os.path.split(path)
    if (fields is None):
        fields = self.fields
    if (records is None):
        records = iter(self)
    _write_table(dirpath, name, records, fields, append=append, gzip=gzip, encoding=self.encoding)
    if (self.is_attached() and (path == _normalize_table_path(self.path))):
        self.path = _table_filename(path)
        self._sync_with_file()

Write the table to disk.

The basic usage has no arguments and writes the table's data
to the attached file. The parameters accommodate a variety of
use cases, such as using *fields* to refresh a table to a
new schema or *records* and *append* to incrementally build a
table.

Args:
records: an iterable of :class:`Record` objects to write;
if `None` the table's existing data is used
path: the destination file path; if `None` use the
path of the file attached to the table
fields (:class:`Relation`): table schema to use for
writing, otherwise use the current one
append: if `True`, append rather than overwrite
gzip: compress with gzip if non-empty
Examples:
>>> table.write()
>>> table.write(results, path='new/path/result')


def OpenClient(client_id=None, token=None):
    if (not token):
        try:
            token = ApprovalFind(client_id, token=token)
        except access_control.UnauthorizedAccess as e:
            logging.debug('No authorization found for access to client: %s', e)
    try:
        client = aff4.FACTORY.Open(rdfvalue.RDFURN(client_id), mode='r', token=token)
        return (client, token)
    except access_control.UnauthorizedAccess:
        logging.warning('Unable to find a valid reason for client %s. You may need to request approval.', client_id)
        return (None, None)

Opens the client, getting potential approval tokens.

Args:
client_id: The client id that should be opened.
token: Token to use to open the client

Returns:
tuple containing (client, token) objects or (None, None) on if
no appropriate aproval tokens were found.


def check_data_type(self):
    metadata_type = self.column_metadata.get('type')
    if ((self.type != metadata_type) and (metadata_type not in self.type)):
        raise ValueError("Types of transformer don't match")

Check the type of the transformer and column match.

Args:
column_metadata(dict): Metadata of the column.

Raises a ValueError if the types don't match


def process_data(data, number_to_keep):

    result = dict()

    if number_to_keep != 0:
        data_temp = dict(Counter(data).most_common(number_to_keep))
        data_temp['rest'] = sum(data.values()) - sum(data_temp.values())
        data = data_temp

    labels = data
    values = np.array([data[key] for key in labels], dtype=float)
    pvalues = values / sum(values)
    for position, label in enumerate(labels):
        result[label] = round(pvalues[position], 5)

    return result

Prepare received data for representation.

Args:
data (dict): values to represent (ex. {'001' : 130})
number_to_keep (int): number of elements to show individually.

Returns:
dict: processed data to show.


def cond(pred, true_fn, false_fn):
    return Cond()(pred, true_fn, false_fn)

Conditionally applies `true_fn` or `false_fn`.

Args:
pred: Boolean scalar type
true_fn: Callable returning the output for the `pred == True` case.
false_fn: Callable returning the output for the `pred == False` case.

Returns:
The output of either `true_fn` or `false_fn` depending on pred.


def list_members(self, name, type="USER", recurse=True, max_results=1000):

        results = self.client.service.getListMembership(
            name, type, recurse, max_results, self.proxy_id,
        )
        return [item["member"] for item in results]

Look up all the members of a list.

Args:
name (str): The name of the list
type (str): The type of results to return. "USER" to get users,
"LIST" to get lists.
recurse (bool): Presumably, whether to recurse into member lists
when retrieving users.
max_results (int): Maximum number of results to return.

Returns:
list of strings: names of the members of the list


def sunrise(self, date=None, zenith=None):

        return (segment.sunrise(date, zenith) for segment in self)

Calculate sunrise times for locations.

Args:
date (datetime.date): Calculate rise or set for given date
zenith (str): Calculate sunrise events, or end of twilight
Returns:
list of list of datetime.datetime: The time for the sunrise for
each point in each segment


def prepare_all_data(data_dir, block_pct_tokens_thresh=0.1):

    gs_blocks_dir = os.path.join(data_dir, GOLD_STANDARD_BLOCKS_DIRNAME)
    gs_blocks_filenames = get_filenames(
        gs_blocks_dir, full_path=False, match_regex=re.escape(GOLD_STANDARD_BLOCKS_EXT))
    gs_blocks_fileroots = (
        re.search(r'(.+)' + re.escape(GOLD_STANDARD_BLOCKS_EXT), gs_blocks_filename).group(1)
        for gs_blocks_filename in gs_blocks_filenames)

    return [prepare_data(data_dir, fileroot, block_pct_tokens_thresh)
            for fileroot in gs_blocks_fileroots]

Prepare data for all HTML + gold standard blocks examples in ``data_dir``.

Args:
data_dir (str)
block_pct_tokens_thresh (float): must be in [0.0, 1.0]

Returns:
List[Tuple[str, List[float, int, List[str]], List[float, int, List[str]]]]

See Also:
:func:`prepare_data`


def create_channel(cls, address="spanner.googleapis.com:443", credentials=None):

        grpc_gcp_config = grpc_gcp.api_config_from_text_pb(
            pkg_resources.resource_string(__name__, _SPANNER_GRPC_CONFIG)
        )
        options = [(grpc_gcp.API_CONFIG_CHANNEL_ARG, grpc_gcp_config)]
        return google.api_core.grpc_helpers.create_channel(
            address, credentials=credentials, scopes=cls._OAUTH_SCOPES
        )

Create and return a gRPC channel object.

Args:
address (str): The host for the channel to use.
credentials (~.Credentials): The
authorization credentials to attach to requests. These
credentials identify this application to the service. If
none are specified, the client will attempt to ascertain
the credentials from the environment.

Returns:
grpc.Channel: A gRPC channel object.


def update(self, b):
    hv = self.hashfunc(b)
    (a, b) = self.permutations
    phv = np.bitwise_and((((a * hv) + b) % _mersenne_prime), np.uint64(_max_hash))
    self.hashvalues = np.minimum(phv, self.hashvalues)

Update this MinHash with a new value.
The value will be hashed using the hash function specified by
the `hashfunc` argument in the constructor.

Args:
b: The value to be hashed using the hash function specified.

Example:
To update with a new string value (using the default SHA1 hash
function, which requires bytes as input):

.. code-block:: python

minhash = Minhash()
minhash.update("new value".encode('utf-8'))

We can also use a different hash function, for example, `pyfarmhash`:

.. code-block:: python

import farmhash
def _hash_32(b):
return farmhash.hash32(b)
minhash = MinHash(hashfunc=_hash_32)
minhash.update("new value")


def with_start_after(self, after_namespace):
    namespace_start = _ord_to_namespace((_namespace_to_ord(after_namespace) + 1))
    return NamespaceRange(namespace_start, self.namespace_end, _app=self.app)

Returns a copy of this NamespaceName with a new namespace_start.

Args:
after_namespace: A namespace string.

Returns:
A NamespaceRange object whose namespace_start is the lexographically next
namespace after the given namespace string.

Raises:
ValueError: if the NamespaceRange includes only a single namespace.


def condition_indices(df):
    eigvals = eigenvalues(df)
    cond_idx = np.sqrt((eigvals.max() / eigvals))
    return pd.Series(cond_idx, df.columns, name='Condition index')

Returns a pandas Series with condition indices of the df columns.

Args:
df: pandas DataFrame with columns to run diagnostics on


def _GetEventLogProviderKey(self, log_source):
    table_names = ['event_log_providers']
    column_names = ['event_log_provider_key']
    condition = 'log_source == "{0:s}"'.format(log_source)
    values_list = list(self._database_file.GetValues(table_names, column_names, condition))
    number_of_values = len(values_list)
    if (number_of_values == 0):
        return None
    if (number_of_values == 1):
        values = values_list[0]
        return values['event_log_provider_key']
    raise RuntimeError('More than one value found in database.')

Retrieves the Event Log provider key.

Args:
log_source (str): Event Log source.

Returns:
str: Event Log provider key or None if not available.

Raises:
RuntimeError: if more than one value is found in the database.


def _model_loss(model, inputs, targets, output_loss_metrics=None, sample_weights=None, training=False):
    total_loss = 0
    kwargs = {}
    if model._expects_training_arg:
        kwargs['training'] = training
    if len(inputs) == 1 and (not isinstance(inputs, dict)):
        inputs = inputs[0]
    if any((isinstance(input_t, (np.ndarray, float, int)) for input_t in nest.flatten(inputs))):
        inputs = nest.map_structure(tensor_conversion.convert_to_tensor_v2_with_dispatch, inputs)
    outs = model(inputs, **kwargs)
    outs = nest.flatten(outs)
    if targets:
        targets = training_utils_v1.cast_if_floating_dtype_and_mismatch(targets, outs)
    if sample_weights:
        new_sample_weights = []
        for val in sample_weights:
            if val is not None:
                new_sample_weights.append(training_utils_v1.cast_if_floating_dtype(tensor_conversion.convert_to_tensor_v2_with_dispatch(val)))
            else:
                new_sample_weights.append(None)
        sample_weights = new_sample_weights
    masks = [getattr(t, '_keras_mask', None) for t in outs]
    targets = nest.flatten(targets)
    output_losses = []
    with backend.name_scope('loss'):
        loss_fns = [loss_fn for loss_fn in model.loss_functions if loss_fn is not None]
        custom_losses = model.losses
        if not loss_fns and (not custom_losses):
            if training:
                raise ValueError('The model cannot be trained because it has no loss to optimize.')
            else:
                raise ValueError('The model cannot be evaluated because it has no loss to compute.')
        for i, loss_fn in enumerate(loss_fns):
            weights = sample_weights[i] if sample_weights else None
            mask = masks[i]
            with backend.name_scope(model.output_names[i] + '_loss'):
                if mask is not None:
                    mask = math_ops.cast(mask, outs[i].dtype)
                    if weights is None:
                        weights = mask
                    else:
                        weights = math_ops.cast(weights, outs[i].dtype)
                        mask, _, weights = losses_utils.squeeze_or_expand_dimensions(mask, sample_weight=weights)
                        weights *= mask
                if hasattr(loss_fn, 'reduction'):
                    per_sample_losses = loss_fn.call(targets[i], outs[i])
                    weighted_losses = losses_utils.compute_weighted_loss(per_sample_losses, sample_weight=weights, reduction=losses_utils.ReductionV2.NONE)
                    loss_reduction = loss_fn.reduction
                    if loss_reduction == losses_utils.ReductionV2.AUTO:
                        loss_reduction = losses_utils.ReductionV2.SUM_OVER_BATCH_SIZE
                    output_loss = losses_utils.reduce_weighted_loss(weighted_losses, reduction=loss_reduction)
                else:
                    output_loss = loss_fn(targets[i], outs[i], sample_weight=weights)
                    loss_reduction = losses_utils.ReductionV2.SUM_OVER_BATCH_SIZE
            if len(model.outputs) > 1:
                output_losses.append(output_loss_metrics[i](output_loss))
            if loss_reduction == losses_utils.ReductionV2.SUM_OVER_BATCH_SIZE:
                output_loss = losses_utils.scale_loss_for_distribution(output_loss)
            total_loss += model._loss_weights_list[i] * output_loss
        if custom_losses:
            total_loss += losses_utils.scale_loss_for_distribution(math_ops.add_n(custom_losses))
    return (outs, total_loss, output_losses, masks)

Calculates the loss for a given model.

Args:
model: The model on which metrics are being calculated.
inputs: Either a dictionary of inputs to the model or a list of input
arrays.
targets: List of target arrays.
output_loss_metrics: List of metrics that are used to aggregated output
loss values.
sample_weights: Optional list of sample weight arrays.
training: Whether the model should be run in inference or training mode.

Returns:
Returns the model output, total loss, loss value calculated using the
specified loss function and masks for each output. The total loss includes
regularization losses and applies masking and sample weighting
to the loss value.


def set_current_position(self, position):
    raise NotImplementedError

Updates the last-consumed position to the given position.

A source may invoke this method for records that do not start at split
points. This may modify the internal state of the ``RangeTracker``. If the
record starts at a split point, method ``try_claim()`` **must** be invoked
instead of this method.

Args:
position: starting position of a record being read by a source.


def get_contacts(self, issue):

        if not issue.resource:
            return []

        account_contacts = issue.resource.account.contacts
        try:
            resource_owners = issue.resource.get_owner_emails()

            if type(resource_owners) is list:
                for resource_owner in resource_owners:
                    account_contacts.append({'type': 'email', 'value': resource_owner})
        except AttributeError:
            pass
        return account_contacts

Returns a list of contacts for an issue

Args:
issue (:obj:`RequiredTagsIssue`): Issue record

Returns:
`list` of `dict`


def _register_json_primitive(object_type, encoder, decoder):

  global _TYPE_TO_ENCODER
  global _TYPE_NAME_TO_DECODER
  if object_type not in _TYPE_TO_ENCODER:
    _TYPE_TO_ENCODER[object_type] = encoder
    _TYPE_NAME_TO_DECODER[object_type.__name__] = decoder

Extend what Pipeline can serialize.

Args:
object_type: type of the object.
encoder: a function that takes in an object and returns
a dict of json primitives.
decoder: inverse function of encoder.


def get_iterator_id_fn(unused_dummy):
    return script_ops.numpy_function(generator_state.get_next_id, args, dtypes.int64)

Creates a unique `iterator_id` for each pass over the dataset.

The returned `iterator_id` disambiguates between multiple concurrently
existing iterators.

Args:
unused_dummy: Ignored value.

Returns:
A `tf.int64` tensor whose value uniquely identifies an iterator in
`generator_state`.


def line(self, x0, y0, x1, y1, char):

        if x0 > x1:
            x1, x0 = x0, x1
            y1, y0 = y0, y1

        dx = x1 - x0
        dy = y1 - y0

        if dx == 0 and dy == 0:
            self.point(x0, y0, char)
        elif abs(dx) >= abs(dy):
            for x in range(x0, x1 + 1):
                if dx == 0:
                    y = y0
                else:
                    y = y0 + int(round((x - x0) * dy / float((dx))))
                self.point(x, y, char)
        elif y0 < y1:
            for y in range(y0, y1 + 1):
                if dy == 0:
                    x = x0
                else:
                    x = x0 + int(round((y - y0) * dx / float((dy))))
                self.point(x, y, char)
        else:
            for y in range(y1, y0 + 1):
                if dy == 0:
                    x = x0
                else:
                    x = x1 + int(round((y - y1) * dx / float((dy))))
                self.point(x, y, char)

Create a line on ASCII canvas.

Args:
x0 (int): x coordinate where the line should start.
y0 (int): y coordinate where the line should start.
x1 (int): x coordinate where the line should end.
y1 (int): y coordinate where the line should end.
char (str): character to draw the line with.


def fill_treeview(self, tree, input_dict):

        tree.model().removeRows(0, tree.model().rowCount())

        def add_element(item, key, value):
            child_name = QtWidgets.QStandardItem(key)

            if isinstance(value, dict):
                for key_child, value_child in value.items():
                    add_element(child_name, key_child, value_child)
                item.appendRow(child_name)
            else:
                child_value = QtWidgets.QStandardItem(str(value))

                item.appendRow([child_name, child_value])

        for index, (key, value) in enumerate(input_dict.items()):

            if isinstance(value, dict):
                item = QtWidgets.QStandardItem(key)
                for sub_key, sub_value in value.items():
                    add_element(item, sub_key, sub_value)
                tree.model().appendRow(item)
            elif isinstance(value, str):
                item = QtGui.QStandardItem(key)
                item_value = QtGui.QStandardItem(value)
                item_value.setEditable(True)
                item_value.setSelectable(True)
                tree.model().appendRow([item, item_value])

fills a treeview with nested parameters
Args:
tree: QtWidgets.QTreeView
parameters: dictionary or Parameter object

Returns:


def read_locations(filename):

    data = ConfigParser()
    if filename == '-':
        data.read_file(sys.stdin)
    else:
        data.read(filename)
    if not data.sections():
        logging.debug('Config file is empty')

    locations = {}
    for name in data.sections():
        if data.has_option(name, 'locator'):
            latitude, longitude = utils.from_grid_locator(data.get(name,
                                                                   'locator'))
        else:
            latitude = data.getfloat(name, 'latitude')
            longitude = data.getfloat(name, 'longitude')
        locations[name] = (latitude, longitude)
    return locations

Pull locations from a user's config file.

Args:
filename (str): Config file to parse

Returns:
dict: List of locations from config file


def process_file(options, source_text=None, generate_callgraphs=False, preserve_pytype_vm=False):
    with config.verbosity_from(options):
        loader = load_pytd.create_loader(options)
        src = source_text or io.read_source_file(options.input)
        with io.wrap_pytype_exceptions(PytypeError, filename=options.input):
            ret = analyze.infer_types(src=src, options=options, loader=loader)
            pytd_module = ret.ast
    ast_root_node = astlib.parse(src, options.input, feature_version=options.python_version[1])
    module_name = 'module'
    src_code = source.Code(src, ret.context.vm.opcode_traces, VmTrace, filename=options.input)
    ix = Indexer(ast=astlib, src=src_code, loader=loader, module_name=module_name, pytd_module=pytd_module)
    ix.index(ast_root_node)
    ix.finalize()
    ix.vm = ret.context.vm
    if generate_callgraphs:
        ix.function_map = callgraph.collect_function_map(ix)
    if not preserve_pytype_vm:
        ix.vm = None
    return ix

Process a single file and return cross references.

Args:
options: A dictionary of pytype options.
source_text: Optional text of the file; will be read from the file pointed
to by options.input if not supplied.
generate_callgraphs: Collect call graph information
preserve_pytype_vm: Preserve the pytype vm in the indexer

Returns:
The Indexer object used for indexing.

Raises:
PytypeError if pytype fails.


def add(self, data, name=None):

        if name is None:
            n = len(self.data)
            while "Series %d"%n in self.data:
                n += 1
            name = "Series %d"%n
        self.data[name] = data
        return name

Appends a new column of data to the data source.

Args:
data (seq) : new data to add
name (str, optional) : column name to use.
If not supplied, generate a name of the form "Series ####"

Returns:
str:  the column name used


def format_usage(doc, width=None):

    sections = doc.replace('\r', '').split('\n\n')
    width = width or get_terminal_size().columns or 80
    return '\n\n'.join(_wrap_section(s.strip(), width) for s in sections)

Format the docstring for display to the user.

Args:
doc: The docstring to reformat for display.

Returns:
The docstring formatted to parse and display to the user. This includes
dedenting, rewrapping, and translating the docstring if necessary.


def _ParseChatData(self, data):
    data_store = {}
    if ('body' in data):
        body = data.get('body', '').replace('\n', ' ')
        if (body.startswith('
            body_dict = self._ExtractJQuery(body)
            (title, _, _) = body.partition('{')
            body = '{0:s} <{1!s}>'.format(title[2:], self._DictToListOfStrings(body_dict))
    else:
        body = 'No text.'
    data_store['text'] = body
    room = data.get('rooms', None)
    if (not room):
        room = data.get('room', None)
    if room:
        data_store['room'] = room
    data_store['id'] = data.get('id', None)
    user = data.get('user', None)
    if user:
        try:
            user_sid = int(user)
            data_store['sid'] = user_sid
        except (ValueError, TypeError):
            data_store['user'] = user
    return data_store

Parses chat comment data.

Args:
data (dict[str, object]): chat comment data as returned by SQLite.

Returns:
dict[str, object]: parsed chat comment data.


def serialize_file(struct, path, format=None, encoding='utf-8'):
    try:
        with open(path, 'wb') as f:
            return serialize(struct, format, f, encoding)
    except EnvironmentError as e:
        raise AnyMarkupError(e, traceback.format_exc())

A convenience wrapper of serialize, which accepts path of file to serialize to.

Args:
struct: structure (dict or list) with unicode members to serialize; note that list
can only be serialized to json
path: path of the file to serialize to
format: override markup format to serialize structure as (taken from filename
by default)
encoding: encoding to use when serializing, defaults to utf-8
Returns:
number of bytes written
Raises:
AnyMarkupError if a problem occurs while serializing


def predict_task_proba(self, X, t=0, **kwargs):
    return self.predict_proba(X, **kwargs)[t]

Predicts probabilistic labels for an input X on task t

Args:
X: The input for the predict_proba method
t: The task index to predict for which to predict probabilities
Returns:
An [n, K_t] tensor of predictions for task t
NOTE: By default, this method calls predict_proba and extracts element
t. If it is possible to predict individual tasks in isolation, however,
this method may be overriden for efficiency's sake.


def write_alias_config_hash(alias_config_hash='', empty_hash=False):

        with open(GLOBAL_ALIAS_HASH_PATH, 'w') as alias_config_hash_file:
            alias_config_hash_file.write('' if empty_hash else alias_config_hash)

Write self.alias_config_hash to the alias hash file.

Args:
empty_hash: True if we want to write an empty string into the file. Empty string in the alias hash file
means that we have to perform a full load of the command table in the next run.


def et2roc(et_fo, roc_fo):
    stats_dicts = [{'q': q, 'M': 0, 'w': 0, 'm': 0, 'P': 0, 'U': 0, 'u': 0, 'T': 0, 't': 0, 'x': 0} for q in range((rnftools.lavender.MAXIMAL_MAPPING_QUALITY + 1))]
    for line in et_fo:
        line = line.strip()
        if ((line != '') and (line[0] != '
            (read_tuple_name, tab, info_categories) = line.partition('\t')
            intervals = info_categories.split(',')
            for interval in intervals:
                category = interval[0]
                (left, colon, right) = interval[2:].partition('-')
                for q in range(int(left), (int(right) + 1)):
                    stats_dicts[q][category] += 1
    roc_fo.write(('
    roc_fo.write(('
    roc_fo.write(('
    roc_fo.write(('
    roc_fo.write(('
    roc_fo.write(('
    roc_fo.write(('
    roc_fo.write(('
    roc_fo.write(('
    roc_fo.write(('
    roc_fo.write(('
    roc_fo.write(('
    roc_fo.write(('
    roc_fo.write(('
    roc_fo.write(('
    l_numbers = []
    for line in stats_dicts:
        numbers = [line['M'], line['w'], line['m'], line['P'], line['U'], line['u'], line['T'], line['t'], line['x']]
        if (numbers != l_numbers):
            roc_fo.write(('\t'.join((([str(line['q'])] + list(map(str, numbers))) + [str(sum(numbers))])) + os.linesep))
        l_numbers = numbers

ET to ROC conversion.

Args:
et_fo (file): File object for the ET file.
roc_fo (file): File object for the ROC file.

raises: ValueError


def emit_obj_delete(self, category: str, name: str, timestamp: int, pid: int, tid: int, object_id: int) -> None:
    event = self._create_event('D', category, name, pid, tid, timestamp)
    event['id'] = object_id
    self._events.append(event)

Adds an object deletion event to the trace.

Args:
category: The event category as a string.
name:  The event name as a string.
timestamp:  The timestamp of this event as a long integer.
pid:  Identifier of the process generating this event as an integer.
tid:  Identifier of the thread generating this event as an integer.
object_id: Identifier of the object as an integer.


def _ListFileEntry(self, file_system, file_entry, parent_full_path, output_writer):
    full_path = file_system.JoinPath([parent_full_path, file_entry.name])
    if ((not self._list_only_files) or file_entry.IsFile()):
        output_writer.WriteFileEntry(full_path)
    for sub_file_entry in file_entry.sub_file_entries:
        self._ListFileEntry(file_system, sub_file_entry, full_path, output_writer)

Lists a file entry.

Args:
file_system (dfvfs.FileSystem): file system that contains the file entry.
file_entry (dfvfs.FileEntry): file entry to list.
parent_full_path (str): full path of the parent file entry.
output_writer (StdoutWriter): output writer.


def set_file_logger(filename: str, name: str = 'parsl', level: int = logging.DEBUG, format_string: Optional[str] = None):

    if format_string is None:
        format_string = "%(asctime)s.%(msecs)03d %(name)s:%(lineno)d [%(levelname)s]  %(message)s"

    logger = logging.getLogger(name)
    logger.setLevel(logging.DEBUG)
    handler = logging.FileHandler(filename)
    handler.setLevel(level)
    formatter = logging.Formatter(format_string, datefmt='%Y-%m-%d %H:%M:%S')
    handler.setFormatter(formatter)
    logger.addHandler(handler)

    futures_logger = logging.getLogger("concurrent.futures")
    futures_logger.addHandler(handler)

Add a stream log handler.

Args:
- filename (string): Name of the file to write logs to
- name (string): Logger name
- level (logging.LEVEL): Set the logging level.
- format_string (string): Set the format string

Returns:
-  None


def interior_angle(p1, p2, o=(0, 0)):

    v1 = vector(o, p1)
    v2 = vector(o, p2)
    len1 = distance(o, p1)
    len2 = distance(o, p2)
    try:
        return acos(dot_product(v1, v2) / (len1 * len2))
    except ZeroDivisionError:
        raise ValueError("p1 or p2 is overlapped with origin")

Returns interior angle of two vector(0 <= θ <= pi)
Args:
p1, p2: point (x, y)
o: origin
Raises:
ValueError: p1 or p2 is overlapped with origin


def register_trainable(name, trainable):
    from ray.tune.trainable import Trainable
    from ray.tune.function_runner import wrap_function
    if isinstance(trainable, type):
        logger.debug('Detected class for trainable.')
    elif isinstance(trainable, FunctionType):
        logger.debug('Detected function for trainable.')
        trainable = wrap_function(trainable)
    elif callable(trainable):
        logger.warning('Detected unknown callable for trainable. Converting to class.')
        trainable = wrap_function(trainable)
    if (not issubclass(trainable, Trainable)):
        raise TypeError('Second argument must be convertable to Trainable', trainable)
    _global_registry.register(TRAINABLE_CLASS, name, trainable)

Register a trainable function or class.

Args:
name (str): Name to register.
trainable (obj): Function or tune.Trainable class. Functions must
take (config, status_reporter) as arguments and will be
automatically converted into a class during registration.


Returns the default float type, as a string.

E.g. `'float16'`, `'float32'`, `'float64'`.

Returns:
String, the current default float type.

Example:
>>> tf.keras.backend.floatx()
'float32'


def require_validated(self, req, partial=False, bulk=False):
    representations = ([self.require_representation(req)] if (not bulk) else self.require_representation(req))
    if (bulk and (not isinstance(representations, list))):
        raise ValidationError('Request payload should represent a list of resources.').as_bad_request()
    object_dicts = []
    try:
        for representation in representations:
            object_dict = self.serializer.from_representation(representation)
            self.serializer.validate(object_dict, partial)
            object_dicts.append(object_dict)
    except DeserializationError as err:
        raise err.as_bad_request()
    except ValidationError as err:
        raise err.as_bad_request()
    return (object_dicts if bulk else object_dicts[0])

Require fully validated internal object dictionary.

Internal object dictionary creation is based on content-decoded
representation retrieved from request body. Internal object validation
is performed using resource serializer.

Args:
req (falcon.Request): request object
partial (bool): set to True if partially complete representation
is accepted (e.g. for patching instead of full update). Missing
fields in representation will be skiped.
bulk (bool): set to True if request payload represents multiple
resources instead of single one.

Returns:
dict: dictionary of fields and values representing internal object.
Each value is a result of ``field.from_representation`` call.


def match_row_splits_dtypes(*tensors, **kwargs):
    return_dtype = kwargs.pop('return_dtype', False)
    if kwargs:
        raise ValueError(f'Unexpected keyword args {kwargs}.')
    has_int32 = False
    has_int64 = False
    for tensor in tensors:
        if isinstance(tensor, RaggedTensor):
            if tensor.row_splits.dtype == dtypes.int32:
                has_int32 = True
            else:
                has_int64 = True
    if has_int32 and has_int64:
        if not ragged_config.auto_cast_partition_dtype():
            raise ValueError('Input RaggedTensors have mismatched row_splits dtypes; use RaggedTensor.with_row_splits_dtype() to convert them to compatible dtypes.')
        dtype = dtypes.int64
        tensors = tuple((t.with_row_splits_dtype(dtypes.int64) if isinstance(t, RaggedTensor) else t for t in tensors))
    elif has_int32:
        dtype = dtypes.int32
    else:
        dtype = dtypes.int64
    if return_dtype:
        return (dtype, tensors)
    else:
        return tensors

Return a copy of `tensors` with row_splits all having the same dtype.

Args:
*tensors: A list of Tensors or RaggedTensors.
**kwargs: If 'return_dtype=True', then return a tuple (dtype, tensors),
where `dtype` is the data type used by row-splits, and `tensors` is the
converted list of `Tensors` and `RaggedTensors`.

Returns:
The converted list of `Tensors` and `RaggedTensors`.


async def delCronJob(self, iden):

        cron = self.cell.agenda.appts.get(iden)
        if cron is None:
            raise s_exc.NoSuchIden()
        self._trig_auth_check(cron.useriden)
        await self.cell.agenda.delete(iden)

Delete a cron job

Args:
iden (bytes):  The iden of the cron job to be deleted


def _StopExtractionProcesses(self, abort=False):
    logger.debug('Stopping extraction processes.')
    self._StopMonitoringProcesses()
    if abort:
        self._AbortTerminate()
    logger.debug('Emptying task queue.')
    self._task_queue.Empty()
    for _ in self._processes_per_pid:
        try:
            self._task_queue.PushItem(plaso_queue.QueueAbort(), block=False)
        except errors.QueueFull:
            logger.warning('Task queue full, unable to push abort message.')
    self._AbortJoin(timeout=self._PROCESS_JOIN_TIMEOUT)
    self._task_queue.Close(abort=abort)
    if (not abort):
        self._AbortTerminate()
        self._AbortJoin(timeout=self._PROCESS_JOIN_TIMEOUT)
        self._task_queue.Close(abort=True)
    self._AbortKill()

Stops the extraction processes.

Args:
abort (bool): True to indicated the stop is issued on abort.


def __init__(self, asset_id, amount):

        self.AssetId = asset_id
        self.Amount = amount

Create an instance.

Args:
asset_id (UInt256):
amount (Fixed8):


def _print_test_names_for_suite(suite_class):
    config = config_parser.TestRunConfig()
    runner = test_runner.TestRunner(log_dir=config.log_path, testbed_name=config.testbed_name)
    cls = suite_class(runner, config)
    try:
        cls.setup_suite(config)
    finally:
        cls.teardown_suite()
    last = ''
    for name in runner.get_full_test_names():
        tag = name.split('.')[0]
        if tag != last:
            last = tag
            print('==========> %s <==========' % tag)
        print(name)

Prints the names of all the tests in a suite classes.

Args:
suite_class: a test suite_class to be run.


def sync_main(async_main, config_path=None, default_config=None, should_validate_task=True, loop_function=asyncio.get_event_loop):
    context = _init_context(config_path, default_config)
    _init_logging(context)
    if should_validate_task:
        validate_task_schema(context)
    loop = loop_function()
    loop.run_until_complete(_handle_asyncio_loop(async_main, context))

Entry point for scripts using scriptworker.

This function sets up the basic needs for a script to run. More specifically:
* it creates the scriptworker context and initializes it with the provided config
* the path to the config file is either taken from `config_path` or from `sys.argv[1]`.
* it verifies `sys.argv` doesn't have more arguments than the config path.
* it creates the asyncio event loop so that `async_main` can run

Args:
async_main (function): The function to call once everything is set up
config_path (str, optional): The path to the file to load the config from.
Loads from ``sys.argv[1]`` if ``None``. Defaults to None.
default_config (dict, optional): the default config to use for ``_init_context``.
defaults to None.
should_validate_task (bool, optional): whether we should validate the task
schema. Defaults to True.
loop_function (function, optional): the function to call to get the
event loop; here for testing purposes. Defaults to
``asyncio.get_event_loop``.


def _prepare_headers(self, additional_headers=None, **kwargs):
    user_agent = 'pyseaweed/{version}'.format(version=__version__)
    headers = {'User-Agent': user_agent}
    if (additional_headers is not None):
        headers.update(additional_headers)
    return headers

Prepare headers for http communication.

Return dict of header to be used in requests.

Args:
.. versionadded:: 0.3.2
**additional_headers**: (optional) Additional headers
to be used with request

Returns:
Headers dict. Key and values are string


def fillup_layer(layer_length, arrow_char):

        breakwire_layer = []
        for _ in range(layer_length):
            breakwire_layer.append(BreakWire(arrow_char))
        return breakwire_layer

Creates a layer with BreakWire elements.
Args:
layer_length (int): The length of the layer to create
arrow_char (char): The char used to create the BreakWire element.

Returns:
list: The new layer.


def sort_index(self, **kwargs):
    axis = kwargs.pop('axis', 0)
    index = (self.columns if axis else self.index)
    ascending = kwargs.pop('ascending', True)
    if (ascending is None):
        ascending = False
    kwargs['ascending'] = ascending

    def sort_index_builder(df, **kwargs):
        if axis:
            df.columns = index
        else:
            df.index = index
        return df.sort_index(axis=axis, **kwargs)
    func = self._prepare_method(sort_index_builder, **kwargs)
    new_data = self._map_across_full_axis(axis, func)
    if axis:
        new_columns = pandas.Series(self.columns).sort_values(**kwargs)
        new_index = self.index
    else:
        new_index = pandas.Series(self.index).sort_values(**kwargs)
        new_columns = self.columns
    return self.__constructor__(new_data, new_index, new_columns, self.dtypes.copy())

Sorts the data with respect to either the columns or the indices.

Returns:
DataManager containing the data sorted by columns or indices.


def copy_r(src, dst):

    abssrc = os.path.abspath(src)
    absdst = os.path.abspath(dst)
    try:
        os.makedirs(absdst)
    except OSError:

        pass
    for f in os.listdir(abssrc):
        fpath = os.path.join(abssrc, f)
        if os.path.isfile(fpath):
            shutil.copy(fpath, absdst)
        elif not absdst.startswith(fpath):
            copy_r(fpath, os.path.join(absdst, f))
        else:
            warnings.warn("Cannot copy %s to itself" % fpath)

Implements a recursive copy function similar to Unix's "cp -r" command.
Surprisingly, python does not have a real equivalent. shutil.copytree
only works if the destination directory is not present.

Args:
src (str): Source folder to copy.
dst (str): Destination folder.


def apply(self, window_length, samples=True, func1d=None):
    window_length /= (1 if samples else self.step)
    if (func1d is None):
        func1d = np.mean
    params = self.__dict__.copy()
    out = self._rolling_window(int(window_length), func1d)
    return Curve(out, params=params)

Runs any kind of function over a window.

Args:
window_length (int): the window length. Required.
samples (bool): window length is in samples. Use False for a window
length given in metres.
func1d (function): a function that takes a 1D array and returns a
scalar. Default: ``np.mean()``.

Returns:
Curve.


def intrusion_sets(self, name, owner=None, **kwargs):

        return IntrusionSet(self.tcex, name, owner=owner, **kwargs)

Create the Intrustion Set TI object.

Args:
owner:
name:
**kwargs:

Return:


def stop_tuning_job(self, name):
    try:
        LOGGER.info('Stopping tuning job: {}'.format(name))
        self.sagemaker_client.stop_hyper_parameter_tuning_job(HyperParameterTuningJobName=name)
    except ClientError as e:
        error_code = e.response['Error']['Code']
        if (error_code == 'ValidationException'):
            LOGGER.info('Tuning job: {} is already stopped or not running.'.format(name))
        else:
            LOGGER.error('Error occurred while attempting to stop tuning job: {}. Please try again.'.format(name))
            raise

Stop the Amazon SageMaker hyperparameter tuning job with the specified name.

Args:
name (str): Name of the Amazon SageMaker hyperparameter tuning job.

Raises:
ClientError: If an error occurs while trying to stop the hyperparameter tuning job.


def get_compound_bodies(node):
    if isinstance(node, (ast.Module, ast.FunctionDef, ast.ClassDef, ast.With)):
        return [node.body]
    elif isinstance(node, (ast.If, ast.While, ast.For)):
        return [node.body, node.orelse]
    elif (PY2 and isinstance(node, ast.TryFinally)):
        return [node.body, node.finalbody]
    elif (PY2 and isinstance(node, ast.TryExcept)):
        return ([node.body, node.orelse] + [h.body for h in node.handlers])
    elif (PY3 and isinstance(node, ast.Try)):
        return ([node.body, node.orelse, node.finalbody] + [h.body for h in node.handlers])
    end
    return []

Returns a list of bodies of a compound statement node.

Args:
node: AST node.

Returns:
A list of bodies of the node. If the given node does not represent
a compound statement, an empty list is returned.


def replace_batch_norm(model):
    for name, module in model.named_children():
        if isinstance(module, nn.BatchNorm2d):
            new_module = ConditionalDetrFrozenBatchNorm2d(module.num_features)
            if not module.weight.device == torch.device('meta'):
                new_module.weight.data.copy_(module.weight)
                new_module.bias.data.copy_(module.bias)
                new_module.running_mean.data.copy_(module.running_mean)
                new_module.running_var.data.copy_(module.running_var)
            model._modules[name] = new_module
        if len(list(module.children())) > 0:
            replace_batch_norm(module)

Recursively replace all `torch.nn.BatchNorm2d` with `ConditionalDetrFrozenBatchNorm2d`.

Args:
model (torch.nn.Module):
input model


def delete(workflow_id: str = None, workflow_version: str = None):

    if workflow_id is None and workflow_version is None:
        keys = DB.get_keys("workflow_definitions:*")
        DB.delete(*keys)
    elif workflow_id is not None and workflow_version is None:
        keys = DB.get_keys("workflow_definitions:{}:*".format(workflow_id))
        DB.delete(*keys)
    elif workflow_id is None and workflow_version is not None:
        keys = DB.get_keys("workflow_definitions:*:{}"
                           .format(workflow_version))
        DB.delete(*keys)
    else:
        name = "workflow_definitions:{}:{}".format(workflow_id,
                                                   workflow_version)
        DB.delete(name)

Delete workflow definitions.

Args:
workflow_id (str, optional): Optional workflow identifier
workflow_version (str, optional): Optional workflow identifier version

If workflow_id and workflow_version are None, delete all workflow
definitions.


def broadcast_dynamic_shape(shape_x: dynamic_ragged_shape.DenseOrRaggedShape, shape_y: dynamic_ragged_shape.DenseOrRaggedShape) -> dynamic_ragged_shape.DynamicRaggedShape:
    if not isinstance(shape_x, dynamic_ragged_shape.DynamicRaggedShape):
        shape_x = dynamic_ragged_shape.DynamicRaggedShape([], shape_x)
    if not isinstance(shape_y, dynamic_ragged_shape.DynamicRaggedShape):
        shape_y = dynamic_ragged_shape.DynamicRaggedShape([], shape_y)
    return dynamic_ragged_shape.broadcast_dynamic_shape(shape_x, shape_y)

Returns the shape formed by broadcasting two shapes to be compatible.

1. If shape_x and shape_y both have row_partitions, then fail if their dtypes
don't match.
2. If neither has row_partitions and they have different dtypes,
go with int64.
3. If one has row_partitions, go with that dtype.

Args:
shape_x: A `DynamicRaggedShape`
shape_y: A `DynamicRaggedShape`

Returns:
A `DynamicRaggedShape`.
Raises:
ValueError: If `shape_x` and `shape_y` are not broadcast-compatible.


def append_with_data(url, data):

        if data is None:
            return url

        url_parts = list(urlparse(url))

        query = OrderedDict(parse_qsl(url_parts[4], keep_blank_values=True))
        query.update(data)

        url_parts[4] = URLHelper.query_dict_to_string(query)

        return urlunparse(url_parts)

Append the given URL with the given data OrderedDict.

Args:
url (str): The URL to append.
data (obj): The key value OrderedDict to append to the URL.

Returns:
str: The new URL.


def info(self):
    result = list()
    result.append('Agents:\n')
    for agent in self._all_agents:
        result.append('\tName: ')
        result.append(agent.name)
        result.append('\n\tType: ')
        result.append(type(agent).__name__)
        result.append('\n\t')
        result.append('Sensors:\n')
        for sensor in self._sensor_map[agent.name].keys():
            result.append('\t\t')
            result.append(Sensors.name(sensor))
            result.append('\n')
    return ''.join(result)

Returns a string with specific information about the environment.
This information includes which agents are in the environment and which sensors they have.

Returns:
str: The information in a string format.


def save_results(self, output_dir='.', prefix='', prefix_sep='_',
                     image_list=None):

        if prefix == '':
            prefix_sep = ''

        if not exists(output_dir):
            makedirs(output_dir)

        logger.debug("Saving results...")
        if image_list is None:
            image_list = self.images.keys()
        for suffix, img in self.images.items():
            if suffix in image_list:
                filename = prefix + prefix_sep + suffix + '.nii.gz'
                outpath = join(output_dir, filename)
                imageutils.save_img(img, outpath, self.dataset.masker)

Write out any images generated by the meta-analysis.
Args:
output_dir (str): folder to write images to
prefix (str): all image files will be prepended with this string
prefix_sep (str): glue between the prefix and rest of filename
image_list (list): optional list of images to save--e.g.,
['pFgA_z', 'pAgF']. If image_list is None (default), will save
all images.


def get_meta_graph_def_from_tags(self, tags):
    found_match = False
    meta_graph_def_to_load = None
    available_tags = []
    for meta_graph_def in self._saved_model.meta_graphs:
        available_tags.append(set(meta_graph_def.meta_info_def.tags))
        if set(meta_graph_def.meta_info_def.tags) == set(tags):
            meta_graph_def_to_load = meta_graph_def
            found_match = True
            break
    if not found_match:
        raise RuntimeError(f"MetaGraphDef associated with tags {str(tags).strip('[]')} could not be found in SavedModel, with available tags '{available_tags}'. To inspect available tag-sets in the SavedModel, please use the SavedModel CLI: `saved_model_cli`.")
    return meta_graph_def_to_load

Return MetaGraphDef with the exact specified tags.

Args:
tags: A list or set of string tags that identify the MetaGraphDef.

Returns:
MetaGraphDef with the same tags.

Raises:
RuntimeError: if no metagraphs were found with the associated tags.


def stream(
        self,
        accountID,
        **kwargs
    ):

        request = Request(
            'GET',
            '/v3/accounts/{accountID}/transactions/stream'
        )

        request.set_path_param(
            'accountID',
            accountID
        )

        request.set_stream(True)

        class Parser():
            def __init__(self, ctx):
                self.ctx = ctx

            def __call__(self, line):
                j = json.loads(line.decode('utf-8'))

                type = j.get("type")

                if type is None:
                    return ("unknown", j)
                elif type == "HEARTBEAT":
                    return (
                        "transaction.TransactionHeartbeat",
                        self.ctx.transaction.TransactionHeartbeat.from_dict(
                            j,
                            self.ctx
                        )
                    )

                transaction = self.ctx.transaction.Transaction.from_dict(
                    j, self.ctx
                )

                return (
                    "transaction.Transaction",
                    transaction
                )

        request.set_line_parser(
            Parser(self.ctx)
        )

        response = self.ctx.request(request)

        return response

Get a stream of Transactions for an Account starting from when the
request is made.

Args:
accountID:
Account Identifier

Returns:
v20.response.Response containing the results from submitting the
request


def FromDictionary(cls, dictionary):

    if 'user_id' in dictionary:
      raise errors.GitkitClientError('use localId instead')
    if 'localId' not in dictionary:
      raise errors.GitkitClientError('must specify localId')
    if 'email' not in dictionary:
      raise errors.GitkitClientError('must specify email')

    return cls(decode=False, **dictionary)

Initializes from user specified dictionary.

Args:
dictionary: dict of user specified attributes
Returns:
GitkitUser object


def _convert_keras_to_saved_model(self, output_dir):
    try:

        def _is_keras_3():

            try:
                import keras
                return keras.__version__.startswith('3') and isinstance(self._keras_model, keras.layers.Layer)
            except ImportError:
                return False
        if _is_keras_3():
            import keras
            export_archive = keras.export.ExportArchive()
            export_archive.track(self._keras_model)
            if isinstance(self._keras_model, (keras.src.models.Functional, keras.src.models.Sequential)):
                input_signature = nest.map_structure(lambda x: tensor_spec.TensorSpec(x.shape, dtype=x.dtype, name=x.name), self._keras_model.inputs)
                if isinstance(input_signature, list) and len(input_signature) > 1:
                    input_signature = [input_signature]
            else:
                save_spec = _get_save_spec(self._keras_model)
                if not save_spec:
                    raise ValueError('The model provided has never been called. It must be called at least once before export.')
                input_signature = [save_spec]
            inference_fn = functools.partial(self._keras_model.__call__, training=False)
            export_archive.add_endpoint('serve', inference_fn, input_signature)
            export_archive.write_out(output_dir)
        else:
            _save.save(self._keras_model, output_dir, options=_save_options.SaveOptions(save_debug_info=True))
    except Exception:
        return (None, None, None)
    self.saved_model_dir = output_dir
    self._saved_model_tags = set([_tag_constants.SERVING])
    self._saved_model_exported_names = [_signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY]
    self._parse_saved_model_args(always_enable_saved_model_import=self.experimental_lower_to_saved_model)
    if self.saved_model_dir:
        graph_def, input_tensors, output_tensors = self._load_saved_model(self.saved_model_dir, self._saved_model_tags)
        self._trackable_obj = _load(self.saved_model_dir, self._saved_model_tags)
        return (graph_def, input_tensors, output_tensors)
    return (None, None, None)

Save Keras model to the SavedModel format.

Args:
output_dir: The output directory to save the SavedModel.

Returns:
graph_def: The frozen GraphDef.
input_tensors: List of input tensors.
output_tensors: List of output tensors.


def _to_tf_type(dtype):
    return dtypes.as_dtype(dtype)

Converts a native python or numpy type to TF DType.

Args:
dtype: Could be a python type, a numpy type or a TF DType.

Returns:
A tensorflow `DType`.


def transform(self, args):
    if self.parse_error():
        AliasManager.write_alias_config_hash(empty_hash=True)
        return args
    if self.detect_alias_config_change():
        self.load_full_command_table()
        self.collided_alias = AliasManager.build_collision_table(self.alias_table.sections())
        build_tab_completion_table(self.alias_table)
    else:
        self.load_collided_alias()
    transformed_commands = []
    alias_iter = enumerate(args, 1)
    for (alias_index, alias) in alias_iter:
        is_collided_alias = ((alias in self.collided_alias) and (alias_index in self.collided_alias[alias]))
        is_named_arg = ((alias_index > 1) and args[(alias_index - 2)].startswith('-'))
        is_named_arg_flag = alias.startswith('-')
        excluded_commands = is_alias_command(['remove', 'export'], transformed_commands)
        if ((not alias) or is_collided_alias or is_named_arg or is_named_arg_flag or excluded_commands):
            transformed_commands.append(alias)
            continue
        full_alias = self.get_full_alias(alias)
        if self.alias_table.has_option(full_alias, 'command'):
            cmd_derived_from_alias = self.alias_table.get(full_alias, 'command')
            telemetry.set_alias_hit(full_alias)
        else:
            transformed_commands.append(alias)
            continue
        pos_args_table = build_pos_args_table(full_alias, args, alias_index)
        if pos_args_table:
            logger.debug(POS_ARG_DEBUG_MSG, full_alias, cmd_derived_from_alias, pos_args_table)
            transformed_commands += render_template(cmd_derived_from_alias, pos_args_table)
            for pos_arg in pos_args_table:
                next(alias_iter)
        else:
            logger.debug(DEBUG_MSG, full_alias, cmd_derived_from_alias)
            transformed_commands += shlex.split(cmd_derived_from_alias)
    return self.post_transform(transformed_commands)

Transform any aliases in args to their respective commands.

Args:
args: A list of space-delimited command input extracted directly from the console.

Returns:
A list of transformed commands according to the alias configuration file.


def validate(datapackage, schema='base'):
    errors = []
    schema_obj = None
    datapackage_obj = None
    if isinstance(datapackage, six.string_types):
        try:
            datapackage_obj = json.loads(datapackage)
        except ValueError as e:
            errors.append(DataPackageValidateException(e))
    elif (not isinstance(datapackage, dict)):
        msg = "Data Package must be a dict or JSON string, but was a '{0}'"
        dp_type = type(datapackage).__name__
        error = DataPackageValidateException(msg.format(dp_type))
        errors.append(error)
    else:
        datapackage_obj = datapackage
    try:
        if isinstance(schema, six.string_types):
            try:
                schema = json.loads(schema)
            except ValueError:
                pass
        schema_obj = Schema(schema)
    except (SchemaError, RegistryError) as e:
        errors.append(e)
    if ((datapackage_obj is not None) and (schema_obj is not None)):
        try:
            schema_obj.validate(datapackage_obj)
        except ValidationError as e:
            errors.append(e)
    if errors:
        exception = DataPackageValidateException()
        exception.errors = errors
        raise exception

Validate Data Package datapackage.json files against a jsonschema.

Args:
datapackage (str or dict): The Data Package descriptor file (i.e.
datapackage.json) as a dict or its contents in a string.
schema (str or dict): If a string, it can be the schema ID in the
registry, a local path, a URL or the schema's JSON as a string. If
a dict, it must be the JSON Schema itself.

Returns:
None

Raises:
DataPackageValidateException: This exception has the list of the
validation errors in its `.errors` attribute.


def register_multi_flags_validator(flag_names, multi_flags_checker, message='Flags validation failed', flag_values=FLAGS):
    v = gflags_validators.MultiFlagsValidator(flag_names, multi_flags_checker, message)
    _add_validator(flag_values, v)

Adds a constraint to multiple flags.

The constraint is validated when flags are initially parsed, and after each
change of the corresponding flag's value.

Args:
flag_names: [str], a list of the flag names to be checked.
multi_flags_checker: callable, a function to validate the flag.
input - dictionary, with keys() being flag_names, and value for each key
being the value of the corresponding flag (string, boolean, etc).
output - Boolean. Must return True if validator constraint is satisfied.
If constraint is not satisfied, it should either return False or
raise gflags.ValidationError.
message: Error text to be shown to the user if checker returns False.
If checker raises gflags.ValidationError, message from the raised error
will be shown.
flag_values: An optional FlagValues instance to validate against.

Raises:
AttributeError: If a flag is not registered as a valid flag name.


async def check_status(self, pipeline_uuid: str) -> api_pb2.Status:
    self._verify_pipeline_uuid(pipeline_uuid)
    request = api_pb2.CheckStatusRequest(pipeline_uuid=pipeline_uuid)
    response = await self._stub.CheckStatus(request, **self._kwargs)
    return response.status

Get status of the pipeline by his pipeline

Args:
pipeline_uuid: uuid of the pipeline

Returns:
status: status of the pipeline


def task_done(self, message):

        topic_partition = (message.topic, message.partition)
        if topic_partition not in self._topics:
            logger.warning('Unrecognized topic/partition in task_done message: '
                           '{0}:{1}'.format(*topic_partition))
            return False

        offset = message.offset

        prev_done = self._offsets.task_done[topic_partition]
        if prev_done is not None and offset != (prev_done + 1):
            logger.warning('Marking task_done on a non-continuous offset: %d != %d + 1',
                           offset, prev_done)

        prev_commit = self._offsets.commit[topic_partition]
        if prev_commit is not None and ((offset + 1) <= prev_commit):
            logger.warning('Marking task_done on a previously committed offset?: %d (+1) <= %d',
                           offset, prev_commit)

        self._offsets.task_done[topic_partition] = offset

        if self._does_auto_commit_messages():
            self._incr_auto_commit_message_count()

        if self._should_auto_commit():
            self.commit()

        return True

Mark a fetched message as consumed.

Offsets for messages marked as "task_done" will be stored back
to the kafka cluster for this consumer group on commit()

Arguments:
message (KafkaMessage): the message to mark as complete

Returns:
True, unless the topic-partition for this message has not
been configured for the consumer. In normal operation, this
should not happen. But see github issue 364.


def _download(self):
    repo = self._config.get('napps', 'repo')
    napp_id = '{}/{}-{}.napp'.format(self.user, self.napp, self.version)
    uri = os.path.join(repo, napp_id)
    return urllib.request.urlretrieve(uri)[0]

Download NApp package from server.

Return:
str: Downloaded temp filename.

Raises:
urllib.error.HTTPError: If download is not successful.


def _CreateStyleForRoute(self, doc, route):

    style_id = 'route_%s' % route.route_id
    style = ET.SubElement(doc, 'Style', {'id': style_id})
    linestyle = ET.SubElement(style, 'LineStyle')
    width = ET.SubElement(linestyle, 'width')
    type_to_width = {0: '3',
                     1: '3',
                     2: '5',
                     3: '1'}
    width.text = type_to_width.get(route.route_type, '1')
    if route.route_color:
      color = ET.SubElement(linestyle, 'color')
      red = route.route_color[0:2].lower()
      green = route.route_color[2:4].lower()
      blue = route.route_color[4:6].lower()
      color.text = 'ff%s%s%s' % (blue, green, red)
    return style_id

Create a KML Style element for the route.

The style sets the line colour if the route colour is specified. The
line thickness is set depending on the vehicle type.

Args:
doc: The KML Document ElementTree.Element instance.
route: The transitfeed.Route to create the style for.

Returns:
The id of the style as a string.


def parent_callback(self, executor_fu):
    with self._update_lock:
        if (not executor_fu.done()):
            raise ValueError('done callback called, despite future not reporting itself as done')
        if (executor_fu != self.parent):
            if ((executor_fu.exception() is None) and (not isinstance(executor_fu.result(), RemoteExceptionWrapper))):
                raise ValueError('internal consistency error: AppFuture done callback called without an exception, but parent has been changed since then')
        try:
            res = executor_fu.result()
            if isinstance(res, RemoteExceptionWrapper):
                res.reraise()
            super().set_result(executor_fu.result())
        except Exception as e:
            if (executor_fu.retries_left > 0):
                pass
            else:
                super().set_exception(e)

Callback from a parent future to update the AppFuture.

Used internally by AppFuture, and should not be called by code using AppFuture.

Args:
- executor_fu (Future): Future returned by the executor along with callback.
This may not be the current parent future, as the parent future may have
already been updated to point to a retrying execution, and in that case,
this is logged.

In the case that a new parent has been attached, we must immediately discard
this result no matter what it contains (although it might be interesting
to log if it was successful...)

Returns:
- None

Updates the super() with the result() or exception()


def get_content_of_file(self, name, full_path=False):

        if self.handle:
            for member in self.handle.getmembers():
                if (full_path and member.name == name) or (
                        not full_path and os.path.basename(
                            member.name) == name):
                    extracted = self.handle.extractfile(member)
                    return extracted.read().decode(
                        locale.getpreferredencoding())

        return None

Returns content of file from archive.

If full_path is set to False and two files with given name exist,
content of one is returned (it is not specified which one that is).
If set to True, returns content of exactly that file.

Args:
name: name of the file to get content of
Returns:
Content of the file with given name or None, if no such.


def _NormalizedVolumeIdentifiers(self, volume_system, volume_identifiers, prefix='v'):
    normalized_volume_identifiers = []
    for volume_identifier in volume_identifiers:
        if isinstance(volume_identifier, int):
            volume_identifier = '{0:s}{1:d}'.format(prefix, volume_identifier)
        elif (not volume_identifier.startswith(prefix)):
            try:
                volume_identifier = int(volume_identifier, 10)
                volume_identifier = '{0:s}{1:d}'.format(prefix, volume_identifier)
            except (TypeError, ValueError):
                pass
        try:
            volume = volume_system.GetVolumeByIdentifier(volume_identifier)
        except KeyError:
            volume = None
        if (not volume):
            raise errors.ScannerError('Volume missing for identifier: {0:s}.'.format(volume_identifier))
        normalized_volume_identifiers.append(volume_identifier)
    return normalized_volume_identifiers

Normalizes volume identifiers.

Args:
volume_system (VolumeSystem): volume system.
volume_identifiers (list[int|str]): allowed volume identifiers, formatted
as an integer or string with prefix.
prefix (Optional[str]): volume identifier prefix.

Returns:
list[str]: volume identifiers with prefix.

Raises:
ScannerError: if the volume identifier is not supported or no volume
could be found that corresponds with the identifier.


def __enter__(self) -> str:
    ctx = context.context()
    if ctx.executing_eagerly():
        old_name = ctx.scope_name
        name = self._name
        if not name:
            scope_name = ''
        elif name[-1] == '/':
            scope_name = name
        elif old_name:
            scope_name = old_name + name + '/'
        else:
            scope_name = name + '/'
        ctx.scope_name = scope_name

        def _restore_name_scope(*_):
            ctx.scope_name = old_name
        self._exit_fns.append(_restore_name_scope)
    else:
        scope = get_default_graph().name_scope(self._name)
        scope_name = scope.__enter__()
        self._exit_fns.append(scope.__exit__)
    return scope_name

Start the scope block.

Returns:
The scope name.


def prepend_to_list(self, key, *value, pipeline=False):
    if pipeline:
        self._pipeline.lpush(key, *value)
    else:
        self._db.lpush(key, *value)

Add new element to the start of the list stored at key.

Args:
key (str): Key where the list is stored
value: Value to add to the list
pipeline (bool): True, start a transaction block. Default false.


def get_cond_latents(all_latents=None, hparams=None):

  cond_latents = None
  if hparams.gen_mode == "conditional":
    if hparams.latent_dist_encoder in ["conv_net", "conv3d_net"]:
      num_cond_latents = (hparams.num_cond_latents +
                          int(hparams.cond_first_frame))
      if len(all_latents) >= num_cond_latents:
        cond_latents = all_latents[-hparams.num_cond_latents:]
        if hparams.cond_first_frame:
          cond_latents = [all_latents[0]] + cond_latents
    elif hparams.latent_dist_encoder in ["pointwise", "conv_lstm"]:
      if all_latents:
        cond_latents = all_latents[-1]

  if hparams.gen_mode == "conditional":
    global_step = tf.train.get_or_create_global_step()
    condition = tf.greater(global_step, hparams.pretrain_steps)
  else:
    condition = tf.constant(False, dtype=tf.bool)
  return condition, cond_latents

Get z^{cond}_{t} given z^{1..t-1}.

Args:
all_latents: list of list of tensors,
outer-size equals no.of time_steps-1
inner-size equals hparams.n_levels.
hparams: See next_frame_glow_hparams.
Returns:
cond_latents: conditional latents at time-step t.


def draw_rect(self, rect):

        check_int_err(lib.SDL_RenderDrawRect(self._ptr, rect._ptr))

Draw a rectangle on the current rendering target.

Args:
rect (Rect): The destination rectangle, or None to outline the entire rendering target.

Raises:
SDLError: If an error is encountered.


def _weight_generator(self, reviewers):

        scores = [r.anomalous_score for r in reviewers]
        mu = np.average(scores)
        sigma = np.std(scores)

        if sigma:
            def w(v):

                try:
                    exp = math.exp(self.alpha * (v - mu) / sigma)
                    return 1. / (1. + exp)
                except OverflowError:
                    return 0.

            return w

        else:

            return lambda v: 1.

Compute a weight function for the given reviewers.

Args:
reviewers: a set of reviewers to compute weight function.

Returns:
a function computing a weight for a reviewer.


def as_dataframe(self, pattern='*', max_rows=None):

    data = []
    for i, group in enumerate(self.list(pattern)):
      if max_rows is not None and i >= max_rows:
        break
      parent = self._group_dict.get(group.parent_id)
      parent_display_name = '' if parent is None else parent.display_name
      data.append([
          group.id, group.display_name, group.parent_id,
          parent_display_name, group.is_cluster, group.filter])

    return pandas.DataFrame(data, columns=self._DISPLAY_HEADERS)

Creates a pandas dataframe from the groups that match the filters.

Args:
pattern: An optional pattern to further filter the groups. This can
include Unix shell-style wildcards. E.g. ``"Production *"``,
``"*-backend"``.
max_rows: The maximum number of groups to return. If None, return all.

Returns:
A pandas dataframe containing matching groups.


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

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

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

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

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


def get_keypoint_predictions(heatmaps: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:
    if not isinstance(heatmaps, np.ndarray):
        raise ValueError('Heatmaps should be np.ndarray')
    if heatmaps.ndim != 4:
        raise ValueError('Heatmaps should be 4-dimensional')
    batch_size, num_keypoints, _, width = heatmaps.shape
    heatmaps_reshaped = heatmaps.reshape((batch_size, num_keypoints, -1))
    idx = np.argmax(heatmaps_reshaped, 2).reshape((batch_size, num_keypoints, 1))
    scores = np.amax(heatmaps_reshaped, 2).reshape((batch_size, num_keypoints, 1))
    preds = np.tile(idx, (1, 1, 2)).astype(np.float32)
    preds[:, :, 0] = preds[:, :, 0] % width
    preds[:, :, 1] = preds[:, :, 1]
    preds = np.where(np.tile(scores, (1, 1, 2)) > 0.0, preds, -1)
    return (preds, scores)

Get keypoint predictions from score maps.

Args:
heatmaps (`np.ndarray` of shape `(batch_size, num_keypoints, height, width)`):
Model predicted heatmaps.

Returns:
tuple: A tuple containing aggregated results.

- coords (`np.ndarray` of shape `(batch_size, num_keypoints, 2)`):
Predicted keypoint location.
- scores (`np.ndarray` of shape `(batch_size, num_keypoints, 1)`):
Scores (confidence) of the keypoints.


def parse_compounds(compound_info, case_id, variant_type):
    compounds = []
    if compound_info:
        for family_info in compound_info.split(','):
            splitted_entry = family_info.split(':')
            if (splitted_entry[0] == case_id):
                for compound in splitted_entry[1].split('|'):
                    splitted_compound = compound.split('>')
                    compound_obj = {}
                    compound_name = splitted_compound[0]
                    compound_obj['variant'] = generate_md5_key((compound_name.split('_') + [variant_type, case_id]))
                    try:
                        compound_score = float(splitted_compound[1])
                    except (TypeError, IndexError):
                        compound_score = 0.0
                    compound_obj['score'] = compound_score
                    compound_obj['display_name'] = compound_name
                    compounds.append(compound_obj)
    return compounds

Get a list with compounds objects for this variant.

Arguments:
compound_info(str): A Variant dictionary
case_id (str): unique family id
variant_type(str): 'research' or 'clinical'

Returns:
compounds(list(dict)): A list of compounds


def extractHolidayDate(self, setting_holiday):

        ret = namedtuple("result", ["Holiday", "Month", "Day"])
        setting_holiday += 1
        ret.Holiday = str(setting_holiday)

        if (setting_holiday < 1) or (setting_holiday > Extents.Holidays):
            ekm_log("Out of bounds:  holiday " + str(setting_holiday))
            ret.Holiday = ret.Month = ret.Day = str(0)
            return ret

        idxday = "Holiday_" + str(setting_holiday) + "_Day"
        idxmon = "Holiday_" + str(setting_holiday) + "_Mon"
        if idxmon not in self.m_hldy:
            ret.Holiday = ret.Month = ret.Day = str(0)
            return ret
        if idxday not in self.m_hldy:
            ret.Holiday = ret.Month = ret.Day = str(0)
            return ret
        ret.Day = self.m_hldy[idxday][MeterData.StringValue]
        ret.Month = self.m_hldy[idxmon][MeterData.StringValue]
        return ret

Read a single holiday date from meter buffer.

Args:
setting_holiday (int):  Holiday from 0-19 or in range(Extents.Holidays)

Returns:
tuple: Holiday tuple, elements are strings.

=============== ======================
Holiday         Holiday 0-19 as string
Day             Day 1-31 as string
Month           Monty 1-12 as string
=============== ======================


def _ParseKeyWithPlugin(self, parser_mediator, registry_key, plugin):

    try:
      plugin.UpdateChainAndProcess(parser_mediator, registry_key)
    except (IOError, dfwinreg_errors.WinRegistryValueError) as exception:
      parser_mediator.ProduceExtractionWarning(
          'in key: {0:s} error: {1!s}'.format(registry_key.path, exception))

Parses the Registry key with a specific plugin.

Args:
parser_mediator (ParserMediator): parser mediator.
registry_key (dfwinreg.WinRegistryKey): Windwos Registry key.
plugin (WindowsRegistryPlugin): Windows Registry plugin.


def execute(self, command, *args, encoding=_NOTSET):
    if ((self._reader is None) or self._reader.at_eof()):
        msg = (self._close_msg or 'Connection closed or corrupted')
        raise ConnectionClosedError(msg)
    if (command is None):
        raise TypeError('command must not be None')
    if (None in args):
        raise TypeError('args must not contain None')
    command = command.upper().strip()
    is_pubsub = (command in _PUBSUB_COMMANDS)
    is_ping = (command in ('PING', b'PING'))
    if (self._in_pubsub and (not (is_pubsub or is_ping))):
        raise RedisError('Connection in SUBSCRIBE mode')
    elif is_pubsub:
        logger.warning('Deprecated. Use `execute_pubsub` method directly')
        return self.execute_pubsub(command, *args)
    if (command in ('SELECT', b'SELECT')):
        cb = partial(self._set_db, args=args)
    elif (command in ('MULTI', b'MULTI')):
        cb = self._start_transaction
    elif (command in ('EXEC', b'EXEC')):
        cb = partial(self._end_transaction, discard=False)
    elif (command in ('DISCARD', b'DISCARD')):
        cb = partial(self._end_transaction, discard=True)
    else:
        cb = None
    if (encoding is _NOTSET):
        encoding = self._encoding
    fut = self._loop.create_future()
    if (self._pipeline_buffer is None):
        self._writer.write(encode_command(command, *args))
    else:
        encode_command(command, *args, buf=self._pipeline_buffer)
    self._waiters.append((fut, encoding, cb))
    return fut

Executes redis command and returns Future waiting for the answer.

Raises:
* TypeError if any of args can not be encoded as bytes.
* ReplyError on redis '-ERR' responses.
* ProtocolError when response can not be decoded meaning connection
is broken.
* ConnectionClosedError when either client or server has closed the
connection.


def batch_normalize_with_arguments(x, arguments):
    x = prettytensor.wrap(x)
    if isinstance(arguments, bool):
        if arguments:
            return x.batch_normalize()
        else:
            return x
    kwargs = arguments._asdict()
    defaults = prettytensor._defaults
    for arg in ('learned_moments_update_rate', 'variance_epsilon', 'scale_after_normalization'):
        if (kwargs.get(arg, None) is None):
            if (arg in defaults):
                kwargs[arg] = defaults[arg]
            else:
                del kwargs[arg]
    return x.batch_normalize(**kwargs)

Applies batch normalization to x as specified in arguments.

Args:
x: A Pretty Tensor.
arguments: Either a boolean to batch_normalize or a
BatchNormalizationArguments

Returns:
x with batch normalization applied.


def get_counter_metric(result: PipelineResult, namespace: str, name: str) -> int:
    metrics = result.metrics().query(MetricsFilter().with_namespace(namespace).with_name(name))
    counters = metrics['counters']
    if len(counters) > 1:
        raise RuntimeError('%d instead of one metric result matches name: %s in namespace %s' % (len(counters), name, namespace))
    return counters[0].result if len(counters) > 0 else -1

get specific counter metric from pipeline result

Args:
result: the PipelineResult which metrics are read from
namespace: a string representing the namespace of wanted metric
name: a string representing the  name of the wanted metric

Returns:
the result of the wanted metric if it exist, else -1


def range(*args, prefix: str):

        return [NamedQubit(prefix + str(i)) for i in range(*args)]

Returns a range of NamedQubits.

The range returned starts with the prefix, and followed by a qubit for
each number in the range, e.g.:

NamedQubit.range(3, prefix="a") -> ["a1", "a2", "a3]
NamedQubit.range(2, 4, prefix="a") -> ["a2", "a3]

Args:
*args: Args to be passed to Python's standard range function.
prefix: A prefix for constructed NamedQubits.

Returns:
A list of NamedQubits.


def generate_sitemap(self, path='sitemap.xml', https=False):

		sitemap = russell.sitemap.generate_sitemap(self, https=https)
		self.write_file(path, sitemap)

Generate an XML sitemap.

Args:
path (str): The name of the file to write to.
https (bool): If True, links inside the sitemap with relative scheme
(e.g. example.com/something) will be set to HTTPS. If False (the
default), they will be set to plain HTTP.


def set_timestamp(cls, filename: str, response: HTTPResponse):

        last_modified = response.fields.get('Last-Modified')

        if not last_modified:
            return

        try:
            last_modified = email.utils.parsedate(last_modified)
        except ValueError:
            _logger.exception('Failed to parse date.')
            return

        last_modified = time.mktime(last_modified)

        os.utime(filename, (time.time(), last_modified))

Set the Last-Modified timestamp onto the given file.

Args:
filename: The path of the file
response: Response