def render(self, tmpl_name, request_env):
    return super(WebApplication, self).render(tmpl_name, request_env)

Render the specified template and return the output.

Args:
tmpl_name (str): file name of the template
request_env (dict): request environment

Returns:
str - the rendered template


def _ParseChatData(self, data):

    data_store = {}

    if 'body' in data:
      body = data.get('body', '').replace('\n', ' ')
      if body.startswith('
        body_dict = self._ExtractJQuery(body)
        title, _, _ = body.partition('{')
        body = '{0:s} <{1!s}>'.format(
            title[2:], self._DictToListOfStrings(body_dict))
    else:
      body = 'No text.'

    data_store['text'] = body

    room = data.get('rooms', None)
    if not room:
      room = data.get('room', None)
    if room:
      data_store['room'] = room

    data_store['id'] = data.get('id', None)
    user = data.get('user', None)
    if user:
      try:
        user_sid = int(user)
        data_store['sid'] = user_sid
      except (ValueError, TypeError):
        data_store['user'] = user

    return data_store

Parses chat comment data.

Args:
data (dict[str, object]): chat comment data as returned by SQLite.

Returns:
dict[str, object]: parsed chat comment data.


def create_next_candidates(prev_candidates, length):

    item_set = set()
    for candidate in prev_candidates:
        for item in candidate:
            item_set.add(item)
    items = sorted(item_set)

    tmp_next_candidates = (frozenset(x) for x in combinations(items, length))

    if length < 3:
        return list(tmp_next_candidates)

    next_candidates = [
        candidate for candidate in tmp_next_candidates
        if all(
            True if frozenset(x) in prev_candidates else False
            for x in combinations(candidate, length - 1))
    ]
    return next_candidates

Returns the apriori candidates as a list.

Arguments:
prev_candidates -- Previous candidates as a list.
length -- The lengths of the next candidates.


def _GetUnsortedNotifications(self,
                                queue_shard,
                                notifications_by_session_id=None):

    if notifications_by_session_id is None:
      notifications_by_session_id = {}
    end_time = self.frozen_timestamp or rdfvalue.RDFDatetime.Now()
    for notification in self.data_store.GetNotifications(queue_shard, end_time):

      existing = notifications_by_session_id.get(notification.session_id)
      if existing:

        if notification.first_queued > existing.first_queued:
          notifications_by_session_id[notification.session_id] = notification
        elif notification.first_queued == existing.first_queued and (
            notification.last_status > existing.last_status):

          logging.warning(
              "Notifications with equal first_queued fields detected: %s %s",
              notification, existing)
          notifications_by_session_id[notification.session_id] = notification
      else:
        notifications_by_session_id[notification.session_id] = notification

    return notifications_by_session_id

Returns all the available notifications for a queue_shard.

Args:
queue_shard: urn of queue shard
notifications_by_session_id: store notifications in this dict rather than
creating a new one

Returns:
dict of notifications. keys are session ids.


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

Get encoded debug configuration for component. Not cacheable.

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


def _Open(self, path_spec=None, mode='rb'):

    if not path_spec:
      raise ValueError('Missing path specfication.')

    volume_index = lvm.LVMPathSpecGetVolumeIndex(path_spec)
    if volume_index is None:
      raise errors.PathSpecError(
          'Unable to retrieve volume index from path specification.')

    self._file_system = resolver.Resolver.OpenFileSystem(
        path_spec, resolver_context=self._resolver_context)
    vslvm_volume_group = self._file_system.GetLVMVolumeGroup()

    if (volume_index < 0 or
        volume_index >= vslvm_volume_group.number_of_logical_volumes):
      raise errors.PathSpecError((
          'Unable to retrieve LVM logical volume index: {0:d} from path '
          'specification.').format(volume_index))

    self._vslvm_logical_volume = vslvm_volume_group.get_logical_volume(
        volume_index)

Opens the file-like object defined by path specification.

Args:
path_spec (PathSpec): path specification.
mode (Optional[str]): file access mode.

Raises:
AccessError: if the access to open the file was denied.
IOError: if the file-like object could not be opened.
OSError: if the file-like object could not be opened.
PathSpecError: if the path specification is incorrect.
ValueError: if the path specification is invalid.


def get_network_usage(access_token, subscription_id, location):

    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/providers/Microsoft.Network/locations/', location,
                        '/usages?api-version=', NETWORK_API])
    return do_get(endpoint, access_token)

List network usage and limits for a location.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
location (str): Azure data center location. E.g. westus.

Returns:
HTTP response. JSON body of network usage.


def rating(self, value):
    if (not self.can_update()):
        self._tcex.handle_error(910, [self.type])
    request_data = {'rating': value}
    return self.tc_requests.update(self.api_type, self.api_sub_type, self.unique_id, request_data, owner=self.owner)

Updates the Indicators rating

Args:
value:


def AddExtensionDescriptor(self, extension):

    if not (isinstance(extension, descriptor.FieldDescriptor) and
            extension.is_extension):
      raise TypeError('Expected an extension descriptor.')

    if extension.extension_scope is None:
      self._toplevel_extensions[extension.full_name] = extension

    try:
      existing_desc = self._extensions_by_number[
          extension.containing_type][extension.number]
    except KeyError:
      pass
    else:
      if extension is not existing_desc:
        raise AssertionError(
            'Extensions "%s" and "%s" both try to extend message type "%s" '
            'with field number %d.' %
            (extension.full_name, existing_desc.full_name,
             extension.containing_type.full_name, extension.number))

    self._extensions_by_number[extension.containing_type][
        extension.number] = extension
    self._extensions_by_name[extension.containing_type][
        extension.full_name] = extension

    if _IsMessageSetExtension(extension):
      self._extensions_by_name[extension.containing_type][
          extension.message_type.full_name] = extension

Adds a FieldDescriptor describing an extension to the pool.

Args:
extension: A FieldDescriptor.

Raises:
AssertionError: when another extension with the same number extends the
same message.
TypeError: when the specified extension is not a
descriptor.FieldDescriptor.


def add_to_tensor(self, mat, name='add_to_tensor'):
    with self._name_scope(name):
        multiplier_vector = array_ops.expand_dims(self.multiplier, -1)
        mat = tensor_conversion.convert_to_tensor_v2_with_dispatch(mat, name='mat')
        mat_diag = array_ops.matrix_diag_part(mat)
        new_diag = multiplier_vector + mat_diag
        return array_ops.matrix_set_diag(mat, new_diag)

Add matrix represented by this operator to `mat`.  Equiv to `I + mat`.

Args:
mat:  `Tensor` with same `dtype` and shape broadcastable to `self`.
name:  A name to give this `Op`.

Returns:
A `Tensor` with broadcast shape and same `dtype` as `self`.


def write_filter(script, filter_xml):

    if isinstance(script, mlx.FilterScript):
        script.filters.append(filter_xml)
    elif isinstance(script, str):
        script_file = open(script, 'a')
        script_file.write(filter_xml)
        script_file.close()
    else:
        print(filter_xml)
    return None

Write filter to FilterScript object or filename

Args:
script (FilterScript object or filename str): the FilterScript object
or script filename to write the filter to.
filter_xml (str): the xml filter string


def _GetOutputValues(self, event):

    if not hasattr(event, 'timestamp'):
      logger.error('Unable to output event without timestamp.')
      return None

    message, message_short = self._output_mediator.GetFormattedMessages(event)
    if message is None or message_short is None:
      data_type = getattr(event, 'data_type', 'UNKNOWN')
      raise errors.NoFormatterFound(
          'Unable to find event formatter for: {0:s}.'.format(data_type))

    source_short, source = self._output_mediator.GetFormattedSources(event)
    if source is None or source_short is None:
      data_type = getattr(event, 'data_type', 'UNKNOWN')
      raise errors.NoFormatterFound(
          'Unable to find event formatter for: {0:s}.'.format(data_type))

    date_time = dfdatetime_posix_time.PosixTimeInMicroseconds(
        timestamp=event.timestamp)

    format_variables = self._output_mediator.GetFormatStringAttributeNames(
        event)
    if format_variables is None:
      data_type = getattr(event, 'data_type', 'UNKNOWN')
      raise errors.NoFormatterFound(
          'Unable to find event formatter for: {0:s}.'.format(data_type))

    extra_attributes = []
    for attribute_name, attribute_value in sorted(event.GetAttributes()):
      if (attribute_name in definitions.RESERVED_VARIABLE_NAMES or
          attribute_name in format_variables):
        continue

      extra_attributes.append(
          '{0:s}: {1!s}'.format(attribute_name, attribute_value))

    extra_attributes = '; '.join(extra_attributes)
    extra_attributes = extra_attributes.replace('\n', '-').replace('\r', '')

    inode = getattr(event, 'inode', None)
    if inode is None:
      if hasattr(event, 'pathspec') and hasattr(
          event.pathspec, 'image_inode'):
        inode = event.pathspec.image_inode
    if inode is None:
      inode = '-'

    hostname = self._FormatHostname(event)
    username = self._FormatUsername(event)

    notes = []
    note_string = getattr(event, 'notes', None)
    if note_string:
      notes.append(note_string)

    tag = getattr(event, 'tag', None)
    if tag:
      notes.extend(tag.labels)

    if not notes:
      notes.append('-')

    year, month, day_of_month = date_time.GetDate()
    hours, minutes, seconds = date_time.GetTimeOfDay()
    try:
      date_string = '{0:02d}/{1:02d}/{2:04d}'.format(month, day_of_month, year)
      time_string = '{0:02d}:{1:02d}:{2:02d}'.format(hours, minutes, seconds)
    except (TypeError, ValueError):
      self._ReportEventError(event, (
          'unable to copy timestamp: {0!s} to a human readable date and time. '
          'Defaulting to: "00/00/0000" "--:--:--"').format(event.timestamp))

      date_string = '00/00/0000'
      time_string = '--:--:--'

    output_values = [
        date_string,
        time_string,
        '{0!s}'.format(self._output_mediator.timezone),
        '....',
        source_short,
        source,
        '-',
        username,
        hostname,
        message_short,
        message,
        '2',
        getattr(event, 'display_name', '-'),
        '{0!s}'.format(inode),
        ' '.join(notes),
        getattr(event, 'parser', '-'),
        extra_attributes]

    return output_values

Retrieves output values.

Args:
event (EventObject): event.

Returns:
list[str]: output values or None if no timestamp was present in the event.

Raises:
NoFormatterFound: If no event formatter can be found to match the data
type in the event.


def find_files(paths, file_predicate):
    file_list = []
    for path in paths:
        p = abs_path(path)
        for dirPath, _, fileList in os.walk(p):
            for fname in fileList:
                name, ext = os.path.splitext(fname)
                if file_predicate(name, ext):
                    file_list.append((dirPath, name, ext))
    return file_list

Locate files whose names and extensions match the given predicate in
the specified directories.

Args:
paths: A list of directory paths where to find the files.
file_predicate: A function that returns True if the file name and
extension are desired.

Returns:
A list of files that match the predicate.


def get_course_duration(self, obj):
    duration = ((obj.end - obj.start) if (obj.start and obj.end) else None)
    if duration:
        return strfdelta(duration, '{W} weeks {D} days.')
    return ''

