def _get_account_xml(soco):

        device = soco or discovery.any_soco()
        log.debug("Fetching account data from %s", device)
        settings_url = "http:
            device.ip_address)
        result = requests.get(settings_url).content
        log.debug("Account data: %s", result)
        return result

Fetch the account data from a Sonos device.

Args:
soco (SoCo): a SoCo instance to query. If soco is `None`, a
random device will be used.

Returns:
str: a byte string containing the account data xml


def __init__(self, callback):

        self._callback = callback
        self._rbridge = brocade_rbridge(callback=pynos.utilities.return_xml)

BGP object init.

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

Returns:
BGP Object

Raises:
None


def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
    tstream = BytearrayStream()
    self.application_namespace.write(tstream, kmip_version=kmip_version)
    self.application_data.write(tstream, kmip_version=kmip_version)
    self.length = tstream.length()
    super(ApplicationSpecificInformation, self).write(ostream, kmip_version=kmip_version)
    ostream.write(tstream.buffer)

Write the data encoding the ApplicationSpecificInformation object to a
stream.

Args:
ostream (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 _plot_thermo(self, func, temperatures, factor=1, ax=None, ylabel=None, label=None, ylim=None, **kwargs):
    (ax, fig, plt) = get_ax_fig_plt(ax)
    values = []
    for t in temperatures:
        values.append((func(t, structure=self.structure) * factor))
    ax.plot(temperatures, values, label=label, **kwargs)
    if ylim:
        ax.set_ylim(ylim)
    ax.set_xlim((np.min(temperatures), np.max(temperatures)))
    ylim = plt.ylim()
    if (ylim[0] < 0 < ylim[1]):
        plt.plot(plt.xlim(), [0, 0], 'k-', linewidth=1)
    ax.set_xlabel('$T$ (K)')
    if ylabel:
        ax.set_ylabel(ylabel)
    return fig

Plots a thermodynamic property for a generic function from a PhononDos instance.

Args:
func: the thermodynamic function to be used to calculate the property
temperatures: a list of temperatures
factor: a multiplicative factor applied to the thermodynamic property calculated. Used to change
the units.
ax: matplotlib :class:`Axes` or None if a new figure should be created.
ylabel: label for the y axis
label: label of the plot
ylim: tuple specifying the y-axis limits.
kwargs: kwargs passed to the matplotlib function 'plot'.
Returns:
matplotlib figure


def _ExpandUsersHomeDirectoryPathSegments(
      cls, path_segments, path_separator, user_accounts):

    if not path_segments:
      return []

    user_paths = []

    first_path_segment = path_segments[0].lower()
    if first_path_segment not in ('%%users.homedir%%', '%%users.userprofile%%'):
      if cls._IsWindowsDrivePathSegment(path_segments[0]):
        path_segments[0] = ''

      user_path = path_separator.join(path_segments)
      user_paths.append(user_path)

    else:
      for user_account in user_accounts:
        user_path_segments = user_account.GetUserDirectoryPathSegments()

        if not user_path_segments:
          continue

        if cls._IsWindowsDrivePathSegment(user_path_segments[0]):
          user_path_segments[0] = ''

        if not user_path_segments[-1]:
          user_path_segments.pop()

        user_path_segments.extend(path_segments[1:])

        user_path = path_separator.join(user_path_segments)
        user_paths.append(user_path)

    return user_paths

Expands a path to contain all users home or profile directories.

Expands the artifacts path variable "%%users.homedir%%" or
"%%users.userprofile%%".

Args:
path_segments (list[str]): path segments.
path_separator (str): path segment separator.
user_accounts (list[UserAccountArtifact]): user accounts.

Returns:
list[str]: paths returned for user accounts without a drive indicator.


def api_server(connection, server_class):

    return server_class(
        link=xbahn.connection.link.Link(

            receive=connection,

            respond=connection
        )
    )

Establishes an API Server on the supplied connection

Arguments:
- connection (xbahn.connection.Connection)
- server_class (xbahn.api.Server)

Returns:
- server_class: server instance


def __init__(self, index_file=None, template_dir=None):

        super(CliTable, self).__init__()
        self._keys = set()
        self.raw = None
        self.index_file = index_file
        self.template_dir = template_dir
        if index_file:
            self.ReadIndex(index_file)

Create new CLiTable object.
Args:
index_file: String, file where template/command mappings reside.
template_dir: String, directory where index file and templates reside.


def _ReconstructPath(self, came_from, current_node):

    if current_node in came_from:
      (previous_node, previous_edge) = came_from[current_node]
      if previous_edge.GetPoint(0) == current_node:
        previous_edge = previous_edge.Reversed()
      p = self._ReconstructPath(came_from, previous_node)
      return Poly.MergePolys([p, previous_edge], merge_point_threshold=0)
    else:
      return Poly([], '')

Helper method for ShortestPath, to reconstruct path.

Arguments:
came_from: a dictionary mapping Point to (Point, Poly) tuples.
This dictionary keeps track of the previous neighbor to a node, and
the edge used to get from the previous neighbor to the node.
current_node: the current Point in the path.

Returns:
A Poly that represents the path through the graph from the start of the
search to current_node.


def from_file(filepath):

    if filepath.endswith(".prj"):
        string = open(filepath, "r").read()
        return parse.from_unknown_wkt(string)

    elif filepath.endswith((".geojson",".json")):
        raw = open(filepath).read()
        geoj = json.loads(raw)
        if "crs" in geoj:
            crsinfo = geoj["crs"]

            if crsinfo["type"] == "name":
                string = crsinfo["properties"]["name"]
                return parse.from_unknown_text(string)

            elif crsinfo["type"] == "link":
                url = crsinfo["properties"]["name"]
                type = crsinfo["properties"].get("type")
                return from_url(url, format=type)

            else: raise FormatError("Invalid GeoJSON crs type: must be either 'name' or 'link'")

        else:

            return parse.from_epsg_code("4326")

Returns the crs object from a file, with the format determined from the filename extension.

Arguments:

- *filepath*: filepath to be loaded, including extension.


def __call__(self, shape, dtype=dtypes.float32, **kwargs):
    self._validate_kwargs(kwargs)
    dtype = dtypes.as_dtype(dtype)
    if not dtype.is_floating and (not dtype.is_integer):
        raise ValueError(f'Argument `dtype` expected to be numeric or boolean. Received {dtype}.')
    if _PARTITION_SHAPE in kwargs:
        shape = kwargs[_PARTITION_SHAPE]
    return self._random_generator.random_uniform(shape, self.minval, self.maxval, dtype)

Returns a tensor object initialized as specified by the initializer.

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

Raises:
ValueError: If the dtype is not numeric.


def take_along_axis(x, indices, axis=None):
    if any_symbolic_tensors((x, indices)):
        return TakeAlongAxis(axis=axis).symbolic_call(x, indices)
    return backend.numpy.take_along_axis(x, indices, axis=axis)

Select values from `x` at the 1-D `indices` along the given axis.

Args:
x: Source tensor.
indices: The indices of the values to extract.
axis: The axis over which to select values. By default, the flattened
input tensor is used.

Returns:
The corresponding tensor of values.


def set(self, property_name, property_val):
    if property_name not in self._config:
        raise KeyError('%s is not a valid property name.' % property_name)
    orig_val = self._config[property_name]
    if isinstance(orig_val, bool):
        if isinstance(property_val, str):
            if property_val.lower() in ('1', 'true', 't', 'yes', 'y', 'on'):
                property_val = True
            elif property_val.lower() in ('0', 'false', 'f', 'no', 'n', 'off'):
                property_val = False
            else:
                raise ValueError('Invalid string value for bool type: %s' % property_val)
        else:
            property_val = bool(property_val)
    elif isinstance(orig_val, int):
        property_val = int(property_val)
    elif isinstance(orig_val, str):
        property_val = str(property_val)
    else:
        raise TypeError('Unsupported property type: %s' % type(orig_val))
    self._config[property_name] = property_val
    self._save_to_file()
    if property_name in self._set_callbacks:
        self._set_callbacks[property_name](self._config)

Set the value of a property.

Supports limitd property value types: `bool`, `int` and `str`.

Args:
property_name: Name of the property.
property_val: Value of the property. If the property has `bool` type and
this argument has `str` type, the `str` value will be parsed as a `bool`

Raises:
ValueError: if a `str` property_value fails to be parsed as a `bool`.
KeyError: if `property_name` is an invalid property name.


def mac(self, data, uid=None, algorithm=None):
    if (not isinstance(data, six.binary_type)):
        raise TypeError('data must be bytes')
    if (uid is not None):
        if (not isinstance(uid, six.string_types)):
            raise TypeError('uid must be a string')
    if (algorithm is not None):
        if (not isinstance(algorithm, enums.CryptographicAlgorithm)):
            raise TypeError('algorithm must be a CryptographicAlgorithm enumeration')
    parameters_attribute = self._build_cryptographic_parameters({'cryptographic_algorithm': algorithm})
    result = self.proxy.mac(data, uid, parameters_attribute)
    status = result.result_status.value
    if (status == enums.ResultStatus.SUCCESS):
        uid = result.uuid.value
        mac_data = result.mac_data.value
        return (uid, mac_data)
    else:
        reason = result.result_reason.value
        message = result.result_message.value
        raise exceptions.KmipOperationFailure(status, reason, message)

Get the message authentication code for data.

Args:
data (string): The data to be MACed.
uid (string): The unique ID of the managed object that is the key
to use for the MAC operation.
algorithm (CryptographicAlgorithm): An enumeration defining the
algorithm to use to generate the MAC.

Returns:
string: The unique ID of the managed object that is the key
to use for the MAC operation.
string: The data MACed

Raises:
ClientConnectionNotOpen: if the client connection is unusable
KmipOperationFailure: if the operation result is a failure
TypeError: if the input arguments are invalid


def get(self, dash_id):
    return make_response(render_template('dashboard.html', dash_id=dash_id, api_root=config.app_host))

Just return the dashboard id in the rendering html.

JS will do other work [ajax and rendering] according to the dash_id.

Args:
dash_id: dashboard id.

Returns:
rendered html.


def verify_sc_url(url: str) -> bool:

    parsed = urlsplit(url)

    scheme: str = parsed.scheme
    netloc: str = parsed.netloc
    path: str = parsed.path

    try:
        port = parsed.port
    except ValueError:
        port = None

    result = (scheme.lower() == 'https' and
              netloc.lower().split(':')[0] == 's3.amazonaws.com' and
              path.startswith('/echo.api/') and
              (port == 443 or port is None))

    return result

Verify signature certificate URL against Amazon Alexa requirements.

Each call of Agent passes incoming utterances batch through skills filter,
agent skills, skills processor. Batch of dialog IDs can be provided, in
other case utterances indexes in incoming batch are used as dialog IDs.

Args:
url: Signature certificate URL from SignatureCertChainUrl HTTP header.

Returns:
result: True if verification was successful, False if not.


def DeviceReadThread(hid_device):

  hid_device.run_loop_ref = cf.CFRunLoopGetCurrent()
  if not hid_device.run_loop_ref:
    logger.error('Failed to get current run loop')
    return

  iokit.IOHIDDeviceScheduleWithRunLoop(hid_device.device_handle,
                                       hid_device.run_loop_ref,
                                       K_CF_RUNLOOP_DEFAULT_MODE)

  run_loop_run_result = K_CF_RUN_LOOP_RUN_TIMED_OUT
  while (run_loop_run_result == K_CF_RUN_LOOP_RUN_TIMED_OUT or
         run_loop_run_result == K_CF_RUN_LOOP_RUN_HANDLED_SOURCE):
    run_loop_run_result = cf.CFRunLoopRunInMode(
        K_CF_RUNLOOP_DEFAULT_MODE,
        1000,
        False)

  if run_loop_run_result != K_CF_RUN_LOOP_RUN_STOPPED:
    logger.error('Unexpected run loop exit code: %d', run_loop_run_result)

  iokit.IOHIDDeviceUnscheduleFromRunLoop(hid_device.device_handle,
                                         hid_device.run_loop_ref,
                                         K_CF_RUNLOOP_DEFAULT_MODE)

Binds a device to the thread's run loop, then starts the run loop.

Args:
hid_device: The MacOsHidDevice object

The HID manager requires a run loop to handle Report reads. This thread
function serves that purpose.


def user(self, id):
    json = self.skype.conn('POST', '{0}/batch/profiles'.format(SkypeConnection.API_PROFILE), auth=SkypeConnection.Auth.SkypeToken, json={'usernames': [id]}).json()
    if (json and ('status' not in json[0])):
        return self.merge(SkypeUser.fromRaw(self.skype, json[0]))
    else:
        return None

Retrieve public information about a user.

Args:
id (str): user identifier to lookup

Returns:
SkypeUser: resulting user object


def group_indices(groupid_list):
    item_list = range(len(groupid_list))
    grouped_dict = util_dict.group_items(item_list, groupid_list)
    keys_ = list(grouped_dict.keys())
    try:
        keys = sorted(keys_)
    except TypeError:
        keys = util_list.sortedby2(keys_, keys_)
    groupxs = util_dict.dict_take(grouped_dict, keys)
    return (keys, groupxs)

groups indicies of each item in ``groupid_list``

Args:
groupid_list (list): list of group ids

SeeAlso:
vt.group_indices - optimized numpy version
ut.apply_grouping

CommandLine:
python -m utool.util_alg --test-group_indices
python3 -m utool.util_alg --test-group_indices

Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_alg import *  # NOQA
>>> import utool as ut
>>> groupid_list = ['b', 1, 'b', 1, 'b', 1, 'b', 'c', 'c', 'c', 'c']
>>> (keys, groupxs) = ut.group_indices(groupid_list)
>>> result = ut.repr3((keys, groupxs), nobraces=1, nl=1)
>>> print(result)
[1, 'b', 'c'],
[[1, 3, 5], [0, 2, 4, 6], [7, 8, 9, 10]],


def associate_blocks(blocks, layout_pairs, start_peb_num):

    seq_blocks = []
    for layout_pair in layout_pairs:
        seq_blocks = sort.by_image_seq(blocks, blocks[layout_pair[0]].ec_hdr.image_seq)

        layout_pair.append(seq_blocks)

    return layout_pairs

Group block indexes with appropriate layout pairs

Arguments:
List:blocks        -- List of block objects
List:layout_pairs  -- List of grouped layout blocks
Int:start_peb_num  -- Number of the PEB to start from.

Returns:
List -- Layout block pairs grouped with associated block ranges.


def _Upgrade1To2(self, data):

    def RemapOperator(opcode_name):

        old_name_to_new_name = {'CONVOLUTION': 'CONV_2D', 'DEPTHWISE_CONVOLUTION': 'DEPTHWISE_CONV_2D', 'AVERAGE_POOL': 'AVERAGE_POOL_2D', 'MAX_POOL': 'MAX_POOL_2D', 'L2_POOL': 'L2_POOL_2D', 'SIGMOID': 'LOGISTIC', 'L2NORM': 'L2_NORMALIZATION', 'LOCAL_RESPONSE_NORM': 'LOCAL_RESPONSE_NORMALIZATION', 'Basic_RNN': 'RNN'}
        return old_name_to_new_name[opcode_name] if opcode_name in old_name_to_new_name else opcode_name

    def RemapOperatorType(operator_type):

        old_to_new = {'PoolOptions': 'Pool2DOptions', 'DepthwiseConvolutionOptions': 'DepthwiseConv2DOptions', 'ConvolutionOptions': 'Conv2DOptions', 'LocalResponseNormOptions': 'LocalResponseNormalizationOptions', 'BasicRNNOptions': 'RNNOptions'}
        return old_to_new[operator_type] if operator_type in old_to_new else operator_type
    for subgraph in data['subgraphs']:
        for ops in subgraph['operators']:
            ops['builtin_options_type'] = RemapOperatorType(ops['builtin_options_type'])
    for operator_code in data['operator_codes']:
        if not isinstance(operator_code['builtin_code'], type(u'')):
            raise ValueError('builtin_code %r is non-string. this usually means your model has consistency problems.' % operator_code['builtin_code'])
        operator_code['builtin_code'] = RemapOperator(operator_code['builtin_code'])

Upgrade data from Version 1 to Version 2.

Changes: Rename operators to Conform to NN API.

Args:
data: Dictionary representing the TensorFlow lite data to be upgraded.
This will be modified in-place to be an upgraded version.
Raises:
ValueError: Throws when model builtins are numeric rather than symbols.


def get_stream(self, request, start):
    if self._download_request and (start != self._download_pos or request.bucket != self._download_request.bucket or request.object != self._download_request.object):
        self._download_stream.close()
        self._download_stream = None
    if not self._download_stream or self._download_stream._raw_stream.closed:
        try:
            self._download_stream = self.client.get_object(Bucket=request.bucket, Key=request.object, Range='bytes={}-'.format(start))['Body']
            self._download_request = request
            self._download_pos = start
        except Exception as e:
            raise messages.S3ClientError(str(e), get_http_error_code(e))
    return self._download_stream

Opens a stream object starting at the given position.

Args:
request: (GetRequest) request
start: (int) start offset
Returns:
(Stream) Boto3 stream object.


def WriteDebuggedGraph(self, debugged_graph):
    debug_event = debug_event_pb2.DebugEvent(debugged_graph=debugged_graph)
    self._EnsureTimestampAdded(debug_event)
    _pywrap_debug_events_writer.WriteDebuggedGraph(self._dump_root, debug_event)

Write a DebuggedGraph proto with the writer.

Args:
debugged_graph: A DebuggedGraph proto, describing the details of a
TensorFlow Graph that has completed its construction.


def _GetDecrypter(self):
    resolver.Resolver.key_chain.ExtractCredentialsFromPathSpec(self._path_spec)
    try:
        credentials = resolver.Resolver.key_chain.GetCredentials(self._path_spec)
        return encryption_manager.EncryptionManager.GetDecrypter(self._encryption_method, **credentials)
    except ValueError as exception:
        raise IOError(exception)

Retrieves a decrypter.

Returns:
Decrypter: decrypter.

Raises:
IOError: if the decrypter cannot be initialized.
OSError: if the decrypter cannot be initialized.


def _compile_constant_expression(self, expr: Expression, scope: Dict[(str, TensorFluent)], batch_size: Optional[int]=None, noise: Optional[List[tf.Tensor]]=None) -> TensorFluent:
    etype = expr.etype
    args = expr.args
    dtype = utils.python_type_to_dtype(etype[1])
    fluent = TensorFluent.constant(args, dtype=dtype)
    return fluent

Compile a constant expression `expr` into a TensorFluent
in the given `scope` with optional batch size.

Args:
expr (:obj:`rddl2tf.expr.Expression`): A RDDL constant expression.
scope (Dict[str, :obj:`rddl2tf.fluent.TensorFluent`]): A fluent scope.
batch_size (Optional[size]): The batch size.

Returns:
:obj:`rddl2tf.fluent.TensorFluent`: The compiled expression as a TensorFluent.


def save_and_scan(filename, b64_data):

    with NTFile(suffix="_"+os.path.basename(filename), mode="wb") as ifile:
        ifile.write(
            b64decode(b64_data)
        )
        ifile.flush()

        os.chmod(ifile.name, 0755)

        return scan_file(ifile.name)

Save `b64_data` to temporary file and scan it for viruses.

Args:
filename (str): Name of the file - used as basename for tmp file.
b64_data (str): Content of the file encoded in base64.

Returns:
dict: ``{filename: ("FOUND", "virus type")}`` or blank dict.


def add_callback(self, name, func):
    if (name not in self.callbacks):
        raise ValueError(('Unknown callback name: %s' % name))
    self.callbacks[name].add(func)

Add a callback when Device events happen

Args:
name (str): currently support 'on_scan' and 'on_disconnect'
func (callable): the function that should be called


def _get_value_or_dummy(input_workers, optional_list, produce_dummy):
    value_list = []
    for i, worker in enumerate(input_workers.worker_devices):
        with ops.device(worker):
            devices = input_workers.compute_devices_for_worker(i)
            for j, device in enumerate(devices):
                with ops.device(device):
                    if produce_dummy:
                        value_list.append(tf_cond.cond(optional_list[i][j].has_value(), lambda: optional_list[i][j].get_value(), lambda: _dummy_tensor_fn(optional_list[i][j].element_spec), strict=True))
                    else:
                        value_list.append(optional_list[i][j].get_value())
    return value_list

Returns the value of the optionals or dummy values.

Args:
input_workers: the `InputWorkers`.
optional_list: a list of lists `tf.experimental.Optional`. The values from
each compute device grouped by the input device.
produce_dummy: a bool. Whether to produce dummy tensors when the optional
doesn't have a value.

Returns:
A flatten list of Tensors.


def hurst_compare_nvals(data, nvals=None):
    import matplotlib.pyplot as plt
    data = np.asarray(data)
    n_all = np.arange(2, (len(data) + 1))
    dd_all = nolds.hurst_rs(data, nvals=n_all, debug_data=True, fit='poly')
    dd_def = nolds.hurst_rs(data, debug_data=True, fit='poly')
    n_def = np.round(np.exp(dd_def[1][0])).astype('int32')
    n_div = n_all[np.where(((len(data) % n_all[:(- 1)]) == 0))]
    dd_div = nolds.hurst_rs(data, nvals=n_div, debug_data=True, fit='poly')

    def corr(nvals):
        return [np.log(nolds.expected_rs(n)) for n in nvals]
    l_all = plt.plot(dd_all[1][0], (dd_all[1][1] - corr(n_all)), 'o')
    l_def = plt.plot(dd_def[1][0], (dd_def[1][1] - corr(n_def)), 'o')
    l_div = plt.plot(dd_div[1][0], (dd_div[1][1] - corr(n_div)), 'o')
    l_cst = []
    t_cst = []
    if (nvals is not None):
        dd_cst = nolds.hurst_rs(data, nvals=nvals, debug_data=True, fit='poly')
        l_cst = plt.plot(dd_cst[1][0], (dd_cst[1][1] - corr(nvals)), 'o')
        l_cst = l_cst
        t_cst = ['custom']
    plt.xlabel('log(n)')
    plt.ylabel('log((R/S)_n - E[(R/S)_n])')
    plt.legend((((l_all + l_def) + l_div) + l_cst), (['all', 'default', 'divisors'] + t_cst))
    labeled_data = zip([dd_all[0], dd_def[0], dd_div[0]], ['all', 'def', 'div'])
    for (data, label) in labeled_data:
        print(('%s: %.3f' % (label, data)))
    if (nvals is not None):
        print(('custom: %.3f' % dd_cst[0]))
    plt.show()

Creates a plot that compares the results of different choices for nvals
for the function hurst_rs.

Args:
data (array-like of float):
the input data from which the hurst exponent should be estimated

Kwargs:
nvals (array of int):
a manually selected value for the nvals parameter that should be plotted
in comparison to the default choices


def frosted_glass_blur(x, severity=1):

  c = [(0.7, 1, 2), (0.9, 2, 1), (1, 2, 3), (1.1, 3, 2), (1.5, 4,
                                                          2)][severity - 1]
  x = np.uint8(
      tfds.core.lazy_imports.skimage.filters.gaussian(
          np.array(x) / 255., sigma=c[0], multichannel=True) * 255)

  for _ in range(c[2]):
    for h in range(x.shape[0] - c[1], c[1], -1):
      for w in range(x.shape[1] - c[1], c[1], -1):
        dx, dy = np.random.randint(-c[1], c[1], size=(2,))
        h_prime, w_prime = h + dy, w + dx

        x[h, w], x[h_prime, w_prime] = x[h_prime, w_prime], x[h, w]
  x_clip = np.clip(
      tfds.core.lazy_imports.skimage.filters.gaussian(
          x / 255., sigma=c[0], multichannel=True), 0, 1)
  x_clip *= 255
  return around_and_astype(x_clip)

Frosted glass blurring to images.

Apply frosted glass blurring to images by shuffling pixels locally.

Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.

Returns:
numpy array, image with uint8 pixels in [0,255]. Applied frosted glass blur.


def _build(self, inputs):

    shape_inputs = inputs.get_shape().as_list()
    rank = len(shape_inputs)

    max_dim = np.max(self._dims) + 1
    if rank < max_dim:
      raise ValueError("Rank of inputs must be at least {}.".format(max_dim))

    full_begin = [0] * rank
    full_size = [-1] * rank

    for dim, begin, size in zip(self._dims, self._begin, self._size):
      full_begin[dim] = begin
      full_size[dim] = size

    return tf.slice(inputs, begin=full_begin, size=full_size)

Connects the SliceByDim module into the graph.

Args:
inputs: `Tensor` to slice. Its rank must be greater than the maximum
dimension specified in `dims` (plus one as python is 0 indexed).

Returns:
The sliced tensor.

Raises:
ValueError: If `inputs` tensor has insufficient rank.


def load(fp, **kwargs) -> BioCCollection:

    obj = json.load(fp, **kwargs)
    return parse_collection(obj)

Deserialize fp (a .read()-supporting text file or binary file containing a JSON document) to
a BioCCollection object

Args:
fp: a file containing a JSON document
**kwargs:

Returns:
BioCCollection: a collection


def register_write_multiple(self, register_indices, values):
    if (len(register_indices) != len(values)):
        raise ValueError('Must be an equal number of registers and values')
    num_regs = len(register_indices)
    buf = (ctypes.c_uint32 * num_regs)(*register_indices)
    data = (ctypes.c_uint32 * num_regs)(*values)
    statuses = (ctypes.c_uint8 * num_regs)(0)
    res = self._dll.JLINKARM_WriteRegs(buf, data, statuses, num_regs)
    if (res != 0):
        raise errors.JLinkException(res)
    return None

Writes to multiple CPU registers.

Writes the values to the given registers in order.  There must be a
one-to-one correspondence between the values and the registers
specified.

Args:
self (JLink): the ``JLink`` instance
register_indices (list): list of registers to write to
values (list): list of values to write to the registers

Returns:
``None``

Raises:
ValueError: if ``len(register_indices) != len(values)``
JLinkException: if a register could not be written to or on error


def to_html(self):

        icon = self.html_icon()
        attributes = self.html_attributes()

        wrappable_text = self.to_text().replace(os.sep, '<wbr>' + os.sep)
        if icon is not '' and attributes is not '':
            return '<span%s>%s%s</span>' % (attributes, icon, wrappable_text)
        else:
            return self.to_text()

Render as html

Args:
None

Returns:
Str the html representation

Raises:
Errors are propagated


def get_index_models(index):

    models = []
    for app_model in get_index_config(index).get("models"):
        app, model = app_model.split(".")
        models.append(apps.get_model(app, model))
    return models

Return list of models configured for a named index.

Args:
index: string, the name of the index to look up.


def mask(self, predicates, new_value):

        if isinstance(predicates, SeriesWeld):
            predicates = predicates.expr
        return SeriesWeld(
            grizzly_impl.mask(
                self.expr,
                predicates,
                new_value,
                self.weld_type
            ),
            self.weld_type,
            self.df,
            self.column_name
        )

Summary

Args:
predicates (TYPE): Description
new_value (TYPE): Description

Returns:
TYPE: Description


def get_metar_from_mission(
        mission_file: str,
        icao: str = 'XXXX',
        time: str = None,
) -> str:

    return _MetarFromMission(
        mission_file=mission_file,
        icao=icao,
        time=time,
    ).metar

Builds a dummy METAR string from a mission file

Args:
mission_file: input mission file
icao: dummy ICAO (defaults to XXXX)
time: dummy time (defaults to now())

Returns: METAR str


def update(self, uid: int, flag_set: Iterable[Flag], op: FlagOp=FlagOp.REPLACE) -> FrozenSet[Flag]:
    orig_set = self._flags.get(uid, frozenset())
    new_flags = op.apply(orig_set, (self & flag_set))
    if new_flags:
        self._flags[uid] = new_flags
    else:
        self._flags.pop(uid, None)
    return new_flags

Update the flags for the session, returning the resulting flags.

Args:
uid: The message UID value.
flag_set: The set of flags for the update operation.
op: The type of update.


def _ListActiveBreakpoints(self, service):
    try:
        response = service.debuggees().breakpoints().list(debuggeeId=self._debuggee_id, waitToken=self._wait_token, successOnTimeout=True).execute()
        if (not response.get('waitExpired')):
            self._wait_token = response.get('nextWaitToken')
            breakpoints = (response.get('breakpoints') or [])
            if (self._breakpoints != breakpoints):
                self._breakpoints = breakpoints
                native.LogInfo(('Breakpoints list changed, %d active, wait token: %s' % (len(self._breakpoints), self._wait_token)))
                self.on_active_breakpoints_changed(copy.deepcopy(self._breakpoints))
    except BaseException:
        native.LogInfo(('Failed to query active breakpoints: ' + traceback.format_exc()))
        self._debuggee_id = None
        return (True, self.list_backoff.Failed())
    self.list_backoff.Succeeded()
    return (False, 0)

Single attempt query the list of active breakpoints.

Must not be called before the debuggee has been registered. If the request
fails, this function resets self._debuggee_id, which triggers repeated
debuggee registration.

Args:
service: client to use for API calls

Returns:
(registration_required, delay) tuple


def SetStorageWriter(self, storage_writer):

    self._storage_writer = storage_writer

    self._last_event_data_hash = None
    self._last_event_data_identifier = None

Sets the storage writer.

Args:
storage_writer (StorageWriter): storage writer.


def cross_product(self, dfa_2, accept_method):

        dfa_1states = copy.deepcopy(self.states)
        dfa_2states = dfa_2.states
        self.states = []
        states = {}

        def _create_transitions_representation(graph, state):

            return {self.isyms.find(arc.ilabel): graph[arc.nextstate] for arc in state}

        def _add_state_if_nonexistent(state_a, state_b):

            if (state_a.stateid, state_b.stateid) not in states:
                states[(state_a.stateid, state_b.stateid)] \
                    = self.add_state()
                self[states[(state_a.stateid, state_b.stateid)]].initial \
                    = state_a.initial and state_b.initial
                self[states[(state_a.stateid, state_b.stateid)]].final \
                    = accept_method(state_a.final, state_b.final)
            return states[(state_a.stateid, state_b.stateid)]

        for state1, state2 in product(dfa_1states, dfa_2states):
            sid1 = _add_state_if_nonexistent(state1, state2)
            transitions_s1 = _create_transitions_representation(dfa_1states, state1)
            transitions_s2 = _create_transitions_representation(dfa_2states, state2)
            for char in self.alphabet:
                sid2 = _add_state_if_nonexistent(
                    transitions_s1[char], transitions_s2[char])
                self.add_arc(sid1, sid2, char)

A generalized cross-product constructor over two DFAs.
The third argument is a binary boolean function f; a state (q1, q2) in the final
DFA accepts if f(A[q1],A[q2]), where A indicates the acceptance-value of the state.
Args:
dfa_2: The second dfa
accept_method: The boolean action
Returns:
None


def loads(s, single=False):

    corpus = etree.fromstring(s)
    if single:
        ds = _deserialize_dmrs(next(iter(corpus)))
    else:
        ds = (_deserialize_dmrs(dmrs_elem) for dmrs_elem in corpus)
    return ds

Deserialize DMRX string representations

Args:
s (str): a DMRX string
single (bool): if `True`, only return the first Xmrs object
Returns:
a generator of Xmrs objects (unless *single* is `True`)


def left_sample(continuous_pulse: Callable, duration: int, *args, **kwargs) -> np.ndarray:

    times = np.arange(duration)
    return continuous_pulse(times, *args, **kwargs)

Left sample a continuous function.
Args:
continuous_pulse: Continuous pulse function to sample.
duration: Duration to sample for.
*args: Continuous pulse function args.
**kwargs: Continuous pulse function kwargs.


def unravel_index(indices, shape):
    if any_symbolic_tensors((indices,)):
        return UnravelIndex(shape).symbolic_call(indices)
    return backend.numpy.unravel_index(indices, shape)

Convert flat indices to coordinate arrays in a given array shape.

Args:
indices: An integer or array of integers representing flat indices.
shape: The shape of the array to unravel into.

Returns:
Tuple of arrays for each dimension with unraveled indices.

Example:
>>> indices = 5
>>> shape = (3, 3)
>>> unravel_index(indices, shape)
(1, 2)  # 5 is at row 1, column 2 in a 3x3 array


def ls(github_user, template=None):
    temple.check.has_env_vars(temple.constants.GITHUB_API_TOKEN_ENV_VAR)
    if template:
        temple.check.is_git_ssh_path(template)
        search_q = 'user:{} filename:{} {}'.format(github_user, temple.constants.TEMPLE_CONFIG_FILE, template)
    else:
        search_q = 'user:{} cookiecutter.json in:path'.format(github_user)
    results = _code_search(search_q, github_user)
    return collections.OrderedDict(sorted(results.items()))

Lists all temple templates and packages associated with those templates

If ``template`` is None, returns the available templates for the configured
Github org.

If ``template`` is a Github path to a template, returns all projects spun
up with that template.

``ls`` uses the github search API to find results.

Note that the `temple.constants.TEMPLE_ENV_VAR` is set to 'ls' for the duration of this
function.

Args:
github_user (str): The github user or org being searched.
template (str, optional): The template git repo path. If provided, lists
all projects that have been created with the provided template. Note
that the template path is the SSH path
(e.g. git@github.com:CloverHealth/temple.git)

Returns:
dict: A dictionary of repository information keyed on the SSH Github url

Raises:
`InvalidGithubUserError`: When ``github_user`` is invalid


def normalize_to(self, comp, factor=1):

        scale_factor = abs(1 / self._coeffs[self._all_comp.index(comp)]
                           * factor)
        self._coeffs = [c * scale_factor for c in self._coeffs]

Normalizes the reaction to one of the compositions.
By default, normalizes such that the composition given has a
coefficient of 1. Another factor can be specified.

Args:
comp (Composition): Composition to normalize to
factor (float): Factor to normalize to. Defaults to 1.


def process_file(filename: str, filetypes: List[str], move_to: str, delete_if_not_specified_file_type: bool, show_zip_output: bool) -> None:
    try:
        reader = CorruptedOpenXmlReader(filename, show_zip_output=show_zip_output)
        if (reader.file_type in filetypes):
            log.info('Found {}: {}', reader.description, filename)
            if move_to:
                dest_file = os.path.join(move_to, os.path.basename(filename))
                (_, ext) = os.path.splitext(dest_file)
                if (ext != reader.suggested_extension()):
                    dest_file += reader.suggested_extension()
                reader.move_to(destination_filename=dest_file)
        else:
            log.info(('Unrecognized or unwanted contents: ' + filename))
            if delete_if_not_specified_file_type:
                log.info(('Deleting: ' + filename))
                os.remove(filename)
    except Exception as e:
        log.critical('Uncaught error in subprocess: {!r}\n{}', e, traceback.format_exc())
        raise

Deals with an OpenXML, including if it is potentially corrupted.

Args:
filename: filename to process
filetypes: list of filetypes that we care about, e.g.
``['docx', 'pptx', 'xlsx']``.
move_to: move matching files to this directory
delete_if_not_specified_file_type: if ``True``, and the file is **not**
a type specified in ``filetypes``, then delete the file.
show_zip_output: show the output from the external ``zip`` tool?


def header(self, name, value):

        headers = {name: value}
        self._request.headers = headers
        self.add_matcher(matcher('HeadersMatcher', headers))

Defines a URL path to match.

Only call this method if the URL has no path already defined.

Arguments:
path (str): URL path value to match. E.g: ``/api/users``.

Returns:
self: current Mock instance.


def file_content(self, file_content, update_if_exists=True):
    if (not self.can_update()):
        self._tcex.handle_error(910, [self.type])
    self._data['fileContent'] = file_content
    return self.tc_requests.upload(self.api_type, self.api_sub_type, self.unique_id, file_content, update_if_exists=update_if_exists)

Updates the file content.

Args:
file_content: The file_content to upload.
update_if_exists:

Returns:


def normalize_to_dense(dataset: Dataset):
    if structured_function._should_unpack(dataset.element_spec):

        def normalize(*args):
            return structure.to_batched_tensor_list(dataset.element_spec, tuple(args))
    else:

        def normalize(arg):
            return structure.to_batched_tensor_list(dataset.element_spec, arg)
    normalized_dataset = dataset.map(normalize)
    return _RestructuredDataset(normalized_dataset, dataset.element_spec)

Normalizes non-tensor components in a dataset to dense representations.

This is necessary for dataset transformations that slice along the batch
dimension and are oblivious to non-tensors, e.g. `unbatch`, `rebatch`.

Args:
dataset: Dataset to normalize.

Returns:
A dataset whose sparse and ragged tensors have been normalized to their
dense representations.


def _parse_header(self, data):
    ((magic, word_size, byte_order, version, osabi, abi_version, _), data) = (unpack('4sBBBBB7s', data[:16]), data[16:])
    assert (magic == self._ELF_MAGIC), 'Missing ELF magic'
    assert (word_size in (1, 2)), 'Invalid word size'
    assert (byte_order in (1, 2)), 'Invalid byte order'
    assert (version == 1), 'Invalid version'
    self.osabi = self.OSABI(osabi)
    self.abi_version = abi_version
    endian = Target.Endian((byte_order - 1))
    ((type_, machine, version), data) = (unpack('HHI', data[:8], endian=endian), data[8:])
    try:
        self.type = self.Type(type_)
    except ValueError:
        self.type = self.Type.unknown
    try:
        self.machine = ELF.Machine(machine)
    except ValueError:
        self.machine = ELF.Machine.unknown
    assert (version == 1), 'Invalid version'
    if (self.machine is ELF.Machine.i386):
        arch = Target.Arch.x86
        assert (word_size == 1), 'Unexpected ELF64 for machine type x86'
        assert (endian is Target.Endian.little), 'Unexpected big-endian for machine type x86'
    elif (self.machine is ELF.Machine.x86_64):
        arch = Target.Arch.x86
        assert (word_size == 2), 'Unexpected ELF32 for machine type x64_64'
        assert (endian is Target.Endian.little), 'Unexpected big-endian for machine type x86'
    elif (self.machine is ELF.Machine.arm):
        arch = Target.Arch.arm
        assert (word_size == 1), 'Unexpected ELF64 for machine type arm'
    elif (self.machine is ELF.Machine.aarch64):
        arch = Target.Arch.arm
        assert (word_size == 2), 'Unexpected ELF32 for machine type aarch64'
    else:
        arch = Target.Arch.unknown
    self.arch = arch
    self.bits = (32 * word_size)
    self.endian = endian
    if (self.bits == 32):
        fmt = 'IIIIHHHHHH'
    else:
        fmt = 'QQQIHHHHHH'
    fmt_size = pack_size(fmt)
    (self.entry, self.phoff, self.shoff, self.flags, self.hsize, self.phentsize, self.phnum, self.shentsize, self.shnum, self.shstrndx) = unpack(fmt, data[:fmt_size], target=self)

Parse the ELF header in ``data`` and populate the properties.

Args:
data(bytes): The ELF header.


def _ConvertEnumDescriptor(self, enum_proto, package=None, file_desc=None, containing_type=None, scope=None):
    if package:
        enum_name = '.'.join((package, enum_proto.name))
    else:
        enum_name = enum_proto.name
    if (file_desc is None):
        file_name = None
    else:
        file_name = file_desc.name
    values = [self._MakeEnumValueDescriptor(value, index) for (index, value) in enumerate(enum_proto.value)]
    desc = descriptor.EnumDescriptor(name=enum_proto.name, full_name=enum_name, filename=file_name, file=file_desc, values=values, containing_type=containing_type, options=enum_proto.options)
    scope[('.%s' % enum_name)] = desc
    self._enum_descriptors[enum_name] = desc
    return desc

Make a protobuf EnumDescriptor given an EnumDescriptorProto protobuf.

Args:
enum_proto: The descriptor_pb2.EnumDescriptorProto protobuf message.
package: Optional package name for the new message EnumDescriptor.
file_desc: The file containing the enum descriptor.
containing_type: The type containing this enum.
scope: Scope containing available types.

Returns:
The added descriptor


def storage_volume_templates(self):
    if (not self.__storage_volume_templates):
        self.__storage_volume_templates = StorageVolumeTemplates(self.__connection)
    return self.__storage_volume_templates

Gets the StorageVolumeTemplates API client.

Returns:
StorageVolumeTemplates:


def print_search_results(self, search_results, buf=sys.stdout):
    formatted_lines = self.format_search_results(search_results)
    pr = Printer(buf)
    for (txt, style) in formatted_lines:
        pr(txt, style)

Print formatted search results.

Args:
search_results (list of `ResourceSearchResult`): Search to format.


def _init_zeo_root(self, attempts=3):

        try:
            db_root = self._connection.root()
        except ConnectionStateError:
            if attempts <= 0:
                raise

            self._open_connection()
            return self._init_zeo_root(attempts=attempts-1)

        if self.project_key and self.project_key not in db_root:
            with transaction.manager:
                db_root[self.project_key] = self.default_type()

        self._root = db_root[self.project_key] if self.project_key else db_root

Get and initialize the ZEO root object.

Args:
attempts (int, default 3): How many times to try, if the connection
was lost.


def ToArray(value):

        ms = StreamManager.GetStream()
        writer = BinaryWriter(ms)

        value.Serialize(writer)

        retVal = ms.ToArray()
        StreamManager.ReleaseStream(ms)

        return retVal

Serialize the given `value` to a an array of bytes.

Args:
value (neo.IO.Mixins.SerializableMixin): object extending SerializableMixin.

Returns:
bytes: hex formatted bytes


def build_query_string(self, data):

        queryValues = []
        keys_to_be_removed = []
        for key, value in data.items():
            if key not in ['version', 'restApi', 'resourcePath']:
                if not key == 'point':
                    queryValues.append('{0}={1}'.format(key, value))
                    keys_to_be_removed.append(key)
                keys_to_be_removed.append(key)
        queryString = '&'.join(queryValues)
        data['query'] = '{0}?{1}'.format(data['point'], queryString)
        for k in list(set(keys_to_be_removed)):
            del data[k]
        return data

This method occurs after dumping the data into the class.

Args:
data (dict): dictionary of all the query values

Returns:
data (dict): ordered dict of all the values


def func_dump(func):
    if os.name == 'nt':
        raw_code = marshal.dumps(func.__code__).replace(b'\\', b'/')
        code = codecs.encode(raw_code, 'base64').decode('ascii')
    else:
        raw_code = marshal.dumps(func.__code__)
        code = codecs.encode(raw_code, 'base64').decode('ascii')
    defaults = func.__defaults__
    if func.__closure__:
        closure = tuple((c.cell_contents for c in func.__closure__))
    else:
        closure = None
    return (code, defaults, closure)

Serializes a user-defined function.

Args:
func: the function to serialize.

Returns:
A tuple `(code, defaults, closure)`.


def check_script(vouts):
    for vout in [v for v in vouts[::(- 1)] if v['hex'].startswith('6a')]:
        verb = BlockchainSpider.decode_op_return(vout['hex'])
        action = Spoolverb.from_verb(verb).action
        if (action in Spoolverb.supported_actions):
            return verb
    raise Exception('Invalid ascribe transaction')

Looks into the vouts list of a transaction
and returns the ``op_return`` if one exists.

Args;
vouts (list): List of outputs of a transaction.

Returns:
str: String representation of the ``op_return``.

Raises:
Exception: If no ``vout`` having a supported
verb (:attr:`supported_actions`) is found.


def list_occupied_adb_ports():
    out = AdbProxy().forward('--list')
    clean_lines = str(out, 'utf-8').strip().split('\n')
    used_ports = []
    for line in clean_lines:
        tokens = line.split(' tcp:')
        if (len(tokens) != 3):
            continue
        used_ports.append(int(tokens[1]))
    return used_ports

Lists all the host ports occupied by adb forward.

This is useful because adb will silently override the binding if an attempt
to bind to a port already used by adb was made, instead of throwing binding
error. So one should always check what ports adb is using before trying to
bind to a port with adb.

Returns:
A list of integers representing occupied host ports.


def dr(self, cell_lengths):
    half_cell_lengths = (cell_lengths / 2.0)
    this_dr = (self.final_site.r - self.initial_site.r)
    for i in range(3):
        if (this_dr[i] > half_cell_lengths[i]):
            this_dr[i] -= cell_lengths[i]
        if (this_dr[i] < (- half_cell_lengths[i])):
            this_dr[i] += cell_lengths[i]
    return this_dr

Particle displacement vector for this jump

Args:
cell_lengths (np.array(x,y,z)): Cell lengths for the orthogonal simulation cell.

Returns
(np.array(x,y,z)): dr


def as_pyplot_figure(self, label=1, **kwargs):

        import matplotlib.pyplot as plt
        exp = self.as_list(label=label, **kwargs)
        fig = plt.figure()
        vals = [x[1] for x in exp]
        names = [x[0] for x in exp]
        vals.reverse()
        names.reverse()
        colors = ['green' if x > 0 else 'red' for x in vals]
        pos = np.arange(len(exp)) + .5
        plt.barh(pos, vals, align='center', color=colors)
        plt.yticks(pos, names)
        if self.mode == "classification":
            title = 'Local explanation for class %s' % self.class_names[label]
        else:
            title = 'Local explanation'
        plt.title(title)
        return fig

Returns the explanation as a pyplot figure.

Will throw an error if you don't have matplotlib installed
Args:
label: desired label. If you ask for a label for which an
explanation wasn't computed, will throw an exception.
Will be ignored for regression explanations.
kwargs: keyword arguments, passed to domain_mapper

Returns:
pyplot figure (barchart).


def cross(r1, r2):

    if r1.size != r2.size:
        raise ValueError("Both arguments must have the same input size.")
    if r1.deriv != r2.deriv:
        raise ValueError("Both arguments must have the same deriv.")
    result = Vector3(r1.size, r1.deriv)
    result.x = r1.y*r2.z - r1.z*r2.y
    result.y = r1.z*r2.x - r1.x*r2.z
    result.z = r1.x*r2.y - r1.y*r2.x
    return result

Compute the cross product

Arguments:
| ``r1``, ``r2``  -- two :class:`Vector3` objects

(Returns a Vector3)


def delete(self, namespace, key):

        if self.key_exists(namespace, key):
            obj = db.ConfigItem.find_one(
                ConfigItem.namespace_prefix == namespace,
                ConfigItem.key == key
            )

            del self.__data[namespace][key]

            db.session.delete(obj)
            db.session.commit()
        else:
            raise KeyError('{}/{}'.format(namespace, key))

Remove a configuration item from the database

Args:
namespace (`str`): Namespace of the config item
key (`str`): Key to delete

Returns:
`None`


def add_outputs(self, **kwargs):

        self._closed()

        for name, source_name in kwargs.items():
            obj = {}
            obj['outputSource'] = source_name
            obj['type'] = self.step_output_types[source_name]
            self.wf_outputs[name] = obj

Add workflow outputs.

The output type is added automatically, based on the steps in the steps
library.

Args:
kwargs (dict): A dict containing ``name=source name`` pairs.
``name`` is the name of the workflow output (e.g.,
``txt_files``) and source name is the name of the step that
produced this output plus the output name (e.g.,
``saf-to-txt/out_files``).


def get_variable_for_feature(self, feature_key, variable_key):
    feature = self.feature_key_map.get(feature_key)
    if (not feature):
        self.logger.error(('Feature with key "%s" not found in the datafile.' % feature_key))
        return None
    if (variable_key not in feature.variables):
        self.logger.error(('Variable with key "%s" not found in the datafile.' % variable_key))
        return None
    return feature.variables.get(variable_key)

Get the variable with the given variable key for the given feature.

Args:
feature_key: The key of the feature for which we are getting the variable.
variable_key: The key of the variable we are getting.

Returns:
Variable with the given key in the given variation.


def lstm_posterior_builder(getter, name, *args, **kwargs):
    del args
    parameter_shapes = tfp.distributions.Normal.param_static_shapes(kwargs['shape'])
    prior_stddev = np.sqrt(((FLAGS.prior_pi * np.square(FLAGS.prior_sigma1)) + ((1 - FLAGS.prior_pi) * np.square(FLAGS.prior_sigma2))))
    loc_var = getter('{}/posterior_loc'.format(name), shape=parameter_shapes['loc'], initializer=kwargs.get('initializer'), dtype=tf.float32)
    scale_var = getter('{}/posterior_scale'.format(name), initializer=tf.random_uniform(minval=np.log((np.exp((prior_stddev / 4.0)) - 1.0)), maxval=np.log((np.exp((prior_stddev / 2.0)) - 1.0)), dtype=tf.float32, shape=parameter_shapes['scale']))
    return tfp.distributions.Normal(loc=loc_var, scale=(tf.nn.softplus(scale_var) + 1e-05), name='{}/posterior_dist'.format(name))

A builder for a particular diagonal gaussian posterior.

Args:
getter: The `getter` passed to a `custom_getter`. Please see the
documentation for `tf.get_variable`.
name: The `name` argument passed to `tf.get_variable`.
*args: Positional arguments forwarded by `tf.get_variable`.
**kwargs: Keyword arguments forwarded by `tf.get_variable`.

Returns:
An instance of `tfp.distributions.Distribution` representing the
posterior distribution over the variable in question.


def recipe_google_api_to_bigquery(config, auth_read, api, version, function, kwargs, kwargs_remote, api_key, developer_token, login_customer_id, dataset, table):
    google_api(config, {'auth': auth_read, 'api': api, 'version': version, 'function': function, 'kwargs': kwargs, 'kwargs_remote': kwargs_remote, 'key': api_key, 'headers': {'developer-token': developer_token, 'login-customer-id': login_customer_id}, 'results': {'bigquery': {'dataset': dataset, 'table': table}}})

Execute any Google API function and store results to BigQuery.

Args:
auth_read (authentication) - Credentials used for reading data.
api (string) - See developer guide.
version (string) - Must be supported version.
function (string) - Full function dot notation path.
kwargs (json) - Dictionray object of name value pairs.
kwargs_remote (json) - Fetch arguments from remote source.
api_key (string) - Associated with a Google Cloud Project.
developer_token (string) - Associated with your organization.
login_customer_id (string) - Associated with your Adwords account.
dataset (string) - Existing dataset in BigQuery.
table (string) - Table to write API call results to.


def read_config(config_path=CONFIG_PATH):

    if not os.path.isfile(config_path):
        raise IOError("No config file found at %s" % config_path)
    config_parser = configparser.ConfigParser()
    config_parser.read(config_path)
    config = _config_parser_to_defaultdict(config_parser)
    return config

Read the config information from the config file.

Args:
config_path (str): Relative path to the email config file.
Returns:
defaultdict: A defaultdict with the config information.
Raises:
IOError


def _is_arg_name(name):
    name = name.strip()
    arg_pattern = '^[a-zA-Z_]\\w*$'
    re.match(arg_pattern, name)
    return re.match(arg_pattern, name) is not None

Returns whether name is a valid arg name.

This is used to prevent multiple words (plaintext) from being misinterpreted
as an argument name. Any line that doesn't match the pattern for a valid
argument is treated as not being an argument.

Args:
name: The name of the potential arg.
Returns:
True if name looks like an arg name, False otherwise.


def _maybe_commit(self, transaction):
    try:
        transaction._commit()
        return True
    except exceptions.GoogleAPICallError as exc:
        if transaction._read_only:
            raise
        if isinstance(exc, exceptions.Aborted):
            return False
        else:
            raise

Try to commit the transaction.

If the transaction is read-write and the ``Commit`` fails with the
``ABORTED`` status code, it will be retried. Any other failure will
not be caught.

Args:
transaction (~.firestore_v1beta1.transaction.Transaction): The
transaction to be ``Commit``-ed.

Returns:
bool: Indicating if the commit succeeded.


def _log_test_stage(self, stage_name):
    parent_token = self.current_test_info.name
    if parent_token == stage_name:
        parent_token = self.TAG
    logging.debug(TEST_STAGE_BEGIN_LOG_TEMPLATE.format(parent_token=parent_token, child_token=stage_name))
    try:
        yield
    finally:
        logging.debug(TEST_STAGE_END_LOG_TEMPLATE.format(parent_token=parent_token, child_token=stage_name))

Logs the begin and end of a test stage.

This context adds two log lines meant for clarifying the boundary of
each execution stage in Mobly log.

Args:
stage_name: string, name of the stage to log.


def StartClients(cls, hunt_id, client_ids, token=None):
    token = (token or access_control.ACLToken(username='Hunt', reason='hunting'))
    with queue_manager.QueueManager(token=token) as flow_manager:
        for client_id in client_ids:
            state = rdf_flow_runner.RequestState(id=random.UInt32(), session_id=hunt_id, client_id=client_id, next_state='AddClient')
            flow_manager.QueueRequest(state)
            msg = rdf_flows.GrrMessage(session_id=hunt_id, request_id=state.id, response_id=1, auth_state=rdf_flows.GrrMessage.AuthorizationState.AUTHENTICATED, type=rdf_flows.GrrMessage.Type.STATUS, payload=rdf_flows.GrrStatus())
            flow_manager.QueueResponse(msg)
            flow_manager.QueueNotification(session_id=hunt_id)

This method is called by the foreman for each client it discovers.

Note that this function is performance sensitive since it is called by the
foreman for every client which needs to be scheduled.

Args:
hunt_id: The hunt to schedule.
client_ids: List of clients that should be added to the hunt.
token: An optional access token to use.


def calc_shape_statistics(self, stat_names):

        stats = {}
        try:
            all_props = [regionprops(m) for m in self.masks]
        except TypeError:
            print(self.masks)
            exit()
        for stat in stat_names:
            stats[stat] = np.mean([p[0][stat] for p in all_props])
        return stats

Calculate shape statistics using regionprops applied to the object mask.

Args:
stat_names: List of statistics to be extracted from those calculated by regionprops.

Returns:
Dictionary of shape statistics


def repeat(x, repeats, axis=None):
    if any_symbolic_tensors((x,)):
        return Repeat(repeats, axis=axis).symbolic_call(x)
    return backend.numpy.repeat(x, repeats, axis=axis)

Repeat each element of a tensor after themselves.

Args:
x: Input tensor.
repeats: The number of repetitions for each element.
axis: The axis along which to repeat values. By default, use
the flattened input array, and return a flat output array.

Returns:
Output tensor.


def sample_frames(self, video: 'torch.Tensor', metadata: Optional[Union[VideoMetadata, dict]]=None, num_frames: Optional[int]=None, fps: Optional[int]=None, initial_shift: Optional[Union[bool, float, int]]=None):
    num_frames = num_frames if num_frames is not None else self.num_frames
    initial_shift = initial_shift if initial_shift is not None else self.initial_shift
    total_num_frames = video.shape[0]
    if num_frames is None and fps is not None:
        if metadata is None:
            raise ValueError('Asked to sample `fps` frames per second but no video metadata was provided which is required when sampling with `fps`. Please pass in `VideoMetadata` object or use a fixed `num_frames` per input video')
        num_frames = int(total_num_frames / metadata['fps'] * fps)
    if initial_shift is True:
        initial_shift = total_num_frames / num_frames / 2
    if num_frames > total_num_frames:
        raise ValueError(f"Video can't be sampled. The `num_frames={num_frames}` exceeds `total_num_frames={total_num_frames}`. ")
    indices = torch.arange(initial_shift, total_num_frames, total_num_frames / num_frames).int()
    video = video[indices].contiguous()
    return video

Default sampling function which uniformly samples the desired number of frames between 0 and total number of frames.
If `fps` is passed along with metadata, `fps` frames per second are sampled uniformty. Arguments `num_frames`
and `fps` are mutually exclusive.

Args:
video (`torch.Tensor`):
Video that need to be sampled.
metadata (`VideoMetadata`, *optional*):
Metadata of the video containing information about total duration, fps and total number of frames.
num_frames (`int`, *optional*):
Maximum number of frames to sample. Defaults to `self.num_frames`.
fps (`int`, *optional*):
Target frames to sample per second. Defaults to `self.fps`.
initial_shift (`bool`, `float` or `int`, defaults to `self.initial_shift`):
The initial shift to apply when sampling frames. If `True`, the shift is set so that frames are sampled from the middle of the video.

Returns:
torch.Tensor:
Sampled video frames.


Return the value of the fuzz factor used in numeric expressions.

Returns:
A float.

Example:

>>> keras.config.epsilon()
1e-07


def depth_atleast(list_, depth):
    if (depth == 0):
        return True
    else:
        try:
            return all([depth_atleast(item, (depth - 1)) for item in list_])
        except TypeError:
            return False

r"""
Returns if depth of list is at least ``depth``

Args:
list_ (list):
depth (int):

Returns:
bool: True

CommandLine:
python -m utool.util_dict --exec-depth_atleast --show

Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_dict import *  # NOQA
>>> import utool as ut
>>> list_ = [[[[0]]], [[0]]]
>>> depth = 0
>>> result = [depth_atleast(list_, depth) for depth in range(0, 7)]
>>> print(result)


def __getitem__(self, key):

        if isinstance(key, slice):
            start = key.start

            step = key.step
            stop = key.stop
            if self.index_type is not None:
                index_expr = grizzly_impl.get_field(self.expr, 0)
                column_expr = grizzly_impl.get_field(self.expr, 1)
                zip_expr = grizzly_impl.zip_columns([index_expr, column_expr])
                sliced_expr = grizzly_impl.slice_vec(zip_expr, start, stop)
                unzip_expr = grizzly_impl.unzip_columns(
                    sliced_expr,
                    [self.index_type, self.weld_type]
                )
                return SeriesWeld(
                    unzip_expr,
                    self.weld_type,
                    self.df,
                    self.column_name,
                    self.index_type,
                    self.index_name
                )
            else:
                return SeriesWeld(
                    grizzly_impl.slice_vec(
                        self.expr,
                        start,
                        stop
                    )
                )
        else:

            return self.filter(key)

Summary

Args:
predicates (TYPE): Description
new_value (TYPE): Description

Returns:
TYPE: Description


def pow(cls, x: 'TensorFluent', y: 'TensorFluent') -> 'TensorFluent':
    return cls._binary_op(x, y, tf.pow, tf.float32)

Returns a TensorFluent for the pow function.TensorFluent

Args:
x: The first operand.
y: The second operand.

Returns:
A TensorFluent wrapping the pow function.


def _get_single_block_row_attention(block_id, to_start_block_id, to_end_block_id, num_rand_blocks, indices_prng_key: Optional[jax.random.PRNGKey]=None, window_block_left=1, window_block_right=1, global_block_left=1, global_block_right=1):
    to_block_list = jnp.arange(to_start_block_id, to_end_block_id, dtype=jnp.int32)
    perm_block = jax.random.permutation(indices_prng_key, to_block_list)
    illegal_blocks = list(range(block_id - window_block_left, block_id + window_block_right + 1))
    illegal_blocks.extend(list(range(global_block_left)))
    illegal_blocks.extend(list(range(to_end_block_id - global_block_right, to_end_block_id)))
    if block_id == 1:
        illegal_blocks.append(to_end_block_id - 2)
    if block_id == to_end_block_id - 2:
        illegal_blocks.append(1)
    selected_random_blocks = []
    for i in range(to_end_block_id - to_start_block_id):
        if perm_block[i] not in illegal_blocks:
            selected_random_blocks.append(perm_block[i])
        if len(selected_random_blocks) == num_rand_blocks:
            break
    return jnp.array(selected_random_blocks, dtype=jnp.int32)

For a single row block get random row attention.

Args:
block_id: int. block id of row.
to_start_block_id: int. random attention column start id.
to_end_block_id: int. random attention column end id.
num_rand_blocks: int. number of random blocks to be selected.
indices_prng_key: jax.random.PRNGKey. PRNG key that is used to perform random jax operations
window_block_left: int. number of blocks of window to left of a block.
window_block_right: int. number of blocks of window to right of a block.
global_block_left: int. Number of blocks globally used to the left.
global_block_right: int. Number of blocks globally used to the right.

Returns:
row containing the random attention vector of size num_rand_blocks.


def GetMACBRepresentation(self, event):

    data_type = getattr(event, 'data_type', None)
    if not data_type:
      return '....'

    if data_type == 'fs:stat':
      descriptions = event.timestamp_desc.split(';')

      return_characters = ['.', '.', '.', '.']
      for description in descriptions:
        if description in (
            'mtime', definitions.TIME_DESCRIPTION_MODIFICATION):
          return_characters[0] = 'M'
        elif description in (
            'atime', definitions.TIME_DESCRIPTION_LAST_ACCESS):
          return_characters[1] = 'A'
        elif description in (
            'ctime', definitions.TIME_DESCRIPTION_CHANGE):
          return_characters[2] = 'C'
        elif description in (
            'crtime', definitions.TIME_DESCRIPTION_CREATION):
          return_characters[3] = 'B'

      return ''.join(return_characters)

    if event.timestamp_desc in [
        definitions.TIME_DESCRIPTION_LAST_ACCESS,
        definitions.TIME_DESCRIPTION_ACCOUNT_CREATED,
        definitions.TIME_DESCRIPTION_LAST_VISITED,
        definitions.TIME_DESCRIPTION_START,
        definitions.TIME_DESCRIPTION_LAST_SHUTDOWN,
        definitions.TIME_DESCRIPTION_LAST_LOGIN,
        definitions.TIME_DESCRIPTION_LAST_PASSWORD_RESET,
        definitions.TIME_DESCRIPTION_LAST_CONNECTED,
        definitions.TIME_DESCRIPTION_LAST_RUN,
        definitions.TIME_DESCRIPTION_LAST_PRINTED]:
      return '.A..'

    if event.timestamp_desc in [
        definitions.TIME_DESCRIPTION_MODIFICATION,
        definitions.TIME_DESCRIPTION_WRITTEN,
        definitions.TIME_DESCRIPTION_DELETED]:
      return 'M...'

    if event.timestamp_desc in [
        definitions.TIME_DESCRIPTION_CREATION,
        definitions.TIME_DESCRIPTION_ADDED,
        definitions.TIME_DESCRIPTION_FILE_DOWNLOADED,
        definitions.TIME_DESCRIPTION_FIRST_CONNECTED]:
      return '...B'

    if event.timestamp_desc in [
        definitions.TIME_DESCRIPTION_CHANGE,
        definitions.TIME_DESCRIPTION_ENTRY_MODIFICATION]:
      return '..C.'

    return '....'

Retrieves the MACB representation.

Args:
event (EventObject): event.

Returns:
str: MACB representation.


def load(self, path):
    missing_files = self._check_for_missing_files(path)
    if (len(missing_files) > 0):
        raise IOError('Invalid data set of type {}: files {} not found at {}'.format(self.type(), ' '.join(missing_files), path))
    return self._load(path)

Load and return the corpus from the given path.

Args:
path (str): Path to the data set to load.

Returns:
Corpus: The loaded corpus

Raises:
IOError: When the data set is invalid, for example because required files (annotations, …) are missing.


def get_camera_imageseries(self, number_of_imageseries=10, offset=0):
    response = None
    try:
        response = requests.get(urls.get_imageseries(self._giid), headers={'Accept': 'application/json, text/javascript, */*; q=0.01', 'Cookie': 'vid={}'.format(self._vid)}, params={'numberOfImageSeries': int(number_of_imageseries), 'offset': int(offset), 'fromDate': '', 'toDate': '', 'onlyNotViewed': '', '_': self._giid})
    except requests.exceptions.RequestException as ex:
        raise RequestError(ex)
    _validate_response(response)
    return json.loads(response.text)

Get smartcam image series

Args:
number_of_imageseries (int): number of image series to get
offset (int): skip offset amount of image series


def CreateKey(self, prikey=None):

        account = super(UserWallet, self).CreateKey(private_key=prikey)
        self.OnCreateAccount(account)
        contract = WalletContract.CreateSignatureContract(account.PublicKey)
        self.AddContract(contract)
        return account

Create a KeyPair and store it encrypted in the database.

Args:
private_key (iterable_of_ints): (optional) 32 byte private key.

Returns:
KeyPair: a KeyPair instance.


def is_directory(dirname):
    return is_directory_v2(dirname)

Returns whether the path is a directory or not.

Args:
dirname: string, path to a potential directory

Returns:
True, if the path is a directory; False otherwise


def read_file(filename):

    hits = glob.glob('**/{}'.format(filename), recursive=True)
    if not len(hits):
        pf.debug('No file "{}" found.'.format(filename))
        return ''
    elif len(hits) > 1:
        pf.debug('File pattern "{}" ambiguous. Using first.'.format(filename))

    with open(hits[0], 'r') as f:
        return f.read()

Reads a file which matches the pattern `filename`.

Args:
filename The filename pattern

Returns:
The file content or the empty string, if the file is not found.


def write_data(data):

    sorted_dict = sort_recursive(data)

    with open(_datafile, 'w') as file:
        _json.dump(sorted_dict, file, indent=2)

Write the data to the data.json file

Args:
data (dict): The updated data dictionary for Modis


def __init__(self, desired_capabilities, url='http:

        self.session_id = None
        self.capabilities = None
        self.desired_capabilities = desired_capabilities
        self.remote_invoker = RemoteInvoker(url)

Initialize the WebDriver

Args:
desired_capabilities(dict): The desired capabilities requested by
the local end.
url(str): The url of remote server, default: localhost:3456/wd/hub.


def error_wrapper(fn, error_class):

    def wrapper(*args, **kwargs):
        try:
            return fn(*args, **kwargs)
        except Exception as e:
            six.reraise(error_class, error_class(e), sys.exc_info()[2])

    return wrapper

Wraps function fn in a try catch block that re-raises error_class.

Args:
fn (function): function to wrapped
error_class (Exception): Error class to be re-raised

Returns:
(object): fn wrapped in a try catch.


def canonicalize_text(self, text, *, keep_punctuation_exact_string=None):
    if keep_punctuation_exact_string:
        text = keep_punctuation_exact_string.join((self.remove_punctuation(part) for part in text.split(keep_punctuation_exact_string)))
    else:
        text = self.remove_punctuation(text)
    text = re.sub('\\s+', ' ', text)
    text = text.strip()
    return text

Returns canonicalized `text` (puncuation removed).

Args:
text (`str`):
String to be canonicalized.
keep_punctuation_exact_string (`str`, *optional*):
If provided, then this exact string is kept. For example providing '{}' will keep any occurrences of '{}'
(but will still remove '{' and '}' that appear separately).


def dump(o, f):

    if not f.write:
        raise TypeError("You can only dump an object to a file descriptor")
    d = dumps(o)
    f.write(d)
    return d

Writes out dict as toml to a file

Args:
o: Object to dump into toml
f: File descriptor where the toml should be stored

Returns:
String containing the toml corresponding to dictionary

Raises:
TypeError: When anything other than file descriptor is passed


def get_instance_key(self, group_key, device):
    with self._lock:
        group = self._instance_key_table.get(group_key, None)
        if group is None:
            raise ValueError(f'Group {group_key} is not found.')
        if device not in group:
            raise ValueError(f'Device {device} is not present in group {group_key}')
        v = group[device]
        group[device] += 1
        return v

Returns a new instance key for use in defining a collective op.

You should call this once per each collective op of a collective instance.

Args:
group_key: the group key returned by get_group_key(). You should not
assign the group key yourself.
device: a canonical device string. It should be the device this collective
op is on.

Returns:
a new instance key.

Raises:
ValueError: when the group key is invalid or the device is not in the
group.


def func(self, volume):
    return self._func(np.array(volume), self.eos_params)

The equation of state function with the paramters other than volume set
to the ones obtained from fitting.

Args:
volume (list/numpy.array)

Returns:
numpy.array


def users_lookupByEmail(self, *, email: str, **kwargs) -> SlackResponse:
    kwargs.update({'email': email})
    return self.api_call('users.lookupByEmail', http_verb='GET', params=kwargs)

Find a user with an email address.

Args:
email (str): An email address belonging to a user in the workspace.
e.g. 'spengler@ghostbusters.example.com'


def pad_blank_lines(indent_texts):

    current_indent = 0
    result = []
    for indent, text in indent_texts:
        if len(text) > 0:
            current_indent = indent
        result.append((current_indent, text))
    return result

Give blank (empty) lines the same indent level as the preceding line.

Args:
indent_texts: An iterable of tuples each containing an integer in the
first element and a string in the second element.

Returns:
A list of tuples each containing an integer in the first element and a
string in the second element.


def _GetNumberOfSeconds(self, fat_date_time):
    day_of_month = (fat_date_time & 31)
    month = ((fat_date_time >> 5) & 15)
    year = ((fat_date_time >> 9) & 127)
    days_per_month = self._GetDaysPerMonth(year, month)
    if ((day_of_month < 1) or (day_of_month > days_per_month)):
        raise ValueError('Day of month value out of bounds.')
    number_of_days = self._GetDayOfYear((1980 + year), month, day_of_month)
    number_of_days -= 1
    for past_year in range(0, year):
        number_of_days += self._GetNumberOfDaysInYear(past_year)
    fat_date_time >>= 16
    seconds = ((fat_date_time & 31) * 2)
    minutes = ((fat_date_time >> 5) & 63)
    hours = ((fat_date_time >> 11) & 31)
    if (hours not in range(0, 24)):
        raise ValueError('Hours value out of bounds.')
    if (minutes not in range(0, 60)):
        raise ValueError('Minutes value out of bounds.')
    if (seconds not in range(0, 60)):
        raise ValueError('Seconds value out of bounds.')
    number_of_seconds = ((((hours * 60) + minutes) * 60) + seconds)
    number_of_seconds += (number_of_days * definitions.SECONDS_PER_DAY)
    return number_of_seconds

Retrieves the number of seconds from a FAT date time.

Args:
fat_date_time (int): FAT date time.

Returns:
int: number of seconds since January 1, 1980 00:00:00.

Raises:
ValueError: if the month, day of month, hours, minutes or seconds
value is out of bounds.


def _parse_query(self, source):
    if self.OBJECTFILTER_WORDS.search(source):
        syntax_ = 'objectfilter'
    else:
        syntax_ = None
    return query.Query(source, syntax=syntax_)

Parse one of the rules as either objectfilter or dottysql.

Example:
_parse_query("5 + 5")
# Returns Sum(Literal(5), Literal(5))

Arguments:
source: A rule in either objectfilter or dottysql syntax.

Returns:
The AST to represent the rule.


def __init__(self, channel):

        self.ListInstances = channel.unary_unary(
            "/google.cloud.redis.v1.CloudRedis/ListInstances",
            request_serializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.ListInstancesRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.ListInstancesResponse.FromString,
        )
        self.GetInstance = channel.unary_unary(
            "/google.cloud.redis.v1.CloudRedis/GetInstance",
            request_serializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.GetInstanceRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.Instance.FromString,
        )
        self.CreateInstance = channel.unary_unary(
            "/google.cloud.redis.v1.CloudRedis/CreateInstance",
            request_serializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.CreateInstanceRequest.SerializeToString,
            response_deserializer=google_dot_longrunning_dot_operations__pb2.Operation.FromString,
        )
        self.UpdateInstance = channel.unary_unary(
            "/google.cloud.redis.v1.CloudRedis/UpdateInstance",
            request_serializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.UpdateInstanceRequest.SerializeToString,
            response_deserializer=google_dot_longrunning_dot_operations__pb2.Operation.FromString,
        )
        self.ImportInstance = channel.unary_unary(
            "/google.cloud.redis.v1.CloudRedis/ImportInstance",
            request_serializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.ImportInstanceRequest.SerializeToString,
            response_deserializer=google_dot_longrunning_dot_operations__pb2.Operation.FromString,
        )
        self.ExportInstance = channel.unary_unary(
            "/google.cloud.redis.v1.CloudRedis/ExportInstance",
            request_serializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.ExportInstanceRequest.SerializeToString,
            response_deserializer=google_dot_longrunning_dot_operations__pb2.Operation.FromString,
        )
        self.FailoverInstance = channel.unary_unary(
            "/google.cloud.redis.v1.CloudRedis/FailoverInstance",
            request_serializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.FailoverInstanceRequest.SerializeToString,
            response_deserializer=google_dot_longrunning_dot_operations__pb2.Operation.FromString,
        )
        self.DeleteInstance = channel.unary_unary(
            "/google.cloud.redis.v1.CloudRedis/DeleteInstance",
            request_serializer=google_dot_cloud_dot_redis__v1_dot_proto_dot_cloud__redis__pb2.DeleteInstanceRequest.SerializeToString,
            response_deserializer=google_dot_longrunning_dot_operations__pb2.Operation.FromString,
        )

Constructor.

Args:
channel: A grpc.Channel.


def create_with_secret(self, name, secret, encryption):
    try:
        encryption = (encryption or DEFAULT_ENCRYPTION)
        enc = ENCRYPTION_MAP[encryption]
    except KeyError:
        raise TypeError('encryption must be one of "cleartext", "md5" or "sha512"')
    cmd = ('username %s secret %s %s' % (name, enc, secret))
    return self.configure(cmd)

Creates a new user on the local node

Args:
name (str): The name of the user to craete

secret (str): The secret (password) to assign to this user

encryption (str): Specifies how the secret is encoded.  Valid
values are "cleartext", "md5", "sha512".  The default is
"cleartext"

Returns:
True if the operation was successful otherwise False


def ResolvePath(self, path, expand_variables=True):

    location, path_spec = self._ResolvePath(
        path, expand_variables=expand_variables)

    if not location or not path_spec:
      return None

    kwargs = path_spec_factory.Factory.GetProperties(path_spec)

    kwargs['location'] = location
    if not path_spec_factory.Factory.IsSystemLevelTypeIndicator(
        self._file_system.type_indicator):
      kwargs['parent'] = self._mount_point

    return path_spec_factory.Factory.NewPathSpec(
        self._file_system.type_indicator, **kwargs)

Resolves a Windows path in file system specific format.

Args:
path (str): Windows path to resolve.
expand_variables (Optional[bool]): True if path variables should be
expanded or not.

Returns:
PathSpec: path specification in file system specific format.


def normalize_text(value):
    if (value is None):
        return ''
    text = (decode_bytes(value) if isbytes(value) else str_(value))
    return normalize_whitespace(text)

Normalizes the given value to a string of text with extra whitespace removed.

Byte sequences are decoded. ``None`` is converted to an empty string. Everything else
is simply cast to a string.

Args:
value (Any): The data to normalize.

Returns:
str: The normalized text.


def __init__(self, message_type=None, length=None, xid=None):

        super().__init__()
        self.message_type = message_type
        self.length = length
        self.xid = xid

Create a Header with the optional parameters below.

Args:
message_type (~pyof.v0x04.common.header.Type):
One of the OFPT_* constants.
length (int): Length including this ofp_header.
xid (int): Transaction id associated with this packet. Replies use
the same id as was in the request to facilitate pairing.


def _get_wrapper(x, tf_should_use_helper):
    type_x = type(x)
    memoized = _WRAPPERS.get(type_x, None)
    if memoized:
        return memoized(x, tf_should_use_helper)
    tx = copy.deepcopy(ShouldUseWrapper)
    bases = getattr(tx, '__orig_bases__', tx.__bases__)

    def set_body(ns):
        ns.update(tx.__dict__)
        return ns
    copy_tx = types.new_class(tx.__name__, bases, exec_body=set_body)
    copy_tx.__init__ = _new__init__
    copy_tx.__getattribute__ = _new__getattribute__
    for op in OVERLOADABLE_OPERATORS:
        if hasattr(type_x, op):
            setattr(copy_tx, op, getattr(type_x, op))
    copy_tx.mark_used = _new_mark_used
    copy_tx.__setattr__ = _new__setattr__
    _WRAPPERS[type_x] = copy_tx
    return copy_tx(x, tf_should_use_helper)

Create a wrapper for object x, whose class subclasses type(x).

The wrapper will emit a warning if it is deleted without any of its
properties being accessed or methods being called.

Args:
x: The instance to wrap.
tf_should_use_helper: The object that tracks usage.

Returns:
An object wrapping `x`, of type `type(x)`.


class SquadExample:

    def __init__(self, qas_id, question_text, context_text, answer_text, start_position_character, title, answers=[], is_impossible=False):
        self.qas_id = qas_id
        self.question_text = question_text
        self.context_text = context_text
        self.answer_text = answer_text
        self.title = title
        self.is_impossible = is_impossible
        self.answers = answers
        self.start_position, self.end_position = (0, 0)
        doc_tokens = []
        char_to_word_offset = []
        prev_is_whitespace = True
        for c in self.context_text:
            if _is_whitespace(c):
                prev_is_whitespace = True
            else:
                if prev_is_whitespace:
                    doc_tokens.append(c)
                else:
                    doc_tokens[-1] += c
                prev_is_whitespace = False
            char_to_word_offset.append(len(doc_tokens) - 1)
        self.doc_tokens = doc_tokens
        self.char_to_word_offset = char_to_word_offset
        if start_position_character is not None and (not is_impossible):
            self.start_position = char_to_word_offset[start_position_character]
            self.end_position = char_to_word_offset[min(start_position_character + len(answer_text) - 1, len(char_to_word_offset) - 1)]

A single training/test example for the Squad dataset, as loaded from disk.

Args:
qas_id: The example's unique identifier
question_text: The question string
context_text: The context string
answer_text: The answer string
start_position_character: The character position of the start of the answer
title: The title of the example
answers: None by default, this is used during evaluation. Holds answers as well as their start positions.
is_impossible: False by default, set to True if the example has no possible answer.


def _ReadAndCheckStorageMetadata(self, check_readable_only=False):

    query = 'SELECT key, value FROM metadata'
    self._cursor.execute(query)

    metadata_values = {row[0]: row[1] for row in self._cursor.fetchall()}

    self._CheckStorageMetadata(
        metadata_values, check_readable_only=check_readable_only)

    self.format_version = metadata_values['format_version']
    self.compression_format = metadata_values['compression_format']
    self.serialization_format = metadata_values['serialization_format']
    self.storage_type = metadata_values['storage_type']

Reads storage metadata and checks that the values are valid.

Args:
check_readable_only (Optional[bool]): whether the store should only be
checked to see if it can be read. If False, the store will be checked
to see if it can be read and written to.


def getUserCaPath(self, name):

        cert = self.getUserCert(name)
        if cert is None:
            return None

        return self._getCaPath(cert)

Gets the path to the CA certificate that issued a given user keypair.

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

Examples:
Get the path to the CA cert which issue the cert for "myuser":

mypath = cdir.getUserCaPath('myuser')

Returns:
str: The path if exists.


def _auditpol_cmd(cmd):
    ret = salt.modules.cmdmod.run_all(cmd='auditpol {0}'.format(cmd), python_shell=True)
    if (ret['retcode'] == 0):
        return ret['stdout'].splitlines()
    msg = 'Error executing auditpol command: {0}\n'.format(cmd)
    msg += '\n'.join(ret['stdout'])
    raise CommandExecutionError(msg)

Helper function for running the auditpol command

Args:
cmd (str): the auditpol command to run

Returns:
list: A list containing each line of the return (splitlines)

Raises:
CommandExecutionError: If the command encounters an error


def line_id(self, lat):
    if (self.grid == 'WAC'):
        line = np.rint(((1.0 + self.LINE_PROJECTION_OFFSET) - (((self.A_AXIS_RADIUS * np.pi) * lat) / ((self.MAP_SCALE * 0.001) * 180))))
    else:
        line = (np.rint((float(self.LINE_PROJECTION_OFFSET) - (float(self.MAP_RESOLUTION) * (lat - float(self.CENTER_LATITUDE))))) + 1)
    return self._control_line(line)

Return the corresponding line

Args:
lat (int): latitude in degree

Returns:
Correponding line


def _decode_byte(byte):
    bits = []
    for _ in range(8):
        bits.append((byte & 1))
        byte >>= 1
    return bits

Helper for decode_qp, turns a single byte into a list of bits.

Args:
byte: byte to be decoded

Returns:
list of bits corresponding to byte


def _from_tensor_list(self, tensor_list: List['core_types.Symbol']) -> Any:
    self.__check_tensor_list(tensor_list)
    return self._from_compatible_tensor_list(tensor_list)

Reconstructs a value from a flat list of `tf.Tensor`.

Args:
tensor_list: A flat list of `tf.Tensor`, compatible with
`self._flat_tensor_specs`.

Returns:
A value that is compatible with this `TypeSpec`.

Raises:
ValueError: If `tensor_list` is not compatible with
`self._flat_tensor_specs`.


def sg_rnn_layer_func(func):
    r
    @wraps(func)
    def wrapper(tensor, **kwargs):
        r

        opt = tf.sg_opt(kwargs) + sg_get_context()

        try:
            shape = tensor.get_shape().as_list()

            opt += tf.sg_opt(shape=shape, in_dim=shape[-1], dim=shape[-1], dout=0, summary=True)

            opt += tf.sg_opt(bias=not opt.ln)
        finally:
            pass

        if opt.name is None:

            opt.name = func.__name__.replace('sg_', '')

            exist_layers = []
            for t in tf.global_variables():
                scope_name = tf.get_variable_scope().name
                prefix = scope_name + '/' if len(scope_name) > 0 else ''
                i = t.name.rfind(prefix + opt.name)
                if i >= 0:
                    exist_layers.append(t.name[i:].split('/')[-2])
            exist_layers = list(set(exist_layers))

            if len(exist_layers) == 0:
                opt.name += '_1'
            else:
                opt.name += '_%d' % (max([int(n.split('_')[-1]) for n in exist_layers]) + 1)

        with tf.variable_scope(opt.name, reuse=opt.reuse) as scope:

            out = func(tensor, opt)

            if opt.dout:
                out = tf.cond(_phase,
                              lambda: tf.nn.dropout(out, 1 - opt.dout),
                              lambda: out)

            out = tf.identity(out, 'out')

            if opt.summary:
                tf.sg_summary_activation(out)

            out._sugar = tf.sg_opt(func=func, arg=tf.sg_opt(kwargs) + sg_get_context(),
                                   prev=tensor, is_layer=True, name=opt.name)

            out.sg_reuse = types.MethodType(sg_reuse, out)

        return out

    return wrapper

r"""Decorates function as sg_rnn_layer functions.
Args:
func: function to decorate


def Create(self, project_id, start_options=None, deadline=10):

    return DatastoreEmulator(self._emulator_cmd, self._working_directory,
                             project_id, deadline, start_options)

Creates an emulator instance.

This method will wait for up to 'deadline' seconds for the emulator to
start.

Args:
project_id: project ID
start_options: a list of additional command-line options to pass to the
emulator 'start' command
deadline: number of seconds to wait for the datastore to respond

Returns:
a DatastoreEmulator

Raises:
IOError: if the emulator could not be started within the deadline


def _interpolate_df_col(df, x=None, y=None, new_x=None, dx=10.0, number_of_points=None, direction=1, **kwargs):
    if (x is None):
        x = df.columns[0]
    if (y is None):
        y = df.columns[1]
    xs = df[x].values
    ys = df[y].values
    if (direction > 0):
        x_min = xs.min()
        x_max = xs.max()
    else:
        x_max = xs.min()
        x_min = xs.max()
        dx = (- dx)
    bounds_error = kwargs.pop('bounds_error', False)
    f = interpolate.interp1d(xs, ys, bounds_error=bounds_error, **kwargs)
    if (new_x is None):
        if number_of_points:
            new_x = np.linspace(x_min, x_max, number_of_points)
        else:
            new_x = np.arange(x_min, x_max, dx)
    new_y = f(new_x)
    new_df = pd.DataFrame({x: new_x, y: new_y})
    return new_df

Interpolate a column based on another column.

Args:
df: DataFrame with the (cycle) data.
x: Column name for the x-value (defaults to the step-time column).
y: Column name for the y-value (defaults to the voltage column).
new_x (numpy array or None): Interpolate using these new x-values
instead of generating x-values based on dx or number_of_points.
dx: step-value (defaults to 10.0)
number_of_points: number of points for interpolated values (use
instead of dx and overrides dx if given).
direction (-1,1): if direction is negetive, then invert the
x-values before interpolating.
**kwargs: arguments passed to scipy.interpolate.interp1d

Returns: DataFrame with interpolated y-values based on given or
generated x-values.


def prepare_question_encoder(inputs, hparams):
    encoder_input = inputs
    encoder_padding = common_attention.embedding_to_padding(encoder_input)
    ignore_padding = common_attention.attention_bias_ignore_padding(encoder_padding)
    encoder_self_attention_bias = ignore_padding
    if (hparams.pos == 'timing'):
        encoder_input = common_attention.add_timing_signal_1d(encoder_input)
    elif (hparams.pos == 'emb'):
        encoder_input = common_attention.add_positional_embedding(encoder_input, hparams.max_length, 'inputs_positional_embedding', None)
    return (encoder_input, encoder_self_attention_bias)

Prepare question encoder.

Args:
inputs: a Tensor.
hparams: run hyperparameters

Returns:
encoder_input: a Tensor, bottom of encoder stack
encoder_self_attention_bias: a bias tensor for use in encoder self-attention


def racks(self):
    if (not self.__racks):
        self.__racks = Racks(self.__connection)
    return self.__racks

Gets the Racks API client.

Returns:
Racks:


def snake_case_to_camel_case(input_str: str, upper: bool=False) -> str:
    parts = input_str.split('_')
    if len(parts) == 1:
        return input_str.capitalize() if upper else input_str
    result = parts[0] + ''.join([w[0].upper() + w[1:] for w in parts[1:]])
    return result[0].upper() + result[1:] if upper else result

Transforms a snake_case string into a camelCase/UpperCamelCase string.

Args:
input_str: The input string to transform.
upper: If True, returns a representation in Pascal/UpperCamelCase. Defaults
to False.

Returns:
A camelCase/UpperCamelCase string.


def mark_bool_flags_as_mutual_exclusive(flag_names, required=False, flag_values=_flagvalues.FLAGS):
    for flag_name in flag_names:
        if (not flag_values[flag_name].boolean):
            raise _exceptions.ValidationError('Flag --{} is not Boolean, which is required for flags used in mark_bool_flags_as_mutual_exclusive.'.format(flag_name))

    def validate_boolean_mutual_exclusion(flags_dict):
        flag_count = sum((bool(val) for val in flags_dict.values()))
        if ((flag_count == 1) or ((not required) and (flag_count == 0))):
            return True
        raise _exceptions.ValidationError('{} one of ({}) must be True.'.format(('Exactly' if required else 'At most'), ', '.join(flag_names)))
    register_multi_flags_validator(flag_names, validate_boolean_mutual_exclusion, flag_values=flag_values)

Ensures that only one flag among flag_names is True.

Args:
flag_names: [str], names of the flags.
required: bool. If true, exactly one flag must be True. Otherwise, at most
one flag can be True, and it is valid for all flags to be False.
flag_values: flags.FlagValues, optional FlagValues instance where the flags
are defined.


def _clone_and_score_clusterer(clf, X, n_clusters):
    start = time.time()
    clf = clone(clf)
    setattr(clf, 'n_clusters', n_clusters)
    return (clf.fit(X).score(X), (time.time() - start))

Clones and scores clusterer instance.

Args:
clf: Clusterer instance that implements ``fit``,``fit_predict``, and
``score`` methods, and an ``n_clusters`` hyperparameter.
e.g. :class:`sklearn.cluster.KMeans` instance

X (array-like, shape (n_samples, n_features)):
Data to cluster, where n_samples is the number of samples and
n_features is the number of features.

n_clusters (int): Number of clusters

Returns:
score: Score of clusters

time: Number of seconds it took to fit cluster


def df_to_parquet(df, filename, compression='SNAPPY'):

    for column in df.columns:
        if(df[column].dtype == 'timedelta64[ns]'):
            print('Converting timedelta column {:s}...'.format(column))
            df[column] = df[column].astype(str)

    arrow_table = pa.Table.from_pandas(df)
    if compression == 'UNCOMPRESSED':
        compression = None
    pq.write_table(arrow_table, filename, compression=compression, use_deprecated_int96_timestamps=True)

write_to_parquet: Converts a Pandas DataFrame into a Parquet file
Args:
df (pandas dataframe): The Pandas Dataframe to be saved as parquet file
filename (string): The full path to the filename for the Parquet file


def create_temp_grad(node, namer, tangent=False):
    if (not isinstance(node, (gast.Subscript, gast.Name))):
        raise TypeError

    def _name_temp_grad(node):
        name = namer.temp_grad(node.id, tangent)
        temp_node = gast.Name(id=name, annotation=None, ctx=None)
        return temp_node
    if isinstance(node, gast.Subscript):
        temp_node = _name_temp_grad(node.value)
    else:
        temp_node = _name_temp_grad(node)
    anno.setanno(temp_node, 'temp_adjoint_var', node)
    return temp_node

Create a variable to store partial gradients.

Args:
node: See `create_grad`.
namer: See `create_grad`.
tangent: See `create_grad`.

Returns:
node: See `create_grad`. Returns a node representing the partial gradient.
Note that this is always a simple variable e.g. the temporary partial
of `x[i]` can be something like `_dxi`.

Nodes are given an annotation `temp_adjoint_var`.


def encode(self):
    if self.histogram.total_count:
        relevant_length = (self.histogram.get_counts_array_index(self.histogram.max_value) + 1)
    else:
        relevant_length = 0
    cpayload = self.payload.compress(relevant_length)
    if self.b64_wrap:
        self.header.length = len(cpayload)
        header_str = ctypes.string_at(addressof(self.header), ext_header_size)
        return base64.b64encode((header_str + cpayload))
    return cpayload

Compress the associated encodable payload,
prepend the header then encode with base64 if requested

Returns:
the b64 encoded wire encoding of the histogram (as a string)
or the compressed payload (as a string, if b64 wrappinb is disabled)


def _sample_actions(self,
            state: Sequence[tf.Tensor]) -> Tuple[Sequence[tf.Tensor], tf.Tensor, tf.Tensor]:

        default = self.compiler.compile_default_action(self.batch_size)
        bound_constraints = self.compiler.compile_action_bound_constraints(state)
        action = self._sample_action(bound_constraints, default)
        n, action, checking = self._check_preconditions(state, action, bound_constraints, default)
        return action, n, checking

Returns sampled action fluents and tensors related to the sampling.

Args:
state (Sequence[tf.Tensor]): A list of state fluents.

Returns:
Tuple[Sequence[tf.Tensor], tf.Tensor, tf.Tensor]: A tuple with
action fluents, an integer tensor for the number of samples, and
a boolean tensor for checking all action preconditions.


def get_and_check_single_upstream_artifact_full_path(context, task_id, path):
    abs_path = get_single_upstream_artifact_full_path(context, task_id, path)
    if (not os.path.exists(abs_path)):
        raise ScriptWorkerTaskException('upstream artifact with path: {}, does not exist'.format(abs_path))
    return abs_path

Return the full path where an upstream artifact is located on disk.

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

Returns:
str: absolute path to the artifact

Raises:
scriptworker.exceptions.ScriptWorkerTaskException: when an artifact doesn't exist.


def ParseNetworkDataUsage(
      self, parser_mediator, cache=None, database=None, table=None,
      **unused_kwargs):

    self._ParseGUIDTable(
        parser_mediator, cache, database, table,
        self._NETWORK_DATA_USAGE_VALUES_MAP, SRUMNetworkDataUsageEventData)

Parses the network data usage monitor table.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
cache (Optional[ESEDBCache]): cache, which contains information about
the identifiers stored in the SruDbIdMapTable table.
database (Optional[pyesedb.file]): ESE database.
table (Optional[pyesedb.table]): table.


def get_as(access_token, subscription_id, resource_group, as_name):
    endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourceGroups/', resource_group, '/providers/Microsoft.Compute/availabilitySets/', as_name, '?api-version=', COMP_API])
    return do_get(endpoint, access_token)

Get availability set details.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
as_name (str): Name of the new availability set.

Returns:
HTTP response. JSON body of the availability set properties.


def __fspath__(self) -> str:
    raise NotImplementedError('zipapp not supported. Please send us a PR.')

Path string for `os.path.join`, `open`,...

compatibility.

Note: Calling `os.fspath` on the path extract the file, so should be
discouraged. Prefer using `read_bytes`,... This only works for files,
not directories.

Returns:
the extracted path string.


def RunShellWithReturnCode(command, print_output=False,
		universal_newlines=True, env=os.environ):

	logging.info("Running %s", command)
	p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
		shell=use_shell, universal_newlines=universal_newlines, env=env)
	if print_output:
		output_array = []
		while True:
			line = p.stdout.readline()
			if not line:
				break
			print line.strip("\n")
			output_array.append(line)
		output = "".join(output_array)
	else:
		output = p.stdout.read()
	p.wait()
	errout = p.stderr.read()
	if print_output and errout:
		print >>sys.stderr, errout
	p.stdout.close()
	p.stderr.close()
	return output, p.returncode

Executes a command and returns the output from stdout and the return code.

Args:
command: Command to execute.
print_output: If True, the output is printed to stdout.
If False, both stdout and stderr are ignored.
universal_newlines: Use universal_newlines flag (default: True).

Returns:
Tuple (output, return code)


def match_template(tree, template, args=None):

    tokens = get_tokens(template.split())
    cur_args = {}
    if match_tokens(tree, tokens, cur_args):
        if args is not None:
            for k, v in cur_args.items():
                args[k] = v
        logger.debug('MATCHED: {0}'.format(template))
        return True
    else:
        return False

Check if match string matches Tree structure

Args:
tree (Tree): Parsed Tree structure of a sentence
template (str): String template to match. Example: "( S ( NP ) )"
Returns:
bool: If they match or not