def ParseCookieRow(self, parser_mediator, query, row, **unused_kwargs):

    query_hash = hash(query)

    cookie_name = self._GetRowValue(query_hash, row, 'name')
    cookie_data = self._GetRowValue(query_hash, row, 'value')

    hostname = self._GetRowValue(query_hash, row, 'host_key')
    if hostname.startswith('.'):
      hostname = hostname[1:]

    httponly = self._GetRowValue(query_hash, row, 'httponly')
    path = self._GetRowValue(query_hash, row, 'path')
    persistent = self._GetRowValue(query_hash, row, 'persistent')
    secure = self._GetRowValue(query_hash, row, 'secure')

    if secure:
      scheme = 'https'
    else:
      scheme = 'http'

    url = '{0:s}://{1:s}{2:s}'.format(scheme, hostname, path)

    event_data = ChromeCookieEventData()
    event_data.cookie_name = cookie_name
    event_data.data = cookie_data
    event_data.host = hostname
    event_data.httponly = bool(httponly)
    event_data.path = path
    event_data.persistent = bool(persistent)
    event_data.query = query
    event_data.secure = bool(secure)
    event_data.url = url

    timestamp = self._GetRowValue(query_hash, row, 'creation_utc')
    date_time = dfdatetime_webkit_time.WebKitTime(timestamp=timestamp)
    event = time_events.DateTimeValuesEvent(
        date_time, definitions.TIME_DESCRIPTION_CREATION)
    parser_mediator.ProduceEventWithEventData(event, event_data)

    timestamp = self._GetRowValue(query_hash, row, 'last_access_utc')
    date_time = dfdatetime_webkit_time.WebKitTime(timestamp=timestamp)
    event = time_events.DateTimeValuesEvent(
        date_time, definitions.TIME_DESCRIPTION_LAST_ACCESS)
    parser_mediator.ProduceEventWithEventData(event, event_data)

    timestamp = self._GetRowValue(query_hash, row, 'expires_utc')
    if timestamp:
      date_time = dfdatetime_webkit_time.WebKitTime(timestamp=timestamp)
      event = time_events.DateTimeValuesEvent(
          date_time, definitions.TIME_DESCRIPTION_EXPIRATION)
      parser_mediator.ProduceEventWithEventData(event, event_data)

    for plugin in self._cookie_plugins:
      if cookie_name != plugin.COOKIE_NAME:
        continue

      try:
        plugin.UpdateChainAndProcess(
            parser_mediator, cookie_data=cookie_data, cookie_name=cookie_name,
            url=url)

      except Exception as exception:  # pylint: disable=broad-except
        parser_mediator.ProduceExtractionWarning(
            'plugin: {0:s} unable to parse cookie with error: {1!s}'.format(
                plugin.NAME, exception))

Parses a cookie row.

Args:
        parser_mediator (ParserMediator): parser mediator.
        query (str): query that created the row.
        row (sqlite3.Row): row resulting from the query.


def remove_node(self, node):

        if node not in self.node_list:
            return
        self.node_list.remove(node)
        # Remove links pointing to the deleted node
        for n in self.node_list:
            n.link_list = [link for link in n.link_list if
                           link.target != node]

Remove a node from ``self.node_list`` and links pointing to it.

    If ``node`` is not in the graph, do nothing.

Args:
        node (Node): The node to be removed

    Returns: None

Example:
        >>> from blur.markov.node import Node
        >>> node_1 = Node('One')
        >>> graph = Graph([node_1])
        >>> graph.remove_node(node_1)
        >>> len(graph.node_list)
        0


def __le__(self, other):

    if not isinstance(other, interface.DateTimeValues):
      raise ValueError('Other not an instance of DateTimeValues')

    return isinstance(other, Never)

Determines if the date time values are less than or equal to other.

Args:
        other (DateTimeValues): date time values to compare against.

Returns:
        bool: True if the date time values are greater than or equal to other.

Raises:
        ValueError: if other is not an instance of DateTimeValues.


def call(self, url, method=None, args=None):

        if not args:
            args = {}

        if sys.version_info.major == 3:
            data = urllib.parse.urlparse(url)
            path = data.path.rstrip('/') + '/'
            _args = dict(urllib.parse.parse_qs(data.query,
                                               keep_blank_values=True))
        elif sys.version_info.major == 2:
            data = urlparse.urlparse(url)
            path = data.path.rstrip('/') + '/'
            _args = dict(urlparse.parse_qs(data.query,
                                           keep_blank_values=True))

        for elem in self._data_store:
            pattern = elem['pattern']
            function = elem['function']
            _method = elem['method']
            type_cast = elem['type_cast']

            result = re.match(pattern, path)

            # Found matching method
            if result and _method == method:
                _args = dict(_args, **result.groupdict())

                # Unpack value lists (due to urllib.parse.parse_qs) in case
                # theres only one value available
                for key, val in _args.items():
                    if isinstance(_args[key], list) and len(_args[key]) == 1:
                        _args[key] = _args[key][0]

                # Apply typ-casting if necessary
                for key, val in type_cast.items():

                    # Not within available _args, no type-cast required
                    if key not in _args:
                        continue

                    # Is None or empty, no type-cast required
                    if not _args[key]:
                        continue

                    # Try and cast the values
                    if isinstance(_args[key], list):
                        for i, _val in enumerate(_args[key]):
                            _args[key][i] = self._cast(_val, val)
                    else:
                        _args[key] = self._cast(_args[key], val)

                requiered_args = self._get_function_args(function)
                for key, val in args.items():
                    if key in requiered_args:
                        _args[key] = val

                return function(**_args)

        return None

Calls the first function matching the urls pattern and method.

Args:
        url (str): Url for which to call a matching function.
        method (str, optional): The method used while registering a
            function.
            Defaults to None
        args (dict, optional): Additional args to be passed to the
            matching function.

Returns:
        The functions return value or `None` if no function was called.


def list_vmss_vm_instance_view_pg(access_token, subscription_id, resource_group, vmss_name,
                                  link=None):

    if link is None:
        endpoint = ''.join([get_rm_endpoint(),
                            '/subscriptions/', subscription_id,
                            '/resourceGroups/', resource_group,
                            '/providers/Microsoft.Compute/virtualMachineScaleSets/', vmss_name,
                            '/virtualMachines?$expand=instanceView&$select=instanceView',
                            '&api-version=', COMP_API])
    else:
        endpoint = link
    return do_get(endpoint, access_token)

Gets one page of a paginated list of scale set VM instance views.

Args:
        access_token (str): A valid Azure authentication token.
        subscription_id (str): Azure subscription id.
        resource_group (str): Azure resource group name.
        vmss_name (str): Name of the virtual machine scale set.
        link (str): Optional link to URI to get list (as part of a paginated API query).

Returns:
        HTTP response. JSON body of list of VM instance views.


def tokenize(self, s, pattern=None, active=None):

        if pattern is None:
            if self.tokenize_pattern is None:
                pattern = r'[ \t]+'
            else:
                pattern = self.tokenize_pattern
        if active is None:
            active = self.active
        return self.group.tokenize(s, pattern=pattern, active=active)

Rewrite and tokenize the input string *s*.

Args:
        s (str): the input string to process
        pattern (str, optional): the regular expression pattern on
            which to split tokens; defaults to `[ \t]+`
        active (optional): a collection of external module names
            that may be applied if called

Returns:
        a :class:`~delphin.tokens.YyTokenLattice` containing the
        tokens and their characterization information


def is_array(self, data_type):

    # Split off any brackets
    data_type = data_type.split('[')[0].strip()

    return data_type.lower() in self.array_types

Check if a type is a known array type

Args:
        data_type (str): Name of type to check

Returns:
        True if ``data_type`` is a known array type.


def return_item_count_on_page(self, page=1, total_items=1):

        up_to_page = ((page - 1) * self.page_items)
        #   Number of items up to the page in question

        if total_items > up_to_page:
            #   Remove all the items up to the page in question
            #
            count = total_items - up_to_page

        if count >= self.page_items:
            # The remaining items are greater than the items per page
            # so the answer is a full page
            return self.page_items
        else:
            #   There are less items than a full page,
            #
            return count

Return the number of items on page.

Args:
        * page = The Page to test for
        * total_items = the total item count

Returns:
        * Integer - Which represents the calculated number of items on page.


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

        try:
            self.logger.debug("Received args=%r kwargs=%r.", args, kwargs)
            start = time.perf_counter()
            return self.fn(*args, **kwargs)
        finally:
            delta = time.perf_counter() - start
            self.logger.debug("Completed after %.02fms.", delta * 1000)

Synchronously call this actor.

    Parameters:
        *args: Positional arguments to send to the actor.
        **kwargs: Keyword arguments to send to the actor.

Returns:
        Whatever the underlying function backing this actor returns.


def _create_handler(self, config):

        if config is None:
            raise ValueError('No handler config to create handler from.')

        if 'name' not in config:
            raise ValueError('Handler name is required.')

        handler_name = config['name']
        # try to create handler
        module_name = handler_name.rsplit('.', 1)[0]
        class_name = handler_name.rsplit('.', 1)[-1]
        module = import_module(module_name)
        handler_class = getattr(module, class_name)
        instance = handler_class(**config)

        return instance

Creates a handler from its config.

    Params:
        config:      handler config

Returns:
        handler instance


def filter_by_pattern(self, pattern):

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

Filter the Data Collection based on a list of booleans.

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

Returns:
        A new Data Collection with filtered data


def __call__(self, index, graph):

        for c in self.criteria:
            if c(index, graph):
                return True
        return False

Evaluates all the criteria and applies an OR opartion

Args:
    | ``index``  --  the index of the vertex/edge on which the criterion
                    is applied
    | ``graph``  --  the graph on which the criterion is tested


def get_result_xml(result):

    result_xml = Element('result')
    for name, value in [('name', result['name']),
                        ('type', ResultType.get_str(result['type'])),
                        ('severity', result['severity']),
                        ('host', result['host']),
                        ('test_id', result['test_id']),
                        ('port', result['port']),
                        ('qod', result['qod'])]:
        result_xml.set(name, str(value))
    result_xml.text = result['value']
    return result_xml

Formats a scan result to XML format.

Args:
        result (dict): Dictionary with a scan result.

Returns:
        Result as xml element object.


def _prepare_init_params_from_job_description(cls, job_details, model_channel_name=None):

        init_params = super(Estimator, cls)._prepare_init_params_from_job_description(job_details, model_channel_name)

        init_params['image_name'] = init_params.pop('image')
        return init_params

Convert the job description to init params that can be handled by the class constructor

Args:
        job_details: the returned job details from a describe_training_job API call.
        model_channel_name (str): Name of the channel where pre-trained model data will be downloaded

Returns:
        dictionary: The transformed init_params