Get course's duration as a timedelta.

Arguments:
obj (CourseOverview): CourseOverview object

Returns:
(timedelta): Duration of a course.


def json(self, json):
    self._request.json = json
    self.add_matcher(matcher('JSONMatcher', json))

Defines the JSON body to match.

``json`` argument can be an JSON string, a JSON serializable
Python structure, such as a ``dict`` or ``list`` or it can be
a regular expression used to match the body.

Arguments:
json (str|dict|list|regex): body JSON to match.

Returns:
self: current Mock instance.


def get_lambda_function(lambda_function, flags=FLAGS.ALL, **conn):

    try:
        basestring
    except NameError as _:
        basestring = str

    if isinstance(lambda_function, basestring):
        lambda_function_arn = ARN(lambda_function)
        if lambda_function_arn.error:
            lambda_function = dict(FunctionName=lambda_function)
        else:
            lambda_function = dict(FunctionName=lambda_function_arn.name, FunctionArn=lambda_function)

    if 'FunctionArn' in lambda_function:
        lambda_function_arn = ARN(lambda_function['FunctionArn'])
        if not lambda_function_arn.error:
            if lambda_function_arn.account_number:
                conn['account_number'] = lambda_function_arn.account_number
            if lambda_function_arn.region:
                conn['region'] = lambda_function_arn.region

    return registry.build_out(flags, start_with=lambda_function, pass_datastructure=True, **conn)

Fully describes a lambda function.

Args:
lambda_function: Name, ARN, or dictionary of lambda function. If dictionary, should likely be the return value from list_functions. At a minimum, must contain a key titled 'FunctionName'.
flags: Flags describing which sections should be included in the return value. Default ALL

Returns:
dictionary describing the requested lambda function.


class MeanSquaredError(MeanMetricWrapper):

    def __init__(self, name='mean_squared_error', dtype=None):
        super(MeanSquaredError, self).__init__(mean_squared_error, name, dtype=dtype)

Computes the mean squared error between `y_true` and `y_pred`.

Args:
name: (Optional) string name of the metric instance.
dtype: (Optional) data type of the metric result.

Standalone usage:

>>> m = tf.keras.metrics.MeanSquaredError()
>>> m.update_state([[0, 1], [0, 0]], [[1, 1], [0, 0]])
>>> m.result().numpy()
0.25

>>> m.reset_state()
>>> m.update_state([[0, 1], [0, 0]], [[1, 1], [0, 0]],
...                sample_weight=[1, 0])
>>> m.result().numpy()
0.5

Usage with `compile()` API:

```python
model.compile(
optimizer='sgd',
loss='mse',
metrics=[tf.keras.metrics.MeanSquaredError()])
```


def fetch_committed_offsets(self, partitions):
    if (not partitions):
        return {}
    while True:
        self.ensure_coordinator_ready()
        future = self._send_offset_fetch_request(partitions)
        self._client.poll(future=future)
        if future.succeeded():
            return future.value
        if (not future.retriable()):
            raise future.exception
        time.sleep((self.config['retry_backoff_ms'] / 1000))

Fetch the current committed offsets for specified partitions

Arguments:
partitions (list of TopicPartition): partitions to fetch

Returns:
dict: {TopicPartition: OffsetAndMetadata}


def GetAutomountMap(self, since=None, location=None):
    if location is None:
        self.log.error('A location is required to retrieve an automount map!')
        raise error.EmptyMap
    automount_url = urljoin(self.conf['automount_base_url'], location)
    return AutomountUpdateGetter().GetUpdates(self, automount_url, since)

Return an automount map from this source.

Note that autmount maps are stored in multiple locations, thus we expect
a caller to provide a location.  We also follow the automount spec and
set our search scope to be 'one'.

Args:
location: Currently a string containing our search source, later we
may support hostname and additional parameters.
since: Get data only changed since this timestamp (inclusive) or None
for all data.

Returns:
instance of AutomountMap

Raises:
EmptyMap:


def GetEventTypeString(self, event_type):

    if 0 <= event_type < len(self._EVENT_TYPES):
      return self._EVENT_TYPES[event_type]
    return 'Unknown {0:d}'.format(event_type)

Retrieves a string representation of the event type.

Args:
event_type (int): event type.

Returns:
str: description of the event type.


def _get_depencency_var_name(self, dependency):

        for dep_path, var_name in self.dependencies:
            if dep_path == dependency:
                return var_name

Returns the variable name assigned to the given dependency or None if the dependency has
not yet been registered.

Args:
dependency (str): Thet dependency that needs to be imported.

Returns:
str or None


def MultiNotifyQueue(self, notifications, mutation_pool=None):

    extract_queue = lambda notification: notification.session_id.Queue()
    for queue, notifications in iteritems(
        collection.Group(notifications, extract_queue)):
      self._MultiNotifyQueue(queue, notifications, mutation_pool=mutation_pool)

This is the same as NotifyQueue but for several session_ids at once.

Args:
notifications: A list of notifications.
mutation_pool: A MutationPool object to schedule Notifications on.

Raises:
RuntimeError: An invalid session_id was passed.


def data_string_compare(db_data, user_data):
    db_data = ''.join(db_data.split())
    user_data = ''.join(user_data.split())
    if operator.eq(db_data, user_data):
        return True
    return False

Validate string removing all white space before comparison.

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

Returns:
bool: True if the data passed validation.


def IsFile(self):
    if (self._stat_object is None):
        self._stat_object = self._GetStat()
    if (self._stat_object is not None):
        self.entry_type = self._stat_object.type
    return (self.entry_type == definitions.FILE_ENTRY_TYPE_FILE)

Determines if the file entry is a file.

Returns:
bool: True if the file entry is a file.


def predict(self, X):
    return collections.deque(self.iter_predict(X), maxlen=1).pop()

Returns the predictions for ``X``.

Under the hood this method simply goes through the outputs of ``iter_predict`` and returns
the final one.

Arguments:
X (array-like or sparse matrix of shape (n_samples, n_features)): The input samples.
Sparse matrices are accepted only if they are supported by the weak model.

Returns:
array of shape (n_samples,) containing the predicted values.


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

Corresponds to IDD Field `depth_august_average_ground_temperature`

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

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


def distort_image(image, thread_id):

    with tf.name_scope("flip_horizontal"):

        image = tf.image.random_flip_left_right(image)

    color_ordering = thread_id % 2
    with tf.name_scope("distort_color"):

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

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

    return image

Perform random distortions on an image.
Args:
image: A float32 Tensor of shape [height, width, 3] with values in [0, 1).
thread_id: Preprocessing thread id used to select the ordering of color
distortions. There should be a multiple of 2 preprocessing threads.
Returns:````
distorted_image: A float32 Tensor of shape [height, width, 3] with values in
[0, 1].


def set_global_step(self, new_global_step, name=None):
    return gen_data_flow_ops.resource_accumulator_set_global_step(self._accumulator_ref, math_ops.cast(ops.convert_to_tensor(new_global_step), _dtypes.int64), name=name)

Sets the global time step of the accumulator.

The operation logs a warning if we attempt to set to a time step that is
lower than the accumulator's own time step.

Args:
new_global_step: Value of new time step. Can be a variable or a constant
name: Optional name for the operation.

Returns:
Operation that sets the accumulator's time step.


def _redirect_operation(self, operation_name: str, rhs: BuilderOperand) -> 'ColumnExpressionBuilder':
    if self._sealed:
        raise self._fhir_path_sealed_error(operation_name)
    operand = rhs.builder if isinstance(rhs, type(self)) else rhs
    result = getattr(self._builder, operation_name)(operand)
    return ColumnExpressionBuilder._wrap_any(self, result)

Redirects an operation to the expressions.Builder.

Args:
operation_name: The operation name as a string.
rhs: The right hand side operand of the operation.

Returns:
A ColumnExpressionBuilder, because the operation result from the
expressions.Builder is always the type of Builder.

Raises:
AttributeError: if the FHIR path in this class is already sealed.


def get_available_servers(self, **kwargs):
    uri = self._helper.build_uri_with_query_string(kwargs, '/available-servers')
    return self._helper.do_get(uri)

Retrieves the list of available servers.

Args:
enclosureGroupUri (str): The URI of the enclosure group associated with the resource.
serverHardwareTypeUri (str): The URI of the server hardware type associated with the resource.
profileUri (str): The URI of the server profile resource.
scopeUris (str): An expression to restrict the resources returned according to
the scopes to which they are assigned.
filter (list or str): A general filter/query string to narrow the list of items returned.
The default is no filter, all resources are returned.
Returns:
list: Available servers.


def site_specific_coordination_numbers( self ):

        specific_coordination_numbers = {}
        for site in self.sites:
            specific_coordination_numbers[ site.label ] = site.site_specific_neighbours()
        return specific_coordination_numbers

Returns a dictionary of coordination numbers for each site type.

Args:
None

Returns:
(Dict(Str:List(Int))) : Dictionary of coordination numbers for each site type, e.g.::

{ 'A' : [ 2, 4 ], 'B' : [ 2 ] }


def _convert_hdxobjects(self, hdxobjects):

        newhdxobjects = list()
        for hdxobject in hdxobjects:
            newhdxobjects.append(hdxobject.data)
        return newhdxobjects

Helper function to convert supplied list of HDX objects to a list of dict

Args:
hdxobjects (List[T <= HDXObject]): List of HDX objects to convert

Returns:
List[Dict]: List of HDX objects converted to simple dictionaries


def stat(self, path=None, client_kwargs=None, header=None):
    stat = OrderedDict((('st_mode', 0), ('st_ino', 0), ('st_dev', 0), ('st_nlink', 0), ('st_uid', 0), ('st_gid', 0), ('st_size', 0), ('st_atime', 0), ('st_mtime', 0), ('st_ctime', 0)))
    header = self.head(path, client_kwargs, header)
    for (key, method) in (('st_size', self._getsize_from_header), ('st_ctime', self._getctime_from_header), ('st_mtime', self._getmtime_from_header)):
        try:
            stat[key] = int(method(header))
        except UnsupportedOperation:
            continue
    if self.islink(path=path, header=header):
        stat['st_mode'] = S_IFLNK
    elif (((not path) or (path[(- 1)] == '/') or self.is_locator(path)) and (not stat['st_size'])):
        stat['st_mode'] = S_IFDIR
    else:
        stat['st_mode'] = S_IFREG
    sub = self._CHAR_FILTER.sub
    for (key, value) in tuple(header.items()):
        stat[('st_' + sub('', key.lower()))] = value
    stat_result = namedtuple('stat_result', tuple(stat))
    stat_result.__name__ = 'os.stat_result'
    stat_result.__module__ = 'pycosio'
    return stat_result(**stat)

Get the status of an object.

Args:
path (str): File path or URL.
client_kwargs (dict): Client arguments.
header (dict): Object header.

Returns:
os.stat_result: Stat result object


def __init__(self, min_value=None, max_value=None):

    if not isinstance(min_value, float):
      raise TypeError("min_value must be a float: %r" % (min_value,))
    if not isinstance(max_value, float):
      raise TypeError("max_value must be a float: %r" % (max_value,))
    if min_value > max_value:
      raise ValueError("%r > %r" % (min_value, max_value))
    self._min_value = min_value
    self._max_value = max_value

