def fulfill_order(self, order_number, site_code=None, email_opt_in=False):

    max_fulfillment_retries = get_configuration('MAX_FULFILLMENT_RETRIES', site_code=site_code)
    api = get_ecommerce_client(site_code=site_code)
    try:
        logger.info('Requesting fulfillment of order [%s].', order_number)
        api.orders(order_number).fulfill.put(email_opt_in=email_opt_in)
    except exceptions.HttpClientError as exc:
        status_code = exc.response.status_code  # pylint: disable=no-member
        if status_code == 406:
            # The order is not fulfillable. Therefore, it must be complete.
            logger.info('Order [%s] has already been fulfilled. Ignoring.', order_number)
            raise Ignore()
        else:
            # Unknown client error. Let's retry to resolve it.
            logger.warning(
                'Fulfillment of order [%s] failed because of HttpClientError. Retrying',
                order_number,
                exc_info=True
            )
            _retry_order(self, exc, max_fulfillment_retries, order_number)

    except (exceptions.HttpServerError, exceptions.Timeout, SSLError) as exc:
        # Fulfillment failed, retry
        _retry_order(self, exc, max_fulfillment_retries, order_number)

Fulfills an order.

Args:
        order_number (str): Order number indicating which order to fulfill.

Returns:
        None


def find_module_defining_flag(self, flagname, default=None):

    registered_flag = self._flags().get(flagname)
    if registered_flag is None:
      return default
    for module, flags in six.iteritems(self.flags_by_module_dict()):
      for flag in flags:
        # It must compare the flag with the one in _flags. This is because a
        # flag might be overridden only for its long name (or short name),
        # and only its short name (or long name) is considered registered.
        if (flag.name == registered_flag.name and
            flag.short_name == registered_flag.short_name):
          return module
    return default

Return the name of the module defining this flag, or default.

Args:
        flagname: str, name of the flag to lookup.
        default: Value to return if flagname is not defined. Defaults
        to None.

Returns:
        The name of the module which registered the flag with this name.
        If no such module exists (i.e. no flag with this name exists),
        we return default.


def get_self_attention_bias(x):

  x_shape = common_layers.shape_list(x)
  self_attention_bias = common_attention.attention_bias_lower_triangle(
      x_shape[1])
  return self_attention_bias

Creates masked self attention bias.

Args:
        x: A tensor of shape [batch, length, depth]

Returns:
        self_attention_bias: A tensor of shape [length, length, 1]


def angles( self ):

        ( a, b, c ) = [ row for row in self.matrix ]
        return [ angle( b, c ), angle( a, c ), angle( a, b ) ]

The cell angles (in degrees).

Args:
        None

Returns:
        (list(alpha,beta,gamma)): The cell angles.


def _write_move_counts(self, sess, h):

        def gen():
            for k, v in h.items():
                # The keys in the histogram may be of type 'bytes'
                k = str(k, 'utf-8')
                vs = str(v)
                yield (k.replace('g_', 'ct_') + '_%d' % v, vs)
                yield (k + '_m_000', vs)
        mc = tf.data.Dataset.from_generator(gen, (tf.string, tf.string))
        wr_op = self.tf_table.write(mc,
                                    column_families=[METADATA],
                                    columns=[MOVE_COUNT])
        sess.run(wr_op)

Add move counts from the given histogram to the table.

    Used to update the move counts in an existing table.  Should
    not be needed except for backfill or repair.

Args:
        sess:  TF session to use for doing a Bigtable write.
        tf_table:  TF Cloud Bigtable to use for writing.
        h:  a dictionary keyed by game row prefix ("g_0023561") whose values
        are the move counts for each game.


def camel_to_underscore(string):

    string = FIRST_CAP_RE.sub(r'\1_\2', string)
    return ALL_CAP_RE.sub(r'\1_\2', string).lower()

Convert camelcase to lowercase and underscore.

    Recipe from http://stackoverflow.com/a/1176023

Args:
        string (str): The string to convert.

Returns:
        str: The converted string.


def display_task_progress(
      self, instance, project, region, request_id=None, user=None,
      poll_interval=60):

    total_completed = 0

    while True:
      task_results = self.client.get_task_data(
          instance, project, region, request_id=request_id, user=user)
      tasks = {task['id']: task for task in task_results}
      completed_tasks = set()
      pending_tasks = set()

      for task in tasks.values():
        if task.get('successful') is not None:
          completed_tasks.add(task['id'])
        else:
          pending_tasks.add(task['id'])

      if len(completed_tasks) > total_completed or not completed_tasks:
        total_completed = len(completed_tasks)

        print('Task status update (completed: {0:d} | pending: {1:d})'.format(
            len(completed_tasks), len(pending_tasks)))

        print('Completed tasks:')
        for task_id in completed_tasks:
          self._print_task_data(tasks[task_id])

        print('Pending tasks:')
        for task_id in pending_tasks:
          self._print_task_data(tasks[task_id])

      if len(completed_tasks) == len(task_results) and completed_tasks:
        print('All {0:d} Tasks completed'.format(len(task_results)))
        return

      time.sleep(poll_interval)

Displays the overall progress of tasks in a Turbinia job.

Args:
        instance (string): The name of the Turbinia instance
        project (string): The project containing the disk to process
        region (string): Region where turbinia is configured.
        request_id (string): The request ID provided by Turbinia.
        user (string): The username to filter tasks by.
        poll_interval (int): The interval at which to poll for new results.


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

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

Create a Header with the optional parameters below.

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


def count_matching(self, selector, offset=0):

        if selector.output:
            data = self.streaming_data
        elif selector.buffered:
            data = self.storage_data
        else:
            raise ArgumentError("You can only pass a buffered selector to count_matching", selector=selector)

        count = 0
        for i in range(offset, len(data)):
            reading = data[i]

            stream = DataStream.FromEncoded(reading.stream)
            if selector.matches(stream):
                count += 1

        return count

Count the number of readings matching selector.

Args:
        selector (DataStreamSelector): The selector that we want to
            count matching readings for.
        offset (int): The starting offset that we should begin counting at.

Returns:
        int: The number of matching readings.


def _ConvertEnumDescriptor(self, enum_proto, package=None, file_desc=None,
                             containing_type=None, scope=None):

    if package:
      enum_name = '.'.join((package, enum_proto.name))
    else:
      enum_name = enum_proto.name

    if file_desc is None:
      file_name = None
    else:
      file_name = file_desc.name

    values = [self._MakeEnumValueDescriptor(value, index)
              for index, value in enumerate(enum_proto.value)]
    desc = descriptor.EnumDescriptor(name=enum_proto.name,
                                     full_name=enum_name,
                                     filename=file_name,
                                     file=file_desc,
                                     values=values,
                                     containing_type=containing_type,
                                     options=enum_proto.options)
    scope['.%s' % enum_name] = desc
    self._enum_descriptors[enum_name] = desc
    return desc

Make a protobuf EnumDescriptor given an EnumDescriptorProto protobuf.

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

Returns:
        The added descriptor


def _generate_examples(self, filepath):

    # Simultaneously iterating through the different data sets in the hdf5
    # file is >100x slower and the data set is small (26.7MB). Hence, we first
    # load everything into memory before yielding the samples.
    image_array, class_array, values_array = _load_data(filepath)
    for image, classes, values in moves.zip(image_array, class_array,
                                            values_array):
      yield dict(
          image=np.expand_dims(image, -1),
          label_shape=classes[1],
          label_scale=classes[2],
          label_orientation=classes[3],
          label_x_position=classes[4],
          label_y_position=classes[5],
          value_shape=values[1],
          value_scale=values[2],
          value_orientation=values[3],
          value_x_position=values[4],
          value_y_position=values[5])

Generates examples for the dSprites data set.

Args:
        filepath: path to the dSprites hdf5 file.

Yields:
        Dictionaries with images, latent classes, and latent values.


def add_boot_info_table(self, boot_info_table):
        # type: (eltorito.EltoritoBootInfoTable) -> None

        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError('Inode is not yet initialized')

        self.boot_info_table = boot_info_table

A method to add a boot info table to this Inode.

    Parameters:
    boot_info_table - The Boot Info Table object to add to this Inode.

Returns:
    Nothing.


def compile_intermediate_cpfs(self,
                                  scope: Dict[str, TensorFluent],
                                  batch_size: Optional[int] = None,
                                  noise: Optional[Noise] = None) -> List[CPFPair]:

        interm_fluents = []

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

                for cpf in self.rddl.domain.intermediate_cpfs:
                    cpf_noise = noise.get(cpf.name, None) if noise is not None else None

                    name_scope = utils.identifier(cpf.name)
                    with tf.name_scope(name_scope):
                        t = self._compile_expression(cpf.expr, scope, batch_size, cpf_noise)

                    interm_fluents.append((cpf.name, t))
                    scope[cpf.name] = t

        return interm_fluents

Compiles the intermediate fluent CPFs given the current `state` and `action` scope.

Args:
        scope (Dict[str, :obj:`rddl2tf.fluent.TensorFluent`]): The fluent scope for CPF evaluation.
        batch_size (Optional[int]): The batch size.

Returns:
        A list of intermediate fluent CPFs compiled to :obj:`rddl2tf.fluent.TensorFluent`.


def marketYesterdayDF(token='', version=''):

    x = marketYesterday(token, version)
    data = []
    for key in x:
        data.append(x[key])
        data[-1]['symbol'] = key
    df = pd.DataFrame(data)
    _toDatetime(df)
    _reindex(df, 'symbol')
    return df

This returns previous day adjusted price data for whole market

    https://iexcloud.io/docs/api/#previous-day-prices
    Available after 4am ET Tue-Sat

Args:
        symbol (string); Ticker to request
        token (string); Access token
        version (string); API version

Returns:
        DataFrame: result


def _project_TH3(self, hist: Hist) -> Any:

        # Axis length validation
        if len(self.projection_axes) < 1 or len(self.projection_axes) > 2:
            raise ValueError(len(self.projection_axes), "Invalid number of axes")

        # Need to concatenate the names of the axes together
        projection_axis_name = ""
        for axis in self.projection_axes:
            # Determine the axis name based on the name of the axis type.
            # [:1] returns just the first letter. For example, we could get "xy" if the first axis as
            # x_axis and the second was y_axis.
            # NOTE: Careful. This depends on the name of the enumerated values!!! Since this isn't terribly
            #       safe, we then perform additional validation on the same to ensure that it is one of the
            #       expected axis names.
            proj_axis_name = axis.axis_type.name[:1]
            if proj_axis_name not in ["x", "y", "z"]:
                raise ValueError(f"Projection axis name {proj_axis_name} is not 'x', 'y', or 'z'. Please check your configuration.")
            projection_axis_name += proj_axis_name

        # Handle ROOT Project3D quirk...
        # 2D projection are called as (y, x, options), so we should reverse the order so it performs
        # as expected.
        # NOTE: This isn't well documented in TH3. It is instead described in THnBase.Projection(...)
        if len(self.projection_axes) == 2:
            # Reverse the axes
            projection_axis_name = projection_axis_name[::-1]

        # Do the actual projection
        logger.info(f"Projecting onto axes \"{projection_axis_name}\" from hist {hist.GetName()}")
        projected_hist = hist.Project3D(projection_axis_name)

        return projected_hist

