def run(self):
    ctx = FSM.Context(self.name, self.device)
    transition_counter = 0
    timeout = self.timeout
    self.log('{} Start'.format(self.name))
    while (transition_counter < self.max_transitions):
        transition_counter += 1
        try:
            start_time = time()
            if (self.init_pattern is None):
                ctx.event = self.ctrl.expect(self.events, searchwindowsize=self.searchwindowsize, timeout=timeout)
            else:
                self.log('INIT_PATTERN={}'.format(pattern_to_str(self.init_pattern)))
                try:
                    ctx.event = self.events.index(self.init_pattern)
                except ValueError:
                    self.log('INIT_PATTERN unknown.')
                    continue
                finally:
                    self.init_pattern = None
            finish_time = (time() - start_time)
            key = (ctx.event, ctx.state)
            ctx.pattern = self.events[ctx.event]
            if (key in self.transition_table):
                transition = self.transition_table[key]
                (next_state, action_instance, next_timeout) = transition
                self.log('E={},S={},T={},RT={:.2f}'.format(ctx.event, ctx.state, timeout, finish_time))
                if (callable(action_instance) and (not isclass(action_instance))):
                    if (not action_instance(ctx)):
                        self.log('Error: {}'.format(ctx.msg))
                        return False
                elif isinstance(action_instance, Exception):
                    self.log('A=Exception {}'.format(action_instance))
                    raise action_instance
                elif (action_instance is None):
                    self.log('A=None')
                else:
                    self.log('FSM Action is not callable: {}'.format(str(action_instance)))
                    raise RuntimeWarning('FSM Action is not callable')
                if (next_timeout != 0):
                    timeout = next_timeout
                ctx.state = next_state
                self.log('NS={},NT={}'.format(next_state, timeout))
            else:
                self.log('Unknown transition: EVENT={},STATE={}'.format(ctx.event, ctx.state))
                continue
        except EOF:
            raise ConnectionError('Session closed unexpectedly', self.ctrl.hostname)
        if (ctx.finished or (next_state == (- 1))):
            self.log('{} Stop at E={},S={}'.format(self.name, ctx.event, ctx.state))
            return True
    self.log('FSM looped. Exiting')
    return False

Start the FSM.

Returns:
boolean: True if FSM reaches the last state or false if the exception or error message was raised


def _handle_request_error(self, orig_request, error, start_response):

    headers = [('Content-Type', 'application/json')]
    status_code = error.status_code()
    body = error.rest_error()

    response_status = '%d %s' % (status_code,
                                 httplib.responses.get(status_code,
                                                       'Unknown Error'))
    cors_handler = self._create_cors_handler(orig_request)
    return util.send_wsgi_response(response_status, headers, body,
                                   start_response, cors_handler=cors_handler)

Handle a request error, converting it to a WSGI response.

Args:
orig_request: An ApiRequest, the original request from the user.
error: A RequestError containing information about the error.
start_response: A function with semantics defined in PEP-333.

Returns:
A string containing the response body.


async def _on_progress_notification(self, progress):
    conn_string = progress.get('connection_string')
    done = progress.get('done_count')
    total = progress.get('total_count')
    operation = progress.get('operation')
    (await self.notify_progress(conn_string, operation, done, total, wait=True))

Callback function called when a progress notification is received.

Args:
progress (dict): The received notification containing the progress information


def bind_queues(self, bindings):
    channel = (yield self._allocate_channel())
    try:
        for binding in bindings:
            try:
                (yield channel.queue_bind(**binding))
            except pika.exceptions.ChannelClosed as e:
                raise BadDeclaration('binding', binding, e)
    finally:
        try:
            channel.close()
        except pika.exceptions.AMQPError:
            pass

Declare a set of bindings between queues and exchanges.

Args:
bindings (list of dict): A list of binding definitions. Each dictionary
must contain the "queue" key whose value is the name of the queue
to create the binding on, as well as the "exchange" key whose value
should be the name of the exchange to bind to. Additional acceptable
keys are any keyword arguments accepted by
:meth:`pika.channel.Channel.queue_bind`.

Raises:
NoFreeChannels: If there are no available channels on this connection.
If this occurs, you can either reduce the number of consumers on this
connection or create an additional connection.
BadDeclaration: If a binding could not be declared. This can occur if the
queue or exchange don't exist, or if they do, but the current user does
not have permissions to create bindings.


def timeout(coro, timeout=None, loop=None):

    @asyncio.coroutine
    def _timeout(coro):
        return (yield from asyncio.wait_for(coro, timeout, loop=loop))

    @asyncio.coroutine
    def wrapper(*args, **kw):
        return (yield from _timeout(coro(*args, **kw)))
    return (_timeout(coro) if asyncio.iscoroutine(coro) else wrapper)

Wraps a given coroutine function, that when executed, if it takes more
than the given timeout in seconds to execute, it will be canceled and
raise an `asyncio.TimeoutError`.

This function is equivalent to Python standard
`asyncio.wait_for()` function.

This function can be used as decorator.

Arguments:
coro (coroutinefunction|coroutine): coroutine to wrap.
timeout (int|float): max wait timeout in seconds.
loop (asyncio.BaseEventLoop): optional event loop to use.

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

Returns:
coroutinefunction: wrapper coroutine function.

Usage::

await paco.timeout(coro, timeout=10)


def get_session(db_url):
    engine = create_engine(db_url, poolclass=NullPool, echo=False)
    Session = sessionmaker(bind=engine)
    Base.metadata.create_all(engine)
    return Session()

Gets SQLAlchemy session given url. Your tables must inherit
from Base in hdx.utilities.database.

Args:
db_url (str): SQLAlchemy url

Returns:
sqlalchemy.orm.session.Session: SQLAlchemy session


def mesh2fc(script, all_visible_layers=False):
    filter_xml = ''.join(['  <filter name="Transfer Color: Mesh to Face">\n', '    <Param name="allVisibleMesh" ', ('value="%s" ' % str(all_visible_layers).lower()), 'description="Apply to all Meshes" ', 'type="RichBool" ', '/>\n', '  </filter>\n'])
    util.write_filter(script, filter_xml)
    return None

Transfer mesh colors to face colors

Args:
script: the FilterScript object or script filename to write
the filter to.
all_visible_layers (bool): If true the color mapping is applied to all the meshes


def set_computer_desc(desc=None):

    if six.PY2:
        desc = _to_unicode(desc)

    system_info = win32net.NetServerGetInfo(None, 101)

    if desc is None:
        return False

    system_info['comment'] = desc

    try:
        win32net.NetServerSetInfo(None, 101, system_info)
    except win32net.error as exc:
        (number, context, message) = exc.args
        log.error('Failed to update system')
        log.error('nbr: %s', number)
        log.error('ctx: %s', context)
        log.error('msg: %s', message)
        return False

    return {'Computer Description': get_computer_desc()}

Set the Windows computer description

Args:

desc (str):
The computer description

Returns:
str: Description if successful, otherwise ``False``

CLI Example:

.. code-block:: bash

salt 'minion-id' system.set_computer_desc 'This computer belongs to Dave!'


def GetDisplayNameForPathSpec(self, path_spec):

    return path_helper.PathHelper.GetDisplayNameForPathSpec(
        path_spec, mount_path=self._mount_path, text_prepend=self._text_prepend)

Retrieves the display name for a path specification.

Args:
path_spec (dfvfs.PathSpec): path specification.

Returns:
str: human readable version of the path specification.


def run(self, args, options):

        config.LOGGER.info('In SushiChef.run method. args=' + str(args) + 'options=' + str(options))
        self.pre_run(args, options)
        uploadchannel_wrapper(self, args, options)

This function calls uploadchannel which performs all the run steps:
Args:
args (dict): chef command line arguments
options (dict): additional compatibility mode options given on command line


def get(self):
    if self._n < 2:
        return float('nan')
    dof = self._n - 1
    return math.sqrt(self._m2 / dof)

Returns the current incremental standard deviation.

Returns:
float: The current incremental standard deviation value.
Returns NaN if fewer than 2 valid (non-NaN) values have been pushed.


def get_tiny_config(config_class, model_class=None, **model_tester_kwargs):
    model_type = config_class.model_type
    config_source_file = inspect.getsourcefile(config_class)
    modeling_name = config_source_file.split(os.path.sep)[-1].replace('configuration_', '').replace('.py', '')
    try:
        print('Importing', model_type_to_module_name(model_type))
        module_name = model_type_to_module_name(model_type)
        if not modeling_name.startswith(module_name):
            raise ValueError(f"{modeling_name} doesn't start with {module_name}!")
        test_file = os.path.join('tests', 'models', module_name, f'test_modeling_{modeling_name}.py')
        models_to_model_testers = get_model_to_tester_mapping(test_file)
        model_tester_class = None
        tester_classes = []
        if model_class is not None:
            tester_classes = get_tester_classes_for_model(test_file, model_class)
        else:
            for _tester_classes in models_to_model_testers.values():
                tester_classes.extend(_tester_classes)
        if len(tester_classes) > 0:
            model_tester_class = sorted(tester_classes, key=lambda x: (len(x.__name__), x.__name__))[0]
    except ModuleNotFoundError:
        error = f'Tiny config not created for {model_type} - cannot find the testing module from the model name.'
        raise ValueError(error)
    if model_tester_class is None:
        error = f'Tiny config not created for {model_type} - no model tester is found in the testing module.'
        raise ValueError(error)
    if 'vocab_size' in model_tester_kwargs:
        if 'text_kwargs' in inspect.signature(model_tester_class.__init__).parameters.keys():
            vocab_size = model_tester_kwargs.pop('vocab_size')
            model_tester_kwargs['text_kwargs'] = {'vocab_size': vocab_size}
    model_tester = model_tester_class(parent=None, **model_tester_kwargs)
    if hasattr(model_tester, 'get_pipeline_config'):
        config = model_tester.get_pipeline_config()
    elif hasattr(model_tester, 'prepare_config_and_inputs'):
        config = model_tester.prepare_config_and_inputs()[0]
    elif hasattr(model_tester, 'get_config'):
        config = model_tester.get_config()
    else:
        error = f'Tiny config not created for {model_type} - the model tester {model_tester_class.__name__} lacks necessary method to create config.'
        raise ValueError(error)
    max_positions = []
    for key in ['max_position_embeddings', 'max_source_positions', 'max_target_positions']:
        if getattr(config, key, 0) > 0:
            max_positions.append(getattr(config, key))
        if getattr(config, 'text_config', None) is not None:
            if getattr(config.text_config, key, None) is not None:
                max_positions.append(getattr(config.text_config, key))
    if len(max_positions) > 0:
        max_position = max(200, min(max_positions))
        for key in ['max_position_embeddings', 'max_source_positions', 'max_target_positions']:
            if getattr(config, key, 0) > 0:
                setattr(config, key, max_position)
            if getattr(config, 'text_config', None) is not None:
                if getattr(config.text_config, key, None) is not None:
                    setattr(config.text_config, key, max_position)
    return config