def serialize_skycoord(o):

    representation = o.representation.get_name()
    frame = o.frame.name

    r = o.represent_as('spherical')

    d = dict(
        _type='astropy.coordinates.SkyCoord',
        frame=frame,
        representation=representation,
        lon=r.lon,
        lat=r.lat)

    if len(o.distance.unit.to_string()):
        d['distance'] = r.distance

    return d

Serializes an :obj:`astropy.coordinates.SkyCoord`, for JSONification.

Args:
        o (:obj:`astropy.coordinates.SkyCoord`): :obj:`SkyCoord` to be serialized.

Returns:
        A dictionary that can be passed to :obj:`json.dumps`.


def get_lowest_decomposition(self, composition):

        entries_list = []
        elements = [e.symbol for e in composition.elements]
        for i in range(len(elements)):
            for combi in itertools.combinations(elements, i + 1):
                chemsys = [Element(e) for e in combi]
                x = self.costdb.get_entries(chemsys)
                entries_list.extend(x)
        try:
            pd = PhaseDiagram(entries_list)
            return pd.get_decomposition(composition)
        except IndexError:
            raise ValueError("Error during PD building; most likely, "
                             "cost data does not exist!")

Get the decomposition leading to lowest cost

Args:
        composition:
            Composition as a pymatgen.core.structure.Composition

Returns:
        Decomposition as a dict of {Entry: amount}


def get_template(template_file='', **kwargs):

    template = get_template_object(template_file)

    LOG.info('Rendering template %s', template.filename)
    for key, value in kwargs.items():
        LOG.debug('%s => %s', key, value)

    rendered_json = template.render(**kwargs)
    LOG.debug('Rendered JSON:\n%s', rendered_json)

    return rendered_json

Get the Jinja2 template and renders with dict _kwargs_.

Args:
        template_file (str): name of the template file
        kwargs: Keywords to use for rendering the Jinja2 template.

Returns:
        String of rendered JSON template.


An exponential tween function that accelerates, reaches the midpoint, and then decelerates.

Args:
        n (float): The time progress, starting at 0.0 and ending at 1.0.

Returns:
        (float) The line progress, starting at 0.0 and ending at 1.0. Suitable for passing to getPointOnLine().


def get_current_round(self, tournament=1):

        # zero is an alias for the current round!
        query =
        arguments = {'tournament': tournament}
        data = self.raw_query(query, arguments)['data']['rounds'][0]
        if data is None:
            return None
        round_num = data["number"]
        return round_num

Get number of the current active round.

Args:
        tournament (int): ID of the tournament (optional, defaults to 1)

Returns:
        int: number of the current active round

Example:
        >>> NumerAPI().get_current_round()
        104


def create_model_table(self, model):

        try:
            return db_model_factory(self.Base, model, self.models)
        except Exception as exc:
            raise ModelError(
                model.name,
                message="failed to create in-memory table.",
                orig_exc=exc,
                context=self.error_context
            )

Creates the table for the given model.

Args:
        model: A StatikModel instance.

Returns:
        A SQLAlchemy model instance for the table corresponding to this
        particular model.


def _update_trial_info(self, expr_dir):

        trial_id = expr_dir[-8:]

        meta_file = os.path.join(expr_dir, EXPR_META_FILE)
        meta = parse_json(meta_file)

        result_file = os.path.join(expr_dir, EXPR_RESULT_FILE)
        offset = self._result_offsets.get(trial_id, 0)
        results, new_offset = parse_multiple_json(result_file, offset)
        self._add_results(results, trial_id)
        self._result_offsets[trial_id] = new_offset

        if meta:
            TrialRecord.objects \
                .filter(trial_id=trial_id) \
                .update(trial_status=meta["status"],
                        end_time=timestamp2date(meta.get("end_time", None)))
        elif len(results) > 0:
            metrics = {
                "episode_reward": results[-1].get("episode_reward_mean", None),
                "accuracy": results[-1].get("mean_accuracy", None),
                "loss": results[-1].get("loss", None)
            }
            if results[-1].get("done"):
                TrialRecord.objects \
                    .filter(trial_id=trial_id) \
                    .update(trial_status="TERMINATED",
                            end_time=results[-1].get("date", None),
                            metrics=str(metrics))
            else:
                TrialRecord.objects \
                    .filter(trial_id=trial_id) \
                    .update(metrics=str(metrics))

Update information for given trial.

    Meta file will be loaded if exists, and the trial information
    in db backend will be updated.

Args:
        expr_dir(str)


def __init__(self, left, right):

        if isinstance(left, Dist) and len(left) > 1:
            if (not isinstance(left, J) or
                    evaluation.get_dependencies(*list(left.inverse_map))):
                raise StochasticallyDependentError(
                    "Joint distribution with dependencies not supported.")
        if isinstance(right, Dist) and len(right) > 1:
            if (not isinstance(right, J) or
                    evaluation.get_dependencies(*list(right.inverse_map))):
                raise StochasticallyDependentError(
                    "Joint distribution with dependencies not supported.")

        assert isinstance(left, Dist) or isinstance(right, Dist)
        Dist.__init__(self, left=left, right=right)

Constructor.

Args:
        left (Dist, numpy.ndarray) : Left hand side.
        right (Dist, numpy.ndarray) : Right hand side.


def _del_conversation(self, conversation_key: str) -> None:

        if conversation_key in self.conversations.keys():
            del self.conversations[conversation_key]
            log.info(f'Deleted conversation, key: {conversation_key}')

Deletes Conversation instance.

Args:
        conversation_key: Conversation key.


def parse_cytoband(lines):

    cytobands = {}
    for line in lines:
        line = line.rstrip()
        splitted_line = line.split('\t')
        chrom = splitted_line[0].lstrip('chr')
        start = int(splitted_line[1])
        stop = int(splitted_line[2])
        name = splitted_line[3]
        if chrom in cytobands:
            # Add interval to existing tree
            cytobands[chrom][start:stop] = name
        else:
            # Create a new interval tree
            new_tree = intervaltree.IntervalTree()
            # create the interval
            new_tree[start:stop] = name
            # Add the interval tree
            cytobands[chrom] = new_tree

    return cytobands

Parse iterable with cytoband coordinates

Args:
        lines(iterable): Strings on format "chr1\t2300000\t5400000\tp36.32\tgpos25"

Returns:
        cytobands(dict): Dictionary with chromosome names as keys and
                        interval trees as values


def get_available_references(self, datas):

        names = []

        for k, v in datas.items():
            if k.startswith(RULE_REFERENCE):
                names.append(k[len(RULE_REFERENCE)+1:])

        return names

Get available manifest reference names.

    Every rules starting with prefix from ``nomenclature.RULE_REFERENCE``
    are available references.

    Only name validation is performed on these references.

Args:
        datas (dict): Data where to search for reference declarations.

Returns:
        list: List of every available reference names. This is the real
            name unprefixed.


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

        # set new limits so the maximum value of `beta` is equal to or
        # greater than the maximum `beta` inferred from the gamma distribution
        # with the constrained `alpha_beta` and `beta_beta` parameters
        new_max_beta = DiscreteGamma(self.PARAMLIMITS["alpha_lambda"][1],
                self.PARAMLIMITS["beta_lambda"][0], ncats)[-1]
        new_limits = model.PARAMLIMITS
        new_limits["beta"] = (new_limits["beta"][0], new_max_beta)
        model.PARAMLIMITS = new_limits

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

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

Initialize an `GammaDistributedModel` object.

    The `lambda_param` is set to "beta".

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


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

        if 'style_class' in kwargs:
            my_class = '%s alert alert-success' % kwargs['style_class']
            kwargs['style_class'] = my_class
        super(SuccessParagraph, self).__init__(**kwargs)
        self.text = Text(*args)

Creates an important paragraph object.

Args:
        String text, a string to add to the message

Returns:
        None

Raises:
        Errors are propagated

    We pass the kwargs on to the base class so an exception is raised
    if invalid keywords were passed. See:

    http://stackoverflow.com/questions/13124961/
    how-to-pass-arguments-efficiently-kwargs-in-python


def get_resource_from_handle(self, resource_handle):

        repo_type = resource_handle.get("repository_type")
        location = resource_handle.get("location")
        if not (repo_type and location):
            raise ValueError("PackageRepositoryManager requires "
                             "resource_handle objects to have a "
                             "repository_type and location defined")
        path = "%s@%s" % (repo_type, location)
        repo = self.get_repository(path)
        resource = repo.get_resource_from_handle(resource_handle)
        return resource

Get a resource.

Args:
        resource_handle (`ResourceHandle`): Handle of the resource.

Returns:
        `PackageRepositoryResource` instance.


def __init__(self, key, value, timeout):

        self.key = key
        self.value = value
        self.expiration = time.clock() * 1000 + timeout

Creates instance of the cache entry.

Args:
        key: the unique key used to identify and locate the value.
        value: the cached value.
        timeout: time to live for the object in milliseconds


def ParseOptions(cls, options, configuration_object):

    if not isinstance(configuration_object, tools.CLITool):
      raise errors.BadConfigObject(
          'Configuration object is not an instance of CLITool')

    process_memory_limit = cls._ParseNumericOption(
        options, 'process_memory_limit')

    if process_memory_limit and process_memory_limit < 0:
      raise errors.BadConfigOption(
          'Invalid process memory limit value cannot be negative.')

    setattr(configuration_object, '_process_memory_limit', process_memory_limit)

Parses and validates options.

Args:
        options (argparse.Namespace): parser options.
        configuration_object (CLITool): object to be configured by the argument
        helper.

Raises:
        BadConfigObject: when the configuration object is of the wrong type.
        BadConfigOption: when a configuration parameter fails validation.


Convert the color from YIQ coordinates to RGB.

    Parameters:
        :y:
        Tte Y component value [0...1]
        :i:
        The I component value [0...1]
        :q:
        The Q component value [0...1]

Returns:
        The color as an (r, g, b) tuple in the range:
        r[0...1],
        g[0...1],
        b[0...1]

    >>> '(%g, %g, %g)' % Color.YiqToRgb(0.592263, 0.458874, -0.0499818)
    '(1, 0.5, 5.442e-07)'


def device_type_from_string(cl_device_type_str):

    cl_device_type_str = cl_device_type_str.upper()
    if hasattr(cl.device_type, cl_device_type_str):
        return getattr(cl.device_type, cl_device_type_str)
    return None

Converts values like ``gpu`` to a pyopencl device type string.

    Supported values are: ``accelerator``, ``cpu``, ``custom``, ``gpu``. If ``all`` is given, None is returned.

Args:
        cl_device_type_str (str): The string we want to convert to a device type.

Returns:
        cl.device_type: the pyopencl device type.


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

    # forward_min_event_ndims = 0.
    # No forward_min_event_ndims specified as this is done in PowerTransform.
    super(Exp, self).__init__(
        validate_args=validate_args,
        name=name)

Instantiates the `Exp` bijector.

Args:
        validate_args: Python `bool` indicating whether arguments should be
        checked for correctness.
        name: Python `str` name given to ops managed by this object.