Perform the actual TH3 -> TH1 projection.

    This projection could be to 1D or 2D.

Args:
        hist (ROOT.TH3): Histogram from which the projections should be performed.

Returns:
        ROOT.TH1: The projected histogram.


def AddEventTags(self, event_tags):

    self._RaiseIfNotWritable()

    for event_tag in event_tags:
      self.AddEventTag(event_tag)

Adds event tags.

Args:
        event_tags (list[EventTag]): event tags.

Raises:
        IOError: when the storage file is closed or read-only or
        if the event tags cannot be serialized.
        OSError: when the storage file is closed or read-only or
        if the event tags cannot be serialized.


def _finalize_outputs(cls, mapreduce_spec, mapreduce_state):

    # Only finalize the output writers if the job is successful.
    if (mapreduce_spec.mapper.output_writer_class() and
        mapreduce_state.result_status == model.MapreduceState.RESULT_SUCCESS):
      mapreduce_spec.mapper.output_writer_class().finalize_job(mapreduce_state)

Finalize outputs.

Args:
        mapreduce_spec: an instance of MapreduceSpec.
        mapreduce_state: an instance of MapreduceState.


def _checkMode(mode):

    if not isinstance(mode, str):
        raise TypeError('The {0} should be a string. Given: {1!r}'.format("mode", mode))

    if mode not in [MODE_RTU, MODE_ASCII]:
        raise ValueError("Unreconized Modbus mode given. Must be 'rtu' or 'ascii' but {0!r} was given.".format(mode))

Check that the Modbus mode is valie.

Args:
        mode (string): The Modbus mode (MODE_RTU or MODE_ASCII)

Raises:
        TypeError, ValueError


def extract_archive(archive_path, dest):

  # Make the dest folder if it does not exist
  if not os.path.isdir(dest):
    os.makedirs(dest)

  try:
    tmpfolder = None

    if (not tf.gfile.Exists(archive_path)) or tf.gfile.IsDirectory(archive_path):
      raise ValueError('archive path %s is not a file' % archive_path)

    if archive_path.startswith('gs://'):
      # Copy the file to a local temp folder
      tmpfolder = tempfile.mkdtemp()
      cmd_args = ['gsutil', 'cp', archive_path, tmpfolder]
      _shell_process.run_and_monitor(cmd_args, os.getpid())
      archive_path = os.path.join(tmpfolder, os.path.name(archive_path))

    if archive_path.lower().endswith('.tar.gz'):
      flags = '-xzf'
    elif archive_path.lower().endswith('.tar'):
      flags = '-xf'
    else:
      raise ValueError('Only tar.gz or tar.Z files are supported.')

    cmd_args = ['tar', flags, archive_path, '-C', dest]
    _shell_process.run_and_monitor(cmd_args, os.getpid())
  finally:
    if tmpfolder:
      shutil.rmtree(tmpfolder)

Extract a local or GCS archive file to a folder.

Args:
        archive_path: local or gcs path to a *.tar.gz or *.tar file
        dest: local folder the archive will be extracted to


def register(self, username=""):

        if not username:
            username = utils.mxid2localpart(self.identity)
        content = {
            "type": "m.login.application_service",
            "username": username,
        }
        return self._send("POST", "/register", content,
                          api_path=MATRIX_V2_API_PATH)

Performs /register with type: m.login.application_service

Args:
        username(str): Username to register.


def provide(self, cls):

        support.verify_class_type(cls, 'cls')
        if not self._is_injectable_fn(cls):
            provide_loc = locations.get_back_frame_loc()
            raise errors.NonExplicitlyBoundClassError(provide_loc, cls)
        try:
            return self._obj_provider.provide_class(
                cls, self._injection_context_factory.new(cls.__init__),
                direct_init_pargs=[], direct_init_kwargs={})
        except errors.Error as e:
            if self._use_short_stack_traces:
                raise e
            else:
                raise

Provides an instance of the given class.

Args:
        cls: a class (not an instance)

Returns:
        an instance of cls

Raises:
        Error: an instance of cls is not providable


def ints_to_rgb(r, g=None, b=None):

  if type(r) in [list,tuple]:
    r, g, b = r
  return tuple(float(v) / 255.0 for v in [r, g, b])

Convert ints in the [0...255] range to the standard [0...1] range.

    Parameters:
        :r:
        The Red component value [0...255]
        :g:
        The Green component value [0...255]
        :b:
        The Blue component value [0...255]

Returns:
        The color as an (r, g, b) tuple in the range:
        r[0...1],
        g[0...1],
        b[0...1]

    >>> '(%g, %g, %g)' % ints_to_rgb((255, 128, 0))
    '(1, 0.501961, 0)'


def scalar_input_map(func, input_):

    if util_iter.isiterable(input_):
        return list(map(func, input_))
    else:
        return func(input_)

Map like function

Args:
        func: function to apply
        input_ : either an iterable or scalar value

Returns:
        If ``input_`` is iterable this function behaves like map
        otherwise applies func to ``input_``


def get_by(self, field, value, uri=None):

        if not field:
            logger.exception(RESOURCE_CLIENT_INVALID_FIELD)
            raise ValueError(RESOURCE_CLIENT_INVALID_FIELD)

        if not uri:
            uri = self._uri
        self.__validate_resource_uri(uri)

        logger.debug('Get by (uri = %s, field = %s, value = %s)' %
                     (uri, field, str(value)))

        filter = "\"{0}='{1}'\"".format(field, value)
        results = self.get_all(filter=filter, uri=uri)

        # Workaround when the OneView filter does not work, it will filter again
        if "." not in field:
            # This filter only work for the first level
            results = [item for item in results if str(item.get(field, '')).lower() == value.lower()]

        return results

This function uses get_all passing a filter.

    The search is case-insensitive.

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

Returns:
        dict


def populate_ast_nsarg_orthologs(ast, species):

    ortholog_namespace = "EG"

    if isinstance(ast, NSArg):
        if re.match(ortholog_namespace, ast.canonical):
            orthologs = bel.terms.orthologs.get_orthologs(
                ast.canonical, list(species.keys())
            )
            for species_id in species:
                if species_id in orthologs:
                    orthologs[species_id]["species_label"] = species[species_id]

            ast.orthologs = copy.deepcopy(orthologs)

    # Recursively process every NSArg by processing BELAst and Functions
    if hasattr(ast, "args"):
        for arg in ast.args:
            populate_ast_nsarg_orthologs(arg, species)

    return ast

Recursively collect NSArg orthologs for BEL AST

    This requires bo.collect_nsarg_norms() to be run first so NSArg.canonical is available

Args:
        ast: AST at recursive point in belobj
        species: dictionary of species ids vs labels for or


def __init__(self, dims, multiples, name="tile_by_dim"):

    super(TileByDim, self).__init__(name=name)
    self._dims = dims
    self._multiples = multiples
    if np.unique(dims).size != len(dims):
      raise ValueError("dims must not have any repeated integers.")
    if len(multiples) != len(dims):
      raise ValueError(
          "multiples must have the same length as dims: {}.".format(len(dims)))

Constructs the `TileByDim` module.

Args:
        dims: The dimensions to tile along, as a list of unique integers.
        multiples: The multiple of the tiling, as a list of integers. Must
        be the same length as the `dims` list.
        name: The name of the module.

Raises:
        ValueError: If `dims` has non-unique integers, or if the size of
        `multiples` is different from the size of `dims`.


def desaturate(self, level):

    h, s, l = self.__hsl
    return Color((h, max(s - level, 0), l), 'hsl', self.__a, self.__wref)

Create a new instance based on this one but less saturated.

    Parameters:
        :level:
        The amount by which the color should be desaturated to produce
        the new one [0...1].

Returns:
        A grapefruit.Color instance.

    >>> Color.from_hsl(30, 0.5, 0.5).desaturate(0.25)
    Color(0.625, 0.5, 0.375, 1.0)
    >>> Color.from_hsl(30, 0.5, 0.5).desaturate(0.25).hsl
    (30.0, 0.25, 0.5)


def log_histogram(self, name, value, step=None):

        if isinstance(value, six.string_types):
            raise TypeError('"value" should be a number, got {}'
                            .format(type(value)))

        self._check_step(step)
        tf_name = self._ensure_tf_name(name)

        summary = self._histogram_summary(tf_name, value, step=step)
        self._log_summary(tf_name, summary, value, step=step)

Log a histogram for given name on given step.

Args:
        name (str): name of the variable (it will be converted to a valid
            tensorflow summary name).
        value (tuple or list): either list of numbers
            to be summarized as a histogram, or a tuple of bin_edges and
            bincounts that directly define a histogram.
        step (int): non-negative integer used for visualization


def _all_correct_list(array):

    if type(array) not in _ITERABLE_TYPES:
        return False

    for item in array:
        if not type(item) in _ITERABLE_TYPES:
            return False

        if len(item) != 2:
            return False

    return True

Make sure, that all items in `array` has good type and size.

Args:
        array (list): Array of python types.

Returns:
        True/False


def _prefix_exists_in_gcs(gcs_prefix, credentials=None):

  gcs_service = _get_storage_service(credentials)

  bucket_name, prefix = gcs_prefix[len('gs://'):].split('/', 1)
  # documentation in
  # https://cloud.google.com/storage/docs/json_api/v1/objects/list
  request = gcs_service.objects().list(
      bucket=bucket_name, prefix=prefix, maxResults=1)
  response = request.execute()
  return response.get('items', None)

Check whether there is a GCS object whose name starts with the prefix.

    Since GCS doesn't actually have folders, this is how we check instead.

Args:
        gcs_prefix: The path; should start with 'gs://'.
        credentials: Optional credential to be used to load the file from gcs.

Returns:
        True if the prefix matches at least one object in GCS.

Raises:
        errors.HttpError: if it can't talk to the server


def stop_dag(self, name=None):

        return self._client.send(
            Request(
                action='stop_dag',
                payload={'name': name if name is not None else self._dag_name}
            )
        ).success

Send a stop signal to the specified dag or the dag that hosts this task.

Args:
        name str: The name of the dag that should be stopped. If no name is given the
                dag that hosts this task is stopped.

    Upon receiving the stop signal, the dag will not queue any new tasks and wait
    for running tasks to terminate.

Returns:
        bool: True if the signal was sent successfully.


def CreateDataTypeMap(self, definition_name):

    data_type_definition = self._definitions_registry.GetDefinitionByName(
        definition_name)
    if not data_type_definition:
      return None

    return DataTypeMapFactory.CreateDataTypeMapByType(data_type_definition)

Creates a specific data type map by name.