Retrieve a tiny configuration from `config_class` using each model's `ModelTester`.

Args:
config_class: Subclass of `PreTrainedConfig`.

Returns:
An instance of `config_class` with tiny hyperparameters


def receive_data(socket):
    answer = b''
    while True:
        packet = socket.recv(4096)
        if (not packet):
            break
        answer += packet
    response = pickle.loads(answer)
    socket.close()
    return response

Receive an answer from the daemon and return the response.

Args:
socket (socket.socket): A socket that is connected to the daemon.

Returns:
dir or string: The unpickled answer.


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

        init_params = super(RLEstimator, cls)\
            ._prepare_init_params_from_job_description(job_details, model_channel_name)

        image_name = init_params.pop('image')
        framework, _, tag, _ = fw_utils.framework_name_from_image(image_name)

        if not framework:

            init_params['image_name'] = image_name
            return init_params

        toolkit, toolkit_version = cls._toolkit_and_version_from_tag(tag)

        if not cls._is_combination_supported(toolkit, toolkit_version, framework):
            training_job_name = init_params['base_job_name']
            raise ValueError(
                "Training job: {} didn't use image for requested framework".format(
                    training_job_name)
            )

        init_params['toolkit'] = RLToolkit(toolkit)
        init_params['toolkit_version'] = toolkit_version
        init_params['framework'] = RLFramework(framework)

        return init_params

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

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

Returns:
dictionary: The transformed init_params


def fetch_s3_package(self, config):

        extractor_map = {'.tar.gz': TarGzipExtractor,
                         '.tar': TarExtractor,
                         '.zip': ZipExtractor}
        extractor = None
        for suffix, klass in extractor_map.items():
            if config['key'].endswith(suffix):
                extractor = klass()
                logger.debug("Using extractor %s for S3 object \"%s\" in "
                             "bucket %s.",
                             klass.__name__,
                             config['key'],
                             config['bucket'])
                dir_name = self.sanitize_uri_path(
                    "s3-%s-%s" % (config['bucket'],
                                  config['key'][:-len(suffix)])
                )
                break

        if extractor is None:
            raise ValueError(
                "Archive type could not be determined for S3 object \"%s\" "
                "in bucket %s." % (config['key'], config['bucket'])
            )

        session = get_session(region=None)
        extra_s3_args = {}
        if config.get('requester_pays', False):
            extra_s3_args['RequestPayer'] = 'requester'

        if config.get('use_latest', True):
            try:

                modified_date = session.client('s3').head_object(
                    Bucket=config['bucket'],
                    Key=config['key'],
                    **extra_s3_args
                )['LastModified'].astimezone(dateutil.tz.tzutc())
            except botocore.exceptions.ClientError as client_error:
                logger.error("Error checking modified date of "
                             "s3:
                             config['bucket'],
                             config['key'],
                             client_error)
                sys.exit(1)
            dir_name += "-%s" % modified_date.strftime(self.ISO8601_FORMAT)
        cached_dir_path = os.path.join(self.package_cache_dir, dir_name)
        if not os.path.isdir(cached_dir_path):
            logger.debug("Remote package s3:
                         "been previously downloaded - starting download and "
                         "extraction to %s",
                         config['bucket'],
                         config['key'],
                         cached_dir_path)
            tmp_dir = tempfile.mkdtemp(prefix='stacker')
            tmp_package_path = os.path.join(tmp_dir, dir_name)
            try:
                extractor.set_archive(os.path.join(tmp_dir, dir_name))
                logger.debug("Starting remote package download from S3 to %s "
                             "with extra S3 options \"%s\"",
                             extractor.archive,
                             str(extra_s3_args))
                session.resource('s3').Bucket(config['bucket']).download_file(
                    config['key'],
                    extractor.archive,
                    ExtraArgs=extra_s3_args
                )
                logger.debug("Download complete; extracting downloaded "
                             "package to %s",
                             tmp_package_path)
                extractor.extract(tmp_package_path)
                logger.debug("Moving extracted package directory %s to the "
                             "Stacker cache at %s",
                             dir_name,
                             self.package_cache_dir)
                shutil.move(tmp_package_path, self.package_cache_dir)
            finally:
                shutil.rmtree(tmp_dir)
        else:
            logger.debug("Remote package s3:
                         "been previously downloaded to %s -- bypassing "
                         "download",
                         config['bucket'],
                         config['key'],
                         cached_dir_path)

        self.update_paths_and_config(config=config,
                                     pkg_dir_name=dir_name)

Make a remote S3 archive available for local use.

Args:
config (dict): git config dictionary


def get_models(self, model, page=None):
    if (page is not None):
        return self._store.find_all(self._get_model_class(model), params={'page': int(page)})
    else:
        return self._store.find_all(self._get_model_class(model))

Get all the models from the server.

Args:
model (string): The class as a string.
page (string, optional): The page number as a string

Returns:
list: A list of instances of the requested model.


def load_ner_model(lang="en", version="2"):

  src_dir = "ner{}".format(version)
  p = locate_resource(src_dir, lang)
  fh = _open(p)
  try:
    return pickle.load(fh)
  except UnicodeDecodeError:
    fh.seek(0)
    return pickle.load(fh, encoding='latin1')

Return a named entity extractor parameters for `lang` and of version `version`

Args:
lang (string): language code.
version (string): version of the parameters to be used.


def _tf_glue_convert_examples_to_features(examples: tf.data.Dataset, tokenizer: PreTrainedTokenizer, task=str, max_length: Optional[int]=None) -> tf.data.Dataset:
    processor = glue_processors[task]()
    examples = [processor.tfds_map(processor.get_example_from_tensor_dict(example)) for example in examples]
    features = glue_convert_examples_to_features(examples, tokenizer, max_length=max_length, task=task)
    label_type = tf.float32 if task == 'sts-b' else tf.int64

    def gen():
        for ex in features:
            d = {k: v for k, v in asdict(ex).items() if v is not None}
            label = d.pop('label')
            yield (d, label)
    input_names = tokenizer.model_input_names
    return tf.data.Dataset.from_generator(gen, (dict.fromkeys(input_names, tf.int32), label_type), ({k: tf.TensorShape([None]) for k in input_names}, tf.TensorShape([])))

Returns:
A `tf.data.Dataset` containing the task-specific features.


def recode_wgsim_reads(
        rnf_fastq_fo,
        fai_fo,
        genome_id,
        wgsim_fastq_1_fn,
        wgsim_fastq_2_fn=None,
        number_of_read_tuples=10**9,
    ):

        wgsim_pattern = re.compile(
            '@(.*)_([0-9]+)_([0-9]+)_([0-9]+):([0-9]+):([0-9]+)_([0-9]+):([0-9]+):([0-9]+)_([0-9a-f]+)/([12])'
        )

        fai_index = rnftools.utils.FaIdx(fai_fo)
        read_tuple_id_width = len(format(number_of_read_tuples, 'x'))

        last_read_tuple_name = None

        fq_creator = rnftools.rnfformat.FqCreator(
            fastq_fo=rnf_fastq_fo,
            read_tuple_id_width=read_tuple_id_width,
            genome_id_width=2,
            chr_id_width=fai_index.chr_id_width,
            coor_width=fai_index.coor_width,
            info_reads_in_tuple=True,
            info_simulator="wgsim",
        )

        reads_in_tuple = 2
        if wgsim_fastq_2_fn is None:
            reads_in_tuple = 1

        i = 0
        with open(wgsim_fastq_1_fn, "r+") as f_inp_1:
            if reads_in_tuple == 2:

                f_inp_2 = open(wgsim_fastq_2_fn)

            for line_a in f_inp_1:
                lines = [line_a.strip()]
                if reads_in_tuple == 2:
                    lines.append(f_inp_2.readline().strip())

                if i % 4 == 0:
                    segments = []

                    m = wgsim_pattern.search(lines[0])
                    if m is None:
                        rnftools.utils.error(
                            "Read tuple '{}' was not generated by WgSim.".format(lines[0][1:]), program="RNFtools",
                            subprogram="MIShmash", exception=ValueError
                        )

                    contig_name = m.group(1)
                    start_1 = int(m.group(2))
                    end_2 = int(m.group(3))
                    errors_1 = int(m.group(4))
                    substitutions_1 = int(m.group(5))
                    indels_1 = int(m.group(6))
                    errors_2 = int(m.group(7))
                    substitutions_2 = int(m.group(8))
                    indels_2 = int(m.group(9))
                    read_tuple_id_w = int(m.group(10), 16)
                    pair = int(m.group(11))

                    chr_id = fai_index.dict_chr_ids[contig_name] if fai_index.dict_chr_ids != {} else "0"

                    if start_1 < end_2:
                        direction_1 = "F"
                        direction_2 = "R"
                    else:
                        direction_1 = "R"
                        direction_2 = "F"

                    segment1 = rnftools.rnfformat.Segment(
                        genome_id=genome_id,
                        chr_id=chr_id,
                        direction=direction_1,
                        left=start_1,
                        right=0,
                    )

                    segment2 = rnftools.rnfformat.Segment(
                        genome_id=genome_id,
                        chr_id=chr_id,
                        direction=direction_2,
                        left=0,
                        right=end_2,
                    )

                elif i % 4 == 1:
                    bases = lines[0]
                    if reads_in_tuple == 2:
                        bases2 = lines[1]

                elif i % 4 == 2:
                    pass

                elif i % 4 == 3:
                    qualities = lines[0]
                    if reads_in_tuple == 2:
                        qualities2 = lines[1]

                    if reads_in_tuple == 1:
                        fq_creator.add_read(
                            read_tuple_id=i
                            bases=bases,
                            qualities=qualities,
                            segments=[segment1, segment2],
                        )
                    else:
                        fq_creator.add_read(
                            read_tuple_id=i
                            bases=bases,
                            qualities=qualities,
                            segments=[segment1],
                        )
                        fq_creator.add_read(
                            read_tuple_id=i
                            bases=bases2,
                            qualities=qualities2,
                            segments=[segment2],
                        )

                i += 1

        fq_creator.flush_read_tuple()

Convert WgSim FASTQ files to RNF FASTQ files.

Args:
rnf_fastq_fo (file): File object of the target RNF file.
fai_fo (file): File object of FAI index of the reference genome.
genome_id (int): RNF genome ID.
wgsim_fastq_1_fn (str): File name of the first WgSim FASTQ file.
wgsim_fastq_2_fn (str): File name of the second WgSim FASTQ file.
number_of_read_tuples (int): Expected number of read tuples (to estimate widths).