def automatic_linemode(divisions, ibz):

        kpoints = list()
        labels = list()
        for path in ibz.kpath["path"]:
            kpoints.append(ibz.kpath["kpoints"][path[0]])
            labels.append(path[0])
            for i in range(1, len(path) - 1):
                kpoints.append(ibz.kpath["kpoints"][path[i]])
                labels.append(path[i])
                kpoints.append(ibz.kpath["kpoints"][path[i]])
                labels.append(path[i])

            kpoints.append(ibz.kpath["kpoints"][path[-1]])
            labels.append(path[-1])

        return Kpoints("Line_mode KPOINTS file",
                       style=Kpoints.supported_modes.Line_mode,
                       coord_type="Reciprocal",
                       kpts=kpoints,
                       labels=labels,
                       num_kpts=int(divisions))

Convenient static constructor for a KPOINTS in mode line_mode.
    gamma centered Monkhorst-Pack grids and the number of subdivisions
    along each reciprocal lattice vector determined by the scheme in the
    VASP manual.

Args:
        divisions: Parameter determining the number of k-points along each
            hight symetry lines.
        ibz: HighSymmKpath object (pymatgen.symmetry.bandstructure)

Returns:
        Kpoints object


def Selector(fields):

    check_user_facing_fields_dict(fields, 'Selector')

    class _Selector(_ConfigSelector):
        def __init__(self):
            key = 'Selector.' + str(DictCounter.get_next_count())
            super(_Selector, self).__init__(
                key=key,
                name=None,
                fields=fields,
                # description='A configuration dictionary with typed fields',
                type_attributes=ConfigTypeAttributes(is_builtin=True),
            )

    return _Selector

Selectors are used when you want to be able present several different options to the user but
    force them to select one. For example, it would not make much sense to allow them
    to say that a single input should be sourced from a csv and a parquet file: They must choose.

    Note that in other type systems this might be called an "input union."

Args:
        fields (Dict[str, Field]):


def flatten(lst):

    for elm in lst:
        if isinstance(elm, collections.Iterable) and not isinstance(
                elm, string_types):
            for sub in flatten(elm):
                yield sub
        else:
            yield elm

Flatten list.

Args:
        lst (list): List to flatten

Returns:
        generator


def GetMessages(self, formatter_mediator, event):

    if self.DATA_TYPE != event.data_type:
      raise errors.WrongFormatter('Unsupported data type: {0:s}.'.format(
          event.data_type))

    event_values = event.CopyToDict()

    read_receipt = event_values.get('read_receipt', None)
    if read_receipt is not None:
      event_values['read_receipt'] = (
          self._READ_RECEIPT.get(read_receipt, 'UNKNOWN'))

    message_type = event_values.get('message_type', None)
    if message_type is not None:
      event_values['message_type'] = (
          self._MESSAGE_TYPE.get(message_type, 'UNKNOWN'))

    return self._ConditionalFormatMessages(event_values)

Determines the formatted message strings for an event object.

Args:
        formatter_mediator (FormatterMediator): mediates the interactions
        between formatters and other components, such as storage and Windows
        EventLog resources.
        event (EventObject): event.

Returns:
        tuple(str, str): formatted message string and short message string.

Raises:
        WrongFormatter: if the event object cannot be formatted by the formatter.


def to_string(cls, error_code):

        if error_code == cls.RTT_ERROR_CONTROL_BLOCK_NOT_FOUND:
            return 'The RTT Control Block has not yet been found (wait?)'
        return super(JLinkRTTErrors, cls).to_string(error_code)

Returns the string message for the given error code.

Args:
        cls (JLinkRTTErrors): the ``JLinkRTTErrors`` class
        error_code (int): error code to convert

Returns:
        An error string corresponding to the error code.

Raises:
        ValueError: if the error code is invalid.


def handle_block(
        mediator_state: MediatorTransferState,
        state_change: Block,
        channelidentifiers_to_channels: ChannelMap,
        pseudo_random_generator: random.Random,
) -> TransitionResult[MediatorTransferState]:

    expired_locks_events = events_to_remove_expired_locks(
        mediator_state,
        channelidentifiers_to_channels,
        state_change.block_number,
        pseudo_random_generator,
    )

    secret_reveal_events = events_for_onchain_secretreveal_if_dangerzone(
        channelmap=channelidentifiers_to_channels,
        secrethash=mediator_state.secrethash,
        transfers_pair=mediator_state.transfers_pair,
        block_number=state_change.block_number,
        block_hash=state_change.block_hash,
    )

    unlock_fail_events = events_for_expired_pairs(
        channelidentifiers_to_channels=channelidentifiers_to_channels,
        transfers_pair=mediator_state.transfers_pair,
        waiting_transfer=mediator_state.waiting_transfer,
        block_number=state_change.block_number,
    )

    iteration = TransitionResult(
        mediator_state,
        unlock_fail_events + secret_reveal_events + expired_locks_events,
    )

    return iteration

After Raiden learns about a new block this function must be called to
    handle expiration of the hash time locks.

Args:
        state: The current state.

Returns:
        TransitionResult: The resulting iteration


def get_session(self, app_path, session_id):

        if app_path not in self._applications:
            raise ValueError("Application %s does not exist on this server" % app_path)
        return self._applications[app_path].get_session(session_id)

Get an active a session by name application path and session ID.

Args:
        app_path (str) :
            The configured application path for the application to return
            a session for.

        session_id (str) :
            The session ID of the session to retrieve.

Returns:
        ServerSession


def size_filter(labeled_grid, min_size):

        out_grid = np.zeros(labeled_grid.shape, dtype=int)
        slices = find_objects(labeled_grid)
        j = 1
        for i, s in enumerate(slices):
            box = labeled_grid[s]
            size = np.count_nonzero(box.ravel() == (i + 1))
            if size >= min_size and box.shape[0] > 1 and box.shape[1] > 1:
                out_grid[np.where(labeled_grid == i + 1)] = j
                j += 1
        return out_grid

Remove labeled objects that do not meet size threshold criteria.

Args:
        labeled_grid: 2D output from label method.
        min_size: minimum size of object in pixels.

Returns:
        labeled grid with smaller objects removed.


def convert(model_path: str, out_file: str):

    print('Converting', model_path, 'to', out_file, '...')

    import tensorflow as tf
    from precise.model import load_precise_model
    from keras import backend as K

    out_dir, filename = split(out_file)
    out_dir = out_dir or '.'
    os.makedirs(out_dir, exist_ok=True)

    K.set_learning_phase(0)
    model = load_precise_model(model_path)

    out_name = 'net_output'
    tf.identity(model.output, name=out_name)
    print('Output node name:', out_name)
    print('Output folder:', out_dir)

    sess = K.get_session()

    # Write the graph in human readable
    tf.train.write_graph(sess.graph.as_graph_def(), out_dir, filename + 'txt', as_text=True)
    print('Saved readable graph to:', filename + 'txt')

    # Write the graph in binary .pb file
    from tensorflow.python.framework import graph_util
    from tensorflow.python.framework import graph_io

    cgraph = graph_util.convert_variables_to_constants(sess, sess.graph.as_graph_def(), [out_name])
    graph_io.write_graph(cgraph, out_dir, filename, as_text=False)

    if isfile(model_path + '.params'):
        copyfile(model_path + '.params', out_file + '.params')

    print('Saved graph to:', filename)

    del sess

Converts an HD5F file from Keras to a .pb for use with TensorFlow

Args:
        model_path: location of Keras model
        out_file: location to write protobuf


def prepare(path, name):  # type: (str, str) -> None

    setup_path = os.path.join(path, 'setup.py')
    if not os.path.exists(setup_path):
        data = textwrap.dedent( % name)

        logger.info('Module %s does not provide a setup.py. \nGenerating setup.py' % name)

        _files.write_file(setup_path, data)

        data = textwrap.dedent()

        logger.info('Generating setup.cfg')

        _files.write_file(os.path.join(path, 'setup.cfg'), data)

        data = textwrap.dedent()

        logger.info('Generating MANIFEST.in')

        _files.write_file(os.path.join(path, 'MANIFEST.in'), data)

Prepare a Python script (or module) to be imported as a module.
    If the script does not contain a setup.py file, it creates a minimal setup.

Args:
        path (str): path to directory with the script or module.
        name (str): name of the script or module.


def _req(self, req):

        logger.debug('DUT> %s', req)
        self._log and self.pause()
        times = 3
        res = None

        while times:
            times = times - 1
            try:
                self._sendline(req)
                self._expect(req)

                line = None
                res = []

                while True:
                    line = self._readline()
                    logger.debug('Got line %s', line)

                    if line == 'Done':
                        break

                    if line:
                        res.append(line)
                break

            except:
                logger.exception('Failed to send command')
                self.close()
                self._init()

        self._log and self.resume()
        return res

Send command and wait for response.

    The command will be repeated 3 times at most in case data loss of serial port.

Args:
        req (str): Command to send, please do not include new line in the end.

Returns:
        [str]: The output lines


def tfms_from_model(f_model, sz, aug_tfms=None, max_zoom=None, pad=0, crop_type=CropType.RANDOM,
                    tfm_y=None, sz_y=None, pad_mode=cv2.BORDER_REFLECT, norm_y=True, scale=None):

    stats = inception_stats if f_model in inception_models else imagenet_stats
    return tfms_from_stats(stats, sz, aug_tfms, max_zoom=max_zoom, pad=pad, crop_type=crop_type,
                           tfm_y=tfm_y, sz_y=sz_y, pad_mode=pad_mode, norm_y=norm_y, scale=scale)

Returns separate transformers of images for training and validation.
    Transformers are constructed according to the image statistics given by the model. (See tfms_from_stats)

Args:
        f_model: model, pretrained or not pretrained


def omega(self, structure, n, u):

        l0 = np.dot(np.sum(structure.lattice.matrix, axis=0), n)
        l0 *= 1e-10 # in A
        weight = float(structure.composition.weight) * 1.66054e-27 # in kg
        vol = structure.volume * 1e-30 # in m^3
        vel = (1e9 * self[0].einsum_sequence([n, u, n, u])
               / (weight / vol)) ** 0.5
        return vel / l0

Finds directional frequency contribution to the heat
    capacity from direction and polarization

Args:
        structure (Structure): Structure to be used in directional heat
            capacity determination
        n (3x1 array-like): direction for Cv determination
        u (3x1 array-like): polarization direction, note that
            no attempt for verification of eigenvectors is made