Create a `RealInterval`.

Args:
min_value: The lower bound (inclusive) of the interval.
max_value: The upper bound (inclusive) of the interval.

Raises:
TypeError: If `min_value` or `max_value` is not an `float`.
ValueError: If `min_value > max_value`.


def _SimpleDecoder(wire_type, decode_value):

    def SpecificDecoder(field_number, is_repeated, is_packed, key, new_default):
        if is_packed:
            local_DecodeVarint = _DecodeVarint

            def DecodePackedField(buffer, pos, end, message, field_dict):
                value = field_dict.get(key)
                if (value is None):
                    value = field_dict.setdefault(key, new_default(message))
                (endpoint, pos) = local_DecodeVarint(buffer, pos)
                endpoint += pos
                if (endpoint > end):
                    raise _DecodeError('Truncated message.')
                while (pos < endpoint):
                    (element, pos) = decode_value(buffer, pos)
                    value.append(element)
                if (pos > endpoint):
                    del value[(- 1)]
                    raise _DecodeError('Packed element was truncated.')
                return pos
            return DecodePackedField
        elif is_repeated:
            tag_bytes = encoder.TagBytes(field_number, wire_type)
            tag_len = len(tag_bytes)

            def DecodeRepeatedField(buffer, pos, end, message, field_dict):
                value = field_dict.get(key)
                if (value is None):
                    value = field_dict.setdefault(key, new_default(message))
                while 1:
                    (element, new_pos) = decode_value(buffer, pos)
                    value.append(element)
                    pos = (new_pos + tag_len)
                    if ((buffer[new_pos:pos] != tag_bytes) or (new_pos >= end)):
                        if (new_pos > end):
                            raise _DecodeError('Truncated message.')
                        return new_pos
            return DecodeRepeatedField
        else:

            def DecodeField(buffer, pos, end, message, field_dict):
                (field_dict[key], pos) = decode_value(buffer, pos)
                if (pos > end):
                    del field_dict[key]
                    raise _DecodeError('Truncated message.')
                return pos
            return DecodeField
    return SpecificDecoder

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

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


def token_to_word(self, batch_or_token_index: int, token_index: Optional[int]=None) -> int:
    if not self._encodings:
        raise ValueError('token_to_word() is not available when using Python based tokenizers')
    if token_index is not None:
        batch_index = batch_or_token_index
    else:
        batch_index = 0
        token_index = batch_or_token_index
    if batch_index < 0:
        batch_index = self._batch_size + batch_index
    if token_index < 0:
        token_index = self._seq_len + token_index
    return self._encodings[batch_index].token_to_word(token_index)

Get the index of the word corresponding (i.e. comprising) to an encoded token in a sequence of the batch.

Can be called as:

- `self.token_to_word(token_index)` if batch size is 1
- `self.token_to_word(batch_index, token_index)` if batch size is greater than 1

This method is particularly suited when the input sequences are provided as pre-tokenized sequences (i.e.,
words are defined by the user). In this case it allows to easily associate encoded tokens with provided
tokenized words.

Args:
batch_or_token_index (`int`):
Index of the sequence in the batch. If the batch only comprise one sequence, this can be the index of
the token in the sequence.
token_index (`int`, *optional*):
If a batch index is provided in *batch_or_token_index*, this can be the index of the token in the
sequence.

Returns:
`int`: Index of the word in the input sequence.


def _send_http_request(self, xml_request):

        headers = {"Host": self._host, "Content-Type": "text/xml", "Recipient": self._storage}
        try:
            self._connection.request("POST", self._selector_url, xml_request, headers)
            response = self._connection.getresponse()
        except (httplib.CannotSendRequest, httplib.BadStatusLine):
            Debug.warn("\nRestarting socket, resending message!")
            self._open_connection()
            self._connection.request("POST", self._selector_url, xml_request, headers)
            response = self._connection.getresponse()
        data = response.read()
        return data

Send a request via HTTP protocol.

Args:
xml_request -- A fully formed xml request string for the CPS.

Returns:
The raw xml response string.


class ThresholdFn(abc.ABC):

    def __init__(self, normal_label: int=DEFAULT_NORMAL_LABEL, outlier_label: int=DEFAULT_OUTLIER_LABEL, missing_label: int=DEFAULT_MISSING_LABEL):
        self._normal_label = normal_label
        self._outlier_label = outlier_label
        self._missing_label = missing_label

    @property
    @abc.abstractmethod
    def is_stateful(self) -> bool:

        raise NotImplementedError

    @property
    @abc.abstractmethod
    def threshold(self) -> Optional[float]:

        raise NotImplementedError

    @abc.abstractmethod
    def apply(self, score: Optional[float]) -> Optional[int]:

        raise NotImplementedError

An abstract base class for threshold functions.

Args:
normal_label: The integer label used to identify normal data. Defaults to 0.
outlier_label: The integer label used to identify outlier data. Defaults to
1.
missing_label: The integer label used when a score is missing because the
model is not ready to score.


def _record_purchase(sailthru_client, email, item, purchase_incomplete, message_id, options):
    try:
        sailthru_response = sailthru_client.purchase(email, [item], incomplete=purchase_incomplete, message_id=message_id, options=options)
        if (not sailthru_response.is_ok()):
            error = sailthru_response.get_error()
            logger.error('Error attempting to record purchase in Sailthru: %s', error.get_message())
            return (not can_retry_sailthru_request(error))
    except SailthruClientError as exc:
        logger.exception('Exception attempting to record purchase for %s in Sailthru - %s', email, text_type(exc))
        return False
    return True

Record a purchase in Sailthru

Arguments:
sailthru_client (object): SailthruClient
email (str): user's email address
item (dict): Sailthru required information about the course
purchase_incomplete (boolean): True if adding item to shopping cart
message_id (str): Cookie used to identify marketing campaign
options (dict): Sailthru purchase API options (e.g. template name)

Returns:
False if retryable error, else True


def _parse_source_interface(self, config):
    match = re.search('vxlan source-interface ([^\\s]+)', config)
    value = (match.group(1) if match else self.DEFAULT_SRC_INTF)
    return dict(source_interface=value)

Parses the conf block and returns the vxlan source-interface value

Parses the provided configuration block and returns the value of
vxlan source-interface.  If the value is not configured, this method
will return DEFAULT_SRC_INTF instead.

Args:
config (str): The Vxlan config block to scan

Return:
dict: A dict object intended to be merged into the resource dict


def add_notice_to_docstring(doc, instructions, no_doc_str, suffix_str, notice, notice_type='Warning'):
    allowed_notice_types = ['Deprecated', 'Warning', 'Caution', 'Important', 'Note']
    if notice_type not in allowed_notice_types:
        raise ValueError(f'Unrecognized notice type. Should be one of: {allowed_notice_types}')
    if not doc:
        lines = [no_doc_str]
    else:
        lines = _normalize_docstring(doc).splitlines()
        lines[0] += ' ' + suffix_str
    if not notice:
        raise ValueError('The `notice` arg must not be empty.')
    notice[0] = f'{notice_type}: {notice[0]}'
    notice = [''] + notice + ([instructions] if instructions else [])
    if len(lines) > 1:
        if lines[1].strip():
            notice.append('')
        lines[1:1] = notice
    else:
        lines += notice
    return '\n'.join(lines)

Adds a deprecation notice to a docstring.

Args:
doc: The original docstring.
instructions: A string, describing how to fix the problem.
no_doc_str: The default value to use for `doc` if `doc` is empty.
suffix_str: Is added to the end of the first line.
notice: A list of strings. The main notice warning body.
notice_type: The type of notice to use. Should be one of `[Caution,
Deprecated, Important, Note, Warning]`

Returns:
A new docstring, with the notice attached.

Raises:
ValueError: If `notice` is empty.


def load(steps, reload=False):

    if reload:
        _STEP_CACHE.clear()

    if callable(steps):
        steps = steps()

    if not isinstance(steps, collections.Iterable):
        return load([steps])[0]

    loaded = []
    for s in steps:
        digest = s._digest
        if digest in _STEP_CACHE:
            loaded.append(_STEP_CACHE[digest])
        else:
            try:
                s.load()
                _STEP_CACHE[digest] = s
                loaded.append(s)
            except(Exception):
                logging.warn('Error during step load:\n%s' %
                             util.indent(traceback.format_exc()))

    return loaded

safely load steps in place, excluding those that fail
Args:
steps: the steps to load


def _add_dependency(self, dependency, var_name=None):

        if var_name is None:
            var_name = next(self.temp_var_names)

        if (dependency, var_name) not in self.dependencies:
            self.dependencies.append((dependency, var_name))
        return var_name

Adds the given dependency and returns the variable name to use to access it. If `var_name`
is not given then a random one will be created.

Args:
dependency (str):
var_name (str, optional):

Returns:
str


def DownloadAccount(self, next_page_token=None, max_results=None):

    param = {}
    if next_page_token:
      param['nextPageToken'] = next_page_token
    if max_results:
      param['maxResults'] = max_results
    response = self._InvokeGitkitApi('downloadAccount', param)

    return response.get('nextPageToken', None), response.get('users', {})

Downloads multiple accounts from Gitkit server.

Args:
next_page_token: string, pagination token.
max_results: pagination size.

Returns:
An array of accounts.


def modname_to_relpath(modname, project_root=None, add_init=True):
    parts = modname.split('.')
    relpath = pathlib.Path(*parts)
    if (project_root is not None):
        relpath_resolved = pathlib.Path(project_root).joinpath(relpath)
    else:
        relpath_resolved = relpath
    if relpath_resolved.is_dir():
        if add_init:
            relpath = relpath.joinpath('__init__.py')
    else:
        relpath = (str(relpath) + '.py')
    return str(relpath)

Convert module name to relative path.

The project root is usually needed to detect if the module is a package, in
which case the relevant file is the `__init__.py` within the subdirectory.

Example:
>>> modname_to_relpath('foo.features')
'foo/features.py'
>>> modname_to_relpath('foo.features',
project_root='/path/to/project')
'foo/features/__init__.py'

Args:
modname (str): Module name, e.g. `os.path`
project_root (str): Path to project root
add_init (bool): Whether to add `__init__.py` to the path of modules
that are packages. Defaults to True

Returns:
str


def on_binlog(event, stream):
    (rows, meta) = _rows_event_to_dict(event, stream)
    table_name = ('%s.%s' % (meta['schema'], meta['table']))
    if (meta['action'] == 'insert'):
        sig = signals.rows_inserted
    elif (meta['action'] == 'update'):
        sig = signals.rows_updated
    elif (meta['action'] == 'delete'):
        sig = signals.rows_deleted
    else:
        raise RuntimeError(('Invalid action "%s"' % meta['action']))
    sig.send(table_name, rows=rows, meta=meta)

Process on a binlog event

1. Convert event instance into a dict
2. Send corresponding schema/table/signals

Args:
event (pymysqlreplication.row_event.RowsEvent): the event