def _transform_variable_to_expression(expression, node, context):

    variable_name = expression.variable_name
    if not variable_name.startswith(u'$'):
        raise AssertionError(u'Unexpectedly received variable name {} that is not '
                             u'prefixed with "$"'.format(variable_name))
    return bindparam(variable_name[1:])

Transform a Variable compiler expression into its SQLAlchemy expression representation.

Args:
expression: expression, Variable compiler expression.
node: SqlNode, the SqlNode the expression applies to.
context: CompilationContext, global compilation state and metadata.

Returns:
Expression, SQLAlchemy expression.


def load(self, source, filepath=None):
    try:
        self._path = source.name
    except AttributeError:
        self._path = filepath
    try:
        source_content = source.read()
    except AttributeError:
        source_content = source
    parser = TinycssSourceParser()
    self._datas = parser.parse(source_content)
    serializer = ManifestSerializer()
    references = serializer.serialize(self._datas)
    self.metas = serializer._metas
    for (k, v) in references.items():
        self.set_rule(k, v)
    return self._datas

Load source as manifest attributes

Arguments:
source (string or file-object): CSS source to parse and serialize
to find metas and rules. It can be either a string or a
file-like object (aka with a ``read()`` method which return
string).

Keyword Arguments:
filepath (string): Optional filepath to memorize if source comes
from a file. Default is ``None`` as if source comes from a
string. If ``source`` argument is a file-like object, you
should not need to bother of this argument since filepath will
be filled from source ``name`` attribute.

Returns:
dict: Dictionnary of serialized rules.


def process_new_issues(self, volumes, existing_issues):

        new_issues = {}
        for issue_id, volume in volumes.items():
            state = EBSIssueState.DETECTED.value

            if issue_id in existing_issues:
                issue = existing_issues[issue_id]

                data = {
                    'state': state,
                    'notes': issue.notes,
                    'last_notice': issue.last_notice
                }
                if issue.update(data):
                    new_issues.setdefault(issue.volume.account, []).append(issue)
                    self.log.debug('Updated EBSVolumeAuditIssue {}'.format(
                        issue_id
                    ))

            else:
                properties = {
                    'volume_id': volume.id,
                    'account_id': volume.account_id,
                    'location': volume.location,
                    'state': state,
                    'last_change': datetime.now(),
                    'last_notice': None,
                    'notes': []
                }

                issue = EBSVolumeAuditIssue.create(issue_id, properties=properties)
                new_issues.setdefault(issue.volume.account, []).append(issue)

        return new_issues

Takes a dict of existing volumes missing tags and a dict of existing issues, and finds any new or updated
issues.

Args:
volumes (:obj:`dict` of `str`: `EBSVolume`): Dict of current volumes with issues
existing_issues (:obj:`dict` of `str`: `EBSVolumeAuditIssue`): Current list of issues

Returns:
:obj:`dict` of `str`: `EBSVolumeAuditIssue`


def write_value(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):

        try:
            ostream.write(pack('!Q', self.value))
        except Exception:
            self.logger.error("Error writing boolean value to buffer")
            raise

Write the value of the Boolean object to the output stream.

Args:
ostream (Stream): A buffer to contain the encoded bytes of the
value of a Boolean object. Usually a BytearrayStream object.
Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.


def __init__(self, op_type):
    if not isinstance(op_type, str):
        raise TypeError('op_type must be a string')
    self._op_type = op_type

Creates a new decorator with `op_type` as the Operation type.

Args:
op_type: The string type of an operation. This corresponds to the
`OpDef.name` field for the proto that defines the operation.

Raises:
TypeError: If `op_type` is not string.


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

Generate a guest session id.

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


def _config_net_topology(self, conf):
    conf = self._init_net_specs(conf)
    mgmts = self._select_mgmt_networks(conf)
    self._validate_netconfig(conf)
    (allocated_subnets, conf) = self._allocate_subnets(conf)
    try:
        self._add_mgmt_to_domains(conf, mgmts)
        self._register_preallocated_ips(conf)
        self._allocate_ips_to_nics(conf)
        self._set_mtu_to_nics(conf)
        self._add_dns_records(conf, mgmts)
    except:
        self._subnet_store.release(allocated_subnets)
        raise
    return conf

Initialize and populate all the network related elements, like
reserving ips and populating network specs of the given confiiguration
spec

Args:
conf (dict): Configuration spec to initalize

Returns:
None


def get_config_file(program, system_wide=False):

	program_config_homes = get_config_dir(program, system_wide)
	config_homes = get_config_dir(system_wide=system_wide)
	config_files = []

	for home in config_homes:
		for sub in os.listdir(home):
			if os.path.isfile(os.path.join(home, sub)):
				if sub.startswith(program):
					config_files.append(os.path.join(home, sub))

	if not program.startswith('.'):
		config_files.extend(get_config_file('.' + program, system_wide))

	for home in program_config_homes:
		for sub in os.listdir(home):
			if os.path.isfile(os.path.join(home, sub)
							  ) and sub.startswith(program):
				config_files.append(os.path.join(home, sub))

	return config_files

Get the configuration file for a program.

Gets the configuration file for a given program, assuming it stores it in
a standard location. See also :func:`get_config_dir()`.

Args:
program	 (str): The program for which to get the configuration file.
system_wide (bool):Whether to get the system-wide file for the program.

Returns:
list: A list of all matching configuration files found.


def traverse_postorder(self, leaves=True, internal=True):
    for node in self.root.traverse_postorder(leaves=leaves, internal=internal):
        (yield node)

Perform a postorder traversal of the ``Node`` objects in this ``Tree``

Args:
``leaves`` (``bool``): ``True`` to include leaves, otherwise ``False``

``internal`` (``bool``): ``True`` to include internal nodes, otherwise ``False``


def _build_param_string(params):
    pairs = []
    for (key, value) in params.iteritems():
        if (value is None):
            value = ''
        pairs.append('{0}={1}'.format(key, value))
    if (len(pairs) > 0):
        return '?{0}'.format('&'.join(pairs))
    return ''

Build query params string from a dictionary.

Args:
params (dict): A dictionary of params

Returns:
string: A valid url query params string.


def _table_viewer(table, rows_per_page=25, fields=None):
    if (not table.exists()):
        raise Exception(('Table %s does not exist' % table.full_name))
    if (not table.is_listable()):
        return 'Done'
    _HTML_TEMPLATE = u'\n
{static_table}
\n
{meta_data}
\n    \n

Return a table viewer.

This includes a static rendering of the first page of the table, that gets replaced
by the charting code in environments where Javascript is executable and BQ is available.

Args:
table: the table to view.
rows_per_page: how many rows to display at one time.
fields: an array of field names to display; default is None which uses the full schema.
Returns:
A string containing the HTML for the table viewer.


def get_subscription_from_cli(name=None):
    home = os.path.expanduser('~')
    azure_profile_path = ((((home + os.sep) + '.azure') + os.sep) + 'azureProfile.json')
    if (os.path.isfile(azure_profile_path) is False):
        print(('Error from get_subscription_from_cli(): Cannot find ' + azure_profile_path))
        return None
    with io.open(azure_profile_path, 'r', encoding='utf-8-sig') as azure_profile_fd:
        azure_profile = json.load(azure_profile_fd)
    for subscription_info in azure_profile['subscriptions']:
        if (((name is None) and (subscription_info['isDefault'] is True)) or (subscription_info['name'] == name)):
            return subscription_info['id']
    return None

Get the default, or named, subscription id from CLI's local cache.

Args:
name (str): Optional subscription name. If this is set, the subscription id of the named
subscription is returned from the CLI cache if present. If not set, the subscription id
of the default subscription is returned.

Returns:
Azure subscription ID string.

Requirements:
User has run 'az login' once, or is in Azure Cloud Shell.


def setup_lookup_table( self, hamiltonian='nearest-neighbour' ):

        expected_hamiltonian_values = [ 'nearest-neighbour', 'coordination_number' ]
        if hamiltonian not in expected_hamiltonian_values:
            raise ValueError
        self.lattice.jump_lookup_table = lookup_table.LookupTable( self.lattice, hamiltonian )

Create a jump-probability look-up table corresponding to the appropriate Hamiltonian.

Args:
hamiltonian (Str, optional): String specifying the simulation Hamiltonian.
valid values are 'nearest-neighbour' (default) and 'coordination_number'.

Returns:
None


def __init__(self, path, encoding='utf-8'):

    super(FileOutputWriter, self).__init__(encoding=encoding)
    self._file_object = None
    self._path = path

Initializes an output writer.

Args:
path (str): name of the path.
encoding (Optional[str]): input encoding.


def tokenize(self, text, never_split=None):
    never_split = self.never_split.union(set(never_split)) if never_split else self.never_split
    text = self._clean_text(text)
    if self.tokenize_chinese_chars:
        text = self._tokenize_chinese_chars(text)
    unicode_normalized_text = unicodedata.normalize('NFC', text)
    orig_tokens = whitespace_tokenize(unicode_normalized_text)
    split_tokens = []
    for token in orig_tokens:
        if token not in never_split:
            if self.do_lower_case:
                token = token.lower()
                if self.strip_accents is not False:
                    token = self._run_strip_accents(token)
            elif self.strip_accents:
                token = self._run_strip_accents(token)
        split_tokens.extend(self._run_split_on_punc(token, never_split))
    output_tokens = whitespace_tokenize(' '.join(split_tokens))
    return output_tokens

Basic Tokenization of a piece of text. For sub-word tokenization, see WordPieceTokenizer.

Args:
never_split (`List[str]`, *optional*)
Kept for backward compatibility purposes. Now implemented directly at the base class level (see
[`PreTrainedTokenizer.tokenize`]) List of token not to split.


def build_one_definition_example(self, def_name):
    if (def_name in self.definitions_example.keys()):
        return True
    elif (def_name not in self.specification['definitions'].keys()):
        return False
    self.definitions_example[def_name] = {}
    def_spec = self.specification['definitions'][def_name]
    if ((def_spec.get('type') == 'array') and ('items' in def_spec)):
        item = self.get_example_from_prop_spec(def_spec['items'])
        self.definitions_example[def_name] = [item]
        return True
    if ('properties' not in def_spec):
        self.definitions_example[def_name] = self.get_example_from_prop_spec(def_spec)
        return True
    for (prop_name, prop_spec) in def_spec['properties'].items():
        example = self.get_example_from_prop_spec(prop_spec)
        if (example is None):
            return False
        self.definitions_example[def_name][prop_name] = example
    return True

Build the example for the given definition.

Args:
def_name: Name of the definition.

Returns:
True if the example has been created, False if an error occured.