def __init__(
        self,
        deconvolution_layer_list,
        opt_params=None,
        learning_rate=1e-05,
        verbose_mode=False
    ):

        for deconvolution_layer in deconvolution_layer_list:
            if isinstance(deconvolution_layer, DeconvolutionLayer) is False:
                raise TypeError()

        if opt_params is None:
            opt_params = Adam()
            opt_params.dropout_rate = 0.0

        if isinstance(opt_params, OptParams) is False:
            raise TypeError()

        logger = getLogger("pydbm")
        handler = StreamHandler()
        if verbose_mode is True:
            handler.setLevel(DEBUG)
            logger.setLevel(DEBUG)
        else:
            handler.setLevel(ERROR)
            logger.setLevel(ERROR)

        logger.addHandler(handler)

        self.__deconvolution_layer_list = deconvolution_layer_list
        self.__learning_rate = learning_rate
        self.__attenuate_epoch = 50
        self.__opt_params = opt_params
        self.__logger = logger

Init.

Args:
        deconvolution_layer_list:   `list` of `DeconvolutionLayer`.
        opt_params:                 is-a `OptParams`. If `None`, this value will be `Adam`.
        learning_rate:              Learning rate.
        verbose_mode:               Verbose mode or not.


def add_string_pairs_from_text_view_element(xib_file, results, text_view, special_ui_components_prefix):

    text_view_entry_comment = extract_element_internationalized_comment(text_view)
    if text_view_entry_comment is None:
        return

    if text_view.hasAttribute('usesAttributedText') and text_view.attributes['usesAttributedText'].value == 'YES':
        add_string_pairs_from_attributed_ui_element(results, text_view, text_view_entry_comment)
    else:
        try:
            text_view_entry_key = text_view.attributes['text'].value
            results.append((text_view_entry_key, text_view_entry_comment + ' default text value'))
        except KeyError:
            pass
    warn_if_element_not_of_class(text_view, 'TextView', special_ui_components_prefix)

Adds string pairs from a textview element.

Args:
        xib_file (str): Path to the xib file.
        results (list): The list to add the results to.
        text_view(element): The textview element from the xib, to extract the string pairs from.
        special_ui_components_prefix(str): A custom prefix for internationalize component to allow (default is only JT)


def set_data_length(self, length):
        # type: (int) -> None

        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized')

        len_diff = length - self.info_len
        if len_diff > 0:
            # If we are increasing the length, update the last alloc_desc up
            # to the max of 0x3ffff800, and throw an exception if we overflow.
            new_len = self.alloc_descs[-1][0] + len_diff
            if new_len > 0x3ffff800:
                raise pycdlibexception.PyCdlibInvalidInput('Cannot increase the size of a UDF file beyond the current descriptor')
            self.alloc_descs[-1][0] = new_len
        elif len_diff < 0:
            # We are decreasing the length.  It's possible we are removing one
            # or more alloc_descs, so run through the list updating all of the
            # descriptors and remove any we no longer need.
            len_left = length
            alloc_descs_needed = 0
            index = 0
            while len_left > 0:
                this_len = min(len_left, 0x3ffff800)
                alloc_descs_needed += 1
                self.alloc_descs[index][0] = this_len
                index += 1
                len_left -= this_len

            self.alloc_descs = self.alloc_descs[:alloc_descs_needed]

        self.info_len = length

A method to set the length of the data that this UDF File Entry
    points to.

    Parameters:
    length - The new length for the data.

Returns:
    Nothing.


def serialize_ndarray_npy(o):

    with io.BytesIO() as f:
        np.save(f, o)
        f.seek(0)
        serialized = json.dumps(f.read().decode('latin-1'))
    return dict(
        _type='np.ndarray',
        npy=serialized)

Serializes a :obj:`numpy.ndarray` using numpy's built-in :obj:`save` function.
    This produces totally unreadable (and very un-JSON-like) results (in "npy"
    format), but it's basically guaranteed to work in 100% of cases.

Args:
        o (:obj:`numpy.ndarray`): :obj:`ndarray` to be serialized.

Returns:
        A dictionary that can be passed to :obj:`json.dumps`.


def extend(self, trajectory):

        if self.time_step != trajectory.time_step:
            raise ValueError('Trajectory not extended: Time steps of trajectories is incompatible')

        if len(self.species) != len(trajectory.species) and self.species != trajectory.species:
            raise ValueError('Trajectory not extended: species in trajectory do not match')

        self.to_positions()
        trajectory.to_positions()

        self.frac_coords = np.concatenate((self.frac_coords, trajectory.frac_coords), axis=0)
        self.lattice, self.constant_lattice = self._combine_attribute(self.lattice, trajectory.lattice,
                                                                      self.frac_coords.shape[0],
                                                                      trajectory.frac_coords.shape[0])
        self.site_properties = self._combine_attribute(self.site_properties, trajectory.site_properties,
                                                       self.frac_coords.shape[0], trajectory.frac_coords.shape[0])

Concatenate another trajectory

Args:
        trajectory (Trajectory): Trajectory to add


def get_all(self, attrs: Iterable[FetchAttribute]) \
            -> Sequence[Tuple[FetchAttribute, MaybeBytes]]:

        ret: List[Tuple[FetchAttribute, MaybeBytes]] = []
        for attr in attrs:
            try:
                ret.append((attr.for_response, self.get(attr)))
            except NotFetchable:
                pass
        return ret

Return a list of tuples containing the attribute iself and the bytes
    representation of that attribute from the message.

Args:
        attrs: The fetch attributes.


def parse_mapping(mapping_file: Optional[str]) -> configparser.ConfigParser:

    LOGGER.debug('Parsing mapping file. Command line: %s', mapping_file)

    def parse(mapping_file):
        config = configparser.ConfigParser()
        config.read_file(mapping_file)
        return config

    # give precedence to the user-specified file
    if mapping_file is not None:
        LOGGER.debug('Parsing command line mapping file')
        return parse(mapping_file)

    # fall back on XDG config location
    xdg_config_dir = xdg.BaseDirectory.load_first_config('pass-git-helper')
    if xdg_config_dir is None:
        raise RuntimeError(
            'No mapping configured so far at any XDG config location. '
            'Please create {config_file}'.format(
                config_file=DEFAULT_CONFIG_FILE))
    mapping_file = os.path.join(xdg_config_dir, CONFIG_FILE_NAME)
    LOGGER.debug('Parsing mapping file %s', mapping_file)
    with open(mapping_file, 'r') as file_handle:
        return parse(file_handle)

Parse the file containing the mappings from hosts to pass entries.

Args:
        mapping_file:
            Name of the file to parse. If ``None``, the default file from the
            XDG location is used.


def mtz(n,c):

    model = Model("atsp - mtz")

    x,u = {},{}
    for i in range(1,n+1):
        u[i] = model.addVar(lb=0, ub=n-1, vtype="C", name="u(%s)"%i)
        for j in range(1,n+1):
            if i != j:
                x[i,j] = model.addVar(vtype="B", name="x(%s,%s)"%(i,j))

    for i in range(1,n+1):
        model.addCons(quicksum(x[i,j] for j in range(1,n+1) if j != i) == 1, "Out(%s)"%i)
        model.addCons(quicksum(x[j,i] for j in range(1,n+1) if j != i) == 1, "In(%s)"%i)

    for i in range(1,n+1):
        for j in range(2,n+1):
            if i != j:
                model.addCons(u[i] - u[j] + (n-1)*x[i,j] <= n-2, "MTZ(%s,%s)"%(i,j))

    model.setObjective(quicksum(c[i,j]*x[i,j] for (i,j) in x), "minimize")

    model.data = x,u
    return model

mtz: Miller-Tucker-Zemlin's model for the (asymmetric) traveling salesman problem
    (potential formulation)
    Parameters:
        - n: number of nodes
        - c[i,j]: cost for traversing arc (i,j)
    Returns a model, ready to be solved.


def not_evaluator(conditions, leaf_evaluator):

  if not len(conditions) > 0:
    return None

  result = evaluate(conditions[0], leaf_evaluator)
  return None if result is None else not result

Evaluates a list of conditions as if the evaluator had been applied
    to a single entry and NOT was applied to the result.

Args:
        conditions: List of conditions ex: [operand_1, operand_2].
        leaf_evaluator: Function which will be called to evaluate leaf condition values.

Returns:
        Boolean:
        - True if the operand evaluates to False.
        - False if the operand evaluates to True.
        None: if conditions is empty or condition couldn't be evaluated.


def songs_iter(self, *, page_size=250):

		start_token = None

		while True:
			response = self._call(
				mc_calls.TrackFeed,
				max_results=page_size,
				start_token=start_token
			)
			items = response.body.get('data', {}).get('items', [])

			if items:
				yield items

			start_token = response.body.get('nextPageToken')
			if start_token is None:
				break

Get a paged iterator of library songs.

    Parameters:
    page_size (int, Optional): The maximum number of results per returned page.
        Max allowed is ``49995``.
        Default: ``250``

Yields:
    list: Song dicts.


def get(self, request, *args, **kwargs):

        context = self.get_context_data(**kwargs)
        context.update(self.extra_context)
        context['crumbs'] = self.get_crumbs()
        context['title'] = self.title
        context['suit'] = 'suit' in settings.INSTALLED_APPS
        if context.get('dashboard_grid', None) is None and self.grid:
            context['dashboard_grid'] = self.grid
        return self.render_to_response(context)

Django view get function.

    Add items of extra_context, crumbs and grid to context.

Args:
        request (): Django's request object.
        *args (): request args.
        **kwargs (): request kwargs.

Returns:
        response: render to response with context.


def get_smeared_densities(self, sigma):

        from scipy.ndimage.filters import gaussian_filter1d
        smeared_dens = {}
        diff = [self.energies[i + 1] - self.energies[i]
                for i in range(len(self.energies) - 1)]
        avgdiff = sum(diff) / len(diff)
        for spin, dens in self.densities.items():
            smeared_dens[spin] = gaussian_filter1d(dens, sigma / avgdiff)
        return smeared_dens

Returns the Dict representation of the densities, {Spin: densities},
    but with a Gaussian smearing of std dev sigma applied about the fermi
    level.

Args:
        sigma: Std dev of Gaussian smearing function.

Returns:
        Dict of Gaussian-smeared densities.


def init_from_acceptor(self, acceptor):

        self.states = copy.deepcopy(acceptor.states)
        self.alphabet = copy.deepcopy(acceptor.alphabet)
        self.osyms = copy.deepcopy(acceptor.osyms)
        self.isyms = copy.deepcopy(acceptor.isyms)

Adds a sink state

Args:
        alphabet (list): The input alphabet

Returns:
        None