Args:
        definition_name (str): name of the data type definition.

Returns:
        DataTypeMap: data type map or None if the date type definition
        is not available.


def typical_or_extreme_period_name(self, value=None):

        if value is not None:
            try:
                value = str(value)
            except ValueError:
                raise ValueError(
                    'value {} need to be of type str '
                    'for field `typical_or_extreme_period_name`'.format(value))
            if ',' in value:
                raise ValueError('value should not contain a comma '
                                 'for field `typical_or_extreme_period_name`')

        self._typical_or_extreme_period_name = value

Corresponds to IDD Field `typical_or_extreme_period_name`

Args:
        value (str): value for IDD Field `typical_or_extreme_period_name`
            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 get(cls, option, default_value=None):

        config = cls.__get_instance()
        for name in option.split(':'):
            if not name:
                raise Exception('Incorrect value in path (maybe double `:` or empty path)')
            if name not in config:
                return default_value
            config = config[name]
        return deepcopy(config)

Return value of given option.

    If option isn't found - return default_value (None by default).

Args:
    - option: string with path to option with `:` separator


def tracers(tracersfile):

    if not tracersfile.is_file():
        return None
    tra = {}
    with tracersfile.open('rb') as fid:
        readbin = partial(_readbin, fid)
        magic = readbin()
        if magic > 8000:  # 64 bits
            magic -= 8000
            readbin()
            readbin = partial(readbin, file64=True)
        if magic < 100:
            raise ParsingError(tracersfile,
                               'magic > 100 expected to get tracervar info')
        nblk = magic % 100
        readbin('f', 2)  # aspect ratio
        readbin()  # istep
        readbin('f')  # time
        ninfo = readbin()
        ntra = readbin(nwords=nblk, unpack=False)
        readbin('f')  # tracer ideal mass
        curv = readbin()
        if curv:
            readbin('f')  # r_cmb
        infos = []  # list of info names
        for _ in range(ninfo):
            infos.append(b''.join(readbin('b', 16)).strip().decode())
            tra[infos[-1]] = []
        if magic > 200:
            ntrace_elt = readbin()
            if ntrace_elt > 0:
                readbin('f', ntrace_elt)  # outgassed
        for ntrab in ntra:  # blocks
            data = readbin('f', ntrab * ninfo)
            for idx, info in enumerate(infos):
                tra[info].append(data[idx::ninfo])
    return tra

Extract tracers data.

Args:
        tracersfile (:class:`pathlib.Path`): path of the binary tracers file.

Returns:
        dict of list of numpy.array:
            Tracers data organized by attribute and block.


def delete(self, key):

    try:
      del self._collection(key)[key]

      if len(self._collection(key)) == 0:
        del self._items[str(key.path)]
    except KeyError, e:
      pass

Removes the object named by `key`.

    Removes the object from the collection corresponding to ``key.path``.

Args:
        key: Key naming the object to remove.


def get_vep_info(vep_string, vep_header):

    vep_annotations = [
        dict(zip(vep_header, vep_annotation.split('|')))
        for vep_annotation in vep_string.split(',')
    ]

    return vep_annotations

Make the vep annotations into a dictionaries

    A vep dictionary will have the vep column names as keys and
    the vep annotations as values.
    The dictionaries are stored in a list

Args:
        vep_string (string): A string with the CSQ annotation
        vep_header (list): A list with the vep header

Returns:
        vep_annotations (list): A list of vep dicts


def select_qadapter(self, pconfs):

        # Order the list of configurations according to policy.
        policy, max_ncpus = self.policy, self.max_cores
        pconfs = pconfs.get_ordered_with_policy(policy, max_ncpus)

        if policy.precedence == "qadapter":

            # Try to run on the qadapter with the highest priority.
            for qadpos, qad in enumerate(self.qads):
                possible_pconfs = [pc for pc in pconfs if qad.can_run_pconf(pc)]

                if qad.allocation == "nodes":
                #if qad.allocation in ["nodes", "force_nodes"]:
                    # Select the configuration divisible by nodes if possible.
                    for pconf in possible_pconfs:
                        if pconf.num_cores % qad.hw.cores_per_node == 0:
                            return self._use_qadpos_pconf(qadpos, pconf)

                # Here we select the first one.
                if possible_pconfs:
                    return self._use_qadpos_pconf(qadpos, possible_pconfs[0])

        elif policy.precedence == "autoparal_conf":
            # Try to run on the first pconf irrespectively of the priority of the qadapter.
            for pconf in pconfs:
                for qadpos, qad in enumerate(self.qads):

                    if qad.allocation == "nodes" and not pconf.num_cores % qad.hw.cores_per_node == 0:
                        continue # Ignore it. not very clean

                    if qad.can_run_pconf(pconf):
                        return self._use_qadpos_pconf(qadpos, pconf)

        else:
            raise ValueError("Wrong value of policy.precedence = %s" % policy.precedence)

        # No qadapter could be found
        raise RuntimeError("Cannot find qadapter for this run!")

Given a list of parallel configurations, pconfs, this method select an `optimal` configuration
    according to some criterion as well as the :class:`QueueAdapter` to use.

Args:
        pconfs: :class:`ParalHints` object with the list of parallel configurations

Returns:
        :class:`ParallelConf` object with the `optimal` configuration.


def _filterByPaddingNum(cls, iterable, num):

        _check = DISK_RE.match

        for item in iterable:
            # Add a filter for paths that don't match the frame
            # padding of a given number
            matches = _check(item)
            if not matches:
                if num <= 0:
                    # Not a sequence pattern, but we were asked
                    # to match on a zero padding
                    yield item

                continue

            frame = matches.group(3) or ''

            if not frame:
                if num <= 0:
                    # No frame value was parsed, but we were asked
                    # to match on a zero padding
                    yield item
                continue

            # We have a frame number

            if frame[0] == '0' or frame[:2] == '-0':
                if len(frame) == num:
                    # A frame leading with '0' is explicitly
                    # padded and can only be a match if its exactly
                    # the target padding number
                    yield item
                continue

            if len(frame) >= num:
                # A frame that does not lead with '0' can match
                # a padding width >= to the target padding number
                yield item
                continue

Yield only path elements from iterable which have a frame
    padding that matches the given target padding number

Args:
        iterable (collections.Iterable):
        num (int):

Yields:
        str:


def package_and_copy(package_root_dir, setup_py, output_tar_path):

  if not output_tar_path.startswith('gs://'):
    raise ValueError('output_tar_path needs to be a GCS path.')
  if not os.path.isfile(setup_py):
    raise ValueError('Supplied file "%s" does not exist.' % setup_py)

  dest_setup_py = os.path.join(package_root_dir, 'setup.py')
  if dest_setup_py != setup_py:
    # setuptools requires a "setup.py" in the current dir, so copy setup.py there.
    # Also check if there is an existing setup.py. If so, back it up.
    if os.path.isfile(dest_setup_py):
      os.rename(dest_setup_py, dest_setup_py + '._bak_')
    shutil.copyfile(setup_py, dest_setup_py)

  tempdir = tempfile.mkdtemp()
  previous_cwd = os.getcwd()
  os.chdir(package_root_dir)
  try:
    # Repackage.
    sdist = ['python', dest_setup_py, 'sdist', '--format=gztar', '-d', tempdir]
    subprocess.check_call(sdist)

    # Copy to GCS.
    source = os.path.join(tempdir, '*.tar.gz')
    gscopy = ['gsutil', 'cp', source, output_tar_path]
    subprocess.check_call(gscopy)
    return
  finally:
    os.chdir(previous_cwd)
    if dest_setup_py != setup_py:
      os.remove(dest_setup_py)
    if os.path.isfile(dest_setup_py + '._bak_'):
      os.rename(dest_setup_py + '._bak_', dest_setup_py)
    shutil.rmtree(tempdir)

Repackage an CloudML package and copy it to a staging dir.

Args:
        package_root_dir: the root dir to install package from. Usually you can get the path
        from inside your module using a relative path to __file__.
        setup_py: the path to setup.py.
        output_tar_path: the GCS path of the output tarball package.

Raises:
        ValueError if output_tar_path is not a GCS path, or setup_py does not exist.


def learn_dfa(self, mma=None):

        logging.info('Initializing learning procedure.')
        if mma:
            self._init_table_from_dfa(mma)
        else:
            self._init_table()

        logging.info('Generating a closed and consistent observation table.')
        while True:

            closed = False
            # Make sure that the table is closed
            while not closed:
                logging.debug('Checking if table is closed.')
                closed, string = self.observation_table.is_closed()
                if not closed:
                    logging.debug('Closing table.')
                    self._ot_make_closed(string)
                else:
                    logging.debug('Table closed.')

            # Create conjecture

            dfa = self.get_dfa_conjecture()

            logging.info('Generated conjecture machine with %d states.',len(list(dfa.states)))

            # _check correctness
            logging.debug('Running equivalence query.')
            found, counter_example = self._equivalence_query(dfa)

            # Are we done?
            if found:
                logging.info('No counterexample found. Hypothesis is correct!')
                break

            # Add the new experiments into the table to reiterate the
            # learning loop
            logging.info('Processing counterexample %s with length %d.', counter_example, len(counter_example))
            self._process_counter_example(dfa, counter_example)

        logging.info('Learning complete.')
        logging.info('Learned em_vector table is the following:')
        logging.info(self.observation_table.em_vector)
        return '', dfa

Implements the high level loop of the algorithm for learning a
    Mealy machine.

Args:
        mma (DFA): The input automaton

Returns:
        MealyMachine: A string and a model for the Mealy machine to be learned.


def FileEntryExistsByPathSpec(self, path_spec):

    tsk_vs_part, _ = tsk_partition.GetTSKVsPartByPathSpec(
        self._tsk_volume, path_spec)

    # The virtual root file has not corresponding TSK volume system part object
    # but should have a location.
    if tsk_vs_part is None:
      location = getattr(path_spec, 'location', None)
      return location is not None and location == self.LOCATION_ROOT

    return True

Determines if a file entry for a path specification exists.

Args:
        path_spec (PathSpec): a path specification.

Returns:
        bool: True if the file entry exists or false otherwise.


def _ReadPresetsFromFileObject(self, file_object):

    yaml_generator = yaml.safe_load_all(file_object)

    last_preset_definition = None
    for yaml_definition in yaml_generator:
      try:
        preset_definition = self._ReadParserPresetValues(yaml_definition)
      except errors.MalformedPresetError as exception:
        error_location = 'At start'
        if last_preset_definition:
          error_location = 'After: {0:s}'.format(last_preset_definition.name)

        raise errors.MalformedPresetError(
            '{0:s} {1!s}'.format(error_location, exception))

      yield preset_definition
      last_preset_definition = preset_definition

Reads parser and parser plugin presets from a file-like object.

Args:
        file_object (file): file-like object containing the parser and parser
        plugin presets definitions.

Yields:
        ParserPreset: a parser preset.