def get_text_features(self, input_ids: Optional[torch.Tensor]=None, attention_mask: Optional[torch.Tensor]=None, position_ids: Optional[torch.Tensor]=None, return_dict: Optional[bool]=None) -> torch.FloatTensor:
    return_dict = return_dict if return_dict is not None else self.config.use_return_dict
    text_outputs = self.text_model(input_ids=input_ids, attention_mask=attention_mask, position_ids=position_ids, return_dict=return_dict)
    pooled_output = text_outputs[1]
    text_features = self.text_projection(pooled_output)
    return text_features

Returns:
text_features (`torch.FloatTensor` of shape `(batch_size, output_dim`): The text embeddings obtained by
applying the projection layer to the pooled output of [`BlipTextModel`].

Examples:

```python
>>> from transformers import AutoProcessor, BlipModel

>>> model = BlipModel.from_pretrained("Salesforce/blip-image-captioning-base")
>>> processor = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-base")

>>> inputs = processor(text=["a photo of a cat", "a photo of a dog"], padding=True, return_tensors="pt")
>>> text_features = model.get_text_features(**inputs)
```


def get_module_action(self, module):
    f = module.full_path
    if f in self.filenames:
        action = Action.CHECK
        report = logging.warning
    else:
        action = Action.INFER
        report = logging.info
    if not module.name.startswith('pytype_extensions.') and module.kind in ('Builtin', 'System'):
        action = Action.GENERATE_DEFAULT
        report('%s: %s module %s', action, module.kind, module.name)
    return action

Get the action for the given module.

Args:
module: A module_utils.Module object.

Returns:
An Action object, or None for a non-Python file.


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

Parse configuration options and return a configuration object.

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

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

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


def remove_event_handler(self, handler, event_name):

        if event_name not in self._event_handlers:
            raise ValueError("Input event name '{}' does not exist".format(event_name))

        new_event_handlers = [(h, args, kwargs) for h, args, kwargs in self._event_handlers[event_name]
                              if h != handler]
        if len(new_event_handlers) == len(self._event_handlers[event_name]):
            raise ValueError("Input handler '{}' is not found among registered event handlers".format(handler))
        self._event_handlers[event_name] = new_event_handlers

Remove event handler `handler` from registered handlers of the engine

Args:
handler (callable): the callable event handler that should be removed
event_name: The event the handler attached to.


def to_obj(self, wd=False, pack=False, relpath=None):
    self._closed()
    obj = CommentedMap()
    obj['cwlVersion'] = 'v1.0'
    obj['class'] = 'Workflow'
    try:
        obj['doc'] = self.documentation
    except (AttributeError, ValueError):
        pass
    try:
        obj['label'] = self.label
    except (AttributeError, ValueError):
        pass
    if self._has_requirements():
        obj['requirements'] = []
    if self.has_workflow_step:
        obj['requirements'].append({'class': 'SubworkflowFeatureRequirement'})
    if self.has_scatter_requirement:
        obj['requirements'].append({'class': 'ScatterFeatureRequirement'})
    if self.has_multiple_inputs:
        obj['requirements'].append({'class': 'MultipleInputFeatureRequirement'})
    obj['inputs'] = self.wf_inputs
    obj['outputs'] = self.wf_outputs
    steps_obj = CommentedMap()
    for key in self.wf_steps:
        steps_obj[key] = self.wf_steps[key].to_obj(relpath=relpath, pack=pack, wd=wd)
    obj['steps'] = steps_obj
    return obj

Return the created workflow as a dict.

The dict can be written to a yaml file.

Returns:
A yaml-compatible dict representing the workflow.


def _mask(self, tensor, length, padding_value=0):
    with tf.name_scope('mask'):
        range_ = tf.range(tensor.shape[1].value)
        mask = (range_[(None, :)] < length[(:, None)])
        if (tensor.shape.ndims > 2):
            for _ in range((tensor.shape.ndims - 2)):
                mask = mask[(..., None)]
            mask = tf.tile(mask, ([1, 1] + tensor.shape[2:].as_list()))
        masked = tf.where(mask, tensor, (padding_value * tf.ones_like(tensor)))
        return tf.check_numerics(masked, 'masked')

Set padding elements of a batch of sequences to a constant.

Useful for setting padding elements to zero before summing along the time
dimension, or for preventing infinite results in padding elements.

Args:
tensor: Tensor of sequences.
length: Batch of sequence lengths.
padding_value: Value to write into padding elements.

Returns:
Masked sequences.


def get_url(url: str, params: dict = {}, timeout: float = 5.0, cache: bool = True):

    try:

        if not cache:
            with requests_cache.disabled():
                r = requests.get(url, params=params, timeout=timeout)
        else:
            r = requests.get(url, params=params, timeout=timeout)

        log.debug(f"Response headers {r.headers}  From cache {r.from_cache}")
        return r

    except requests.exceptions.Timeout:
        log.warn(f"Timed out getting url in get_url: {url}")
        return None
    except Exception as e:
        log.warn(f"Error getting url: {url}  error: {e}")
        return None

Wrapper for requests.get(url)

Args:
url: url to retrieve
params: query string parameters
timeout: allow this much time for the request and time it out if over
cache: Cache for up to a day unless this is false

Returns:
Requests Result obj or None if timed out


def is_installed(name):

    out = __salt__['cmd.run_all'](FLATPAK_BINARY_NAME + ' info ' + name)

    if out['retcode'] and out['stderr']:
        return False
    else:
        return True

Determine if a package or runtime is installed.

Args:
name (str): The name of the package or the runtime.

Returns:
bool: True if the specified package or runtime is installed.

CLI Example:

.. code-block:: bash

salt '*' flatpak.is_installed org.gimp.GIMP


def request(self, send_terminator=False):
    try:
        retA = self.requestA()
        retB = self.requestB()
        if (retA and retB):
            self.makeAB()
            self.calculateFields()
            self.updateObservers()
            return True
    except:
        ekm_log(traceback.format_exc(sys.exc_info()))
    return False

Combined A and B read for V4 meter.

Args:
send_terminator (bool): Send termination string at end of read.

Returns:
bool: True on completion.


def sg_get_context():
    global _context
    res = tf.sg_opt()
    for c in _context:
        res += c
    return res