def ScanForStorageMediaImage(self, source_path_spec):

    try:
      type_indicators = analyzer.Analyzer.GetStorageMediaImageTypeIndicators(
          source_path_spec, resolver_context=self._resolver_context)
    except RuntimeError as exception:
      raise errors.BackEndError((
          'Unable to process source path specification with error: '
          '{0!s}').format(exception))

    if not type_indicators:
      # The RAW storage media image type cannot be detected based on
      # a signature so we try to detect it based on common file naming schemas.
      file_system = resolver.Resolver.OpenFileSystem(
          source_path_spec, resolver_context=self._resolver_context)
      raw_path_spec = path_spec_factory.Factory.NewPathSpec(
          definitions.TYPE_INDICATOR_RAW, parent=source_path_spec)

      try:
        # The RAW glob function will raise a PathSpecError if the path
        # specification is unsuitable for globbing.
        glob_results = raw.RawGlobPathSpec(file_system, raw_path_spec)
      except errors.PathSpecError:
        glob_results = None

      file_system.Close()

      if not glob_results:
        return None

      return raw_path_spec

    if len(type_indicators) > 1:
      raise errors.BackEndError(
          'Unsupported source found more than one storage media image types.')

    return path_spec_factory.Factory.NewPathSpec(
        type_indicators[0], parent=source_path_spec)

Scans the path specification for a supported storage media image format.

Args:
        source_path_spec (PathSpec): source path specification.

Returns:
        PathSpec: storage media image path specification or None if no supported
        storage media image type was found.

Raises:
        BackEndError: if the source cannot be scanned or more than one storage
        media image type is found.


def generate(self, text):

        if not text:
            raise Exception("No text to speak")

        if len(text) >= self.MAX_CHARS:
            raise Exception("Number of characters must be less than 2000")

        params = self.__params.copy()
        params["text"] = text
        self._data = requests.get(self.TTS_URL, params=params,
                                  stream=False).iter_content()

Try to get the generated file.

Args:
        text: The text that you want to generate.


def WMITimeStrToRDFDatetime(self, timestr):

    # We use manual parsing here because the time functions provided (datetime,
    # dateutil) do not properly deal with timezone information.
    offset_minutes = timestr[21:]
    year = timestr[:4]
    month = timestr[4:6]
    day = timestr[6:8]
    hours = timestr[8:10]
    minutes = timestr[10:12]
    seconds = timestr[12:14]
    microseconds = timestr[15:21]

    unix_seconds = calendar.timegm(
        tuple(map(int, [year, month, day, hours, minutes, seconds])))
    unix_seconds -= int(offset_minutes) * 60
    return rdfvalue.RDFDatetime(unix_seconds * 1e6 + int(microseconds))

Return RDFDatetime from string like 20140825162259.000000-420.

Args:
        timestr: WMI time string

Returns:
        rdfvalue.RDFDatetime

    We have some timezone manipulation work to do here because the UTC offset is
    in minutes rather than +-HHMM


def set_name(self, name, anyway=False):

        set_name(self.startEA, name, anyway=anyway)

Set Function Name.

    Default behavior throws an exception when setting to a name that already exists in
    the IDB. to make IDA automatically add a counter to the name (like in the GUI,)
    use `anyway=True`.

Args:
        name: Desired name.
        anyway: `True` to set anyway.


def __init__(self,
                 base_url: str = None,
                 *,
                 timeout_connection: int = 30
                 ) -> None:

        if base_url is None:
            base_url = "http://127.0.0.1:6060"
        self.__api = APIClient(base_url, timeout_connection=timeout_connection)
        self.__bugs = BugManager(self.__api)
        self.__containers = ContainerManager(self.__api)
        self.__files = FileManager(self.__api, self.__bugs)
        self.__docker = DockerManager(self.__api)

Constructs a new client for communicating with a BugZoo server.

    Parameters:
        base_url: the base URL of the BugZoo server.
        timeout_connection: the maximum number of seconds to wait whilst
            attempting to connect to the server before declaring the
            connection to have failed.

Raises:
        ConnectionFailure: if a connection to the server could not be
            established within the timeout window.


def checkPermissions(permissions=[], obj=None):

    if not obj:
        return False
    sm = getSecurityManager()
    for perm in permissions:
        if not sm.checkPermission(perm, obj):
            return ''
    return True

Checks if a user has permissions for a given object.

Args:
        permissions: The permissions the current user must be compliant with
        obj: The object for which the permissions apply

Returns:
        1 if the user complies with all the permissions for the given object.
        Otherwise, it returns empty.


def swo_disable(self, port_mask):

        res = self._dll.JLINKARM_SWO_DisableTarget(port_mask)
        if res != 0:
            raise errors.JLinkException(res)
        return None

Disables ITM & Stimulus ports.

Args:
        self (JLink): the ``JLink`` instance
        port_mask (int): mask specifying which ports to disable

Returns:
        ``None``

Raises:
        JLinkException: on error


def _environment_variables(**kwargs):
        # type: (Any) -> Any

        hdx_key = os.getenv('HDX_KEY')
        if hdx_key is not None:
            kwargs['hdx_key'] = hdx_key
        hdx_url = os.getenv('HDX_URL')
        if hdx_url is not None:
            kwargs['hdx_url'] = hdx_url
        else:
            hdx_site = os.getenv('HDX_SITE')
            if hdx_site is not None:
                kwargs['hdx_site'] = hdx_site
        return kwargs

Overwrite keyword arguments with environment variables

Args:
        **kwargs: See below
        hdx_url (str): HDX url to use. Overrides hdx_site.
        hdx_site (str): HDX site to use eg. prod, test. Defaults to test.
        hdx_key (str): Your HDX key. Ignored if hdx_read_only = True.

Returns:
        kwargs: Changed keyword arguments


def _get_parsed_args(command_name, doc, argv):
    # type: (str, str, typing.List[str]) -> typing.Dict[str, typing.Any]

    _LOGGER.debug('Parsing docstring:  with arguments %s.', doc, argv)
    args = docopt(doc, argv=argv)
    if command_name == settings.command:
        args[command_name] = True
    return args

Parse the docstring with docopt.

Args:
        command_name: The name of the subcommand to parse.
        doc: A docopt-parseable string.
        argv: The list of arguments to pass to docopt during parsing.

Returns:
        The docopt results dictionary. If the subcommand has the same name as
        the primary command, the subcommand value will be added to the
        dictionary.


def _process_book(book_url):

    data = DOWNER.download(book_url)
    dom = dhtmlparser.parseString(data)

    details_tags = dom.find("div", {"id": "contentDetail"})

    assert details_tags, "Can't find details of the book."

    details = details_tags[0]

    # parse required informations
    title = _parse_title(dom, details)
    authors = _parse_authors(details)
    publisher = _parse_publisher(details)
    price = _parse_price(details)
    pages, binding = _parse_pages_binding(details)

    pub = Publication(
        title,
        authors,
        price,
        publisher
    )

    # parse optional informations
    pub.optionals.URL = book_url
    pub.optionals.binding = binding

    pub.optionals.pages = pages
    pub.optionals.ISBN, pub.optionals.EAN = _parse_ISBN_EAN(details)
    pub.optionals.edition = _parse_edition(details)
    pub.optionals.description = _parse_description(details)

    return pub

Parse available informations about book from the book details page.

Args:
        book_url (str): Absolute URL of the book.

Returns:
        obj: :class:`structures.Publication` instance with book details.


def get_pipeline_path(pipeline_name, working_directory):

    logger.debug("starting")

    # look for name.yaml in the pipelines/ sub-directory
    logger.debug(f"current directory is {working_directory}")

    # looking for {cwd}/pipelines/[pipeline_name].yaml
    pipeline_path = os.path.abspath(os.path.join(
        working_directory,
        'pipelines',
        pipeline_name + '.yaml'))

    if os.path.isfile(pipeline_path):
        logger.debug(f"Found {pipeline_path}")
    else:
        logger.debug(f"{pipeline_name} not found in current "
                     "directory/pipelines folder. Looking in pypyr install "
                     "directory instead.")
        pypyr_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        logger.debug(f"pypyr installation directory is: {pypyr_dir}")
        pipeline_path = os.path.abspath(os.path.join(
            pypyr_dir,
            'pipelines',
            pipeline_name + '.yaml'))

        if os.path.isfile(pipeline_path):
            logger.debug(f"Found {pipeline_path}")
        else:
            raise PipelineNotFoundError(f"{pipeline_name}.yaml not found in "
                                        f"either "
                                        f"{working_directory}/pipelines "
                                        f"or {pypyr_dir}/pipelines")

    logger.debug("done")
    return pipeline_path

Look for the pipeline in the various places it could be.

    First checks the cwd. Then checks pypyr/pipelines dir.

Args:
        pipeline_name: string. Name of pipeline to find
        working_directory: string. Path in which to look for pipeline_name.yaml

Returns:
        Absolute path to the pipeline_name.yaml file

Raises:
        PipelineNotFoundError: if pipeline_name.yaml not found in working_dir
                            or in {pypyr install dir}/pipelines.


def fresh(t, non_generic):

    mappings = {}  # A mapping of TypeVariables to TypeVariables

    def freshrec(tp):
        p = prune(tp)
        if isinstance(p, TypeVariable):
            if is_generic(p, non_generic):
                if p not in mappings:
                    mappings[p] = TypeVariable()
                return mappings[p]
            else:
                return p
        elif isinstance(p, dict):
            return p  # module
        elif isinstance(p, Collection):
            return Collection(*[freshrec(x) for x in p.types])
        elif isinstance(p, Scalar):
            return Scalar([freshrec(x) for x in p.types])
        elif isinstance(p, TypeOperator):
            return TypeOperator(p.name, [freshrec(x) for x in p.types])
        elif isinstance(p, MultiType):
            return MultiType([freshrec(x) for x in p.types])
        else:
            assert False, "missing freshrec case {}".format(type(p))

    return freshrec(t)

Makes a copy of a type expression.

    The type t is copied. The generic variables are duplicated and the
    non_generic variables are shared.

Args:
        t: A type to be copied.
        non_generic: A set of non-generic TypeVariables


def profile_view(request, user_id=None):

    if request.user.is_eighthoffice and "full" not in request.GET and user_id is not None:
        return redirect("eighth_profile", user_id=user_id)

    if user_id is not None:
        try:
            profile_user = User.objects.get(id=user_id)

            if profile_user is None:
                raise Http404
        except User.DoesNotExist:
            raise Http404
    else:
        profile_user = request.user

    num_blocks = 6

    eighth_schedule = []
    start_block = EighthBlock.objects.get_first_upcoming_block()

    blocks = []
    if start_block:
        blocks = [start_block] + list(start_block.next_blocks(num_blocks - 1))

    for block in blocks:
        sch = {"block": block}
        try:
            sch["signup"] = EighthSignup.objects.get(scheduled_activity__block=block, user=profile_user)
        except EighthSignup.DoesNotExist:
            sch["signup"] = None
        except MultipleObjectsReturned:
            client.captureException()
            sch["signup"] = None
        eighth_schedule.append(sch)

    if profile_user.is_eighth_sponsor:
        sponsor = EighthSponsor.objects.get(user=profile_user)
        start_date = get_start_date(request)
        eighth_sponsor_schedule = (EighthScheduledActivity.objects.for_sponsor(sponsor).filter(block__date__gte=start_date).order_by(
            "block__date", "block__block_letter"))
        eighth_sponsor_schedule = eighth_sponsor_schedule[:10]
    else:
        eighth_sponsor_schedule = None

    admin_or_teacher = (request.user.is_eighth_admin or request.user.is_teacher)
    can_view_eighth = (profile_user.can_view_eighth or request.user == profile_user)
    eighth_restricted_msg = (not can_view_eighth and admin_or_teacher)

    if not can_view_eighth and not request.user.is_eighth_admin and not request.user.is_teacher:
        eighth_schedule = []

    has_been_nominated = profile_user.username in [
        u.nominee.username for u in request.user.nomination_votes.filter(position__position_name=settings.NOMINATION_POSITION)
    ]
    context = {
        "profile_user": profile_user,
        "eighth_schedule": eighth_schedule,
        "can_view_eighth": can_view_eighth,
        "eighth_restricted_msg": eighth_restricted_msg,
        "eighth_sponsor_schedule": eighth_sponsor_schedule,
        "nominations_active": settings.NOMINATIONS_ACTIVE,
        "nomination_position": settings.NOMINATION_POSITION,
        "has_been_nominated": has_been_nominated
    }
    return render(request, "users/profile.html", context)

