def content_metadata_uploads(self, mirror=False):
    excludes_str = ''
    includes_cmds = []
    cmd_base = self._get_upload_cmd(mirror=mirror)
    for content in self.s3props.get('content_metadata'):
        full_path = os.path.join(self.artifact_path, content['path'])
        if (not os.listdir(full_path)):
            raise S3ArtifactNotFound
        excludes_str += '--exclude "{}/*" '.format(content['path'])
        include_cmd = '{} --exclude "*", --include "{}/*"'.format(cmd_base, content['path'])
        include_cmd += ' --content-encoding {} --metadata-directive REPLACE'.format(content['content-encoding'])
        includes_cmds.append(include_cmd)
    exclude_cmd = '{} {}'.format(cmd_base, excludes_str)
    result = subprocess.run(exclude_cmd, check=True, shell=True, stdout=subprocess.PIPE)
    LOG.info('Uploaded files without metadata with command: %s', exclude_cmd)
    LOG.debug('Upload Command Output: %s', result.stdout)
    for include_cmd in includes_cmds:
        result = subprocess.run(include_cmd, check=True, shell=True, stdout=subprocess.PIPE)
        LOG.info('Uploaded files with metadata with command: %s', include_cmd)
        LOG.debug('Upload Command Output: %s', result.stdout)
    return True

Finds all specified encoded directories and uploads in multiple parts,
    setting metadata for objects.

Args:
        mirror (bool): If true, uses a flat directory structure instead of nesting under a version.

Returns:
        bool: True if uploaded


def postprocess_periodical(marc_xml, mods, uuid, counter, url):
    dom = double_linked_dom(mods)
    add_missing_xml_attributes(dom, counter)
    if uuid:
        add_uuid(dom, uuid)
    return dom.prettify()

Some basic postprocessing of the periodical publications.

Args:
        marc_xml (str): Original Aleph record.
        mods (str): XML string generated by XSLT template.
        uuid (str): UUID of the package.
        counter (int): Number of record, is added to XML headers.
        url (str): URL of the publication (public or not).

Returns:
        str: Updated XML.


def matches_to_marker_results(df):
    assert isinstance(df, pd.DataFrame)
    from collections import defaultdict
    d = defaultdict(list)
    for (idx, row) in df.iterrows():
        marker = row['marker']
        d[marker].append(row)
    marker_results = {}
    for (k, v) in d.items():
        if (len(v) > 1):
            logging.debug('Multiple potential cgMLST allele matches (n=%s) found for marker %s. Selecting match on longest contig.', len(v), k)
            df_marker = pd.DataFrame(v)
            df_marker.sort_values('slen', ascending=False, inplace=True)
            for (i, r) in df_marker.iterrows():
                allele = r['allele_name']
                slen = r['slen']
                logging.debug('Selecting allele %s from contig with length %s', allele, slen)
                seq = r['sseq']
                if ('-' in seq):
                    logging.warning('Gaps found in allele. Removing gaps. %s', r)
                    seq = seq.replace('-', '').upper()
                    allele = allele_name(seq)
                marker_results[k] = allele_result_dict(allele, seq, r.to_dict())
                break
        elif (len(v) == 1):
            row = v[0]
            seq = row['sseq']
            if ('-' in seq):
                logging.warning('Gaps found in allele. Removing gaps. %s', row)
                seq = seq.replace('-', '').upper()
            allele = allele_name(seq)
            marker_results[k] = allele_result_dict(allele, seq, row.to_dict())
        else:
            err_msg = 'Empty list of matches for marker {}'.format(k)
            logging.error(err_msg)
            raise Exception(err_msg)
    return marker_results

Perfect BLAST matches to marker results dict

    Parse perfect BLAST matches to marker results dict.

Args:
        df (pandas.DataFrame): DataFrame of perfect BLAST matches

Returns:
        dict: cgMLST330 marker names to matching allele numbers


def need(self, folder, page=None, perpage=None):
    assert (isinstance(page, int) or (page is None))
    assert (isinstance(perpage, int) or (perpage is None))
    return self.get('need', params={'folder': folder, 'page': page, 'perpage': perpage})

Returns lists of files which are needed by this device in order
    for it to become in sync.

Args:
            folder (str):
            page (int): If defined applies pagination accross the
                collection of results.
            perpage (int): If defined applies pagination across the
                collection of results.

Returns:
            dict


def cctop_save_xml(jobid, outpath):
    status = cctop_check_status(jobid=jobid)
    if (status == 'Finished'):
        result = 'http://cctop.enzim.ttk.mta.hu/php/result.php?jobId={}'.format(jobid)
        result_text = requests.post(result)
        with open(outpath, 'w') as f:
            f.write(result_text.text)
        return outpath
    else:
        raise ConnectionRefusedError('CCTOP job incomplete, status is "{}"'.format(status))

Save the CCTOP results file in XML format.

Args:
        jobid (str): Job ID obtained when job was submitted
        outpath (str): Path to output filename

Returns:
        str: Path to output filename


def is_bateries_included(item):
    flag = False
    if (hasattr(item, '__call__') and hasattr(item, '__module__')):
        if (item.__module__ is not None):
            module = sys.modules[item.__module__]
            if (module == builtins):
                flag = True
            elif hasattr(module, '__file__'):
                flag = (LIB_PATH == dirname(module.__file__))
    return flag

Returns if a value is a python builtin function

Args:
        item (object):

Returns:
        bool: flag

    References:
        http://stackoverflow.com/questions/23149218/check-if-a-python-function-is-builtin

    CommandLine:
        python -m utool._internal.meta_util_six is_builtin

Example:
        >>> # DISABLE_DOCTEST
        >>> from utool._internal.meta_util_six import *  # NOQA
        >>> item = zip
        >>> flag = is_bateries_included(item)
        >>> result = ('flag = %s' % (str(flag),))
        >>> print(result)


def defer(coro, delay=1):
    assert_corofunction(coro=coro)

    @asyncio.coroutine
    def wrapper(*args, **kw):
        (yield from asyncio.sleep(delay))
        return (yield from coro(*args, **kw))
    return wrapper

Returns a coroutine function wrapper that will defer the given coroutine
    execution for a certain amount of seconds in a non-blocking way.

    This function can be used as decorator.

Args:
        coro (coroutinefunction): coroutine function to defer.
        delay (int/float): number of seconds to defer execution.

Raises:
        TypeError: if coro argument is not a coroutine function.

Returns:
        filtered values (list): ordered list of resultant values.

    Usage::

        # Usage as function
        await paco.defer(coro, delay=1)
        await paco.defer(coro, delay=0.5)

        # Usage as decorator
        @paco.defer(delay=1)
        async def mul_2(num):
            return num * 2

        await mul_2(2)
        # => 4


def _GetSerializedAttributeContainerList(self, container_type):
    container_list = self._serialized_attribute_containers.get(container_type, None)
    if (not container_list):
        container_list = SerializedAttributeContainerList()
        self._serialized_attribute_containers[container_type] = container_list
    return container_list

Retrieves a serialized attribute container list.

Args:
        container_type (str): attribute container type.

Returns:
        SerializedAttributeContainerList: serialized attribute container list.


def clone(self, *args, **overrides):
    clone = super(Layout, self).clone(*args, **overrides)
    clone._max_cols = self._max_cols
    return clone

Clones the Layout, overriding data and parameters.

Args:
        data: New data replacing the existing data
        shared_data (bool, optional): Whether to use existing data
        new_type (optional): Type to cast object to
        *args: Additional arguments to pass to constructor
        **overrides: New keyword arguments to pass to constructor

Returns:
        Cloned Layout object


def from_samples_bqm(cls, samples_like, bqm, **kwargs):
    samples_like = as_samples(samples_like)
    energies = bqm.energies(samples_like)
    return cls.from_samples(samples_like, energy=energies, vartype=bqm.vartype, **kwargs)

Build a SampleSet from raw samples using a BinaryQuadraticModel to get energies and vartype.

Args:
        samples_like:
            A collection of raw samples. 'samples_like' is an extension of NumPy's array_like.
            See :func:`.as_samples`.

        bqm (:obj:`.BinaryQuadraticModel`):
            A binary quadratic model. It is used to calculate the energies
            and set the vartype.

        info (dict, optional):
            Information about the :class:`SampleSet` as a whole formatted as a dict.

        num_occurrences (array_like, optional):
            Number of occurrences for each sample. If not provided, defaults to a vector of 1s.

        aggregate_samples (bool, optional, default=False):
            If true, returned :obj:`.SampleSet` will have all unique samples.

        sort_labels (bool, optional, default=True):
            If true, :attr:`.SampleSet.variables` will be in sorted-order.
            Note that mixed types are not sortable in which case the given
            order will be maintained.

        **vectors (array_like):
            Other per-sample data.

Returns:
        :obj:`.SampleSet`

Example:
        >>> bqm = dimod.BinaryQuadraticModel.from_ising({}, {('a', 'b'): -1})
        >>> samples = dimod.SampleSet.from_samples_bqm({'a': -1, 'b': 1}, bqm)


def _ReceiveItemOnActivity(self, zmq_socket):
    events = zmq_socket.poll(self._ZMQ_SOCKET_RECEIVE_TIMEOUT_MILLISECONDS)
    if events:
        try:
            received_object = self._zmq_socket.recv_pyobj()
            return received_object
        except zmq.error.Again:
            logger.error('{0:s}. Failed to receive item in time.'.format(self.name))
            raise
        except zmq.error.ZMQError as exception:
            if (exception.errno == errno.EINTR):
                logger.error('ZMQ syscall interrupted in {0:s}. Queue aborting.'.format(self.name))
            raise
    raise errors.QueueEmpty

Attempts to receive an item from a ZeroMQ socket.

Args:
        zmq_socket (zmq.Socket): used to the receive the item.

Returns:
        object: item from the socket.

Raises:
        QueueEmpty: if no item could be received within the timeout.
        zmq.error.ZMQError: if an error occurs in ZeroMQ


def parse_GSE(filepath):
    gpls = {}
    gsms = {}
    series_counter = 0
    database = None
    metadata = {}
    gse_name = None
    with utils.smart_open(filepath) as soft:
        groupper = groupby(soft, (lambda x: x.startswith('^')))
        for (is_new_entry, group) in groupper:
            if is_new_entry:
                (entry_type, entry_name) = __parse_entry(next(group))
                logger.debug(('%s: %s' % (entry_type.upper(), entry_name)))
                if (entry_type == 'SERIES'):
                    gse_name = entry_name
                    series_counter += 1
                    if (series_counter > 1):
                        raise Exception('GSE file should contain only one series entry!')
                    (is_data, data_group) = next(groupper)
                    message = 'The key is not False, probably there is an error in the SOFT file'
                    assert (not is_data), message
                    metadata = parse_metadata(data_group)
                elif (entry_type == 'SAMPLE'):
                    (is_data, data_group) = next(groupper)
                    gsms[entry_name] = parse_GSM(data_group, entry_name)
                elif (entry_type == 'PLATFORM'):
                    (is_data, data_group) = next(groupper)
                    gpls[entry_name] = parse_GPL(data_group, entry_name)
                elif (entry_type == 'DATABASE'):
                    (is_data, data_group) = next(groupper)
                    database_metadata = parse_metadata(data_group)
                    database = GEODatabase(name=entry_name, metadata=database_metadata)
                else:
                    logger.error(('Cannot recognize type %s' % entry_type))
    gse = GSE(name=gse_name, metadata=metadata, gpls=gpls, gsms=gsms, database=database)
    return gse