def _get_sqlite_columns(connection, table):
    SQL_TO_PYTHON_TYPES = {'INT': int, 'INTEGER': int, 'TINYINT': int, 'SMALLINT': int, 'MEDIUMINT': int, 'BIGINT': int, 'UNSIGNED BIG INT': int, 'INT': int, 'INT8': int, 'NUMERIC': float, 'REAL': float, 'FLOAT': float, 'DOUBLE': float, 'BOOLEAN': bool, 'CHARACTER': str, 'VARCHAR': str, 'TEXT': str}
    query = "PRAGMA table_info('{}');"
    result = connection.execute(query.format(table))
    ret = []
    for row in result:
        position = (row[0] + 1)
        name = row[1]
        datatype = row[2]
        try:
            datatype = SQL_TO_PYTHON_TYPES[datatype]
        except KeyError:
            raise Exception('Do not know how to convert {} sql datatype to python data type.'.format(datatype))
        ret.append((name, datatype, position))
    return ret

Returns list of tuple containg columns of the table.

Args:
connection: sqlalchemy connection to sqlite database.
table (str): name of the table

Returns:
list of (name, datatype, position): where name is column name, datatype is
python type of the column, position is ordinal position of the column.


def _EvaluateNumberOfElements(self, context):

    number_of_elements = None
    if self._data_type_definition.number_of_elements:
      number_of_elements = self._data_type_definition.number_of_elements

    elif self._data_type_definition.number_of_elements_expression:
      expression = self._data_type_definition.number_of_elements_expression
      namespace = {}
      if context and context.values:
        namespace.update(context.values)

      namespace['__builtins__'] = {}

      try:
        number_of_elements = eval(expression, namespace)
      except Exception as exception:
        raise errors.MappingError(
            'Unable to determine number of elements with error: {0!s}'.format(
                exception))

    if number_of_elements is None or number_of_elements < 0:
      raise errors.MappingError(
          'Invalid number of elements: {0!s}'.format(number_of_elements))

    return number_of_elements

Evaluates number of elements.

Args:
context (DataTypeMapContext): data type map context.

Returns:
int: number of elements.

Raises:
MappingError: if the number of elements cannot be determined.


def check_updates(transformers, datastore=None, stimuli=None):
    datastore = (datastore or expanduser('~/.pliers_updates'))
    prior_data = (pd.read_csv(datastore) if exists(datastore) else None)
    stimuli = (stimuli or glob.glob(join(dirname(realpath(__file__)), '../tests/data/image/CC0/*')))
    stimuli = load_stims(stimuli)
    loaded_transformers = {get_transformer(name, **params): (name, params) for (name, params) in transformers}
    results = pd.DataFrame({'time_extracted': [datetime.datetime.now()]})
    for trans in loaded_transformers.keys():
        for stim in stimuli:
            if trans._stim_matches_input_types(stim):
                res = trans.transform(stim)
                try:
                    res = [getattr(res, '_data', res.data) for r in res]
                except TypeError:
                    res = getattr(res, '_data', res.data)
                res = hash_data(res)
                results['{}.{}'.format(trans.__hash__(), stim.name)] = [res]
    mismatches = []
    if (prior_data is not None):
        last = prior_data[(prior_data.time_extracted == prior_data.time_extracted.max())].iloc[0].drop('time_extracted')
        for (label, value) in results.iteritems():
            old = last.get(label)
            new = value.values[0]
            if (old is not None):
                if isinstance(new, str):
                    if (new != old):
                        mismatches.append(label)
                elif (not np.isclose(old, new)):
                    mismatches.append(label)
        results = prior_data.append(results)
    results.to_csv(datastore, index=False)

    def get_trans(hash_tr):
        for (obj, attr) in loaded_transformers.items():
            if (str(obj.__hash__()) == hash_tr):
                return attr
    delta_t = set([m.split('.')[0] for m in mismatches])
    delta_t = [get_trans(dt) for dt in delta_t]
    return {'transformers': delta_t, 'mismatches': mismatches}

Run transformers through a battery of stimuli, and check if output has
changed. Store results in csv file for comparison.

Args:
transformers (list): A list of tuples of transformer names and
dictionary of parameters to instantiate with (or empty dict).
datastore (str): Filepath of CSV file with results. Stored in home dir
by default.
stimuli (list): List of stimuli file paths to extract from. If None,
use test data.


def get_text(html: str) -> str:
    text_content_extractor = TextContentExtractor()
    text_content_extractor.feed(html)
    return text_content_extractor.output

Gets the text content from the input HTML string.

Args:
html (str): Input HTML string.

Returns:
The text content.


def _create_and_save_vocab_table_lookup_model_tf1(self, output_path: str, tags: Collection[str], signature_def_key: str) -> Tuple[Mapping[str, core.Tensor], Mapping[str, core.Tensor]]:
    with session.Session(graph=ops.Graph()) as sess:
        input_vocabs_placeholder, lookup_tensor, output_tensor = self._create_vocab_table_lookup_model_tf1(sess)
        inputs = {'input_vocabs': input_vocabs_placeholder}
        outputs = {'lookup': lookup_tensor, 'output': output_tensor}
        self._save_tf1_model(sess, output_path, signature_def_key, tags, inputs=inputs, outputs=outputs, init_op=lookup_ops.tables_initializer(), assets_collection=ops.get_collection(ops.GraphKeys.ASSET_FILEPATHS))
    return (inputs, outputs)

Creates and saves a simple model that uses a vocab table.

Args:
output_path: Path to the directory to save the created model.
tags: Set of strings that identifies the saved meta graph.
signature_def_key: Name of the SignatureDef. Used to identify the
SignatureDef within the meta graph.

Returns:
inputs: A mapping of input_key -> input_tensor (placeholder). The input
key is "input_vocabs".
outputs: A mapping of output_key -> output_tensor. The output keys are
"lookup" and "output".


def size(self, time):

        if self.start_time <= time <= self.end_time:
            return self.masks[time - self.start_time].sum()
        else:
            return 0

Gets the size of the object at a given time.

Args:
time: Time value being queried.

Returns:
size of the object in pixels


def get_by(self, field, value):
    return self._client.get_by(field=field, value=value)

Gets all drive enclosures that match the filter.

The search is case-insensitive.

Args:
Field: field name to filter.
Value: value to filter.

Returns:
list: A list of drive enclosures.


def _verify_output_dir(output_dir: Optional[str], overwrite: bool) -> None:
    dir_not_empty = output_dir is not None and file_io.file_exists_v2(output_dir) and file_io.list_directory_v2(output_dir)
    if dir_not_empty and (not overwrite):
        raise FileExistsError(f'Output directory already exists: {output_dir} . Please set overwrite_output_directory to true to overwrite the existing directory.')

Verifies the output directory.

Raises an error if `output_dir` is not suitable for writing the output saved
model.

Args:
output_dir: Output directory.
overwrite: An option allowing to overwrite the existing output directory if
set to true. Does not actually create or modify the `output_dir` in this
function.

Raises:
FileExistsError: Iff `output_dir` is not empty and `overwrite` is false.


def to_csv(self, sep=',', path=None):

        data = []
        first_row = ['Stat']
        first_row.extend(self._names)
        data.append(sep.join(first_row))

        stats = self._stats()

        for stat in stats:
            k, n, f = stat

            if k is None:
                row = [''] * len(data[0])
                data.append(sep.join(row))
                continue

            row = [n]
            for key in self._names:
                raw = getattr(self[key], k)
                if f is None:
                    row.append(raw)
                elif f == 'p':
                    row.append(fmtp(raw))
                elif f == 'n':
                    row.append(fmtn(raw))
                elif f == 'dt':
                    row.append(raw.strftime('%Y-%m-%d'))
                else:
                    raise NotImplementedError('unsupported format %s' % f)
            data.append(sep.join(row))

        res = '\n'.join(data)

        if path is not None:
            with open(path, 'w') as fl:
                fl.write(res)
        else:
            return res

Returns a CSV string with appropriate formatting.
If path is not None, the string will be saved to file
at path.

Args:
* sep (char): Separator
* path (str): If None, CSV string returned. Else file
written to specified path.


def random(self, pages=1):

        if pages is None or pages < 1:
            raise ValueError("Number of pages must be greater than 0")

        query_params = {"list": "random", "rnnamespace": 0, "rnlimit": pages}

        request = self.wiki_request(query_params)
        titles = [page["title"] for page in request["query"]["random"]]

        if len(titles) == 1:
            return titles[0]
        return titles

Request a random page title or list of random titles

Args:
pages (int): Number of random pages to return
Returns:
list or int: A list of random page titles or a random page \
title if pages = 1


def pst_from_parnames_obsnames(parnames, obsnames,
                               tplfilename='model.input.tpl', insfilename='model.output.ins'):

    simple_tpl_from_pars(parnames, tplfilename)
    simple_ins_from_obs(obsnames, insfilename)

    modelinputfilename = tplfilename.replace('.tpl','')
    modeloutputfilename = insfilename.replace('.ins','')

    return pyemu.Pst.from_io_files(tplfilename, modelinputfilename, insfilename, modeloutputfilename)

Creates a Pst object from a list of parameter names and a list of observation names.
Default values are provided for the TPL and INS
Args:
parnames: list of names from which to make a template file
obsnames: list of obsnames to read in
tplfilename: filename for TPL file (default: model.input.tpl)
insfilename: filename for INS file (default: model.output.ins)

Returns:
Pst object


def price(self, valuation_date, market, model=None, pricing_context=None, name=None):
    name = name or self._name + '_price'
    with tf.name_scope(name):
        valuation_date = dates.convert_to_date_tensor(valuation_date)
        discount_curve = market.discount_curve
        past_fixing = rc.get_rate_index(market, self._start_date, rc.RateIndexType.SWAP, dtype=self._dtype)
        past_fixing = tf.repeat(tf.convert_to_tensor(past_fixing, dtype=self._dtype), self._num_cashflows)
        discount_factors = discount_curve.get_discount_factor(self._payment_dates)
        cms_rates = self._swap.par_rate(valuation_date, market, model)
        cms_rates = tf.where(self._daycount_fractions > 0.0, cms_rates, tf.zeros_like(cms_rates))
        cms_rates = tf.where(self._coupon_end_dates < valuation_date, tf.constant(0.0, dtype=self._dtype), tf.where(self._coupon_start_dates < valuation_date, past_fixing, cms_rates))
        cms_rates = self._adjust_convexity(valuation_date, market, model, pricing_context, cms_rates, discount_factors)
        coupon_rate = self._coupon_multiplier * (cms_rates + self._coupon_basis)
        cashflow_pvs = self._notional * (self._daycount_fractions * coupon_rate * discount_factors)
        return tf.math.segment_sum(cashflow_pvs, self._contract_index)

Returns the present value of the stream on the valuation date.

Args:
valuation_date: A scalar `DateTensor` specifying the date on which
valuation is being desired.
market: A namedtuple of type `InterestRateMarket` which contains the
necessary information for pricing the cashflow stream.
model: An optional input of type `InterestRateModelType` to specify which
model to use for pricing.
Default value: `None` in which case `NORMAL_RATE` model is used.
pricing_context: An optional input to provide additional parameters (such
as model parameters) relevant for pricing.
name: Python str. The name to give to the ops created by this function.
Default value: `None` which maps to 'price'.

Returns:
A Rank 1 `Tensor` of real type containing the modeled price of each stream
contract based on the input market data.


