def page_length(self, length):

        mH = length/256
        mL = length%256
        if length < 12000:
            self.send(chr(27)+'('+'C'+chr(2)+chr(0)+chr(mL)+chr(mH))
        else:
            raise RuntimeError('Length must be less than 12000.')

Specifies page length. This command is only valid with continuous length labels.

Args:
length: The length of the page, in dots. Can't exceed 12000.
Returns:
None
Raises:
RuntimeError: Length must be less than 12000.


def ModulePath(module_name):

  module = importlib.import_module(module_name)
  path = inspect.getfile(module)

  if compatibility.PY2:
    path = path.decode("utf-8")

  if os.path.basename(path).startswith("__init__."):
    path = os.path.dirname(path)

  if path.endswith(".pyc"):
    path = path[:-4] + ".py"

  return path

Computes a path to the specified module.

Args:
module_name: A name of the module to get the path for.

Returns:
A path to the specified module.

Raises:
ImportError: If specified module cannot be imported.


def of_type(self, classinfo):
    if self.closed():
        raise ValueError('Attempt to call of_type() on a closed Queryable.')
    if (not is_type(classinfo)):
        raise TypeError('of_type() parameter classinfo={0} is not a class object or a type objector a tuple of class or type objects.'.format(classinfo))
    return self.where((lambda x: isinstance(x, classinfo)))

Filters elements according to whether they are of a certain type.

Note: This method uses deferred execution.

Args:
classinfo: If classinfo is neither a class object nor a type object
it may be a tuple of class or type objects, or may recursively
contain other such tuples (other sequence types are not
accepted).

Returns:
A Queryable over those elements of the source sequence for which
the predicate is True.

Raises:
ValueError: If the Queryable is closed.
TypeError: If classinfo is not a class, type, or tuple of classes,
types, and such tuples.


def __init__(self, drop_ffi_call_fn, initialized_ptr=None):

        if initialized_ptr is not None:
            self._ptr = initialized_ptr
        else:
            self._ptr = ctypes.c_void_p()

        self._drop_ffi_fn = drop_ffi_call_fn

Constructs an owned pointer.
Initializing the pointer is left to the extending classes

Args:
drop_ffi_call_fn (str): the name of the FFI function to call on
drop or garbage collection.
initialized_ptr (ctypes.c_void_p:optional): a preinitialized
pointer to the native memory


def add(app: web.Application, feature: Any, key: Hashable=None, exist_ok: bool=False):
    if (FEATURES_KEY not in app):
        app[FEATURES_KEY] = dict()
    key = (key or type(feature))
    if (key in app[FEATURES_KEY]):
        if exist_ok:
            return
        else:
            raise KeyError(f'Feature "{key}" already registered')
    app[FEATURES_KEY][key] = feature

Adds a new feature to the app.

Features can either be registered as the default feature for the class,
or be given an explicit name.

Args:
app (web.Application):
The current Aiohttp application.

feature (Any):
The new feature that should be registered.
It is recommended, but not required to use a `ServiceFeature`.

key (Hashable, optional):
The key under which the feature should be registered.
Defaults to `type(feature)`.

exist_ok (bool):
If truthy, this function will do nothing if a feature was already registered for `key`.
Otherwise, an exception is raised.