Parse GSE SOFT file.

Args:
        filepath (:obj:`str`): Path to GSE SOFT file.

Returns:
        :obj:`GEOparse.GSE`: A GSE object.


def parse_headers(cls, msg):
    return list(email.parser.Parser().parsestr(msg).items())

Parse HTTP headers.

Args:
        msg (str): HTTP message.

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


def find_surface_sites_by_height(self, slab, height=0.9, xy_tol=0.05):
    m_projs = np.array([np.dot(site.coords, self.mvec) for site in slab.sites])
    mask = ((m_projs - np.amax(m_projs)) >= (- height))
    surf_sites = [slab.sites[n] for n in np.where(mask)[0]]
    if xy_tol:
        surf_sites = [s for (h, s) in zip(m_projs[mask], surf_sites)]
        surf_sites.reverse()
        (unique_sites, unique_perp_fracs) = ([], [])
        for site in surf_sites:
            this_perp = (site.coords - np.dot(site.coords, self.mvec))
            this_perp_frac = slab.lattice.get_fractional_coords(this_perp)
            if (not in_coord_list_pbc(unique_perp_fracs, this_perp_frac)):
                unique_sites.append(site)
                unique_perp_fracs.append(this_perp_frac)
        surf_sites = unique_sites
    return surf_sites

This method finds surface sites by determining which sites are within
    a threshold value in height from the topmost site in a list of sites

Args:
        site_list (list): list of sites from which to select surface sites
        height (float): threshold in angstroms of distance from topmost
            site in slab along the slab c-vector to include in surface
            site determination
        xy_tol (float): if supplied, will remove any sites which are
            within a certain distance in the miller plane.

Returns:
        list of sites selected to be within a threshold of the highest


def GetFileSystemTypeIndicators(cls, path_spec, resolver_context=None):
    if ((cls._file_system_remainder_list is None) or (cls._file_system_store is None)):
        (specification_store, remainder_list) = cls._GetSpecificationStore(definitions.FORMAT_CATEGORY_FILE_SYSTEM)
        cls._file_system_remainder_list = remainder_list
        cls._file_system_store = specification_store
    if (cls._file_system_scanner is None):
        cls._file_system_scanner = cls._GetSignatureScanner(cls._file_system_store)
    return cls._GetTypeIndicators(cls._file_system_scanner, cls._file_system_store, cls._file_system_remainder_list, path_spec, resolver_context=resolver_context)

Determines if a file contains a supported file system types.

Args:
        path_spec (PathSpec): path specification.
        resolver_context (Optional[Context]): resolver context, where None
        represents the built-in context which is not multi process safe.

Returns:
        list[str]: supported format type indicators.


def get(self, key, mem_map=True):
    self.raise_error_if_not_open()
    if (key in self._file):
        data = self._file[key]
        sampling_rate = data.attrs[SAMPLING_RATE_ATTR]
        if (not mem_map):
            data = data[()]
        data = (np.float32(data) / MAX_INT16_VALUE)
        return (data, sampling_rate)

Return the samples for the given key and the sampling-rate.

Args:
        key (str): The key to read the data from.
        mem_map (bool): If ``True`` returns the data as
                        memory-mapped array, otherwise a copy is returned.

Note:
        The container has to be opened in advance.

Returns:
        tuple: A tuple containing the samples as numpy array
            with ``np.float32`` [-1.0,1.0] and the sampling-rate.


def sia_bipartitions(nodes, node_labels=None):
    if config.CUT_ONE_APPROXIMATION:
        bipartitions = directed_bipartition_of_one(nodes)
    else:
        bipartitions = directed_bipartition(nodes, nontrivial=True)
    return [Cut(bipartition[0], bipartition[1], node_labels) for bipartition in bipartitions]

Return all |big_phi| cuts for the given nodes.

    This value changes based on :const:`config.CUT_ONE_APPROXIMATION`.

Args:
        nodes (tuple[int]): The node indices to partition.

Returns:
        list[Cut]: All unidirectional partitions.


def get_single_upstream_artifact_full_path(context, task_id, path):
    return os.path.abspath(os.path.join(context.config['work_dir'], 'cot', task_id, path))

Return the full path where an upstream artifact should be located.

    Artifact may not exist. If you want to be sure if does, use
    ``get_and_check_single_upstream_artifact_full_path()`` instead.

    This function is mainly used to move artifacts to the expected location.

Args:
        context (scriptworker.context.Context): the scriptworker context.
        task_id (str): the task id of the task that published the artifact
        path (str): the relative path of the artifact

Returns:
        str: absolute path to the artifact should be.


def copy_file(self, file_id, dest_folder_id):
    return self.__request('POST', (('/files/' + unicode(file_id)) + '/copy'), data={'parent': {'id': unicode(dest_folder_id)}})

Copy file to new destination

Args:
        file_id (int): ID of the folder.

        dest_folder_id (int): ID of parent folder you are copying to.

Returns:
        dict. Response from Box.