def _CopyFileObjectToTemporaryFile(self, file_object, temporary_file):

    file_object.seek(0, os.SEEK_SET)
    data = file_object.read(self._READ_BUFFER_SIZE)
    while data:
      temporary_file.write(data)
      data = file_object.read(self._READ_BUFFER_SIZE)

Copies the contents of the file-like object to a temporary file.

Args:
file_object (dfvfs.FileIO): file-like object.
temporary_file (file): temporary file.


def add(self, decorations):

        added = 0
        if isinstance(decorations, list):
            not_repeated = set(decorations) - set(self._decorations)
            self._decorations.extend(list(not_repeated))
            added = len(not_repeated)
        elif decorations not in self._decorations:
            self._decorations.append(decorations)
            added = 1

        if added > 0:
            self._order_decorations()
            self.update()
        return added

Add text decorations on a CodeEditor instance.

Don't add duplicated decorations, and order decorations according
draw_order and the size of the selection.

Args:
decorations (sourcecode.api.TextDecoration) (could be a list)
Returns:
int: Amount of decorations added.


def __init__(self, modl, name, info, opts):

        self.modl = modl
        self.name = name
        self.info = info
        self.form = None
        self.subof = None

        self.opts = dict(self._opt_defs)
        self.opts.update(opts)

        self._type_norms = {}
        self._cmpr_ctors = {}
        self._cmpr_ctor_lift = {}

        self.indxcmpr = {
            '=': self.indxByEq,
            '*in=': self.indxByIn,
            '*range=': self.indxByRange,
        }

        self.setCmprCtor('=', self._ctorCmprEq)
        self.setCmprCtor('!=', self._ctorCmprNe)
        self.setCmprCtor('~=', self._ctorCmprRe)
        self.setCmprCtor('^=', self._ctorCmprPref)
        self.setCmprCtor('*in=', self._ctorCmprIn)
        self.setCmprCtor('*range=', self._ctorCmprRange)

        self.setNormFunc(s_node.Node, self._normStormNode)

        self.postTypeInit()

Construct a new Type object.

Args:
modl (synpase.datamodel.DataModel): The data model instance.
name (str): The name of the type.
info (dict): The type info (docs etc).
opts (dict): Options that are specific to the type.


def close(self, suppress_warning: bool=False) -> None:
    if (self._file is None):
        if (not suppress_warning):
            logging.warn('Connection to %s is already closed', self.filename)
    else:
        self._file.close()
        self._file = None
    self.layers = None
    self.ra = None
    self.row_attrs = None
    self.ca = None
    self.col_attrs = None
    self.row_graphs = None
    self.col_graphs = None
    self.shape = (0, 0)
    self._closed = True

Close the connection. After this, the connection object becomes invalid. Warns user if called after closing.

Args:
suppress_warning:		Suppresses warning message if True (defaults to false)


def sort(expr, field = None, keytype=None, ascending=True):

    weld_obj = WeldObject(encoder_, decoder_)

    expr_var = weld_obj.update(expr)
    if isinstance(expr, WeldObject):
        expr_var = expr.obj_id
        weld_obj.dependencies[expr_var] = expr

    if field is not None:
        key_str = "x.$%s" % field
    else:
        key_str = "x"

    if not ascending:

        key_str = key_str + "* %s(-1)" % keytype

    weld_template =
    weld_obj.weld_code = weld_template % {"expr":expr_var, "key":key_str}
    return weld_obj

Sorts the vector.
If the field parameter is provided then the sort
operators on a vector of structs where the sort key
is the field of the struct.

Args:
expr (WeldObject)
field (Int)


def index_of(self, file_path, function_name, function_start_line):
    function_key = (file_path, function_name, function_start_line)
    if function_key in self._function_key_to_function:
        return self._function_key_to_function[function_key].id
    else:
        function_index = len(self._function_key_to_function) + 1
        function = profile_pb2.Function()
        function.id = function_index
        function.name = self._string_table.index_of(function_name)
        function.filename = self._string_table.index_of(file_path)
        function.start_line = function_start_line
        self._function_key_to_function[function_key] = function
        return function_index

Returns index of the function, adding the function if needed.

Args:
file_path: (string) Path to file where the function is defined.
function_name: (string) Function name.
function_start_line: (integer) Start line number of function definition.

Returns:
Function index.


def delete(workflow_id: str=None, workflow_version: str=None):
    if ((workflow_id is None) and (workflow_version is None)):
        keys = DB.get_keys('workflow_definitions:*')
        DB.delete(*keys)
    elif ((workflow_id is not None) and (workflow_version is None)):
        keys = DB.get_keys('workflow_definitions:{}:*'.format(workflow_id))
        DB.delete(*keys)
    elif ((workflow_id is None) and (workflow_version is not None)):
        keys = DB.get_keys('workflow_definitions:*:{}'.format(workflow_version))
        DB.delete(*keys)
    else:
        name = 'workflow_definitions:{}:{}'.format(workflow_id, workflow_version)
        DB.delete(name)

Delete workflow definitions.

Args:
workflow_id (str, optional): Optional workflow identifier
workflow_version (str, optional): Optional workflow identifier version

If workflow_id and workflow_version are None, delete all workflow
definitions.


def get_log_line_timestamp(delta=None):
    return _get_timestamp('%m-%d %H:%M:%S.%f', delta)

Returns a timestamp in the format used by log lines.

Default is current time. If a delta is set, the return value will be
the current time offset by delta seconds.

Args:
delta: Number of seconds to offset from current time; can be negative.

Returns:
A timestamp in log line format with an offset.


def _is_hostmask(self, ip_str):

        bits = ip_str.split('.')
        try:
            parts = [x for x in map(int, bits) if x in self._valid_mask_octets]
        except ValueError:
            return False
        if len(parts) != len(bits):
            return False
        if parts[0] < parts[-1]:
            return True
        return False

Test if the IP string is a hostmask (rather than a netmask).

Args:
ip_str: A string, the potential hostmask.

Returns:
A boolean, True if the IP string is a hostmask.


def _ReadDataTypeDefinitionWithMembers(self, definitions_registry, definition_values, data_type_definition_class, definition_name, supports_conditions=False):
    members = definition_values.get('members', None)
    if (not members):
        error_message = 'missing members'
        raise errors.DefinitionReaderError(definition_name, error_message)
    supported_definition_values = self._SUPPORTED_DEFINITION_VALUES_STORAGE_DATA_TYPE_WITH_MEMBERS
    definition_object = self._ReadDataTypeDefinition(definitions_registry, definition_values, data_type_definition_class, definition_name, supported_definition_values)
    attributes = definition_values.get('attributes', None)
    if attributes:
        unsupported_attributes = set(attributes.keys()).difference(self._SUPPORTED_ATTRIBUTES_STORAGE_DATA_TYPE)
        if unsupported_attributes:
            error_message = 'unsupported attributes: {0:s}'.format(', '.join(unsupported_attributes))
            raise errors.DefinitionReaderError(definition_name, error_message)
        byte_order = attributes.get('byte_order', definitions.BYTE_ORDER_NATIVE)
        if (byte_order not in definitions.BYTE_ORDERS):
            error_message = 'unsupported byte-order attribute: {0!s}'.format(byte_order)
            raise errors.DefinitionReaderError(definition_name, error_message)
        definition_object.byte_order = byte_order
    for member in members:
        section = member.get('section', None)
        if section:
            member_section_definition = data_types.MemberSectionDefinition(section)
            definition_object.AddSectionDefinition(member_section_definition)
        else:
            member_data_type_definition = self._ReadMemberDataTypeDefinitionMember(definitions_registry, member, definition_object.name, supports_conditions=supports_conditions)
            definition_object.AddMemberDefinition(member_data_type_definition)
    return definition_object

Reads a data type definition with members.

Args:
definitions_registry (DataTypeDefinitionsRegistry): data type definitions
registry.
definition_values (dict[str, object]): definition values.
data_type_definition_class (str): data type definition class.
definition_name (str): name of the definition.
supports_conditions (Optional[bool]): True if conditions are supported
by the data type definition.

Returns:
StringDefinition: string data type definition.

Raises:
DefinitionReaderError: if the definitions values are missing or if
the format is incorrect.


def _move_dims_to_flat_end(x, axis, x_ndims, right_end=True):

  if not axis:
    return x

  other_dims = sorted(set(range(x_ndims)).difference(axis))

  perm = other_dims + list(axis) if right_end else list(axis) + other_dims
  x_permed = tf.transpose(a=x, perm=perm)

  if x.shape.is_fully_defined():
    x_shape = x.shape.as_list()

    other_shape = [x_shape[i] for i in other_dims]
    end_shape = [np.prod([x_shape[i] for i in axis])]
    full_shape = (
        other_shape + end_shape if right_end else end_shape + other_shape)
  else:
    other_shape = tf.gather(tf.shape(input=x), other_dims)
    full_shape = tf.concat(
        [other_shape, [-1]] if right_end else [[-1], other_shape], axis=0)
  return tf.reshape(x_permed, shape=full_shape)

Move dims corresponding to `axis` in `x` to the end, then flatten.

Args:
x: `Tensor` with shape `[B0,B1,...,Bb]`.
axis:  Python list of indices into dimensions of `x`.
x_ndims:  Python integer holding number of dimensions in `x`.
right_end:  Python bool.  Whether to move dims to the right end (else left).

Returns:
`Tensor` with value from `x` and dims in `axis` moved to end into one single
dimension.


def find_effect_class(self, path) -> Type[Effect]:
    (package_name, class_name) = parse_package_string(path)
    if package_name:
        package = self.get_package(package_name)
        return package.find_effect_class(class_name, raise_for_error=True)
    for package in self.packages:
        effect_cls = package.find_effect_class(class_name)
        if effect_cls:
            return effect_cls
    raise EffectError("No effect class '{}' found in any packages".format(class_name))

Find an effect class by class name or full python path to class

Args:
path (str): effect class name or full python path to effect class

Returns:
Effect class

Raises:
EffectError if no class is found


def resolve_calls(func):
    node = quoting.parse_function(func)
    ResolveCalls(func).visit(node)
    return node

Parse a function into an AST with function calls resolved.

Since the calls are resolved using the global and local namespace of the
function it means that procedural parameters (i.e. functions passed as
arguments) won't be resolved.

Similarly, functions defined inside of the function that we are trying to
resolve won't be resolved, since they are not in the local namespace of the
outer function.

The function definition itself is also annotated, so that it can be matched
to calls to it in other functions.

Args:
func: The function whose calls are being resolved.

Returns:
node: An AST where each `Call` node has a `func` annotation with the
function handle that the call resolves to.

Raises:
AttributeError: When a function is used on the RHS of an assignment cannot
be resolved (because it was passed as an argument or was defined in the
body of the function).


def _get_ip_unnumbered(self, unnumbered_type, unnumbered_name):
    unnumbered_type = self._callback(unnumbered_type, handler='get_config')
    unnumbered_name = self._callback(unnumbered_name, handler='get_config')
    unnumbered_type = pynos.utilities.return_xml(str(unnumbered_type))
    unnumbered_name = pynos.utilities.return_xml(str(unnumbered_name))
    return pynos.utilities.merge_xml(unnumbered_type, unnumbered_name)

Get and merge the `ip unnumbered` config from an interface.