Raises:
        MalformedPresetError: if one or more plugin preset definitions are
        malformed.


def __init__(self, channel):

    self.GetChanges = channel.unary_stream(
        '/pb.Data/GetChanges',
        request_serializer=lookout_dot_sdk_dot_service__data__pb2.ChangesRequest.SerializeToString,
        response_deserializer=lookout_dot_sdk_dot_service__data__pb2.Change.FromString,
        )
    self.GetFiles = channel.unary_stream(
        '/pb.Data/GetFiles',
        request_serializer=lookout_dot_sdk_dot_service__data__pb2.FilesRequest.SerializeToString,
        response_deserializer=lookout_dot_sdk_dot_service__data__pb2.File.FromString,
        )

Constructor.

Args:
        channel: A grpc.Channel.


def devno_free(self, devno):

        devno_int = int(devno, 16)
        self._devno_pool.free(devno_int)

Free a device number allocated with :meth:`devno_alloc`.

    The device number must be allocated.

    Parameters:
        devno (string): The device number as four hexadecimal digits.

Raises:
        ValueError: Device number not in pool range or not currently
        allocated.


def brake_on(self):

        data = []
        data.append(0x0A)
        data.append(self.servoid)
        data.append(RAM_WRITE_REQ)
        data.append(TORQUE_CONTROL_RAM)
        data.append(0x01)
        data.append(0x40)
        send_data(data)

Set the Brakes of Herkulex

    In braked mode, position control and velocity control
    will not work, enable torque before that

Args:
        none


def isubset(self, *keys):
        # type: (*Hashable) -> ww.g

        return ww.g((key, self[key]) for key in keys)

Return key, self[key] as generator for key in keys.

    Raise KeyError if a key does not exist

Args:
        keys: Iterable containing keys

Example:
        >>> from ww import d
        >>> list(d({1: 1, 2: 2, 3: 3}).isubset(1, 3))
        [(1, 1), (3, 3)]


def send_status_message(self, object_id, status):

        try:
            body = json.dumps({
                'id': object_id,
                'status': status
            })

            self.status_queue.send_message(
                MessageBody=body,
                MessageGroupId='job_status',
                MessageDeduplicationId=get_hash((object_id, status))
            )
            return True
        except Exception as ex:
            print(ex)
            return False

Send a message to the `status_queue` to update a job's status.

    Returns `True` if the message was sent, else `False`

Args:
        object_id (`str`): ID of the job that was executed
        status (:obj:`SchedulerStatus`): Status of the job

Returns:
        `bool`


def write(self, data):

        if not isinstance(data, (bytes, bytearray, list)):
            raise TypeError("Invalid data type, should be bytes, bytearray, or list.")

        if isinstance(data, list):
            data = bytearray(data)

        try:
            return os.write(self._fd, data)
        except OSError as e:
            raise SerialError(e.errno, "Writing serial port: " + e.strerror)

Write `data` to the serial port and return the number of bytes
    written.

Args:
        data (bytes, bytearray, list): a byte array or list of 8-bit integers to write.

Returns:
        int: number of bytes written.

Raises:
        SerialError: if an I/O or OS error occurs.
        TypeError: if `data` type is invalid.
        ValueError: if data is not valid bytes.


def mctransp(I,J,K,c,d,M):

    model = Model("multi-commodity transportation")

    # Create variables
    x = {}

    for (i,j,k) in c:
        x[i,j,k] = model.addVar(vtype="C", name="x(%s,%s,%s)" % (i,j,k))

    # Demand constraints
    for i in I:
        for k in K:
            model.addCons(sum(x[i,j,k] for j in J if (i,j,k) in x) == d[i,k], "Demand(%s,%s)" % (i,k))

    # Capacity constraints
    for j in J:
        model.addCons(sum(x[i,j,k] for (i,j2,k) in x if j2 == j) <= M[j], "Capacity(%s)" % j)

    # Objective
    model.setObjective(quicksum(c[i,j,k]*x[i,j,k]  for (i,j,k) in x), "minimize")

    model.data = x

    return model

mctransp -- model for solving the Multi-commodity Transportation Problem
    Parameters:
        - I: set of customers
        - J: set of facilities
        - K: set of commodities
        - c[i,j,k]: unit transportation cost on arc (i,j) for commodity k
        - d[i][k]: demand for commodity k at node i
        - M[j]: capacity
    Returns a model, ready to be solved.


def ParseFileObject(self, parser_mediator, file_object):

    file_size = file_object.get_size()

    file_header_map = self._GetDataTypeMap('rp_log_file_header')

    try:
      file_header, _ = self._ReadStructureFromFileObject(
          file_object, 0, file_header_map)
    except (ValueError, errors.ParseError) as exception:
      raise errors.UnableToParseFile(
          'Unable to parse file header with error: {0!s}'.format(
              exception))

    file_footer_map = self._GetDataTypeMap('rp_log_file_footer')

    file_footer_offset = file_size - file_footer_map.GetByteSize()

    try:
      file_footer, _ = self._ReadStructureFromFileObject(
          file_object, file_footer_offset, file_footer_map)
    except (ValueError, errors.ParseError) as exception:
      parser_mediator.ProduceExtractionWarning(
          'unable to parse file footer with error: {0!s}'.format(exception))
      return

    # The description in the file header includes the end-of-string character
    # that we need to strip off.
    description = file_header.description.rstrip('\0')

    if file_footer.creation_time == 0:
      date_time = dfdatetime_semantic_time.SemanticTime('Not set')
    else:
      date_time = dfdatetime_filetime.Filetime(
          timestamp=file_footer.creation_time)

    event_data = RestorePointEventData()
    event_data.description = description
    event_data.restore_point_event_type = file_header.event_type
    event_data.restore_point_type = file_header.restore_point_type
    event_data.sequence_number = file_header.sequence_number

    event = time_events.DateTimeValuesEvent(
        date_time, definitions.TIME_DESCRIPTION_CREATION)
    parser_mediator.ProduceEventWithEventData(event, event_data)

Parses a Windows Restore Point (rp.log) log file-like object.

Args:
        parser_mediator (ParserMediator): mediates interactions between parsers
        and other components, such as storage and dfvfs.
        file_object (dfvfs.FileIO): file-like object.

Raises:
        UnableToParseFile: when the file cannot be parsed.


def add_dataset(self, task_name, dataset=None, *, aliases=None):

        self._datasets.append(dataset if dataset is not None else TaskData())
        last_index = len(self._datasets) - 1
        self._aliases[task_name] = last_index

        if aliases is not None:
            for alias in aliases:
                self._aliases[alias] = last_index

        if len(self._datasets) == 1:
            self._default_index = 0

Add a new dataset to the MultiTaskData.

Args:
        task_name (str): The name of the task from which the dataset was received.
        dataset (TaskData): The dataset that should be added.
        aliases (list): A list of aliases that should be registered with the dataset.


def write_dict_to_new_file(file_name, localization_key_to_comment):

    output_file_descriptor = open_strings_file(file_name, "w")
    for entry_key, entry_comment in sorted(localization_key_to_comment.iteritems(), key=operator.itemgetter(1)):
        write_entry_to_file(output_file_descriptor, entry_comment, entry_key)
        output_file_descriptor.write(u'\n')
    output_file_descriptor.close()

Writes dictionary of localization keys and comments to a file.

Args:
        localization_key_to_comment (dict): A mapping between localization keys and comments.
        file_name (str): The path of the file to append to.


def extract_tree_with(self, labels, suppress_unifurcations=True):

        return self.extract_tree(labels, False, suppress_unifurcations)

Extract a copy of this ``Tree`` with only the leaves labeled by the strings in ``labels``

Args:
        ``leaves`` (``set``): Set of leaf labels to include.

        ``suppress_unifurcations`` (``bool``): ``True`` to suppress unifurcations, otherwise ``False``

Returns:
        Tree: Copy of this Tree, including only the leaves labeled by the strings in ``labels``


def wait_for_tuning_job(self, job, poll=5):

        desc = _wait_until(lambda: _tuning_job_status(self.sagemaker_client, job), poll)
        self._check_job_status(job, desc, 'HyperParameterTuningJobStatus')
        return desc

Wait for an Amazon SageMaker hyperparameter tuning job to complete.

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

Returns:
        (dict): Return value from the ``DescribeHyperParameterTuningJob`` API.

Raises:
        ValueError: If the hyperparameter tuning job fails.


def replace(cls, obj, field, value, state):

        if not hasattr(obj, field):
            raise ValidationError("Field '%s' does not exist, so it cannot be patched" % field)
        setattr(obj, field, value)
        return True

This is method for replace operation. It is separated to provide a
    possibility to easily override it in your Parameters.

Args:
        obj (object): an instance to change.
        field (str): field name
        value (str): new value
        state (dict): inter-operations state storage

Returns:
        processing_status (bool): True


def padFrameRange(frange, zfill):

        def _do_pad(match):

            result = list(match.groups())
            result[1] = pad(result[1], zfill)
            if result[4]:
                result[4] = pad(result[4], zfill)
            return ''.join((i for i in result if i))
        return PAD_RE.sub(_do_pad, frange)

Return the zero-padded version of the frame range string.

Args:
        frange (str): a frame range to test
        zfill (int):

Returns:
        str:


def uri(self, value, strip_iri=True):

        return self.convert_to_uri(value, strip_iri=strip_iri)

Converts py_uri or ttl uri to a http://... full uri format

Args:
        value: the string to convert

Returns:
        full uri of an abbreivated uri


def write_top_half(f, row_metadata_df, col_metadata_df, metadata_null, filler_null):

    # Initialize the top half of the gct including the third line
    size_of_top_half_df = (1 + col_metadata_df.shape[1],
                           1 + row_metadata_df.shape[1] + col_metadata_df.shape[0])

    top_half_df = pd.DataFrame(np.full(size_of_top_half_df, filler_null, dtype=object))

    # Assemble the third line of the gct: "id", then rhds, then cids
    top_half_df.iloc[0, :] = np.hstack(("id", row_metadata_df.columns.values, col_metadata_df.index.values))

    # Insert the chds
    top_half_df.iloc[range(1, top_half_df.shape[0]), 0] = col_metadata_df.columns.values

    # Insert the column metadata, but first convert to strings and replace NaNs
    col_metadata_indices = (range(1, top_half_df.shape[0]),
                            range(1 + row_metadata_df.shape[1], top_half_df.shape[1]))
    # pd.DataFrame.at to insert into dataframe(python3)
    top_half_df.at[col_metadata_indices[0], col_metadata_indices[1]] = (
        col_metadata_df.astype(str).replace("nan", value=metadata_null).T.values)

    # Write top_half_df to file
    top_half_df.to_csv(f, header=False, index=False, sep="\t")

Write the top half of the gct file: top-left filler values, row metadata
    headers, and top-right column metadata.

Args:
        f (file handle): handle for output file
        row_metadata_df (pandas df)
        col_metadata_df (pandas df)
        metadata_null (string): how to represent missing values in the metadata
        filler_null (string): what value to fill the top-left filler block with