Displays a view of a user's profile.

Args:
        user_id
            The ID of the user whose profile is being viewed. If not
            specified, show the user's own profile.


def _parse_alt_url(html_chunk):

    url_list = html_chunk.find("a", fn=has_param("href"))
    url_list = map(lambda x: x.params["href"], url_list)
    url_list = filter(lambda x: not x.startswith("autori/"), url_list)

    if not url_list:
        return None

    return normalize_url(BASE_URL, url_list[0])

Parse URL from alternative location if not found where it should be.

Args:
        html_chunk (obj): HTMLElement containing slice of the page with details.

Returns:
        str: Book's URL.


def _ParseRecords(self, parser_mediator, evt_file):

    # To handle errors when parsing a Windows EventLog (EVT) file in the most
    # granular way the following code iterates over every event record. The
    # call to evt_file.get_record() and access to members of evt_record should
    # be called within a try-except.

    for record_index in range(evt_file.number_of_records):
      if parser_mediator.abort:
        break

      try:
        evt_record = evt_file.get_record(record_index)
        self._ParseRecord(parser_mediator, record_index, evt_record)
      except IOError as exception:
        parser_mediator.ProduceExtractionWarning(
            'unable to parse event record: {0:d} with error: {1!s}'.format(
                record_index, exception))

    for record_index in range(evt_file.number_of_recovered_records):
      if parser_mediator.abort:
        break

      try:
        evt_record = evt_file.get_recovered_record(record_index)
        self._ParseRecord(
            parser_mediator, record_index, evt_record, recovered=True)
      except IOError as exception:
        parser_mediator.ProduceExtractionWarning((
            'unable to parse recovered event record: {0:d} with error: '
            '{1!s}').format(record_index, exception))

Parses Windows EventLog (EVT) records.

Args:
        parser_mediator (ParserMediator): mediates interactions between parsers
        and other components, such as storage and dfvfs.
        evt_file (pyevt.file): Windows EventLog (EVT) file.


def __init__(self, artifacts_registry, knowledge_base):

    super(ArtifactDefinitionsFilterHelper, self).__init__()
    self._artifacts_registry = artifacts_registry
    self._knowledge_base = knowledge_base

    self.file_system_artifact_names = set()
    self.file_system_find_specs = []
    self.registry_artifact_names = set()
    self.registry_find_specs = []

Initializes an artifact definitions filter helper.

Args:
        artifacts_registry (artifacts.ArtifactDefinitionsRegistry): artifact
        definitions registry.
        knowledge_base (KnowledgeBase): contains information from the source
        data needed for filtering.


def _check_and_parse_eltorito(self, br):
        # type: (headervd.BootRecord) -> None

        if br.boot_system_identifier != b'EL TORITO SPECIFICATION'.ljust(32, b'\x00'):
            return

        if self.eltorito_boot_catalog is not None:
            raise pycdlibexception.PyCdlibInvalidISO('Only one El Torito boot record is allowed')

        # According to the El Torito specification, section 2.0, the El
        # Torito boot record must be at extent 17.
        if br.extent_location() != 17:
            raise pycdlibexception.PyCdlibInvalidISO('El Torito Boot Record must be at extent 17')

        # Now that we have verified that the BootRecord is an El Torito one
        # and that it is sane, we go on to parse the El Torito Boot Catalog.
        # Note that the Boot Catalog is stored as a file in the ISO, though
        # we ignore that for the purposes of parsing.

        self.eltorito_boot_catalog = eltorito.EltoritoBootCatalog(br)
        eltorito_boot_catalog_extent, = struct.unpack_from('=L', br.boot_system_use[:4], 0)

        old = self._cdfp.tell()
        self._cdfp.seek(eltorito_boot_catalog_extent * self.pvd.logical_block_size())
        data = self._cdfp.read(32)
        while not self.eltorito_boot_catalog.parse(data):
            data = self._cdfp.read(32)
        self._cdfp.seek(old)

An internal method to examine a Boot Record and see if it is an
    El Torito Boot Record.  If it is, parse the El Torito Boot Catalog,
    verification entry, initial entry, and any additional section entries.

    Parameters:
    br - The boot record to examine for an El Torito signature.

Returns:
    Nothing.


def __init__(self, path):

        # if list, do a pathjoin
        if isinstance(path, list):
            path = os.path.join(*path)

        # store as pathlib.Path, to avoid unexpected relative
        # path redirection
        self.path = Path(path).resolve()

        # ensure that path exists
        if not self.path.is_dir():
            log.error("No path exists at {}".format(self.path))
            err_msg = "Path '{}' is not a directory.".format(self.path)
            raise NotADirectoryError(err_msg)

        log.info("%d Serving static files out of %s" % (id(self), self.path))

Construct Static method.

Args:
        path (str or list): The directory path to search for files.
            If this is a list, the paths will be path-joined
            automatically.


def _is_valid_netmask(self, prefixlen):

        try:
            prefixlen = int(prefixlen)
        except ValueError:
            return False
        return 0 <= prefixlen <= self._max_prefixlen

Verify that the netmask/prefixlen is valid.

Args:
        prefixlen: A string, the netmask in prefix length format.

Returns:
        A boolean, True if the prefix represents a valid IPv6
        netmask.


def record(self, crc_bytes):
        # type: (bytes) -> bytes

        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError('UDF Descriptor Tag not initialized')

        crc_byte_len = len(crc_bytes)
        if self.desc_crc_length >= 0:
            crc_byte_len = self.desc_crc_length

        # We need to compute the checksum, but we'll do that by first creating
        # the output buffer with the csum field set to 0, computing the csum,
        # and then setting that record back as usual.
        rec = bytearray(struct.pack(self.FMT, self.tag_ident, self.desc_version,
                                    0, 0, self.tag_serial_number,
                                    crc_ccitt(crc_bytes[:crc_byte_len]),
                                    crc_byte_len, self.tag_location))

        rec[4] = _compute_csum(rec)

        return bytes(rec)

A method to generate the string representing this UDF Descriptor Tag.

    Parameters:
    crc_bytes - The string to compute the CRC over.

Returns:
    A string representing this UDF Descriptor Tag.


def content_create(self, key, model, contentid, meta, protected=False):

        params = {'id': contentid, 'meta': meta}
        if protected is not False:
            params['protected'] = 'true'
        data = urlencode(params)
        path = PROVISION_MANAGE_CONTENT + model + '/'
        return self._request(path,
                             key, data, 'POST', self._manage_by_cik)

Creates a content entity bucket with the given `contentid`.

    This method maps to
    https://github.com/exosite/docs/tree/master/provision#post---create-content-entity.

Args:
        key: The CIK or Token for the device
        model:
        contentid: The ID used to name the entity bucket
        meta:
        protected: Whether or not this is restricted to certain device serial numbers only.


def update_dynamic_gene_list(self, case, hgnc_symbols=None, hgnc_ids=None,
                                 phenotype_ids=None, build='37'):

        dynamic_gene_list = []
        res = []
        if hgnc_ids:
            LOG.info("Fetching genes by hgnc id")
            res = self.hgnc_collection.find({'hgnc_id': {'$in': hgnc_ids}, 'build': build})
        elif hgnc_symbols:
            LOG.info("Fetching genes by hgnc symbols")
            res = []
            for symbol in hgnc_symbols:
                for gene_obj in self.gene_by_alias(symbol=symbol, build=build):
                    res.append(gene_obj)

        for gene_obj in res:
            dynamic_gene_list.append(
                {
                    'hgnc_symbol': gene_obj['hgnc_symbol'],
                    'hgnc_id': gene_obj['hgnc_id'],
                    'description': gene_obj['description'],
                }
            )

        LOG.info("Update dynamic gene panel for: %s", case['display_name'])
        updated_case = self.case_collection.find_one_and_update(
            {'_id': case['_id']},
            {'$set': {'dynamic_gene_list': dynamic_gene_list,
                      'dynamic_panel_phenotypes': phenotype_ids or []}},
            return_document=pymongo.ReturnDocument.AFTER
        )
        LOG.debug("Case updated")
        return updated_case

Update the dynamic gene list for a case

    Adds a list of dictionaries to case['dynamic_gene_list'] that looks like

    {
        hgnc_symbol: str,
        hgnc_id: int,
        description: str
    }

Args:
        case (dict): The case that should be updated
        hgnc_symbols (iterable): A list of hgnc_symbols
        hgnc_ids (iterable): A list of hgnc_ids

Returns:
        updated_case(dict)


def file_exists(file_path, credentials=None):

  if file_path.startswith('gs://'):
    return _file_exists_in_gcs(file_path, credentials)
  else:
    return os.path.isfile(file_path)

Check whether the file exists, on local disk or GCS.

Args:
        file_path: The target file path; should have the 'gs://' prefix if in gcs.
        credentials: Optional credential to be used to load the file from gcs.

Returns:
        True if the file's there.


def _open_streaming_interface(self, connection_id, callback):

        try:
            context = self.connections.get_context(connection_id)
        except ArgumentError:
            callback(connection_id, self.id, False, "Could not find connection information")
            return

        self._logger.info("Attempting to enable streaming")
        self.connections.begin_operation(connection_id, 'open_interface', callback, self.get_config('default_timeout'))

        try:
            characteristic = context['services'][TileBusService][StreamingChar]
        except KeyError:
            self.connections.finish_operation(
                connection_id,
                False,
                "Can't find characteristic to open streaming interface"
            )
            return

        context['parser'] = IOTileReportParser(report_callback=self._on_report, error_callback=self._on_report_error)
        context['parser'].context = connection_id

        def on_report_chunk_received(report_chunk):

            context['parser'].add_data(report_chunk)

        # Register our callback function in the notifications callbacks
        self._register_notification_callback(
            context['connection_handle'],
            characteristic.value_handle,
            on_report_chunk_received
        )

        self.bable.set_notification(
            enabled=True,
            connection_handle=context['connection_handle'],
            characteristic=characteristic,
            on_notification_set=[self._on_interface_opened, context],
            on_notification_received=self._on_notification_received,
            timeout=1.0,
            sync=False
        )