You should not use this method.
You probably want `Interface.ip_unnumbered`.

Args:
unnumbered_type: XML document with the XML to get the donor type.
unnumbered_name: XML document with the XML to get the donor name.

Returns:
Merged XML document.

Raises:
None


def readOutput(self, directory, projectFileName, session, spatial=False, spatialReferenceID=None):
    self.project_directory = directory
    with tmp_chdir(directory):
        session.add(self)
        self.read(directory, projectFileName, session, spatial, spatialReferenceID)
        batchDirectory = self._getBatchDirectory(directory)
        maskMap = WatershedMaskFile()
        maskMapFilename = self.getCard('WATERSHED_MASK').value.strip('"')
        maskMap.read(session=session, directory=directory, filename=maskMapFilename, spatial=spatial)
        maskMap.projectFile = self
        if (spatialReferenceID is None):
            spatialReferenceID = self._automaticallyDeriveSpatialReferenceId(directory)
        self._readXput(self.OUTPUT_FILES, batchDirectory, session, spatial=spatial, spatialReferenceID=spatialReferenceID)
        self._readWMSDatasets(self.WMS_DATASETS, batchDirectory, session, spatial=spatial, spatialReferenceID=spatialReferenceID)
        self._commit(session, self.COMMIT_ERROR_MESSAGE)

Read only output files for a GSSHA project to the database.

Use this method to read a project when only post-processing tasks need to be performed.

Args:
directory (str): Directory containing all GSSHA model files. This method assumes that all files are located
in the same directory.
projectFileName (str): Name of the project file for the GSSHA model which will be read (e.g.: 'example.prj').
session (:mod:`sqlalchemy.orm.session.Session`): SQLAlchemy session object bound to PostGIS enabled database
spatial (bool, optional): If True, spatially enabled objects will be read in as PostGIS spatial objects.
Defaults to False.
spatialReferenceID (int, optional): Integer id of spatial reference system for the model. If no id is
provided GsshaPy will attempt to automatically lookup the spatial reference ID. If this process fails,
default srid will be used (4326 for WGS 84).


def ToScriptHash(self, address):
    if (len(address) == 34):
        if (address[0] == 'A'):
            data = b58decode(address)
            if (data[0] != self.AddressVersion):
                raise ValueError('Not correct Coin Version')
            checksum = Crypto.Default().Hash256(data[:21])[:4]
            if (checksum != data[21:]):
                raise Exception('Address format error')
            return UInt160(data=data[1:21])
        else:
            raise Exception('Address format error')
    else:
        raise ValueError('Not correct Address, wrong length.')

Retrieve the script_hash based from an address.

Args:
address (str): a base58 encoded address.

Raises:
ValuesError: if an invalid address is supplied or the coin version is incorrect
Exception: if the address string does not start with 'A' or the checksum fails

Returns:
UInt160: script hash.


def write_image(self, stream, image_format="svg", **kwargs):

        plt = self.get_plot(**kwargs)

        f = plt.gcf()
        f.set_size_inches((12, 10))

        plt.savefig(stream, format=image_format)

Writes the phase diagram to an image in a stream.

Args:
stream:
stream to write to. Can be a file stream or a StringIO stream.
image_format
format for image. Can be any of matplotlib supported formats.
Defaults to svg for best results for vector graphics.
\\*\\*kwargs: Pass through to get_plot functino.


def __call__(self, shape, dtype=None, **kwargs):
    _validate_kwargs(self.__class__.__name__, kwargs, support_partition=False)
    dtype = _assert_float_dtype(_get_dtype(dtype))
    if len(shape) != 2:
        raise ValueError('Identity matrix initializer can only be used for 2D matrices.')
    initializer = linalg_ops.eye(*shape, dtype=dtype)
    return self.gain * initializer

Returns a tensor object initialized to a 2D identity matrix.

Args:
shape: Shape of the tensor. It should have exactly rank 2.
dtype: Optional dtype of the tensor. Only floating point types are
supported. If not specified, `tf.keras.backend.floatx()` is used,
which default to `float32` unless you configured it otherwise
(via `tf.keras.backend.set_floatx(float_dtype)`)
**kwargs: Additional keyword arguments.


def start_vm(access_token, subscription_id, resource_group, vm_name):

    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/resourceGroups/', resource_group,
                        '/providers/Microsoft.Compute/virtualMachines/',
                        vm_name,
                        '/start',
                        '?api-version=', COMP_API])
    return do_post(endpoint, '', access_token)

Start a virtual machine.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
vm_name (str): Name of the virtual machine.

Returns:
HTTP response.


def UpdateClass(self, class_name, gtfs_class):
    if (class_name not in self._class_mapping):
        raise problems.NonexistentMapping(class_name)
    self._class_mapping[class_name] = gtfs_class

Updates an entry in the list of known classes.

Args:
class_name: A string with the class name that is to be updated.
gtfs_class: The new class
Raises:
NonexistentMapping if there is no class with the specified class_name.


def error(self, error_msg):

        if self.logger is not None:
            self.logger.error(error_msg)

        if self.exc is not None:
            raise self.exc(error_msg)

Outputs error message on own logger. Also raises exceptions if need be.

Args:
error_msg: message to output


def projection_name(self, **kwargs: Dict[str, Any]) -> str:

        return self.projection_name_format.format(**kwargs)

Define the projection name for this projector.

Note:
This function is just a basic placeholder and likely should be overridden.

Args:
kwargs: Projection information dict combined with additional arguments passed to the
projection function.
Returns:
Projection name string formatted with the passed options. By default, it returns
``projection_name_format`` formatted with the arguments to this function.


def from_datetime(dt, machine_id=0):

        td = dt - Timestamp._EPOCH
        seconds = td.days * 3600 * 24
        seconds += td.seconds
        return Timestamp(seconds, td.microseconds*1000, machine_id)

Convert a datetime to an SPL `Timestamp`.

Args:
dt(datetime.datetime): Datetime to be converted.
machine_id(int): Machine identifier.

Returns:
Timestamp: Datetime converted to Timestamp.


def _construct_operation_id(self, service_name, protorpc_method_name):
    method_name_camel = util.snake_case_to_headless_camel_case(protorpc_method_name)
    return '{0}_{1}'.format(service_name, method_name_camel)

Return an operation id for a service method.

Args:
service_name: The name of the service.
protorpc_method_name: The ProtoRPC method name.

Returns:
A string representing the operation id.


def _add_loss_summaries(total_loss):
    loss_averages = tf.train.ExponentialMovingAverage(0.9, name='avg')
    losses = tf.get_collection('losses')
    loss_averages_op = loss_averages.apply((losses + [total_loss]))
    for l in (losses + [total_loss]):
        tf.summary.scalar((l.op.name + ' (raw)'), l)
        tf.summary.scalar(l.op.name, loss_averages.average(l))
    return loss_averages_op

Add summaries for losses in CIFAR-10 model.

Generates moving average for all losses and associated summaries for
visualizing the performance of the network.

Args:
total_loss: Total loss from loss().
Returns:
loss_averages_op: op for generating moving averages of losses.


def trace_set_format(self, fmt):
    cmd = enums.JLinkTraceCommand.SET_FORMAT
    data = ctypes.c_uint32(fmt)
    res = self._dll.JLINKARM_TRACE_Control(cmd, ctypes.byref(data))
    if (res == 1):
        raise errors.JLinkException('Failed to set trace format.')
    return None

Sets the format for the trace buffer to use.

Args:
self (JLink): the ``JLink`` instance.
fmt (int): format for the trace buffer; this is one of the attributes
of ``JLinkTraceFormat``.

Returns:
``None``


def grid_deploy(site, nodes, options):
    gk = get_api_client()
    environment = options.pop('env_name')
    options.update(environment=environment)
    options.update(nodes=nodes)
    key_path = DEFAULT_SSH_KEYFILE
    options.update(key=key_path.read_text())
    logger.info(('Deploying %s with options %s' % (nodes, options)))
    deployment = gk.sites[site].deployments.create(options)
    while (deployment.status not in ['terminated', 'error']):
        deployment.refresh()
        print(('Waiting for the end of deployment [%s]' % deployment.uid))
        time.sleep(10)
    deploy = []
    undeploy = []
    if (deployment.status == 'terminated'):
        deploy = [node for (node, v) in deployment.result.items() if (v['state'] == 'OK')]
        undeploy = [node for (node, v) in deployment.result.items() if (v['state'] == 'KO')]
    elif (deployment.status == 'error'):
        undeploy = nodes
    return (deploy, undeploy)

Deploy and wait for the deployment to be finished.

Args:
site(str): the site
nodes(list): list of nodes (str) to depoy
options(dict): option of the deployment (refer to the Grid'5000 API
Specifications)

Returns:
tuple of deployed(list), undeployed(list) nodes.


async def disconnect(self, client_id, conn_string):
    conn_id = self._client_connection(client_id, conn_string)
    try:
        (await self.adapter.disconnect(conn_id))
    finally:
        self._hook_disconnect(conn_string, client_id)

Disconnect from a device on behalf of a client.

See :meth:`AbstractDeviceAdapter.disconnect`.

Args:
client_id (str): The client we are working for.
conn_string (str): A connection string that will be
passed to the underlying device adapter to connect.

Raises:
DeviceServerError: There is an issue with your client_id such
as not being connected to the device.
DeviceAdapterError: The adapter had an issue disconnecting.


def get_coordination_numbers(d):
    structure = Structure.from_dict(d['output']['crystal'])
    f = VoronoiNN()
    cn = []
    for (i, s) in enumerate(structure.sites):
        try:
            n = f.get_cn(structure, i)
            number = int(round(n))
            cn.append({'site': s.as_dict(), 'coordination': number})
        except Exception:
            logger.error('Unable to parse coordination errors')
    return cn

Helper method to get the coordination number of all sites in the final
structure from a run.

Args:
d:
Run dict generated by VaspToDbTaskDrone.

Returns:
Coordination numbers as a list of dict of [{"site": site_dict,
"coordination": number}, ...].


def Matches(self, registry_key, search_depth):

    if self._key_path_segments is None:
      key_path_match = None
    else:
      key_path_match = self._CheckKeyPath(registry_key, search_depth)
      if not key_path_match:
        return False, key_path_match

      if search_depth != self._number_of_key_path_segments:
        return False, key_path_match

    return True, key_path_match

Determines if the Windows Registry key matches the find specification.

Args:
registry_key (WinRegistryKey): Windows Registry key.
search_depth (int): number of key path segments to compare.

Returns:
tuple: contains:

bool: True if the Windows Registry key matches the find specification,
False otherwise.
bool: True if the key path matches, False if not or None if no key path
specified.