r"""Get current context information

Returns:
tf.sg_opt class object which contains all context information


def add_event(self, source, reference, event_title, event_type, method='', description='', bucket_list=[], campaign='', confidence='', date=None):
    events = self.get_events(event_title)
    if (events is not None):
        if (events['meta']['total_count'] == 1):
            return events['objects'][0]
        if (events['meta']['total_count'] > 1):
            log.error('Multiple events found while trying to add the event: {}'.format(event_title))
            return None
    data = {'api_key': self.api_key, 'username': self.username, 'source': source, 'reference': reference, 'method': method, 'campaign': campaign, 'confidence': confidence, 'description': description, 'event_type': event_type, 'date': date, 'title': event_title, 'bucket_list': ','.join(bucket_list)}
    r = requests.post('{}/events/'.format(self.url), data=data, verify=self.verify, proxies=self.proxies)
    if (r.status_code == 200):
        log.debug('Event created: {}'.format(event_title))
        json_obj = json.loads(r.text)
        if ('id' not in json_obj):
            log.error('Error adding event. id not returned.')
            return None
        return json_obj
    else:
        log.error('Event creation failed with status code: {}'.format(r.status_code))
        return None

Adds an event. If the event name already exists, it will return that
event instead.

Args:
source: Source of the information
reference: A reference where more information can be found
event_title: The title of the event
event_type: The type of event. See your CRITs vocabulary.
method: The method for obtaining the event.
description: A text description of the event.
bucket_list: A list of bucket list items to add
campaign: An associated campaign
confidence: The campaign confidence
date: A datetime.datetime object of when the event occurred.
Returns:
A JSON event object or None if there was an error.


def inspect_image(self, image):

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

Get detailed information about an image. Similar to the ``docker
inspect`` command, but only for images.

Args:
image (str): The image to inspect

Returns:
(dict): Similar to the output of ``docker inspect``, but as a
single dict

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


def remove_vdir(name, site, app=_DEFAULT_APP):

    current_vdirs = list_vdirs(site, app)
    app_path = os.path.join(*app.rstrip('/').split('/'))

    if app_path:
        app_path = '{0}\\'.format(app_path)
    vdir_path = r'IIS:\Sites\{0}\{1}{2}'.format(site, app_path, name)

    if name not in current_vdirs:
        log.debug('Virtual directory already absent: %s', name)
        return True

    ps_cmd = ['Remove-Item',
              '-Path', r"'{0}'".format(vdir_path),
              '-Recurse']

    cmd_ret = _srvmgr(ps_cmd)

    if cmd_ret['retcode'] != 0:
        msg = 'Unable to remove virtual directory: {0}\nError: {1}' \
              ''.format(name, cmd_ret['stderr'])
        raise CommandExecutionError(msg)

    new_vdirs = list_vdirs(site, app)

    if name not in new_vdirs:
        log.debug('Virtual directory removed successfully: %s', name)
        return True

    log.error('Unable to remove virtual directory: %s', name)
    return False

Remove an IIS virtual directory.

Args:
name (str): The virtual directory name.
site (str): The IIS site name.
app (str): The IIS application.

Returns:
bool: True if successful, otherwise False

CLI Example:

.. code-block:: bash

salt '*' win_iis.remove_vdir name='vdir0' site='site0'


def update(dst, src):
    for (k, v) in src.items():
        if isinstance(v, Mapping):
            r = update(dst.get(k, {}), v)
            dst[k] = r
        else:
            dst[k] = src[k]
    return dst

Recursively update values in dst from src.

Unlike the builtin dict.update() function, this method will decend into
nested dicts, updating all nested values.

Arguments:
dst (dict): Destination dict.
src (dict): Source dict.

Returns:
dict: dst updated with entries from src.


def set_row_count(self, count):

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

Sets the table row count.

Args:
count (int): number of rows


def _on_scan_request(self, sequence, topic, message):

        if messages.ProbeCommand.matches(message):
            self._logger.debug("Received probe message on topic %s, message=%s", topic, message)
            self._loop.add_callback(self._publish_scan_response, message['client'])
        else:
            self._logger.warn("Invalid message received on topic %s, message=%s", topic, message)

Process a request for scanning information

Args:
sequence (int:) The sequence number of the packet received
topic (string): The topic this message was received on
message_type (string): The type of the packet received
message (dict): The message itself


def _parse_trunk_allowed_vlans(self, config):
    match = re.search('switchport trunk allowed vlan (.+)$', config, re.M)
    return dict(trunk_allowed_vlans=match.group(1))

Scans the specified config and parse the trunk allowed vlans value

Args:
config (str): The interface configuration block to scan

Returns:
dict: A Python dict object with the value of switchport trunk
allowed vlans value.  The dict returned is intended to be
merged into the resource dict


def setMaximum(self, maximum):

        if not isinstance(maximum, int):
            raise TypeError("Argument is not of type int or long")
        self._maximum = maximum

setter to _maximum.

Args:
maximum (int or long): new _maximum value


def chat_getPermalink(self, *, channel: str, message_ts: str, **kwargs) -> SlackResponse:
    kwargs.update({'channel': channel, 'message_ts': message_ts})
    return self.api_call('chat.getPermalink', http_verb='GET', params=kwargs)

Retrieve a permalink URL for a specific extant message

Args:
channel (str): The channel id. e.g. 'C1234567890'
message_ts (str): The timestamp. e.g. '1234567890.123456'


def find_secondary_sources(assignment_nodes, sources, lattice):
    for source in sources:
        source.secondary_nodes = find_assignments(assignment_nodes, source, lattice)

Sets the secondary_nodes attribute of each source in the sources list.

Args:
assignment_nodes([AssignmentNode])
sources([tuple])
lattice(Lattice): the lattice we're analysing.


def __init__(self, columns: list[str], hub_url: str, preprocessing_url: Optional[str]=None, **kwargs):
    super().__init__(columns=columns, **kwargs)
    self.model_uri = hub_url
    self.preprocessing_url = preprocessing_url

Embedding config for tensorflow hub models. This config can be used with
MLTransform to embed text data. Models are loaded using the RunInference
PTransform with the help of a ModelHandler.

Args:
columns: The columns containing the text to be embedded.
hub_url: The url of the tensorflow hub model.
preprocessing_url: The url of the preprocessing model. This is optional.
If provided, the preprocessing model will be used to preprocess the
text before feeding it to the main model.
min_batch_size: The minimum batch size to be used for inference.
max_batch_size: The maximum batch size to be used for inference.
large_model: Whether to share the model across processes.


def write_to_file(file_path, data, mkdir=False):

    folder, fname = os.path.split(file_path)
    return write_to_file_by_name(folder, fname, data, mkdir)

Write a string of data to file.

Args:
file_path: Full path for a valid file path (e.g. c:/ladybug/testPts.pts)
data: Any data as string
mkdir: Set to True to create the directory if doesn't exist (Default: False)


def thaw_parameter(self, name):

        i = self.get_parameter_names(include_frozen=True).index(name)
        self.unfrozen_mask[i] = True

Thaw a parameter by name

Args:
name: The name of the parameter


def create(self, name, network):
    if (not (network in SUPPORTED_NETWORKS)):
        raise ValueError('Network not valid!')
    account = self.wrap(self.resource.create(dict(name=name, network=network)))
    self.add(account)
    return account

Create a new Account object and add it to this Accounts collection.

Args:
name (str): Account name
network (str): Type of cryptocurrency.  Can be one of, 'bitcoin', '
bitcoin_testnet', 'litecoin', 'dogecoin'.

Returns: The new round.Account


async def send_files_preconf(filepaths, config_path=CONFIG_PATH):

    config = read_config(config_path)
    subject = "PDF files from pdfebc"
    message = ""
    await send_with_attachments(subject, message, filepaths, config)

Send files using the config.ini settings.

Args:
filepaths (list(str)): A list of filepaths.


def get_record(self, name, record_id):
    if (name in self._cache):
        if (record_id in self._cache[name]):
            return self._cache[name][record_id]

Retrieve a record with a given type name and record id.

Args:
name (string): The name which the record is stored under.
record_id (int): The id of the record requested.

Returns:
:class:`cinder_data.model.CinderModel`: The cached model.


def aerosol_optical_depth(self, value=0.999):

        if value is not None:
            try:
                value = float(value)
            except ValueError:
                raise ValueError(
                    'value {} need to be of type float '
                    'for field `aerosol_optical_depth`'.format(value))

        self._aerosol_optical_depth = value

Corresponds to IDD Field `aerosol_optical_depth`

Args:
value (float): value for IDD Field `aerosol_optical_depth`
Unit: thousandths
Missing value: 0.999
if `value` is None it will not be checked against the
specification and is assumed to be a missing value

Raises:
ValueError: if `value` is not a valid value


def changeTo(self, path):

        dictionary = DictSingle(Pair('PATH', StringSingle(path)))
        self.value = [dictionary]

change value

Args:
path (str): the new environment path


def __init__(self, priv_key):

        self.setup_curve()

        length = len(priv_key)

        if length != 32 and length != 96 and length != 104:
            raise ValueError("Invalid private key")

        self.PrivateKey = bytearray(priv_key[-32:])

        pubkey_encoded_not_compressed = None

        if length == 32:
            try:
                pubkey_encoded_not_compressed = bitcoin.privkey_to_pubkey(priv_key)
            except Exception as e:
                raise Exception("Could not determine public key")

        elif length == 96 or length == 104:
            skip = length - 96
            pubkey_encoded_not_compressed = bytearray(b'\x04') + bytearray(priv_key[skip:skip + 64])

        if pubkey_encoded_not_compressed:
            pubkey_points = bitcoin.decode_pubkey(pubkey_encoded_not_compressed, 'bin')

            pubx = pubkey_points[0]
            puby = pubkey_points[1]
            edcsa = ECDSA.secp256r1()
            self.PublicKey = edcsa.Curve.point(pubx, puby)

        self.PublicKeyHash = Crypto.ToScriptHash(self.PublicKey.encode_point(True), unhex=True)

Create an instance.

Args:
priv_key (bytes): a private key.


def add(self, message):

        if not isinstance(message, ValidationMessage):
            raise TypeError("Argument must of type ValidationMessage")
        self.messages.append(message)

Add a new validation message to this instance.

Args:
message (ValidationMessage): A validation message to add to this instance's list of messages.


def _process_comparison_filter_directive(filter_operation_info, location, context, parameters, operator=None):
    comparison_operators = {u'=', u'!=', u'>', u'<', u'>=', u'<='}
    if (operator not in comparison_operators):
        raise AssertionError(u'Expected a valid comparison operator ({}), but got {}'.format(comparison_operators, operator))
    filtered_field_type = filter_operation_info.field_type
    filtered_field_name = filter_operation_info.field_name
    argument_inferred_type = strip_non_null_from_type(filtered_field_type)
    (argument_expression, non_existence_expression) = _represent_argument(location, context, parameters[0], argument_inferred_type)
    comparison_expression = expressions.BinaryComposition(operator, expressions.LocalField(filtered_field_name), argument_expression)
    final_expression = None
    if (non_existence_expression is not None):
        final_expression = expressions.BinaryComposition(u'||', non_existence_expression, comparison_expression)
    else:
        final_expression = comparison_expression
    return blocks.Filter(final_expression)

Return a Filter basic block that performs the given comparison against the property field.

Args:
filter_operation_info: FilterOperationInfo object, containing the directive and field info
of the field where the filter is to be applied.
location: Location where this filter is used.
context: dict, various per-compilation data (e.g. declared tags, whether the current block
is optional, etc.). May be mutated in-place in this function!
parameters: list of 1 element, containing the value to perform the comparison against;
if the parameter is optional and missing, the check will return True
operator: unicode, a comparison operator, like '=', '!=', '>=' etc.
This is a kwarg only to preserve the same positional arguments in the
function signature, to ease validation.

Returns:
a Filter basic block that performs the requested comparison


def _wait_process_events(self, total_time, return_filter, end_filter):
    acc = []
    delta = 0.01
    start_time = time.time()
    end_time = (start_time + total_time)
    while (time.time() < end_time):
        events = self._process_events((lambda x: (return_filter(x) or end_filter(x))), max_events=1)
        acc += events
        for event in events:
            if end_filter(event):
                return acc
        if (len(events) == 0):
            time.sleep(delta)
    return acc

Synchronously process events until a specific event is found or we timeout

Args:
total_time (float): The aproximate maximum number of seconds we should wait for the end event
return_filter (callable): A function that returns True for events we should return and not process
normally via callbacks to the IOLoop
end_filter (callable): A function that returns True for the end event that we are looking for to
stop processing.

Returns:
list: A list of events that matched return_filter or end_filter


def generate(self, str=None, fpath=None):
    self.prepare_storage()
    self.str = (self.load_file(fpath) if fpath else self.sanitize(str))
    self.validate_config()
    self.generate_kgrams()
    self.hash_kgrams()
    self.generate_fingerprints()
    return self.fingerprints

generates fingerprints of the input. Either provide `str` to compute fingerprint directly from your string or `fpath` to compute fingerprint from the text of the file. Make sure to have your text decoded in `utf-8` format if you pass the input string.

Args:
str (Optional(str)): string whose fingerprint is to be computed.
fpath (Optional(str)): absolute path of the text file whose fingerprint is to be computed.

Returns:
List(int): fingerprints of the input.

Raises:
FingerprintException: If the input string do not meet the requirements of parameters provided for fingerprinting.


def prepare_read(data, method='readlines', mode='r'):
    if hasattr(data, 'readlines'):
        data = getattr(data, method)()
    elif isinstance(data, list):
        if (method == 'read'):
            return ''.join(data)
    elif isinstance(data, basestring):
        data = getattr(open(data, mode), method)()
    else:
        raise TypeError(('Unable to handle data of type %r' % type(data)))
    return data

Prepare various input types for parsing.

Args:
data (iter): Data to read
method (str): Method to process data with
mode (str): Custom mode to process with, if data is a file

Returns:
list: List suitable for parsing

Raises:
TypeError: Invalid value for data


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

Deletes a `BuildTrigger` by its project ID and trigger ID. This API is experimental.

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


def encode_png(image, compression=-1, name=None):
    return gen_image_ops.encode_png(ops.convert_to_tensor(image), compression, name)

PNG-encode an image.

`image` is a rank-N Tensor of type uint8 or uint16 with shape `batch_dims +
[height, width, channels]`, where `channels` is:

*   1: for grayscale.
*   2: for grayscale + alpha.
*   3: for RGB.
*   4: for RGBA.

The ZLIB compression level, `compression`, can be -1 for the PNG-encoder
default or a value from 0 to 9.  9 is the highest compression level,
generating the smallest output, but is slower.

Args:
image: A `Tensor`. Must be one of the following types: `uint8`, `uint16`.
Rank N >= 3 with shape `batch_dims + [height, width, channels]`.
compression: An optional `int`. Defaults to `-1`. Compression level.
name: A name for the operation (optional).

Returns:
A `Tensor` of type `string`.


def object_download(self, bucket, key, start_offset=0, byte_count=None):
    args = {'alt': 'media'}
    headers = {}
    if ((start_offset > 0) or (byte_count is not None)):
        header = ('bytes=%d-' % start_offset)
        if (byte_count is not None):
            header += ('%d' % byte_count)
        headers['Range'] = header
    url = (Api._DOWNLOAD_ENDPOINT + (Api._OBJECT_PATH % (bucket, Api._escape_key(key))))
    return google.datalab.utils.Http.request(url, args=args, headers=headers, credentials=self._credentials, raw_response=True)

Reads the contents of an object as text.

Args:
bucket: the name of the bucket containing the object.
key: the key of the object to be read.
start_offset: the start offset of bytes to read.
byte_count: the number of bytes to read. If None, it reads to the end.
Returns:
The text content within the object.
Raises:
Exception if the object could not be read from.


def categories(self):
    keys = [k for k in self.__dict__.keys() if (k not in SPECIAL)]
    return keys

Lists the categories in the lexicon, except the
optional categories.

Returns:
list: A list of strings of category names.


def __init__(self, command_line_args=None, conf_file=None, defaults=None,
                 json_conf=None):

        self.conf_file = None
        self.__conf_dir = None
        self.__config = {}

        if conf_file:
            self.conf_file = os.path.abspath(conf_file)
            self.__conf_dir = os.path.dirname(self.conf_file)

            if not json_conf:
                self.__config = load_config_json(self.conf_file)
            else:
                self.__config = json_conf

        self.__invoke_dir = os.getcwd()
        self.__cli = command_line_args or {}
        self.__defaults = defaults or {}

Constructor for `ConfigParser`.

Args:
command_line_args: list, a list of command line arguments
that will override the keys defined in `conf_file`,
or `None`
conf_file: str, the path to the configuration file. If
`None`, `ConfigParser` will look for a file named
`hotdoc.json` in the current directory.


def rotoreflection(axis, angle, origin=(0, 0, 0)):
    rot = SymmOp.from_origin_axis_angle(origin, axis, angle)
    refl = SymmOp.reflection(axis, origin)
    m = np.dot(rot.affine_matrix, refl.affine_matrix)
    return SymmOp(m)

Returns a roto-reflection symmetry operation

Args:
axis (3x1 array): Axis of rotation / mirror normal
angle (float): Angle in degrees
origin (3x1 array): Point left invariant by roto-reflection.
Defaults to (0, 0, 0).

Return:
Roto-reflection operation


def from_hoy(cls, hoy, leap_year=False):
    return cls.from_moy(round((hoy * 60)), leap_year)

Create Ladybug Datetime from an hour of the year.

Args:
hoy: A float value 0 <= and < 8760


def DeregisterAttributeContainer(cls, attribute_container_class):
    container_type = attribute_container_class.CONTAINER_TYPE.lower()
    if (container_type not in cls._attribute_container_classes):
        raise KeyError('Attribute container class not set for container type: {0:s}.'.format(attribute_container_class.CONTAINER_TYPE))
    del cls._attribute_container_classes[container_type]

Deregisters an attribute container class.

The attribute container classes are identified based on their lower case
container type.

Args:
attribute_container_class (type): attribute container class.

Raises:
KeyError: if attribute container class is not set for
the corresponding container type.


def _read_group_h5(filename, groupname):
    with h5py.File(filename, 'r') as h5f:
        data = h5f[groupname][()]
    return data

Return group content.

Args:
filename (:class:`pathlib.Path`): path of hdf5 file.
groupname (str): name of group to read.
Returns:
:class:`numpy.array`: content of group.


def replace(self,
                entity_id,
                property_name,
                old_value,
                value):

        if not entity_id.startswith("http"):
            entity_uri = '/'.join([self.base_url, self.transaction, entity_id])
        else:
            entity_uri = entity_id
        sparql_template = Template()
        sparql = sparql_template.substitute(
            prefix=build_prefixes(self.namespaces),
            entity=entity_uri,
            prop_name=property_name,
            old_value=self.__value_format__(old_value),
            new_value=self.__value_format__(value))
        update_request = urllib.request.Request(
            entity_uri,
            data=sparql.encode(),
            method='PATCH',
            headers={'Content-Type': 'application/sparql-update'})
        response = urllib.request.urlopen(update_request)
        if response.code < 400:
            return True
        return False

Method replaces a triple for the given entity/subject. Property
name is from the schema.org vocabulary.

Args:
entity_id(string): Unique ID of Fedora object
property_name(string): Prefix and property name i.e. schema:name
old_value(string): Literal or URI of old value
value(string): Literal or new value


def apply(self, func, workers=1, job_size=10000):
    if (workers == 1):
        for lines in self.iter_chunks(job_size):
            (yield func(lines))
    else:
        with ProcessPoolExecutor(max_workers=workers) as executor:
            for result in executor.map(func, self.iter_chunks(job_size)):
                (yield result)

Apply `func` to lines of text in parallel or sequential.

Args:
func : a function that takes a list of lines.


def insert(self, loc, column, value):

        if is_list_like(value):

            if isinstance(value, pandas.Series):
                value = value.reindex(self.index)
            value = list(value)

        def insert(df, internal_indices=[]):
            internal_idx = int(internal_indices[0])
            old_index = df.index
            df.index = pandas.RangeIndex(len(df.index))
            df.insert(internal_idx, internal_idx, value, allow_duplicates=True)
            df.columns = pandas.RangeIndex(len(df.columns))
            df.index = old_index
            return df

        new_data = self.data.apply_func_to_select_indices_along_full_axis(
            0, insert, loc, keep_remaining=True
        )
        new_columns = self.columns.insert(loc, column)
        return self.__constructor__(new_data, self.index, new_columns)

Insert new column data.

Args:
loc: Insertion index.
column: Column labels to insert.
value: Dtype object values to insert.

Returns:
A new PandasQueryCompiler with new data inserted.


def delete_handler(Model, name=None, **kwds):

    from nautilus.database import db

    async def action_handler(service, action_type, payload, props, notify=True, **kwds):

        if action_type == get_crud_action('delete', name or Model):
            try:

                message_props = {}

                if 'correlation_id' in props:

                    message_props['correlation_id'] = props['correlation_id']

                record_id = payload['id'] if 'id' in payload else payload['pk']

                try:
                    model_query = Model.select().where(Model.primary_key() == record_id)
                except KeyError:
                    raise RuntimeError("Could not find appropriate id to remove service record.")

                model_query.get().delete_instance()

                if notify:

                    await service.event_broker.send(
                        payload='{"status":"ok"}',
                        action_type=change_action_status(action_type, success_status()),
                        **message_props
                    )

            except Exception as err:

                if notify:

                    await service.event_broker.send(
                        payload=str(err),
                        action_type=change_action_status(action_type, error_status()),
                        **message_props
                    )

                else:

                    raise err

    return action_handler

This factory returns an action handler that deletes a new instance of
the specified model when a delete action is recieved, assuming the
action follows nautilus convetions.

Args:
Model (nautilus.BaseModel): The model to delete when the action
received.

Returns:
function(type, payload): The action handler for this model


def set_ipv4_routing(self, vrf_name, default=False, disable=False):

        cmd = 'ip routing vrf %s' % vrf_name
        if default:
            cmd = 'default %s' % cmd
        elif disable:
            cmd = 'no %s' % cmd
        cmd = make_iterable(cmd)
        return self.configure(cmd)

Configures ipv4 routing for the vrf

Args:
vrf_name (str): The VRF name to configure
default (bool): Configures ipv4 routing for the vrf value to
default if this value is true
disable (bool): Negates the ipv4 routing for the vrf if set to true

Returns:
True if the operation was successful otherwise False


def __call__(self, shape, dtype=dtypes.float32, **kwargs):
    self._validate_kwargs(kwargs, support_partition=False)
    dtype = _assert_float_dtype(dtype)
    if len(shape) != 2:
        raise ValueError(f'The tensor to initialize, specified by argument `shape` must be at least two-dimensional. Received shape={shape}')
    initializer = linalg_ops_impl.eye(*shape, dtype=dtype)
    return self.gain * initializer

Returns a tensor object initialized as specified by the initializer.

Args:
shape: Shape of the tensor.
dtype: Optional dtype of the tensor. Only floating point types are
supported.
**kwargs: Additional keyword arguments.

Raises:
ValueError: If the dtype is not floating point
ValueError: If the requested shape does not have exactly two axes.


def Colorize(self, string, color, justify=None):
    if justify:
        string = justify(string)
    if self._csi and color in self._ANSI_COLOR:
        return '{csi}{color_code}{string}{csi}{reset_code}'.format(csi=self._csi, color_code=self._ANSI_COLOR[color], reset_code=self._ANSI_COLOR_RESET, string=string)
    return string

Generates a colorized string, optionally justified.

Args:
string: The string to write.
color: The color name -- must be in _ANSI_COLOR.
justify: The justification function, no justification if None. For
example, justify=lambda s: s.center(10)

Returns:
str, The colorized string that can be printed to the console.


def ListAttrs(cls):

  precondition.AssertType(cls, type)

  if PY2:

    return [item.decode("ascii") for item in dir(cls)]
  else:
    return dir(cls)

A compatibility wrapper for listing class attributes.

This method solves similar Python 2 compatibility issues for `dir` function as
`GetName` does for `__name__` invocations. See documentation for `GetName` for
more details.

Once support for Python 2 is dropped all invocations of this function should
be replaced with ordinary `dir` calls.

Args:
cls: A class object to list the attributes for.

Returns:
A list of attribute names as unicode strings.


def get_trivial_search_space():
    return pg.float_value(-1.0, 1.0)

Trivial search space.

Each point in the space is a value in [-1, 1].

Returns:
A tunable value.


def get_subport_statistics(self, id_or_uri, port_name, subport_number):
    uri = (self._client.build_uri(id_or_uri) + '/statistics/{0}/subport/{1}'.format(port_name, subport_number))
    return self._client.get(uri)

Gets the subport statistics on an interconnect.

Args:
id_or_uri:  Can be either the interconnect id or the interconnect uri.
port_name (str): A specific port name of an interconnect.
subport_number (int): The subport.

Returns:
dict: The statistics for the interconnect that matches id, port_name, and subport_number.


def _ParseLogonApplications(self, parser_mediator, registry_key):
    for application in self._LOGON_APPLICATIONS:
        command_value = registry_key.GetValueByName(application)
        if (not command_value):
            continue
        values_dict = {'Application': application, 'Command': command_value.GetDataAsObject(), 'Trigger': 'Logon'}
        event_data = windows_events.WindowsRegistryEventData()
        event_data.key_path = registry_key.path
        event_data.offset = registry_key.offset
        event_data.regvalue = values_dict
        event_data.source_append = ': Winlogon'
        event = time_events.DateTimeValuesEvent(registry_key.last_written_time, definitions.TIME_DESCRIPTION_WRITTEN)
        parser_mediator.ProduceEventWithEventData(event, event_data)

Parses the registered logon applications.

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


def _load_activations(self, filename):

        logger.info("Loading activation data from %s..." % filename)

        activations = pd.read_csv(filename, sep='\t')
        activations.columns = [col.lower()
                               for col in list(activations.columns)]

        mc = ['x', 'y', 'z', 'id', 'space']
        if (set(mc) - set(list(activations.columns))):
            logger.error(
                "At least one of mandatory columns (x, y, z, id, and space) "
                "is missing from input file.")
            return

        spaces = activations['space'].unique()
        xyz = activations[['x', 'y', 'z']].values
        for s in spaces:
            if s != self.transformer.target:
                inds = activations['space'] == s
                xyz[inds] = self.transformer.apply(s, xyz[inds])
        activations[['x', 'y', 'z']] = xyz

        ijk = pd.DataFrame(
            transformations.xyz_to_mat(xyz), columns=['i', 'j', 'k'])
        activations = pd.concat([activations, ijk], axis=1)
        return activations

Load activation data from a text file.

Args:
filename (str): a string pointing to the location of the txt file
to read from.


def find_source_file(obj: Any) -> Path:
    module = obj.__module__
    obj_file = PATH_TO_TRANSFORMERS
    for part in module.split('.')[1:]:
        obj_file = obj_file / part
    return obj_file.with_suffix('.py')

Finds the source file of an object.

Args:
obj (`Any`): The object whose source file we are looking for.

Returns:
`Path`: The source file.


def all_reduce_v3(communicator, t, reduction='Add', group_assignment=None, timeout_seconds=None):
    if group_assignment is None:
        group_assignment = []
    return gen_collective_ops.collective_reduce_v3(communicator=communicator, input=t, group_assignment=group_assignment, reduction=reduction, timeout_seconds=timeout_seconds)

Reduces tensors mutually.

Args:
communicator: the resource `tf.Tensor` returned from
`initialize_communicator`.
t: the `tf.Tensor` to be reduced.
reduction: a string. The name of the operation to reduce the values.
Accpeted values are `"min"`, `"max"`, `"mul"`, `"add"`.
group_assignment: Optional int32 `tf.Tensor` with shape [num_groups,
num_ranks_per_group]. `group_assignment[i]` represents the ranks in the
`ith` subgroup.
timeout_seconds: If set to a non zero, set a completion timeout to detect
staleness. If the timer goes off, a DeadlineExceededError is raised. The
timeout value in seconds. This feature is experimental.

Returns:
The reduced `tf.Tensor`.


def __init__(self, windowfn, triggerfn=None, accumulation_mode=None, timestamp_combiner=None, allowed_lateness=0, environment_id=None):
    global AccumulationMode, DefaultTrigger
    from apache_beam.transforms.trigger import AccumulationMode, DefaultTrigger
    if triggerfn is None:
        triggerfn = DefaultTrigger()
    if accumulation_mode is None:
        if triggerfn == DefaultTrigger():
            accumulation_mode = AccumulationMode.DISCARDING
        else:
            raise ValueError('accumulation_mode must be provided for non-trivial triggers')
    if not windowfn.get_window_coder().is_deterministic():
        raise ValueError('window fn (%s) does not have a determanistic coder (%s)' % (windowfn, windowfn.get_window_coder()))
    self.windowfn = windowfn
    self.triggerfn = triggerfn
    self.accumulation_mode = accumulation_mode
    self.allowed_lateness = Duration.of(allowed_lateness)
    self.environment_id = environment_id
    self.timestamp_combiner = timestamp_combiner or TimestampCombiner.OUTPUT_AT_EOW
    self._is_default = self.windowfn == GlobalWindows() and self.triggerfn == DefaultTrigger() and (self.accumulation_mode == AccumulationMode.DISCARDING) and (self.timestamp_combiner == TimestampCombiner.OUTPUT_AT_EOW) and (self.allowed_lateness == 0)

Class representing the window strategy.

Args:
windowfn: Window assign function.
triggerfn: Trigger function.
accumulation_mode: a AccumulationMode, controls what to do with data
when a trigger fires multiple times.
timestamp_combiner: a TimestampCombiner, determines how output
timestamps of grouping operations are assigned.
allowed_lateness: Maximum delay in seconds after end of window
allowed for any late data to be processed without being discarded
directly.
environment_id: Environment where the current window_fn should be
applied in.


async def get_graph(self, pipeline_uuid: str, example_filepath: str) -> str:
    self._verify_pipeline_uuid(pipeline_uuid)
    request = api_pb2.GetGraphRequest(pipeline_uuid=pipeline_uuid)
    try:
        response = await self._stub.GetGraph(request, **self._kwargs)
        if response.graph == '':
            logging.warning("Graph for %s wasn't generated", example_filepath)
        return response.graph
    except grpc.RpcError:
        logging.warning("Graph for %s wasn't generated", example_filepath)
        return ''

Get the graph of pipeline execution.

Args:
pipeline_uuid: uuid of the pipeline
example_filepath: path to the file of the example

Returns:
graph: contain the graph of pipeline execution as a string


def parse_docstring(docstring, max_indent_level=0):
    match = re.search('(?m)^([ \\t]*)(?=Example|Return)', docstring)
    if match:
        remainder_docstring = docstring[match.start():]
        docstring = docstring[:match.start()]
    else:
        remainder_docstring = ''
    args_pattern = re.compile('(?:Args:)(\\n.*)?(\\n)?$', re.DOTALL)
    args_match = args_pattern.search(docstring)
    args_section = args_match.group(1).lstrip('\n') if args_match else docstring
    if args_section.split('\n')[-1].strip() == '' or args_section.split('\n')[0].strip() == '"""':
        args_section = '\n'.join(args_section.split('\n')[1:])
    args_section = set_min_indent(args_section, 0)
    params = {}
    if args_section:
        param_pattern = re.compile(f'^\\s{{0,{max_indent_level}}}(\\w+)\\s*\\(\\s*([^, \\)]*)(\\s*.*?)\\s*\\)\\s*:\\s*((?:(?!\\n^\\s{{0,{max_indent_level}}}\\w+\\s*\\().)*)', re.DOTALL | re.MULTILINE)
        for match in param_pattern.finditer(args_section):
            param_name = match.group(1)
            param_type = match.group(2)
            additional_info = match.group(3)
            optional = 'optional' in additional_info
            shape = parse_shape(additional_info)
            default = parse_default(additional_info)
            param_description = match.group(4).strip()
            param_description = re.sub('^', ' ' * 4, param_description, 1)
            param_description = f'\n{param_description}'
            params[param_name] = {'type': param_type, 'description': param_description, 'optional': optional, 'shape': shape, 'default': default, 'additional_info': additional_info}
    if params and remainder_docstring:
        remainder_docstring = '\n' + remainder_docstring
    remainder_docstring = set_min_indent(remainder_docstring, 0)
    return (params, remainder_docstring)