Enable streaming interface for this IOTile device

Args:
        connection_id (int): The unique identifier for the connection
        callback (callback): Callback to be called when this command finishes
            callback(conn_id, adapter_id, success, failure_reason)


def _send_offset_requests(self, timestamps):

        timestamps_by_node = collections.defaultdict(dict)
        for partition, timestamp in six.iteritems(timestamps):
            node_id = self._client.cluster.leader_for_partition(partition)
            if node_id is None:
                self._client.add_topic(partition.topic)
                log.debug("Partition %s is unknown for fetching offset,"
                          " wait for metadata refresh", partition)
                return Future().failure(Errors.StaleMetadata(partition))
            elif node_id == -1:
                log.debug("Leader for partition %s unavailable for fetching "
                          "offset, wait for metadata refresh", partition)
                return Future().failure(
                    Errors.LeaderNotAvailableError(partition))
            else:
                timestamps_by_node[node_id][partition] = timestamp

        # Aggregate results until we have all
        list_offsets_future = Future()
        responses = []
        node_count = len(timestamps_by_node)

        def on_success(value):
            responses.append(value)
            if len(responses) == node_count:
                offsets = {}
                for r in responses:
                    offsets.update(r)
                list_offsets_future.success(offsets)

        def on_fail(err):
            if not list_offsets_future.is_done:
                list_offsets_future.failure(err)

        for node_id, timestamps in six.iteritems(timestamps_by_node):
            _f = self._send_offset_request(node_id, timestamps)
            _f.add_callback(on_success)
            _f.add_errback(on_fail)
        return list_offsets_future

Fetch offsets for each partition in timestamps dict. This may send
    request to multiple nodes, based on who is Leader for partition.

Args:
        timestamps (dict): {TopicPartition: int} mapping of fetching
            timestamps.

Returns:
        Future: resolves to a mapping of retrieved offsets


def bars(n=3,n_categories=3,prefix='category',columns=None,mode='abc'):

	categories=[]
	if not columns:
		columns=getName(n,mode=mode)
	for i in range(n_categories):
		categories.extend([prefix+str(i+1)])
	data=dict([(x,np.random.randint(1,100,n_categories)) for x in columns])
	return pd.DataFrame(data,index=categories)

Returns a DataFrame with the required format for
    a bar plot

    Parameters:
    -----------
    n : int
        Number of points for each trace
    n_categories : int
        Number of categories for each point
    prefix : string
        Name for each category
    columns : [str]
        List of column names
    mode : string
        Format for each item
        'abc' for alphabet columns
        'stocks' for random stock names


def iterator_zip(variables: VarType, parent: str = None) -> Iterable[VarMatrix]:

    logger.debug("Yielding from zip iterator")
    if isinstance(variables, list):
        for item in variables:
            yield list(variable_matrix(item, parent, "zip"))
    else:
        yield list(variable_matrix(variables, parent, "zip"))

Apply the zip operator to a set of variables.

    This uses the python zip iterator to combine multiple lists of variables such that
    the nth variable in each list is aligned.

Args:
        variables: The variables object
        parent: Unused


def post(self, json=None):

        return self._call('post', url=self.endpoint, json=json)

Send a POST request and return the JSON decoded result.

Args:
        json (dict, optional): Object to encode and send in request.

Returns:
        mixed: JSON decoded response data.


def timed_display(msg):

    def print_header(msg, newline=True):

        if sys.stdout.isatty():
            print('\r', end=Style.BRIGHT + Fore.BLUE)
        print(' {} '.format(msg).center(_ncols(), '='),
              end='\n{}'.format(Style.RESET_ALL)
              if newline else Style.RESET_ALL)
        sys.stdout.flush()

    def print_message(msg):

        if sys.stdout.isatty():
            print('\r', end='')
            msg = msg.ljust(_ncols())
        print(msg, end='')
        sys.stdout.flush()

    start = time.time()
    print_header(msg)
    with hidden_cursor():
        try:
            yield print_message
        finally:
            delta = time.time() - start
            print_header('completed in {:.2f}s'.format(delta), False)

A timed block to run tasks with titles and success/failure messages.

Args:
        msg: The header message to print at the beginning of the timed block.


def __init__(self, callback):

        super(LLDP, self).__init__(callback)
        self._lldp = brcd_lldp(callback=pynos.utilities.return_xml)

LLDP init method.

Args:
        callback (function): Callback function that will be called for each
            action.

Returns:
        LLDP Object

Raises:
        None


def getFingerprint(self, text):

        fp = self._fullClient.getFingerprintForText(text)
        return fp.positions

Get the semantic fingerprint of the input text.

Args:
        text, str: The text to be evaluated

Returns:
        list of str: the positions of the semantic fingerprint

Raises:
        CorticalioException: if the request was not successful


def get_py_dtypes(data_frame):

    df_py_dtypes = data_frame.dtypes.map(get_py_dtype).to_frame('dtype').copy()
    df_py_dtypes.loc[df_py_dtypes.dtype == object, 'dtype'] = \
        (df_py_dtypes.loc[df_py_dtypes.dtype == object].index
         .map(lambda c: str if data_frame[c]
              .map(lambda v: isinstance(v, str)).all() else object))

    df_py_dtypes.insert(0, 'i', range(df_py_dtypes.shape[0]))
    df_py_dtypes.index.name = 'column'
    return df_py_dtypes

Return a `pandas.DataFrame` containing Python type information for the
    columns in `data_frame`.

Args:
        data_frame (pandas.DataFrame) : Data frame containing data columns.

Returns:
        (pandas.DataFrame) : Data frame indexed by the column names from
            `data_frame`, with the columns `'i'` and `'dtype'` indicating the
            index and Python type of the corresponding `data_frame` column,
            respectively.


def __init__(self, a_schedule, b_schedule, merged_schedule,
               problem_reporter):

    self.a_schedule = a_schedule
    self.b_schedule = b_schedule
    self.merged_schedule = merged_schedule
    self.a_merge_map = {}
    self.b_merge_map = {}
    self.a_zone_map = {}
    self.b_zone_map = {}
    self._mergers = []
    self._idnum = max(self._FindLargestIdPostfixNumber(self.a_schedule),
                      self._FindLargestIdPostfixNumber(self.b_schedule))

    self.problem_reporter = problem_reporter

Initialise the merger.

    Once this initialiser has been called, a_schedule and b_schedule should
    not be modified.

Args:
        a_schedule: The old schedule, an instance of transitfeed.Schedule.
        b_schedule: The new schedule, an instance of transitfeed.Schedule.
        problem_reporter: The problem reporter, an instance of
                        transitfeed.ProblemReporter.


def ud_grade_ipix(ipix, nside_in, nside_out, nest=False):

    if nside_in == nside_out: return ipix
    elif nside_in < nside_out:
        return u_grade_ipix(ipix, nside_in, nside_out, nest)
    elif nside_in > nside_out:
        return d_grade_ipix(ipix, nside_in, nside_out, nest)

Upgrade or degrade resolution of a pixel list.

    Parameters:
    -----------
    ipix:array-like
    the input pixel(s)

    nside_in:int
    the nside of the input pixel(s)

    nside_out:int
    the desired nside of the output pixel(s)

    order:str
    pixel ordering of input and output ("RING" or "NESTED")

Returns:
    --------
    pix_out:array-like
    the upgraded or degraded pixel array


def make_es_id(uri):

    try:
        uri = uri.clean_uri
    except AttributeError:
        pass
    return sha1(uri.encode()).hexdigest()

Creates the id based off of the uri value

Args:
    -----
        uri: the uri to conver to an elasticsearch id


def from_dict(cls, metadata):

        hyperparameters = metadata.get('hyperparameters')
        tunable = metadata.get('tunable_hyperparameters')

        pipeline = cls(
            metadata['primitives'],
            metadata.get('init_params'),
            metadata.get('input_names'),
            metadata.get('output_names'),
        )

        if hyperparameters:
            pipeline.set_hyperparameters(hyperparameters)

        if tunable is not None:
            pipeline._tunable_hyperparameters = tunable

        return pipeline

Create a new MLPipeline from a dict specification.

    The dict structure is the same as the one created by the `to_dict` method.

Args:
        metadata (dict): Dictionary containing the pipeline specification.

Returns:
        MLPipeline:
            A new MLPipeline instance with the details found in the
            given specification dictionary.


def check_synced(localval, comm=None):

    comm = comm or MPI.COMM_WORLD
    vals = comm.gather(localval)
    if comm.rank == 0:
        assert all(val==vals[0] for val in vals[1:])

It's common to forget to initialize your variables to the same values, or
    (less commonly) if you update them in some other way than adam, to get them out of sync.
    This function checks that variables on all MPI workers are the same, and raises
    an AssertionError otherwise

Args:
        comm: MPI communicator
        localval: list of local variables (list of variables on current worker to be compared with the other workers)


def get_foreign_id(self, idspace='musicbrainz', cache=True):

        if not (cache and ('foreign_ids' in self.cache) and filter(lambda d: d.get('catalog') == idspace, self.cache['foreign_ids'])):
            response = self.get_attribute('profile', bucket=['id:'+idspace])
            foreign_ids = response['artist'].get("foreign_ids", [])
            self.cache['foreign_ids'] = self.cache.get('foreign_ids', []) + foreign_ids
        cval = filter(lambda d: d.get('catalog') == util.map_idspace(idspace),
                      self.cache.get('foreign_ids'))
        return cval[0].get('foreign_id') if cval else None

Get the foreign id for this artist for a specific id space

Args:
    Kwargs:
        idspace (str): A string indicating the idspace to fetch a foreign id for.

Returns:
        A foreign ID string

Example:
    >>> a = artist.Artist('fabulous')
    >>> a.get_foreign_id('7digital')
    u'7digital:artist:186042'
    >>>