def d_step(self, true_frames, gen_frames):

    hparam_to_disc_loss = {
        "least_squares": gan_losses.least_squares_discriminator_loss,
        "cross_entropy": gan_losses.modified_discriminator_loss,
        "wasserstein": gan_losses.wasserstein_discriminator_loss}

    _, batch_size, _, _, _ = common_layers.shape_list(true_frames)
    all_frames = tf.concat(
        [true_frames, tf.stop_gradient(gen_frames)], axis=1)

    all_logits = self.discriminator(all_frames)
    true_logits, fake_logits_stop = \
      all_logits[:batch_size], all_logits[batch_size:]
    mean_true_logits = tf.reduce_mean(true_logits)
    tf.summary.scalar("mean_true_logits", mean_true_logits)

    mean_fake_logits_stop = tf.reduce_mean(fake_logits_stop)
    tf.summary.scalar("mean_fake_logits_stop", mean_fake_logits_stop)

    discriminator_loss_func = hparam_to_disc_loss[self.hparams.gan_loss]
    gan_d_loss = discriminator_loss_func(
        discriminator_real_outputs=true_logits,
        discriminator_gen_outputs=fake_logits_stop,
        add_summaries=True)
    return gan_d_loss, true_logits, fake_logits_stop

Performs the discriminator step in computing the GAN loss.

Applies stop-gradient to the generated frames while computing the
discriminator loss to make sure that the gradients are not back-propagated
to the generator. This makes sure that only the discriminator is updated.

Args:
true_frames: True outputs
gen_frames: Generated frames.
Returns:
d_loss: Loss component due to the discriminator.


def hpo_term(self, hpo_id):

        LOG.debug("Fetching hpo term %s", hpo_id)

        return self.hpo_term_collection.find_one({'_id': hpo_id})

Fetch a hpo term

Args:
hpo_id(str)

Returns:
hpo_obj(dict)


def search(self, term: str, case_sensitive: bool=False) -> 'PrettyDir':
    if case_sensitive:
        return PrettyDir(self.obj, [pattr for pattr in self.pattrs if (term in pattr.name)])
    else:
        term = term.lower()
        return PrettyDir(self.obj, [pattr for pattr in self.pattrs if (term in pattr.name.lower())])

Searches for names that match some pattern.

Args:
term: String used to match names. A name is returned if it matches
the whole search term.
case_sensitive: Boolean to match case or not, default is False
(case insensitive).

Return:
A PrettyDir object with matched names.


def get_installed_version(vcs):
    version_path = _get_version_path(vcs)
    if (not os.path.exists(version_path)):
        raise VersionNotInstalledError
    with open(version_path, 'r') as f:
        return f.read().strip()

Get the installed version for this project.

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

Returns:
str - version number

Raises:
VersionNotInstalledError


def pool_function(domain, launchWhois=False):

    is_valid = True
    try:
        ipv4 = socket.gethostbyname(domain["domain"])

        if isBlackListed(ipv4):
            return {"platform" : str(domain), "status": "ERROR", "data": {}}

        aux = {}
        aux["type"] = "i3visio.result"
        aux["value"] = "Domain Info - " + domain["domain"]
        aux["attributes"] = []

        try:
            if domain["type"] != "global" and launchWhois:
                aux["attributes"] = getWhoisInfo(domain["domain"])
        except Exception as e:

            pass

        tmp = {}
        tmp["type"] = "i3visio.domain"
        tmp["value"] =  domain["domain"]
        tmp["attributes"] = []

        aux["attributes"].append(tmp)

        tmp = {}
        tmp["type"] = "i3visio.tld_type"
        tmp["value"] =  domain["type"]
        tmp["attributes"] = []

        aux["attributes"].append(tmp)

        tmp = {}
        tmp["type"] = "i3visio.ipv4"
        tmp["value"] =  ipv4
        tmp["attributes"] = []

        aux["attributes"].append(tmp)

        return {"platform" : str(domain), "status": "DONE", "data": aux}
    except Exception as e:
        return {"platform" : str(domain), "status": "ERROR", "data": {}}

Wrapper for being able to launch all the threads of getPageWrapper.

Args:
-----
domain: We receive the parameters as a dictionary.
```
{
"domain" : ".com",
"type" : "global"
}
```
launchWhois: Whether the whois info will be launched.
Returns:
--------
dict: A dictionary containing the following values:
`{"platform" : str(domain), "status": "DONE", "data": aux}`


def normalize_url(url):

    uri = urlparse(url)
    query = uri.query or ""

    pairs = parse_qsl(query)
    decoded_pairs = [(unquote(key), value) for key, value in pairs]
    encoded_pairs = [(quote(key), value) for key, value in decoded_pairs]
    normalized_query = urlencode(encoded_pairs)

    return ParseResult(
        scheme=uri.scheme,
        netloc=uri.netloc,
        path=uri.path,
        params=uri.params,
        query=normalized_query,
        fragment=uri.fragment).geturl()

Returns the given URL with all query keys properly escaped.

Args:
url (str): The URL to normalize.

Returns:
str: The normalized URL.


def tpu_batch_size_per_shard(self, model_hparams):

    if self.batch_size_means_tokens and not model_hparams.use_fixed_batch_size:
      return model_hparams.batch_size
    else:
      return model_hparams.batch_size

Batch size in examples per TPU core.

Args:
model_hparams: model hyperparameters
Returns:
an integer


def strip_path_prefix(ipath, prefix):
    if (prefix is None):
        return ipath
    return (ipath[len(prefix):] if ipath.startswith(prefix) else ipath)

Strip prefix from path.

Args:
ipath: input path
prefix: the prefix to remove, if it is found in :ipath:

Examples:
>>> strip_path_prefix("/foo/bar", "/bar")
'/foo/bar'
>>> strip_path_prefix("/foo/bar", "/")
'foo/bar'
>>> strip_path_prefix("/foo/bar", "/foo")
'/bar'
>>> strip_path_prefix("/foo/bar", "None")
'/foo/bar'


def inverse_event_shape_tensor(self, output_shape, name='inverse_event_shape_tensor'):
    with self._name_scope(name, [output_shape]):
        output_shape = ops.convert_to_tensor(output_shape, dtype=dtypes.int32, name='output_shape')
        return self._inverse_event_shape_tensor(output_shape)

Shape of a single sample from a single batch as an `int32` 1D `Tensor`.

Args:
output_shape: `Tensor`, `int32` vector indicating event-portion shape
passed into `inverse` function.
name: name to give to the op

Returns:
inverse_event_shape_tensor: `Tensor`, `int32` vector indicating
event-portion shape after applying `inverse`.


def _verify_request(self, signature_chain_url: str, signature: str, request_body: bytes) -> bool:

        if signature_chain_url not in self.valid_certificates.keys():
            amazon_cert: X509 = verify_cert(signature_chain_url)
            if amazon_cert:
                amazon_cert_lifetime: timedelta = self.config['amazon_cert_lifetime']
                expiration_timestamp = datetime.utcnow() + amazon_cert_lifetime
                validated_cert = ValidatedCert(cert=amazon_cert, expiration_timestamp=expiration_timestamp)
                self.valid_certificates[signature_chain_url] = validated_cert
                log.info(f'Certificate {signature_chain_url} validated')
            else:
                log.error(f'Certificate {signature_chain_url} validation failed')
                return False
        else:
            validated_cert: ValidatedCert = self.valid_certificates[signature_chain_url]
            amazon_cert: X509 = validated_cert.cert

        if verify_signature(amazon_cert, signature, request_body):
            result = True
        else:
            log.error(f'Failed signature verification for request: {request_body.decode("utf-8", "replace")}')
            result = False

        return result

Conducts series of Alexa request verifications against Amazon Alexa requirements.

Args:
signature_chain_url: Signature certificate URL from SignatureCertChainUrl HTTP header.
signature: Base64 decoded Alexa request signature from Signature HTTP header.
request_body: full HTTPS request body
Returns:
result: True if verification was successful, False if not.


def wait_any(jobs, timeout=None):
    return Job._wait(jobs, timeout, concurrent.futures.FIRST_COMPLETED)

Return when at least one of the specified jobs has completed or timeout expires.

Args:
jobs: a Job or list of Jobs to wait on.
timeout: a timeout in seconds to wait for. None (the default) means no timeout.
Returns:
A list of the jobs that have now completed or None if there were no jobs.


def merged(self, timeslots: 'TimeslotCollection') -> 'TimeslotCollection':
    slots = [Timeslot(slot.interval, slot.channel) for slot in self.timeslots]
    slots.extend([Timeslot(slot.interval, slot.channel) for slot in timeslots.timeslots])
    return TimeslotCollection(*slots)

Return a new TimeslotCollection merged with a specified `timeslots`

Args:
timeslots: TimeslotCollection to be merged


def build_inputs_with_special_tokens(self, token_ids_0: List[int], token_ids_1: Optional[List[int]]=None) -> List[int]:
    if token_ids_1 is None:
        return [self.cls_token_id] + token_ids_0 + [self.sep_token_id]
    cls = [self.cls_token_id]
    sep = [self.sep_token_id]
    return cls + token_ids_0 + sep + token_ids_1 + sep

Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
adding special tokens. A RoFormer sequence has the following format:

- single sequence: `[CLS] X [SEP]`
- pair of sequences: `[CLS] A [SEP] B [SEP]`

Args:
token_ids_0 (`List[int]`):
List of IDs to which the special tokens will be added.
token_ids_1 (`List[int]`, *optional*):
Optional second list of IDs for sequence pairs.