Parse the docstring to extract the Args section and return it as a dictionary.
The docstring is expected to be in the format:
Args:
arg1 (type): Description of arg1.
arg2 (type): Description of arg2.

# This function will also return the remaining part of the docstring after the Args section.
Returns:/Example:
...


def labels2onehot(labels: [List[str], List[List[str]], np.ndarray], classes:  [list, np.ndarray]) -> np.ndarray:

    n_classes = len(classes)
    y = []
    for sample in labels:
        curr = np.zeros(n_classes)
        if isinstance(sample, list):
            for intent in sample:
                if intent not in classes:
                    log.warning('Unknown intent {} detected. Assigning no class'.format(intent))
                else:
                    curr[np.where(np.array(classes) == intent)[0]] = 1
        else:
            curr[np.where(np.array(classes) == sample)[0]] = 1
        y.append(curr)
    y = np.asarray(y)
    return y

Convert labels to one-hot vectors for multi-class multi-label classification

Args:
labels: list of samples where each sample is a class or a list of classes which sample belongs with
classes: array of classes' names

Returns:
2d array with one-hot representation of given samples


def DeleteIndex(self, index):
    to_remove = None
    for i in self.Items:
        if (i.index == index):
            to_remove = i
    if to_remove:
        self.Items.remove(to_remove)