Returns:
        None


def binfiles_set(self, isnap):

        possible_files = set(self.filename(fstem, isnap, force_legacy=True)
                             for fstem in phyvars.FIELD_FILES)
        return possible_files & self.files

Set of existing binary files at a given snap.

Args:
        isnap (int): snapshot index.

Returns:
        set of pathlib.Path: the set of output files available for this
        snapshot number.


def lat_id(self, line):

        if self.grid == 'WAC':
            lat = ((1 + self.LINE_PROJECTION_OFFSET - line) *
                   self.MAP_SCALE * 1e-3 / self.A_AXIS_RADIUS)
            return lat * 180 / np.pi
        else:
            lat = float(self.CENTER_LATITUDE) - \
                (line - float(self.LINE_PROJECTION_OFFSET) - 1)\
                / float(self.MAP_RESOLUTION)
            return lat

Return the corresponding latitude

Args:
        line (int): Line number

Returns:
        Correponding latitude in degree


def EnumerateAllConfigs(self, stats, file_objects):

    # Convert the stats & file_objects into a cache of a
    # simple path keyed dict of file contents.
    cache = {}
    for stat_obj, file_obj in zip(stats, file_objects):
      cache[stat_obj.pathspec.path] = utils.ReadFileBytesAsUnicode(file_obj)

    result = []
    external = []
    # Check to see if we have the old pam config file laying around.
    if self.OLD_PAMCONF_FILENAME in cache:
      # The PAM documentation says if it contains config data, then
      # it takes precedence over the rest of the config.
      # If it doesn't, the rest of the PAMDIR config counts.
      result, external = self.EnumerateConfig(None, self.OLD_PAMCONF_FILENAME,
                                              cache)
      if result:
        return result, external

    # If we made it here, there isn't a old-style pam.conf file worth
    # speaking of, so process everything!
    for path in cache:
      # PAM uses the basename as the 'service' id.
      service = os.path.basename(path)
      r, e = self.EnumerateConfig(service, path, cache)
      result.extend(r)
      external.extend(e)
    return result, external

Generate RDFs for the fully expanded configs.

Args:
        stats: A list of RDF StatEntries corresponding to the file_objects.
        file_objects: A list of file handles.

Returns:
        A tuple of a list of RDFValue PamConfigEntries found & a list of strings
        which are the external config references found.


def projects(self, term, field=None, **kwargs):

        params = kwargs
        params['q'] = term
        if field:
            params['f'] = self._FIELD_MAP[field]
        else:
            params['f'] = 'pro.t'
        baseuri = self._BASE_URI + 'projects'
        res = self.session.get(baseuri, params=params)
        self.handle_http_error(res)
        return res

Search for projects. Defaults to project_title. Other fields
    are:
        project_reference
        project_abstract

Args:
        term (str): Term to search for.
        kwargs (dict): additional keywords passed into
        requests.session.get params keyword.


def fit(self, X):

        U, V = self.split_matrix(X)
        self.tau = stats.kendalltau(U, V)[0]
        self.theta = self.compute_theta()
        self.check_theta()

Fit a model to the data updating the parameters.

Args:
        X: `np.ndarray` of shape (,2).

Returns:
        None


def groups_invite(self, *, channel: str, user: str, **kwargs) -> SlackResponse:

        self._validate_xoxp_token()
        kwargs.update({"channel": channel, "user": user})
        return self.api_call("groups.invite", json=kwargs)

Invites a user to a private channel.

Args:
        channel (str): The group id. e.g. 'G1234567890'
        user (str): The user id. e.g. 'U1234567890'


def create_assembly(self, did, wid, name='My Assembly'):

        payload = {
            'name': name
        }

        return self._api.request('post', '/api/assemblies/d/' + did + '/w/' + wid, body=payload)

Creates a new assembly element in the specified document / workspace.

Args:
        - did (str): Document ID
        - wid (str): Workspace ID
        - name (str, default='My Assembly')

Returns:
        - requests.Response: Onshape response data


def PushEvent(self, event):

    event_string = event.GetAttributeValuesString()
    heap_values = (event.timestamp, event.timestamp_desc, event_string, event)
    heapq.heappush(self._heap, heap_values)

Pushes an event onto the heap.

Args:
        event (EventObject): event.


def _parse_frange_part(frange):

        match = FRANGE_RE.match(frange)
        if not match:
            msg = 'Could not parse "{0}": did not match {1}'
            raise ParseException(msg.format(frange, FRANGE_RE.pattern))
        start, end, modifier, chunk = match.groups()
        start = int(start)
        end = int(end) if end is not None else start

        if end > start and chunk is not None and int(chunk) < 0:
            msg = 'Could not parse "{0}: chunk can not be negative'
            raise ParseException(msg.format(frange))

        chunk = abs(int(chunk)) if chunk is not None else 1
        # a zero chunk is just plain illogical
        if chunk == 0:
            msg = 'Could not parse "{0}": chunk cannot be 0'
            raise ParseException(msg.format(frange))
        return start, end, modifier, chunk

Internal method: parse a discrete frame range part.

Args:
        frange (str): single part of a frame range as a string
            (ie "1-100x5")

Returns:
        tuple: (start, end, modifier, chunk)

Raises:
        :class:`.ParseException`: if the frame range can
            not be parsed


def download_as_obj(
    base_url=d1_common.const.URL_DATAONE_ROOT,
    timeout_sec=d1_common.const.DEFAULT_HTTP_TIMEOUT,
):

    return decode_der(download_as_der(base_url, timeout_sec))

Download public certificate from a TLS/SSL web server as Certificate object.

    Also see download_as_der().

Args:
        base_url : str
        A full URL to a DataONE service endpoint or a server hostname
        timeout_sec : int or float
        Timeout for the SSL socket operations

Returns:
        cryptography.Certificate


def __init__(self, force=False):

        self.colorize = force or sys.stdout.isatty() or os.environ.get('JPY_PARENT_PID', None)

Initialize the class.

Args:
        force (bool): If True, render colorizes output no matter where the output is (default: False).


def _retrieve_info(self, request):

        info = _metadata.get_service_account_info(
            request,
            service_account=self._service_account_email)

        self._service_account_email = info['email']
        self._scopes = info['scopes']

Retrieve information about the service account.

    Updates the scopes and retrieves the full service account email.

Args:
        request (google.auth.transport.Request): The object used to make
            HTTP requests.


def cancelTickByTickData(self, contract: Contract, tickType: str):

        ticker = self.ticker(contract)
        reqId = self.wrapper.endTicker(ticker, tickType)
        if reqId:
            self.client.cancelTickByTickData(reqId)
        else:
            self._logger.error(
                f'cancelMktData: No reqId found for contract {contract}')

Unsubscribe from tick-by-tick data

Args:
        contract: The exact contract object that was used to
            subscribe with.


def write_plot(plot, filename, width=DEFAULT_PAGE_WIDTH, height=DEFAULT_PAGE_HEIGHT, unit=DEFAULT_PAGE_UNIT):

    svg = plot_to_svg(plot, width, height, unit)
    with open(filename, 'w') as outfile:
        outfile.write(svg)

Writes a plot SVG to a file.

Args:
        plot (list): a list of layers to plot
        filename (str): the name of the file to write
        width (float): the width of the output SVG
        height (float): the height of the output SVG
        unit (str): the unit of the height and width


def calc_timestep_statistic(self, statistic, time):

        ti = np.where(self.times == time)[0][0]
        ma = np.where(self.masks[ti].ravel() == 1)
        if statistic in ['mean', 'max', 'min', 'std', 'ptp']:
            stat_val = getattr(self.timesteps[ti].ravel()[ma], statistic)()
        elif statistic == 'median':
            stat_val = np.median(self.timesteps[ti].ravel()[ma])
        elif 'percentile' in statistic:
            per = int(statistic.split("_")[1])
            stat_val = np.percentile(self.timesteps[ti].ravel()[ma], per)
        elif 'dt' in statistic:
            stat_name = statistic[:-3]
            if ti == 0:
                stat_val = 0
            else:
                stat_val = self.calc_timestep_statistic(stat_name, time) -\
                    self.calc_timestep_statistic(stat_name, time - 1)
        else:
            stat_val = np.nan
        return stat_val

Calculate statistics from the primary attribute of the StObject.

Args:
        statistic: statistic being calculated
        time: Timestep being investigated

Returns:
        Value of the statistic


def write_contents(self, filename, contents, directory=None):

        filepath = "{}/{}".format(directory.rstrip("/"), filename) if directory else filename
        self._write_to_zipfile(filepath, contents)
        return filepath

write_contents: Write contents to filename in zip

Args:
        contents: (str) contents of file
        filename: (str) name of file in zip
        directory: (str) directory in zipfile to write file to (optional)
    Returns: path to file in zip


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

    super(PaddingDefinition, self).__init__(
        name, aliases=aliases, description=description, urls=urls)
    self.alignment_size = alignment_size

Initializes a padding data type definition.

Args:
        name (str): name.
        aliases (Optional[list[str]]): aliases.
        alignment_size (Optional[int]): alignment size.
        description (Optional[str]): description.
        urls (Optional[list[str]]): URLs.


def get_help_datapacks(module_name, server_prefix):

    _dir = os.path.realpath(
        os.path.join(os.getcwd(), os.path.dirname(__file__)))
    module_dir = "{}/../{}".format(_dir, module_name, "_help.json")
    if os.path.isdir(module_dir):
        module_help_path = "{}/{}".format(module_dir, "_help.json")

        if os.path.isfile(module_help_path):
            return helptools.get_help_datapacks(module_help_path, server_prefix)
        else:
            return [("Help", "{} does not have a help.json file".format(module_name), False)]
    else:
        return [("Help", "No module found called {}".format(module_name), False)]

Get the help datapacks for a module

Args:
        module_name (str): The module to get help data for
        server_prefix (str): The command prefix for this server

Returns:
        datapacks (list): The help datapacks for the module


def __init__(self, rom_path):

        # create a ROM file from the ROM path
        rom = ROM(rom_path)
        # check that there is PRG ROM
        if rom.prg_rom_size == 0:
            raise ValueError('ROM has no PRG-ROM banks.')
        # ensure that there is no trainer
        if rom.has_trainer:
            raise ValueError('ROM has trainer. trainer is not supported.')
        # try to read the PRG ROM and raise a value error if it fails
        _ = rom.prg_rom
        # try to read the CHR ROM and raise a value error if it fails
        _ = rom.chr_rom
        # check the TV system
        if rom.is_pal:
            raise ValueError('ROM is PAL. PAL is not supported.')
        # check that the mapper is implemented
        elif rom.mapper not in {0, 1, 2, 3}:
            msg = 'ROM has an unsupported mapper number {}.'
            raise ValueError(msg.format(rom.mapper))
        # create a dedicated random number generator for the environment
        self.np_random = np.random.RandomState()
        # store the ROM path
        self._rom_path = rom_path
        # initialize the C++ object for running the environment
        self._env = _LIB.Initialize(self._rom_path)
        # setup a placeholder for a 'human' render mode viewer
        self.viewer = None
        # setup a placeholder for a pointer to a backup state
        self._has_backup = False
        # setup a done flag
        self.done = True
        # setup the controllers, screen, and RAM buffers
        self.controllers = [self._controller_buffer(port) for port in range(2)]
        self.screen = self._screen_buffer()
        self.ram = self._ram_buffer()