def _assert_gcs_files(files):

  if sys.version_info.major > 2:
    string_type = (str, bytes)
  else:
    string_type = basestring

  if isinstance(files, string_type):
    files = [files]

  for f in files:
    if f is not None and not f.startswith('gs:
      raise ValueError('File %s is not a gcs path' % f)

Check files starts wtih gs://.

Args:
files: string to file path, or list of file paths.


def cd(new_directory, clean_up=(lambda : True)):
    previous_directory = os.getcwd()
    os.chdir(os.path.expanduser(new_directory))
    try:
        (yield)
    finally:
        os.chdir(previous_directory)
        clean_up()

Changes into a given directory and cleans up after it is done

Args:
new_directory: The directory to change to
clean_up: A method to clean up the working directory once done


async def _async_supervisor(func, animation_, step, *args, **kwargs):
    with ThreadPoolExecutor(max_workers=2) as pool:
        with _terminating_event() as event:
            pool.submit(animate_cli, animation_, step, event)
            result = (await func(*args, **kwargs))
    return result

Supervisor for running an animation with an asynchronous function.

Args:
func: A function to be run alongside an animation.
animation_: An infinite generator that produces
strings for the animation.
step: Seconds between each animation frame.
*args: Arguments for func.
**kwargs: Keyword arguments for func.
Returns:
The result of func(*args, **kwargs)
Raises:
Any exception that is thrown when executing func.


def SerializeExclusiveData(self, writer):

        writer.WriteByte(self.AssetType)
        writer.WriteVarString(self.Name)
        writer.WriteFixed8(self.Amount)
        writer.WriteByte(self.Precision)

        self.Owner.Serialize(writer)

        writer.WriteUInt160(self.Admin)

Serialize object.

Args:
writer (neo.IO.BinaryWriter):


def recognize(self, node: yaml.Node, expected_type: Type) -> RecResult:
    logger.debug('Recognizing {} as a {}'.format(node, expected_type))
    recognized_types = None
    if (expected_type in [str, int, float, bool, bool_union_fix, datetime, None, type(None)]):
        (recognized_types, message) = self.__recognize_scalar(node, expected_type)
    elif is_generic_union(expected_type):
        (recognized_types, message) = self.__recognize_union(node, expected_type)
    elif is_generic_list(expected_type):
        (recognized_types, message) = self.__recognize_list(node, expected_type)
    elif is_generic_dict(expected_type):
        (recognized_types, message) = self.__recognize_dict(node, expected_type)
    elif (expected_type in self.__registered_classes.values()):
        (recognized_types, message) = self.__recognize_user_classes(node, expected_type)
    if (recognized_types is None):
        raise RecognitionError('Could not recognize for type {}, is it registered?'.format(expected_type))
    logger.debug('Recognized types {} matching {}'.format(recognized_types, expected_type))
    return (recognized_types, message)

Figure out how to interpret this node.

This is not quite a type check. This function makes a list of \
all types that match the expected type and also the node, and \
returns that list. The goal here is not to test validity, but \
to determine how to process this node further.

That said, it will recognize built-in types only in case of \
an exact match.

Args:
node: The YAML node to recognize.
expected_type: The type we expect this node to be, based \
on the context provided by our type definitions.

Returns:
A list of matching types.


def __init__(self, api, endpoint=None, cls=None):

        self.api = api
        self.endpoint = endpoint
        self._cls = cls

Creates an instance of the APIEndpoint class.

Args:
api - Gophish.client - The authenticated REST client
endpoint - str - The URL path to the resource endpoint
cls - gophish.models.Model - The Class to use when parsing results


def most_frequent(self, k):
    word_count = {w: self.word_count[w] for w in self.words[:k]}
    return CountedVocabulary(word_count=word_count)

Returns a vocabulary with the most frequent `k` words.

Args:
k (integer): specifies the top k most frequent words to be returned.


def install_package(tar_url, folder, md5_url='{tar_url}.md5', on_download=(lambda : None), on_complete=(lambda : None)):
    data_file = join(folder, basename(tar_url))
    md5_url = md5_url.format(tar_url=tar_url)
    try:
        remote_md5 = download(md5_url).decode('utf-8').split(' ')[0]
    except (UnicodeDecodeError, URLError):
        raise ValueError(('Invalid MD5 url: ' + md5_url))
    if (remote_md5 != calc_md5(data_file)):
        on_download()
        if isfile(data_file):
            try:
                with tarfile.open(data_file) as tar:
                    for i in reversed(list(tar)):
                        try:
                            os.remove(join(folder, i.path))
                        except OSError:
                            pass
            except (OSError, EOFError):
                pass
        download_extract_tar(tar_url, folder, data_file)
        on_complete()
        if (remote_md5 != calc_md5(data_file)):
            raise ValueError(('MD5 url does not match tar: ' + md5_url))
        return True
    return False

Install or update a tar package that has an md5

Args:
tar_url (str): URL of package to download
folder (str): Location to extract tar. Will be created if doesn't exist
md5_url (str): URL of md5 to use to check for updates
on_download (Callable): Function that gets called when downloading a new update
on_complete (Callable): Function that gets called when a new download is complete

Returns:
bool: Whether the package was updated


def _ParseFile(self, file_obj, line_parser):
    lines = [l.strip() for l in utils.ReadFileBytesAsUnicode(file_obj).splitlines()]
    try:
        for (index, line) in enumerate(lines):
            if line:
                line_parser(line)
    except (IndexError, KeyError) as e:
        raise parser.ParseError(('Invalid file at line %d: %s' % ((index + 1), e)))

Process a file line by line.

Args:
file_obj: The file to parse.
line_parser: The parser method used to process and store line content.

Raises:
parser.ParseError if the parser is unable to process the line.


def ee_initialize(use_personal_account: bool=False, enforce_high_volume: bool=False, service_account: t.Optional[str]=None, private_key: t.Optional[str]=None, project_id: t.Optional[str]=None) -> None:
    creds = get_creds(use_personal_account, service_account, private_key)
    on_compute_engine = is_compute_engine()
    if on_compute_engine:
        if project_id is None and use_personal_account:
            raise RuntimeError('Project_name should not be None!')
        params = {'credentials': creds, 'opt_url': 'https:
        if project_id:
            params['project'] = project_id
        ee.Initialize(**params)
    elif enforce_high_volume and (not on_compute_engine):
        raise RuntimeError('Must run on a compute engine VM to use the high volume earth engine api.')
    else:
        ee.Initialize(creds)

Initializes earth engine with the high volume API when using a compute engine VM.

Args:
use_personal_account: A flag to use personal account for ee authentication. Default: False.
enforce_high_volume: A flag to use the high volume API when using a compute engine VM. Default: False.
service_account: Service account address when using a private key for earth engine authentication.
private_key: A private key path to authenticate earth engine using private key. Default: None.
Project ID: An identifier that represents the name of a project present in Earth Engine.
Raises:
RuntimeError: Earth Engine did not initialize.


def validate_start_end_range(range_tuple):

    start, end = range_tuple

    if (start and end) and (start > end):
        raise ValueError(_("Start after end!"))

    return range_tuple

Perform basic sanity checks on a timeframe.

Args:
range_tuple (tuple): ``(start, end)`` tuple as returned by
``complete_timeframe``.

Raises:
ValueError: If start > end.

Returns:
tuple: ``(start, end)`` tuple that passed validation.

Note:
``timeframes`` may be incomplete, especially if ``complete_timeframe(partial=True)`` has
been used to construct them.


def remat(f):
    return tf.recompute_grad(f)

Implementation of rematerialization.

Args:
f: The function or operation to rematerialize.
Returns:
A function wrapping f that defines a custom gradient, which
recomputes f on the backwards pass of a gradient call.


def expand_groups(grp):
    p = re.compile('(?P<name>.+)\\[(?P<start>\\d+)-(?P<end>\\d+)\\]')
    m = p.match(grp)
    if (m is not None):
        s = int(m.group('start'))
        e = int(m.group('end'))
        n = m.group('name')
        return list(map((lambda x: (n + str(x))), range(s, (e + 1))))
    else:
        return [grp]

Expand group names.

Args:
grp (string): group names to expand

Returns:
list of groups

Examples:

* grp[1-3] will be expanded to [grp1, grp2, grp3]
* grp1 will be expanded to [grp1]


def __init__(self, launchdjobs):

    self.launchdjobs = launchdjobs

    self.blacklist_regex = [
        re.compile(r"^0x[a-z0-9]+\.anonymous\..+$"),
        re.compile(r"^0x[a-z0-9]+\.mach_init\.(crash_inspector|Inspector)$"),
    ]

Initialize.

Args:
launchdjobs: NSCFArray of NSCFDictionarys containing launchd job data from
the ServiceManagement framework.


def graph_key_from_tag(tag, entity_index):

    start_token = tag.get('start_token')
    entity = tag.get('entities', [])[entity_index]
    return str(start_token) + '-' + entity.get('key') + '-' + str(entity.get('confidence'))

Returns a key from a tag entity

Args:
tag (tag) : this is the tag selected to get the key from
entity_index (int) : this is the index of the tagged entity

Returns:
str : String representing the key for the given tagged entity.


def substitute_globals(config_dict):

    constants = get_all_constants()

    if type(config_dict) != dict:
        return

    for key in config_dict.keys():
        if key in constants and type(config_dict[key]) in _ALLOWED:
            globals()[key] = config_dict[key]

Set global variables to values defined in `config_dict`.

Args:
config_dict (dict): dictionary with data, which are used to set \
`globals`.

Note:
`config_dict` have to be dictionary, or it is ignored. Also all
variables, that are not already in globals, or are not types defined in
:attr:`_ALLOWED` (str, int, float) or starts with ``_`` are silently
ignored.


def _parse_data_fields(self, fields, tag_id="tag", sub_id="code"):

        for field in fields:
            params = field.params

            if tag_id not in params:
                continue

            field_repr = OrderedDict([
                [self.i1_name, params.get(self.i1_name, " ")],
                [self.i2_name, params.get(self.i2_name, " ")],
            ])

            for subfield in field.find("subfield"):
                if sub_id not in subfield.params:
                    continue

                content = MARCSubrecord(
                    val=subfield.getContent().strip(),
                    i1=field_repr[self.i1_name],
                    i2=field_repr[self.i2_name],
                    other_subfields=field_repr
                )

                code = subfield.params[sub_id]
                if code in field_repr:
                    field_repr[code].append(content)
                else:
                    field_repr[code] = [content]

            tag = params[tag_id]
            if tag in self.datafields:
                self.datafields[tag].append(field_repr)
            else:
                self.datafields[tag] = [field_repr]

Parse data fields.

Args:
fields (list): of HTMLElements
tag_id (str): parameter name, which holds the information, about
field name this is normally "tag", but in case of
oai_marc "id"
sub_id (str): id of parameter, which holds informations about
subfield name this is normally "code" but in case of
oai_marc "label"


def _get_media_files(cls, packager, media_packages, media_type, extra_files):
    source_files = list(extra_files)
    if ((not settings.PIPELINE_ENABLED) and settings.PIPELINE_COLLECTOR_ENABLED):
        default_collector.collect()
    for media_package in media_packages:
        package = packager.package_for(media_type, media_package)
        if settings.PIPELINE_ENABLED:
            source_files.append(staticfiles_storage.url(package.output_filename))
        else:
            source_files += packager.compile(package.paths)
    return source_files

Return source or output media files for a list of packages.

This will go through the media files belonging to the provided list
of packages referenced in a Media class and return the output files
(if Pipeline is enabled) or the source files (if not enabled).

Args:
packager (pipeline.packager.Packager):
The packager responsible for media compilation for this type
of package.

media_packages (list of unicode):
The list of media packages referenced in Media to compile or
return.

extra_files (list of unicode):
The list of extra files to include in the result. This would
be the list stored in the Media class's original :py:attr:`css`
or :py:attr:`js` attributes.

Returns:
list:
The list of media files for the given packages.


def get_transcript_lengths(ensembl, transcript_ids):

    transcripts = {}
    for transcript_id in transcript_ids:

        try:
            seq = ensembl.get_protein_seq_for_transcript(transcript_id)
        except ValueError:
            continue

        transcripts[transcript_id] = len(seq)

    return transcripts

finds the protein length for ensembl transcript IDs for a gene

Args:
ensembl: EnsemblRequest object to request sequences and data
from the ensembl REST API
transcript_ids: list of transcript IDs for a single gene

Returns:
dictionary of lengths (in amino acids), indexed by transcript IDs


def _as_serialized_graph(self, allow_stateful=None, strip_device_assignment=None, external_state_policy=options_lib.ExternalStatePolicy.WARN):
    if external_state_policy:
        policy = external_state_policy.value
        return gen_dataset_ops.dataset_to_graph_v2(self._variant_tensor, external_state_policy=policy, strip_device_assignment=strip_device_assignment)
    if strip_device_assignment:
        return gen_dataset_ops.dataset_to_graph(self._variant_tensor, allow_stateful=allow_stateful, strip_device_assignment=strip_device_assignment)
    return gen_dataset_ops.dataset_to_graph(self._variant_tensor, allow_stateful=allow_stateful)

Produces serialized graph representation of the dataset.

Args:
allow_stateful: If true, we allow stateful ops to be present in the graph
def. In that case, the state in these ops would be thrown away.
strip_device_assignment: If true, non-local (i.e. job and task) device
assignment is stripped from ops in the serialized graph.
external_state_policy: The ExternalStatePolicy enum that determines how we
handle input pipelines that depend on external state. By default, its
set to WARN.

Returns:
A scalar `tf.Tensor` of `tf.string` type, representing this dataset as a
serialized graph.


def resolve_image_as_pil(self, image_url, coords=None):

        files = self.mets.find_files(url=image_url)
        if files:
            image_filename = self.download_file(files[0]).local_filename
        else:
            image_filename = self.download_url(image_url)

        if image_url not in self.image_cache['pil']:
            self.image_cache['pil'][image_url] = Image.open(image_filename)

        pil_image = self.image_cache['pil'][image_url]

        if coords is None:
            return pil_image
        if image_url not in self.image_cache['cv2']:
            log.debug("Converting PIL to OpenCV: %s", image_url)
            color_conversion = cv2.COLOR_GRAY2BGR if pil_image.mode in ('1', 'L') else  cv2.COLOR_RGB2BGR
            pil_as_np_array = np.array(pil_image).astype('uint8') if pil_image.mode == '1' else np.array(pil_image)
            self.image_cache['cv2'][image_url] = cv2.cvtColor(pil_as_np_array, color_conversion)
        cv2_image = self.image_cache['cv2'][image_url]
        poly = np.array(coords, np.int32)
        log.debug("Cutting region %s from %s", coords, image_url)
        region_cut = cv2_image[
            np.min(poly[:, 1]):np.max(poly[:, 1]),
            np.min(poly[:, 0]):np.max(poly[:, 0])
        ]
        return Image.fromarray(region_cut)

Resolve an image URL to a PIL image.

Args:
coords (list) : Coordinates of the bounding box to cut from the image

Returns:
Image or region in image as PIL.Image


def toy_logistic_data(num_examples, input_size=2, weights_prior_stddev=5.0):
    random_weights = (weights_prior_stddev * np.random.randn(input_size))
    random_bias = np.random.randn()
    design_matrix = ((np.random.rand(num_examples, input_size) * 2) - 1)
    logits = np.reshape((np.dot(design_matrix, random_weights) + random_bias), ((- 1), 1))
    p_labels = (1.0 / (1 + np.exp((- logits))))
    labels = np.int32((p_labels > np.random.rand(num_examples, 1)))
    return (random_weights, random_bias, np.float32(design_matrix), labels)

Generates synthetic data for binary classification.

Args:
num_examples: The number of samples to generate (scalar Python `int`).
input_size: The input space dimension (scalar Python `int`).
weights_prior_stddev: The prior standard deviation of the weight
vector. (scalar Python `float`).

Returns:
random_weights: Sampled weights as a Numpy `array` of shape
`[input_size]`.
random_bias: Sampled bias as a scalar Python `float`.
design_matrix: Points sampled uniformly from the cube `[-1,
1]^{input_size}`, as a Numpy `array` of shape `(num_examples,
input_size)`.
labels: Labels sampled from the logistic model `p(label=1) =
logistic(dot(features, random_weights) + random_bias)`, as a Numpy
`int32` `array` of shape `(num_examples, 1)`.


def are_you_sure(msg=''):
    r
    print(msg)
    from utool import util_arg
    from utool import util_str
    override = util_arg.get_argflag(('--yes', '--y', '-y'))
    if override:
        print('accepting based on command line flag')
        return True
    valid_ans = ['yes', 'y']
    valid_prompt = util_str.conj_phrase(valid_ans, 'or')
    ans = input('Are you sure?\n Enter %s to accept\n' % valid_prompt)
    return ans.lower() in valid_ans

r"""
Prompts user to accept or checks command line for -y

Args:
msg (str):

Returns:
bool: accept or not


def _astimezone_ts(self, timezone):

    if self.created.tzinfo is timezone:
        return self
    else:
        nw_obj = Timestamps((None,)*4)
        nw_obj.created = self.created.astimezone(timezone)
        nw_obj.changed = self.changed.astimezone(timezone)
        nw_obj.mft_changed = self.mft_changed.astimezone(timezone)
        nw_obj.accessed = self.accessed.astimezone(timezone)

        return nw_obj

Changes the time zones of all timestamps.

Receives a new timezone and applies to all timestamps, if necessary.

Args:
timezone (:obj:`tzinfo`): Time zone to be applied

Returns:
A new ``Timestamps`` object if the time zone changes, otherwise returns ``self``.


def key_swap(d, cls, marshal):
    dname = '_{}marshal_key_swap'.format(('' if marshal else 'un'))
    if hasattr(cls, dname):
        key_swap = getattr(cls, dname)
        return {(key_swap[k] if (k in key_swap) else k): v for (k, v) in d.items()}
    else:
        return d

Swap the keys in a dictionary

Args:
d:       dict, The dict to swap keys in
cls:     class, If the class has a staticly defined
_marshal_key_swap and/or _unmarshal_key_swap dict,
the keys will be swapped.
Otherwise @d is returned
marshal: bool, True if marshalling class to JSON,
False if unmarshalling JSON to class
Returns:
dict


def _run_conversion(self, meta_graph_def):
    grappler_session_config = config_pb2.ConfigProto()
    custom_rewriter_config = _get_tensorrt_rewriter_config(conversion_params=self._conversion_params._replace(allow_build_at_runtime=True), is_dynamic_op=True, max_batch_size=None, disable_non_trt_optimizers=self._test_only_disable_non_trt_optimizers, use_implicit_batch=not self._use_dynamic_shape, profile_strategy=self._profile_strategy)
    grappler_session_config.graph_options.rewrite_options.CopyFrom(custom_rewriter_config)
    return tf_optimizer.OptimizeGraph(grappler_session_config, meta_graph_def, graph_id=b'tf_graph')

Run Grappler's OptimizeGraph() tool to convert the graph.

Args:
meta_graph_def: the MetaGraphDef instance to run the optimizations on.

Returns:
The optimized GraphDef.


def Decode(data, encoding=None):
    if data is None:
        return None
    if isinstance(data, str) or isinstance(data, bytes):
        string = data
    else:
        string = str(data)
    if isinstance(string, str):
        return string
    try:
        return string.decode('ascii')
    except UnicodeError:
        pass
    if encoding:
        try:
            return string.decode(encoding)
        except UnicodeError:
            pass
    try:
        return string.decode('utf8')
    except UnicodeError:
        pass
    try:
        return string.decode(sys.getfilesystemencoding())
    except UnicodeError:
        pass
    try:
        return string.decode(sys.getdefaultencoding())
    except UnicodeError:
        pass
    return string.decode('iso-8859-1')

Returns string with non-ascii characters decoded to UNICODE.

UTF-8, the suggested encoding, and the usual suspects will be attempted in
order.

Args:
data: A string or object that has str() and unicode() methods that may
contain an encoding incompatible with the standard output encoding.
encoding: The suggested encoding if known.

Returns:
A text string representing the decoded byte string.


def transpose(a, axes=None):

    if isinstance(a, np.ndarray):
        return np.transpose(a, axes)
    elif isinstance(a, RemoteArray):
        return a.transpose(*axes)
    elif isinstance(a, Remote):
        return _remote_to_array(a).transpose(*axes)
    elif isinstance(a, DistArray):
        if axes is None:
            axes = range(a.ndim - 1, -1, -1)
        axes = list(axes)
        if len(set(axes)) < len(axes):
            raise ValueError("repeated axis in transpose")
        if sorted(axes) != list(range(a.ndim)):
            raise ValueError("axes don't match array")
        distaxis = a._distaxis
        new_distaxis = axes.index(distaxis)
        new_subarrays = [ra.transpose(*axes) for ra in a._subarrays]
        return DistArray(new_subarrays, new_distaxis)
    else:
        return np.transpose(a, axes)

Returns a view of the array with axes transposed.

For a 1-D array, this has no effect.
For a 2-D array, this is the usual matrix transpose.
For an n-D array, if axes are given, their order indicates how the
axes are permuted

Args:
a (array_like): Input array.
axes (list of int, optional): By default, reverse the dimensions,
otherwise permute the axes according to the values given.


def push(self, stream, value):

        raise ArgumentError("Attempting to push reading to an invalid stream walker that cannot hold data", selector=self.selector, stream=stream)

Update this stream walker with a new responsive reading.

Args:
stream (DataStream): The stream that we're pushing
value (IOTileReading): The reading tha we're pushing


def exit_code(self, code):
    if ((code is not None) and (code in [0, 1, 3])):
        self._exit_code = code
    else:
        self.log.warning(u'Invalid exit code')

Set the App exit code.

For TC Exchange Apps there are 3 supported exit codes.
* 0 indicates a normal exit
* 1 indicates a failure during execution
* 3 indicates a partial failure

Args:
code (integer): The exit code value for the app.


def _add_function(self, func, identify_observed):
    key = self.make_key(func)
    if (key not in self.observers):
        self.observers[key] = ObserverFunction(func, identify_observed, (key, self.observers))
        return True
    else:
        return False

Add a function as an observer.

Args:
func: The function to register as an observer.
identify_observed: See docstring for add_observer.

Returns:
True if the function is added, otherwise False.


def getHostCertPath(self, name):
    path = s_common.genpath(self.certdir, 'hosts', ('%s.crt' % name))
    if (not os.path.isfile(path)):
        return None
    return path

Gets the path to a host certificate.

Args:
name (str): The name of the host keypair.

Examples:
Get the path to the host certificate for the host "myhost":

mypath = cdir.getHostCertPath('myhost')

Returns:
str: The path if exists.


def get_next_base26(prev=None):
    if (not prev):
        return 'a'
    r = re.compile('^[a-z]*$')
    if (not r.match(prev)):
        raise ValueError('Invalid base26')
    if (not prev.endswith('z')):
        return (prev[:(- 1)] + chr((ord(prev[(- 1)]) + 1)))
    return (get_next_base26(prev[:(- 1)]) + 'a')

Increment letter-based IDs.

Generates IDs like ['a', 'b', ..., 'z', 'aa', ab', ..., 'az', 'ba', ...]

Returns:
str: Next base-26 ID.


def process_input(self, stream, value, rpc_executor):

        self.sensor_log.push(stream, value)

        if stream.important:
            associated_output = stream.associated_stream()
            self.sensor_log.push(associated_output, value)

        to_check = deque([x for x in self.roots])

        while len(to_check) > 0:
            node = to_check.popleft()
            if node.triggered():
                try:
                    results = node.process(rpc_executor, self.mark_streamer)
                    for result in results:
                        result.raw_time = value.raw_time
                        self.sensor_log.push(node.stream, result)
                except:
                    self._logger.exception("Unhandled exception in graph node processing function for node %s", str(node))

                if len(results) > 0:
                    to_check.extend(node.outputs)

Process an input through this sensor graph.

The tick information in value should be correct and is transfered
to all results produced by nodes acting on this tick.

Args:
stream (DataStream): The stream the input is part of
value (IOTileReading): The value to process
rpc_executor (RPCExecutor): An object capable of executing RPCs
in case we need to do that.


def set_timing(self, timing: bool, reset: bool=False) -> None:
    self._timing = timing
    if reset:
        self.reset()

Manually set the ``timing`` parameter, and optionally reset the timers.

Args:
timing: should we be timing?
reset: reset the timers?


def get_object_id_from_graph(access_token=None):
    if (access_token is None):
        access_token = get_graph_token_from_msi()
    endpoint = (('https:
    headers = {'Authorization': ('Bearer ' + access_token), 'Host': GRAPH_RESOURCE_HOST}
    ret = requests.get(endpoint, headers=headers)
    return ret.json()['id']

Return the object ID for the Graph user who owns the access token.

Args:
access_token (str): A Microsoft Graph access token. (Not an Azure access token.)
If not provided, attempt to get it from MSI_ENDPOINT.

Returns:
An object ID string for a user or service principal.


def get_definition(self, name: YangIdentifier, kw: YangIdentifier) -> Optional['Statement']:
    stmt = self.superstmt
    while stmt:
        res = stmt.find1(kw, name)
        if res:
            return res
        stmt = stmt.superstmt
    return None

Search ancestor statements for a definition.

Args:
name: Name of a grouping or datatype (with no prefix).
kw: ``grouping`` or ``typedef``.

Raises:
DefinitionNotFound: If the definition is not found.


def parse_panel_app_panel(panel_info, hgnc_map, institute='cust000', panel_type='clinical'):

    date_format = "%Y-%m-%dT%H:%M:%S.%f"

    gene_panel = {}
    gene_panel['version'] = float(panel_info['version'])
    gene_panel['date'] = get_date(panel_info['Created'][:-1], date_format=date_format)
    gene_panel['display_name'] = panel_info['SpecificDiseaseName']
    gene_panel['institute'] = institute
    gene_panel['panel_type'] = panel_type

    LOG.info("Parsing panel %s", gene_panel['display_name'])

    gene_panel['genes'] = []

    nr_low_confidence = 1
    nr_genes = 0
    for nr_genes, gene in enumerate(panel_info['Genes'],1):
        gene_info = parse_panel_app_gene(gene, hgnc_map)
        if not gene_info:
            nr_low_confidence += 1
            continue
        gene_panel['genes'].append(gene_info)

    LOG.info("Number of genes in panel %s", nr_genes)
    LOG.info("Number of low confidence genes in panel %s", nr_low_confidence)

    return gene_panel

Parse a PanelApp panel

Args:
panel_info(dict)
hgnc_map(dict): Map from symbol to hgnc ids
institute(str)
panel_type(str)

Returns:
gene_panel(dict)


def find_newline(self, size=-1):

    if size < 0:
      return self._buffer.find('\n', self._offset)
    return self._buffer.find('\n', self._offset, self._offset + size)

Search for newline char in buffer starting from current offset.

Args:
size: number of bytes to search. -1 means all.

Returns:
offset of newline char in buffer. -1 if doesn't exist.


def _traceback_to_alignment(tb, a, b):

    for idx, direction in tb:
        if direction == Direction.DIAG:
            yield (idx[0] - 1, idx[1] - 1)
        elif direction == Direction.UP:
            yield (idx[0] - 1, None)
        elif direction == Direction.LEFT:
            yield (None, idx[1] - 1)

Convert a traceback (i.e. as returned by `tracebacks()`) into an alignment
(i.e. as returned by `align`).

Arguments:
tb: A traceback.
a: the sequence defining the rows in the traceback matrix.
b: the sequence defining the columns in the traceback matrix.

Returns: An iterable of (index, index) tupless where ether (but not both)
tuples can be `None`.


def create_graph_from_data(self, data, **kwargs):

        self.arguments['{SCORE}'] = self.scores[self.score]
        self.arguments['{CUTOFF}'] = str(self.cutoff)
        self.arguments['{VARSEL}'] = str(self.variablesel).upper()
        self.arguments['{SELMETHOD}'] = self.var_selection[self.selmethod]
        self.arguments['{PRUNING}'] = str(self.pruning).upper()
        self.arguments['{PRUNMETHOD}'] = self.var_selection[self.prunmethod]
        self.arguments['{NJOBS}'] = str(self.nb_jobs)
        self.arguments['{VERBOSE}'] = str(self.verbose).upper()
        results = self._run_cam(data, verbose=self.verbose)

        return nx.relabel_nodes(nx.DiGraph(results),
                                {idx: i for idx, i in enumerate(data.columns)})

Apply causal discovery on observational data using CAM.

Args:
data (pandas.DataFrame): DataFrame containing the data

Returns:
networkx.DiGraph: Solution given by the CAM algorithm.


def _get_entities(self, text, language=''):
    body = {'document': {'type': 'PLAIN_TEXT', 'content': text}, 'encodingType': 'UTF32'}
    if language:
        body['document']['language'] = language
    request = self.service.documents().analyzeEntities(body=body)
    response = request.execute()
    result = []
    for entity in response.get('entities', []):
        mentions = entity.get('mentions', [])
        if (not mentions):
            continue
        entity_text = mentions[0]['text']
        offset = entity_text['beginOffset']
        for word in entity_text['content'].split():
            result.append({'content': word, 'beginOffset': offset})
            offset += len(word)
    return result

Returns the list of entities retrieved from the given text.

Args:
text (str): Input text.
language (:obj:`str`, optional): Language code.

Returns:
List of entities.


def root(self):
    node = self
    while (node.package is not None):
        node = node.package
    return node

Property to return the root of this node.

Returns:
Package: this node's root package.


def extract_jtl_string_pairs_from_text_file(results_dict, file_path):

    result_pairs = re.findall(JTL_REGEX, open(file_path).read())
    for result_key, result_comment in result_pairs:
        results_dict[result_key] = result_comment
    return results_dict

Extracts all string pairs matching the JTL pattern from given text file.

This can be used as an "extract_func" argument in the extract_string_pairs_in_directory method.

Args:
results_dict (dict): The dict to add the the string pairs to.
file_path (str): The path of the file from which to extract the string pairs.


def Pack(cls, obj, version):

    if isinstance(obj, (datetime.datetime, datetime.date)):
      return cls.AdManagerDateTimePacker(obj, version)
    return obj

Pack the given object using Ad Manager-specific logic.

Args:
obj: an object to be packed for SOAP using Ad Manager-specific logic, if
applicable.
version: the version of the current API, e.g. 'v201811'

Returns:
The given object packed with Ad Manager-specific logic for SOAP,
if applicable. Otherwise, returns the given object unmodified.


def read(self, directory, filename, session, spatial=False, spatialReferenceID=4236, replaceParamFile=None, **kwargs):
    path = os.path.join(directory, filename)
    filename_split = filename.split('.')
    name = filename_split[0]
    extension = ''
    if (len(filename_split) >= 2):
        extension = filename_split[(- 1)]
    if os.path.isfile(path):
        session.add(self)
        self._read(directory, filename, session, path, name, extension, spatial, spatialReferenceID, replaceParamFile, **kwargs)
        self._commit(session, self.COMMIT_ERROR_MESSAGE)
    else:
        session.rollback()
        log.warning('Could not find file named {0}. File not read.'.format(filename))

Generic read file into database method.

Args:
directory (str): Directory containing the file to be read.
filename (str): Name of the file which will be read (e.g.: 'example.prj').
session (:mod:`sqlalchemy.orm.session.Session`): SQLAlchemy session object bound to PostGIS enabled database.
spatial (bool, optional): If True, spatially enabled objects will be read in as PostGIS spatial objects.
Defaults to False.
spatialReferenceID (int, optional): Integer id of spatial reference system for the model. Required if
spatial is True. Defaults to srid 4236.
replaceParamFile (:class:`gsshapy.orm.ReplaceParamFile`, optional): ReplaceParamFile instance. Use this if
the file you are reading contains replacement parameters.


def seek(self, offset, whence=os.SEEK_SET):

    if not self._is_open:
      raise IOError('Not opened.')

    if whence not in [os.SEEK_SET, os.SEEK_CUR, os.SEEK_END]:
      raise IOError('Unsupported whence.')

    self._file_object.seek(offset, whence)

Seeks to an offset within the file-like object.

Args:
offset (int): offset to seek to.
whence (Optional(int)): value that indicates whether offset is an absolute
or relative position within the file.

Raises:
IOError: if the seek failed.
OSError: if the seek failed.


def xzhdr(self, header, msgid_range=None):
    args = header
    if (msgid_range is not None):
        args += (' ' + utils.unparse_msgid_range(msgid_range))
    (code, message) = self.command('XZHDR', args)
    if (code != 221):
        raise NNTPReplyError(code, message)
    return self.info(code, message, compressed=True)

XZHDR command.

Args:
msgid_range: A message-id as a string, or an article number as an
integer, or a tuple of specifying a range of article numbers in
the form (first, [last]) - if last is omitted then all articles
after first are included. A msgid_range of None (the default)
uses the current article.


def diff_dictionaries(old_dict, new_dict):
    old_set = set(old_dict)
    new_set = set(new_dict)
    added_set = (new_set - old_set)
    removed_set = (old_set - new_set)
    common_set = (old_set & new_set)
    changes = 0
    output = []
    for key in added_set:
        changes += 1
        output.append(DictValue(key, None, new_dict[key]))
    for key in removed_set:
        changes += 1
        output.append(DictValue(key, old_dict[key], None))
    for key in common_set:
        output.append(DictValue(key, old_dict[key], new_dict[key]))
        if (str(old_dict[key]) != str(new_dict[key])):
            changes += 1
    output.sort(key=attrgetter('key'))
    return [changes, output]

Diffs two single dimension dictionaries

Returns the number of changes and an unordered list
expressing the common entries and changes.

Args:
old_dict(dict): old dictionary
new_dict(dict): new dictionary

Returns: list()
int: number of changed records
list: [DictValue]


def manual_payment(request, invoice_id):
    FORM_PREFIX = 'manual_payment'
    current_invoice = InvoiceController.for_id_or_404(invoice_id)
    form = forms.ManualPaymentForm((request.POST or None), prefix=FORM_PREFIX)
    if (request.POST and form.is_valid()):
        form.instance.invoice = current_invoice.invoice
        form.instance.entered_by = request.user
        form.save()
        current_invoice.update_status()
        form = forms.ManualPaymentForm(prefix=FORM_PREFIX)
    data = {'invoice': current_invoice.invoice, 'form': form}
    return render(request, 'registrasion/manual_payment.html', data)

Allows staff to make manual payments or refunds on an invoice.

This form requires a login, and the logged in user needs to be staff.

Arguments:
invoice_id (castable to int): The invoice ID to be paid

Returns:
render:
Renders ``registrasion/manual_payment.html`` with the following
data::

{
"invoice": models.commerce.Invoice(),
"form": form,   # A form that saves a ``ManualPayment``
# object.
}


def GetMessages(self, formatter_mediator, event):

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

    event_values = event.CopyToDict()

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

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

    return self._ConditionalFormatMessages(event_values)

Determines the formatted message strings for an event object.

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

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

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


def list(self, keyword=None, arg=None):
    return [x for x in self.list_gen(keyword, arg)]

LIST command.

A wrapper for all of the other list commands. The output of this command
depends on the keyword specified. The output format for each keyword can
be found in the list function that corresponds to the keyword.

Args:
keyword: Information requested.
arg: Pattern or keyword specific argument.

Note: Keywords supported by this function are include ACTIVE,
ACTIVE.TIMES, DISTRIB.PATS, HEADERS, NEWSGROUPS, OVERVIEW.FMT and
EXTENSIONS.

Raises:
NotImplementedError: For unsupported keywords.


def push(self, files, run=None, entity=None, project=None, description=None, force=True, progress=False):
    if (project is None):
        project = self.get_project()
    if (project is None):
        raise CommError('No project configured.')
    if (run is None):
        run = self.current_run_id
    (run_id, result) = self.upload_urls(project, files, run, entity, description)
    responses = []
    for (file_name, file_info) in result.items():
        try:
            normal_name = os.path.join(*file_name.split('/'))
            open_file = (files[normal_name] if isinstance(files, dict) else open(normal_name, 'rb'))
        except IOError:
            print(('%s does not exist' % file_name))
            continue
        if progress:
            if hasattr(progress, '__call__'):
                responses.append(self.upload_file_retry(file_info['url'], open_file, progress))
            else:
                length = os.fstat(open_file.fileno()).st_size
                with click.progressbar(file=progress, length=length, label=('Uploading file: %s' % file_name), fill_char=click.style('&', fg='green')) as bar:
                    responses.append(self.upload_file_retry(file_info['url'], open_file, (lambda bites, _: bar.update(bites))))
        else:
            responses.append(self.upload_file_retry(file_info['url'], open_file))
        open_file.close()
    return responses

Uploads multiple files to W&B

Args:
files (list or dict): The filenames to upload
run (str, optional): The run to upload to
entity (str, optional): The entity to scope this project to.  Defaults to wandb models
project (str, optional): The name of the project to upload to. Defaults to the one in settings.
description (str, optional): The description of the changes
force (bool, optional): Whether to prevent push if git has uncommitted changes
progress (callable, or stream): If callable, will be called with (chunk_bytes,
total_bytes) as argument else if True, renders a progress bar to stream.

Returns:
The requests library response object


def from_url(url, format=None):

    string = urllib2.urlopen(url).read()

    if PY3 is True:

        string = string.decode('utf-8')

    if format:

        format = format.lower().replace(" ", "_")
        func = parse.__getattr__("from_%s" % format)
    else:

        func = parse.from_unknown_text

    crs = func(string)
    return crs

Returns the crs object from a string interpreted as a specified format, located at a given url site.

Arguments:

- *url*: The url where the crs string is to be read from.
- *format* (optional): Which format to parse the crs string as. One of "ogc wkt", "esri wkt", or "proj4".
If None, tries to autodetect the format for you (default).

Returns:

- CRS object.


def device(self, idx):

    class GpuDevice(Structure):
        pass
    c_nvmlDevice_t = POINTER(GpuDevice)
    c_index = c_uint(idx)
    device = c_nvmlDevice_t()
    _check_return(_NVML.get_function('nvmlDeviceGetHandleByIndex_v2')(c_index, byref(device)))
    return NvidiaDevice(device)

Get a specific GPU device

Args:
idx: index of device

Returns:
NvidiaDevice: single GPU device


def console_set_default_background(con: tcod.console.Console, col: Tuple[(int, int, int)]) -> None:
    lib.TCOD_console_set_default_background(_console(con), col)

Change the default background color for a console.

Args:
con (Console): Any Console instance.
col (Union[Tuple[int, int, int], Sequence[int]]):
An (r, g, b) sequence or Color instance.

.. deprecated:: 8.5
Use :any:`Console.default_bg` instead.


def read_zmat(cls, inputfile, implicit_index=True):

        cols = ['atom', 'b', 'bond', 'a', 'angle', 'd', 'dihedral']
        if implicit_index:
            zmat_frame = pd.read_table(inputfile, comment='
                                       delim_whitespace=True,
                                       names=cols)
            zmat_frame.index = range(1, len(zmat_frame) + 1)
        else:
            zmat_frame = pd.read_table(inputfile, comment='
                                       delim_whitespace=True,
                                       names=['temp_index'] + cols)
            zmat_frame.set_index('temp_index', drop=True, inplace=True)
            zmat_frame.index.name = None
        if pd.isnull(zmat_frame.iloc[0, 1]):
            zmat_values = [1.27, 127., 127.]
            zmat_refs = [constants.int_label[x] for x in
                         ['origin', 'e_z', 'e_x']]
            for row, i in enumerate(zmat_frame.index[:3]):
                cols = ['b', 'a', 'd']
                zmat_frame.loc[:, cols] = zmat_frame.loc[:, cols].astype('O')
                if row < 2:
                    zmat_frame.loc[i, cols[row:]] = zmat_refs[row:]
                    zmat_frame.loc[i, ['bond', 'angle', 'dihedral'][row:]
                                   ] = zmat_values[row:]
                else:
                    zmat_frame.loc[i, 'd'] = zmat_refs[2]
                    zmat_frame.loc[i, 'dihedral'] = zmat_values[2]

        elif zmat_frame.iloc[0, 1] in constants.int_label.keys():
            zmat_frame = zmat_frame.replace(
                {col: constants.int_label for col in ['b', 'a', 'd']})
        zmat_frame = cls._cast_correct_types(zmat_frame)
        try:
            Zmat = cls(zmat_frame)
        except InvalidReference:
            raise UndefinedCoordinateSystem(
                'Your zmatrix cannot be transformed to cartesian coordinates')
        return Zmat

Reads a zmat file.

Lines beginning with ``#`` are ignored.

Args:
inputfile (str):
implicit_index (bool): If this option is true the first column
has to be the element symbols for the atoms.
The row number is used to determine the index.

Returns:
Zmat:


def _construct(self, context):
    with self.g.as_default():
        if self._pass_through:
            return self._pass_through._construct(context)
        current_value = context.get(self, None)
        assert (current_value is not _unspecified), 'Circular dependency'
        if (current_value is not None):
            return current_value
        context[self] = _unspecified
        method_args = self._replace_deferred(self._method_args, context)
        method_kwargs = self._replace_deferred(self._method_kwargs, context)
        result = self._method(*method_args, **method_kwargs)
        _strip_unnecessary_contents_from_stack(result, set())
        context[self] = result
        return result

Constructs this by calling the deferred method.

This assumes that all unbound_vars have been specified in context and if
this layer has already been computed in this context, then the previously
constructed value will be returned.

Args:
context: A dict of UnboundVariables/_DeferredLayers to their values.
Returns:
The result of calling the given method on this layer.


def append_transformation(self, transformation, extend_collection=False, clear_redo=True):
    if (self.ncores and transformation.use_multiprocessing):
        p = Pool(self.ncores)
        z = map((lambda x: (x, transformation, extend_collection, clear_redo)), self.transformed_structures)
        new_tstructs = p.map(_apply_transformation, z, 1)
        self.transformed_structures = []
        for ts in new_tstructs:
            self.transformed_structures.extend(ts)
    else:
        new_structures = []
        for x in self.transformed_structures:
            new = x.append_transformation(transformation, extend_collection, clear_redo=clear_redo)
            if (new is not None):
                new_structures.extend(new)
        self.transformed_structures.extend(new_structures)

Appends a transformation to all TransformedStructures.

Args:
transformation: Transformation to append
extend_collection: Whether to use more than one output structure
from one-to-many transformations. extend_collection can be a
number, which determines the maximum branching for each
transformation.
clear_redo (bool): Whether to clear the redo list. By default,
this is True, meaning any appends clears the history of
undoing. However, when using append_transformation to do a
redo, the redo list should not be cleared to allow multiple
redos.

Returns:
List of booleans corresponding to initial transformed structures
each boolean describes whether the transformation altered the
structure


def compute_batch_size(dataset):

    def get_static_batch_dim(type_spec):
        try:
            output_shape = type_spec._to_legacy_output_shapes()
        except NotImplementedError:
            return None
        if not isinstance(output_shape, tensor_shape.TensorShape):
            return None
        if output_shape.rank is None:
            return None
        return output_shape.dims[0].value
    batch_dims = [get_static_batch_dim(type_spec) for type_spec in nest.flatten(dataset_ops.get_structure(dataset))]
    if all((d is not None for d in batch_dims)):
        if all((d == batch_dims[0] for d in batch_dims)):
            batch_dim = batch_dims[0]
        else:
            batch_dim = -1
        return constant_op.constant(batch_dim, dtype=dtypes.int64, name='static_batch_size')
    return ged_ops.compute_batch_size(dataset._variant_tensor)

An operation that returns the batch size of the dataset.

This op tries to infer the batch size statically by walking up the dataset
tree from the final dataset node and returning the batch size of the first
batching dataset (such as from .batch() and .padded_batch()) that it
encounters. This differs from using the `element_spec` of a dataset in that it
does not account for partial batches.

This operation may fail if it encounters contradictory batch sizes (for
example, if the dataset is created by zipping together two datasets with
different batch sizes), if there are no explicit batching transformations, or
if there are operations downstream from the batching transformation that may
modify its batch size. In these cases, it returns a -1.

Args:
dataset: A `tf.data.Dataset` object.

Returns:
A `tf.int64` Tensor representing the batch size of the dataset sans partial
batches. If this cannot be inferred statically, the value of this tensor
will be -1.


def filter_by_months(self, months):

        _filt_values = []
        _filt_datetimes = []
        for i, d in enumerate(self.datetimes):
            if d in months:
                _filt_datetimes.append(d)
                _filt_values.append(self._values[i])
        _filt_header = self.header.duplicate()
        return MonthlyCollection(_filt_header, _filt_values, _filt_datetimes)

Filter the Data Collection based on a list of months of the year (as integers).

Args:
months: A List of months of the year [1..12]

Return:
A new Data Collection with filtered data


def _add_sync_queues_and_barrier(self, name, dependencies):

        self._sync_queue_counter += 1
        with tf.device(self.sync_queue_devices[self._sync_queue_counter % len(self.sync_queue_devices)]):
            sync_queues = [
                tf.FIFOQueue(self.num_worker, [tf.bool], shapes=[[]],
                             shared_name='%s%s' % (name, i))
                for i in range(self.num_worker)]
            queue_ops = []

            token = tf.constant(False)
            with tf.control_dependencies(dependencies):
                for i, q in enumerate(sync_queues):
                    if i != self.task_index:
                        queue_ops.append(q.enqueue(token))

            queue_ops.append(
                sync_queues[self.task_index].dequeue_many(len(sync_queues) - 1))

            return tf.group(*queue_ops, name=name)

Adds ops to enqueue on all worker queues.

Args:
name: prefixed for the shared_name of ops.
dependencies: control dependency from ops.

Returns:
an op that should be used as control dependency before starting next step.


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

    if registry_key is None:
      return

    values_dict = {}
    for value_name in self._VALUE_NAMES:
      registry_value = registry_key.GetValueByName(value_name)
      if not registry_value:
        continue

      value_data = registry_value.GetDataAsObject()
      if value_data is None:
        continue

      values_dict[value_name] = value_data

    event_data = windows_events.WindowsRegistryEventData()
    event_data.key_path = registry_key.path
    event_data.offset = registry_key.offset
    event_data.regvalue = values_dict

    event = time_events.DateTimeValuesEvent(
        registry_key.last_written_time, definitions.TIME_DESCRIPTION_WRITTEN)
    parser_mediator.ProduceEventWithEventData(event, event_data)

Extracts events from a Windows Registry key.

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


def easeInOutCirc(n):
    _checkRange(n)
    n = (n * 2)
    if (n < 1):
        return ((- 0.5) * (math.sqrt((1 - (n ** 2))) - 1))
    else:
        n = (n - 2)
        return (0.5 * (math.sqrt((1 - (n ** 2))) + 1))

A circular tween function that accelerates, reaches the midpoint, and then decelerates.

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

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


def parse(self, line, cell, namespace=None):
    if (namespace is None):
        ipy = IPython.get_ipython()
        namespace = ipy.user_ns
    args = CommandParser.create_args(line, namespace)
    sub_parsers_progs = [x.prog for x in self._get_subparsers()]
    matched_progs = []
    for prog in sub_parsers_progs:
        match = prog.split()[1:]
        for i in range(len(args)):
            if (args[i:(i + len(match))] == match):
                matched_progs.append(prog)
                break
    matched_prog = None
    if matched_progs:
        matched_prog = max(matched_progs, key=(lambda x: len(x.split())))
    line_args = self._get_subparser_line_args(matched_prog)
    if line_args:
        cell_config = None
        try:
            (cell_config, cell) = google.datalab.utils.commands.parse_config_for_selected_keys(cell, line_args)
        except:
            pass
        if cell_config:
            google.datalab.utils.commands.replace_vars(cell_config, namespace)
            for arg_name in cell_config:
                arg_value = cell_config[arg_name]
                if (arg_value is None):
                    continue
                if (('--' + arg_name) in args):
                    raise ValueError(('config item "%s" is specified in both cell and line.' % arg_name))
                if isinstance(arg_value, bool):
                    if arg_value:
                        line += (' --%s' % arg_name)
                else:
                    line += (' --%s %s' % (arg_name, str(cell_config[arg_name])))
    args = CommandParser.create_args(line, namespace)
    args = vars(self.parse_args(args))
    cell_config = None
    cell_args = self._get_subparser_cell_args(matched_prog)
    if cell_args:
        try:
            (cell_config, _) = google.datalab.utils.commands.parse_config_for_selected_keys(cell, cell_args)
        except:
            pass
        if cell_config:
            google.datalab.utils.commands.replace_vars(cell_config, namespace)
        for arg in cell_args:
            if (cell_args[arg]['required'] and ((cell_config is None) or (cell_config.get(arg, None) is None))):
                raise ValueError(('Cell config "%s" is required.' % arg))
    if cell_config:
        args.update(cell_config)
    return (args, cell)

Parses a line and cell into a dictionary of arguments, expanding variables from a namespace.

For each line parameters beginning with --, it also checks the cell content and see if it exists
there. For example, if "--config1" is a line parameter, it checks to see if cell dict contains
"config1" item, and if so, use the cell value. The "config1" item will also be removed from
cell content.

Args:
line: line content.
cell: cell content.
namespace: user namespace. If None, IPython's user namespace is used.

Returns:
A tuple of: 1. parsed config dict. 2. remaining cell after line parameters are extracted.


def onScreen(x, y=None):
    (x, y) = _unpackXY(x, y)
    x = int(x)
    y = int(y)
    (width, height) = platformModule._size()
    return ((0 <= x < width) and (0 <= y < height))

Returns whether the given xy coordinates are on the screen or not.

Args:
Either the arguments are two separate values, first arg for x and second
for y, or there is a single argument of a sequence with two values, the
first x and the second y.
Example: onScreen(x, y) or onScreen([x, y])

Returns:
bool: True if the xy coordinates are on the screen at its current
resolution, otherwise False.


def buckets_get(self, bucket, projection='noAcl'):

    args = {'projection': projection}
    url = Api._ENDPOINT + (Api._BUCKET_PATH % bucket)
    return google.datalab.utils.Http.request(url, credentials=self._credentials, args=args)

Issues a request to retrieve information about a bucket.

Args:
bucket: the name of the bucket.
projection: the projection of the bucket information to retrieve.
Returns:
A parsed bucket information dictionary.
Raises:
Exception if there is an error performing the operation.


def add_batch_parser(subparsers, parent_parser):

    parser = subparsers.add_parser(
        'batch',
        help='Displays information about batches and submit new batches',
        description='Provides subcommands to display Batch information and '
        'submit Batches to the validator via the REST API.')

    grand_parsers = parser.add_subparsers(title='subcommands',
                                          dest='subcommand')
    grand_parsers.required = True
    add_batch_list_parser(grand_parsers, parent_parser)
    add_batch_show_parser(grand_parsers, parent_parser)
    add_batch_status_parser(grand_parsers, parent_parser)
    add_batch_submit_parser(grand_parsers, parent_parser)

Adds arguments parsers for the batch list, batch show and batch status
commands

Args:
subparsers: Add parsers to this subparser object
parent_parser: The parent argparse.ArgumentParser object


def main(pipeline_name, pipeline_context_input, working_dir, log_level, log_path):
    pypyr.log.logger.set_root_logger(log_level, log_path)
    logger.debug('starting pypyr')
    pypyr.moduleloader.set_working_directory(working_dir)
    load_and_run_pipeline(pipeline_name=pipeline_name, pipeline_context_input=pipeline_context_input, working_dir=working_dir)
    logger.debug('pypyr done')

Entry point for pypyr pipeline runner.

Call this once per pypyr run. Call me if you want to run a pypyr pipeline
from your own code. This function does some one-off 1st time initialization
before running the actual pipeline.

pipeline_name.yaml should be in the working_dir/pipelines/ directory.

Args:
pipeline_name: string. Name of pipeline, sans .yaml at end.
pipeline_context_input: string. Initialize the pypyr context with this
string.
working_dir: path. looks for ./pipelines and modules in this directory.
log_level: int. Standard python log level enumerated value.
log_path: os.path. Append log to this path.

Returns:
None


def list():
    kbs = []
    ret = _pshell_json('Get-HotFix | Select HotFixID')
    for item in ret:
        kbs.append(item['HotFixID'])
    return kbs

Get a list of updates installed on the machine

Returns:
list: A list of installed updates

CLI Example:

.. code-block:: bash

salt '*' wusa.list


def sbi_ids(self) -> List[str]:
    return ast.literal_eval(DB.get_hash_value(self._key, 'sbi_ids'))

Get the list of SBI Ids.

Returns:
list, list of SBI ids associated with this subarray.


def create_public_ip(access_token, subscription_id, resource_group, public_ip_name, dns_label, location):
    endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourceGroups/', resource_group, '/providers/Microsoft.Network/publicIPAddresses/', public_ip_name, '?api-version=', NETWORK_API])
    ip_body = {'location': location}
    properties = {'publicIPAllocationMethod': 'Dynamic'}
    properties['dnsSettings'] = {'domainNameLabel': dns_label}
    ip_body['properties'] = properties
    body = json.dumps(ip_body)
    return do_put(endpoint, body, access_token)

Create a public ip address.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
public_ip_name (str): Name of the new public ip address resource.
dns_label (str): DNS label to apply to the IP address.
location (str): Azure data center location. E.g. westus.

Returns:
HTTP response. Public IP address JSON body.


def copy2(src, dst, metadata=None, retry_params=None):

  common.validate_file_path(src)
  common.validate_file_path(dst)

  if metadata is None:
    metadata = {}
    copy_meta = 'COPY'
  else:
    copy_meta = 'REPLACE'
  metadata.update({'x-goog-copy-source': src,
                   'x-goog-metadata-directive': copy_meta})

  api = storage_api._get_storage_api(retry_params=retry_params)
  status, resp_headers, content = api.put_object(
      api_utils._quote_filename(dst), headers=metadata)
  errors.check_status(status, [200], src, metadata, resp_headers, body=content)

Copy the file content from src to dst.

Args:
src: /bucket/filename
dst: /bucket/filename
metadata: a dict of metadata for this copy. If None, old metadata is copied.
For example, {'x-goog-meta-foo': 'bar'}.
retry_params: An api_utils.RetryParams for this call to GCS. If None,
the default one is used.

Raises:
errors.AuthorizationError: if authorization failed.
errors.NotFoundError: if an object that's expected to exist doesn't.


def validate(self, value):
    if (value == ''):
        if self.kwargs.get('nullable', __nullable__):
            value = None
        else:
            value = 0
    if (not isinstance(value, Model)):
        return super(ReferenceProperty, self).validate(value)
    if (not value.is_saved()):
        raise BadValueError(('%s instance must be saved before it can be stored as a reference' % self.reference_class.__class__.__name__))
    if (not isinstance(value, self.reference_class)):
        raise KindError(('Property %s must be an instance of %s' % (self.name, self.reference_class.__class__.__name__)))
    return value

Validate reference.

Returns:
A valid value.

Raises:
BadValueError for the following reasons:
- Value is not saved.
- Object not of correct model type for reference.


def get_list_subtask_positions_objs(client, list_id):
    params = {'list_id': int(list_id)}
    response = client.authenticated_request(client.api.Endpoints.SUBTASK_POSITIONS, params=params)
    return response.json()

Gets all subtask positions objects for the tasks within a given list. This is a convenience method so you don't have to get all the list's tasks before getting subtasks, though I can't fathom how mass subtask reordering is useful.

Returns:
List of SubtaskPositionsObj-mapped objects representing the order of subtasks for the tasks within the given list


def __random_density_hs(N, rank=None, seed=None):

    G = __ginibre_matrix(N, rank, seed)
    G = G.dot(G.conj().T)
    return G / np.trace(G)

Generate a random density matrix from the Hilbert-Schmidt metric.

Args:
N (int): the length of the density matrix.
rank (int or None): the rank of the density matrix. The default
value is full-rank.
seed (int): Optional. To set a random seed.
Returns:
ndarray: rho (N,N  a density matrix.


def decrypt(key, ciphertext, shift_function=shift_case_english):

    return [shift_function(key, symbol) for symbol in ciphertext]

Decrypt Shift enciphered ``ciphertext`` using ``key``.

Examples:
>>> ''.join(decrypt(3, "KHOOR"))
HELLO

>> decrypt(15, [0xcf, 0x9e, 0xaf, 0xe0], shift_bytes)
[0xde, 0xad, 0xbe, 0xef]

Args:
key (int): The shift to use
ciphertext (iterable): The symbols to decrypt
shift_function (function (shift, symbol)): Shift function to apply to symbols in the ciphertext

Returns:
Decrypted ciphertext, list of plaintext symbols


def matches(self, msg_seq: int, msg: MessageInterface) -> bool:
    return all((crit.matches(msg_seq, msg) for crit in self.all_criteria))

The message matches if all the defined search key criteria match.

Args:
msg_seq: The message sequence ID.
msg: The message object.


def predict(self, data, alpha=0.01, max_iter=2000, **kwargs):

        edge_model = GraphLasso(alpha=alpha, max_iter=max_iter)
        edge_model.fit(data.values)

        return nx.relabel_nodes(nx.DiGraph(edge_model.get_precision()),
                                {idx: i for idx, i in enumerate(data.columns)})

Predict the graph skeleton.

Args:
data (pandas.DataFrame): observational data
alpha (float): regularization parameter
max_iter (int): maximum number of iterations

Returns:
networkx.Graph: Graph skeleton


def _create_sample_validator(expected_input_keys: Collection[str]) -> Callable[[rd.RepresentativeSample], rd.RepresentativeSample]:

    def validator(sample: rd.RepresentativeSample) -> rd.RepresentativeSample:

        if not isinstance(sample, Mapping):
            raise ValueError(f'Invalid representative sample type. Provide a mapping (usually a dict) of {{input_key: input_value}}. Got type: {type(sample)} instead.')
        if set(sample.keys()) != expected_input_keys:
            raise KeyError(f'Invalid input keys for representative sample. The function expects input keys of: {set(expected_input_keys)}. Got: {set(sample.keys())}. Please provide correct input keys for representative samples.')
        return sample
    return validator

Creates a validator function for a representative sample.

Args:
expected_input_keys: Input keys (keyword argument names) that the function
the sample will be used for is expecting to receive.

Returns:
A callable that validates a `RepresentativeSample`.


def _validate_iss(claims, issuer=None):

    if issuer is not None:
        if isinstance(issuer, string_types):
            issuer = (issuer,)
        if claims.get('iss') not in issuer:
            raise JWTClaimsError('Invalid issuer')

Validates that the 'iss' claim is valid.

The "iss" (issuer) claim identifies the principal that issued the
JWT.  The processing of this claim is generally application specific.
The "iss" value is a case-sensitive string containing a StringOrURI
value.  Use of this claim is OPTIONAL.

Args:
claims (dict): The claims dictionary to validate.
issuer (str or iterable): Acceptable value(s) for the issuer that
signed the token.


def _get_required_fn(fn, root_path):
    if (not fn.startswith(root_path)):
        raise ValueError('Both paths have to be absolute or local!')
    replacer = ('/' if root_path.endswith('/') else '')
    return fn.replace(root_path, replacer, 1)

Definition of the MD5 file requires, that all paths will be absolute
for the package directory, not for the filesystem.

This function converts filesystem-absolute paths to package-absolute paths.

Args:
fn (str): Local/absolute path to the file.
root_path (str): Local/absolute path to the package directory.

Returns:
str: Package-absolute path to the file.

Raises:
ValueError: When `fn` is absolute and `root_path` relative or \
conversely.


def get_hours_description(self):
    expression = self._expression_parts[2]
    return self.get_segment_description(expression, _('every hour'), (lambda s: self.format_time(s, '0')), (lambda s: _('every {0} hours').format(s)), (lambda s: _('between {0} and {1}')), (lambda s: _('at {0}')))

Generates a description for only the HOUR portion of the expression

Returns:
The HOUR description


def pathcase(string):

    string = snakecase(string)
    if not string:
        return string
    return re.sub(r"_", "/", string)

Convert string into path case.
Join punctuation with slash.

Args:
string: String to convert.

Returns:
string: Path cased string.


def compile_source(self, sourcepath):
    relpath = os.path.relpath(sourcepath, self.settings.SOURCES_PATH)
    conditions = {'sourcedir': None, 'nopartial': True, 'exclude_patterns': self.settings.EXCLUDES, 'excluded_libdirs': self.settings.LIBRARY_PATHS}
    if self.finder.match_conditions(sourcepath, **conditions):
        destination = self.finder.get_destination(relpath, targetdir=self.settings.TARGET_PATH)
        self.logger.debug(u'Compile: {}'.format(sourcepath))
        (success, message) = self.compiler.safe_compile(self.settings, sourcepath, destination)
        if success:
            self.logger.info(u'Output: {}'.format(message))
        else:
            self.logger.error(message)
        return (sourcepath, destination)
    return None

Compile source to its destination

Check if the source is eligible to compile (not partial and allowed
from exclude patterns)

Args:
sourcepath (string): Sass source path to compile to its
destination using project settings.

Returns:
tuple or None: A pair of (sourcepath, destination), if source has
been compiled (or at least tried). If the source was not
eligible to compile, return will be ``None``.


def format_statevector(vec, decimals=None):
    num_basis = len(vec)
    vec_complex = np.zeros(num_basis, dtype=complex)
    for i in range(num_basis):
        vec_complex[i] = (vec[i][0] + (1j * vec[i][1]))
    if decimals:
        vec_complex = np.around(vec_complex, decimals=decimals)
    return vec_complex

Format statevector coming from the backend to present to the Qiskit user.

Args:
vec (list): a list of [re, im] complex numbers.
decimals (int): the number of decimals in the statevector.
If None, no rounding is done.

Returns:
list[complex]: a list of python complex numbers.


def load_tf_sharded_weights_from_safetensors(model, shard_files, ignore_mismatched_sizes=False, strict=False, _prefix=None):
    unexpected_keys = set()
    all_missing_keys = []
    mismatched_keys = set()
    for shard_file in shard_files:
        missing_layers, unexpected_layers, mismatched_layers = load_tf_weights_from_safetensors(model, shard_file, ignore_mismatched_sizes=ignore_mismatched_sizes, _prefix=_prefix)
        all_missing_keys.append(set(missing_layers))
        unexpected_keys.update(unexpected_layers)
        mismatched_keys.update(mismatched_layers)
        gc.collect()
    missing_keys = set.intersection(*all_missing_keys)
    if strict and (len(missing_keys) > 0 or len(unexpected_keys) > 0):
        error_message = f'Error(s) in loading state_dict for {model.__class__.__name__}'
        if len(missing_keys) > 0:
            str_missing_keys = ','.join([f'"{k}"' for k in missing_keys])
            error_message += f'\nMissing key(s): {str_missing_keys}.'
        if len(unexpected_keys) > 0:
            str_unexpected_keys = ','.join([f'"{k}"' for k in unexpected_keys])
            error_message += f'\nMissing key(s): {str_unexpected_keys}.'
        raise RuntimeError(error_message)
    return (missing_keys, unexpected_keys, mismatched_keys)

This is the same as `load_tf_weights_from_safetensors` but for a sharded TF-format safetensors checkpoint.
Detect missing and unexpected layers and load the TF weights from the shard file accordingly to their names and
shapes.

This load is performed efficiently: each checkpoint shard is loaded one by one in RAM and deleted after being
loaded in the model.

Args:
model (`keras.models.Model`): The model in which to load the checkpoint.
shard_files (`str` or `os.PathLike`): A list containing the sharded checkpoint names.
ignore_mismatched_sizes`bool`, *optional`, defaults to `True`):
Whether or not to ignore the mismatch between the sizes
strict (`bool`, *optional*, defaults to `True`):
Whether to strictly enforce that the keys in the model state dict match the keys in the sharded checkpoint.

Returns:
Three lists, one for the missing layers, another one for the unexpected layers, and a last one for the
mismatched layers.


def attach(cls, transform_job_name, sagemaker_session=None):
    sagemaker_session = (sagemaker_session or Session())
    job_details = sagemaker_session.sagemaker_client.describe_transform_job(TransformJobName=transform_job_name)
    init_params = cls._prepare_init_params_from_job_description(job_details)
    transformer = cls(sagemaker_session=sagemaker_session, **init_params)
    transformer.latest_transform_job = _TransformJob(sagemaker_session=sagemaker_session, job_name=init_params['base_transform_job_name'])
    return transformer

Attach an existing transform job to a new Transformer instance

Args:
transform_job_name (str): Name for the transform job to be attached.
sagemaker_session (sagemaker.session.Session): Session object which manages interactions with
Amazon SageMaker APIs and any other AWS services needed. If not specified, one will be created
using the default AWS configuration chain.

Returns:
sagemaker.transformer.Transformer: The Transformer instance with the specified transform job attached.


def _on_receive(self, client, userdata, message):

        topic = message.topic
        encoded = message.payload

        try:
            packet = json.loads(encoded)
        except ValueError:
            self._logger.warn("Could not decode json packet: %s", encoded)
            return

        try:
            seq = packet['sequence']
            message_data = packet['message']
        except KeyError:
            self._logger.warn("Message received did not have required sequence and message keys: %s", packet)
            return

        if topic not in self.queues:
            found = False
            for _, regex, callback, ordered in self.wildcard_queues:
                if regex.match(topic):
                    self.queues[topic] = PacketQueue(0, callback, ordered)
                    found = True
                    break

            if not found:
                self._logger.warn("Received message for unknown topic: %s", topic)
                return

        self.queues[topic].receive(seq, [seq, topic, message_data])

Callback called whenever we receive a message on a subscribed topic

Args:
client (string): The client id of the client receiving the message
userdata (string): Any user data set with the underlying MQTT client
message (object): The mesage with a topic and payload.


def _apply(self, ctx: ExtensionContext) -> AugmentedDict:

    def process(pattern: Pattern[str], _str: str) -> Any:
        _match = pattern.match(_str)
        if (_match is None):
            return _str
        (placeholder, external_path) = (_match.group(1), _match.group(2))
        with open(self.locator(external_path, (cast(str, ctx.document) if Validator.is_file(document=ctx.document) else None))) as fhandle:
            content = fhandle.read()
        return _str.replace(placeholder, content)
    (node_key, node_value) = ctx.node
    _pattern = re.compile(self.__pattern__)
    return {node_key: process(_pattern, node_value)}

Performs the actual loading of an external resource into the current model.

Args:
ctx: The processing context.

Returns:
Returns a dictionary that gets incorporated into the actual model.


def get_item_concept_mapping(self, lang):
    concepts = self.filter(active=True, lang=lang)
    return group_keys_by_value_lists(Concept.objects.get_concept_item_mapping(concepts, lang))

Get mapping of items_ids to concepts containing these items

Args:
lang (str): language of concepts

Returns:
dict: item (int) -> set of concepts (int)


def Open(self, file_object):
    if (not file_object):
        raise ValueError('Missing file-like object.')
    file_object.seek(0, os.SEEK_SET)
    data = file_object.read(len(self._HEADER_SIGNATURE))
    if (data != self._HEADER_SIGNATURE):
        file_object.close()
        raise IOError('Unsupported SQLite database signature.')
    with tempfile.NamedTemporaryFile(delete=False) as temp_file:
        self._temp_file_path = temp_file.name
        while data:
            temp_file.write(data)
            data = file_object.read(self._COPY_BUFFER_SIZE)
    self._connection = sqlite3.connect(self._temp_file_path)
    self._connection.text_factory = bytes
    self._cursor = self._connection.cursor()

Opens the database file object.

Args:
file_object (FileIO): file-like object.

Raises:
IOError: if the SQLite database signature does not match.
OSError: if the SQLite database signature does not match.
ValueError: if the file-like object is invalid.


def get_all_leaves(self, item_ids=None, language=None, forbidden_item_ids=None):

        return sorted(set(flatten(self.get_leaves(item_ids, language=language, forbidden_item_ids=forbidden_item_ids).values())))

Get all leaves reachable from the given set of items. Leaves having
inactive relations to other items are omitted.

Args:
item_ids (list): items which are taken as roots for the reachability
language (str): if specified, filter out items which are not
available in the given language

Returns:
set: leaf items which are reachable from the given set of items


def get_angle(v1, v2, units="degrees"):

    d = np.dot(v1, v2) / np.linalg.norm(v1) / np.linalg.norm(v2)
    d = min(d, 1)
    d = max(d, -1)
    angle = math.acos(d)
    if units == "degrees":
        return math.degrees(angle)
    elif units == "radians":
        return angle
    else:
        raise ValueError("Invalid units {}".format(units))

Calculates the angle between two vectors.

Args:
v1: Vector 1
v2: Vector 2
units: "degrees" or "radians". Defaults to "degrees".

Returns:
Angle between them in degrees.


def ParseInteger(text, is_signed=False, is_long=False):
    result = _ParseAbstractInteger(text, is_long=is_long)
    checker = _INTEGER_CHECKERS[((2 * int(is_long)) + int(is_signed))]
    checker.CheckValue(result)
    return result

Parses an integer.

Args:
text: The text to parse.
is_signed: True if a signed integer must be parsed.
is_long: True if a long integer must be parsed.

Returns:
The integer value.

Raises:
ValueError: Thrown Iff the text is not a valid integer.


def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
    local_stream = BytearrayStream()
    if self._unique_identifier:
        self._unique_identifier.write(local_stream, kmip_version=kmip_version)
    else:
        raise ValueError('Invalid struct missing the unique identifier attribute.')
    if self._cryptographic_parameters:
        self._cryptographic_parameters.write(local_stream, kmip_version=kmip_version)
    self.length = local_stream.length()
    super(MACSignatureKeyInformation, self).write(output_stream, kmip_version=kmip_version)
    output_stream.write(local_stream.buffer)

Write the data encoding the MACSignatureKeyInformation struct to a
stream.

Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.


def make_coordinated_read_dataset(self, cluster, num_consumers, sharding_policy=data_service_ops.ShardingPolicy.OFF):
    if sharding_policy not in [data_service_ops.ShardingPolicy.OFF, data_service_ops.ShardingPolicy.DYNAMIC]:
        raise ValueError(f'Unsupported sharding policy: {sharding_policy}')
    ds = dataset_ops.Dataset.from_tensors(math_ops.cast(0, dtypes.int64))
    ds = ds.concatenate(dataset_ops.Dataset.random())

    def make_group(x):
        x = x % 2 ** 32
        return dataset_ops.Dataset.range(x * num_consumers, (x + 1) * num_consumers)
    ds = ds.flat_map(make_group)
    consumers = []
    for consumer_index in range(num_consumers):
        consumers.append(self.make_distributed_dataset(ds, cluster, job_name='test', processing_mode=sharding_policy, consumer_index=consumer_index, num_consumers=num_consumers))
    ds = dataset_ops.Dataset.from_tensor_slices(consumers)
    ds = ds.interleave(lambda x: x, cycle_length=num_consumers, num_parallel_calls=num_consumers)
    return ds

Creates a dataset that performs coordinated reads.

The dataset simulates `num_consumers` consumers by using parallel
interleave to read with `num_consumers` threads, one for each consumer. The
nth element of the dataset is produced by consumer `n % num_consumers`.

The dataset executed on each worker will produce groups of `num_consumers`
sequentially increasing numbers. For example, if `num_consumers=3` a worker
dataset could produce [0, 1, 2, 9, 10, 11, 21, 22, 23]. This enables
`checkCoordinatedReadGroups` below to assess whether the values received in
each step came from the same group.

Args:
cluster: A tf.data service `TestCluster`.
num_consumers: The number of consumers to simulate.
sharding_policy: The sharding policy to use. Currently only OFF and
DYNAMIC are supported.

Returns:
A dataset that simulates reading with `num_consumers` consumers.


def make_hash(self, task):
    t = [serialize_object(task['func_name'])[0], serialize_object(task['fn_hash'])[0], serialize_object(task['args'])[0], serialize_object(task['kwargs'])[0], serialize_object(task['env'])[0]]
    x = b''.join(t)
    hashedsum = hashlib.md5(x).hexdigest()
    return hashedsum

Create a hash of the task inputs.

This uses a serialization library borrowed from ipyparallel.
If this fails here, then all ipp calls are also likely to fail due to failure
at serialization.

Args:
- task (dict) : Task dictionary from dfk.tasks

Returns:
- hash (str) : A unique hash string


def __init__(self, channel):

        self.GetGroup = channel.unary_unary(
            "/google.devtools.clouderrorreporting.v1beta1.ErrorGroupService/GetGroup",
            request_serializer=google_dot_devtools_dot_clouderrorreporting__v1beta1_dot_proto_dot_error__group__service__pb2.GetGroupRequest.SerializeToString,
            response_deserializer=google_dot_devtools_dot_clouderrorreporting__v1beta1_dot_proto_dot_common__pb2.ErrorGroup.FromString,
        )
        self.UpdateGroup = channel.unary_unary(
            "/google.devtools.clouderrorreporting.v1beta1.ErrorGroupService/UpdateGroup",
            request_serializer=google_dot_devtools_dot_clouderrorreporting__v1beta1_dot_proto_dot_error__group__service__pb2.UpdateGroupRequest.SerializeToString,
            response_deserializer=google_dot_devtools_dot_clouderrorreporting__v1beta1_dot_proto_dot_common__pb2.ErrorGroup.FromString,
        )

Constructor.

Args:
channel: A grpc.Channel.


def sketch_fasta(fasta_path, outdir):
    genome_name = genome_name_from_fasta_path(fasta_path)
    outpath = os.path.join(outdir, genome_name)
    args = ['mash', 'sketch', '-o', outpath, fasta_path]
    logging.info('Running Mash sketch with command: %s', ' '.join(args))
    p = Popen(args)
    p.wait()
    sketch_path = (outpath + '.msh')
    assert os.path.exists(sketch_path), 'Mash sketch for genome {} was not created at {}'.format(genome_name, sketch_path)
    return sketch_path

Create a Mash sketch from an input fasta file

Args:
fasta_path (str): input fasta file path. Genome name in fasta filename
outdir (str): output directory path to write Mash sketch file to

Returns:
str: output Mash sketch file path


def distort_color(image, thread_id=0, scope=None):

  with tf.name_scope(values=[image], name=scope, default_name='distort_color'):
    color_ordering = thread_id % 2

    if color_ordering == 0:
      image = tf.image.random_brightness(image, max_delta=32. / 255.)
      image = tf.image.random_saturation(image, lower=0.5, upper=1.5)
      image = tf.image.random_hue(image, max_delta=0.2)
      image = tf.image.random_contrast(image, lower=0.5, upper=1.5)
    elif color_ordering == 1:
      image = tf.image.random_brightness(image, max_delta=32. / 255.)
      image = tf.image.random_contrast(image, lower=0.5, upper=1.5)
      image = tf.image.random_saturation(image, lower=0.5, upper=1.5)
      image = tf.image.random_hue(image, max_delta=0.2)

    image = tf.clip_by_value(image, 0.0, 1.0)
    return image

Distort the color of the image.

Each color distortion is non-commutative and thus ordering of the color ops
matters. Ideally we would randomly permute the ordering of the color ops.
Rather then adding that level of complication, we select a distinct ordering
of color ops for each preprocessing thread.

Args:
image: Tensor containing single image.
thread_id: preprocessing thread ID.
scope: Optional scope for name_scope.
Returns:
color-distorted image


def ParseRecord(self, parser_mediator, key, structure):
    if (key not in ('log_entry', 'log_entry_at_end', 'log_entry_offset', 'log_entry_offset_at_end')):
        raise errors.ParseError('Unable to parse record, unknown structure: {0:s}'.format(key))
    try:
        date_time_string = self._GetISO8601String(structure)
    except ValueError as exception:
        parser_mediator.ProduceExtractionWarning('unable to determine date time string with error: {0!s}'.format(exception))
    fraction_of_second_length = len(structure.fraction_of_second)
    if (fraction_of_second_length == 3):
        date_time = dfdatetime_time_elements.TimeElementsInMilliseconds()
    elif (fraction_of_second_length in (6, 7)):
        date_time = dfdatetime_time_elements.TimeElementsInMicroseconds()
    try:
        date_time.CopyFromStringISO8601(date_time_string)
    except ValueError as exception:
        parser_mediator.ProduceExtractionWarning('unable to parse date time value: {0:s} with error: {1!s}'.format(date_time_string, exception))
        return
    event_data = SCCMLogEventData()
    event_data.component = structure.component
    event_data.offset = 0
    event_data.text = structure.text
    event = time_events.DateTimeValuesEvent(date_time, definitions.TIME_DESCRIPTION_WRITTEN)
    parser_mediator.ProduceEventWithEventData(event, event_data)

Parse the record and return an SCCM log event object.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
key (str): name of the parsed structure.
structure (pyparsing.ParseResults): structure of tokens derived from
a line of a text file.

Raises:
ParseError: when the structure type is unknown.


def find_local_maxima(self, input_grid):
    (pixels, q_data) = self.quantize(input_grid)
    centers = OrderedDict()
    for p in pixels.keys():
        centers[p] = []
    marked = (np.ones(q_data.shape, dtype=int) * self.UNMARKED)
    MIN_INFL = int(np.round((1 + (0.5 * np.sqrt(self.max_size)))))
    MAX_INFL = (2 * MIN_INFL)
    marked_so_far = []
    for b in sorted(pixels.keys(), reverse=True):
        infl_dist = (MIN_INFL + int(np.round(((float(b) / self.max_bin) * (MAX_INFL - MIN_INFL)))))
        for p in pixels[b]:
            if (marked[p] == self.UNMARKED):
                ok = False
                del marked_so_far[:]
                for ((i, j), v) in np.ndenumerate(marked[((p[0] - infl_dist):((p[0] + infl_dist) + 1), (p[1] - infl_dist):((p[1] + infl_dist) + 1))]):
                    if (v == self.UNMARKED):
                        ok = True
                        marked[(((i - infl_dist) + p[0]), ((j - infl_dist) + p[1]))] = b
                        marked_so_far.append((((i - infl_dist) + p[0]), ((j - infl_dist) + p[1])))
                    else:
                        ok = False
                        break
                if ok:
                    centers[b].append(p)
                else:
                    for m in marked_so_far:
                        marked[m] = self.UNMARKED
    marked[(:, :)] = self.UNMARKED
    deferred_from_last = []
    deferred_to_next = []
    for delta in range(0, (self.delta + 1)):
        for b in sorted(centers.keys(), reverse=True):
            bin_lower = (b - delta)
            deferred_from_last[:] = deferred_to_next[:]
            del deferred_to_next[:]
            foothills = []
            n_centers = len(centers[b])
            tot_centers = (n_centers + len(deferred_from_last))
            for i in range(tot_centers):
                if (i < n_centers):
                    center = centers[b][i]
                else:
                    center = deferred_from_last[(i - n_centers)]
                if (bin_lower < 0):
                    bin_lower = 0
                if (marked[center] == self.UNMARKED):
                    captured = self.set_maximum(q_data, marked, center, bin_lower, foothills)
                    if (not captured):
                        deferred_to_next.append(center)
                    else:
                        pass
            self.remove_foothills(q_data, marked, b, bin_lower, centers, foothills)
        del deferred_from_last[:]
        del deferred_to_next[:]
    return marked

Finds the local maxima in the inputGrid and perform region growing to identify objects.

Args:
input_grid: Raw input data.

Returns:
array with labeled objects.


def compute_weighted_loss(losses, sample_weight=None, reduction=ReductionV2.SUM_OVER_BATCH_SIZE, name=None):
    ReductionV2.validate(reduction)
    if reduction == ReductionV2.AUTO:
        reduction = ReductionV2.SUM_OVER_BATCH_SIZE
    if sample_weight is None:
        sample_weight = 1.0
    with backend.name_scope(name or 'weighted_loss'):
        ops.get_default_graph()._last_loss_reduction = reduction
        if not isinstance(losses, (keras_tensor.KerasTensor, ragged_tensor.RaggedTensor)):
            losses = tensor_conversion.convert_to_tensor_v2_with_dispatch(losses)
        input_dtype = losses.dtype
        if not isinstance(sample_weight, keras_tensor.KerasTensor):
            sample_weight = tensor_conversion.convert_to_tensor_v2_with_dispatch(sample_weight)
        losses = math_ops.cast(losses, 'float32')
        sample_weight = math_ops.cast(sample_weight, 'float32')
        losses, _, sample_weight = squeeze_or_expand_dimensions(losses, None, sample_weight)
        weighted_losses = math_ops.multiply(losses, sample_weight)
        loss = reduce_weighted_loss(weighted_losses, reduction)
        loss = math_ops.cast(loss, input_dtype)
        return loss

Computes the weighted loss.

Args:
losses: `Tensor` of shape `[batch_size, d1, ... dN]`.
sample_weight: Optional `Tensor` whose rank is either 0, or the same rank as
`losses`, or be broadcastable to `losses`.
reduction: (Optional) Type of `tf.keras.losses.Reduction` to apply to loss.
Default value is `SUM_OVER_BATCH_SIZE`.
name: Optional name for the op.

Raises:
ValueError: If the shape of `sample_weight` is not compatible with `losses`.

Returns:
Weighted loss `Tensor` of the same type as `losses`. If `reduction` is
`NONE`, this has the same shape as `losses`; otherwise, it is scalar.


def sparse_top_k_categorical_accuracy(y_true, y_pred, k=5, from_sorted_ids=False):
    reshape_matches = False
    y_pred = ops.convert_to_tensor(y_pred)
    y_true_dtype = y_pred.dtype if from_sorted_ids else 'int32'
    y_true = ops.convert_to_tensor(y_true, dtype=y_true_dtype)
    y_true_rank = len(y_true.shape)
    y_pred_rank = len(y_pred.shape)
    y_true_org_shape = ops.shape(y_true)
    if y_true_rank is not None and y_pred_rank is not None:
        if y_pred_rank > 2:
            y_pred = ops.reshape(y_pred, [-1, y_pred.shape[-1]])
        if y_true_rank > 1:
            reshape_matches = True
            y_true = ops.reshape(y_true, [-1])
    if from_sorted_ids:
        matches = ops.any(ops.equal(ops.expand_dims(y_true, axis=1), y_pred[:, :k]), axis=1)
    else:
        matches = ops.in_top_k(y_true, y_pred, k=k)
    matches = ops.cast(matches, dtype=backend.floatx())
    if reshape_matches:
        matches = ops.reshape(matches, y_true_org_shape)
    return matches

Computes how often integer targets are in the top `K` predictions.

Args:
y_true: A tensor of shape `(batch_size)` representing indices or IDs of
true categories.
y_pred: If `from_sorted_ids=False`, a tensor of shape
`(batch_size, num_categories)` containing the scores for each sample
for all possible categories. If `from_sorted_ids=True`, a tensor of
shape `(batch_size, N)` containing indices or IDs of the top `N`
categories in order from highest score to lowest score.
k: (Optional) Number of top elements to look at for computing accuracy.
Defaults to `5`.
from_sorted_ids: (Optional) Whether `y_pred` is sorted category IDs or
scores for all categories (the default).

Returns:
A tensor with the same shape as `y_true` containing ones where `y_true`
is in the top `k` and zeros elsewhere.


def load_install_json(self, filename=None):
    if (filename is None):
        filename = 'install.json'
    file_fqpn = os.path.join(self.app_path, filename)
    install_json = None
    if os.path.isfile(file_fqpn):
        try:
            with open(file_fqpn, 'r') as fh:
                install_json = json.load(fh)
        except ValueError as e:
            self.handle_error('Failed to load "{}" file ({}).'.format(file_fqpn, e))
    else:
        self.handle_error('File "{}" could not be found.'.format(file_fqpn))
    return install_json

Return install.json data.

Args:
filename (str, optional): Defaults to None. The install.json filename (for bundled
Apps).

Returns:
dict: The contents of the install.json file.


def is_supported(cls, file=None, request=None, response=None, url_info=None):
    tests = ((response, cls.is_response), (file, cls.is_file), (request, cls.is_request), (url_info, cls.is_url))
    for (instance, method) in tests:
        if instance:
            try:
                result = method(instance)
            except NotImplementedError:
                pass
            else:
                if result:
                    return True
                elif (result is VeryFalse):
                    return VeryFalse

Given the hints, return whether the document is supported.

Args:
file: A file object containing the document.
request (:class:`.http.request.Request`): An HTTP request.
response (:class:`.http.request.Response`): An HTTP response.
url_info (:class:`.url.URLInfo`): A URLInfo.

Returns:
bool: If True, the reader should be able to read it.


def get_named_parent(decl):
    if (not decl):
        return None
    parent = decl.parent
    while (parent and ((not parent.name) or (parent.name == '::'))):
        parent = parent.parent
    return parent

Returns a reference to a named parent declaration.

Args:
decl (declaration_t): the child declaration

Returns:
declaration_t: the declaration or None if not found.


def unlock(self):
    if (not unlockers.unlock(self, self._device.manufacturer)):
        raise errors.JLinkException('Failed to unlock device.')
    return True

Unlocks the device connected to the J-Link.

Unlocking a device allows for access to read/writing memory, as well as
flash programming.

Note:
Unlock is not supported on all devices.

Supported Devices:
Kinetis

Returns:
``True``.

Raises:
JLinkException: if the device fails to unlock.


def is_file(self, follow_symlinks=True):

        return self._system.isfile(
            path=self._path, client_kwargs=self._client_kwargs)

Return True if this entry is a file or a symbolic link pointing to a
file; return False if the entry is or points to a directory or other
non-file entry, or if it doesn’t exist anymore.

The result is cached on the os.DirEntry object.

Args:
follow_symlinks (bool): Follow symlinks.
Not supported on cloud storage objects.

Returns:
bool: True if directory exists.


def _ensure_list(tensor_or_list):

  if isinstance(tensor_or_list, (list, tuple)):
    return list(tensor_or_list), True
  return [tensor_or_list], False

Converts the input arg to a list if it is not a list already.

Args:
tensor_or_list: A `Tensor` or a Python list of `Tensor`s. The argument to
convert to a list of `Tensor`s.

Returns:
A tuple of two elements. The first is a Python list of `Tensor`s containing
the original arguments. The second is a boolean indicating whether
the original argument was a list or tuple already.