Remove a spent coin based on its index.

Args:
index (int):


def write(self):
    return '{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}{11}'.format(self.qname, str(self.flag), self.rname, str(self.pos), str(self.mapq), self.cigar, self.rnext, str(self.pnext), str(self.tlen), self.seq, self.qual, os.linesep)

Return SAM formatted string

Returns:
str: SAM formatted string containing entire SAM entry


def _ParseInformationalOptions(self, options):

    super(PsortTool, self)._ParseInformationalOptions(options)

    self._quiet_mode = getattr(options, 'quiet', False)

    helpers_manager.ArgumentHelperManager.ParseOptions(
        options, self, names=['status_view'])

Parses the informational options.

Args:
options (argparse.Namespace): command line arguments.

Raises:
BadConfigOption: if the options are invalid.


def map_graph(inputs, outputs):
    nodes_in_decreasing_depth, operation_indices = _build_map(inputs, outputs)
    network_nodes = {make_node_key(node.operation, node.operation._inbound_nodes.index(node)) for node in nodes_in_decreasing_depth}
    nodes_depths = {}
    operations_depths = {}
    for node in reversed(nodes_in_decreasing_depth):
        depth = nodes_depths.setdefault(node, 0)
        previous_depth = operations_depths.get(node.operation, 0)
        depth = max(depth, previous_depth)
        operations_depths[node.operation] = depth
        nodes_depths[node] = depth
        for node_dep in node.parent_nodes:
            previous_depth = nodes_depths.get(node_dep, 0)
            nodes_depths[node_dep] = max(depth + 1, previous_depth)
    for input_t in inputs:
        input_operation = input_t._keras_history[0]
        if input_operation and input_operation not in operations_depths:
            operations_depths[input_operation] = 0
            operation_indices[input_operation] = -1
            nodes_depths[input_operation._inbound_nodes[0]] = 0
            network_nodes.add(make_node_key(input_operation, 0))
    nodes_by_depth = collections.defaultdict(list)
    for node, depth in nodes_depths.items():
        nodes_by_depth[depth].append(node)
    operations_by_depth = collections.defaultdict(list)
    for operation, depth in operations_depths.items():
        operations_by_depth[depth].append(operation)
    depth_keys = list(operations_by_depth.keys())
    depth_keys.sort(reverse=True)
    operations = []
    for depth in depth_keys:
        operations_for_depth = operations_by_depth[depth]
        operations_for_depth.sort(key=lambda x: operation_indices[x])
        operations.extend(operations_for_depth)
    depth_keys = list(nodes_by_depth.keys())
    depth_keys.sort(reverse=True)
    computable_tensors = set()
    for x in inputs:
        computable_tensors.add(x)
    operations_with_complete_input = []
    for depth in depth_keys:
        for node in nodes_by_depth[depth]:
            for x in tree.flatten(node.input_tensors):
                if x not in computable_tensors:
                    operation = node.operation
                    raise ValueError(f"Graph disconnected: cannot find parent for tensor {x} at operation '{operation}'. The following previous operations were accessed without issue: {operations_with_complete_input}")
                operations_with_complete_input.append(node.operation.name)
            for x in tree.flatten(node.outputs):
                computable_tensors.add(x)
    all_names = [operation.name for operation in operations]
    for name in all_names:
        if all_names.count(name) != 1:
            raise ValueError(f'The name "{name}" is used {all_names.count(name)} times in the model. All operation names should be unique.')
    return (network_nodes, nodes_by_depth, operations, operations_by_depth)