Create a new NES environment.

Args:
        rom_path (str): the path to the ROM for the environment

Returns:
        None


def clean(self, value):

		# If the value is None and it's optional, return as is
		if value is None and self._optional:
			return None

		# If the value is not a dict
		if not isinstance(value, dict):
			raise ValueError('value')

		# Init the return value
		dRet = {}

		# Go through each value and clean it using the associated node
		for k in value.keys():
			try:
				dRet[k] = self._nodes[k].clean(value[k])
			except KeyError:
				raise ValueError('%s is not a valid node in the parent' % k)

		# Return the cleaned values
		return dRet

Clean

    Goes through each of the values in the dict, cleans it, stores it, and
    returns a new dict

Args:
    value {dict} -- The value to clean

Returns:
    dict


def __init__(self, channel):

    self.Ping = channel.unary_unary(
        '/processor.Processor/Ping',
        request_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString,
        response_deserializer=processor__pb2.Status.FromString,
        )
    self.Process = channel.unary_unary(
        '/processor.Processor/Process',
        request_serializer=message__pb2.Message.SerializeToString,
        response_deserializer=message__pb2.Message.FromString,
        )

Constructor.

Args:
        channel: A grpc.Channel.


def _indicator(self, indicator_data):

        if isinstance(indicator_data, dict):
            # get xid from dict
            xid = indicator_data.get('xid')
        else:
            # get xid from object
            xid = indicator_data.xid

        if self.indicators.get(xid) is not None:
            # return existing indicator from memory
            indicator_data = self.indicators.get(xid)
        elif self.indicators_shelf.get(xid) is not None:
            # return existing indicator from shelf
            indicator_data = self.indicators_shelf.get(xid)
        else:
            # store new indicators
            self.indicators[xid] = indicator_data
        return indicator_data

Return previously stored indicator or new indicator.

Args:
        indicator_data (dict|obj): An Indicator dict or instance of Indicator object.

Returns:
        dict|obj: The new Indicator dict/object or the previously stored dict/object.


def set_hook_data(self, key, data):

        if not isinstance(data, collections.Mapping):
            raise ValueError("Hook (key: %s) data must be an instance of "
                             "collections.Mapping (a dictionary for "
                             "example)." % key)

        if key in self.hook_data:
            raise KeyError("Hook data for key %s already exists, each hook "
                           "must have a unique data_key.", key)

        self.hook_data[key] = data

Set hook data for the given key.

Args:
        key(str): The key to store the hook data in.
        data(:class:`collections.Mapping`): A dictionary of data to store,
            as returned from a hook.


def unit(n, d=None, j=None, tt_instance=True):

    if isinstance(n, int):
        if d is None:
            d = 1
        n = n * _np.ones(d, dtype=_np.int32)
    else:
        d = len(n)
    if j is None:
        j = 0
    rv = []

    j = _ind2sub(n, j)

    for k in xrange(d):
        rv.append(_np.zeros((1, n[k], 1)))
        rv[-1][0, j[k], 0] = 1
    if tt_instance:
        rv = _vector.vector.from_list(rv)
    return rv

Generates e_j _vector in tt.vector format
    ---------
    Parameters:
        n - modes (either integer or array)
        d - dimensionality (integer)
        j - position of 1 in full-format e_j (integer)
        tt_instance - if True, returns tt.vector;
                    if False, returns tt cores as a list


def sleep(self, seconds):

        until = time.time() + seconds
        try:
            while True:
                self._service_futures([], until)
        except TimeoutError:
            return

Services all futures while waiting

Args:
        seconds (float): Time to wait


def write_version_and_dims(version, dims, f):

    f.write(("#" + version + "\n"))
    f.write((dims[0] + "\t" + dims[1] + "\t" + dims[2] + "\t" + dims[3] + "\n"))

Write first two lines of gct file.

Args:
        version (string): 1.3 by default
        dims (list of strings): length = 4
        f (file handle): handle of output file

Returns:
        nothing


def __init__(self, name):

    super(MemberSectionDefinition, self).__init__()
    self.name = name
    self.members = []

Initializes a member section definition.

Args:
        name (str): name.


def readinto(self, b):

        if not self._readable:
            raise UnsupportedOperation('read')

        with self._seek_lock:
            # Gets seek
            seek = self._seek

            # Initializes queue
            queue = self._read_queue
            if seek == 0:
                # Starts initial preloading on first call
                self._preload_range()

            # Initializes read data buffer
            size = len(b)
            if size:
                # Preallocated buffer:
                # Use memory view to avoid copies
                b_view = memoryview(b)
                size_left = size
            else:
                # Dynamic buffer:
                # Can't avoid copy, read until EOF
                b_view = b
                size_left = -1
            b_end = 0

            # Starts reading
            buffer_size = self._buffer_size
            while size_left > 0 or size_left == -1:

                # Finds buffer position in queue and buffer seek
                start = seek % buffer_size
                queue_index = seek - start

                # Gets preloaded buffer
                try:
                    buffer = queue[queue_index]
                except KeyError:
                    # EOF
                    break

                # Get buffer from future
                with handle_os_exceptions():
                    try:
                        queue[queue_index] = buffer = buffer.result()

                    # Already evaluated
                    except AttributeError:
                        pass
                buffer_view = memoryview(buffer)
                data_size = len(buffer)

                # Checks if end of file reached
                if not data_size:
                    break

                # Gets theoretical range to copy
                if size_left != -1:
                    end = start + size_left
                else:
                    end = data_size - start

                # Checks for end of buffer
                if end >= data_size:
                    # Adjusts range to copy
                    end = data_size

                    # Removes consumed buffer from queue
                    del queue[queue_index]

                    # Append another buffer preload at end of queue
                    index = queue_index + buffer_size * self._max_buffers
                    if index < self._size:
                        queue[index] = self._workers.submit(
                            self._read_range, index, index + buffer_size)

                # Gets read size, updates seek and updates size left
                read_size = end - start
                if size_left != -1:
                    size_left -= read_size
                seek += read_size

                # Defines read buffer range
                b_start = b_end
                b_end = b_start + read_size

                # Copy data from preload buffer to read buffer
                b_view[b_start:b_end] = buffer_view[start:end]

            # Updates seek and sync raw
            self._seek = seek
            self._raw.seek(seek)

        # Returns read size
        return b_end

Read bytes into a pre-allocated, writable bytes-like object b,
    and return the number of bytes read.

Args:
        b (bytes-like object): buffer.

Returns:
        int: number of bytes read


def _log_every_n_to_logger(n, logger, level, message, *args):  # pylint: disable=invalid-name

  logger = logger or logging.getLogger()
  def _gen():  # pylint: disable=missing-docstring
    while True:
      for _ in range(n):
        yield False
      logger.log(level, message, *args)
      yield True
  gen = _gen()
  return lambda: six.next(gen)

Logs the given message every n calls to a logger.

Args:
        n: Number of calls before logging.
        logger: The logger to which to log.
        level: The logging level (e.g. logging.INFO).
        message: A message to log
        *args: Any format args for the message.

Returns:
        A method that logs and returns True every n calls.


def driver_for_path(path, drivers=None):

    ext = (os.path.splitext(path)[1][1:] or path).lower()
    drivers = drivers or ImageDriver.registry if ext else {}
    for name, meta in drivers.items():
        if ext == meta.get('DMD_EXTENSION', '').lower():
            return ImageDriver(name)
    return None

Returns the gdal.Driver for a path or None based on the file extension.

Args:
    path -- file path as str with a GDAL supported file extension


def AddWatchOnly(self, script_hash):

        if script_hash in self._contracts:
            logger.error("Address already in contracts")
            return

        self._watch_only.append(script_hash)

Add a watch only address to the wallet.

Args:
        script_hash (UInt160): a bytearray (len 20) representing the public key.

Note:
        Prints a warning to the console if the address already exists in the wallet.


def extract_function_argument(text, f_name, f_argn, f_argt=asttypes.String):

    tree = parse(text)
    return list(filter_function_argument(tree, f_name, f_argn, f_argt))

Extract a specific argument from a specific function name.

Args:
    text
        The source text.
    f_name
        The name of the function
    f_argn
        The argument position
    f_argt
        The argument type from calmjs.parse.asttypes;
        default: calmjs.parse.asttypes.String


def write_worksheets(workbook, data_list, result_info_key, identifier_keys):

    # we can use the first item to figure out the worksheet keys
    worksheet_keys = get_worksheet_keys(data_list[0], result_info_key)

    for key in worksheet_keys:

        title = key.split('/')[1]

        title = utilities.convert_snake_to_title_case(title)

        title = KEY_TO_WORKSHEET_MAP.get(title, title)

        if key == 'property/nod':
            # the property/nod endpoint needs to be split into two worksheets
            create_property_nod_worksheets(workbook, data_list, result_info_key, identifier_keys)
        else:
            # all other endpoints are written to a single worksheet

            # Maximum 31 characters allowed in sheet title
            worksheet = workbook.create_sheet(title=title[:31])

            processed_data = process_data(key, data_list, result_info_key, identifier_keys)

            write_data(worksheet, processed_data)

    # remove the first, unused empty sheet
    workbook.remove_sheet(workbook.active)

Writes rest of the worksheets to workbook.

Args:
        workbook: workbook to write into
        data_list: Analytics API data as a list of dicts
        result_info_key: the key in api_data dicts that contains the data results
        identifier_keys: the list of keys used as requested identifiers
                        (address, zipcode, block_id, etc)


def do_IDENT(self, service_name: str, source: list, *args, **kwargs) -> None:

        self.logger.info(' IDENT %s as %s', service_name, source)
        self.messaging._address_map[service_name] = source

Perform identification of a service to a binary representation.

Args:
        service_name: human readable name for service
        source: zmq representation for the socket source


def unpack_message(buffer):

    hdr_size = Header().get_size()
    hdr_buff, msg_buff = buffer[:hdr_size], buffer[hdr_size:]
    header = Header()
    header.unpack(hdr_buff)
    message = new_message_from_header(header)
    message.unpack(msg_buff)
    return message

Unpack the whole buffer, including header pack.

Args:
        buffer (bytes): Bytes representation of a openflow message.

Returns:
        object: Instance of openflow message.


def FindFirst(cls, setting_matcher, device_matcher=None, **kwargs):

        try:
            return next(cls.FindDevices(
                setting_matcher, device_matcher=device_matcher, **kwargs))
        except StopIteration:
            raise usb_exceptions.DeviceNotFoundError(
                'No device available, or it is in the wrong configuration.')