Raises:
        BoxError: An error response is returned from Box (status_code >= 400).

        BoxError: 409 - Item with the same name already exists.
        In this case you will need download the file and upload a new version to your destination.
        (Box currently doesn't have a method to copy a new verison.)

        BoxHttpResponseError: Response from Box is malformed.

        requests.exceptions.*: Any connection related problem.


def findSequenceOnDisk(cls, pattern, strictPadding=False):
    seq = cls(pattern)
    if ((seq.frameRange() == '') and (seq.padding() == '')):
        if os.path.isfile(pattern):
            return seq
    patt = seq.format('{dirname}{basename}*{extension}')
    ext = seq.extension()
    basename = seq.basename()
    pad = seq.padding()
    globbed = iglob(patt)
    if (pad and strictPadding):
        globbed = cls._filterByPaddingNum(globbed, seq.zfill())
        pad = cls.conformPadding(pad)
    matches = cls.yield_sequences_in_list(globbed)
    for match in matches:
        if ((match.basename() == basename) and (match.extension() == ext)):
            if (pad and strictPadding):
                match.setPadding(pad)
            return match
    msg = 'no sequence found on disk matching {0}'
    raise FileSeqException(msg.format(pattern))

Search for a specific sequence on disk.

    The padding characters used in the `pattern` are used to filter the
    frame values of the files on disk (if `strictPadding` is True).

Example:
        Find sequence matching basename and extension, and a wildcard for
        any frame.
        returns bar.1.exr bar.10.exr, bar.100.exr, bar.1000.exr, inclusive

        >>> findSequenceOnDisk("seq/bar@@@@.exr")

        Find exactly 4-padded sequence, i.e. seq/bar1-100#.exr
        returns only frames bar1000.exr through bar9999.exr

        >>> findSequenceOnDisk("seq/bar#.exr", strictPadding=True)

Args:
        pattern (str): the sequence pattern being searched for
        strictPadding (bool): if True, ignore files with padding length different from `pattern`

Returns:
        str:

Raises:
        :class:`.FileSeqException`: if no sequence is found on disk


def get(self, name):
    interface = name
    if (not interface):
        raise ValueError('Vrrp.get(): interface must contain a value.')
    config = self.get_block(('interface %s' % interface))
    if (config is None):
        return config
    match = set(re.findall('^\\s+(?:no |)vrrp (\\d+)', config, re.M))
    if (not match):
        return None
    result = dict()
    for vrid in match:
        subd = dict()
        subd.update(self._parse_delay_reload(config, vrid))
        subd.update(self._parse_description(config, vrid))
        subd.update(self._parse_enable(config, vrid))
        subd.update(self._parse_ip_version(config, vrid))
        subd.update(self._parse_mac_addr_adv_interval(config, vrid))
        subd.update(self._parse_preempt(config, vrid))
        subd.update(self._parse_preempt_delay_min(config, vrid))
        subd.update(self._parse_preempt_delay_reload(config, vrid))
        subd.update(self._parse_primary_ip(config, vrid))
        subd.update(self._parse_priority(config, vrid))
        subd.update(self._parse_secondary_ip(config, vrid))
        subd.update(self._parse_timers_advertise(config, vrid))
        subd.update(self._parse_track(config, vrid))
        subd.update(self._parse_bfd_ip(config, vrid))
        result.update({int(vrid): subd})
    return (result if result else None)

Get the vrrp configurations for a single node interface

Args:
        name (string): The name of the interface for which vrrp
            configurations will be retrieved.

Returns:
        A dictionary containing the vrrp configurations on the interface.
        Returns None if no vrrp configurations are defined or
        if the interface is not configured.


def GetObject(self, identifier):
    cache_value = self._values.get(identifier, None)
    if (not cache_value):
        return None
    return cache_value.vfs_object

Retrieves a cached object based on the identifier.

    This method ignores the cache value reference count.

Args:
        identifier (str): VFS object identifier.

Returns:
        object: cached VFS object or None if not cached.


def update(self, sparql_query_only=False, auto_refresh=None, update_binary=True):
    self._diff_graph()
    sq = SparqlUpdate(self.rdf.prefixes, self.rdf.diffs)
    if sparql_query_only:
        return sq.build_query()
    response = self.repo.api.http_request('PATCH', ('%s/fcr:metadata' % self.uri), data=sq.build_query(), headers={'Content-Type': 'application/sparql-update'})
    if (response.status_code != 204):
        logger.debug(response.content)
        raise Exception(('HTTP %s, expecting 204' % response.status_code))
    if ((type(self) == NonRDFSource) and update_binary and (type(self.binary.data) != requests.models.Response)):
        self.binary._prep_binary()
        binary_data = self.binary.data
        binary_response = self.repo.api.http_request('PUT', self.uri, data=binary_data, headers={'Content-Type': self.binary.mimetype})
        if ((not auto_refresh) and (not self.repo.default_auto_refresh)):
            logger.debug('not refreshing resource RDF, but updated binary, so must refresh binary data')
            updated_self = self.repo.get_resource(self.uri)
            self.binary.refresh(updated_self)
    if hasattr(self, '_post_update'):
        self._post_update()
    '\n\t\tIf not updating binary, pass that bool to refresh as refresh_binary flag to avoid touching binary data\n\t\t'
    if auto_refresh:
        self.refresh(refresh_binary=update_binary)
    elif (auto_refresh == None):
        if self.repo.default_auto_refresh:
            self.refresh(refresh_binary=update_binary)
    return True

Method to update resources in repository.  Firing this method computes the difference in the local modified graph and the original one,
    creates an instance of SparqlUpdate and builds a sparql query that represents these differences, and sends this as a PATCH request.

    Note: send PATCH request, regardless of RDF or NonRDF, to [uri]/fcr:metadata

    If the resource is NonRDF (Binary), this also method also updates the binary data.

Args:
    sparql_query_only (bool): If True, returns only the sparql query string and does not perform any actual updates
    auto_refresh (bool): If True, refreshes resource after update. If left None, defaults to repo.default_auto_refresh
    update_binary (bool): If True, and resource is NonRDF, updates binary data as well

Returns:
    (bool)


def get_course_completions(self, enterprise_customer, days):
    return PersistentCourseGrade.objects.filter(passed_timestamp__gt=(datetime.datetime.now() - datetime.timedelta(days=days))).filter(user_id__in=enterprise_customer.enterprise_customer_users.values_list('user_id', flat=True))

Get course completions via PersistentCourseGrade for all the learners of given enterprise customer.

Args:
        enterprise_customer (EnterpriseCustomer): Include Course enrollments for learners
            of this enterprise customer.
        days (int): Include course enrollment of this number of days.

Returns:
        (list): A list of PersistentCourseGrade objects.


def parse_coach_go(infile):
    go_list = []
    with open(infile) as go_file:
        for line in go_file.readlines():
            go_dict = {}
            go_split = line.split()
            go_dict['go_id'] = go_split[0]
            go_dict['c_score'] = go_split[1]
            go_dict['go_term'] = ' '.join(go_split[2:])
            go_list.append(go_dict)
    return go_list

Parse a GO output file from COACH and return a rank-ordered list of GO term predictions

    The columns in all files are: GO terms, Confidence score, Name of GO terms. The files are:

        - GO_MF.dat - GO terms in 'molecular function'
        - GO_BP.dat - GO terms in 'biological process'
        - GO_CC.dat - GO terms in 'cellular component'

Args:
        infile (str): Path to any COACH GO prediction file

Returns:
        Pandas DataFrame: Organized dataframe of results, columns defined below

            - ``go_id``: GO term ID
            - ``go_term``: GO term text
            - ``c_score``: confidence score of the GO prediction


def __get_unused_context(self, parse_result, context):
    tags_keys = set([t['key'] for t in parse_result['tags'] if t['from_context']])
    result_context = [c for c in context if (c['key'] not in tags_keys)]
    return result_context

Used to get unused context from context.  Any keys not in
    parse_result

Args:
        parse_results(list): parsed results used to identify what keys
            in the context are used.
        context(list): this is the context used to match with parsed results
            keys missing in the parsed results are the unused context

Returns:
        list: A list of the unused context results.


def _sample_action_fluent(self, name: str, dtype: tf.DType, size: Sequence[int], constraints: Dict[(str, Constraints)], default_value: tf.Tensor, prob: float) -> tf.Tensor:
    shape = ([self.batch_size] + list(size))
    if (dtype == tf.float32):
        bounds = constraints.get(name)
        if (bounds is None):
            (low, high) = ((- self.MAX_REAL_VALUE), self.MAX_REAL_VALUE)
            dist = tf.distributions.Uniform(low=low, high=high)
            sampled_fluent = dist.sample(shape)
        else:
            (low, high) = bounds
            batch = (((low is not None) and low.batch) or ((high is not None) and high.batch))
            low = (tf.cast(low.tensor, tf.float32) if (low is not None) else (- self.MAX_REAL_VALUE))
            high = (tf.cast(high.tensor, tf.float32) if (high is not None) else self.MAX_REAL_VALUE)
            dist = tf.distributions.Uniform(low=low, high=high)
            if batch:
                sampled_fluent = dist.sample()
            elif (isinstance(low, tf.Tensor) or isinstance(high, tf.Tensor)):
                if ((low + high).shape.as_list() == list(size)):
                    sampled_fluent = dist.sample([self.batch_size])
                else:
                    raise ValueError('bounds are not compatible with action fluent.')
            else:
                sampled_fluent = dist.sample(shape)
    elif (dtype == tf.int32):
        logits = ([1.0] * self.MAX_INT_VALUE)
        dist = tf.distributions.Categorical(logits=logits, dtype=tf.int32)
        sampled_fluent = dist.sample(shape)
    elif (dtype == tf.bool):
        probs = 0.5
        dist = tf.distributions.Bernoulli(probs=probs, dtype=tf.bool)
        sampled_fluent = dist.sample(shape)
    select_default = tf.distributions.Bernoulli(prob, dtype=tf.bool).sample(self.batch_size)
    action_fluent = tf.where(select_default, default_value, sampled_fluent)
    return action_fluent

Samples the action fluent with given `name`, `dtype`, and `size`.

    With probability `prob` it chooses the action fluent `default_value`,
    with probability 1-`prob` it samples the fluent w.r.t. its `constraints`.

Args:
        name (str): The name of the action fluent.
        dtype (tf.DType): The data type of the action fluent.
        size (Sequence[int]): The size and shape of the action fluent.
        constraints (Dict[str, Tuple[Optional[TensorFluent], Optional[TensorFluent]]]): The bounds for each action fluent.
        default_value (tf.Tensor): The default value for the action fluent.
        prob (float): A probability measure.

Returns:
        tf.Tensor: A tensor for sampling the action fluent.


def modify_prefix(channel, new_prefix):
    gui = ui_embed.UI(channel, 'Prefix updated', 'Modis prefix is now `{}`'.format(new_prefix), modulename=modulename)
    return gui

Creates an embed UI containing the prefix modified message

Args:
        channel (discord.Channel): The Discord channel to bind the embed to
        new_prefix (str): The value of the new prefix

Returns:
        embed: The created embed


def list(self, cat, ctr=None, nb_results=None, offset=None):
    path = (LIST_URL + '?c=3&cat={}'.format(requests.utils.quote(cat)))
    if (ctr is not None):
        path += '&ctr={}'.format(requests.utils.quote(ctr))
    if (nb_results is not None):
        path += '&n={}'.format(requests.utils.quote(str(nb_results)))
    if (offset is not None):
        path += '&o={}'.format(requests.utils.quote(str(offset)))
    data = self.executeRequestApi2(path)
    clusters = []
    docs = []
    if (ctr is None):
        for pf in data.preFetch:
            for cluster in pf.response.payload.listResponse.doc:
                clusters.extend(cluster.child)
        return [c.docid for c in clusters]
    else:
        apps = []
        for d in data.payload.listResponse.doc:
            for c in d.child:
                for a in c.child:
                    apps.append(utils.parseProtobufObj(a))
        return apps

List all possible subcategories for a specific category. If
    also a subcategory is provided, list apps from this category.

Args:
        cat (str): category id
        ctr (str): subcategory id
        nb_results (int): if a subcategory is specified, limit number
            of results to this number
        offset (int): if a subcategory is specified, start counting from this
            result

Returns:
        A list of categories. If subcategory is specified, a list of apps in this
        category.


def mtu(self, **kwargs):
    int_type = kwargs.pop('int_type').lower()
    name = kwargs.pop('name')
    mtu = kwargs.pop('mtu')
    callback = kwargs.pop('callback', self._callback)
    int_types = ['gigabitethernet', 'tengigabitethernet', 'fortygigabitethernet', 'hundredgigabitethernet', 'port_channel']
    if (int_type not in int_types):
        raise ValueError('Incorrect int_type value.')
    minimum_mtu = 1522
    maximum_mtu = 9216
    if ((int(mtu) < minimum_mtu) or (int(mtu) > maximum_mtu)):
        raise ValueError('Incorrect mtu value 1522-9216')
    mtu_args = dict(name=name, mtu=mtu)
    if (not pynos.utilities.valid_interface(int_type, name)):
        raise ValueError('`name` must be in the format of x/y/z for physical interfaces or x for port channel.')
    config = getattr(self._interface, ('interface_%s_mtu' % int_type))(**mtu_args)
    return callback(config)

Set interface mtu.

Args:
        int_type (str): Type of interface. (gigabitethernet,
            tengigabitethernet, etc)
        name (str): Name of interface. (1/0/5, 1/0/10, etc)
        mtu (str): Value between 1522 and 9216
        callback (function): A function executed upon completion of the
            method.  The only parameter passed to `callback` will be the
            ``ElementTree`` `config`.

Returns:
        Return value of `callback`.

Raises:
        KeyError: if `int_type`, `name`, or `mtu` is not specified.
        ValueError: if `int_type`, `name`, or `mtu` is invalid.

Example:
        >>> import pynos.device
        >>> switches = ['10.24.39.211', '10.24.39.203']
        >>> auth = ('admin', 'password')
        >>> for switch in switches:
        ...     conn = (switch, '22')
        ...     with pynos.device.Device(conn=conn, auth=auth) as dev:
        ...         output = dev.interface.mtu(mtu='1666',
        ...         int_type='tengigabitethernet', name='225/0/38')
        ...         dev.interface.mtu() # doctest: +IGNORE_EXCEPTION_DETAIL
        Traceback (most recent call last):
        KeyError


def parse_options(files, env_prefix='CONFPY', strict=True):
    return check_for_missing_options(config=set_cli_options(config=set_environment_var_options(config=configuration_from_paths(paths=files, strict=strict), prefix=env_prefix)))

Parse configuration options and return a configuration object.

Args:
        files (iter of str): File paths which identify configuration files.
            These files are processed in order with values in later files
            overwriting values in earlier files.
        env_prefix (str): The static prefix prepended to all options when set
            as environment variables. The default is CONFPY.
        strict (bool): Whether or not to parse the files in strict mode.

Returns:
        confpy.core.config.Configuration: The loaded configuration object.

Raises:
        MissingRequiredOption: If a required option is not defined in any file.
        NamespaceNotRegistered: If a file contains a namespace which is not
            defined.
        OptionNotRegistered: If a file contains an option which is not defined
            but resides under a valid namespace.
        UnrecognizedFileExtension: If there is no loader for a path.


def load_dict_values(self, db_key: str, dict_keys: List[str], hierarchical: bool=False) -> List:
    result = []
    if (not hierarchical):
        _values = self._db.hmget(db_key, *dict_keys)
        result = [ast.literal_eval(_value) for _value in _values]
    else:
        db_keys = self._db.keys(pattern=(db_key + '*'))
        for _db_key in db_keys:
            for name in _db_key.split(':')[1:]:
                if (name in dict_keys):
                    _values = self._load_values(_db_key)
                    result.append(_values)
            _values = self._db.hmget(_db_key, *dict_keys)
            for (i, value) in enumerate(_values):
                try:
                    _values[i] = ast.literal_eval(value)
                except SyntaxError:
                    pass
                except ValueError:
                    pass
            result += [value for value in _values if (value is not None)]
    return result

Load values from a dictionary with the specified dict_keys.

Args:
        db_key (str): Key where the dictionary is stored
        dict_keys (List[str]): Keys within the dictionary to load.
        hierarchical (bool): If True, expect the dictionary to have been
            stored hierarchically. If False, expect the dictionary to have
            been stored flat.

Returns:
        object: The value stored at dict_key in the dictionary stored at
        key


def update_in_hdx(self, **kwargs):
    self._check_load_existing_object('resource', 'id')
    if (self.file_to_upload and ('url' in self.data)):
        del self.data['url']
    self._merge_hdx_update('resource', 'id', self.file_to_upload, **kwargs)

Check if resource exists in HDX and if so, update it

Args:
        **kwargs: See below
        operation (string): Operation to perform eg. patch. Defaults to update.

Returns:
        None


def array(self, size_chunk, start, bytesize):
    with open(self.img, 'rb') as f1:
        f1.seek((self.start_byte + (start * self.bytesize)))
        data = f1.read((size_chunk * self.bytesize))
        Z = np.fromstring(data, dtype=self.dtype, count=size_chunk)
        if (self.grid == 'LOLA'):
            return (Z * float(self.SCALING_FACTOR))
        else:
            return Z

Read part of the binary file

Args:
        size_chunk (int) : Size of the chunk to read
        start (int): Starting byte
        bytesize (int): Ending byte

Returns:
        (np.array): array of the corresponding values


def find_amplitude(chunk):
    return (abs(int((chunk.max() - chunk.min()))) / config.SAMPLE_RANGE)

Calculate the 0-1 amplitude of an ndarray chunk of audio samples.

    Samples in the ndarray chunk are signed int16 values oscillating
    anywhere between -32768 and 32767. Find the amplitude between 0 and 1
    by summing the absolute values of the minimum and maximum, and dividing
    by 32767.

Args:
        chunk (numpy.ndarray): An array of int16 audio samples

Returns:
        float: The amplitude of the sample between 0 and 1.
            Note that this is not a decibel representation of
            the amplitude.


def find_mip(self, direction, mechanism, purview, allow_neg=False):
    alpha_min = float('inf')
    probability = self.probability(direction, mechanism, purview)
    for partition in mip_partitions(mechanism, purview, self.node_labels):
        partitioned_probability = self.partitioned_probability(direction, partition)
        alpha = log2((probability / partitioned_probability))
        if (utils.eq(alpha, 0) or ((alpha < 0) and (not allow_neg))):
            return AcRepertoireIrreducibilityAnalysis(state=self.mechanism_state(direction), direction=direction, mechanism=mechanism, purview=purview, partition=partition, probability=probability, partitioned_probability=partitioned_probability, node_labels=self.node_labels, alpha=0.0)
        if ((abs(alpha_min) - abs(alpha)) > constants.EPSILON):
            alpha_min = alpha
            acria = AcRepertoireIrreducibilityAnalysis(state=self.mechanism_state(direction), direction=direction, mechanism=mechanism, purview=purview, partition=partition, probability=probability, partitioned_probability=partitioned_probability, node_labels=self.node_labels, alpha=alpha_min)
    return acria

Find the ratio minimum information partition for a mechanism
    over a purview.

Args:
        direction (str): |CAUSE| or |EFFECT|
        mechanism (tuple[int]): A mechanism.
        purview (tuple[int]): A purview.

    Keyword Args:
        allow_neg (boolean): If true, ``alpha`` is allowed to be negative.
            Otherwise, negative values of ``alpha`` will be treated as if
            they were 0.

Returns:
        AcRepertoireIrreducibilityAnalysis: The irreducibility analysis for
        the mechanism.


def NewPathSpec(cls, type_indicator, **kwargs):
    if (type_indicator not in cls._path_spec_types):
        raise KeyError('Path specification type: {0:s} not set.'.format(type_indicator))
    if (('parent' in kwargs) and (kwargs['parent'] is None)):
        del kwargs['parent']
    path_spec_type = cls._path_spec_types[type_indicator]
    return path_spec_type(**kwargs)

Creates a new path specification for the specific type indicator.

Args:
        type_indicator (str): type indicator.
        kwargs (dict): keyword arguments depending on the path specification.

Returns:
        PathSpec: path specification.

Raises:
        KeyError: if path specification is not registered.


def get_credentials(credentials=None, client_secret_file=CLIENT_SECRET_FILE, refresh_token=None):
    if credentials:
        if _is_valid_credentials(credentials):
            return credentials
        else:
            print('Invalid credentials supplied. Will generate from default token.')
    token = (refresh_token or DEFAULT_TOKEN)
    dir_name = os.path.dirname(DEFAULT_TOKEN)
    try:
        os.makedirs(dir_name)
    except OSError:
        if (not os.path.isdir(dir_name)):
            raise
    store = file.Storage(token)
    credentials = store.get()
    try:
        import argparse
        flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_known_args()[0]
    except ImportError:
        flags = None
        logr.error('Unable to parse oauth2client args; `pip install argparse`')
    if ((not credentials) or credentials.invalid):
        flow = client.flow_from_clientsecrets(client_secret_file, SCOPES)
        flow.redirect_uri = client.OOB_CALLBACK_URN
        if flags:
            credentials = tools.run_flow(flow, store, flags)
        else:
            credentials = tools.run(flow, store)
        logr.info(('Storing credentials to ' + DEFAULT_TOKEN))
    return credentials

Consistently returns valid credentials object.

    See Also:
        https://developers.google.com/drive/web/quickstart/python

Args:
        client_secret_file (str): path to client secrets file, defaults to .gdrive_private
        refresh_token (str): path to a user provided refresh token that is already
            pre-authenticated
        credentials (`~oauth2client.client.OAuth2Credentials`, optional): handle direct
            input of credentials, which will check credentials for valid type and
            return them

Returns:
        `~oauth2client.client.OAuth2Credentials`: google credentials object


def fit_to_cols(what, indent='', cols=79):
    lines = []
    while what:
        (what, next_line) = split_line(what=what, cols=cols, indent=indent)
        lines.append(next_line)
    return '\n'.join(lines)

Wrap the given text to the columns, prepending the indent to each line.

Args:
        what(str): text to wrap.
        indent(str): indentation to use.
        cols(int): colt to wrap to.

Returns:
        str: Wrapped text


def getDelOps(self, buid):
    return (('prop:del', (buid, self.form.name, self.name, self.storinfo)),)

Get a list of storage operations to delete this property from the buid.

Args:
        buid (bytes): The node buid.

Returns:
        (tuple): The storage operations


def qc_curve_group(self, tests, alias=None):
    keys = [k for (k, v) in self.data.items() if isinstance(v, Curve)]
    if (not keys):
        return {}
    all_tests = tests.get('all', tests.get('All', tests.get('ALL', [])))
    data = {test.__name__: test(self, keys, alias) for test in all_tests}
    results = {}
    for (i, key) in enumerate(keys):
        this = {}
        for (test, result) in data.items():
            this[test] = result[i]
        results[key] = this
    return results

Run tests on a cohort of curves.

Args:
        alias (dict): an alias dictionary, mapping mnemonics to lists of
            mnemonics.

Returns:
        dict.


def coroutine(func):

    def wrapper(*args, **kwargs):
        gen = func(*args, **kwargs)
        val = next(gen)
        if (val != None):
            raise TypeError('Unexpected value from start of coroutine')
        return gen
    wrapper.__name__ = func.__name__
    wrapper.__doc__ = func.__doc__
    return wrapper

Wraps a PEP-342 enhanced generator in a way that avoids boilerplate of the "priming" call to ``next``.

Args:
        func (Callable): The function constructing a generator to decorate.

Returns:
        Callable: The decorated generator.


def parse_conf(self, keys=[]):
    confs = self.app.config.get('WAFFLE_CONFS', {})
    if (not keys):
        keys = confs.keys()
    result = {}
    for key in keys:
        if key.startswith('WAFFLE_'):
            continue
        if (key not in confs.keys()):
            continue
        stored_conf = self.configstore.get(key)
        if (not stored_conf):
            value = confs[key].get('default', '')
            stored_conf = self.configstore.put(key, util.serialize(value))
            self.configstore.commit()
        else:
            value = util.deserialize(stored_conf.get_value())
        result[stored_conf.get_key()] = value
    return result

Parse configuration values from the database.

    The extension must have been previously initialized.

    If a key is not found in the database, it will be created with the
    default value specified.

Args:
        keys (list[str]): list of keys to parse. If the list is empty, then
            all the keys known to the application will be used.

Returns:
        dict of the parsed config values.


def _GetLoadConfigTimestamp(self, pefile_object):
    if (not hasattr(pefile_object, 'DIRECTORY_ENTRY_LOAD_CONFIG')):
        return None
    timestamp = getattr(pefile_object.DIRECTORY_ENTRY_LOAD_CONFIG.struct, 'TimeDateStamp', 0)
    return timestamp

Retrieves the timestamp from the Load Configuration directory.

Args:
        pefile_object (pefile.PE): pefile object.

Returns:
        int: load configuration timestamps or None if there are none present.


def not_implemented(cls, errors=None):
    if cls.expose_status:
        cls.response.content_type = 'application/json'
        cls.response._status_line = '501 Not Implemented'
    return cls(501, None, errors).to_json

Shortcut API for HTTP 501 `Not Implemented` response.

Args:
        errors (list): Response key/value data.

Returns:
        WSResponse Instance.


def rbridge_id(self, **kwargs):
    is_get_config = kwargs.pop('get', False)
    if (not is_get_config):
        rbridge_id = kwargs.pop('rbridge_id')
    else:
        rbridge_id = ''
    callback = kwargs.pop('callback', self._callback)
    rid_args = dict(rbridge_id=rbridge_id)
    rid = getattr(self._rbridge, 'rbridge_id_rbridge_id')
    config = rid(**rid_args)
    if is_get_config:
        return callback(config, handler='get_config')
    return callback(config)

Configures device's rbridge ID. Setting this property will need
    a switch reboot

Args:
        rbridge_id (str): The rbridge ID of the device on which BGP will be
            configured in a VCS fabric.
        get (bool): Get config instead of editing config. (True, False)
        callback (function): A function executed upon completion of the
            method.  The only parameter passed to `callback` will be the
            ``ElementTree`` `config`.

Returns:
        Return value of `callback`.

Raises:
        KeyError: if `rbridge_id` is not specified.

Example:
        >>> import pynos.device
        >>> conn = ('10.24.39.211', '22')
        >>> auth = ('admin', 'password')
        >>> with pynos.device.Device(conn=conn, auth=auth) as dev:
        ...     output = dev.system.rbridge_id(rbridge_id='225')
        ...     output = dev.system.rbridge_id(rbridge_id='225', get=True)
        ...     dev.system.rbridge_id() # doctest: +IGNORE_EXCEPTION_DETAIL
        Traceback (most recent call last):
        KeyError


def compare_profiles(profile1, profile2):
    length = len(profile1)
    profile1 = np.array(list(profile1))
    profile2 = np.array(list(profile2))
    similarity_array = (profile1 == profile2)
    matches = np.sum(similarity_array)
    similarity_ratio = (matches / length)
    return similarity_ratio

Given two profiles, determine the ratio of similarity, i.e.
    the hamming distance between the strings.

Args:
        profile1/2 (str): profile string

Returns:
        similarity_ratio (float): the ratio of similiarity (0-1)


def set_data(self, data):
    for name in self._fields:
        setattr(self, name, data.get(name))
    return self

Fills form with data

Args:
        data (dict): Data to assign form fields.

Returns:
        Self. Form object.


def unlock_kinetis(jlink):
    if (not jlink.connected()):
        raise ValueError('No target to unlock.')
    method = UNLOCK_METHODS.get(jlink.tif, None)
    if (method is None):
        raise NotImplementedError('Unsupported target interface for unlock.')
    return method(jlink)

Unlock for Freescale Kinetis K40 or K60 device.

Args:
        jlink (JLink): an instance of a J-Link that is connected to a target.

Returns:
        ``True`` if the device was successfully unlocked, otherwise ``False``.

Raises:
        ValueError: if the J-Link is not connected to a target.


def create_parser(default_name: str) -> argparse.ArgumentParser:
    argparser = argparse.ArgumentParser(fromfile_prefix_chars='@')
    argparser.add_argument('-H', '--host', help='Host to which the app binds. [%(default)s]', default='0.0.0.0')
    argparser.add_argument('-p', '--port', help='Port to which the app binds. [%(default)s]', default=5000, type=int)
    argparser.add_argument('-o', '--output', help='Logging output. [%(default)s]')
    argparser.add_argument('-n', '--name', help='Service name. This will be used as prefix for all endpoints. [%(default)s]', default=default_name)
    argparser.add_argument('--debug', help='Run the app in debug mode. [%(default)s]', action='store_true')
    argparser.add_argument('--eventbus-host', help='Hostname at which the eventbus can be reached [%(default)s]', default='eventbus')
    argparser.add_argument('--eventbus-port', help='Port at which the eventbus can be reached [%(default)s]', default=5672, type=int)
    return argparser

Creates the default brewblox_service ArgumentParser.
    Service-agnostic arguments are added.

    The parser allows calling code to add additional arguments before using it in create_app()

Args:
        default_name (str):
            default value for the --name commandline argument.

Returns:
        argparse.ArgumentParser: a Python ArgumentParser with defaults set.


def alloc_data(self, value):
    if isinstance(value, six.binary_type):
        return self._alloc_data(value)
    elif isinstance(value, six.text_type):
        return self._alloc_data((value.encode('utf-8') + b'\x00'))
    else:
        raise TypeError(('No idea how to encode %s' % repr(value)))

Allocate a piece of data that will be included in the shellcode body.

Args:
        value(...): The value to add to the shellcode. Can be bytes or
            string type.

Returns:
        ~pwnypack.types.Offset: The offset used to address the data.


def _is_variant(self, gemini_variant, ind_objs):
    indexes = (ind.ind_index for ind in ind_objs)
    for index in indexes:
        gt_call = gemini_variant['gt_types'][index]
        if ((gt_call == 1) or (gt_call == 3)):
            return True
    return False

Check if the variant is a variation in any of the individuals

Args:
        gemini_variant (GeminiQueryRow): The gemini variant
        ind_objs (list(puzzle.models.individual)): A list of individuals to check

Returns:
        bool : If any of the individuals has the variant


def op_nodes(self, op=None):
    nodes = []
    for node in self._multi_graph.nodes():
        if (node.type == 'op'):
            if ((op is None) or isinstance(node.op, op)):
                nodes.append(node)
    return nodes

Get the list of "op" nodes in the dag.

Args:
        op (Type): Instruction subclass op nodes to return. if op=None, return
            all op nodes.

Returns:
        list[DAGNode]: the list of node ids containing the given op.


def instantiate(self, substitutions):
    param_dict = self.substitute_params(substitutions)
    (pkg, ident) = self.name.rsplit('.', 1)
    pkg = ('malcolm.modules.%s' % pkg)
    try:
        ob = importlib.import_module(pkg)
    except ImportError as e:
        raise_with_traceback(ImportError(('\n%s:%d:\n%s' % (self.filename, self.lineno, e))))
    try:
        ob = getattr(ob, ident)
    except AttributeError:
        raise_with_traceback(ImportError(('\n%s:%d:\nPackage %r has no ident %r' % (self.filename, self.lineno, pkg, ident))))
    try:
        model = MethodModel.from_callable(ob, returns=False)
        args = model.validate(param_dict)
        ret = ob(**args)
    except Exception as e:
        sourcefile = inspect.getsourcefile(ob)
        lineno = inspect.getsourcelines(ob)[1]
        raise_with_traceback(YamlError(('\n%s:%d:\n%s:%d:\n%s' % (self.filename, self.lineno, sourcefile, lineno, e))))
    else:
        return ret

Keep recursing down from base using dotted name, then call it with
    self.params and args

Args:
        substitutions (dict): Substitutions to make to self.param_dict

Returns:
        The found object called with (*args, map_from_d)

    E.g. if ob is malcolm.parts, and name is "ca.CADoublePart", then the
    object will be malcolm.parts.ca.CADoublePart


def get_entry_by_material_id(self, material_id, compatible_only=True, inc_structure=None, property_data=None, conventional_unit_cell=False):
    data = self.get_entries(material_id, compatible_only=compatible_only, inc_structure=inc_structure, property_data=property_data, conventional_unit_cell=conventional_unit_cell)
    return data[0]

Get a ComputedEntry corresponding to a material_id.

Args:
        material_id (str): Materials Project material_id (a string,
            e.g., mp-1234).
        compatible_only (bool): Whether to return only "compatible"
            entries. Compatible entries are entries that have been
            processed using the MaterialsProjectCompatibility class,
            which performs adjustments to allow mixing of GGA and GGA+U
            calculations for more accurate phase diagrams and reaction
            energies.
        inc_structure (str): If None, entries returned are
            ComputedEntries. If inc_structure="final",
            ComputedStructureEntries with final structures are returned.
            Otherwise, ComputedStructureEntries with initial structures
            are returned.
        property_data (list): Specify additional properties to include in
            entry.data. If None, no data. Should be a subset of
            supported_properties.
        conventional_unit_cell (bool): Whether to get the standard
            conventional unit cell

Returns:
        ComputedEntry or ComputedStructureEntry object.


def execute_request(self, url, http_method, query_params, post_data):
    response = requests.request(http_method, url, params=query_params, auth=self._auth, json=post_data, headers={'User-Agent': USER_AGENT})
    if (isinstance(self._output_generator, str) and (self._output_generator.lower() == 'json')):
        return response.json()
    elif (self._output_generator is not None):
        return self._output_generator.process_response(response)
    else:
        return response

Makes a request to the specified url endpoint with the
    specified http method, params and post data.

Args:
        url (string): The url to the API without query params.
                    Example: "https://api.housecanary.com/v2/property/value"
        http_method (string): The http method to use for the request.
        query_params (dict): Dictionary of query params to add to the request.
        post_data: Json post data to send in the body of the request.

Returns:
        The result of calling this instance's OutputGenerator process_response method
        on the requests.Response object.
        If no OutputGenerator is specified for this instance, returns the requests.Response.


def _cursor_pb(cursor_pair):
    if (cursor_pair is not None):
        (data, before) = cursor_pair
        value_pbs = [_helpers.encode_value(value) for value in data]
        return query_pb2.Cursor(values=value_pbs, before=before)

Convert a cursor pair to a protobuf.

    If ``cursor_pair`` is :data:`None`, just returns :data:`None`.

Args:
        cursor_pair (Optional[Tuple[list, bool]]): Two-tuple of

            * a list of field values.
            * a ``before`` flag

Returns:
        Optional[google.cloud.firestore_v1beta1.types.Cursor]: A
        protobuf cursor corresponding to the values.


def topics(self, exclude_internal_topics=True):
    topics = set(self._partitions.keys())
    if exclude_internal_topics:
        return (topics - self.internal_topics)
    else:
        return topics

Get set of known topics.

Args:
        exclude_internal_topics (bool): Whether records from internal topics
            (such as offsets) should be exposed to the consumer. If set to
            True the only way to receive records from an internal topic is
            subscribing to it. Default True

Returns:
        set: {topic (str), ...}


def copy_file_if_newer(src_fs, src_path, dst_fs, dst_path):
    with manage_fs(src_fs, writeable=False) as _src_fs:
        with manage_fs(dst_fs, create=True) as _dst_fs:
            if (_src_fs is _dst_fs):
                if _source_is_newer(_src_fs, src_path, _dst_fs, dst_path):
                    _src_fs.copy(src_path, dst_path, overwrite=True)
                    return True
                else:
                    return False
            else:
                with _src_fs.lock(), _dst_fs.lock():
                    if _source_is_newer(_src_fs, src_path, _dst_fs, dst_path):
                        copy_file_internal(_src_fs, src_path, _dst_fs, dst_path)
                        return True
                    else:
                        return False

Copy a file from one filesystem to another, checking times.

    If the destination exists, and is a file, it will be first truncated.
    If both source and destination files exist, the copy is executed only
    if the source file is newer than the destination file. In case
    modification times of source or destination files are not available,
    copy is always executed.

Args:
        src_fs (FS or str): Source filesystem (instance or URL).
        src_path (str): Path to a file on the source filesystem.
        dst_fs (FS or str): Destination filesystem (instance or URL).
        dst_path (str): Path to a file on the destination filesystem.

Returns:
        bool: `True` if the file copy was executed, `False` otherwise.


def match_rules(tree, rules, fun=None, multi=False):
    if multi:
        context = match_rules_context_multi(tree, rules)
    else:
        context = match_rules_context(tree, rules)
        if (not context):
            return None
    if fun:
        args = fun.__code__.co_varnames
        if multi:
            res = []
            for c in context:
                action_context = {}
                for arg in args:
                    if (arg in c):
                        action_context[arg] = c[arg]
                res.append(fun(**action_context))
            return res
        else:
            action_context = {}
            for arg in args:
                if (arg in context):
                    action_context[arg] = context[arg]
            return fun(**action_context)
    else:
        return context

Matches a Tree structure with the given query rules.

    Query rules are represented as a dictionary of template to action.
    Action is either a function, or a dictionary of subtemplate parameter to rules::

        rules = { 'template' : { 'key': rules } }
            | { 'template' : {} }

Args:
        tree (Tree): Parsed tree structure
        rules (dict): A dictionary of query rules
        fun (function): Function to call with context (set to None if you want to return context)
        multi (Bool): If True, returns all matched contexts, else returns first matched context

Returns:
        Contexts from matched rules


def greedy_coloring(adj):
    coloring = {}
    colors = {}
    possible_colors = {n: set(range(len(adj))) for n in adj}
    while possible_colors:
        n = min(possible_colors, key=(lambda n: len(possible_colors[n])))
        color = min(possible_colors[n])
        coloring[n] = color
        if (color not in colors):
            colors[color] = {n}
        else:
            colors[color].add(n)
        for neighbor in adj[n]:
            if ((neighbor in possible_colors) and (color in possible_colors[neighbor])):
                possible_colors[neighbor].remove(color)
        del possible_colors[n]
    return (coloring, colors)

Determines a vertex coloring.

Args:
        adj (dict): The edge structure of the graph to be colored.
            `adj` should be of the form {node: neighbors, ...} where
            neighbors is a set.

Returns:
        dict: the coloring {node: color, ...}
        dict: the colors {color: [node, ...], ...}

Note:
        This is a greedy heuristic: the resulting coloring is not
        necessarily minimal.


def _instantiate_data_type(self, data_type_class, data_type_args, loc):
    assert issubclass(data_type_class, DataType), ('Expected stone.data_type.DataType, got %r' % data_type_class)
    argspec = inspect.getargspec(data_type_class.__init__)
    argspec.args.remove('self')
    num_args = len(argspec.args)
    num_defaults = len((argspec.defaults or ()))
    (pos_args, kw_args) = data_type_args
    if ((num_args - num_defaults) > len(pos_args)):
        raise InvalidSpec(('Missing positional argument %s for %s type' % (quote(argspec.args[len(pos_args)]), quote(data_type_class.__name__))), *loc)
    elif ((num_args - num_defaults) < len(pos_args)):
        raise InvalidSpec(('Too many positional arguments for %s type' % quote(data_type_class.__name__)), *loc)
    args = {}
    for (i, key) in enumerate(argspec.args):
        args[key] = (i >= (num_args - num_defaults))
    for key in kw_args:
        if (key not in args):
            raise InvalidSpec(('Unknown argument %s to %s type.' % (quote(key), quote(data_type_class.__name__))), *loc)
        if (not args[key]):
            raise InvalidSpec(('Positional argument %s cannot be specified as a keyword argument.' % quote(key)), *loc)
        del args[key]
    try:
        return data_type_class(*pos_args, **kw_args)
    except ParameterError as e:
        raise InvalidSpec(('Bad argument to %s type: %s' % (quote(data_type_class.__name__), e.args[0])), *loc)

Responsible for instantiating a data type with additional attributes.
    This method ensures that the specified attributes are valid.

Args:
        data_type_class (DataType): The class to instantiate.
        data_type_attrs (dict): A map from str -> values of attributes.
            These will be passed into the constructor of data_type_class
            as keyword arguments.

Returns:
        stone.data_type.DataType: A parameterized instance.


def show(self, frame):
    if (len(frame.shape) != 3):
        raise ValueError('frame should have shape with only 3 dimensions')
    if (not self.is_open):
        self.open()
    self._window.clear()
    self._window.switch_to()
    self._window.dispatch_events()
    image = ImageData(frame.shape[1], frame.shape[0], 'RGB', frame.tobytes(), pitch=(frame.shape[1] * (- 3)))
    image.blit(0, 0, width=self._window.width, height=self._window.height)
    self._window.flip()

Show an array of pixels on the window.

Args:
        frame (numpy.ndarray): the frame to show on the window

Returns:
        None


def render_policy_template(account_number='', app='coreforrest', env='dev', group='forrest', items=None, pipeline_settings=None, region='us-east-1', service=''):
    statements = []
    rendered_service_policy = get_template('infrastructure/iam/{0}.json.j2'.format(service), account_number=account_number, app=app, env=env, group=group, region=region, items=items, settings=pipeline_settings)
    try:
        statement_block = json.loads(rendered_service_policy)
        statements.append(statement_block)
    except ValueError:
        LOG.debug('Need to make %s template into list.', service)
        statements = json.loads('[{0}]'.format(rendered_service_policy))
    LOG.debug('Rendered IAM Policy statements: %s', statements)
    return statements

Render IAM Policy template.

    To support multiple statement blocks, JSON objects can be separated by a
    comma. This function attempts to turn any invalid JSON into a valid list
    based on this comma separated assumption.

Args:
        account_number (str): AWS Account number.
        app (str): Name of Spinnaker Application.
        env (str): Environment/Account in AWS
        group (str):A Application group/namespace
        items (list): Resource names used to create a Policy per Resource.
        region (str): AWS region.
        pipeline_settings (dict): Settings from *pipeline.json*.
        service (str): Name of cloud service to find matching IAM Policy
            template.

Returns:
        list: IAM Policy :obj:`dict` statements for the given service.


def createEditor(self, parent, option, index):
    combo = QtGui.QComboBox(parent)
    combo.addItems(SupportedDtypes.names())
    combo.currentIndexChanged.connect(self.currentIndexChanged)
    return combo

Creates an Editor Widget for the given index.

    Enables the user to manipulate the displayed data in place. An editor
    is created, which performs the change.
    The widget used will be a `QComboBox` with all available datatypes in the
    `pandas` project.

Args:
        parent (QtCore.QWidget): Defines the parent for the created editor.
        option (QtGui.QStyleOptionViewItem): contains all the information
            that QStyle functions need to draw the items.
        index (QtCore.QModelIndex): The item/index which shall be edited.

Returns:
        QtGui.QWidget: he widget used to edit the item specified by index
            for editing.


def nmf_ensemble(data, k, n_runs=10, W_list=[], **nmf_params):
    nmf = NMF(k)
    if (len(W_list) == 0):
        W_list = []
        for i in range(n_runs):
            W = nmf.fit_transform(data)
            W_list.append(W)
    W_stacked = np.hstack(W_list)
    nmf_w = nmf.fit_transform(W_stacked)
    nmf_h = nmf.components_
    H_new = data.T.dot(nmf_w).T
    nmf2 = NMF(k, init='custom')
    nmf_w = nmf2.fit_transform(data, W=nmf_w, H=H_new)
    H_new = nmf2.components_
    return (nmf_w, H_new)

Runs an ensemble method on the list of NMF W matrices...

Args:
        data: genes x cells array (should be log + cell-normalized)
        k: number of classes
        n_runs (optional): number of random initializations of state estimation
        M_list (optional): list of M arrays from state estimation
        se_params (optional): optional poisson_estimate_state params

Returns:
        W_new
        H_new


def update_ports(self, ports, id_or_uri, timeout=(- 1)):
    resources = merge_default_values(ports, {'type': 'port'})
    uri = (self._client.build_uri(id_or_uri) + '/update-ports')
    return self._client.update(resources, uri, timeout)

Updates the interconnect ports.

Args:
        id_or_uri: Can be either the interconnect id or the interconnect uri.
        ports (list): Ports to update.
        timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
            in OneView; it just stops waiting for its completion.

Returns:
        dict: The interconnect.


def map_seqprop_resnums_to_seqprop_resnums(self, resnums, seqprop1, seqprop2):
    resnums = ssbio.utils.force_list(resnums)
    alignment = self._get_seqprop_to_seqprop_alignment(seqprop1=seqprop1, seqprop2=seqprop2)
    mapped = ssbio.protein.sequence.utils.alignment.map_resnum_a_to_resnum_b(resnums=resnums, a_aln=alignment[0], b_aln=alignment[1])
    return mapped

Map a residue number in any SeqProp to another SeqProp using the pairwise alignment information.

Args:
        resnums (int, list): Residue numbers in seqprop1
        seqprop1 (SeqProp): SeqProp object the resnums match to
        seqprop2 (SeqProp): SeqProp object you want to map the resnums to

Returns:
        dict: Mapping of seqprop1 residue numbers to seqprop2 residue numbers. If mappings don't exist in this
        dictionary, that means the residue number cannot be mapped according to alignment!


def http_list(self, path, query_data={}, as_list=None, **kwargs):
    as_list = (True if (as_list is None) else as_list)
    get_all = kwargs.pop('all', False)
    url = self._build_url(path)
    if (get_all is True):
        return list(GitlabList(self, url, query_data, **kwargs))
    if (('page' in kwargs) or (as_list is True)):
        return list(GitlabList(self, url, query_data, get_next=False, **kwargs))
    return GitlabList(self, url, query_data, **kwargs)

Make a GET request to the Gitlab server for list-oriented queries.

Args:
        path (str): Path or full URL to query ('/projects' or
                    'http://whatever/v4/api/projecs')
        query_data (dict): Data to send as query parameters
        **kwargs: Extra options to send to the server (e.g. sudo, page,
                per_page)

Returns:
        list: A list of the objects returned by the server. If `as_list` is
        False and no pagination-related arguments (`page`, `per_page`,
        `all`) are defined then a GitlabList object (generator) is returned
        instead. This object will make API calls when needed to fetch the
        next items from the server.

Raises:
        GitlabHttpError: When the return code is not 2xx
        GitlabParsingError: If the json data could not be parsed


def quaternion_from_axis_rotation(angle, axis):
    out = np.zeros(4, dtype=float)
    if (axis == 'x'):
        out[1] = 1
    elif (axis == 'y'):
        out[2] = 1
    elif (axis == 'z'):
        out[3] = 1
    else:
        raise ValueError('Invalid axis input.')
    out *= math.sin((angle / 2.0))
    out[0] = math.cos((angle / 2.0))
    return Quaternion(out)

Return quaternion for rotation about given axis.

Args:
        angle (float): Angle in radians.
        axis (str): Axis for rotation

Returns:
        Quaternion: Quaternion for axis rotation.

Raises:
        ValueError: Invalid input axis.


def _GetVisitSource(self, visit_identifier, cache, database):
    sync_cache_results = cache.GetResults('sync')
    if (not sync_cache_results):
        result_set = database.Query(self._SYNC_CACHE_QUERY)
        cache.CacheQueryResults(result_set, 'sync', 'id', ('source',))
        sync_cache_results = cache.GetResults('sync')
    if (sync_cache_results and visit_identifier):
        results = sync_cache_results.get(visit_identifier, None)
        if results:
            return results[0]
    return None

Retrieves a visit source type based on the identifier.

Args:
        visit_identifier (str): identifier from the visits table for the
        particular record.
        cache (SQLiteCache): cache which contains cached results from querying
        the visit_source table.
        database (SQLiteDatabase): database.

Returns:
        int: visit source type or None if no visit source type was found for
        the identifier.


def parse(self, text, layers=None):
    params = {'text': text, 'key': self.key}
    if (layers is not None):
        if isinstance(layers, six.string_types):
            params['layers'] = layers
        elif isinstance(layers, collections.Iterable):
            params['layers'] = ','.join(layers)
    req = requests.get(self.NLU_URL, params=params)
    return req.json()

Parsing passed text to json.

Args:
        text: Text to parse.
        layers (optional): Special fields. Only one string
            or iterable object (e.g "Data", ("Data", "Fio")).
            Only these fields will be returned.

Returns:
        The parsed text into a json object.


def get_score(self, error=None):
    if (error is not None):
        self.error = error
    if (self.error >= 0):
        return (1 / (self.error + 1))
    else:
        return (1 + abs(self.error))

Calculate bee's fitness score given a value returned by the fitness
    function

Args:
        error (float): value returned by the fitness function

Returns:
        float: derived fitness score


def _FormatTag(self, event):
    tag = getattr(event, 'tag', None)
    if (not tag):
        return '-'
    return ' '.join(tag.labels)

Formats the event tag.

Args:
        event (EventObject): event.

Returns:
        str: event tag field.


def resolve_mode(self, name):
    if (name not in settings.CODEMIRROR_MODES):
        msg = "Given config name '{}' does not exists in 'settings.CODEMIRROR_MODES'."
        raise UnknowModeError(msg.format(name))
    return settings.CODEMIRROR_MODES.get(name)

From given mode name, return mode file path from
    ``settings.CODEMIRROR_MODES`` map.

Args:
        name (string): Mode name.

Raises:
        KeyError: When given name does not exist in
            ``settings.CODEMIRROR_MODES``.

Returns:
        string: Mode file path.


def lines_from_file(path, as_interned=False, encoding=None):
    lines = None
    with io.open(path, encoding=encoding) as f:
        if as_interned:
            lines = [sys.intern(line) for line in f.read().splitlines()]
        else:
            lines = f.read().splitlines()
    return lines

Create a list of file lines from a given filepath.

Args:
        path (str): File path
        as_interned (bool): List of "interned" strings (default False)

Returns:
        strings (list): File line list


def normal_mean(data, variance):
    if (not isinstance(data, np.ndarray)):
        data = np.array(data)
    i_variance_2 = (1 / (variance ** 2))
    cmm = [0.0]
    cmm.extend(np.cumsum(data))
    cmm2 = [0.0]
    cmm2.extend(np.cumsum(np.abs(data)))

    def cost(start, end):
        ' Cost function for normal distribution with variable mean\n\n        Args:\n            start (int): start index\n            end (int): end index\n        Returns:\n            float: Cost, from start to end\n        '
        cmm2_diff = (cmm2[end] - cmm2[start])
        cmm_diff = pow((cmm[end] - cmm[start]), 2)
        i_diff = (end - start)
        diff = (cmm2_diff - cmm_diff)
        return ((diff / i_diff) * i_variance_2)
    return cost

Creates a segment cost function for a time series with a
    Normal distribution with changing mean

Args:
    data (:obj:`list` of float): 1D time series data
    variance (float): variance

Returns:
    function: Function with signature
        (int, int) -> float
        where the first arg is the starting index, and the second
        is the last arg. Returns the cost of that segment


def by_issn(issn):
    old_url = aleph.ALEPH_URL
    aleph.ALEPH_URL = NTK_ALEPH_URL
    records = aleph.getISSNsXML(issn, base='STK02')
    aleph.ALEPH_URL = old_url
    for record in records:
        marc = MARCXMLRecord(record)
        additional_info = {'222': marc.get('222', None), 'PER': marc.get('PER', None), '776': marc.get('776', None), '008': marc.get('008', None), 'alt_end_date': ''}
        additional_info = {key: val for (key, val) in additional_info.iteritems() if val}
        alt_end_date = None
        alt_creation_date = None
        if additional_info['008']:
            alt_creation_date = additional_info['008'][7:11]
            alt_end_date = additional_info['008'][11:15]
            if (alt_end_date in ['9999', '****']):
                alt_creation_date += '-'
                alt_end_date = None
            additional_info['alt_end_date'] = alt_end_date
        author = Author.parse_author(marc)
        model = Model(url=_first_or_none(marc.get('856u')), conspect=_first_or_none(marc.get('072a')), annotation_tags=_first_or_none(marc.get('520a')), periodicity=_first_or_none(marc.get('310a')), title_tags=_first_or_none(marc.get('222a')), subtitle_tags=_first_or_none(marc.get('245b')), place_tags=remove_hairs((_first_or_none(marc.get('260a')) or '')), author_tags=(author._asdict() if author else None), publisher_tags=remove_hairs(((_first_or_none(marc.get('260b')) or _first_or_none(marc.get('264b')) or ''),), ', '), creation_dates=_first_or_none(marc.get('260c', [alt_creation_date])), lang_tags=_first_or_none(marc.get('040b')), keyword_tags=marc.get('650a07'), source_info=_first_or_none(marc.get('500a')), original_xml=record, additional_info=additional_info)
        (yield _add_source(model))

Query aleph for records with given `issn`. The lookup is directed to the
    NTK's Aleph.

Args:
        issn (str): ISSN of the periodical.

Returns:
        obj: :class:`Model` instances for each record.


def end_day_to_datetime(end_day, config):
    day_start_time = config['day_start']
    day_end_time = get_day_end(config)
    if (day_start_time == datetime.time(0, 0, 0)):
        end = datetime.datetime.combine(end_day, day_end_time)
    else:
        end = (datetime.datetime.combine(end_day, day_end_time) + datetime.timedelta(days=1))
    return end

Convert a given end day to its proper datetime.

    This is non trivial because of variable ``day_start``. We want to make sure
    that even if an 'end day' is specified the actual point in time may reach into the following
    day.

Args:
        end (datetime.date): Raw end date that is to be adjusted.
        config: Controller config containing information on when a workday starts.

Returns:
        datetime.datetime: The endday as a adjusted datetime object.

Example:
        Given a ``day_start`` of ``5:30`` and end date of ``2015-04-01`` we actually want to
        consider even points in time up to ``2015-04-02 5:29``. That is to represent that a
        *work day*
        does not match *calendar days*.

Note:
        An alternative implementation for the similar problem in legacy hamster:
            ``hamster.storage.db.Storage.__get_todays_facts``.


def from_string(species_string: str):
    m = re.search('([A-Z][a-z]*)([0-9.]*)([+\\-]*)(.*)', species_string)
    if m:
        sym = m.group(1)
        if ((m.group(2) == '') and (m.group(3) == '')):
            oxi = 0
        else:
            oxi = (1 if (m.group(2) == '') else float(m.group(2)))
            oxi = ((- oxi) if (m.group(3) == '-') else oxi)
        properties = None
        if m.group(4):
            toks = m.group(4).split('=')
            properties = {toks[0]: float(toks[1])}
        return DummySpecie(sym, oxi, properties)
    raise ValueError('Invalid DummySpecies String')

Returns a Dummy from a string representation.

Args:
        species_string (str): A string representation of a dummy
            species, e.g., "X2+", "X3+".

Returns:
        A DummySpecie object.

Raises:
        ValueError if species_string cannot be intepreted.


def is_github_task(task):
    return any(((task.get('schedulerId') == 'taskcluster-github'), task.get('extra', {}).get('tasks_for', '').startswith('github-'), is_github_url(task.get('metadata', {}).get('source', ''))))

Determine if a task is related to GitHub.

    This function currently looks into the ``schedulerId``, ``extra.tasks_for``, and
    ``metadata.source``.

Args:
        task (dict): the task definition to check.

Returns:
        bool: True if a piece of data refers to GitHub


def payment(self, origin, destination, amount):
    if (type(amount) != Decimal):
        amount = Decimal(amount)
    if (amount <= 0):
        raise Exception('Amount must be a positive number')
    all_addresses = []
    accounts = self.listaccounts()
    if (origin in accounts):
        if (destination in accounts):
            with self.openwallet():
                result = self.move(origin, destination, amount)
            return self.record_tx(origin, None, amount, result, destination)
        for account in accounts:
            addresses = self.getaddressesbyaccount(account)
            if (destination in addresses):
                with self.openwallet():
                    result = self.move(origin, account, amount)
                return self.record_tx(origin, destination, amount, result, account)
        else:
            with self.openwallet():
                txhash = self.sendfrom(origin, destination, amount)
            return self.record_tx(origin, destination, amount, txhash)

Convenience method for sending Bitcoins.

    Send coins from origin to destination. Calls record_tx to log the
    transaction to database.  Uses free, instant "move" transfers
    if addresses are both local (in the same wallet), and standard
    "sendfrom" transactions otherwise.

    The sender is required to be specified by user_id (account label);
    however, the recipient can be specified either by Bitcoin address
    (anyone) or user_id (if the user is local).

    Payment tries sending Bitcoins in this order:
        1. "move" from account to account (local)
        2. "move" from account to address (local)
        3. "sendfrom" account to address (broadcast)

Args:
        origin (str): user_id of the sender
        destination (str): coin address or user_id of the recipient
        amount (str, Decimal, number): amount to send

Returns:
        bool: True if successful, False otherwise


def join(self, *args, **kwargs):
    super(ThreadReturn, self).join(*args, **kwargs)
    return self._return

Joins the thread.

Args:
        self (ThreadReturn): the ``ThreadReturn`` instance
        args: optional list of arguments
        kwargs: optional key-word arguments

Returns:
        The return value of the exited thread.


def create_symmetric_key(self, algorithm, length):
    if (algorithm not in self._symmetric_key_algorithms.keys()):
        raise exceptions.InvalidField('The cryptographic algorithm {0} is not a supported symmetric key algorithm.'.format(algorithm))
    cryptography_algorithm = self._symmetric_key_algorithms.get(algorithm)
    if (length not in cryptography_algorithm.key_sizes):
        raise exceptions.InvalidField('The cryptographic length ({0}) is not valid for the cryptographic algorithm ({1}).'.format(length, algorithm.name))
    self.logger.info('Generating a {0} symmetric key with length: {1}'.format(algorithm.name, length))
    key_bytes = os.urandom((length // 8))
    try:
        cryptography_algorithm(key_bytes)
    except Exception as e:
        self.logger.exception(e)
        raise exceptions.CryptographicFailure('Invalid bytes for the provided cryptographic algorithm.')
    return {'value': key_bytes, 'format': enums.KeyFormatType.RAW}

Create a symmetric key.

Args:
        algorithm(CryptographicAlgorithm): An enumeration specifying the
            algorithm for which the created key will be compliant.
        length(int): The length of the key to be created. This value must
            be compliant with the constraints of the provided algorithm.

Returns:
        dict: A dictionary containing the key data, with the following
            key/value fields:
            * value - the bytes of the key
            * format - a KeyFormatType enumeration for the bytes format

Raises:
        InvalidField: Raised when the algorithm is unsupported or the
            length is incompatible with the algorithm.
        CryptographicFailure: Raised when the key generation process
            fails.

Example:
        >>> engine = CryptographyEngine()
        >>> key = engine.create_symmetric_key(
        ...     CryptographicAlgorithm.AES, 256)


def is_allowed(self, filepath, excludes=[]):
    if os.path.isabs(filepath):
        raise FinderException("'Finder.is_allowed()' only accept relative filepath")
    if excludes:
        for pattern in excludes:
            if fnmatch.fnmatch(filepath, pattern):
                return False
    return True

Check from exclude patterns if a relative filepath is allowed

Args:
        filepath (str): A relative file path. (exclude patterns are
            allways based from the source directory).

    Keyword Arguments:
        excludes (list): A list of excluding (glob) patterns. If filepath
            matchs one of patterns, filepath is not allowed.

Raises:
        boussole.exception.FinderException: If given filepath is absolute.

Returns:
        str: Filepath with new extension.


def get_enrollments(self, course_id=None, usernames=None):
    params = {}
    if (course_id is not None):
        params['course_id'] = course_id
    if ((usernames is not None) and isinstance(usernames, list)):
        params['username'] = ','.join(usernames)
    done = False
    while (not done):
        (enrollments, next_cursor) = self._get_enrollments_list_page(params)
        for enrollment in enrollments:
            (yield Enrollment(enrollment))
        if next_cursor:
            params['cursor'] = next_cursor
        else:
            done = True

List all course enrollments.

Args:
        course_id (str, optional): If used enrollments will be filtered to the specified
            course id.
        usernames (list, optional): List of usernames to filter enrollments.

Note:
        - This method returns an iterator to avoid going through the entire pagination at once.
        - The :class:`Enrollments` instance returned for each generated item will not have any
            course details.

Example:
        Get all enrollments for a specific course id
        >>> api = EdxApi({'access_token': 'token'}, 'http://base_url')
        >>> enrollments = api.enrollments.get_enrollments(course_id='course_id')
        >>> for enrollment in enrollments:
                do_something(enrollment)

        Get all enrollments for a set of usernames
        >>> api = EdxApi({'access_token': 'token'}, 'http://base_url')
        >>> enrollments = api.enrollments.get_enrollments(usernames=['user1', 'user2'])
        >>> for enrollment in enrollments:
                do_something(enrollment)

Returns:
        Generator with an instance of :class:`Enrollments` for each item.


def pep8_check(files):
    files = fs.wrap_paths(files)
    cfg_path = conf.get_path('lint.pep8_cfg', 'ops/tools/pep8.ini')
    pep8_cmd = 'pep8 --config {} {}'.format(cfg_path, files)
    return shell.run(pep8_cmd, exit_on_error=False).return_code

Run code checks using pep8.

Args:
        files (list[str]):
            A list of files to check

Returns:
        bool: **True** if all files passed the checks, **False** otherwise.

    pep8 tool is **very** fast. Especially compared to pylint and the bigger the
    code base the bigger the difference. If you want to reduce check times you
    might disable all pep8 checks in pylint and use pep8 for that. This way you
    use pylint only for the more advanced checks (the number of checks enabled
    in pylint will make a visible difference in it's run times).


def from_authorized_user_file(cls, filename, scopes=None):
    with io.open(filename, 'r', encoding='utf-8') as json_file:
        data = json.load(json_file)
        return cls.from_authorized_user_info(data, scopes)

Creates a Credentials instance from an authorized user json file.

Args:
        filename (str): The path to the authorized user json file.
        scopes (Sequence[str]): Optional list of scopes to include in the
            credentials.

Returns:
        google.oauth2.credentials.Credentials: The constructed
            credentials.

Raises:
        ValueError: If the file is not in the expected format.


def VerifyStructure(self, parser_mediator, line):
    try:
        structure = self._LINE.parseString(line)
    except pyparsing.ParseException:
        logger.debug('Not a SkyDrive old log file')
        return False
    (day_of_month, month, year, hours, minutes, seconds, milliseconds) = structure.date_time
    time_elements_tuple = (year, month, day_of_month, hours, minutes, seconds, milliseconds)
    try:
        dfdatetime_time_elements.TimeElementsInMilliseconds(time_elements_tuple=time_elements_tuple)
    except ValueError:
        logger.debug('Not a SkyDrive old log file, invalid date and time: {0!s}'.format(structure.date_time))
        return False
    return True

Verify that this file is a SkyDrive old log file.

Args:
        parser_mediator (ParserMediator): mediates interactions between parsers
        and other components, such as storage and dfvfs.
        line (str): line from a text file.

Returns:
        bool: True if the line is in the expected format, False if not.


def trace_set_buffer_capacity(self, size):
    cmd = enums.JLinkTraceCommand.SET_CAPACITY
    data = ctypes.c_uint32(size)
    res = self._dll.JLINKARM_TRACE_Control(cmd, ctypes.byref(data))
    if (res == 1):
        raise errors.JLinkException('Failed to set trace buffer size.')
    return None

Sets the capacity for the trace buffer.

Args:
        self (JLink): the ``JLink`` instance.
        size (int): the new capacity for the trace buffer.

Returns:
        ``None``


def GetRegistryFileMapping(self, registry_file):
    if (not registry_file):
        return ''
    candidate_mappings = []
    for mapping in self._REGISTRY_FILE_MAPPINGS_NT:
        if (not mapping.unique_key_paths):
            continue
        match = True
        for key_path in mapping.unique_key_paths:
            registry_key = registry_file.GetKeyByPath(key_path)
            if (not registry_key):
                match = False
        if match:
            candidate_mappings.append(mapping)
    if (not candidate_mappings):
        return ''
    if (len(candidate_mappings) == 1):
        return candidate_mappings[0].key_path_prefix
    key_path_prefixes = frozenset([mapping.key_path_prefix for mapping in candidate_mappings])
    expected_key_path_prefixes = frozenset(['HKEY_CURRENT_USER', 'HKEY_CURRENT_USER\\Software\\Classes'])
    if (key_path_prefixes == expected_key_path_prefixes):
        return 'HKEY_CURRENT_USER'
    raise RuntimeError('Unable to resolve Windows Registry file mapping.')

Determines the Registry file mapping based on the content of the file.

Args:
        registry_file (WinRegistyFile): Windows Registry file.

Returns:
        str: key path prefix or an empty string.

Raises:
        RuntimeError: if there are multiple matching mappings and
        the correct mapping cannot be resolved.


def nb_fit(data, P_init=None, R_init=None, epsilon=1e-08, max_iters=100):
    means = data.mean(1)
    variances = data.var(1)
    if (means > variances).any():
        raise ValueError('For NB fit, means must be less than variances')
    (genes, cells) = data.shape
    P = (1.0 - (means / variances))
    R = ((means * (1 - P)) / P)
    for i in range(genes):
        result = minimize(nb_ll_row, [P[i], R[i]], args=(data[(i, :)],), bounds=[(0, 1), (eps, None)])
        params = result.x
        P[i] = params[0]
        R[i] = params[1]
    return (P, R)

Fits the NB distribution to data using method of moments.

Args:
        data (array): genes x cells
        P_init (array, optional): NB success prob param - genes x 1
        R_init (array, optional): NB stopping param - genes x 1

Returns:
        P, R - fit to data


def _initialise(self, initial_state: str='unknown') -> dict:
    initial_state = initial_state.lower()
    if ((initial_state != 'unknown') and (initial_state not in self._allowed_states)):
        raise ValueError('Invalid initial state: {}'.format(initial_state))
    _initial_state = dict(current_state=initial_state, target_state=initial_state, current_timestamp=datetime.utcnow().isoformat(), target_timestamp=datetime.utcnow().isoformat())
    return _initial_state

Return a dictionary used to initialise a state object.

    This method is used to obtain a dictionary/hash describing the initial
    state of SDP or a service in SDP.

Args:
        initial_state (str): Initial state.

Returns:
        dict, Initial state configuration


def codemirror_parameters(field):
    manifesto = CodemirrorAssetTagRender()
    names = manifesto.register_from_fields(field)
    config = manifesto.get_codemirror_parameters(names[0])
    return mark_safe(json.dumps(config))

Filter to include CodeMirror parameters as a JSON string for a single
    field.

    This must be called only on an allready rendered field, meaning you must
    not use this filter on a field before a form. Else, the field widget won't
    be correctly initialized.

Example:
        ::

            {% load djangocodemirror_tags %}
            {{ form.myfield|codemirror_parameters }}

Args:
        field (djangocodemirror.fields.CodeMirrorField): A form field.

Returns:
        string: JSON object for parameters, marked safe for Django templates.


def rollback(self, label=None, plane='sdr'):
    begin = time.time()
    rb_label = self._chain.target_device.rollback(label=label, plane=plane)
    elapsed = (time.time() - begin)
    if label:
        self.emit_message('Configuration rollback last {:.0f}s. Label: {}'.format(elapsed, rb_label), log_level=logging.INFO)
    else:
        self.emit_message('Configuration failed.', log_level=logging.WARNING)
    return rb_label

Rollback the configuration.

    This method rolls back the configuration on the device.

Args:
        label (text): The configuration label ID
        plane: (text): sdr or admin

Returns:
        A string with commit label or None


def get_m49_from_iso3(cls, iso3, use_live=True, exception=None):
    countriesdata = cls.countriesdata(use_live=use_live)
    m49 = countriesdata['m49iso3'].get(iso3)
    if (m49 is not None):
        return m49
    if (exception is not None):
        raise exception
    return None

Get M49 from ISO3 code

Args:
        iso3 (str): ISO3 code for which to get M49 code
        use_live (bool): Try to get use latest data from web rather than file in package. Defaults to True.
        exception (Optional[ExceptionUpperBound]): An exception to raise if country not found. Defaults to None.

Returns:
        Optional[int]: M49 code


def encrypt(self, plainText):
    encryptedResult = ''
    for index in range(0, len(plainText), BLOCK_SIZE):
        block = plainText[index:(index + BLOCK_SIZE)]
        if (len(block) < BLOCK_SIZE):
            block = zero_pad(block, BLOCK_SIZE)
        encryptedResult += self.encrypt_block(block)
    return encryptedResult

Encrypt an arbitrary-length block of data.

    NOTE: This function formerly worked only on 16-byte blocks of `plainText`.
    code that assumed this should still work fine, but can optionally be
    modified to call `encrypt_block` instead.

Args:
        plainText (str): data to encrypt. If the data is not a multiple of 16
            bytes long, it will be padded with null (0x00) bytes until it is.

Returns:
        encrypted data. Note that this will always be a multiple of 16 bytes
            long.


def compute_fat_line(nodes):
    (coeff_a, coeff_b, coeff_c) = compute_implicit_line(nodes)
    (_, num_nodes) = nodes.shape
    d_min = 0.0
    d_max = 0.0
    for index in six.moves.xrange(1, (num_nodes - 1)):
        curr_dist = (((coeff_a * nodes[(0, index)]) + (coeff_b * nodes[(1, index)])) + coeff_c)
        if (curr_dist < d_min):
            d_min = curr_dist
        elif (curr_dist > d_max):
            d_max = curr_dist
    return (coeff_a, coeff_b, coeff_c, d_min, d_max)

Compute the "fat line" around a B |eacute| zier curve.

    Both computes the implicit (normalized) form

    .. math::

        ax + by + c = 0

    for the line connecting the first and last node in ``nodes``.
    Also computes the maximum and minimum distances to that line
    from each control point.

Args:
        nodes (numpy.ndarray): ``2 x N`` array of nodes in a curve.

Returns:
        Tuple[float, float, float, float, float]: The 5-tuple of

        * The :math:`x` coefficient :math:`a`
        * The :math:`y` coefficient :math:`b`
        * The constant :math:`c`
        * The "minimum" distance to the fat line among the control points.
        * The "maximum" distance to the fat line among the control points.


def AppendPathEntries(cls, path, path_separator, number_of_wildcards, skip_first):
    if (path[(- 1)] == path_separator):
        path = path[:(- 1)]
    if skip_first:
        path = ''.join([path, path_separator, '*'])
        number_of_wildcards -= 1
    paths = []
    for _ in range(0, number_of_wildcards):
        path = ''.join([path, path_separator, '*'])
        paths.append(path)
    return paths

Appends glob wildcards to a path.

    This function will append glob wildcards "*" to a path, returning paths
    with an additional glob wildcard up to the specified number. E.g. given
    the path "/tmp" and a number of 2 wildcards, this function will return
    "tmp/*", "tmp/*/*". When skip_first is true the path with the first
    wildcard is not returned as a result.

Args:
        path (str): path to append glob wildcards to.
        path_separator (str): path segment separator.
        number_of_wildcards (int): number of glob wildcards to append.
        skip_first (bool): True if the the first path with glob wildcard should
        be skipped as a result.

Returns:
        list[str]: paths with glob wildcards.


def orth_gs(order, dist, normed=False, sort='GR', cross_truncation=1.0, **kws):
    logger = logging.getLogger(__name__)
    dim = len(dist)
    if isinstance(order, int):
        if (order == 0):
            return chaospy.poly.Poly(1, dim=dim)
        basis = chaospy.poly.basis(0, order, dim, sort, cross_truncation=cross_truncation)
    else:
        basis = order
    basis = list(basis)
    polynomials = [basis[0]]
    if normed:
        for idx in range(1, len(basis)):
            for idy in range(idx):
                orth = chaospy.descriptives.E((basis[idx] * polynomials[idy]), dist, **kws)
                basis[idx] = (basis[idx] - (polynomials[idy] * orth))
            norms = chaospy.descriptives.E((polynomials[(- 1)] ** 2), dist, **kws)
            if (norms <= 0):
                logger.warning('Warning: Polynomial cutoff at term %d', idx)
                break
            basis[idx] = (basis[idx] / numpy.sqrt(norms))
            polynomials.append(basis[idx])
    else:
        norms = [1.0]
        for idx in range(1, len(basis)):
            for idy in range(idx):
                orth = chaospy.descriptives.E((basis[idx] * polynomials[idy]), dist, **kws)
                basis[idx] = (basis[idx] - ((polynomials[idy] * orth) / norms[idy]))
            norms.append(chaospy.descriptives.E((polynomials[(- 1)] ** 2), dist, **kws))
            if (norms[(- 1)] <= 0):
                logger.warning('Warning: Polynomial cutoff at term %d', idx)
                break
            polynomials.append(basis[idx])
    return chaospy.poly.Poly(polynomials, dim=dim, shape=(len(polynomials),))

Gram-Schmidt process for generating orthogonal polynomials.

Args:
        order (int, Poly):
            The upper polynomial order. Alternative a custom polynomial basis
            can be used.
        dist (Dist):
            Weighting distribution(s) defining orthogonality.
        normed (bool):
            If True orthonormal polynomials will be used instead of monic.
        sort (str):
            Ordering argument passed to poly.basis. If custom basis is used,
            argument is ignored.
        cross_truncation (float):
            Use hyperbolic cross truncation scheme to reduce the number of
            terms in expansion.

Returns:
        (Poly):
            The orthogonal polynomial expansion.

Example:
        >>> Z = chaospy.J(chaospy.Normal(), chaospy.Normal())
        >>> print(chaospy.around(chaospy.orth_gs(2, Z), 4))
        [1.0, q1, q0, q1^2-1.0, q0q1, q0^2-1.0]