def _getClassInstance(path, args=None):

		if not path.endswith(".py"):
			return None

		if args is None:
			args = {}

		classname = AtomShieldsScanner._getClassName(path)
		basename = os.path.basename(path).replace(".py", "")
		sys.path.append(os.path.dirname(path))
		try:
			mod = __import__(basename, globals(), locals(), [classname], -1)
			class_ = getattr(mod, classname)
			instance = class_(**args)
		except Exception as e:
			AtomShieldsScanner._debug("[!] %s" % e)
			return None
		finally:
			sys.path.remove(os.path.dirname(path))
		return instance

Returns a class instance from a .py file.

Args:
    path (str): Absolute path to .py file
    args (dict): Arguments passed via class constructor

Returns:
    object: Class instance or None


def regex_findall_variables(content):

    try:
        vars_list = []
        for var_tuple in variable_regex_compile.findall(content):
            vars_list.append(
                var_tuple[0] or var_tuple[1]
            )
        return vars_list
    except TypeError:
        return []

extract all variable names from content, which is in format $variable

Args:
        content (str): string content

Returns:
        list: variables list extracted from string content

Example:
        >>> regex_findall_variables("$variable")
        ["variable"]

        >>> regex_findall_variables("/blog/$postid")
        ["postid"]

        >>> regex_findall_variables("/$var1/$var2")
        ["var1", "var2"]

        >>> regex_findall_variables("abc")
        []


def add_arguments(self, parser):

        parser.add_argument('name', nargs=1, choices=['kinetis'],
                            help='name of MCU to unlock')
        return self.add_common_arguments(parser, True)

Adds the unlock command arguments to the parser.

Args:
        self (UnlockCommand): the ``UnlockCommand`` instance
        parser (argparse.ArgumentParser): the parser to add the arguments to

Returns:
        ``None``


def on_click(self, handler):

        self.on_change('active', lambda attr, old, new: handler(new))

Set up a handler for button state changes (clicks).

Args:
        handler (func) : handler function to call when button is toggled.

Returns:
        None


def _bisect(self, begin, end, listener):

        step = (end.date - begin.date) / 2

        while abs(step) >= self._eps_bisect:
            date = begin.date + step
            if self.SPEAKER_MODE == "global":
                orb = self.propagate(date)
            else:
                orb = begin.propagate(date)
            if listener(begin) * listener(orb) > 0:
                begin = orb
            else:
                end = orb
            step = (end.date - begin.date) / 2
        else:
            end.event = listener.info(end)
            return end

This method search for the zero-crossing of the watched parameter

Args:
        begin (Orbit):
        end (Orbit)
        listener (Listener)
    Return
        Return


def get_object(cls, api_token, id):

        load_balancer = cls(token=api_token, id=id)
        load_balancer.load()
        return load_balancer

Class method that will return a LoadBalancer object by its ID.

Args:
        api_token (str): DigitalOcean API token
        id (str): Load Balancer ID


def unique(ar):
    r

    import dask.array as da

    if isinstance(ar, da.core.Array):
        return da.unique(ar)

    return _unique(ar)