def ExtractEvents(self, parser_mediator, registry_key, **kwargs):

    version_value = registry_key.GetValueByName('Version')
    count_subkey = registry_key.GetSubkeyByName('Count')

    if not version_value:
      parser_mediator.ProduceExtractionWarning('missing version value')
      return

    if not version_value.DataIsInteger():
      parser_mediator.ProduceExtractionWarning(
          'unsupported version value data type')
      return

    format_version = version_value.GetDataAsObject()
    if format_version not in (3, 5):
      parser_mediator.ProduceExtractionWarning(
          'unsupported format version: {0:d}'.format(format_version))
      return

    if not count_subkey:
      parser_mediator.ProduceExtractionWarning('missing count subkey')
      return

    userassist_entry_index = 0

    for registry_value in count_subkey.GetValues():
      try:
        # Note that Python 2 codecs.decode() does not support keyword arguments
        # such as encodings='rot-13'.
        value_name = codecs.decode(registry_value.name, 'rot-13')
      except UnicodeEncodeError as exception:
        logger.debug((
            'Unable to decode UserAssist string: {0:s} with error: {1!s}.\n'
            'Attempting piecewise decoding.').format(
                registry_value.name, exception))

        characters = []
        for char in registry_value.name:
          if ord(char) < 128:
            try:
              characters.append(char.decode('rot-13'))
            except UnicodeEncodeError:
              characters.append(char)
          else:
            characters.append(char)

        value_name = ''.join(characters)

      if format_version == 5:
        path_segments = value_name.split('\\')

        for segment_index, path_segment in enumerate(path_segments):
          # Remove the { } from the path segment to get the GUID.
          guid = path_segments[segment_index][1:-1]
          path_segments[segment_index] = known_folder_ids.PATHS.get(
              guid, path_segment)

        value_name = '\\'.join(path_segments)
        # Check if we might need to substitute values.
        if '%' in value_name:
          # TODO: fix missing self._knowledge_base
          # pylint: disable=no-member
          environment_variables = self._knowledge_base.GetEnvironmentVariables()
          value_name = path_helper.PathHelper.ExpandWindowsPath(
              value_name, environment_variables)

      if value_name == 'UEME_CTLSESSION':
        continue

      if format_version == 3:
        entry_map = self._GetDataTypeMap('user_assist_entry_v3')
      elif format_version == 5:
        entry_map = self._GetDataTypeMap('user_assist_entry_v5')
      else:
        parser_mediator.ProduceExtractionWarning(
            'unsupported format version: {0:d}'.format(format_version))
        continue

      if not registry_value.DataIsBinaryData():
        parser_mediator.ProduceExtractionWarning(
            'unsupported value data type: {0:s}'.format(
                registry_value.data_type_string))
        continue

      entry_data_size = entry_map.GetByteSize()
      value_data_size = len(registry_value.data)
      if entry_data_size != value_data_size:
        parser_mediator.ProduceExtractionWarning(
            'unsupported value data size: {0:d}'.format(value_data_size))
        continue

      try:
        user_assist_entry = self._ReadStructureFromByteStream(
            registry_value.data, 0, entry_map)
      except (ValueError, errors.ParseError) as exception:
        parser_mediator.ProduceExtractionWarning(
            'unable to parse UserAssist entry value with error: {0!s}'.format(
                exception))
        continue

      event_data = UserAssistWindowsRegistryEventData()
      event_data.key_path = count_subkey.path
      event_data.number_of_executions = user_assist_entry.number_of_executions
      event_data.value_name = value_name

      if format_version == 3:
        if event_data.number_of_executions > 5:
          event_data.number_of_executions -= 5

      elif format_version == 5:
        userassist_entry_index += 1

        event_data.application_focus_count = (
            user_assist_entry.application_focus_count)
        event_data.application_focus_duration = (
            user_assist_entry.application_focus_duration)
        event_data.entry_index = userassist_entry_index

      timestamp = user_assist_entry.last_execution_time
      if not timestamp:
        date_time = dfdatetime_semantic_time.SemanticTime('Not set')
      else:
        date_time = dfdatetime_filetime.Filetime(timestamp=timestamp)

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

Extracts events from a Windows Registry key.

Args:
        parser_mediator (ParserMediator): mediates interactions between parsers
        and other components, such as storage and dfvfs.
        registry_key (dfwinreg.WinRegistryKey): Windows Registry key.


def variant(self, document_id, gene_panels=None, case_id=None):

        query = {}
        if case_id:
            # search for a variant in a case
            query['case_id'] = case_id
            query['variant_id'] = document_id
        else:
            # search with a unique id
            query['_id'] = document_id

        variant_obj = self.variant_collection.find_one(query)
        if variant_obj:
            variant_obj = self.add_gene_info(variant_obj, gene_panels)
            if variant_obj['chromosome'] in ['X', 'Y']:
                ## TODO add the build here
                variant_obj['is_par'] = is_par(variant_obj['chromosome'],
                                               variant_obj['position'])
        return variant_obj

Returns the specified variant.

Args:
        document_id : A md5 key that represents the variant or "variant_id"
        gene_panels(List[GenePanel])
        case_id (str): case id (will search with "variant_id")

Returns:
        variant_object(Variant): A odm variant object


def find(self, _id, instance = None):

        if instance is None:
            # We are looking for an instance
            return self.service_instance.find(_id)
        else:
            # We are looking for a binding
            return self.service_binding.find(_id, instance)

Find

Args:
        _id (str): instance id or binding Id

    Keyword Arguments:
        instance (AtlasServiceInstance.Instance): Existing instance

Returns:
        AtlasServiceInstance.Instance or AtlasServiceBinding.Binding: An instance or binding.


def __init__(self, inputs=None,
                 outputs=None,
                 assettype=AssetType.GoverningToken,
                 assetname='',
                 amount=Fixed8(0),
                 precision=0,
                 owner=None,
                 admin=None):

        super(RegisterTransaction, self).__init__(inputs, outputs)
        self.Type = TransactionType.RegisterTransaction  # 0x40
        self.AssetType = assettype
        self.Name = assetname
        self.Amount = amount  # Unlimited Mode: -0.00000001

        if inputs is not None:
            self.inputs = inputs
        else:
            self.inputs = []

        if outputs is not None:
            self.outputs = outputs
        else:
            self.outputs = []

        if owner is not None and type(owner) is not EllipticCurve.ECPoint:
            raise Exception("Invalid owner, must be ECPoint instance")

        self.Owner = owner
        self.Admin = admin
        self.Precision = precision

Create an instance.

Args:
        inputs (list):
        outputs (list):
        assettype (neo.Core.AssetType):
        assetname (str):
        amount (Fixed8):
        precision (int): number of decimals the asset has.
        owner (EllipticCurve.ECPoint):
        admin (UInt160):


def _AddOption(self, name):

    # Check for duplicate option declaration
    if name in [option.name for option in self.options]:
      raise TextFSMTemplateError('Duplicate option "%s"' % name)

    # Create the option object
    try:
      option = self._options_cls.GetOption(name)(self)
    except AttributeError:
      raise TextFSMTemplateError('Unknown option "%s"' % name)

    self.options.append(option)

Add an option to this Value.

Args:
        name: (str), the name of the Option to add.

Raises:
        TextFSMTemplateError: If option is already present or
        the option does not exist.


def setUpMethods(self, port):

        assert isinstance(port, WSDLTools.Port), \
            'expecting WSDLTools.Port not: ' %type(port)

        sd = self._services.get(port.getService().name)
        assert sd is not None, 'failed to initialize.'

        binding = port.getBinding()
        portType = port.getPortType()
        action_in = ''
        for bop in binding.operations:
            try:
                op = portType.operations[bop.name]
            except KeyError, ex:
                raise WsdlGeneratorError,\
                    'Port(%s) PortType(%s) missing operation(%s) defined in Binding(%s)' \
                    %(port.name,portType.name,bop.name,binding.name)

            for ext in bop.extensions:
                 if isinstance(ext, WSDLTools.SoapOperationBinding):
                     action_in = ext.soapAction
                     break
            else:
                warnings.warn('Port(%s) operation(%s) defined in Binding(%s) missing soapAction' \
                    %(port.name,op.name,binding.name)
                )

            msgin = op.getInputMessage()
            msgin_name = TextProtect(msgin.name)
            method_name = self.getMethodName(op.name)

            m = sd.newMethod()
            print >>m, '%sdef %s(self, ps, **kw):' %(self.getIndent(level=1), method_name)
            if msgin is not None:
                print >>m, '%srequest = ps.Parse(%s.typecode)' %(self.getIndent(level=2), msgin_name)
            else:
                print >>m, '%s# NO input' %self.getIndent(level=2)

            msgout = op.getOutputMessage()
            if msgout is not None:
                msgout_name = TextProtect(msgout.name)
                print >>m, '%sreturn request,%s()' %(self.getIndent(level=2), msgout_name)
            else:
                print >>m, '%s# NO output' % self.getIndent(level=2)
                print >>m, '%sreturn request,None' % self.getIndent(level=2)

            print >>m, ''
            print >>m, '%ssoapAction[\'%s\'] = \'%s\'' %(self.getIndent(level=1), action_in, method_name)
            print >>m, '%sroot[(%s.typecode.nspname,%s.typecode.pname)] = \'%s\'' \
                     %(self.getIndent(level=1), msgin_name, msgin_name, method_name)

        return

set up all methods representing the port operations.
    Parameters:
        port -- Port that defines the operations.


def install(self, connection, partition, table_name=None, columns=None, materialize=False,
                logger=None):

        partition.localize()

        self._add_partition(connection, partition)
        fdw_table = partition.vid
        view_table = '{}_v'.format(fdw_table)

        if materialize:
            with connection.cursor() as cursor:
                view_exists = self._relation_exists(connection, view_table)
                if view_exists:
                    logger.debug(
                        'Materialized view of the partition already exists.\n    partition: {}, view: {}'
                        .format(partition.name, view_table))
                else:
                    query = 'CREATE MATERIALIZED VIEW {} AS SELECT * FROM {};'\
                        .format(view_table, fdw_table)
                    logger.debug(
                        'Creating new materialized view of the partition.'
                        '\n    partition: {}, view: {}, query: {}'
                        .format(partition.name, view_table, query))
                    cursor.execute(query)
                    cursor.execute('COMMIT;')

        final_table = view_table if materialize else fdw_table

        with connection.cursor() as cursor:
            view_q = "CREATE VIEW IF NOT EXISTS {} AS SELECT * FROM {} ".format(partition.vid, final_table)
            cursor.execute(view_q)
            cursor.execute('COMMIT;')

        return partition.vid

Creates FDW or materialize view for given partition.

Args:
        connection: connection to postgresql
        partition (orm.Partition):
        materialize (boolean): if True, create read-only table. If False create virtual table.

Returns:
        str: name of the created table.


def follow(self, chars):

        chars = chars.lower()

        node = self.node
        for char in chars:
            node = cgaddag.gdg_follow_edge(self.gdg, node, char.encode("ascii"))
            if not node:
                raise KeyError(char)

        return Node(self.gdg, node)

Traverse the GADDAG to the node at the end of the given characters.

Args:
        chars: An string of characters to traverse in the GADDAG.

Returns:
        The Node which is found by traversing the tree.


def __init__(self, value=KeyFormatTypeEnum.RAW):

        super(KeyFormatType, self).__init__(
            KeyFormatTypeEnum, value, Tags.KEY_FORMAT_TYPE)

Construct a KeyFormatType object.

Args:
        value (KeyFormatType): A KeyFormatType enumeration value,
            (e.g., KeyFormatType.PKCS_1). Optional, default to
            KeyFormatType.RAW.