Validates a graph's topology and gather its operations and nodes.

Args:
inputs: List of input tensors.
outputs: List of outputs tensors.

Returns:
A tuple `(nodes, nodes_by_depth, operations, operations_by_depth)`.
- nodes: set of Node instances
- nodes_by_depth: dict mapping ints (depth) to lists of node instances.
- operations: list of Operation instances.
- operations_by_depth: dict mapping ints (depth) to lists of Operation
instances.


def setCard(self, name, value, add_quotes=False):

        gssha_card = self.getCard(name)

        if add_quotes:
            value = '"{0}"'.format(value)

        if gssha_card is None:

            new_card = ProjectCard(name=name, value=value)
            new_card.projectFile = self
        else:
            gssha_card.value = value

Adds/updates card for gssha project file

Args:
name (str): Name of card to be updated/added.
value (str): Value to attach to the card.
add_quotes (Optional[bool]): If True, will add quotes around string. Default is False.


def IsTensorFlowEventsFile(path):

  if not path:
    raise ValueError('Path must be a nonempty string')
  return 'tfevents' in tf.compat.as_str_any(os.path.basename(path))

Check the path name to see if it is probably a TF Events file.

Args:
path: A file path to check if it is an event file.

Raises:
ValueError: If the path is an empty string.

Returns:
If path is formatted like a TensorFlowEventsFile.


class StandardSingleLossStep(StandardInputStep):

    def __init__(self, dataset_fn, loss_fn, optimizer, distribution, iterations_per_step=1):
        super(StandardSingleLossStep, self).__init__(dataset_fn, distribution)
        self._loss_fn = loss_fn
        self._optimizer = optimizer
        self._iterations_per_step = iterations_per_step

    def __call__(self):
        with self._distribution.scope():

            def step_fn(ctx, inputs):

                gradients_fn = backprop.implicit_grad(self._loss_fn)
                gradients_fn = optimizer_lib.get_filtered_grad_fn(gradients_fn)
                grads_and_vars = self.distribution.extended.call_for_each_replica(gradients_fn, args=(ctx, inputs))
                return self._optimizer._distributed_apply(self.distribution, grads_and_vars)
            ctx = self.distribution.extended.experimental_run_steps_on_iterator(step_fn, self._iterator, self._iterations_per_step)
            return ctx.run_op

A step function that implements a training step for a feed forward network.

An instance of this class is intended to be used as a callable:

```python
...
step = step_fn.StandardSingleLossStep(
dataset, loss_fn, optimizer, distribution)

# Run a single training step on a given DistributionStrategy:
step(distribution)
...
```

Args:
dataset_fn: a function that returns a tf.data Dataset that produces the
input for the model.
loss_fn: a function that takes a context and inputs as arguments. It returns
the loss for those inputs. `context` is an instance of
`values.MultiStepContext` that will be passed when `loss_fn` is run.
`context` can be used to specify the outputs to be returned from
`loss_fn`, among other things.
optimizer: an optimizer that implements an update rule.
distribution: a `DistributionStrategy` object.


def is_macos_gfortran(f90_compiler):

    from numpy.distutils.fcompiler import gnu

    if sys.platform != MAC_OS:
        return False

    if not isinstance(f90_compiler, gnu.Gnu95FCompiler):
        return False

    return True

Checks if the current build is ``gfortran`` on macOS.

Args:
f90_compiler (numpy.distutils.fcompiler.FCompiler): A Fortran compiler
instance.

Returns:
bool: Only :data:`True` if

* Current OS is macOS (checked via ``sys.platform``).
* ``f90_compiler`` corresponds to ``gfortran``.


def push(self, item: T) -> bool | Any:
    self.queue.append(item)
    return self.flush()

Add item to queue and attempt a flush.

Args:
* item: Item to add to queue

Returns:
* True, if flushed with no errors
* False, if not flushed
* Error value from consumer, if flushed with errors


def die(message, status=1):

    print(message, file=sys.stderr)
    sys.exit(status)

Print an error message and exit.

This function will call ``sys.exit`` with the given ``status`` and the
process will terminate.

Args:
message (str) : error message to print

status (int) : the exit status to pass to ``sys.exit``


def RemoveForwardedIp(self, address, interface):
    ip = netaddr.IPNetwork(address)
    self._RunIfconfig(args=[interface, '-alias', str(ip.ip)])

Delete an IP address on the network interface.

Args:
address: string, the IP address to configure.
interface: string, the output device to use.


def max_site_coordination_numbers( self ):

        return { l : max( c ) for l, c in self.site_coordination_numbers().items() }

Returns a dictionary of the maximum coordination number for each site label.
e.g.::

{ 'A' : 4, 'B' : 4 }

Args:
none

Returns:
max_coordination_numbers (Dict(Str:Int)): dictionary of maxmimum coordination
number for each site label.


def fetch_gbwithparts(list_of_NC_accessions, email, folder):

    from Bio import Entrez
    from time import sleep

    print 'downloading genomes... please wait'

    for item in list_of_NC_accessions:
        Entrez.email = email
        handle = Entrez.efetch(db="nuccore",
                               id=item,
                               retmode='full',
                               rettype='gbwithparts')
        data = handle.read()

        if not os.path.exists(folder):
            os.makedirs(folder)

        with open('%s/%s.gb' % (folder,item), 'w') as textfile:
            textfile.write(data)

        print 'done downloading %s' % item

        sleep(2)

Download genbank files from NCBI using Biopython Entrez efetch.

Args:
list_of_NC_accessions (list): a list of strings, e.g ['NC_015758', 'NC_002695']
email (string):  NCBI wants your email
folder (string): Where the gb files download to, generally './genomes/'


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

    alias_genes = adapter.genes_by_alias()

    if not hpo_lines:
        hpo_lines = fetch_hpo_terms()

    if not hpo_gene_lines:
        hpo_gene_lines = fetch_hpo_to_genes()

    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 _GetSpecificationStore(cls, format_category):
    specification_store = specification.FormatSpecificationStore()
    remainder_list = []
    for analyzer_helper in iter(cls._analyzer_helpers.values()):
        if (not analyzer_helper.IsEnabled()):
            continue
        if (format_category in analyzer_helper.format_categories):
            format_specification = analyzer_helper.GetFormatSpecification()
            if (format_specification is not None):
                specification_store.AddSpecification(format_specification)
            else:
                remainder_list.append(analyzer_helper)
    return (specification_store, remainder_list)

Retrieves the specification store for specified format category.

Args:
format_category (str): format category.

Returns:
tuple[FormatSpecificationStore, list[AnalyzerHelper]]: a format
specification store and remaining analyzer helpers that do not have
a format specification.


def _example_from_array_spec(self, prop_spec):

        if isinstance(prop_spec['items'], list):
            return [self.get_example_from_prop_spec(item_prop_spec) for item_prop_spec in prop_spec['items']]

        elif 'type' in prop_spec['items'].keys():
            if 'format' in prop_spec['items'].keys() and prop_spec['items']['format'] == 'date-time':
                return self._get_example_from_basic_type('datetime')
            else:
                return self._get_example_from_basic_type(prop_spec['items']['type'])

        elif ('$ref' in prop_spec['items'].keys() or
              ('schema' in prop_spec and'$ref' in prop_spec['schema']['items'].keys())):

            definition_name = self.get_definition_name_from_ref(prop_spec['items']['$ref']) or \
                self.get_definition_name_from_ref(prop_spec['schema']['items']['$ref'])
            if self.build_one_definition_example(definition_name):
                example_dict = self.definitions_example[definition_name]
                if not isinstance(example_dict, dict):
                    return [example_dict]
                if len(example_dict) == 1:
                    try:
                        res = example_dict[example_dict.keys()[0]]
                    except TypeError:
                        res = example_dict[list(example_dict)[0]]
                    return res

                else:
                    return_value = {}
                    for example_name, example_value in example_dict.items():
                        return_value[example_name] = example_value
                    return [return_value]
        elif 'properties' in prop_spec['items']:
            prop_example = {}
            for prop_name, prop_spec in prop_spec['items']['properties'].items():
                example = self.get_example_from_prop_spec(prop_spec)
                if example is not None:
                    prop_example[prop_name] = example
            return [prop_example]

Get an example from a property specification of an array.

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

Returns:
An example array.


def _resource_context(fn):
    return os.path.join(os.path.dirname(__file__), DES_DIR, fn)

Compose path to the ``resources`` directory for given `fn`.

Args:
fn (str): Filename of file in ``resources`` directory.

Returns:
str: Absolute path to the file in resources directory.


def consume(self, fragment):
    self._current_consumer(fragment)
    raise gen.Return(self._message)

Consume individual protocol message fragments.

Args:
fragment (``JSON``) :
A message fragment to assemble. When a complete message is
assembled, the receiver state will reset to begin consuming a
new message.


def compile_action_bound_constraints(self,
            state: Sequence[tf.Tensor]) -> Dict[str, Bounds]:

        scope = self.action_precondition_scope(state)

        lower_bounds = self.rddl.domain.action_lower_bound_constraints
        upper_bounds = self.rddl.domain.action_upper_bound_constraints

        with self.graph.as_default():
            with tf.name_scope('action_bound_constraints'):

                bounds = {}
                for name in self.rddl.domain.action_fluent_ordering:

                    lower_expr = lower_bounds.get(name)
                    lower = None
                    if lower_expr is not None:
                        with tf.name_scope('lower_bound'):
                            lower = self._compile_expression(lower_expr, scope)

                    upper_expr = upper_bounds.get(name)
                    upper = None
                    if upper_expr is not None:
                        with tf.name_scope('upper_bound'):
                            upper = self._compile_expression(upper_expr, scope)

                    bounds[name] = (lower, upper)

                return bounds

Compiles all actions bounds for the given `state`.

Args:
state (Sequence[tf.Tensor]): The current state fluents.

Returns:
A mapping from action names to a pair of
:obj:`rddl2tf.fluent.TensorFluent` representing
its lower and upper bounds.