r"""Find the unique elements of an array.

    It uses ``dask.array.unique`` if necessary.

Args:
        ar (array_like): Input array.

Returns:
        array_like: the sorted unique elements.


def parse(self, datestr):
        # type: (bytes) -> None

        if self._initialized:
            raise pycdlibexception.PyCdlibInternalError('This Volume Descriptor Date object is already initialized')

        if len(datestr) != 17:
            raise pycdlibexception.PyCdlibInvalidISO('Invalid ISO9660 date string')

        timestruct = string_to_timestruct(datestr[:-3])
        self.year = timestruct.tm_year
        self.month = timestruct.tm_mon
        self.dayofmonth = timestruct.tm_mday
        self.hour = timestruct.tm_hour
        self.minute = timestruct.tm_min
        self.second = timestruct.tm_sec
        if timestruct.tm_year == 0 and timestruct.tm_mon == 0 and timestruct.tm_mday == 0 and timestruct.tm_hour == 0 and timestruct.tm_min == 0 and timestruct.tm_sec == 0:
            self.hundredthsofsecond = 0
            self.gmtoffset = 0
            self.date_str = self.EMPTY_STRING
        else:
            self.hundredthsofsecond = int(datestr[14:15])
            self.gmtoffset, = struct.unpack_from('=b', datestr, 16)
            self.date_str = datestr

        self._initialized = True

Parse a Volume Descriptor Date out of a string.  A string of all zeros
    is valid, which means that the date in this field was not specified.

    Parameters:
        datestr - string to be parsed

Returns:
        Nothing.


def save_json(obj, filename, **kwargs):

    with open(filename, 'w', encoding='utf-8') as f:
        json.dump(obj, f, **kwargs)

Save an object as a JSON file.

Args:
        obj: The object to save. Must be JSON-serializable.
        filename: Path to the output file.
        **kwargs: Additional arguments to `json.dump`.


def wiki_list(self, title=None, creator_id=None, body_matches=None,
                  other_names_match=None, creator_name=None, hide_deleted=None,
                  other_names_present=None, order=None):

        params = {
            'search[title]': title,
            'search[creator_id]': creator_id,
            'search[body_matches]': body_matches,
            'search[other_names_match]': other_names_match,
            'search[creator_name]': creator_name,
            'search[hide_deleted]': hide_deleted,
            'search[other_names_present]': other_names_present,
            'search[order]': order
            }
        return self._get('wiki_pages.json', params)

Function to retrieves a list of every wiki page.

    Parameters:
        title (str): Page title.
        creator_id (int): Creator id.
        body_matches (str): Page content.
        other_names_match (str): Other names.
        creator_name (str): Creator name.
        hide_deleted (str): Can be: yes, no.
        other_names_present (str): Can be: yes, no.
        order (str): Can be: date, title.


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

        self.command = list(args)
        self.directory = kwargs['directory'] if 'directory' in kwargs else None
        self.env_vars = kwargs['env_vars'] if 'env_vars' in kwargs else None

Define a subcommand.

Args:
        *args (str): Sequence of program arguments needed to run the command.
        directory (Optional[str]): Directory the command is run in.
        env_vars (Optional[dict]): Environment variable to feed to the subcommand.


def add_primitives_path(path):

    if path not in _PRIMITIVES_PATHS:
        if not os.path.isdir(path):
            raise ValueError('Invalid path: {}'.format(path))

        LOGGER.debug('Adding new primitives path %s', path)
        _PRIMITIVES_PATHS.insert(0, os.path.abspath(path))

Add a new path to look for primitives.

    The new path will be inserted in the first place of the list,
    so any primitive found in this new folder will take precedence
    over any other primitive with the same name that existed in the
    system before.

Args:
        path (str): path to add

Raises:
        ValueError: A `ValueError` will be raised if the path is not valid.


def connect(self, inbox):

        if self.started:
            self.log.error('Piper %s is started and cannot connect to %s.' % \
                           (self, inbox))
            raise PiperError('Piper %s is started and cannot connect to %s.' % \
                             (self, inbox))
        elif self.connected:
            self.log.error('Piper %s is connected and cannot connect to %s.' % \
                           (self, inbox))
            raise PiperError('Piper %s is connected and cannot connect to %s.' % \
                             (self, inbox))
        elif hasattr(self.imap, '_started') and self.imap._started.isSet():
            self.log.error('Piper %s cannot connect (NuMap is started).' % \
                           self)
            raise PiperError('Piper %s cannot connect (NuMap is started).' % \
                           self)
        else:
            # not started and not connected and NuMap not started
            self.log.debug('Piper %s connects to %s' % (self, inbox))
            # determine the stride with which result will be consumed from the
            # input.
            stride = self.imap.stride if hasattr(self.imap, 'stride') else 1

            # Tee input iterators. The idea is to create a promise object for a
            # tee. The actual teed iterator will be created on start. Each tee
            # is protected with a seperate lock the reasons for this are:
            # - tee objects are as a collection not thread safe
            # - tee objects might be next'ed from different threads, a single
            #   lock will not guarantee that a thread might be allowed to finish
            #   it's stride. (How it works that a thread releases the next
            #   thread only if it finished a stride
            teed = []
            for piper in inbox:
                if hasattr(piper, '_iter'): # isinstance Piper?
                    piper.tee_num += 1
                    tee_lock = Lock()
                    tee_lock.acquire()
                    piper.tee_locks.append(tee_lock)
                    piper = _TeePiper(piper, piper.tee_num - 1, stride)
                teed.append(_InputIterator(piper, self))

            # set how much to consume from input iterators.
            self.inbox = _Zip(*teed) if self.consume == 1 else\
                 _Consume(_Zip(*teed), n=self.consume, stride=stride)

            # set how much to
            for i in xrange(self.spawn):
                self.imap_tasks.append(\
                    self.imap(self.worker, self.inbox) \
                        if self.imap is imap else \
                    self.imap(self.worker, self.inbox, timeout=self.timeout, \
                              track=self.track))
            # chain the results together.
            outbox = _Chain(self.imap_tasks, stride=stride)
            # Make output
            #prd = ProduceFromSequence if self.produce_from_sequence else Produce
            if self.produce == 1:
                self.outbox = outbox
            elif self.repeat:
                self.outbox = _Repeat(outbox, n=self.produce, stride=stride)
            else:
                self.outbox = _Produce(outbox, n=self.produce, stride=stride)
            self.connected = True

        return self

Connects the ``Piper`` instance to its upstream ``Pipers`` that should
    be given as a sequence. This connects this ``Piper.inbox`` with the
    upstream ``Piper.outbox`` respecting any "consume", "spawn" and
    "produce" arguments.

Args:
        - inbox(sequence) sequence of ``Piper`` instances.


def add_exac_info(genes, alias_genes, exac_lines):

    LOG.info("Add exac pli scores")
    for exac_gene in parse_exac_genes(exac_lines):
        hgnc_symbol = exac_gene['hgnc_symbol'].upper()
        pli_score = exac_gene['pli_score']

        for hgnc_id in get_correct_ids(hgnc_symbol, alias_genes):
            genes[hgnc_id]['pli_score'] = pli_score

Add information from the exac genes

    Currently we only add the pLi score on gene level

    The exac resource only use HGNC symbol to identify genes so we need
    our alias mapping.

Args:
        genes(dict): Dictionary with all genes
        alias_genes(dict): Genes mapped to all aliases
        ensembl_lines(iteable): Iteable with raw ensembl info


def load_hpo(adapter, disease_lines, hpo_disease_lines=None, hpo_lines=None, hpo_gene_lines=None):

    # Create a map from gene aliases to gene objects
    alias_genes = adapter.genes_by_alias()

    # Fetch the hpo terms if no file
    if not hpo_lines:
        hpo_lines = fetch_hpo_terms()

    # Fetch the hpo gene information if no file
    if not hpo_gene_lines:
        hpo_gene_lines = fetch_hpo_to_genes()

    # Fetch the hpo phenotype information if no file
    if not hpo_disease_lines:
        hpo_disease_lines = fetch_hpo_phenotype_to_terms()

    load_hpo_terms(adapter, hpo_lines, hpo_gene_lines, alias_genes)

    load_disease_terms(adapter, disease_lines, alias_genes, hpo_disease_lines)

Load the hpo terms and hpo diseases into database

Args:
        adapter(MongoAdapter)
        disease_lines(iterable(str)): These are the omim genemap2 information
        hpo_lines(iterable(str))
        disease_lines(iterable(str))
        hpo_gene_lines(iterable(str))


def binary_n(total_N, min_n=50):

  max_exp = np.log2(1.0 * total_N / min_n)
  max_exp = int(np.floor(max_exp))
  return [int(np.floor(1.0 * total_N / (2**i))) for i in range(1, max_exp + 1)]

Creates a list of values by successively halving the total length total_N
    until the resulting value is less than min_n.

    Non-integer results are rounded down.

Args:
        total_N (int):
        total length
    Kwargs:
        min_n (int):
        minimal length after division

Returns:
        list of integers:
        total_N/2, total_N/4, total_N/8, ... until total_N/2^i < min_n


def _string_from_ip_int(self, ip_int):

        octets = []
        for _ in xrange(4):
            octets.insert(0, str(ip_int & 0xFF))
            ip_int >>= 8
        return '.'.join(octets)

Turns a 32-bit integer into dotted decimal notation.

Args:
        ip_int: An integer, the IP address.

Returns:
        The IP address as a string in dotted decimal notation.


def new(self, sector_count, load_seg, media_name, system_type, bootable):
        # type: (int, int, str, int, bool) -> None

        if self._initialized:
            raise pycdlibexception.PyCdlibInternalError('El Torito Entry already initialized')

        if media_name == 'noemul':
            media_type = self.MEDIA_NO_EMUL
        elif media_name == 'floppy':
            if sector_count == 2400:
                media_type = self.MEDIA_12FLOPPY
            elif sector_count == 2880:
                media_type = self.MEDIA_144FLOPPY
            elif sector_count == 5760:
                media_type = self.MEDIA_288FLOPPY
            else:
                raise pycdlibexception.PyCdlibInvalidInput('Invalid sector count for floppy media type; must be 2400, 2880, or 5760')
            # With floppy booting, the sector_count always ends up being 1
            sector_count = 1
        elif media_name == 'hdemul':
            media_type = self.MEDIA_HD_EMUL
            # With HD emul booting, the sector_count always ends up being 1
            sector_count = 1
        else:
            raise pycdlibexception.PyCdlibInvalidInput("Invalid media name '%s'" % (media_name))

        if bootable:
            self.boot_indicator = 0x88
        else:
            self.boot_indicator = 0
        self.boot_media_type = media_type
        self.load_segment = load_seg
        self.system_type = system_type
        self.sector_count = sector_count
        self.load_rba = 0  # This will get set later
        self.selection_criteria_type = 0  # FIXME: allow the user to set this
        self.selection_criteria = b''.ljust(19, b'\x00')

        self._initialized = True

A method to create a new El Torito Entry.

    Parameters:
    sector_count - The number of sectors to assign to this El Torito Entry.
    load_seg - The load segment address of the boot image.
    media_name - The name of the media type, one of 'noemul', 'floppy', or 'hdemul'.
    system_type - The partition type to assign to the entry.
    bootable - Whether this entry is bootable.

Returns:
    Nothing.


def get_userid_from_botid(self, botid):

        botinfo = self.slack_client.api_call('bots.info', bot=botid)
        if botinfo['ok'] is True:
            return botinfo['bot'].get('user_id')
        else:
            return botid

Perform a lookup of bots.info to resolve a botid to a userid

Args:
        botid (string): Slack botid to lookup.

Returns:
        string: userid value


def __init__(self, inqueue, size, num_passes):

        self.inqueue = inqueue
        self.size = size
        self.max_ttl = num_passes
        self.cur_max_ttl = 1  # ramp up slowly to better mix the input data
        self.buffers = [None] * size
        self.ttl = [0] * size
        self.idx = 0

Initialize a minibatch buffer.

Args:
        inqueue: Queue to populate the internal ring buffer from.
        size: Max number of data items to buffer.
        num_passes: Max num times each data item should be emitted.


def compute_mask_offsets(shard_id2num_examples):

  total_num_examples = sum(shard_id2num_examples)

  mask_offsets = []
  total_num_examples = 0
  for num_examples_in_shard in shard_id2num_examples:
    # The offset (nb of examples to skip in the next shard) correspond to the
    # number of examples remaining in the current shard
    mask_offsets.append(total_num_examples % 100)
    total_num_examples += num_examples_in_shard

  return mask_offsets

Return the list of offsets associated with each shards.

Args:
        shard_id2num_examples: `list[int]`, mapping shard_id=>num_examples

Returns:
        mask_offsets: `list[int]`, offset to skip for each of the shard


def HandleNetworkInterfaces(self, result):

    network_interfaces = self._ExtractInterfaceMetadata(result)

    if self.network_setup_enabled:
      self.network_setup.EnableNetworkInterfaces(
          [interface.name for interface in network_interfaces[1:]])

    for interface in network_interfaces:
      if self.ip_forwarding_enabled:
        self.ip_forwarding.HandleForwardedIps(
            interface.name, interface.forwarded_ips, interface.ip)

Called when network interface metadata changes.

Args:
        result: dict, the metadata response with the network interfaces.


def generate_mix2pl_dataset(n, m, useDirichlet=True):

    alpha = np.random.rand()
    gamma1 = None
    gamma2 = None

    if useDirichlet:
        gamma1 = np.random.dirichlet(np.ones(m))
        gamma2 = np.random.dirichlet(np.ones(m))
    else:
        gamma1 = np.random.rand(m)
        gamma1 /= np.sum(gamma1) # normalize sum to 1.0 (not needed for Dirichlet)
        gamma2 = np.random.rand(m)
        gamma2 /= np.sum(gamma1)

    votes = []

    for i in range(n):
        vote = None
        draw = np.random.rand()
        if draw <= alpha:
            vote = draw_pl_vote(m, gamma1)
        else: # draw > alpha
            vote = draw_pl_vote(m, gamma2)
        votes.append(vote)
    params = np.hstack((alpha, gamma1, gamma2))
    return (params, votes)

Description:
    Generate a mixture of 2 Plackett-Luce models dataset
    and return the parameters and votes.
    Parameters:
    n:            number of votes to generate
    m:            number of alternatives
    useDirichlet: boolean flag to use the Dirichlet distribution


def get_site_dos(self, site):

        site_dos = functools.reduce(add_densities, self.pdos[site].values())
        return Dos(self.efermi, self.energies, site_dos)

Get the total Dos for a site (all orbitals).

Args:
        site: Site in Structure associated with CompleteDos.

Returns:
        Dos containing summed orbital densities for site.


def download(url, output_file=None, open_file=True, allow_overwrite=False):

    filename = url.split('/')[-1]
    if output_file is None:
        cache = os.path.join(get_data_home(), filename)
    else:
        cache = output_file
    if os.path.exists(cache) and not allow_overwrite:
        logger.info("> {} already exists.".format(cache))
        logger.info("> If you have any issue when using this file, ")
        logger.info("> manually remove the file and try download again.")
    else:
        r = request.urlopen(url)
        try:
            if six.PY2:
                content_length = int(r.info().dict['content-length'])
            elif six.PY3:
                content_length = int(r.info()['Content-Length'])
        except:
            content_length = 0
        unit = 1000000
        content = b''
        with tqdm(total=content_length, desc=filename, unit='B', unit_scale=True, unit_divisor=1024) as t:
            while True:
                data = r.read(unit)
                l = len(data)
                t.update(l)
                if l == 0:
                    break
                content += data
        with open(cache, 'wb') as f:
            f.write(content)
    if not open_file:
        return
    return open(cache, 'rb')

Download a file from URL.

Args:
        url (str): URL.
        output_file (str, optional): If given, the downloaded file is written to the given path.
        open_file (bool): If True, it returns an opened file stream of the downloaded file.
        allow_overwrite (bool): If True, it overwrites an existing file.

Returns:
        Returns file object if open_file is True, otherwise None.


def _generate_bucket_value(self, bucketing_id):

    ratio = float(self._generate_unsigned_hash_code_32_bit(bucketing_id)) / MAX_HASH_VALUE
    return math.floor(ratio * MAX_TRAFFIC_VALUE)

Helper function to generate bucket value in half-closed interval [0, MAX_TRAFFIC_VALUE).

Args:
        bucketing_id: ID for bucketing.

Returns:
        Bucket value corresponding to the provided bucketing ID.


def _closeElements(childs, HTMLElement):

    out = []

    # close all unclosed pair tags
    for e in childs:
        if not e.isTag():
            out.append(e)
            continue

        if not e.isNonPairTag() and not e.isEndTag() and not e.isComment() \
           and e.endtag is None:
            e.childs = _closeElements(e.childs, HTMLElement)

            out.append(e)
            out.append(HTMLElement("</" + e.getTagName() + ">"))

            # join opener and endtag
            e.endtag = out[-1]
            out[-1].openertag = e
        else:
            out.append(e)

    return out

Create `endtags` to elements which looks like openers, but doesn't have
    proper :attr:`HTMLElement.endtag`.

Args:
        childs (list): List of childs (:class:`HTMLElement` obj) - typically
            from :attr:`HTMLElement.childs` property.

Returns:
        list: List of closed elements.


def create_list(self, **kwargs):

        path = self._get_path('create_list')
        kwargs.update({'session_id': self.session_id})

        payload = {
            'name': kwargs.pop('name', None),
            'description': kwargs.pop('description', None),
        }
        if 'language' in kwargs:
            payload['language'] = kwargs['language']

        response = self._POST(path, kwargs, payload)
        self._set_attrs_to_values(response)
        return response

Create a new list.

    A valid session id is required.

Args:
        name: Name of the list.
        description: Description of the list.
        language: (optional) ISO 639-1 code.

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


def get_ip_address_info(ip_address, cache=None, nameservers=None,
                        timeout=2.0, parallel=False):

    ip_address = ip_address.lower()
    if cache:
        info = cache.get(ip_address, None)
        if info:
            return info
    info = OrderedDict()
    info["ip_address"] = ip_address
    reverse_dns = get_reverse_dns(ip_address,
                                  nameservers=nameservers,
                                  timeout=timeout)
    country = get_ip_address_country(ip_address, parallel=parallel)
    info["country"] = country
    info["reverse_dns"] = reverse_dns
    info["base_domain"] = None
    if reverse_dns is not None:
        base_domain = get_base_domain(reverse_dns)
        info["base_domain"] = base_domain

    return info

Returns reverse DNS and country information for the given IP address

Args:
        ip_address (str): The IP address to check
        cache (ExpiringDict): Cache storage
        nameservers (list): A list of one or more nameservers to use
        (Cloudflare's public DNS resolvers by default)
        timeout (float): Sets the DNS timeout in seconds
        parallel (bool): parallel processing

Returns:
        OrderedDict: ``ip_address``, ``reverse_dns``


def starts_with_prefix_in_list(text, prefixes):

    for prefix in prefixes:
        if text.startswith(prefix):
            return True
    return False

Return True if the given string starts with one of the prefixes in the given list, otherwise
    return False.

Args:
        text (str): Text to check for prefixes.
        prefixes (list): List of prefixes to check for.

Returns:
        bool: True if the given text starts with any of the given prefixes, otherwise False.


def __init__(self, n=65, radius=1, port_distance_from_surface=.07):

        super(Sphere, self).__init__()
        particle = mb.Particle(name='np')
        particle.add(mb.Port(anchor=particle), label='out')

        # Generate 65 points on the surface of a unit sphere.
        pattern = mb.SpherePattern(n)
        # Magnify the unit sphere by the provided radius.
        pattern.scale(radius)

        particles = pattern.apply(particle, orientation='normal', compound_port='out')
        self.add(particles, label='np_[$]')

        # Create particles and Ports at pattern positions.
        for i, pos in enumerate(pattern.points):
            particle = mb.Particle(name="np", pos=pos)
            self.add(particle, "np_{}".format(i))
            port = mb.Port(anchor=particle)
            self.add(port, "port_{}".format(i))

            # Make the top of the port point toward the positive x axis.
            port.spin(-pi/2, [0, 0, 1])
            # Raise up (or down) the top of the port in the z direction.
            port.spin(-arcsin(pos[2]/radius), [0, 1, 0])
            # Rotate the Port along the z axis.
            port.spin(arctan2(pos[1], pos[0]), [0, 0, 1])
            # Move the Port a bit away from the surface of the Sphere.
            port.translate(pos/radius * port_distance_from_surface)

Initialize a Sphere object.

Args:
        n (int): Number of points used to construct the Sphere.
        radius (float): Radius of the Sphere.
        port_distance_from_surface (float): Distance of Ports from Sphere.


def parse_genes(transcripts):

    # Dictionary to group the transcripts by hgnc_id
    genes_to_transcripts = {}

    # List with all genes and there transcripts
    genes = []

    hgvs_identifier = None
    canonical_transcript = None
    exon = None
    # Group all transcripts by gene
    for transcript in transcripts:
        # Check what hgnc_id a transcript belongs to
        hgnc_id = transcript['hgnc_id']
        hgnc_symbol = transcript['hgnc_symbol']

        if (transcript['is_canonical'] and transcript.get('coding_sequence_name')):
            hgvs_identifier = transcript.get('coding_sequence_name')
            canonical_transcript = transcript['transcript_id']
            exon = transcript['exon']

        # If there is a identifier we group the transcripts under gene
        if hgnc_id:
            if hgnc_id in genes_to_transcripts:
                genes_to_transcripts[hgnc_id].append(transcript)
            else:
                genes_to_transcripts[hgnc_id] = [transcript]
        else:
            if hgnc_symbol:
                if hgnc_symbol in genes_to_transcripts:
                    genes_to_transcripts[hgnc_symbol].append(transcript)
                else:
                    genes_to_transcripts[hgnc_symbol] = [transcript]

    # We need to find out the most severe consequence in all transcripts
    # and save in what transcript we found it

    # Loop over all genes
    for gene_id in genes_to_transcripts:
        # Get the transcripts for a gene
        gene_transcripts = genes_to_transcripts[gene_id]
        # This will be a consequece from SO_TERMS
        most_severe_consequence = None
        # Set the most severe score to infinity
        most_severe_rank = float('inf')
        # The most_severe_transcript is a dict
        most_severe_transcript = None

        most_severe_region = None

        most_severe_sift = None
        most_severe_polyphen = None

        # Loop over all transcripts for a gene to check which is most severe
        for transcript in gene_transcripts:
            hgnc_id = transcript['hgnc_id']
            hgnc_symbol = transcript['hgnc_symbol']
            # Loop over the consequences for a transcript
            for consequence in transcript['functional_annotations']:
                # Get the rank based on SO_TERM
                # Lower rank is worse
                new_rank = SO_TERMS[consequence]['rank']

                if new_rank < most_severe_rank:
                    # If a worse consequence is found, update the parameters
                    most_severe_rank = new_rank
                    most_severe_consequence = consequence
                    most_severe_transcript = transcript
                    most_severe_sift = transcript['sift_prediction']
                    most_severe_polyphen = transcript['polyphen_prediction']
                    most_severe_region = SO_TERMS[consequence]['region']

        gene = {
            'transcripts': gene_transcripts,
            'most_severe_transcript': most_severe_transcript,
            'most_severe_consequence': most_severe_consequence,
            'most_severe_sift': most_severe_sift,
            'most_severe_polyphen': most_severe_polyphen,
            'hgnc_id': hgnc_id,
            'hgnc_symbol': hgnc_symbol,
            'region_annotation': most_severe_region,
            'hgvs_identifier': transcript['coding_sequence_name'],
            'canonical_transcript': transcript['transcript_id'],
            'exon': transcript['exon'],
        }
        genes.append(gene)

    return genes

Parse transcript information and get the gene information from there.

    Use hgnc_id as identifier for genes and ensembl transcript id to identify transcripts

Args:
        transcripts(iterable(dict))

Returns:
        genes (list(dict)): A list with dictionaries that represents genes


def _TrimNode(node, index, depth, flags):

        if depth == 1 or node.LeftChild is None:
            return

        if depth == 2:
            if not flags[index * 2] and not flags[index * 2 + 1]:
                node.LeftChild = None
                node.RightChild = None

        else:

            MerkleTree._TrimNode(node.LeftChild, index * 2, depth - 1, flags)
            MerkleTree._TrimNode(node.RightChild, index * 2, depth - 1, flags)

            if node.LeftChild.LeftChild is None and node.RightChild.RightChild is None:
                node.LeftChild = None
                node.RightChild = None

Internal helper method to trim a node.

Args:
        node (MerkleTreeNode):
        index (int): flag index.
        depth (int): node tree depth to start trim from.
        flags (bytearray): of left/right pairs. 1 byte for the left node, 1 byte for the right node.
                            00 to erase, 11 to keep. Will keep the node if either left or right is not-0


def get_size(fileobj):

    old_pos = fileobj.tell()
    try:
        fileobj.seek(0, 2)
        return fileobj.tell()
    finally:
        fileobj.seek(old_pos, 0)

Returns the size of the file.
    The position when passed in will be preserved if no error occurs.

Args:
        fileobj (fileobj)

Returns:
        int: The size of the file

Raises:
        IOError


def distorted_inputs(data_dir, batch_size):

  filenames = [os.path.join(data_dir, 'data_batch_%d.bin' % i)
               for i in xrange(1, 6)]
  for f in filenames:
    if not tf.gfile.Exists(f):
      raise ValueError('Failed to find file: ' + f)

  # Create a queue that produces the filenames to read.
  filename_queue = tf.train.string_input_producer(filenames)

  # Read examples from files in the filename queue.
  read_input = read_cifar10(filename_queue)
  reshaped_image = tf.cast(read_input.uint8image, tf.float32)

  height = IMAGE_SIZE
  width = IMAGE_SIZE

  # Image processing for training the network. Note the many random
  # distortions applied to the image.

  # Randomly crop a [height, width] section of the image.
  distorted_image = tf.random_crop(reshaped_image, [height, width, 3])

  # Randomly flip the image horizontally.
  distorted_image = tf.image.random_flip_left_right(distorted_image)

  # Because these operations are not commutative, consider randomizing
  # the order their operation.
  distorted_image = tf.image.random_brightness(distorted_image,
                                               max_delta=63)
  distorted_image = tf.image.random_contrast(distorted_image,
                                             lower=0.2, upper=1.8)

  # Subtract off the mean and divide by the variance of the pixels.
  float_image = tf.image.per_image_standardization(distorted_image)

  # Set the shapes of tensors.
  float_image.set_shape([height, width, 3])
  read_input.label.set_shape([1])

  # Ensure that the random shuffling has good mixing properties.
  min_fraction_of_examples_in_queue = 0.4
  min_queue_examples = int(NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN *
                           min_fraction_of_examples_in_queue)
  print ('Filling queue with %d CIFAR images before starting to train. '
         'This will take a few minutes.' % min_queue_examples)

  # Generate a batch of images and labels by building up a queue of examples.
  return _generate_image_and_label_batch(float_image, read_input.label,
                                         min_queue_examples, batch_size,
                                         shuffle=True)

Construct distorted input for CIFAR training using the Reader ops.

Args:
        data_dir: Path to the CIFAR-10 data directory.
        batch_size: Number of images per batch.

Returns:
        images: Images. 4D tensor of [batch_size, IMAGE_SIZE, IMAGE_SIZE, 3] size.
        labels: Labels. 1D tensor of [batch_size] size.


def Extract(self, components):

    rundll_index = -1
    for index, component in enumerate(components):
      if component.lower().endswith("rundll32.exe"):
        rundll_index = index

    if rundll_index == -1:
      return []

    components = components[(rundll_index + 1):]

    # We expect components after "rundll32.exe" to point at a DLL and a
    # function. For example:
    # rundll32.exe "C:\Windows\system32\advpack.dll",DelNodeRunDLL32
    last_component = components[-1].rsplit(",", 1)[0]

    extracted_path = " ".join(components[0:-1] + [last_component])
    return [extracted_path]

Extracts interesting paths from a given path.

Args:
        components: Source string represented as a list of components.

Returns:
        A list of extracted paths (as strings).


def _ReadCompressedData(self, read_size):

    compressed_data = self._file_object.read(read_size)

    read_count = len(compressed_data)

    self._compressed_data = b''.join([self._compressed_data, compressed_data])

    self._uncompressed_data, self._compressed_data = (
        self._decompressor.Decompress(self._compressed_data))

    self._uncompressed_data_size = len(self._uncompressed_data)

    return read_count

Reads compressed data from the file-like object.

Args:
        read_size (int): number of bytes of compressed data to read.

Returns:
        int: number of bytes of compressed data read.


def _UpdateYear(self, mediator, month):

    if not self._year_use:
      self._year_use = mediator.GetEstimatedYear()
    if not self._maximum_year:
      self._maximum_year = mediator.GetLatestYear()

    if not self._last_month:
      self._last_month = month
      return

    # Some syslog daemons allow out-of-order sequences, so allow some leeway
    # to not cause Apr->May->Apr to cause the year to increment.
    # See http://bugzilla.adiscon.com/show_bug.cgi?id=527
    if self._last_month > (month + 1):
      if self._year_use != self._maximum_year:
        self._year_use += 1
    self._last_month = month

Updates the year to use for events, based on last observed month.

Args:
        mediator (ParserMediator): mediates the interactions between
        parsers and other components, such as storage and abort signals.
        month (int): month observed by the parser, where January is 1.


def screenrecord(self, bit_rate: int = 5000000, time_limit: int = 180, filename: _PATH = '/sdcard/demo.mp4') -> None:

        self._execute('-s', self.device_sn, 'shell',
                      'screenrecord', '--bit-rate', str(bit_rate), '--time-limit', str(time_limit), filename)

Recording the display of devices running Android 4.4 (API level 19) and higher.

Args:
        bit_rate:You can increase the bit rate to improve video quality, but doing so results in larger movie files.
        time_limit: Sets the maximum recording time, in seconds, and the maximum value is 180 (3 minutes).


def run_docker(self, commands):

        try:
            import docker
        except ImportError:
            print(
                '{}{}Could not import docker module (try "pip install docker").'.format(
                    c.Style.BRIGHT, c.Fore.RED
                )
            )
            sys.exit(1)

        # app_args = self.profile.get('profile_args').standard
        app_args_data = self.profile.get('profile_args').data
        install_json = self.profile.get('install_json')

        # client
        client = docker.from_env()

        # app data
        app_dir = os.getcwd()
        # app_path = '{}/{}'.format(app_dir, program_main)

        # ports
        ports = {}
        if self.args.vscd:
            ports = {'{}/tcp'.format(self.args.vscd_port): self.args.vscd_port}

        # volumes
        volumes = {}
        in_path = '{}/{}'.format(app_dir, app_args_data.get('tc_in_path'))
        if app_args_data.get('tc_in_path') is not None:
            volumes[in_path] = {'bind': in_path}
        log_path = '{}/{}'.format(app_dir, app_args_data.get('tc_log_path'))
        if app_args_data.get('tc_log_path') is not None:
            volumes[log_path] = {'bind': log_path}
        out_path = '{}/{}'.format(app_dir, app_args_data.get('tc_out_path'))
        if app_args_data.get('tc_out_path') is not None:
            volumes[out_path] = {'bind': out_path}
        temp_path = '{}/{}'.format(app_dir, app_args_data.get('tc_temp_path'))
        if app_args_data.get('tc_temp_path') is not None:
            volumes[temp_path] = {'bind': temp_path}
        volumes[app_dir] = {'bind': app_dir}

        if self.args.docker_image is not None:
            # user docker image from cli as an override.
            docker_image = self.args.docker_image
        else:
            # docker image from install.json can be overridden by docker image in profile. if no
            # image is defined in either file use the default image define as self.docker_image.
            docker_image = self.profile.get(
                'dockerImage', install_json.get('dockerImage', self.docker_image)
            )

        status_code = 1
        try:
            self.container = client.containers.run(
                docker_image,
                entrypoint=commands.get('cli_command'),
                environment=['PYTHONPATH={}/lib_latest'.format(app_dir)],
                detach=True,
                # network_mode=install_json.get('docker_host', 'host'),
                ports=ports,
                remove=True,
                volumes=volumes,
                working_dir=app_dir,
            )
            results = self.container.wait()
            status_code = results.get('StatusCode')
            error = results.get('Error')
            if error:
                print('{}{}{}'.format(c.Style.BRIGHT, c.Fore.RED, error))
        except Exception as e:
            print('{}{}{}'.format(c.Style.BRIGHT, c.Fore.RED, e))
            sys.exit()

        # Exit Code
        return self.run_exit_code(status_code)

Run App in Docker Container.

Args:
        commands (dict): A dictionary of the CLI commands.

Returns:
        int: The exit code of the subprocess command.


def __getHyperSearchJobIDFilePath(cls, permWorkDir, outputLabel):

    # Get the base path and figure out the path of the report file.
    basePath = permWorkDir

    # Form the name of the output csv file that will contain all the results
    filename = "%s_HyperSearchJobID.pkl" % (outputLabel,)
    filepath = os.path.join(basePath, filename)

    return filepath

Returns filepath where to store HyperSearch JobID

    Parameters:
    ----------------------------------------------------------------------
    permWorkDir: Directory path for saved jobID file
    outputLabel: Label string for incorporating into file name for saved jobID
    retval:      Filepath where to store HyperSearch JobID


def AddEventAttribute(self, attribute_name, attribute_value):

    if attribute_name in self._extra_event_attributes:
      raise KeyError('Event attribute {0:s} already set'.format(
          attribute_name))

    self._extra_event_attributes[attribute_name] = attribute_value

Adds an attribute that will be set on all events produced.

    Setting attributes using this method will cause events produced via this
    mediator to have an attribute with the provided name set with the
    provided value.

Args:
        attribute_name (str): name of the attribute to add.
        attribute_value (str): value of the attribute to add.

Raises:
        KeyError: if the event attribute is already set.


def __init__(self, channel):

        self.StreamingAnnotateVideo = channel.stream_stream(
            "/google.cloud.videointelligence.v1p3beta1.StreamingVideoIntelligenceService/StreamingAnnotateVideo",
            request_serializer=google_dot_cloud_dot_videointelligence__v1p3beta1_dot_proto_dot_video__intelligence__pb2.StreamingAnnotateVideoRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_videointelligence__v1p3beta1_dot_proto_dot_video__intelligence__pb2.StreamingAnnotateVideoResponse.FromString,
        )

Constructor.

Args:
        channel: A grpc.Channel.


def receive(self, sequence, args):

        # If we are told to ignore sequence numbers, just pass the packet on
        if not self._reorder:
            self._callback(*args)
            return

        # If this packet is in the past, drop it
        if self._next_expected is not None and sequence < self._next_expected:
            print("Dropping out of order packet, seq=%d" % sequence)
            return

        self._out_of_order.append((sequence, args))
        self._out_of_order.sort(key=lambda x: x[0])

        # If we have received packets, attempt to process them in order
        while len(self._out_of_order) > 0:
            seq, args = self._out_of_order[0]

            if self._next_expected is not None and seq != self._next_expected:
                return

            self._callback(*args)
            self._out_of_order.pop(0)
            self._next_expected = seq+1

Receive one packet

    If the sequence number is one we've already seen before, it is dropped.

    If it is not the next expected sequence number, it is put into the
    _out_of_order queue to be processed once the holes in sequence number
    are filled in.

Args:
        sequence (int): The sequence number of the received packet
        args (list): The list of packet contents that will be passed to callback
            as callback(*args)


def __init__(self, min_obs=10):

        self.min_obs = min_obs
        self.label_encoder = LabelEncoder(min_obs)

Initialize the OneHotEncoder class object.

Args:
        min_obs (int): minimum number of observation to create a dummy variable
        label_encoder (LabelEncoder): LabelEncoder that transofrm


def __call__(self, data):

        # For inputs which represent multiple "rows", the result should be newline-separated CSV rows
        if _is_mutable_sequence_like(data) and len(data) > 0 and _is_sequence_like(data[0]):
            return '\n'.join([_CsvSerializer._serialize_row(row) for row in data])
        return _CsvSerializer._serialize_row(data)

Take data of various data formats and serialize them into CSV.

Args:
        data (object): Data to be serialized.

Returns:
        object: Sequence of bytes to be used for the request body.


def _WebSafeComponent(c, alt=False):

    # This sucks, but floating point between 0 and 1 is quite fuzzy...
    # So we just change the scale a while to make the equality tests
    # work, otherwise it gets wrong at some decimal far to the right.
    sc = c * 100.0

    # If the color is already safe, return it straight away
    d = sc % 20
    if d==0: return c

    # Get the lower and upper safe values
    l = sc - d
    u = l + 20

    # Return the 'closest' value according to the alt flag
    if alt:
      if (sc-l) >= (u-sc): return l/100.0
      else: return u/100.0
    else:
      if (sc-l) >= (u-sc): return u/100.0
      else: return l/100.0

Convert a color component to its web safe equivalent.

    Parameters:
        :c:
        The component value [0...1]
        :alt:
        If True, return the alternative value instead of the nearest one.

Returns:
        The web safe equivalent of the component value.


def GetForwardedIps(self, interface, interface_ip=None):

    try:
      ips = netifaces.ifaddresses(interface)
      ips = ips[netifaces.AF_INET]
    except (ValueError, IndexError):
      return []
    forwarded_ips = []
    for ip in ips:
      if ip['addr'] != interface_ip:
        full_addr = '%s/%d' % (ip['addr'], netaddr.IPAddress(ip['netmask']).netmask_bits())
        forwarded_ips.append(full_addr)
    return self.ParseForwardedIps(forwarded_ips)

Retrieve the list of configured forwarded IP addresses.

Args:
        interface: string, the output device to query.
        interface_ip: string, current interface ip address.

Returns:
        list, the IP address strings.


def GetArtifactsForCollection(os_name, artifact_list):

  artifact_arranger = ArtifactArranger(os_name, artifact_list)
  artifact_names = artifact_arranger.GetArtifactsInProperOrder()
  return artifact_names

Wrapper for the ArtifactArranger.

    Extend the artifact list by dependencies and sort the artifacts to resolve the
    dependencies.

Args:
        os_name: String specifying the OS name.
        artifact_list: List of requested artifact names.

Returns:
        A list of artifacts such that if they are collected in the given order
        their dependencies are resolved.


def data_group_association(self, xid):

        groups = []
        group_data = None

        # get group data from one of the arrays
        if self.groups.get(xid) is not None:
            group_data = self.groups.get(xid)
            del self.groups[xid]
        elif self.groups_shelf.get(xid) is not None:
            group_data = self.groups_shelf.get(xid)
            del self.groups_shelf[xid]

        if group_data is not None:
            # convert any obj into dict and process file data
            group_data = self.data_group_type(group_data)
            groups.append(group_data)

            # recursively get associations
            for assoc_xid in group_data.get('associatedGroupXid', []):
                groups.extend(self.data_group_association(assoc_xid))

        return groups

Return group dict array following all associations.

Args:
        xid (str): The xid of the group to retrieve associations.

Returns:
        list: A list of group dicts.


def decode_varint_1(buffer, pos=0):

    value = 0
    shift = 0
    memview = memoryview(buffer)
    for i in range(pos, pos + 10):
        try:
            byte = _read_byte(memview, i)
        except IndexError:
            raise ValueError("End of byte stream")
        if byte & 0x80 != 0:
            value |= (byte & 0x7f) << shift
            shift += 7
        else:
            value |= byte << shift
            break
    else:
        # Max size of endcoded double is 10 bytes for unsigned values
        raise ValueError("Out of double range")
    # Normalize sign
    return (value >> 1) ^ -(value & 1), i + 1

Decode an integer from a varint presentation. See
    https://developers.google.com/protocol-buffers/docs/encoding?csw=1#varints
    on how those can be produced.

Args:
            buffer (bytes-like): any object acceptable by ``memoryview``
            pos (int): optional position to read from

Returns:
            (int, int): Decoded int value and next read position


def suggest_filename(metadata):

	if 'title' in metadata and 'track_number' in metadata:  # Music Manager.
		suggested_filename = f"{metadata['track_number']:0>2} {metadata['title']}"
	elif 'title' in metadata and 'trackNumber' in metadata:  # Mobile.
		suggested_filename = f"{metadata['trackNumber']:0>2} {metadata['title']}"
	elif 'title' in metadata and 'tracknumber' in metadata:  # audio-metadata/mutagen.
		track_number = _split_number_field(
			list_to_single_value(
				metadata['tracknumber']
			)
		)
		title = list_to_single_value(metadata['title'])

		suggested_filename = f"{track_number:0>2} {title}"
	else:
		suggested_filename = f"00 {list_to_single_value(metadata.get('title', ['']))}"

	return _replace_invalid_characters(suggested_filename)

Generate a filename like Google for a song based on metadata.

    Parameters:
    metadata (~collections.abc.Mapping): A metadata dict.

Returns:
    str: A filename string without an extension.


def __init__(self, key_path=''):

    super(WinRegistryKey, self).__init__()
    self._key_path = key_paths.JoinKeyPath([key_path])

Initializes a Windows Registry key.

Args:
        key_path (Optional[str]): Windows Registry key path.


def oxide_type(structure, relative_cutoff=1.1, return_nbonds=False):

    ox_obj = OxideType(structure, relative_cutoff)
    if return_nbonds:
        return ox_obj.oxide_type, ox_obj.nbonds
    else:
        return ox_obj.oxide_type

Determines if an oxide is a peroxide/superoxide/ozonide/normal oxide

Args:
        structure (Structure): Input structure.
        relative_cutoff (float): Relative_cutoff * act. cutoff stipulates the
            max distance two O atoms must be from each other.
        return_nbonds (bool): Should number of bonds be requested?


def update_defaults(self, new_defaults, respect_none=False):

        for key, value in six.iteritems(new_defaults):
            item = self.get_item(key)
            if item is None:
                raise YapconfItemNotFound("Cannot update default for {0}, "
                                          "there is no config item by the "
                                          "name of {1}".format(key, key), None)

            item.update_default(value, respect_none)

Update items defaults to the values in the new_defaults dict.

Args:
        new_defaults (dict): A key-value pair of new defaults to be
            applied.
        respect_none (bool): Flag to indicate if ``None`` values should
            constitute an update to the default.


def assemble_buffer(self, buf_header, buf_payload):

        if self.header.get('num_buffers', 0) <= len(self._buffers):
            raise ProtocolError("too many buffers received expecting " + str(self.header['num_buffers']))
        self._buffers.append((buf_header, buf_payload))

Add a buffer header and payload that we read from the socket.

    This differs from add_buffer() because we're validating vs.
    the header's num_buffers, instead of filling in the header.

Args:
        buf_header (``JSON``) : a buffer header
        buf_payload (``JSON`` or bytes) : a buffer payload

Returns:
        None

Raises:
        ProtocolError


def postings(self, quarter, stats_counter=None):

        logging.info('Finding postings for %s', quarter)
        for posting in self._iter_postings(quarter):
            transformed = self._transform(posting)
            transformed['id'] = '{}_{}'.format(
                self.partner_id,
                self._id(posting)
            )
            if stats_counter:
                stats_counter.track(
                    input_document=posting,
                    output_document=transformed
                )
            yield transformed

Yield job postings in common schema format

Args:
        quarter (str) The quarter, in format '2015Q1'
        stats_counter (object, optional) A counter that can track both
            input and output documents using a 'track' method.


def set_column_count(self, count):

        current_row_count = self.row_count()
        current_column_count = self.column_count()
        if count > current_column_count:
            cl = TableEditableItem if self._editable else TableItem
            for r_key in self.children.keys():
                row = self.children[r_key]
                for i in range(current_column_count, count):
                    row.append(cl(), str(i))
                    if self._editable:
                        row.children[str(i)].onchange.connect(
                            self.on_item_changed, int(r_key), int(i))
            self._update_first_row()
        elif count < current_column_count:
            for row in self.children.values():
                for i in range(count, current_column_count):
                    row.remove_child(row.children[str(i)])
        self._column_count = count

Sets the table column count.

Args:
        count (int): column of rows


def get_plot(self, width=8, height=8):

        plt = pretty_plot(width, height)
        for label, electrode in self._electrodes.items():
            (x, y) = self.get_plot_data(electrode)
            plt.plot(x, y, '-', linewidth=2, label=label)

        plt.legend()
        if self.xaxis == "capacity":
            plt.xlabel('Capacity (mAh/g)')
        else:
            plt.xlabel('Fraction')
        plt.ylabel('Voltage (V)')
        plt.tight_layout()
        return plt

Returns a plot object.

Args:
        width: Width of the plot. Defaults to 8 in.
        height: Height of the plot. Defaults to 6 in.

Returns:
        A matplotlib plot object.


def main(argv=None):

    if argv is None:
        argv = sys.argv[1:]

    parser = build_args()
    args = parser.parse_args(args=argv)
    verbosity = args.verbose

    root = logging.getLogger()

    formatter = logging.Formatter('%(levelname).6s %(name)s %(message)s')
    handler = logging.StreamHandler()
    handler.setFormatter(formatter)

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

        level = loglevels[verbosity]
        root.setLevel(level)
        root.addHandler(handler)
    else:
        root.addHandler(logging.NullHandler())

    try:
        with open(args.script, "rb") as infile:
            binary_script = infile.read()
    except IOError as exc:
        print("ERROR: Unable to read script file: %s" % str(exc))
        return 1

    try:
        script = UpdateScript.FromBinary(binary_script, allow_unknown=args.allow_unknown, show_rpcs=args.show_rpcs)
    except ArgumentError as err:
        print("ERROR: ArgumentError: could not parse script")
        print(str(err))
        return 3
    except DataError as err:
        print("ERROR: DataError: could not parse script")
        print(str(err))
        return 4

    if args.format != 'text':
        print("ERROR: only text format is currently supported")
        return 2

    if args.format == 'text':
        print("\nUpdate Script")
        print("-------------")
        print("Path: %s" % args.script)
        print("Record Count: %d" % len(script.records))
        print("Total length: %d bytes" % len(binary_script))

        print("\nActions")
        print("-------")

        for i, record in enumerate(script.records):
            print("%02d: %s" % (i + 1, str(record)))

        print("")

    return 0

Main script entry point.

Args:
        argv (list): The command line arguments, defaults to sys.argv if not passed.

Returns:
        int: The return value of the script.


def delete(self, personId):

        check_type(personId, basestring, may_be_none=False)

        # API request
        self._session.delete(API_ENDPOINT + '/' + personId)

Remove a person from the system.

    Only an admin can remove a person.

Args:
        personId(basestring): The ID of the person to be deleted.

Raises:
        TypeError: If the parameter types are incorrect.
        ApiError: If the Webex Teams cloud returns an error.


def __init__(
      self, name, aliases=None, description=None, false_value=0, urls=None):

    super(BooleanDefinition, self).__init__(
        name, aliases=aliases, description=description, urls=urls)
    self.false_value = false_value
    self.true_value = None

Initializes a boolean data type definition.

Args:
        name (str): name.
        aliases (Optional[list[str]]): aliases.
        description (Optional[str]): description.
        false_value (Optional[int]): value that represents false.
        urls (Optional[list[str]]): URLs.


def show_edit_form(obj, attrs=None, title="", toolTips=None):

    if attrs is None:
        if hasattr(obj, "keys"):
            attrs = list(obj.keys())
        else:
            raise RuntimeError("attrs is None and cannot determine it from obj")

    specs = []
    for i, name in enumerate(attrs):
        # Tries as attribute, then as key
        try:
            value = obj.__getattribute__(name)
        except AttributeError:
            value = obj[name]

        if value is None:
            value = ""  # None becomes str

        dict_ = {"value": value}

        if toolTips is not None:
            dict_["toolTip"] = toolTips[i]
            dict_["tooltip"] = toolTips[i]

        specs.append((name, dict_))
    form = XParametersEditor(specs=specs, title=title)
    r = form.exec_()
    return r, form

Shows parameters editor modal form.

Args:
        obj: object to extract attribute values from, or a dict-like
        attrs: list of attribute names
        title:
        toolTips:


def when(self, key):

        ctx = Context(key, self)
        self.context.append(ctx)
        return ctx

Specify context, i.e. condition that must be met.

Args:
        key (str): Name of the context whose value you want to query.

Returns:
        Context:


def extract_cluster(self, target_sites, **kwargs):

        cluster = list(target_sites)
        others = [site for site in self if site not in cluster]
        size = 0
        while len(cluster) > size:
            size = len(cluster)
            new_others = []
            for site in others:
                for site2 in cluster:
                    if CovalentBond.is_bonded(site, site2, **kwargs):
                        cluster.append(site)
                        break
                else:
                    new_others.append(site)
            others = new_others
        return cluster

Extracts a cluster of atoms based on bond lengths

Args:
        target_sites ([Site]): List of initial sites to nucleate cluster.
        \\*\\*kwargs: kwargs passed through to CovalentBond.is_bonded.

Returns:
        [Site/PeriodicSite] Cluster of atoms.


def _write_session(self):

        base_name = "%ssession" % self._product_accronym.lower()
        filename = "%s%s.py" % (self._class_prefix.lower(), base_name)
        override_content = self._extract_override_content(base_name)

        self.write(destination=self.output_directory, filename=filename, template_name="session.py.tpl",
                   version=self.api_version,
                   product_accronym=self._product_accronym,
                   class_prefix=self._class_prefix,
                   root_api=self.api_root,
                   api_prefix=self.api_prefix,
                   override_content=override_content,
                   header=self.header_content)

Write SDK session file

Args:
        version (str): the version of the server


def flatten_zip_dataset(*args):

  flattened = tf.data.Dataset.from_tensors(args[0])
  for ex in args[1:]:
    flattened = flattened.concatenate(tf.data.Dataset.from_tensors(ex))
  return flattened

A list of examples to a dataset containing mixed examples.

    Given a list of `n` dataset examples, flatten them by converting
    each element into a dataset and concatenating them to convert into a
    single dataset.

Args:
        *args: A list containing one example each from `n` different datasets.

Returns:
        flattened: A new dataset containing the examples from the list as part
        of a single dataset.


def __init__(self,
               max_entity_count=MAX_ENTITY_COUNT,
               mapreduce_spec=None):

    self.max_entity_count = max_entity_count
    params = mapreduce_spec.params if mapreduce_spec is not None else {}
    self.force_writes = bool(params.get("force_ops_writes", False))
    self.puts = _ItemList(max_entity_count,
                          self._flush_puts,
                          repr_function=self._db_repr)
    self.deletes = _ItemList(max_entity_count,
                             self._flush_deletes)
    self.ndb_puts = _ItemList(max_entity_count,
                              self._flush_ndb_puts,
                              repr_function=self._ndb_repr)
    self.ndb_deletes = _ItemList(max_entity_count,
                                 self._flush_ndb_deletes)

Constructor.

Args:
        max_entity_count: maximum number of entities before flushing it to db.
        mapreduce_spec: An optional instance of MapperSpec.


def dataframe(self, force_refresh=False):

        if force_refresh:
            self.clear_cache()
        if self._dataframe is None:
            self._dataframe = self._fetch_dataframe()
        return self._dataframe

A pandas dataframe with lots of interesting results about this object.
    Created by calling SageMaker List and Describe APIs and converting them into
    a convenient tabular summary.

Args:
        force_refresh (bool): Set to True to fetch the latest data from SageMaker API.


def update_location_centroid(point, cluster, max_distance, min_samples):

    cluster.append(point)
    points = [p.gen2arr() for p in cluster]

    # Estimates the epsilon
    eps = estimate_meters_to_deg(max_distance, precision=6)

    p_cluster = DBSCAN(eps=eps, min_samples=min_samples)
    p_cluster.fit(points)

    clusters = {}
    for i, label in enumerate(p_cluster.labels_):
        if label in clusters.keys():
            clusters[label].append(points[i])
        else:
            clusters[label] = [points[i]]

    centroids = []
    biggest_centroid_l = -float("inf")
    biggest_centroid = None

    for label, n_cluster in clusters.items():
        centroid = compute_centroid(n_cluster)
        centroids.append(centroid)

        if label >= 0 and len(n_cluster) >= biggest_centroid_l:
            biggest_centroid_l = len(n_cluster)
            biggest_centroid = centroid

    if biggest_centroid is None:
        biggest_centroid = compute_centroid(points)

    return biggest_centroid, cluster

Updates the centroid of a location cluster with another point

Args:
        point (:obj:`Point`): Point to add to the cluster
        cluster (:obj:`list` of :obj:`Point`): Location cluster
        max_distance (float): Max neighbour distance
        min_samples (int): Minimum number of samples

Returns:
        (:obj:`Point`, :obj:`list` of :obj:`Point`): Tuple with the location centroid
            and new point cluster (given cluster + given point)


def do_reset_ids(concatenated_meta_df, data_df, concat_direction):

    if concat_direction == "horiz":

        # Make sure cids agree between data_df and concatenated_meta_df
        assert concatenated_meta_df.index.equals(data_df.columns), (
            "cids in concatenated_meta_df do not agree with cids in data_df.")

        # Reset cids in concatenated_meta_df
        reset_ids_in_meta_df(concatenated_meta_df)

        # Replace cids in data_df with the new ones from concatenated_meta_df
        # (just an array of unique integers, zero-indexed)
        data_df.columns = pd.Index(concatenated_meta_df.index.values)

    elif concat_direction == "vert":

        # Make sure rids agree between data_df and concatenated_meta_df
        assert concatenated_meta_df.index.equals(data_df.index), (
            "rids in concatenated_meta_df do not agree with rids in data_df.")

        # Reset rids in concatenated_meta_df
        reset_ids_in_meta_df(concatenated_meta_df)

        # Replace rids in data_df with the new ones from concatenated_meta_df
        # (just an array of unique integers, zero-indexed)
        data_df.index = pd.Index(concatenated_meta_df.index.values)

Reset ids in concatenated metadata and data dfs to unique integers and
    save the old ids in a metadata column.

    Note that the dataframes are modified in-place.

Args:
        concatenated_meta_df (pandas df)
        data_df (pandas df)
        concat_direction (string): 'horiz' or 'vert'

Returns:
        None (dfs modified in-place)


def _FindLargestIdPostfixNumber(self, schedule):

    postfix_number_re = re.compile('(\d+)$')

    def ExtractPostfixNumber(entity_id):

      if entity_id is None:
        return 0
      match = postfix_number_re.search(entity_id)
      if match is not None:
        return int(match.group(1))
      else:
        return 0

    id_data_sets = {'agency_id': schedule.GetAgencyList(),
                    'stop_id': schedule.GetStopList(),
                    'route_id': schedule.GetRouteList(),
                    'trip_id': schedule.GetTripList(),
                    'service_id': schedule.GetServicePeriodList(),
                    'fare_id': schedule.GetFareAttributeList(),
                    'shape_id': schedule.GetShapeList()}

    max_postfix_number = 0
    for id_name, entity_list in id_data_sets.items():
      for entity in entity_list:
        entity_id = getattr(entity, id_name)
        postfix_number = ExtractPostfixNumber(entity_id)
        max_postfix_number = max(max_postfix_number, postfix_number)
    return max_postfix_number

Finds the largest integer used as the ending of an id in the schedule.

Args:
        schedule: The schedule to check.

Returns:
        The maximum integer used as an ending for an id.


def start(self, attempts=5, timeout=2):

        if not self.alive():
            with LogTask('Create network %s' % self.name()):
                net = self.libvirt_con.networkCreateXML(self._libvirt_xml())
                if net is None:
                    raise RuntimeError(
                        'failed to create network, XML: %s' %
                        (self._libvirt_xml())
                    )
                for _ in range(attempts):
                    if net.isActive():
                        return
                    LOGGER.debug(
                        'waiting for network %s to become active', net.name()
                    )
                    time.sleep(timeout)
                raise RuntimeError(
                    'failed to verify network %s is active' % net.name()
                )

Start the network, will check if the network is active ``attempts``
    times, waiting ``timeout`` between each attempt.

Args:
        attempts (int): number of attempts to check the network is active
        timeout  (int): timeout for each attempt

Returns:
        None

Raises:
        RuntimeError: if network creation failed, or failed to verify it is
        active.


def encode(self, object_):

        if self.enforce_reversible:
            self.enforce_reversible = False
            if self.decode(self.encode(object_)) != object_:
                raise ValueError('Encoding is not reversible for "%s"' % object_)
            self.enforce_reversible = True

        return object_

Encodes an object.

Args:
        object_ (object): Object to encode.

Returns:
        object: Encoding of the object.


def __init__(self,
                 segments=None,

                 id=DEFAULT_ID,
                 confidence=DEFAULT_CONFIDENCE,
                 kvpairs=DEFAULT_DYNAMIC_METADATA,
                 status=DEFAULT_STATUS,
                 author=DEFAULT_AUTHOR):

        self.segments = segments

        RAMONBase.__init__(self,
                           id=id,
                           confidence=confidence,
                           kvpairs=kvpairs,
                           status=status,
                           author=author)

Initialize a new `RAMONNeuron`. Neurons take all of the arguments of
    `RAMONBase`.

Args:
        segments (int[]: None): A list of RAMON IDs that make up the neuron


def changes(self, target_version=None, nodes=None, labels=None):

        if nodes is None:
            nodes = []
        if labels is None:
            labels = []

        current_time = time.time()

        params = {
            'nodes': nodes,
            'clientTimestamp': _node.NodeTimestamps.int_to_str(current_time),
            'requestHeader': {
                'clientSessionId': self._session_id,
                'clientPlatform': 'ANDROID',
                'clientVersion': {
                    'major': '9',
                    'minor': '9',
                    'build': '9',
                    'revision': '9'
                },
                'capabilities': [
                    {'type': 'NC'}, # Color support (Send note color)
                    {'type': 'PI'}, # Pinned support (Send note pinned)
                    {'type': 'LB'}, # Labels support (Send note labels)
                    {'type': 'AN'}, # Annotations support (Send annotations)
                    {'type': 'SH'}, # Sharing support
                    {'type': 'DR'}, # Drawing support
                    {'type': 'TR'}, # Trash support (Stop setting the delete timestamp)
                    {'type': 'IN'}, # Indentation support (Send listitem parent)

                    {'type': 'SNB'}, # Allows modification of shared notes?
                    {'type': 'MI'}, # Concise blob info?
                    {'type': 'CO'}, # VSS_SUCCEEDED when off?

                    # TODO: Figure out what these do:
                    # {'type': 'EC'}, # ???
                    # {'type': 'RB'}, # Rollback?
                    # {'type': 'EX'}, # ???
                ]
            },
        }
        if target_version is not None:
            params['targetVersion'] = target_version

        if labels:
            params['userInfo'] = {
                'labels': labels
            }

        logger.debug('Syncing %d labels and %d nodes', len(labels), len(nodes))

        return self.send(
            url=self._base_url + 'changes',
            method='POST',
            json=params
        )

Sync up (and down) all changes.

Args:
        target_version (str): The local change version.
        nodes (List[dict]): A list of nodes to sync up to the server.
        labels (List[dict]): A list of labels to sync up to the server.

Returns:
        dict: Description of all changes.

Raises:
        APIException: If the server returns an error.


def numeric_task_id(task_id):

  # This function exists to support the legacy "task-id" format in the "google"
  # provider. Google labels originally could not be numeric. When the google
  # provider is completely replaced by the google-v2 provider, this function can
  # go away.

  if task_id is not None:
    if task_id.startswith('task-'):
      return int(task_id[len('task-'):])
    else:
      return int(task_id)

Converts a task-id to the numeric task-id.

Args:
        task_id: task-id in either task-n or n format

Returns:
        n


def add_connection(self, connection_id, internal_id, context):

        # Make sure we are not reusing an id that is currently connected to something
        if self._get_connection_state(connection_id) != self.Disconnected:
            return
        if self._get_connection_state(internal_id) != self.Disconnected:
            return

        conn_data = {
            'state': self.Idle,
            'microstate': None,
            'connection_id': connection_id,
            'internal_id': internal_id,
            'context': context
        }

        self._connections[connection_id] = conn_data
        self._int_connections[internal_id] = conn_data

Add an already created connection. Used to register devices connected before starting the device adapter.

Args:
        connection_id (int): The external connection id
        internal_id (string): An internal identifier for the connection
        context (dict): Additional information to associate with this context


def from_file(feff_inp_file='feff.inp', ldos_file='ldos'):

        header_str = Header.header_string_from_file(feff_inp_file)
        header = Header.from_string(header_str)
        structure = header.struct
        nsites = structure.num_sites
        parameters = Tags.from_file(feff_inp_file)

        if "RECIPROCAL" in parameters:
            pot_dict = dict()
            pot_readstart = re.compile('.*iz.*lmaxsc.*xnatph.*xion.*folp.*')
            pot_readend = re.compile('.*ExternalPot.*switch.*')
            pot_inp = re.sub(r'feff.inp', r'pot.inp', feff_inp_file)
            dos_index = 1
            begin = 0

            with zopen(pot_inp, "r") as potfile:
                for line in potfile:
                    if len(pot_readend.findall(line)) > 0:
                        break

                    if begin == 1:
                        begin += 1
                        continue

                    if begin == 2:
                        z_number = int(line.strip().split()[0])
                        ele_name = Element.from_Z(z_number).name
                        if ele_name not in pot_dict:
                            pot_dict[ele_name] = dos_index
                        else:
                            pot_dict[ele_name] = min(dos_index, pot_dict[ele_name])
                        dos_index += 1

                    if len(pot_readstart.findall(line)) > 0:
                        begin = 1
        else:
            pot_string = Potential.pot_string_from_file(feff_inp_file)
            dicts = Potential.pot_dict_from_string(pot_string)
            pot_dict = dicts[0]

        with zopen(ldos_file + "00.dat", "r") as fobject:
            f = fobject.readlines()
        efermi = float(f[0].split()[4])

        dos_energies = []
        ldos = {}

        for i in range(1, len(pot_dict) + 1):
            if len(str(i)) == 1:
                ldos[i] = np.loadtxt("{}0{}.dat".format(ldos_file, i))
            else:
                ldos[i] = np.loadtxt("{}{}.dat".format(ldos_file, i))

        for i in range(0, len(ldos[1])):
            dos_energies.append(ldos[1][i][0])

        all_pdos = []
        vorb = {"s": Orbital.s, "p": Orbital.py, "d": Orbital.dxy,
                "f": Orbital.f0}
        forb = {"s": 0, "p": 1, "d": 2, "f": 3}

        dlength = len(ldos[1])

        for i in range(nsites):
            pot_index = pot_dict[structure.species[i].symbol]
            all_pdos.append(defaultdict(dict))
            for k, v in vorb.items():
                density = [ldos[pot_index][j][forb[k] + 1]
                           for j in range(dlength)]
                updos = density
                downdos = None
                if downdos:
                    all_pdos[-1][v] = {Spin.up: updos, Spin.down: downdos}
                else:
                    all_pdos[-1][v] = {Spin.up: updos}

        pdos = all_pdos
        vorb2 = {0: Orbital.s, 1: Orbital.py, 2: Orbital.dxy, 3: Orbital.f0}
        pdoss = {structure[i]: {v: pdos[i][v]
                                for v in vorb2.values()}
                 for i in range(len(pdos))}

        forb = {"s": 0, "p": 1, "d": 2, "f": 3}

        tdos = [0] * dlength
        for i in range(nsites):
            pot_index = pot_dict[structure.species[i].symbol]
            for v in forb.values():
                density = [ldos[pot_index][j][v + 1] for j in range(dlength)]
                for j in range(dlength):
                    tdos[j] = tdos[j] + density[j]
        tdos = {Spin.up: tdos}

        dos = Dos(efermi, dos_energies, tdos)
        complete_dos = CompleteDos(structure, dos, pdoss)
        charge_transfer = LDos.charge_transfer_from_file(feff_inp_file,
                                                         ldos_file)
        return LDos(complete_dos, charge_transfer)

Creates LDos object from raw Feff ldos files by
    by assuming they are numbered consecutively, i.e. ldos01.dat
    ldos02.dat...

Args:
        feff_inp_file (str): input file of run to obtain structure
        ldos_file (str): output ldos file of run to obtain dos info, etc.


def __init__(self, attribute_values_hash):

    super(FakeIdentifier, self).__init__()
    self.attribute_values_hash = attribute_values_hash

Initializes a fake attribute container identifier.

Args:
        attribute_values_hash (int): hash value of the attribute values.


def get_user_info(self, token):

        url = self.get_user_info_url()

        try:
            headers = {'Authorization': 'Bearer {}'.format(token)}
            response = requests.get(url, headers=headers)
        except requests.RequestException:
            logger.exception('Failed to retrieve user info due to a request exception.')
            raise UserInfoRetrievalFailed

        if response.status_code == 200:
            return self.process_user_info_response(response.json())
        else:
            msg = 'Failed to retrieve user info. Server [{server}] responded with status [{status}].'.format(
                server=url,
                status=response.status_code
            )
            raise UserInfoRetrievalFailed(msg)

Retrieves the user info from the OAuth provider.

Args:
        token (str): OAuth2 access token.

Returns:
        dict

Raises:
        UserInfoRetrievalFailed: Retrieval of user info from the remote server failed.


def spawn_agent(self, agent_definition, location):

        self._should_write_to_command_buffer = True
        self._add_agents(agent_definition)
        command_to_send = SpawnAgentCommand(location, agent_definition.name, agent_definition.type)
        self._commands.add_command(command_to_send)

Queues a spawn agent command. It will be applied when `tick` or `step` is called next.
    The agent won't be able to be used until the next frame.

Args:
        agent_definition (:obj:`AgentDefinition`): The definition of the agent to spawn.
        location (np.ndarray or list): The position to spawn the agent in the world, in XYZ coordinates (in meters).


def mrc_to_marc(mrc):

    # ignore blank lines
    lines = [
        line
        for line in mrc.splitlines()
        if line.strip()
    ]

    def split_to_parts(lines):
        for line in lines:
            first_part, second_part = line.split(" L ", 1)

            yield line, first_part, second_part.lstrip()

    control_lines = []
    data_lines = []
    for line, first_part, second_part in split_to_parts(lines):
        if second_part.startswith("$"):
            data_lines.append(line)
        else:
            control_lines.append(line)

    # convert controlfield lines
    record = MARCXMLRecord()
    record.oai_marc = True
    for line, descr, content in split_to_parts(control_lines):
        record.controlfields[descr.strip()[:3]] = content

    def get_subfield_dict(line):
        fields = (
            (field[0], field[1:])
            for field in line.split("$$")[1:]
        )

        fields_dict = defaultdict(list)
        for key, val in fields:
            fields_dict[key].append(val)

        return fields_dict

    # convert datafield lines
    for line, descr, content_line in split_to_parts(data_lines):
        name = descr[:3]
        i1 = descr[3]
        i2 = descr[4]

        record.add_data_field(
            name,
            i1,
            i2,
            get_subfield_dict(content_line)
        )

    return record.to_XML()

Convert MRC data format to MARC XML.

Args:
        mrc (str): MRC as string.

Returns:
        str: XML with MARC.


def series_with_permutation(self, other):

        combined_permutation = tuple([self.permutation[p]
                                      for p in other.permutation])
        return CPermutation.create(combined_permutation)

Compute the series product with another channel permutation circuit

Args:
        other (CPermutation):

Returns:
        Circuit: The composite permutation circuit (could also be the
            identity circuit for n channels)


def register_instance(self, instance: Any, allow_dotted_names: bool=False):

        if self.instance:
            raise RuntimeError("can only register one instance")
        self.instance = instance
        self.allow_dotted_names = allow_dotted_names
        return True

注册一个实例用于执行,注意只能注册一个.

    Parameters:
        instance (Any): - 将一个类的实例注册到rpc
        allow_dotted_names (bool): 是否允许带`.`号的名字


def get_or_set_section(
            self,
            config,
            section,
            option,
            DEFAULT_VALUE,
            method='get'
    ):

        try:
            if isinstance(DEFAULT_VALUE, str):
                val = DEFAULT_VALUE
            else:
                val = json.dumps(DEFAULT_VALUE)
            if method == 'get':
                return self.get_config(section, option)
            else:
                self.set_config(section, option, val)
                return val

        except:
            self.set_config(section, option, val)
            return val

[summary]

Args:
        config {[type]} -- [description]
        section {[type]} -- [description]
        option {[type]} -- [description]
        DEFAULT_VALUE {[type]} -- [description]

    Keyword Arguments:
        method {str} -- [description] (default: {'get'})

Returns:
        [type] -- [description]


def limit_replace(self, accountID, orderID, **kwargs):

        return self.replace(
            accountID,
            orderID,
            order=LimitOrderRequest(**kwargs)
        )

Shortcut to replace a pending Limit Order in an Account

Args:
        accountID : The ID of the Account
        orderID : The ID of the Limit Order to replace
        kwargs : The arguments to create a LimitOrderRequest

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


def _prefix_from_ip_string(self, ip_str):

        # Parse the netmask/hostmask like an IP address.
        try:
            ip_int = self._ip_int_from_string(ip_str)
        except AddressValueError:
            self._report_invalid_netmask(ip_str)

        # Try matching a netmask (this would be /1*0*/ as a bitwise regexp).
        # Note that the two ambiguous cases (all-ones and all-zeroes) are
        # treated as netmasks.
        try:
            return self._prefix_from_ip_int(ip_int)
        except ValueError:
            pass

        # Invert the bits, and try matching a /0+1+/ hostmask instead.
        ip_int ^= self._ALL_ONES
        try:
            return self._prefix_from_ip_int(ip_int)
        except ValueError:
            self._report_invalid_netmask(ip_str)

Turn a netmask/hostmask string into a prefix length

Args:
        ip_str: The netmask/hostmask to be converted

Returns:
        An integer, the prefix length.

Raises:
        NetmaskValueError: If the input is not a valid netmask/hostmask


def CalculateForecastStats(matched, available, possible=None):

  if matched > 0:
    available_percent = (float(available) / matched) * 100.
  else:
    available_percent = 0

  if possible is not None:
    if matched > 0:
      possible_percent = (possible/float(matched)) * 100.
    else:
      possible_percent = 0
  else:
    possible_percent = None

  return available_percent, possible_percent

Calculate forecast percentage stats.

Args:
        matched: The number of matched impressions.
        available: The number of available impressions.
        possible: The optional number of possible impressions.

Returns:
        The percentage of impressions that are available and possible.


def make_node(cls, lineno, operator, operand, func=None, type_=None):

        assert type_ is None or isinstance(type_, SymbolTYPE)

        if func is not None:  # Try constant-folding
            if is_number(operand):  # e.g. ABS(-5)
                return SymbolNUMBER(func(operand.value), lineno=lineno)
            elif is_string(operand):  # e.g. LEN("a")
                return SymbolSTRING(func(operand.text), lineno=lineno)

        if type_ is None:
            type_ = operand.type_

        if operator == 'MINUS':
            if not type_.is_signed:
                type_ = type_.to_signed()
                operand = SymbolTYPECAST.make_node(type_, operand, lineno)
        elif operator == 'NOT':
            type_ = TYPE.ubyte

        return cls(operator, operand, lineno, type_)

Creates a node for a unary operation. E.g. -x or LEN(a$)

    Parameters:
        -func: lambda function used on constant folding when possible
        -type_: the resulting type (by default, the same as the argument).
            For example, for LEN (str$), result type is 'u16'
            and arg type is 'string'


def _SimpleDecoder(wire_type, decode_value):

  def SpecificDecoder(field_number, is_repeated, is_packed, key, new_default):
    if is_packed:
      local_DecodeVarint = _DecodeVarint
      def DecodePackedField(buffer, pos, end, message, field_dict):
        value = field_dict.get(key)
        if value is None:
          value = field_dict.setdefault(key, new_default(message))
        (endpoint, pos) = local_DecodeVarint(buffer, pos)
        endpoint += pos
        if endpoint > end:
          raise _DecodeError('Truncated message.')
        while pos < endpoint:
          (element, pos) = decode_value(buffer, pos)
          value.append(element)
        if pos > endpoint:
          del value[-1]   # Discard corrupt value.
          raise _DecodeError('Packed element was truncated.')
        return pos
      return DecodePackedField
    elif is_repeated:
      tag_bytes = encoder.TagBytes(field_number, wire_type)
      tag_len = len(tag_bytes)
      def DecodeRepeatedField(buffer, pos, end, message, field_dict):
        value = field_dict.get(key)
        if value is None:
          value = field_dict.setdefault(key, new_default(message))
        while 1:
          (element, new_pos) = decode_value(buffer, pos)
          value.append(element)
          # Predict that the next tag is another copy of the same repeated
          # field.
          pos = new_pos + tag_len
          if buffer[new_pos:pos] != tag_bytes or new_pos >= end:
            # Prediction failed.  Return.
            if new_pos > end:
              raise _DecodeError('Truncated message.')
            return new_pos
      return DecodeRepeatedField
    else:
      def DecodeField(buffer, pos, end, message, field_dict):
        (field_dict[key], pos) = decode_value(buffer, pos)
        if pos > end:
          del field_dict[key]  # Discard corrupt value.
          raise _DecodeError('Truncated message.')
        return pos
      return DecodeField

  return SpecificDecoder

Return a constructor for a decoder for fields of a particular type.

Args:
        wire_type:  The field's wire type.
        decode_value:  A function which decodes an individual value, e.g.
        _DecodeVarint()


def __init__(self, basecache=None):

        self._data = {}

        if basecache is not None:
            for key,val in basecache.items():
                self._data[key] = val

Create a new transient cache.

    Optionally supports populating the cache with values of an
    existing cache.

Args:
        basecache (TransientCache, optional): Cache to populate this new
        cache with.


def users_setPhoto(self, *, image: Union[str, IOBase], **kwargs) -> SlackResponse:

        self._validate_xoxp_token()
        return self.api_call("users.setPhoto", files={"image": image}, data=kwargs)

Set the user profile photo

Args:
        image (str): Supply the path of the image you'd like to upload.
            e.g. 'myimage.png'


def generate_timing_stats(file_list, var_list):

    timing_result = dict()
    timing_summary = dict()
    for file in file_list:
        timing_result[file] = functions.parse_gptl(file, var_list)
    for var in var_list:
        var_time = []
        for f, data in timing_result.items():
            try:
                var_time.append(data[var])
            except:
                continue
        if len(var_time):
            timing_summary[var] = {'mean': np.mean(var_time),
                                   'max': np.max(var_time),
                                   'min': np.min(var_time),
                                   'std': np.std(var_time)}
    return timing_summary

Parse all of the timing files, and generate some statistics
    about the run.

Args:
        file_list: A list of timing files to parse
        var_list: A list of variables to look for in the timing file

Returns:
        A dict containing values that have the form:
            [mean, min, max, mean, standard deviation]


def download(cls, root, check=None):

        path = os.path.join(root, cls.name)
        check = path if check is None else check
        if not os.path.isdir(check):
            for url in cls.urls:
                if isinstance(url, tuple):
                    url, filename = url
                else:
                    filename = os.path.basename(url)
                zpath = os.path.join(path, filename)
                if not os.path.isfile(zpath):
                    if not os.path.exists(os.path.dirname(zpath)):
                        os.makedirs(os.path.dirname(zpath))
                    print('downloading {}'.format(filename))
                    download_from_url(url, zpath)
                zroot, ext = os.path.splitext(zpath)
                _, ext_inner = os.path.splitext(zroot)
                if ext == '.zip':
                    with zipfile.ZipFile(zpath, 'r') as zfile:
                        print('extracting')
                        zfile.extractall(path)
                # tarfile cannot handle bare .gz files
                elif ext == '.tgz' or ext == '.gz' and ext_inner == '.tar':
                    with tarfile.open(zpath, 'r:gz') as tar:
                        dirs = [member for member in tar.getmembers()]
                        tar.extractall(path=path, members=dirs)
                elif ext == '.gz':
                    with gzip.open(zpath, 'rb') as gz:
                        with open(zroot, 'wb') as uncompressed:
                            shutil.copyfileobj(gz, uncompressed)

        return os.path.join(path, cls.dirname)

Download and unzip an online archive (.zip, .gz, or .tgz).

Args:
        root (str): Folder to download data to.
        check (str or None): Folder whose existence indicates
            that the dataset has already been downloaded, or
            None to check the existence of root/{cls.name}.

Returns:
        str: Path to extracted dataset.


def _extract_datasets_to_harvest(cls, report):

        assert isinstance(report, string_types + (list,))

        # Si `report` es una lista de tuplas con longitud 2, asumimos que es un
        # reporte procesado para extraer los datasets a harvestear. Se devuelve
        # intacta.
        if (isinstance(report, list) and all([isinstance(x, tuple) and
                                              len(x) == 2 for x in report])):
            return report

        table = readers.read_table(report)
        table_keys = table[0].keys()
        expected_keys = ["catalog_metadata_url", "dataset_title",
                         "dataset_accrualPeriodicity"]

        # Verifico la presencia de las claves básicas de un config de harvester
        for key in expected_keys:
            if key not in table_keys:
                raise KeyError(.format(key))

        if "harvest" in table_keys:
            # El archivo es un reporte de datasets.
            datasets_to_harvest = [
                (row["catalog_metadata_url"], row["dataset_title"]) for row in
                table if int(row["harvest"])]
        else:
            # El archivo es un config de harvester.
            datasets_to_harvest = [
                (row["catalog_metadata_url"], row["dataset_title"]) for row in
                table]

        return datasets_to_harvest

Extrae de un reporte los datos necesarios para reconocer qué
    datasets marcar para cosecha en cualquier generador.

Args:
        report (str o list): Reporte (lista de dicts) o path a uno.

Returns:
        list: Lista de tuplas con los títulos de catálogo y dataset de cada
        reporte extraído.


def wait_for_endpoint(self, endpoint, poll=5):

        desc = _wait_until(lambda: _deploy_done(self.sagemaker_client, endpoint), poll)
        status = desc['EndpointStatus']

        if status != 'InService':
            reason = desc.get('FailureReason', None)
            raise ValueError('Error hosting endpoint {}: {} Reason: {}'.format(endpoint, status, reason))
        return desc

Wait for an Amazon SageMaker endpoint deployment to complete.

Args:
        endpoint (str): Name of the ``Endpoint`` to wait for.
        poll (int): Polling interval in seconds (default: 5).

Returns:
        dict: Return value from the ``DescribeEndpoint`` API.


def get_structures(self, primitive=True):

        structures = []
        for d in self._cif.data.values():
            try:
                s = self._get_structure(d, primitive)
                if s:
                    structures.append(s)
            except (KeyError, ValueError) as exc:
                # Warn the user (Errors should never pass silently)
                # A user reported a problem with cif files produced by Avogadro
                # in which the atomic coordinates are in Cartesian coords.
                self.errors.append(str(exc))
                warnings.warn(str(exc))
        if self.errors:
            warnings.warn("Issues encountered while parsing CIF:")
            for error in self.errors:
                warnings.warn(error)
        if len(structures) == 0:
            raise ValueError("Invalid cif file with no structures!")
        return structures

Return list of structures in CIF file. primitive boolean sets whether a
    conventional cell structure or primitive cell structure is returned.

Args:
        primitive (bool): Set to False to return conventional unit cells.
            Defaults to True. With magnetic CIF files, will return primitive
            magnetic cell which may be larger than nuclear primitive cell.

Returns:
        List of Structures.


def _augment_observation(self, ob, reward, cumulative_reward):

    img = PIL_Image().new("RGB",
                          (ob.shape[1], self.HEADER_HEIGHT,))
    draw = PIL_ImageDraw().Draw(img)
    draw.text(
        (1, 0), "c:{:3}, r:{:3}".format(int(cumulative_reward), int(reward)),
        fill=(255, 0, 0)
    )
    draw.text(
        (1, 15), "fc:{:3}".format(int(self._frame_counter)),
        fill=(255, 0, 0)
    )
    header = np.asarray(img)
    del img
    header.setflags(write=1)
    # Top row color indicates if WAIT MODE is on.
    if self._wait:
      pixel_fill = (0, 255, 0)
    else:
      pixel_fill = (255, 0, 0)
    header[0, :, :] = pixel_fill
    return np.concatenate([header, ob], axis=0)

Expand observation array with additional information header (top rows).

Args:
        ob: observation
        reward: reward to be included in header.
        cumulative_reward: total cumulated reward to be included in header.

Returns:
        Expanded observation array.


def finish_directory_parse(self):
        # type: () -> None

        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError('UDF File Entry not initialized')

        if self.icb_tag.file_type != 4:
            raise pycdlibexception.PyCdlibInternalError('Can only finish_directory for a directory')

A method to finish up the parsing of this UDF File Entry directory.
    In particular, this method checks to see if it is in sorted order for
    future use.

    Parameters:
    None.

Returns:
    Nothing.


def deep_diff(self, db_data, user_data):

        # NOTE: tcex does include the deepdiff library as a dependencies since it is only
        # required for local testing.
        try:
            from deepdiff import DeepDiff
        except ImportError:
            print('Could not import DeepDiff module (try "pip install deepdiff").')
            sys.exit(1)

        try:
            ddiff = DeepDiff(db_data, user_data, ignore_order=True)
        except KeyError:
            return False
        except NameError:
            return False
        if ddiff:
            self.tcex.log.info(u'[validate] Diff      : {}'.format(ddiff))
            return False
        return True

Validate data in user data.

Args:
        db_data (dict|str|list): The data store in Redis.
        user_data (dict|str|list): The user provided data.

Returns:
        bool: True if the data passed validation.


def RemoveProcessedTaskStorage(self, task):

    if self._storage_type != definitions.STORAGE_TYPE_SESSION:
      raise IOError('Unsupported storage type.')

    processed_storage_file_path = self._GetProcessedStorageFilePath(task)

    try:
      os.remove(processed_storage_file_path)
    except OSError as exception:
      raise IOError((
          'Unable to remove task storage file: {0:s} with error: '
          '{1!s}').format(processed_storage_file_path, exception))

Removes a processed task storage.

Args:
        task (Task): task.

Raises:
        IOError: if the storage type is not supported or
        if the storage file cannot be removed.
        OSError: if the storage type is not supported or
        if the storage file cannot be removed.


def not_storable(_type):

    return Storable(_type, handlers=StorableHandler(poke=fake_poke, peek=fail_peek(_type)))

Helper for tagging unserializable types.

Args:
        _type (type): type to be ignored.

Returns:
        Storable: storable instance that does not poke.


def stage_signature(vcs, signature):

    evidence_path = _get_staged_history_path(vcs)
    staged = get_staged_signatures(vcs)
    if signature in staged:
        raise AlreadyStagedError
    staged.append(signature)
    string = '\n'.join(staged)
    with open(evidence_path, 'w') as f:
        f.write(string)

Add `signature` to the list of staged signatures

Args:
        vcs (easyci.vcs.base.Vcs)
        signature (basestring)

Raises:
        AlreadyStagedError


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

        self.flow = flow
        self.max_njobs_inqueue = kwargs.get("max_njobs_inqueue", 200)

Initialize the object

Args:
        flow: :class:`Flow` object
        max_njobs_inqueue: The launcher will stop submitting jobs when the
            number of jobs in the queue is >= Max number of jobs