Find and return the first matching device.

Args:
        setting_matcher: See cls.FindDevices.
        device_matcher: See cls.FindDevices.
        **kwargs: See cls.FindDevices.

Returns:
        An instance of UsbHandle.

Raises:
        DeviceNotFoundError: Raised if the device is not available.


def Parse(self, conditions, host_data):

    result = CheckResult(check_id=self.check_id)
    methods = self.SelectChecks(conditions)
    result.ExtendAnomalies([m.Parse(conditions, host_data) for m in methods])
    return result

Runs methods that evaluate whether collected host_data has an issue.

Args:
        conditions: A list of conditions to determine which Methods to trigger.
        host_data: A map of artifacts and rdf data.

Returns:
        A CheckResult populated with Anomalies if an issue exists.


def anchored_pairs(self, anchor):

        pairs = OrderedDict()

        for term in self.keys:
            score = self.get_pair(anchor, term)
            if score: pairs[term] = score

        return utils.sort_dict(pairs)

Get distances between an anchor term and all other terms.

Args:
        anchor (str): The anchor term.

Returns:
        OrderedDict: The distances, in descending order.


def set_memcache_policy(self, func):

    if func is None:
      func = self.default_memcache_policy
    elif isinstance(func, bool):
      func = lambda unused_key, flag=func: flag
    self._memcache_policy = func

Set the memcache policy function.

Args:
        func: A function that accepts a Key instance as argument and returns
        a bool indicating if it should be cached.  May be None.


def __init__(self, prefs, g, divPressureValues, kappa=2.0, omega=0.5,
            beta=1.0, mu=1.0,omega2=0.0,
            freeparams=['kappa', 'omega', 'beta', 'mu', 'omega2']):

        _checkParam('omega2',omega2, self.PARAMLIMITS, self.PARAMTYPES)
        self.omega2 = omega2
        self.deltar = scipy.array(divPressureValues.copy())
        assert (max(scipy.absolute(self.deltar))) <= 1, (
                "A scaled deltar value is > 1 or < -1.")
        super(ExpCM_empirical_phi_divpressure, self).__init__(prefs, g,
                kappa=kappa, omega=omega, beta=beta, mu=mu,
                freeparams=freeparams)

Initialize an `ExpCM_empirical_phi_divpressure` object.

Args:
        `prefs`, `kappa`, `omega`, `beta`, `mu`, `g`, `freeparams`
            Same meaning as for an `ExpCM_empirical_phi`
        `divPressureValues`, `omega2`
            Meaning described in the main class doc string.


def __init__(self, layer, named_tensors=None, scope='tf-layer', summary_labels=(), **kwargs):

        self.layer_spec = layer
        self.layer = util.get_object(obj=layer, predefined_objects=TFLayer.tf_layers, kwargs=kwargs)
        self.first_scope = None

        super(TFLayer, self).__init__(named_tensors=named_tensors, scope=scope, summary_labels=summary_labels)

Creates a new layer instance of a TensorFlow layer.

Args:
        name: The name of the layer, one of 'dense'.
        **kwargs: Additional arguments passed on to the TensorFlow layer constructor.


def updateFeatureService(self, efs_config):

        if self.securityhandler is None:
            print ("Security handler required")
            return
        fsRes = None
        fst = None
        fURL = None
        resItm= None
        try:

            fsRes = []
            fst = featureservicetools.featureservicetools(securityinfo=self)

            if isinstance(efs_config, list):
                for ext_service in efs_config:
                    fURL = None
                    cs = 0
                    try:
                        if 'ChunkSize' in ext_service:
                            if common.is_number(ext_service['ChunkSize']):
                                cs = ext_service['ChunkSize']
                    except Exception as e:
                        pass
                    resItm={"DeleteDetails": None,"AddDetails":None}
                    if 'ItemId' in ext_service and 'LayerName' in ext_service:
                        fs = fst.GetFeatureService(itemId=ext_service['ItemId'],returnURLOnly=False)
                        if not fs is None:
                            fURL = fst.GetLayerFromFeatureService(fs=fs,layerName=ext_service['LayerName'],returnURLOnly=True)
                    if fURL is None and 'URL' in ext_service:

                        fURL = ext_service['URL']
                    if fURL is None:
                        print("Item and layer not found or URL not in config")
                        continue

                    if 'DeleteInfo' in ext_service:
                        if str(ext_service['DeleteInfo']['Delete']).upper() == "TRUE":
                            resItm['DeleteDetails'] = fst.DeleteFeaturesFromFeatureLayer(url=fURL, sql=ext_service['DeleteInfo']['DeleteSQL'],chunksize=cs)
                            if not 'error' in resItm['DeleteDetails'] :
                                print ("Delete Successful: %s" % fURL)
                            else:
                                print (str(resItm['DeleteDetails']))

                    resItm['AddDetails'] = fst.AddFeaturesToFeatureLayer(url=fURL, pathToFeatureClass = ext_service['FeatureClass'],chunksize=cs)

                    fsRes.append(resItm)

                    if not 'error' in resItm['AddDetails']:
                        print ("Add Successful: %s " % fURL)
                    else:
                        print (str(resItm['AddDetails']))

            else:
                resItm={"DeleteDetails": None,"AddDetails":None}
                fURL = efs_config['URL']
                cs = 0
                try:
                    if 'ChunkSize' in efs_config:
                        if common.is_number(efs_config['ChunkSize']):
                            cs = efs_config['ChunkSize']
                except Exception as e:
                    pass
                if 'ItemId' in efs_config and 'LayerName' in efs_config:
                    fs = fst.GetFeatureService(itemId=efs_config['ItemId'],returnURLOnly=False)
                    if not fs is None:
                        fURL = fst.GetLayerFromFeatureService(fs=fs,layerName=efs_config['LayerName'],returnURLOnly=True)
                if fURL is None and 'URL' in efs_config:

                    fURL = efs_config['URL']
                if fURL is None:
                    print("Item and layer not found or URL not in config")
                    return None
                if 'DeleteInfo' in efs_config:
                    if str(efs_config['DeleteInfo']['Delete']).upper() == "TRUE":
                        resItm['DeleteDetails'] = fst.DeleteFeaturesFromFeatureLayer(url=fURL, sql=efs_config['DeleteInfo']['DeleteSQL'],chunksize=cs)
                        if not 'error' in resItm['DeleteDetails'] :
                            print ("            Delete Successful: %s" % fURL)
                        else:
                            print ("            " + str(resItm['DeleteDetails']))

                resItm['AddDetails'] = fst.AddFeaturesToFeatureLayer(url=fURL, pathToFeatureClass = efs_config['FeatureClass'],chunksize=cs)

                fsRes.append(resItm)

                if not 'error' in resItm['AddDetails']:
                    print ("            Add Successful: %s " % fURL)
                else:
                    print ("            " + str(resItm['AddDetails']))

            return fsRes

        except common.ArcRestHelperError as e:
            raise e
        except Exception as e:

            line, filename, synerror = trace()
            raise common.ArcRestHelperError({
                "function": "updateFeatureService",
                "line": line,
                "filename":  filename,
                "synerror": synerror,
            })
        finally:
            fst = None
            fURL = None
            resItm= None

            del fst
            del fURL
            del resItm

            gc.collect()

Updates a feature service.

Args:
        efs_config (list): A list of JSON configuration feature service details to update.

Returns:
        dict: A dictionary of results objects.


def dim_reduce_data(data, d):

    genes, cells = data.shape
    distances = np.zeros((cells, cells))
    for i in range(cells):
        for j in range(cells):
            distances[i,j] = poisson_dist(data[:,i], data[:,j])
    # do MDS on the distance matrix (procedure from Wikipedia)
    proximity = distances**2
    J = np.eye(cells) - 1./cells
    B = -0.5*np.dot(J, np.dot(proximity, J))
    # B should be symmetric, so we can use eigh
    e_val, e_vec = np.linalg.eigh(B)
    # Note: lam should be ordered to be the largest eigenvalues
    lam = np.diag(e_val[-d:])[::-1]
    #lam = max_or_zero(lam)
    E = e_vec[:,-d:][::-1]
    X = np.dot(E, lam**0.5)
    return X

Does a MDS on the data directly, not on the means.

Args:
        data (array): genes x cells
        d (int): desired dimensionality

Returns:
        X, a cells x d matrix


def join_sources(source_module: DeploymentModule, contract_name: str):

    joined_file = Path(__file__).parent.joinpath('joined.sol')
    remapping = {module: str(path) for module, path in contracts_source_path().items()}
    command = [
        './utils/join-contracts.py',
        '--import-map',
        json.dumps(remapping),
        str(contracts_source_path_of_deployment_module(
            source_module,
        ).joinpath(contract_name + '.sol')),
        str(joined_file),
    ]
    working_dir = Path(__file__).parent.parent
    try:
        subprocess.check_call(command, cwd=working_dir)
    except subprocess.CalledProcessError as ex:
        print(f'cd {str(working_dir)}; {subprocess.list2cmdline(command)} failed.')
        raise ex

    return joined_file.read_text()

Use join-contracts.py to concatenate all imported Solidity files.

Args:
        source_module: a module name to look up contracts_source_path()
        contract_name: 'TokenNetworkRegistry', 'SecretRegistry' etc.


def Add(self, path, age=None):

    if not isinstance(path, string_types):
      raise ValueError("Only strings should be added to a URN.")

    result = rdfvalue.RDFURN(self.Copy(age))
    result.Update(path=utils.JoinPath(self._string_urn, path))

    return result

Add a relative stem to the current value and return a new RDFURN.

    Note that this returns an RDFURN, not a ClientURN since the resulting object
    would not pass validation.

Args:
        path: A string containing a relative path.
        age: The age of the object. If None set to current time.

Returns:
        A new RDFURN that can be chained.

Raises:
        ValueError: if the path component is not a string.


def put(self, block_id, priority, pb_type='offline'):

        if pb_type not in ('offline', 'realtime'):
            raise ValueError('Invalid PB type.')

        with self._mutex:
            added_time = datetime.datetime.utcnow().isoformat()
            entry = (priority, sys.maxsize-self._index, block_id, pb_type,
                     added_time)
            self._index += 1
            if self._block_map.get(block_id) is not None:
                raise KeyError('ERROR: Block id "{}" already exists in '
                               'PC PB queue!'.
                               format(block_id))
            self._block_map[block_id] = entry
            LOG.debug("Adding PB %s to queue", block_id)
            self._queue.append(entry)
            self._queue.sort()  # Sort by priority followed by insertion order.
            self._queue.reverse()

Add a Processing Block to the queue.

    When a new entry it added, the queue is (re-)sorted by priority
    followed by insertion order (older blocks with equal priority are
    first).