Returns:
`List[int]`: List of [input IDs](../glossary#input-ids) with the appropriate special tokens.


def DeleteCampaignFeed(client, campaign_feed):

  campaign_feed_service = client.GetService('CampaignFeedService', 'v201809')

  operation = {
      'operand': campaign_feed,
      'operator': 'REMOVE'
  }

  campaign_feed_service.mutate([operation])

Deletes a campaign feed.

Args:
client: an AdWordsClient instance.
campaign_feed: the campaign feed to delete.


def _GetNextInterval(self):
    ranges = [x.CurrentRange() for x in self.fingers]
    starts = set([r.start for r in ranges if r])
    ends = set([r.end for r in ranges if r])
    if (not starts):
        return None
    min_start = min(starts)
    starts.remove(min_start)
    ends |= starts
    min_end = min(ends)
    if ((min_end - min_start) > self.BLOCK_SIZE):
        min_end = (min_start + self.BLOCK_SIZE)
    return Range(min_start, min_end)

Returns the next Range of the file that is to be hashed.

For all fingers, inspect their next expected range, and return the
lowest uninterrupted range of interest. If the range is larger than
BLOCK_SIZE, truncate it.

Returns:
Next range of interest in a Range namedtuple.


def upload(s3_conn, filepath, s3_path):

    bucket_name, prefix = split_s3_path(s3_path)
    bucket = s3_conn.get_bucket(bucket_name)
    filename = os.path.basename(filepath)

    key = boto.s3.key.Key(
        bucket=bucket,
        name='{}/{}'.format(prefix, filename)
    )
    logging.info('uploading from %s to %s', filepath, key)
    key.set_contents_from_filename(filepath)

Uploads the given file to s3

Args:
s3_conn: (boto.s3.connection) an s3 connection
filepath (str) the local filename
s3_path (str) the destination path on s3


def _transform_cur_commands(cur_commands, alias_table=None):

    transformed = []
    alias_table = alias_table if alias_table else get_alias_table()
    for cmd in cur_commands:
        if cmd in alias_table.sections() and alias_table.has_option(cmd, 'command'):
            transformed += alias_table.get(cmd, 'command').split()
        else:
            transformed.append(cmd)
    cur_commands[:] = transformed

Transform any aliases in cur_commands into their respective commands.

Args:
alias_table: The alias table.
cur_commands: current commands typed in the console.


def do_transaction(args):
    rest_client = RestClient(args.url, args.user)
    if (args.subcommand == 'list'):
        transactions = rest_client.list_transactions()
        keys = ('transaction_id', 'family', 'version', 'size', 'payload')
        headers = tuple(((k.upper() if (k != 'version') else 'VERS') for k in keys))

        def parse_txn_row(transaction, decode=True):
            decoded = b64decode(transaction['payload'])
            return (transaction['header_signature'], transaction['header']['family_name'], transaction['header']['family_version'], len(decoded), (str(decoded) if decode else transaction['payload']))
        if (args.format == 'default'):
            fmt.print_terminal_table(headers, transactions, parse_txn_row)
        elif (args.format == 'csv'):
            fmt.print_csv(headers, transactions, parse_txn_row)
        elif ((args.format == 'json') or (args.format == 'yaml')):
            data = [{k: d for (k, d) in zip(keys, parse_txn_row(b, False))} for b in transactions]
            if (args.format == 'yaml'):
                fmt.print_yaml(data)
            elif (args.format == 'json'):
                fmt.print_json(data)
            else:
                raise AssertionError('Missing handler: {}'.format(args.format))
        else:
            raise AssertionError('Missing handler: {}'.format(args.format))
    if (args.subcommand == 'show'):
        output = rest_client.get_transaction(args.transaction_id)
        if args.key:
            if (args.key == 'payload'):
                output = b64decode(output['payload'])
            elif (args.key in output):
                output = output[args.key]
            elif (args.key in output['header']):
                output = output['header'][args.key]
            else:
                raise CliException('Key "{}" not found in transaction or header'.format(args.key))
        if (args.format == 'yaml'):
            fmt.print_yaml(output)
        elif (args.format == 'json'):
            fmt.print_json(output)
        else:
            raise AssertionError('Missing handler: {}'.format(args.format))

Runs the transaction list or show command, printing to the console

Args:
args: The parsed arguments sent to the command at runtime


def input_on_stderr(prompt='', default=None, convert=None):
    print(prompt, end='', file=sys.stderr)
    value = builtins.input()
    return _convert(value, default, convert)

Output a string to stderr and wait for input.

Args:
prompt (str): the message to display.
default: the default value to return if the user
leaves the field empty
convert (callable): a callable to be used to convert
the value the user inserted. If None, the type of
``default`` will be used.


def disable_imu_streaming(self):
    self.enabled_imus = []
    for imu in self.imus:
        imu.reset()
    return self.dongle._disable_imu_streaming(self)

Disable IMU streaming for this device.

Returns:
True on success, False if an error occurred.


def __instantiate_page_object(page_obj_class, webdriver, **kwargs):
    try:
        page = page_obj_class(webdriver, **kwargs)
        return page
    except InvalidPageError:
        return True
    except TypeError:
        return False
    except Exception as e:
        raise e

Attempts to instantiate a page object.

Args:
page_obj_class (PageObject) - PageObject to instantiate.
webdriver (WebDriver) - Selenium webdriver to associate with the PageObject

Returns:
PageObject - If page object instantiation succeeded.
True - If page object instantiation failed, but validation was called.
None - If validation did not occur.


def __getitem__(self, key):

        if key in self._dict:
            return self._dict[key]

        return Grouping(key, [])

The sequence corresponding to a given key, or an empty sequence if
there are no values corresponding to that key.

Args:
key: The key of the group to be returned.

Returns:
The Grouping corresponding to the supplied key.


def aggregate_events(events: List[str]) -> List[Tuple[str, int]]:
    frequency_list = collections.Counter(events)
    return sorted(frequency_list.items(), key=lambda x: (-x[1], x[0]))

Returns a list of tuples: (event string, count of times they appear).

The list is sorted descending by count and then ascending by event string.

Args:
events: A list of strings defining an event (either an error or a warning).

Returns:
List of tuples : (event string, number of times they appear).


def double_linked_dom(str_or_dom):
    dom = str_or_dom
    if (not isinstance(str_or_dom, dhtmlparser.HTMLElement)):
        dom = dhtmlparser.parseString(str_or_dom)
    dhtmlparser.makeDoubleLinked(dom)
    return dom

Create double linked DOM from input.

In case of string, parse it, make it double-linked. In case of DOM, just
make it double-linked.

Args:
str_or_dom (str/HTMLelement): String or HTMLelement instance.

Returns:
obj: HTMLelement with parsed, double-linked content from `str_or_dom`.


def topological_sort(data):

    def check_self_dependencies(input_data):
        "Check if there are self dependencies within a node.\n\n        Self dependencies are for example: ``{'a': ('a',)}``.\n\n        Args:\n            input_data (dict): the input data. Of a structure similar to {key: (list of values), ...}.\n\n        Raises:\n            ValueError: if there are indeed self dependencies\n        "
        for (k, v) in input_data.items():
            if (k in v):
                raise ValueError('Self-dependency, {} depends on itself.'.format(k))

    def prepare_input_data(input_data):
        'Prepares the input data by making sets of the dependencies. This automatically removes redundant items.\n\n        Args:\n            input_data (dict): the input data. Of a structure similar to {key: (list of values), ...}.\n\n        Returns:\n            dict: a copy of the input dict but with sets instead of lists for the dependencies.\n        '
        return {k: set(v) for (k, v) in input_data.items()}

    def find_items_without_dependencies(input_data):
        "This searches the dependencies of all the items for items that have no dependencies.\n\n        For example, suppose the input is: ``{'a': ('b',)}``, then ``a`` depends on ``b`` and ``b`` depends on nothing.\n        This class returns ``(b,)`` in this example.\n\n        Args:\n            input_data (dict): the input data. Of a structure similar to {key: (list of values), ...}.\n\n        Returns:\n            list: the list of items without any dependency.\n        "
        return list((reduce(set.union, input_data.values()) - set(input_data.keys())))

    def add_empty_dependencies(data):
        items_without_dependencies = find_items_without_dependencies(data)
        data.update({item: set() for item in items_without_dependencies})

    def get_sorted(input_data):
        data = input_data
        while True:
            ordered = set((item for (item, dep) in data.items() if (len(dep) == 0)))
            if (not ordered):
                break
            (yield ordered)
            data = {item: (dep - ordered) for (item, dep) in data.items() if (item not in ordered)}
        if (len(data) != 0):
            raise ValueError('Cyclic dependencies exist among these items: {}'.format(', '.join((repr(x) for x in data.items()))))
    check_self_dependencies(data)
    if (not len(data)):
        return []
    data_copy = prepare_input_data(data)
    add_empty_dependencies(data_copy)
    result = []
    for d in get_sorted(data_copy):
        try:
            d = sorted(d)
        except TypeError:
            d = list(d)
        result.extend(d)
    return result

Topological sort the given dictionary structure.

Args:
data (dict); dictionary structure where the value is a list of dependencies for that given key.
For example: ``{'a': (), 'b': ('a',)}``, where ``a`` depends on nothing and ``b`` depends on ``a``.

Returns:
tuple: the dependencies in constructor order


def visit_Call(self, node):
    assert self._stack[-1] is node
    full_name = self._get_full_name(node.func)
    if full_name:
        name = full_name.split('.')[-1]
    elif isinstance(node.func, ast.Name):
        name = node.func.id
    elif isinstance(node.func, ast.Attribute):
        name = node.func.attr
    else:
        name = None
    self._maybe_add_call_warning(node, full_name, name)
    self._maybe_add_arg_names(node, full_name)
    self._maybe_modify_args(node, full_name, name)
    transformers = self._get_applicable_entries('function_transformers', full_name, name)
    parent = self._stack[-2]
    if transformers:
        if uses_star_args_or_kwargs_in_call(node):
            self.add_log(WARNING, node.lineno, node.col_offset, '(Manual check required) upgrading %s may require modifying call arguments, but it was passed variable-length *args or **kwargs. The upgrade script cannot handle these automatically.' % (full_name or name))
    for transformer in transformers:
        logs = []
        new_node = transformer(parent, node, full_name, name, logs)
        self.add_logs(logs)
        if new_node and new_node is not node:
            pasta.ast_utils.replace_child(parent, node, new_node)
            node = new_node
            self._stack[-1] = node
    self.generic_visit(node)

Handle visiting a call node in the AST.

Args:
node: Current Node


def new_space_from_module(self, module, recursive=False, **params):

        if "bases" in params:
            params["bases"] = get_impls(params["bases"])

        space = (
            self._impl.model.currentspace
        ) = self._impl.new_space_from_module(
            module, recursive=recursive, **params
        )
        return get_interfaces(space)

Create a child space from an module.

Alias to :py:meth:`import_module`.

Args:
module: a module object or name of the module object.
recursive: Not yet implemented.
**params: arguments to pass to ``new_space``

Returns:
The new child space created from the module.


def __init__(self,
                 device: 'cirq.google.XmonDevice',
                 start: GridQubit) -> None:

        if start not in device.qubits:
            raise ValueError('Starting qubit must be a qubit on the chip')

        self._c = device.qubits
        self._c_adj = chip_as_adjacency_list(device)
        self._start = start
        self._sequence = None

Greedy sequence search constructor.

Args:
device: Chip description.
start: Starting qubit.

Raises:
ValueError: When start qubit is not part of a chip.


def _parse_line(self, line_no, line):
    try:
        matched = statement.parseString(line)
    except ParseException as exc:
        raise DataError('Error parsing line in TileBus file', line_number=line_no, column=exc.col, contents=line)
    if ('symbol' in matched):
        self._parse_cmd(matched)
    elif ('filename' in matched):
        self._parse_include(matched)
    elif ('variable' in matched):
        self._parse_assignment(matched)
    elif ('configvar' in matched):
        self._parse_configvar(matched)

Parse a line in a TileBus file

Args:
line_no (int): The line number for printing useful error messages
line (string): The line that we are trying to parse


def Verify(self, mempool):

        if self.Gas.value % 100000000 != 0:
            return False
        return super(InvocationTransaction, self).Verify(mempool)

Verify the transaction.

Args:
mempool:

Returns:
bool: True if verified. False otherwise.


def heightmap_get_interpolated_value(
    hm: np.ndarray, x: float, y: float
) -> float:

    return float(
        lib.TCOD_heightmap_get_interpolated_value(_heightmap_cdata(hm), x, y)
    )

Return the interpolated height at non integer coordinates.

Args:
hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
x (float): A floating point x coordinate.
y (float): A floating point y coordinate.

Returns:
float: The value at ``x``, ``y``.


def set_base_log(self, dqm_version_id: str, workflow_execution_id: str, table_metadata: TableMetadata, run_dt_utc: datetime) -> None:
    self._base_log = LogMessage(dqm_version_id=dqm_version_id, workflow_execution_id=workflow_execution_id, project_id=table_metadata.project_id, dataset_id=table_metadata.dataset_id, table_name=table_metadata.table_name, full_table_id=table_metadata.full_table_id, run_timestamp_utc=get_formatted_timestamp(run_dt_utc))

Set the common values for each log message.

Args:
* dqm_version_id: DQM version ID
* workflow_execution_id: Workflow execution ID
* table_metadata: Source TableMetadata
* run_dt_utc: UTC timestamp object

Returns:
* None