Args:
        block_id (str): Processing Block Identifier
        priority (int): Processing Block scheduling priority
            (higher values = higher priority)
        pb_type (str): Processing Block type (offline, realtime)


def __edit_distance_alt(self, words):

        words = [x.lower() for x in words]
        return [e2 for e1 in words for e2 in self.edit_distance_1(e1)]

Compute all strings that are 1 edits away from all the words using
    only the letters in the corpus

Args:
        words (list): The words for which to calculate the edit distance

Returns:
        set: The set of strings that are edit distance two from the \
        provided words


def _create_query(node, context):

    visited_nodes = [node]
    output_columns = _get_output_columns(visited_nodes, context)
    filters = _get_filters(visited_nodes, context)
    selectable = sql_context_helpers.get_node_selectable(node, context)
    query = select(output_columns).select_from(selectable).where(and_(*filters))
    return query

Create a query from a SqlNode.

Args:
        node: SqlNode, the current node.
        context: CompilationContext, global compilation state and metadata.

Returns:
        Selectable, selectable of the generated query.


def _Scroll(self, lines=None):

    if lines is None:
      lines = self._cli_lines

    if lines < 0:
      self._displayed -= self._cli_lines
      self._displayed += lines
      if self._displayed < 0:
        self._displayed = 0
      self._lines_to_show = self._cli_lines
    else:
      self._lines_to_show = lines

    self._lastscroll = lines

Set attributes to scroll the buffer correctly.

Args:
        lines: An int, number of lines to scroll. If None, scrolls
        by the terminal length.


def __init__(self, game, ui, visualize=False):

        self.game = game
        self.init_game = copy.deepcopy(self.game)
        self.ui = ui
        self.visualize = visualize

        first_obs, first_reward, _ = self.game.its_showtime()
        self._actions = DMPycolab.get_action_space(self.ui)
        self._states = DMPycolab.get_state_space(first_obs, self.ui._croppers)

Initialize Pycolab environment.

Args:
        game: Pycolab Game Engine object. See https://github.com/deepmind/pycolab/tree/master/pycolab/examples
        ui: Pycolab CursesUI object. See https://github.com/deepmind/pycolab/tree/master/pycolab/examples
        visualize: If set True, the program will visualize the trainings of Pycolab game # TODO


def _prepare_headers(self, request, filter=None, order_by=None, group_by=[], page=None, page_size=None):

        if filter:
            request.set_header('X-Nuage-Filter', filter)

        if order_by:
            request.set_header('X-Nuage-OrderBy', order_by)

        if page is not None:
            request.set_header('X-Nuage-Page', str(page))

        if page_size:
            request.set_header('X-Nuage-PageSize', str(page_size))

        if len(group_by) > 0:
            header = ", ".join(group_by)
            request.set_header('X-Nuage-GroupBy', 'true')
            request.set_header('X-Nuage-Attributes', header)

Prepare headers for the given request

Args:
        request: the NURESTRequest to send
        filter: string
        order_by: string
        group_by: list of names
        page: int
        page_size: int


def cleanup(context):

    for name in 'work_dir', 'artifact_dir', 'task_log_dir':
        path = context.config[name]
        if os.path.exists(path):
            log.debug("rm({})".format(path))
            rm(path)
        makedirs(path)

Clean up the work_dir and artifact_dir between task runs, then recreate.

Args:
        context (scriptworker.context.Context): the scriptworker context.


def like_shared_file(self, sharekey=None):

        if not sharekey:
            raise Exception(
                "You must specify a sharekey of the file you"
                "want to 'like'.")

        endpoint = '/api/sharedfile/{sharekey}/like'.format(sharekey=sharekey)
        data = self._make_request("POST", endpoint=endpoint, data=None)

        try:
            sf = SharedFile.NewFromJSON(data)
            sf.liked = True
            return sf
        except:
            raise Exception("{0}".format(data['error']))

'Like' a SharedFile. mlkshk doesn't allow you to unlike a
    sharedfile, so this is ~~permanent~~.

Args:
        sharekey (str): Sharekey for the file you want to 'like'.

Returns:
        Either a SharedFile on success, or an exception on error.


def compare_jsone_task_definition(parent_link, rebuilt_definitions):

    diffs = []
    for compare_definition in rebuilt_definitions['tasks']:
        # Rebuilt decision tasks have an extra `taskId`; remove
        if 'taskId' in compare_definition:
            del(compare_definition['taskId'])
        # remove key/value pairs where the value is empty, since json-e drops
        # them instead of keeping them with a None/{}/[] value.
        compare_definition = remove_empty_keys(compare_definition)
        runtime_definition = remove_empty_keys(parent_link.task)

        diff = list(dictdiffer.diff(compare_definition, runtime_definition))
        if diff:
            diffs.append(pprint.pformat(diff))
            continue
        log.info("{}: Good.".format(parent_link.name))
        break
    else:
        error_msg = "{} {}: the runtime task doesn't match any rebuilt definition!\n{}".format(
            parent_link.name, parent_link.task_id, pprint.pformat(diffs)
        )
        log.critical(error_msg)
        raise CoTError(error_msg)

Compare the json-e rebuilt task definition vs the runtime definition.

Args:
        parent_link (LinkOfTrust): the parent link to test.
        rebuilt_definitions (dict): the rebuilt task definitions.

Raises:
        CoTError: on failure.


def get_associated_resource(self, task):

        if not task:
            raise HPOneViewUnknownType(MSG_INVALID_TASK)

        if task['category'] != 'tasks' and task['category'] != 'backups':
            # it is an error if type is not in obj, so let the except flow
            raise HPOneViewUnknownType(MSG_UNKNOWN_OBJECT_TYPE)

        if task['type'] == 'TaskResourceV2':
            resource_uri = task['associatedResource']['resourceUri']

            if resource_uri and resource_uri.startswith("/rest/appliance/support-dumps/"):
                # Specific for support dumps
                return task, resource_uri

        elif task['type'] == 'BACKUP':
            task = self._connection.get(task['taskUri'])
            resource_uri = task['uri']
        else:
            raise HPOneViewInvalidResource(MSG_TASK_TYPE_UNRECONIZED % task['type'])

        entity = {}

        if resource_uri:
            entity = self._connection.get(resource_uri)

        return task, entity

Retrieve a resource associated with a task.

Args:
        task: task dict

Returns:
        tuple: task (updated), the entity found (dict)


def _module_info_from_proto_safe(module_info_def, import_scope=None):

  try:
    return _module_info_from_proto(module_info_def, import_scope)
  except Exception as e:  # pylint: disable=broad-except
    logging.warning(
        "Error encountered when deserializing sonnet ModuleInfo:\n%s", str(e))
    return None

Deserializes the `module_info_def` proto without raising exceptions.

Args:
        module_info_def: An instance of `module_pb2.SonnetModule`.
        import_scope: Optional `string`. Name scope to use.

Returns:
        An instance of `ModuleInfo`.


def _make_request(self, url, method="get", data=None, extra_headers=None):

        attempts = 0

        while attempts < 1:
            # Authenticate first if not authenticated already
            if not self._is_authenticated:
                self._authenticate()
            # Make the request and check for authentication errors
            # This allows us to catch session timeouts for long standing connections
            try:
                return self._send_request(url, method, data, extra_headers)
            except HTTPError as e:
                if e.response.status_code == 403:
                    logger.info("Authenticated session against NetMRI timed out. Retrying.")
                    self._is_authenticated = False
                    attempts += 1
                else:
                    # re-raise other HTTP errors
                    raise

Prepares the request, checks for authentication and retries in case of issues

Args:
        url (str): URL of the request
        method (str): Any of "get", "post", "delete"
        data (any): Possible extra data to send with the request
        extra_headers (dict): Possible extra headers to send along in the request

Returns:
        dict


def handleEvent(self, eventObj):

        if eventObj.type not in (MOUSEMOTION, MOUSEBUTTONUP, MOUSEBUTTONDOWN) or not self.visible:
            # The radioButton only cares bout mouse-related events (or no events, if it is invisible)
            return False

        if not self.isEnabled:
            return False

        clicked = False

        if (not self.mouseOverButton) and self.rect.collidepoint(eventObj.pos):
            # if mouse has entered the radioButton:
            self.mouseOverButton = True

        elif self.mouseOverButton and (not self.rect.collidepoint(eventObj.pos)):
            # if mouse has exited the radioButton:
            self.mouseOverButton = False

        if self.rect.collidepoint(eventObj.pos):

            if eventObj.type == MOUSEBUTTONDOWN:
                self.buttonDown = True
                self.lastMouseDownOverButton = True

        else:
            if eventObj.type in (MOUSEBUTTONUP, MOUSEBUTTONDOWN):
                # if an up/down happens off the radioButton, then the next up won't cause mouseClick()
                self.lastMouseDownOverButton = False

        if eventObj.type == MOUSEBUTTONDOWN:
            self.mouseIsDown = True

        # mouse up is handled whether or not it was over the radioButton
        doMouseClick = False
        if eventObj.type == MOUSEBUTTONUP:
            self.mouseIsDown = False
            if self.lastMouseDownOverButton:
                doMouseClick = True
            self.lastMouseDownOverButton = False

            if self.buttonDown:
                self.buttonDown = False

            if doMouseClick:
                self.buttonDown = False
                clicked = True

                # Turn all radio buttons in this group off
                for radioButton in PygWidgetsRadioButton.__PygWidgets__Radio__Buttons__Groups__Dicts__[self.group]:
                    radioButton.setValue(False)
                self.setValue(True)   # And turn the current one (the one that was clicked) on

                if self.playSoundOnClick:
                    self.soundOnClick.play()

        if clicked:
            if self.callBack is not None:
                self.callBack(self.nickname)

        return clicked

This method should be called every time through the main loop.

    It handles showing the up, over, and down states of the button.

    Parameters:
        | eventObj - the event object obtained by calling pygame.event.get()

Returns:
        | False most of the time
        | True when the user selects a radio button from the group


def is_link(url, processed, files):

    if url not in processed:
        is_file = url.endswith(BAD_TYPES)
        if is_file:
            files.add(url)
            return False
        return True
    return False

Determine whether or not a link should be crawled
    A url should not be crawled if it
        - Is a file
        - Has already been crawled

Args:
        url: str Url to be processed
        processed: list[str] List of urls that have already been crawled

Returns:
        bool If `url` should be crawled


def decode_varint(buffer, pos=0):

    result = buffer[pos]
    if not (result & 0x81):
        return (result >> 1), pos + 1
    if not (result & 0x80):
        return (result >> 1) ^ (~0), pos + 1

    result &= 0x7f
    pos += 1
    shift = 7
    while 1:
        b = buffer[pos]
        result |= ((b & 0x7f) << shift)
        pos += 1
        if not (b & 0x80):
            return ((result >> 1) ^ -(result & 1), pos)
        shift += 7
        if shift >= 64:
            raise ValueError("Out of int64 range")

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

Args:
            buffer (bytearry): buffer to read from.
            pos (int): optional position to read from

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