def fileLoad(self, filePath=None, updatePath=True):

        if not filePath:
            filePath = self.filePath
        if not os.path.isfile(filePath):
            raise FileNotFoundError("Data file '%s' does not exist." % (filePath))
        else:
            print("Importing existing data file '%s' ... " % (filePath), end="", flush=True)
            with open(filePath, "r") as q:
                data_raw = q.read()
            print("Imported!")
            self.data = json.loads(data_raw)
            if updatePath:
                self.filePath = filePath

Load a JSON data file into the internal JSON data dictionary.

    Current internal data will be overwritten.
    If no file path is provided, the stored data file path will be used.

Args:
        filePath (Optional[str]): A relative or absolute path to a
            '.json' file. Defaults to None.
        updatePath (Optional[bool]): Specifies whether or not to update
            the stored data file path. Defaults to True.


def calculate_etag(self, expected=None):

        md5s = []
        with open(self.filepath, 'rb') as fp:
            while True:
                data = fp.read(CHUNK_SIZE)
                if not data:
                    break
                md5s.append(hashlib.md5(data))

        digests = b"".join(m.digest() for m in md5s)

        new_md5 = hashlib.md5(digests)
        new_etag = '%s-%s' % (new_md5.hexdigest(),len(md5s))
        self.etag = new_etag

        return new_etag

calculates a multipart upload etag in the same way as amazon s3

Args:
        source_path -- The file to calculate the etage for
        chunk_size -- The chunk size to calculate for.
        expected -- optional If passed a string, the string
        will be compared to the resulting etag and raise an
        exception if they don't match


def get_unverified_claims(token):

    try:
        claims = jws.get_unverified_claims(token)
    except:
        raise JWTError('Error decoding token claims.')

    try:
        claims = json.loads(claims.decode('utf-8'))
    except ValueError as e:
        raise JWTError('Invalid claims string: %s' % e)

    if not isinstance(claims, Mapping):
        raise JWTError('Invalid claims string: must be a json object')

    return claims

Returns the decoded claims without verification of any kind.

Args:
        token (str): A signed JWT to decode the headers from.

Returns:
        dict: The dict representation of the token claims.

Raises:
        JWTError: If there is an exception decoding the token.


def __init__(self, resolver_context):

    super(CompressedStreamFileSystem, self).__init__(resolver_context)
    self._compression_method = None

Initializes a compressed stream file system.

Args:
        resolver_context (Context): a resolver context.


def drop(self, items):

        self._manager.leaser.remove(items)
        self._manager.maybe_resume_consumer()

Remove the given messages from lease management.

Args:
        items(Sequence[DropRequest]): The items to drop.


def update_entity(namespace, workspace, etype, ename, updates):

    headers = _fiss_agent_header({"Content-type":  "application/json"})
    uri = "{0}workspaces/{1}/{2}/entities/{3}/{4}".format(fcconfig.root_url,
                                            namespace, workspace, etype, ename)

    # FIXME: create __patch method, akin to __get, __delete etc
    return __SESSION.patch(uri, headers=headers, json=updates)

Update entity attributes in a workspace.

Args:
        namespace (str): project to which workspace belongs
        workspace (str): Workspace name
        etype     (str): Entity type
        ename     (str): Entity name
        updates   (list(dict)): List of updates to entity from _attr_set, e.g.

    Swagger:
        https://api.firecloud.org/#!/Entities/update_entity


def minimum(x1, x2, output_shape=None, name=None):

  output_shape = convert_to_shape(output_shape)
  with tf.name_scope(name, default_name="minimum"):
    x1, x2 = binary_arguments_to_tensors(x1, x2)
    return MinMaxOperation(
        tf.minimum, x1, x2, output_shape=_infer_binary_broadcast_shape(
            x1.shape, x2.shape, output_shape)).outputs[0]

Binary minimum with broadcsting.

Args:
        x1: a Tensor
        x2: a Tensor
        output_shape: an optional Shape
        name: an optional string

Returns:
        a Tensor


def get_by_resource(self, resource_uri):

        uri = self.URI + self.RESOURCES_PATH + '/' + resource_uri
        return self._client.get(id_or_uri=uri)

Gets all the labels for the specified resource

Args:
        resource_uri: The resource URI

Returns:
        dict: Resource Labels


def get_storage(self, contract_hash, storage_key, id=None, endpoint=None):

        result = self._call_endpoint(GET_STORAGE, params=[contract_hash, binascii.hexlify(storage_key.encode('utf-8')).decode('utf-8')], id=id, endpoint=endpoint)
        try:

            return bytearray(binascii.unhexlify(result.encode('utf-8')))
        except Exception as e:
            raise NEORPCException("could not decode result %s " % e)

Returns a storage item of a specified contract

Args:
        contract_hash: (str) hash of the contract to lookup, for example 'd7678dd97c000be3f33e9362e673101bac4ca654'
        storage_key: (str) storage key to lookup, for example 'totalSupply'
        id: (int, optional) id to use for response tracking
        endpoint: (RPCEndpoint, optional) endpoint to specify to use

Returns:
        bytearray: bytearray value of the storage item


def FormatArtifacts(self, artifacts):

    artifact_definitions = [artifact.AsDict() for artifact in artifacts]
    json_data = json.dumps(artifact_definitions)
    return json_data

Formats artifacts to desired output format.

Args:
        artifacts (list[ArtifactDefinition]): artifact definitions.

Returns:
        str: formatted string of artifact definition.


def join_room(self, room_id_or_alias):

        response = self.api.join_room(room_id_or_alias)
        room_id = (
            response["room_id"] if "room_id" in response else room_id_or_alias
        )
        return self._mkroom(room_id)

Join a room.

Args:
        room_id_or_alias (str): Room ID or an alias.

Returns:
        Room

Raises:
        MatrixRequestError


def _register(self, name, AttrCls):

        if not issubclass(AttrCls, StateAttr):
            raise TypeError("The second argument must a StateAttr instance.")
        if len(name) > 40:
            raise ValueError("Name can count at most 40 characters.")
        self._fields[name] = AttrCls(self._owner, name)

Register a new attribute to take care of with dump and load

Args:
    | ``name``  --  the name to be used in the dump file
    | ``AttrCls``  --  an attr class describing the attribute


def _generate_G_points(self, kpoint):

        gpoints = []
        for i in range(2 * self._nbmax[2] + 1):
            i3 = i - 2 * self._nbmax[2] - 1 if i > self._nbmax[2] else i
            for j in range(2 * self._nbmax[1] + 1):
                j2 = j - 2 * self._nbmax[1] - 1 if j > self._nbmax[1] else j
                for k in range(2 * self._nbmax[0] + 1):
                    k1 = k - 2 * self._nbmax[0] - 1 if k > self._nbmax[0] else k
                    G = np.array([k1, j2, i3])
                    v = kpoint + G
                    g = np.linalg.norm(np.dot(v, self.b))
                    E = g ** 2 / self._C
                    if E < self.encut:
                        gpoints.append(G)
        return np.array(gpoints, dtype=np.float64)

Helper function to generate G-points based on nbmax.

    This function iterates over possible G-point values and determines
    if the energy is less than G_{cut}. Valid values are appended to
    the output array. This function should not be called outside of
    initialization.

Args:
        kpoint (np.array): the array containing the current k-point value

Returns:
        a list containing valid G-points


def orient_undirected_graph(self, data, graph, **kwargs):

        # Building setup w/ arguments.
        self.arguments['{CITEST}'] = self.dir_CI_test[self.CI_test]
        self.arguments['{METHOD_INDEP}'] = self.dir_method_indep[self.method_indep]
        self.arguments['{DIRECTED}'] = 'TRUE'
        self.arguments['{ALPHA}'] = str(self.alpha)
        self.arguments['{NJOBS}'] = str(self.nb_jobs)
        self.arguments['{VERBOSE}'] = str(self.verbose).upper()

        fe = DataFrame(nx.adj_matrix(graph, weight=None).todense())
        fg = DataFrame(1 - fe.values)

        results = self._run_pc(data, fixedEdges=fe, fixedGaps=fg, verbose=self.verbose)

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

Run PC on an undirected graph.

Args:
        data (pandas.DataFrame): DataFrame containing the data
        graph (networkx.Graph): Skeleton of the graph to orient

Returns:
        networkx.DiGraph: Solution given by PC on the given skeleton.


def get(self, key):

        match = self._get_match(key=key)

        if not match:
            return None

        return self._get_value_from_match(key=key, match=match)

Gets the value of the property of the given key.

Args:
        key (str): Key of the property to look-up.


def show_stories(self, raw=False, limit=None):

        show_stories = self._get_stories('showstories', limit)
        if raw:
            show_stories = [story.raw for story in show_stories]
        return show_stories

Returns list of item ids of latest Show HN stories

Args:
        limit (int): specifies the number of stories to be returned.
        raw (bool): Flag to indicate whether to transform all
            objects into raw json.

Returns:
        `list` object containing ids of Show HN stories.


def get_extension_by_name(cert_obj, extension_name):

    try:
        return cert_obj.extensions.get_extension_for_oid(
            getattr(cryptography.x509.oid.ExtensionOID, extension_name)
        )
    except cryptography.x509.ExtensionNotFound:
        pass

Get a standard certificate extension by attribute name.

Args:
        cert_obj: cryptography.Certificate
        Certificate containing a standard extension.

        extension_name : str
        Extension name. E.g., 'SUBJECT_DIRECTORY_ATTRIBUTES'.

Returns:
        Cryptography.Extension


def _get_magic_menu(self,menuidentifier, menulabel=None):

        menu = self._magic_menu_dict.get(menuidentifier,None)
        if not menu :
            if not menulabel:
                menulabel = re.sub("([a-zA-Z]+)([A-Z][a-z])","\g<1> \g<2>",menuidentifier)
            menu = QtGui.QMenu(menulabel,self.magic_menu)
            self._magic_menu_dict[menuidentifier]=menu
            self.magic_menu.insertMenu(self.magic_menu_separator,menu)
        return menu

return a submagic menu by name, and create it if needed

    parameters:
    -----------

    menulabel : str
        Label for the menu

    Will infere the menu name from the identifier at creation if menulabel not given.
    To do so you have too give menuidentifier as a CamelCassedString


def get_day_end(config):

    day_start_datetime = datetime.datetime.combine(datetime.date.today(), config['day_start'])
    day_end_datetime = day_start_datetime - datetime.timedelta(seconds=1)
    return day_end_datetime.time()

Get the day end time given the day start. This assumes full 24h day.

Args:
        config (dict): Configdict. Needed to extract ``day_start``.

Note:
        This is merely a convinience funtion so we do not have to deduct this from ``day_start``
        by hand all the time.


def __init__(self, shape, min_value, max_value, alpha=0.0, beta=0.0, scope='beta', summary_labels=()):

        assert min_value is None or max_value > min_value
        self.shape = shape
        self.min_value = min_value
        self.max_value = max_value
        action_size = util.prod(self.shape)

        self.alpha = Linear(size=action_size, bias=alpha, scope='alpha', summary_labels=summary_labels)
        self.beta = Linear(size=action_size, bias=beta, scope='beta', summary_labels=summary_labels)

        super(Beta, self).__init__(shape=shape, scope=scope, summary_labels=summary_labels)

Beta distribution.

Args:
        shape: Action shape.
        min_value: Minimum value of continuous actions.
        max_value: Maximum value of continuous actions.
        alpha: Optional distribution bias for the alpha value.
        beta: Optional distribution bias for the beta value.


def get_email_message(self, message_uid, message_type="text/plain"):

        self._mail.select("inbox")
        result = self._mail.uid('fetch', message_uid, "(RFC822)")
        msg = email.message_from_string(result[1][0][1])

        try:
            # Try to handle as multipart message first.
            for part in msg.walk():
                if part.get_content_type() == message_type:
                    return part.get_payload(decode=True)
        except:
            # handle as plain text email
            return msg.get_payload(decode=True)

Fetch contents of email.

Args:
        message_uid (int): IMAP Message UID number.

    Kwargs:
        message_type: Can be 'text' or 'html'


def __init__(self, dataset_merger, problem_type=transitfeed.TYPE_WARNING,
               **kwargs):

    kwargs['type'] = problem_type
    kwargs['entity_type_name'] = dataset_merger.ENTITY_TYPE_NAME
    transitfeed.ExceptionWithContext.__init__(self, None, None, **kwargs)
    self.dataset_merger = dataset_merger

Initialise the exception object.

Args:
        dataset_merger: The DataSetMerger instance that generated this problem.
        problem_type: The problem severity. This should be set to one of the
                    corresponding constants in transitfeed.
        kwargs: Keyword arguments to be saved as instance attributes.


def _page(self, text, html=False):

        line_height = QtGui.QFontMetrics(self.font).height()
        minlines = self._control.viewport().height() / line_height
        if self.paging != 'none' and \
                re.match("(?:[^\n]*\n){%i}" % minlines, text):
            if self.paging == 'custom':
                self.custom_page_requested.emit(text)
            else:
                self._page_control.clear()
                cursor = self._page_control.textCursor()
                if html:
                    self._insert_html(cursor, text)
                else:
                    self._insert_plain_text(cursor, text)
                self._page_control.moveCursor(QtGui.QTextCursor.Start)

                self._page_control.viewport().resize(self._control.size())
                if self._splitter:
                    self._page_control.show()
                    self._page_control.setFocus()
                else:
                    self.layout().setCurrentWidget(self._page_control)
        elif html:
            self._append_html(text)
        else:
            self._append_plain_text(text)

Displays text using the pager if it exceeds the height of the
    viewport.

    Parameters:
    -----------
    html : bool, optional (default False)
        If set, the text will be interpreted as HTML instead of plain text.


def transformer_text_encoder(inputs,
                             target_space,
                             hparams,
                             name=None):

  with tf.variable_scope(name, default_name="transformer_text_encoder"):
    inputs = common_layers.flatten4d3d(inputs)
    [
        encoder_input,
        encoder_self_attention_bias,
        ed,
    ] = transformer_layers.transformer_prepare_encoder(
        inputs, target_space=target_space, hparams=hparams)
    encoder_input = tf.nn.dropout(encoder_input, 1.0 - hparams.dropout)
    encoder_output = transformer_layers.transformer_encoder(
        encoder_input, encoder_self_attention_bias, hparams)
    return encoder_output, ed

Transformer text encoder over inputs with unmasked full attention.

Args:
        inputs: Tensor of shape [batch, length, 1, hparams.hidden_size].
        target_space: int. Used for encoding inputs under a target space id.
        hparams: HParams.
        name: string, variable scope.

Returns:
        encoder_output: Tensor of shape [batch, length, hparams.hidden_size].
        ed: Tensor of shape [batch, 1, 1, length]. Encoder-decoder attention bias
        for any padded tokens.


def getGUA(self, filterByPrefix=None):

        print '%s call getGUA' % self.port
        print filterByPrefix
        globalAddrs = []
        try:
            # get global addrs set if multiple
            globalAddrs = self.getGlobal()

            if filterByPrefix is None:
                return self.__padIp6Addr(globalAddrs[0])
            else:
                for line in globalAddrs:
                    line = self.__padIp6Addr(line)
                    print "Padded IPv6 Address:" + line
                    if line.startswith(filterByPrefix):
                        return line
                print 'no global address matched'
                return str(globalAddrs[0])
        except Exception, e:
            ModuleHelper.WriteIntoDebugLogger('getGUA() Error: ' + str(e))
            return e

get expected global unicast IPv6 address of OpenThreadWpan

Args:
        filterByPrefix: a given expected global IPv6 prefix to be matched

Returns:
        a global IPv6 address


def __init__(self, source_path):

        self.source_path = source_path
        self.package = get_developer_package(source_path)
        self.type_settings = self.package.config.plugins.release_hook
        self.settings = self.type_settings.get(self.name())

Create a release hook.

Args:
        source_path: Path containing source that was released.


def allconcat_ring(xs, devices, concat_axis):

  n = len(xs)
  if n == 1:
    return xs
  # [target, source]
  parts = [[xs[target] if target == source else None for source in xrange(n)]
           for target in xrange(n)]
  for distance in xrange(1, n // 2 + 1):
    for target in xrange(n):
      source = (target + distance) % n
      if parts[target][source] is None:
        with tf.device(devices[target]):
          parts[target][source] = tf.identity(parts[(target + 1) % n][source])
      source = (target - distance) % n
      if parts[target][source] is None:
        with tf.device(devices[target]):
          parts[target][source] = tf.identity(parts[(target - 1) % n][source])
  return mtf.parallel(devices, tf.concat, parts, axis=[concat_axis] * n)

Concatenate all Tensors everywhere.

    Performance-optimized for a ring of devices.

Args:
        xs: a list of n tf.Tensors
        devices: a list of n strings
        concat_axis: an integer

Returns:
        a list of n Tensors


def __init__(self, ethertype=None):

        super().__init__(action_type=ActionType.OFPAT_POP_MPLS)
        self.ethertype = ethertype

Create an ActionPopMPLS with the optional parameters below.

Args:
        ethertype (int): indicates the Ethertype of the payload.


def new_cells(self, name=None, formula=None):

        # Outside formulas only
        return self._impl.new_cells(name, formula).interface

Create a cells in the space.

Args:
        name: If omitted, the model is named automatically ``CellsN``,
            where ``N`` is an available number.
        func: The function to define the formula of the cells.

Returns:
        The new cells.


def do_REMOTE(self,
                  target: str,
                  remote_command: str,
                  source: list,
                  *args,
                  **kwargs) -> None:

        if target == self.messaging._service_name:
            info = 'target for remote command is the bot itself! Returning the function'
            self.logger.info(info)
            return self._handle_command(remote_command, source, *args, **kwargs)

        try:
            target = self.messaging._address_map[target]
        except KeyError:
            warn = ' Target %s, not found in addresses. Are you sure that %s sent an IDENT message?'
            self.logger.warn(warn, target, target)
            # TODO: raise an error instead of returning?
            # NOTE: Bail here since there's no point in going forward
            return

        self.logger.info(' REMOTE %s, target: %s | %s, %s',
                         remote_command, target, args, kwargs)

        # package the binary together
        source = target + source
        self.messaging.send_command_response(source,
                                             remote_command,
                                             *args,
                                             **kwargs)

Send a remote command to a service. Used

Args:
        target: The service that the command gets set to
        remote_command: The command to do remotely.
        source: the binary source of the zmq_socket. Packed to send to the


def __init__(self, latitude, longitude, comment=None):

        super(Xearth, self).__init__(latitude, longitude)
        self.comment = comment

Initialise a new ``Xearth`` object.

Args:
        latitude (float): Location's latitude
        longitude (float): Location's longitude
        comment (str): Comment for location


def get_without(self, fragments,
                    use_lookup=None):

        if use_lookup is None:
            use_lookup = settings['defaults']['use_lookup']

        if pd.api.types.is_list_like(fragments):
            for fragment in fragments:
                try:
                    index_of_all_fragments |= fragment.index
                except NameError:
                    index_of_all_fragments = fragment.index
        else:
            index_of_all_fragments = fragments.index
        missing_part = self.loc[self.index.difference(index_of_all_fragments)]
        missing_part = missing_part.fragmentate(use_lookup=use_lookup)
        return sorted(missing_part, key=len, reverse=True)

Return self without the specified fragments.

Args:
        fragments: Either a list of :class:`~chemcoord.Cartesian` or a
            :class:`~chemcoord.Cartesian`.
        use_lookup (bool): Use a lookup variable for
            :meth:`~chemcoord.Cartesian.get_bonds`. The default is
            specified in ``settings['defaults']['use_lookup']``

Returns:
        list: List containing :class:`~chemcoord.Cartesian`.


def __init__(self, _args):

        super(TcExLib, self).__init__(_args)

        # properties
        self.latest_version = None
        self.lib_directory = 'lib_{}.{}.{}'.format(
            sys.version_info.major, sys.version_info.minor, sys.version_info.micro
        )
        self.requirements_file = 'requirements.txt'
        self.static_lib_dir = 'lib_latest'
        self.use_temp_requirements_file = False

Initialize Class properties.

Args:
        _args (namespace): The argparser args Namespace.


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

  src_dir = "pos{}".format(version)
  p = locate_resource(src_dir, lang)
  fh = _open(p)
  return dict(np.load(fh))

Return a part of speech tagger parameters for `lang` and of version `version`

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


def get_diff_coeff(hvec, n=1):

    hvec = np.array(hvec, dtype=np.float)
    acc = len(hvec)
    exp = np.column_stack([np.arange(acc)]*acc)
    a = np.vstack([hvec] * acc) ** exp
    b = np.zeros(acc)
    b[n] = factorial(n)
    return np.linalg.solve(a, b)

Helper function to find difference coefficients of an
    derivative on an arbitrary mesh.

Args:
        hvec (1D array-like): sampling stencil
        n (int): degree of derivative to find


def submit_evaluation(self, variant_obj, user_obj, institute_obj, case_obj, link, criteria):

        variant_specific = variant_obj['_id']
        variant_id = variant_obj['variant_id']
        user_id = user_obj['_id']
        user_name = user_obj.get('name', user_obj['_id'])
        institute_id = institute_obj['_id']
        case_id = case_obj['_id']

        evaluation_terms = [evluation_info['term'] for evluation_info in criteria]

        classification = get_acmg(evaluation_terms)

        evaluation_obj = build_evaluation(
            variant_specific=variant_specific,
            variant_id=variant_id,
            user_id=user_id,
            user_name=user_name,
            institute_id=institute_id,
            case_id=case_id,
            classification=classification,
            criteria=criteria
        )

        self._load_evaluation(evaluation_obj)

        # Update the acmg classification for the variant:
        self.update_acmg(institute_obj, case_obj, user_obj, link, variant_obj, classification)
        return classification

Submit an evaluation to the database

    Get all the relevant information, build a evaluation_obj

Args:
        variant_obj(dict)
        user_obj(dict)
        institute_obj(dict)
        case_obj(dict)
        link(str): variant url
        criteria(list(dict)):

            [
        {
        'term': str,
        'comment': str,
        'links': list(str)
        },
        .
        .
    ]


def get_attribute_label(
        self, main_type, sub_type, unique_id, attribute_id, label, owner=None, params=None
    ):

        return self.attribute_label(
            main_type, sub_type, unique_id, attribute_id, label, owner=owner, params=params
        )

Args:
    owner:
    main_type:
    sub_type:
    unique_id:
    attribute_id:
    label:
    params:

    Return:


def _get_job_resources(args):

  logging = param_util.build_logging_param(
      args.logging) if args.logging else None
  timeout = param_util.timeout_in_seconds(args.timeout)
  log_interval = param_util.log_interval_in_seconds(args.log_interval)

  return job_model.Resources(
      min_cores=args.min_cores,
      min_ram=args.min_ram,
      machine_type=args.machine_type,
      disk_size=args.disk_size,
      disk_type=args.disk_type,
      boot_disk_size=args.boot_disk_size,
      preemptible=args.preemptible,
      image=args.image,
      regions=args.regions,
      zones=args.zones,
      logging=logging,
      logging_path=None,
      service_account=args.service_account,
      scopes=args.scopes,
      keep_alive=args.keep_alive,
      cpu_platform=args.cpu_platform,
      network=args.network,
      subnetwork=args.subnetwork,
      use_private_address=args.use_private_address,
      accelerator_type=args.accelerator_type,
      accelerator_count=args.accelerator_count,
      nvidia_driver_version=args.nvidia_driver_version,
      timeout=timeout,
      log_interval=log_interval,
      ssh=args.ssh)

Extract job-global resources requirements from input args.

Args:
        args: parsed command-line arguments

Returns:
        Resources object containing the requested resources for the job


def from_dir(cls, top, exts=None, exclude_dirs="_*"):

        pseudos = []

        if exts == "all_files":
            for f in [os.path.join(top, fn) for fn in os.listdir(top)]:
                if os.path.isfile(f):
                    try:
                        p = Pseudo.from_file(f)
                        if p:
                            pseudos.append(p)
                        else:
                            logger.info('Skipping file %s' % f)
                    except:
                        logger.info('Skipping file %s' % f)
            if not pseudos:
                logger.warning('No pseudopotentials parsed from folder %s' % top)
                return None
            logger.info('Creating PseudoTable with %i pseudopotentials' % len(pseudos))

        else:
            if exts is None: exts=("psp8",)

            for p in find_exts(top, exts, exclude_dirs=exclude_dirs):
                try:
                    pseudos.append(Pseudo.from_file(p))
                except Exception as exc:
                    logger.critical("Error in %s:\n%s" % (p, exc))

        return cls(pseudos).sort_by_z()

Find all pseudos in the directory tree starting from top.

Args:
        top: Top of the directory tree
        exts: List of files extensions. if exts == "all_files"
                we try to open all files in top
        exclude_dirs: Wildcard used to exclude directories.

    return: :class:`PseudoTable` sorted by atomic number Z.


def response(uri, method, res, token='', keyword='',
             content='', raw_flag=False):

    if method == 'GET' or (method == 'PUT' and not token):
        # response body
        data = res.read()
        data_utf8 = data.decode('utf-8')
        if token:
            datas = json.loads(data_utf8)
        else:
            token = json.loads(data_utf8)['hash']
            return token

        if keyword == 'serial':
            # filtering with keyword
            record = search_record(datas, 'SOA')[0]

            # if SOA record, remove priority unnecessary
            del record['priority']

            # override ttl
            record['ttl'] = int(record['ttl'])

            c = JSONConverter(content['domain'])
            new_record = c.get_soa(record, content)
            return record, new_record

        elif keyword:
            # '--search' option of 'get' subcommand
            records = search_record(datas, keyword)
            datas.update({"records": records})

        if uri.split('/')[3] == 'template':
            # 'tmpl_get' subcommand

            if len(uri.split('/')) == 5:
                # when specify template identfier
                #print_formatted(datas)
                utils.pretty_print(datas)

            else:
                # when get all templates
                for data in datas:
                    #print_formatted(data)
                    utils.pretty_print(datas)

        else:
            # 'get' subcommand
            if raw_flag:
                return datas
            else:
                #print_formatted(datas)
                if len(uri.split('zone/')) > 1:
                    domain = uri.split('zone/')[1]
                else:
                    domain = ''
                utils.pretty_print(datas, keyword, domain)

    else:
        # response non JSON data
        data = res.read()
        print(data)

Response of tonicdns_client request

Args:
        uri:      TonicDNS API URI
        method:   TonicDNS API request method
        res:      Response of against request to TonicDNS API
        token:    TonicDNS API token
        keyword:  Processing keyword
        content:  JSON data
        raw_flag: True is return responsed raw data, False is pretty print


def _FormatSourceShort(self, event):

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

    return source_short

Formats the short source.

Args:
        event (EventObject): event.

Returns:
        str: short source field.

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


def set_log_level(verbose, quiet):

    if quiet:
        verbose = -1
    if verbose < 0:
        verbose = logging.CRITICAL
    elif verbose == 0:
        verbose = logging.WARNING
    elif verbose == 1:
        verbose = logging.INFO
    elif 1 < verbose:
        verbose = logging.DEBUG
    LOGGER.setLevel(verbose)

Ses the logging level of the script based on command line options.

Args:
    - `verbose`:
    - `quiet`:


def name(self):

        return ctypes.cast(self.sName, ctypes.c_char_p).value.decode()

Returns the name of the device.

Args:
        self (JLinkDeviceInfo): the ``JLinkDeviceInfo`` instance

Returns:
        Device name.


def verify(self, obj):

        if not isinstance(obj, int):
            raise ValidationError("Object is not a int", reason='object is not a int', object=obj,
                                  type=type(obj), int_type=int)

        return obj

Verify that the object conforms to this verifier's schema

Args:
        obj (object): A python object to verify

Raises:
        ValidationError: If there is a problem verifying the dictionary, a
            ValidationError is thrown with at least the reason key set indicating
            the reason for the lack of validation.


def _ProcessSources(
      self, source_path_specs, extraction_worker, parser_mediator,
      storage_writer, filter_find_specs=None):

    if self._processing_profiler:
      self._processing_profiler.StartTiming('process_sources')

    number_of_consumed_sources = 0

    self._UpdateStatus(
        definitions.STATUS_INDICATOR_COLLECTING, '',
        number_of_consumed_sources, storage_writer)

    display_name = ''
    path_spec_generator = self._path_spec_extractor.ExtractPathSpecs(
        source_path_specs, find_specs=filter_find_specs,
        recurse_file_system=False,
        resolver_context=parser_mediator.resolver_context)

    for path_spec in path_spec_generator:
      if self._abort:
        break

      display_name = parser_mediator.GetDisplayNameForPathSpec(path_spec)

      # TODO: determine if event sources should be DataStream or FileEntry
      # or both.
      event_source = event_sources.FileEntryEventSource(path_spec=path_spec)
      storage_writer.AddEventSource(event_source)

      self._UpdateStatus(
          definitions.STATUS_INDICATOR_COLLECTING, display_name,
          number_of_consumed_sources, storage_writer)

    # Force the status update here to make sure the status is up to date.
    self._UpdateStatus(
        definitions.STATUS_INDICATOR_RUNNING, display_name,
        number_of_consumed_sources, storage_writer, force=True)

    if self._processing_profiler:
      self._processing_profiler.StartTiming('get_event_source')

    event_source = storage_writer.GetFirstWrittenEventSource()

    if self._processing_profiler:
      self._processing_profiler.StopTiming('get_event_source')

    while event_source:
      if self._abort:
        break

      self._ProcessPathSpec(
          extraction_worker, parser_mediator, event_source.path_spec)
      number_of_consumed_sources += 1

      if self._guppy_memory_profiler:
        self._guppy_memory_profiler.Sample()

      self._UpdateStatus(
          extraction_worker.processing_status, self._current_display_name,
          number_of_consumed_sources, storage_writer)

      if self._processing_profiler:
        self._processing_profiler.StartTiming('get_event_source')

      event_source = storage_writer.GetNextWrittenEventSource()

      if self._processing_profiler:
        self._processing_profiler.StopTiming('get_event_source')

    if self._abort:
      status = definitions.STATUS_INDICATOR_ABORTED
    else:
      status = definitions.STATUS_INDICATOR_COMPLETED

    # Force the status update here to make sure the status is up to date
    # on exit.
    self._UpdateStatus(
        status, '', number_of_consumed_sources, storage_writer, force=True)

    if self._processing_profiler:
      self._processing_profiler.StopTiming('process_sources')

Processes the sources.

Args:
        source_path_specs (list[dfvfs.PathSpec]): path specifications of
        the sources to process.
        extraction_worker (worker.ExtractionWorker): extraction worker.
        parser_mediator (ParserMediator): parser mediator.
        storage_writer (StorageWriter): storage writer for a session storage.
        filter_find_specs (Optional[list[dfvfs.FindSpec]]): find specifications
        used in path specification extraction.


def setSwarmState(self, swarmId, newStatus):

    assert (newStatus in ['active', 'completing', 'completed', 'killed'])

    # Set the swarm status
    swarmInfo = self._state['swarms'][swarmId]
    if swarmInfo['status'] == newStatus:
      return

    # If some other worker noticed it as completed, setting it to completing
    #  is obviously old information....
    if swarmInfo['status'] == 'completed' and newStatus == 'completing':
      return

    self._dirty = True
    swarmInfo['status'] = newStatus
    if newStatus == 'completed':
      (modelId, errScore) = self._hsObj._resultsDB.bestModelIdAndErrScore(swarmId)
      swarmInfo['bestModelId'] = modelId
      swarmInfo['bestErrScore'] = errScore

    # If no longer active, remove it from the activeSwarms entry
    if newStatus != 'active' and swarmId in self._state['activeSwarms']:
      self._state['activeSwarms'].remove(swarmId)

    # If new status is 'killed', kill off any running particles in that swarm
    if newStatus=='killed':
      self._hsObj.killSwarmParticles(swarmId)

    # In case speculative particles are enabled, make sure we generate a new
    #  swarm at this time if all of the swarms in the current sprint have
    #  completed. This will insure that we don't mark the sprint as completed
    #  before we've created all the possible swarms.
    sprintIdx = swarmInfo['sprintIdx']
    self.isSprintActive(sprintIdx)

    # Update the sprint status. Check all the swarms that belong to this sprint.
    #  If they are all completed, the sprint is completed.
    sprintInfo = self._state['sprints'][sprintIdx]

    statusCounts = dict(active=0, completing=0, completed=0, killed=0)
    bestModelIds = []
    bestErrScores = []
    for info in self._state['swarms'].itervalues():
      if info['sprintIdx'] != sprintIdx:
        continue
      statusCounts[info['status']] += 1
      if info['status'] == 'completed':
        bestModelIds.append(info['bestModelId'])
        bestErrScores.append(info['bestErrScore'])

    if statusCounts['active'] > 0:
      sprintStatus = 'active'
    elif statusCounts['completing'] > 0:
      sprintStatus = 'completing'
    else:
      sprintStatus = 'completed'
    sprintInfo['status'] = sprintStatus

    # If the sprint is complete, get the best model from all of its swarms and
    #  store that as the sprint best
    if sprintStatus == 'completed':
      if len(bestErrScores) > 0:
        whichIdx = numpy.array(bestErrScores).argmin()
        sprintInfo['bestModelId'] = bestModelIds[whichIdx]
        sprintInfo['bestErrScore'] = bestErrScores[whichIdx]
      else:
        # This sprint was empty, most likely because all particles were
        #  killed. Give it a huge error score
        sprintInfo['bestModelId'] = 0
        sprintInfo['bestErrScore'] = numpy.inf

      # See if our best err score got NO BETTER as compared to a previous
      #  sprint. If so, stop exploring subsequent sprints (lastGoodSprint
      #  is no longer None).
      bestPrior = numpy.inf
      for idx in range(sprintIdx):
        if self._state['sprints'][idx]['status'] == 'completed':
          (_, errScore) = self.bestModelInCompletedSprint(idx)
          if errScore is None:
            errScore = numpy.inf
        else:
          errScore = numpy.inf
        if errScore < bestPrior:
          bestPrior = errScore

      if sprintInfo['bestErrScore'] >= bestPrior:
        self._state['lastGoodSprint'] = sprintIdx-1

      # If ALL sprints up to the last good one are done, the search is now over
      if self._state['lastGoodSprint'] is not None \
            and not self.anyGoodSprintsActive():
        self._state['searchOver'] = True

Change the given swarm's state to 'newState'. If 'newState' is
    'completed', then bestModelId and bestErrScore must be provided.

    Parameters:
    ---------------------------------------------------------------------
    swarmId:      swarm Id
    newStatus:    new status, either 'active', 'completing', 'completed', or
                    'killed'


def create_s3_bucket(cls, bucket_name, bucket_region, bucket_account, template):

        s3 = get_aws_session(bucket_account).client('s3', region_name=bucket_region)

        # Check to see if the bucket already exists and if we have access to it
        try:
            s3.head_bucket(Bucket=bucket_name)
        except ClientError as ex:
            status_code = ex.response['ResponseMetadata']['HTTPStatusCode']

            # Bucket exists and we do not have access
            if status_code == 403:
                raise Exception('Bucket {} already exists but we do not have access to it and so cannot continue'.format(
                    bucket_name
                ))

            # Bucket does not exist, lets create one
            elif status_code == 404:
                try:
                    s3.create_bucket(
                        Bucket=bucket_name,
                        CreateBucketConfiguration={
                            'LocationConstraint': bucket_region
                        }
                    )

                    auditlog(
                        event='cloudtrail.create_s3_bucket',
                        actor=cls.ns,
                        data={
                            'account': bucket_account.account_name,
                            'bucket_region': bucket_region,
                            'bucket_name': bucket_name
                        }
                    )
                except Exception:
                    raise Exception('An error occured while trying to create the bucket, cannot continue')

        try:
            bucket_acl = template.render(
                bucket_name=bucket_name,
                account_id=bucket_account.account_number
            )
            s3.put_bucket_policy(Bucket=bucket_name, Policy=bucket_acl)

        except Exception as ex:
            raise Warning('An error occurred while setting bucket policy: {}'.format(ex))

Creates the S3 bucket on the account specified as the destination account for log files

Args:
        bucket_name (`str`): Name of the S3 bucket
        bucket_region (`str`): AWS Region for the bucket
        bucket_account (:obj:`Account`): Account to create the S3 bucket in
        template (:obj:`Template`): Jinja2 Template object for the bucket policy

Returns:
        `None`


def send_email_message(self, recipient, subject, html_message, text_message, sender_email, sender_name):

        if not current_app.testing:  # pragma: no cover
            try:
                # Prepare Sendgrid helper objects
                from sendgrid.helpers.mail import Email, Content, Substitution, Mail
                from_email = Email(sender_email, sender_name)
                to_email = Email(recipient)
                text_content = Content('text/plain', text_message)
                html_content = Content('text/html', html_message)
                # Prepare Sendgrid Mail object
                # Note: RFC 1341: text must be first, followed by html
                mail = Mail(from_email, subject, to_email, text_content)
                mail.add_content(html_content)
                # Send mail via the Sendgrid API
                response = self.sg.client.mail.send.post(request_body=mail.get())
                print(response.status_code)
                print(response.body)
                print(response.headers)
            except ImportError:
                raise ConfigError(SENDGRID_IMPORT_ERROR_MESSAGE)
            except Exception as e:
                print(e)
                print(e.body)
                raise

Send email message via sendgrid-python.

Args:
        recipient: Email address or tuple of (Name, Email-address).
        subject: Subject line.
        html_message: The message body in HTML.
        text_message: The message body in plain text.


def new(self):
        # type: () -> None

        if self._initialized:
            raise pycdlibexception.PyCdlibInternalError('PD record already initialized!')

        self._initialized = True
        self.padding = b''

Create a new Rock Ridge Platform Dependent record.

    Parameters:
    None.

Returns:
    Nothing.


def write_inputs(self, output_dir, **kwargs):

        write_lammps_inputs(output_dir=output_dir,
                            script_template=self.script_template,
                            settings=self.settings, data=self.data,
                            script_filename=self.script_filename, **kwargs)

Writes all input files (input script, and data if needed).
    Other supporting files are not handled at this moment.

Args:
        output_dir (str): Directory to output the input files.
        **kwargs: kwargs supported by LammpsData.write_file.


def search(self, query, verbose=0):

        if verbose > 0:
            print("searching " + query)
        query = query.lower()
        qgram = ng(query, self.slb)
        qocument = set()
        for q in qgram:
            if q in self.ngrams.keys():
                for i in self.ngrams[q]:
                    qocument.add(i)
        self.qocument = qocument
        results = {}
        for i in qocument:
           for j in self.D[i].keys():
                if not j in results.keys():
                    results[j] = 0
                results[j] = results[j] + self.D[i][j]
        sorted_results = sorted(results.items(), key=operator.itemgetter(1), reverse=True)
        return [self.elements[f[0]] for f in sorted_results]

Searches files satisfying query

    It first decompose the query in ngrams, then score each document containing
    at least one ngram with the number. The ten document having the most ngrams
    in common with the query are selected.

Args:
        query (str): what to search;
        results_number (int): number of results to return (default: 10)


def __init__(self, endpoint_name, sagemaker_session=None):

        super(ChainerPredictor, self).__init__(endpoint_name, sagemaker_session, npy_serializer, numpy_deserializer)

Initialize an ``ChainerPredictor``.

Args:
        endpoint_name (str): The name of the endpoint to perform inference on.
        sagemaker_session (sagemaker.session.Session): Session object which manages interactions with
            Amazon SageMaker APIs and any other AWS services needed. If not specified, the estimator creates one
            using the default AWS configuration chain.


def extend(*args):

    if not args:
        return {}

    first = args[0]
    rest = args[1:]
    out = type(first)(first)
    for each in rest:
        out.update(each)
    return out

shallow dictionary merge

Args:
        a: dict to extend
        b: dict to apply to a

Returns:
        new instance of the same type as _a_, with _a_ and _b_ merged.


def _from_axis_angle(cls, axis, angle):

        mag_sq = np.dot(axis, axis)
        if mag_sq == 0.0:
            raise ZeroDivisionError("Provided rotation axis has no length")
        # Ensure axis is in unit vector form
        if (abs(1.0 - mag_sq) > 1e-12):
            axis = axis / sqrt(mag_sq)
        theta = angle / 2.0
        r = cos(theta)
        i = axis * sin(theta)

        return cls(r, i[0], i[1], i[2])

Initialise from axis and angle representation

    Create a Quaternion by specifying the 3-vector rotation axis and rotation
    angle (in radians) from which the quaternion's rotation should be created.

    Params:
        axis: a valid numpy 3-vector
        angle: a real valued angle in radians


def noise_get_fbm(
    n: tcod.noise.Noise,
    f: Sequence[float],
    oc: float,
    typ: int = NOISE_DEFAULT,
) -> float:

    return float(
        lib.TCOD_noise_get_fbm_ex(n.noise_c, ffi.new("float[4]", f), oc, typ)
    )

Return the fractal Brownian motion sampled from the ``f`` coordinate.

Args:
        n (Noise): A Noise instance.
        f (Sequence[float]): The point to sample the noise from.
        typ (int): The noise algorithm to use.
        octaves (float): The level of level.  Should be more than 1.

Returns:
        float: The sampled noise value.


def add_candidate_peer_endpoints(self, peer_endpoints):

        with self._lock:
            for endpoint in peer_endpoints:
                if endpoint not in self._candidate_peer_endpoints:
                    self._candidate_peer_endpoints.append(endpoint)

Adds candidate endpoints to the list of endpoints to
    attempt to peer with.

Args:
        peer_endpoints ([str]): A list of public uri's which the
            validator can attempt to peer with.


def _process_dataset(name, directory, num_shards, synset_to_human,
                     image_to_bboxes):

  filenames, synsets, labels = _find_image_files(directory, FLAGS.labels_file)
  humans = _find_human_readable_labels(synsets, synset_to_human)
  bboxes = _find_image_bounding_boxes(filenames, image_to_bboxes)
  _process_image_files(name, filenames, synsets, labels,
                       humans, bboxes, num_shards)

Process a complete data set and save it as a TFRecord.

Args:
        name: string, unique identifier specifying the data set.
        directory: string, root path to the data set.
        num_shards: integer number of shards for this data set.
        synset_to_human: dict of synset to human labels, e.g.,
        'n02119022' --> 'red fox, Vulpes vulpes'
        image_to_bboxes: dictionary mapping image file names to a list of
        bounding boxes. This list contains 0+ bounding boxes.


def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):

        local_stream = utils.BytearrayStream()

        if self._unique_identifier is not None:
            self._unique_identifier.write(
                local_stream,
                kmip_version=kmip_version
            )
        if self._offset is not None:
            self._offset.write(local_stream, kmip_version=kmip_version)
        if self._template_attribute is not None:
            self._template_attribute.write(
                local_stream,
                kmip_version=kmip_version
            )

        self.length = local_stream.length()
        super(RekeyRequestPayload, self).write(
            output_stream,
            kmip_version=kmip_version
        )
        output_stream.write(local_stream.buffer)

Write the data encoding the Rekey request payload to a stream.

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


def duration_to_string(duration):

    m, s = divmod(duration, 60)
    h, m = divmod(m, 60)
    return "%d:%02d:%02d" % (h, m, s)

Converts a duration to a string

Args:
        duration (int): The duration in seconds to convert

    Returns s (str): The duration as a string


def forward(self, device_port, local_port=None):

        port = self._adb_device.forward(device_port, local_port)
        return (self._host, port)

Forward device port to local

Args:
        device_port: port inside device
        local_port: port on PC, if this value is None, a port will random pick one.

Returns:
        tuple, (host, local_port)


def _read_accept_states(self):

        states = []
        i = 0
        regex = re.compile('[ \t\n\r:,]+')
        found = 0  # For maintaining the state of yy_accept declaration
        state = 0  # For maintaining the state of opening and closing tag of yy_accept
        mapping = [] # For writing each set of yy_accept
        cur_line = None
        with open(self.outfile) as flex_file:
            for cur_line in flex_file:
                if cur_line[0:37] == "static yyconst flex_int16_t yy_accept" or cur_line[0:35] == "static const flex_int16_t yy_accept":
                    found = 1
                    continue
                if found == 1:
                    # print x
                    if state == 0 and cur_line[0:5] == "    {":
                        mapping.append(0)  # there is always a zero there
                        state = 1
                        continue

                    if state == 1:
                        if cur_line[0:7] != "    } ;":
                            cur_line = "".join(cur_line.split())
                            if cur_line == '':
                                continue
                            if cur_line[cur_line.__len__() - 1] == ',':
                                splitted_line = regex.split(
                                    cur_line[:cur_line.__len__() - 1])
                            else:
                                splitted_line = regex.split(cur_line)
                            mapping = mapping + splitted_line
                            continue
                        else:
                            cleared = []
                            for j in mapping:
                                cleared.append(int(j))
                            max_value = max(cleared)
                            for i in range(0, len(cleared)):
                                if cleared[i] > 0 and cleared[
                                        i] < (max_value - 1):
                                    states.append(i)
                            return states
        return []

Read DFA accepted states from flex compiled file

Args:
        None

Returns:
        list: The list of accepted states


def loopUntil(
            self, condition=None, timeout: float = 0) -> Iterator[object]:

        endTime = time.time() + timeout
        while True:
            test = condition and condition()
            if test:
                yield test
                return
            elif timeout and time.time() > endTime:
                yield False
                return
            else:
                yield test
            self.waitOnUpdate(endTime - time.time() if timeout else 0)

Iterate until condition is met, with optional timeout in seconds.
    The yielded value is that of the condition or False when timed out.

Args:
        condition: Predicate function that is tested after every network
        update.
        timeout: Maximum time in seconds to wait.
            If 0 then no timeout is used.


def _add_function(self, func, identify_observed):

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

Add a function as an observer.

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

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


def ohlc(symbol, token='', version=''):

    _raiseIfNotStr(symbol)
    return _getJson('stock/' + symbol + '/ohlc', token, version)

Returns the official open and close for a give symbol.

    https://iexcloud.io/docs/api/#news
    9:30am-5pm ET Mon-Fri

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

Returns:
        dict: result


def back_propagation(self, delta_arr):

        re_encoder_delta_arr, delta_hidden_arr, re_encoder_grads_list = self.__retrospective_encoder.hidden_back_propagate(
            delta_arr[:, -1]
        )
        re_encoder_grads_list.insert(0, None)
        re_encoder_grads_list.insert(0, None)

        observed_arr, encoded_arr, decoded_arr, re_encoded_arr = self.__inferenced_tuple
        delta_arr = self.__encoder_decoder_controller.computable_loss.compute_delta(
            decoded_arr,
            observed_arr
        )
        delta_arr[:, -1] += re_encoder_delta_arr[:, -1]

        decoder_grads_list, encoder_delta_arr, encoder_grads_list = self.__encoder_decoder_controller.back_propagation(
            delta_arr
        )
        return re_encoder_grads_list, decoder_grads_list, encoder_delta_arr, encoder_grads_list

Back propagation.

Args:
        delta_output_arr:    Delta.

Returns:
        Tuple data.
        - decoder's `list` of gradations,
        - encoder's `np.ndarray` of Delta,
        - encoder's `list` of gradations.


def guess_peb_size(path):

    file_offset = 0
    offsets = []
    f = open(path, 'rb')
    f.seek(0,2)
    file_size = f.tell()+1
    f.seek(0)

    for _ in range(0, file_size, FILE_CHUNK_SZ):
        buf = f.read(FILE_CHUNK_SZ)
        for m in re.finditer(UBI_EC_HDR_MAGIC, buf):
            start = m.start()

            if not file_offset:
                file_offset = start
                idx = start
            else:
                idx = start+file_offset

            offsets.append(idx)

        file_offset += FILE_CHUNK_SZ
    f.close()

    occurances = {}
    for i in range(0, len(offsets)):
        try:
            diff = offsets[i] - offsets[i-1]
        except:
            diff = offsets[i]

        if diff not in occurances:
            occurances[diff] = 0

        occurances[diff] += 1

    most_frequent = 0
    block_size = None

    for offset in occurances:
        if occurances[offset] > most_frequent:
            most_frequent = occurances[offset]
            block_size = offset

    return block_size

Determine the most likely block size

Args:
    Str:path    -- Path to file.

Returns:
    Int         -- PEB size.

    Searches file for Magic Number, picks most
        common length between them.


def __init__(self, kind, required=False, default_factory=None,
               can_be_none=False):

    if required and default_factory is not None:
      raise ValueError("No default_factory value when option is required.")
    self.kind = kind
    self.required = required
    self.default_factory = default_factory
    self.can_be_none = can_be_none

Init.

Args:
        kind: type of the option.
        required: whether user is required to supply a value.
        default_factory: a factory, when called, returns the default value.
        can_be_none: whether value can be None.

Raises:
        ValueError: if arguments aren't compatible.


def serialize_to_xml(root, block):

    root.tag = 'ubcpi'

    if block.rationale_size is not None:
        if block.rationale_size.get('min'):
            root.set('rationale_size_min', unicode(block.rationale_size.get('min')))
        if block.rationale_size.get('max'):
            root.set('rationale_size_max', unicode(block.rationale_size['max']))

    if block.algo:
        if block.algo.get('name'):
            root.set('algorithm', block.algo.get('name'))
        if block.algo.get('num_responses'):
            root.set('num_responses', unicode(block.algo.get('num_responses')))

    display_name = etree.SubElement(root, 'display_name')
    display_name.text = block.display_name

    question = etree.SubElement(root, 'question')
    question_text = etree.SubElement(question, 'text')
    question_text.text = block.question_text['text']
    serialize_image(block.question_text, question)

    options = etree.SubElement(root, 'options')
    serialize_options(options, block)

    seeds = etree.SubElement(root, 'seeds')
    serialize_seeds(seeds, block)

Serialize the Peer Instruction XBlock's content to XML.

Args:
        block (PeerInstructionXBlock): The peer instruction block to serialize.
        root (etree.Element): The XML root node to update.

Returns:
        etree.Element


def _expect(self, expected, times=50):

        logger.debug('[%s] Expecting [%s]', self.port, expected)
        retry_times = 10
        while times:
            if not retry_times:
                break

            line = self._readline()

            if line == expected:
                return

            if not line:
                retry_times -= 1
                time.sleep(0.1)

            times -= 1

        raise Exception('failed to find expected string[%s]' % expected)

Find the `expected` line within `times` trials.

Args:
        expected    str: the expected string
        times       int: number of trials


def add_config(self, slot, config_id, config_type, value):

        if slot not in self.config_database:
            self.config_database[slot] = {}

        self.config_database[slot][config_id] = (config_type, value)

Add a config variable assignment to this sensor graph.

Args:
        slot (SlotIdentifier): The slot identifier that this config
            variable is assigned to.
        config_id (int): The 16-bit id of this config_id
        config_type (str): The type of the config variable, currently
            supported are fixed width integer types, strings and binary
            blobs.
        value (str|int|bytes): The value to assign to the config variable.


def _ImportPythonModule(module_name):

  try:
    module_object = list(map(__import__, [module_name]))[0]
  except ImportError:
    return None

  # If the module name contains dots get the upper most module object.
  if '.' in module_name:
    for submodule_name in module_name.split('.')[1:]:
      module_object = getattr(module_object, submodule_name, None)

  return module_object

Imports a Python module.

Args:
        module_name (str): name of the module.

Returns:
        module: Python module or None if the module cannot be imported.


def PrintMessage(self, message):

    if (message.DESCRIPTOR.full_name == _ANY_FULL_TYPE_NAME and
        self.descriptor_pool and self._TryPrintAsAnyMessage(message)):
      return
    fields = message.ListFields()
    if self.use_index_order:
      fields.sort(key=lambda x: x[0].index)
    for field, value in fields:
      if _IsMapEntry(field):
        for key in sorted(value):
          # This is slow for maps with submessage entires because it copies the
          # entire tree.  Unfortunately this would take significant refactoring
          # of this file to work around.
          #
          # TODO(haberman): refactor and optimize if this becomes an issue.
          entry_submsg = value.GetEntryClass()(key=key, value=value[key])
          self.PrintField(field, entry_submsg)
      elif field.label == descriptor.FieldDescriptor.LABEL_REPEATED:
        for element in value:
          self.PrintField(field, element)
      else:
        self.PrintField(field, value)

Convert protobuf message to text format.

Args:
        message: The protocol buffers message.


def CreateFeedItemAddOperation(name, price, date, ad_customizer_feed):

  feed_item = {
      'feedId': ad_customizer_feed['feedId'],
      'attributeValues': [
          {
              'feedAttributeId': ad_customizer_feed['feedAttributes'][0]['id'],
              'stringValue': name
          },
          {
              'feedAttributeId': ad_customizer_feed['feedAttributes'][1]['id'],
              'stringValue': price
          },
          {
              'feedAttributeId': ad_customizer_feed['feedAttributes'][2]['id'],
              'stringValue': date
          }
      ]
  }

  operation = {
      'operator': 'ADD',
      'operand': feed_item
  }

  return operation

Creates a FeedItemOperation.

    The generated FeedItemOperation will create a FeedItem with the specified
    values when sent to FeedItemService.mutate.

Args:
        name: the value for the name attribute of the FeedItem.
        price: the value for the price attribute of the FeedItem.
        date: the value for the date attribute of the FeedItem.
        ad_customizer_feed: the AdCustomizerFeed we're associating the FeedItems
        with.

Returns:
        A new FeedItemOperation for adding a FeedItem.


def datasets_insert(self, dataset_name, friendly_name=None, description=None):

    url = Api._ENDPOINT + (Api._DATASETS_PATH % (dataset_name.project_id, ''))
    data = {
        'kind': 'bigquery#dataset',
        'datasetReference': {
            'projectId': dataset_name.project_id,
            'datasetId': dataset_name.dataset_id
        },
    }
    if friendly_name:
      data['friendlyName'] = friendly_name
    if description:
      data['description'] = description
    return datalab.utils.Http.request(url, data=data, credentials=self._credentials)

Issues a request to create a dataset.

Args:
        dataset_name: the name of the dataset to create.
        friendly_name: (optional) the friendly name for the dataset
        description: (optional) a description for the dataset

Returns:
        A parsed result object.

Raises:
        Exception if there is an error performing the operation.


def get(self, title):

        key = '/library/sections/%s/all' % self.key
        return self.fetchItem(key, title__iexact=title)

Returns the media item with the specified title.

    Parameters:
        title (str): Title of the item to return.


def import_tsv(self, tsv_file):

        r = fapi.upload_entities_tsv(self.namespace, self.name,
                                     self.tsv_file, self.api_url)
        fapi._check_response_code(r, 201)

Upload entity data to workspace from tsv loadfile.

Args:
        tsv_file (file): Tab-delimited file of entity data


def read(self, n):

    if self._EOF:
      return ""

    while self._seg_index <= self._last_seg_index:
      result = self._read_from_seg(n)
      if result != "":
        return result
      else:
        self._next_seg()

    self._EOF = True
    return ""

Read data from file segs.

Args:
        n: max bytes to read. Must be positive.

Returns:
        some bytes. May be smaller than n bytes. "" when no more data is left.


def _get_expiration(self, headers: dict) -> int:

        expiration_str = headers.get('expires')
        if not expiration_str:
            return 0
        expiration = datetime.strptime(expiration_str, '%a, %d %b %Y %H:%M:%S %Z')
        delta = (expiration - datetime.utcnow()).total_seconds()
        return math.ceil(abs(delta))

Gets the expiration time of the data from the response headers.

Args:
        headers: dictionary of headers from ESI

Returns:
        value of seconds from now the data expires


def check_imported(module):

        imported = True
        module_info = ('', '', '')
        # TODO: if possible, update to a cleaner method that doesn't require importing the module
        # and running inline code.
        try:
            importlib.import_module(module)
            module_info = imp.find_module(module)
        except ImportError:
            imported = False

        # get module path
        module_path = module_info[1]
        description = module_info[2]

        if not description:
            # if description is None or empty string the module could not be imported
            imported = False
        elif not description and not module_path:
            # if description/module_path are None or empty string the module could not be imported
            imported = False
        elif module_path is not None and (
            'dist-packages' in module_path or 'site-packages' in module_path
        ):
            # if dist-packages|site-packages in module_path the import doesn't count
            imported = False
        return imported

Check whether the provide module can be imported (package installed).

Args:
        module (str): The name of the module to check availability.

Returns:
        bool: True if the module can be imported, False otherwise.


def _map_condition(self, wire_map, condition):

        if condition is None:
            new_condition = None
        else:
            # Map the register name, using fact that registers must not be
            # fragmented by the wire_map (this must have been checked
            # elsewhere)
            bit0 = (condition[0], 0)
            new_condition = (wire_map.get(bit0, bit0)[0], condition[1])
        return new_condition

Use the wire_map dict to change the condition tuple's creg name.

Args:
        wire_map (dict): a map from wires to wires
        condition (tuple): (ClassicalRegister,int)

Returns:
        tuple(ClassicalRegister,int): new condition


def expect_false(condition, msg, extras=None):

    try:
        asserts.assert_false(condition, msg, extras)
    except signals.TestSignal as e:
        logging.exception('Expected a `False` value, got `True`.')
        recorder.add_error(e)

Expects an expression evaluates to False.

    If the expectation is not met, the test is marked as fail after its
    execution finishes.

Args:
        expr: The expression that is evaluated.
        msg: A string explaining the details in case of failure.
        extras: An optional field for extra information to be included in test
            result.


def __init__(self, data_type_definition):

    super(StructureMap, self).__init__(data_type_definition)
    self._attribute_names = self._GetAttributeNames(data_type_definition)
    self._data_type_map_cache = {}
    self._data_type_maps = self._GetMemberDataTypeMaps(
        data_type_definition, self._data_type_map_cache)
    self._fold_byte_stream = None
    self._format_string = None
    self._map_byte_stream = None
    self._number_of_attributes = len(self._attribute_names)
    self._operation = None
    self._structure_values_class = (
        runtime.StructureValuesClassFactory.CreateClass(
            data_type_definition))

    if self._CheckCompositeMap(data_type_definition):
      self._fold_byte_stream = self._CompositeFoldByteStream
      self._map_byte_stream = self._CompositeMapByteStream
    else:
      self._fold_byte_stream = self._LinearFoldByteStream
      self._map_byte_stream = self._LinearMapByteStream
      self._operation = self._GetByteStreamOperation()

Initializes a structure data type map.

Args:
        data_type_definition (DataTypeDefinition): data type definition.


def __init__(self, mpls_ttl=None):

        super().__init__(action_type=ActionType.OFPAT_SET_MPLS_TTL, length=8)
        self.mpls_ttl = mpls_ttl

Create an ActionSetMPLSTTL with the optional parameters below.

Args:
        mpls_ttl (int): The mpls_ttl field is the MPLS TTL to set.


def _parse_authors(authors):

    link = authors.find("a")
    link = link[0].params.get("href") if link else None

    author_list = _strip_content(authors)

    if "(" in author_list:
        author_list = author_list.split("(")[0]

    if not author_list.strip():
        return []

    return map(
        lambda author: Author(author.strip(), link),
        author_list.strip().split(",")
    )

Parse informations about authors of the book.

Args:
        dom (obj): HTMLElement containing slice of the page with details.

Returns:
        list: List of :class:`.Author` objects. Blank if no author \
            found.


def GetMessages(self, formatter_mediator, event):

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

    event_values = event.CopyToDict()

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

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

    return self._ConditionalFormatMessages(event_values)

Determines the formatted message strings for an event object.

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

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

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


def reset_port_protection(self, id_or_uri, timeout=-1):

        uri = self._client.build_uri(id_or_uri) + "/resetportprotection"
        return self._client.update_with_zero_body(uri, timeout)

Triggers a reset of port protection.

    Cause port protection to be reset on all the interconnects of the logical interconnect that matches ID.

Args:
        id_or_uri: Can be either the interconnect id or the interconnect uri.
        timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
            in OneView; it just stops waiting for its completion.

Returns:
        dict: The interconnect.


def predict(parameters, X):

    # Computes probabilities using forward propagation,
    # and classifies to 0/1 using 0.5 as the threshold.
    A2, cache = forward_propagation(X, parameters)
    predictions = np.array([1 if (i > 0.5) else 0 for i in A2[0]])

    return predictions

Using the learned parameters, predicts a class for each example in X

Args:
    parameters -- python dictionary containing your parameters
    X -- input data of size (n_x, m)

    Returns
    predictions -- vector of predictions of our model (red: 0 / blue: 1)


def ParseSMS(self, parser_mediator, query, row, **unused_kwargs):

    query_hash = hash(query)

    phone_number = self._GetRowValue(query_hash, row, 'dstnum_sms')
    if phone_number:
      phone_number = phone_number.replace(' ', '')

    event_data = SkypeSMSEventData()
    event_data.number = phone_number
    event_data.query = query
    event_data.text = self._GetRowValue(query_hash, row, 'msg_sms')

    timestamp = self._GetRowValue(query_hash, row, 'time_sms')
    if timestamp:
      date_time = dfdatetime_posix_time.PosixTime(timestamp=timestamp)
      event = time_events.DateTimeValuesEvent(date_time, 'SMS from Skype')
      parser_mediator.ProduceEventWithEventData(event, event_data)

Parses an SMS.

Args:
        parser_mediator (ParserMediator): mediates interactions between parsers
        and other components, such as storage and dfvfs.
        query (str): query that created the row.
        row (sqlite3.Row): row resulting from query.


def norm(self, coords: Vector3Like, frac_coords: bool = True) -> float:

        return np.sqrt(self.dot(coords, coords, frac_coords=frac_coords))

Compute the norm of vector(s).

Args:
        coords:
            Array-like object with the coordinates.
        frac_coords:
            Boolean stating whether the vector corresponds to fractional or
            cartesian coordinates.

Returns:
        one-dimensional `numpy` array.


def util_pattern_space(time_series, lag, dim):

    n = len(time_series)

    if lag * dim > n:
        raise Exception('Result matrix exceeded size limit, try to change lag or dim.')
    elif lag < 1:
        raise Exception('Lag should be greater or equal to 1.')

    pattern_space = np.empty((n - lag * (dim - 1), dim))
    for i in range(n - lag * (dim - 1)):
        for j in range(dim):
            pattern_space[i][j] = time_series[i + j * lag]

    return pattern_space

Create a set of sequences with given lag and dimension

Args:
        time_series: Vector or string of the sample data
        lag: Lag between beginning of sequences
        dim: Dimension (number of patterns)

Returns:
        2D array of vectors


def _setweights(self):

        for name_w in self.weights:
            raw_w = getattr(self.module, name_w + '_raw')
            w = torch.nn.functional.dropout(raw_w, p=self.dropout, training=self.training)
            if hasattr(self.module, name_w):
                delattr(self.module, name_w)
            setattr(self.module, name_w, w)

Uses pytorch's built-in dropout function to apply dropout to the parameters of
    the wrapped module.

Args:
        None

Returns:
        None


def detect_format(program, attributes) -> str:

    def fmt(attr):

        return attr.array_length * attr.dimension, attr.shape

    return ' '.join('%d%s' % fmt(program[a]) for a in attributes)

Detect format for vertex attributes.
    The format returned does not contain padding.

Args:
        program (Program): The program.
        attributes (list): A list of attribute names.

Returns:
        str


def ask_yes_no(question, default='no', answer=None):
    u
    default = default.lower()
    yes = [u'yes', u'ye', u'y']
    no = [u'no', u'n']
    if default in no:
        help_ = u'[N/y]?'
        default = False
    else:
        default = True
        help_ = u'[Y/n]?'
    while 1:
        display = question + '\n' + help_
        if answer is None:
            log.debug(u'Under None')
            answer = six.moves.input(display)
            answer = answer.lower()
        if answer == u'':
            log.debug(u'Under blank')
            return default
        if answer in yes:
            log.debug(u'Must be true')
            return True
        elif answer in no:
            log.debug(u'Must be false')
            return False
        else:
            sys.stdout.write(u'Please answer yes or no only!\n\n')
            sys.stdout.flush()
            answer = None
            six.moves.input(u'Press enter to continue')
            sys.stdout.write('\n\n\n\n\n')
            sys.stdout.flush()

u"""Will ask a question and keeps prompting until
    answered.

Args:
        question (str): Question to ask end user

        default (str): Default answer if user just press enter at prompt

        answer (str): Used for testing

Returns:
        (bool) Meaning:

            True - Answer is  yes

            False - Answer is no


def ParsePathItem(item, opts=None):

  if item == os.path.curdir:
    return CurrentComponent()

  if item == os.path.pardir:
    return ParentComponent()

  recursion = PATH_RECURSION_REGEX.search(item)
  if recursion is None:
    return GlobComponent(item, opts)

  start, end = recursion.span()
  if not (start == 0 and end == len(item)):
    raise ValueError("malformed recursive component")

  if recursion.group("max_depth"):
    max_depth = int(recursion.group("max_depth"))
  else:
    max_depth = None

  return RecursiveComponent(max_depth=max_depth, opts=opts)

Parses string path component to an `PathComponent` instance.

Args:
        item: A path component string to be parsed.
        opts: A `PathOpts` object.

Returns:
        `PathComponent` instance corresponding to given path fragment.

Raises:
        ValueError: If the path item contains a recursive component fragment but
        cannot be parsed as such.


def select_symbols(self, symbols, ret_list=False):

        symbols = list_strings(symbols)
        exclude = symbols[0].startswith("-")

        if exclude:
            if not all(s.startswith("-") for s in symbols):
                raise ValueError("When excluding symbols, all strings must start with `-`")
            symbols = [s[1:] for s in symbols]

        symbols = set(symbols)
        pseudos = []
        for p in self:
            if exclude:
                if p.symbol in symbols: continue
            else:
                if p.symbol not in symbols: continue

            pseudos.append(p)

        if ret_list:
            return pseudos
        else:
            return self.__class__(pseudos)

Return a :class:`PseudoTable` with the pseudopotentials with the given list of chemical symbols.

Args:
        symbols: str or list of symbols
            Prepend the symbol string with "-", to exclude pseudos.
        ret_list: if True a list of pseudos is returned instead of a :class:`PseudoTable`


def logs_urlpatterns(admin_view=lambda x: x):

    return [
        url(r'^$',
            admin_view(LogsMenu.as_view()),
            name='logs'),
        url(r'^status_codes$',
            admin_view(LogsStatusCodes.as_view()),
            name='logs_status_codes'),
        url(r'^status_codes_by_date$',
            admin_view(LogsStatusCodesByDate.as_view()),
            name='logs_status_codes_by_date'),
        url(r'^most_visited_pages$',
            admin_view(LogsMostVisitedPages.as_view()),
            name='logs_most_visited_pages')
    ]

Return the URL patterns for the logs views.

Args:
        admin_view (callable): admin_view method from an AdminSite instance.

Returns:
        list: the URL patterns for the logs views.


def pull(self, device_filename, dest_file=None, timeout_ms=None):

    should_return_data = dest_file is None
    if isinstance(dest_file, six.string_types):
      dest_file = open(dest_file, 'w')
    elif dest_file is None:
      dest_file = six.StringIO()
    self.filesync_service.recv(device_filename, dest_file,
                               timeouts.PolledTimeout.from_millis(timeout_ms))
    if should_return_data:
      return dest_file.getvalue()

Pull file from device.

Args:
        device_filename: The filename on the device to pull.
        dest_file: If set, a filename or writable file-like object.
        timeout_ms: Expected timeout for the pull.

Returns:
        The file data if dest_file is not set, None otherwise.


def add(self, other, axis="columns", level=None, fill_value=None):

        return self._binary_op(
            "add", other, axis=axis, level=level, fill_value=fill_value
        )

Add this DataFrame to another or a scalar/list.

Args:
        other: What to add this this DataFrame.
        axis: The axis to apply addition over. Only applicaable to Series
            or list 'other'.
        level: A level in the multilevel axis to add over.
        fill_value: The value to fill NaN.

Returns:
        A new DataFrame with the applied addition.


def manufacturer(self):

        buf = ctypes.cast(self.sManu, ctypes.c_char_p).value
        return buf.decode() if buf else None

Returns the name of the manufacturer of the device.

Args:
        self (JLinkDeviceInfo): the ``JLinkDeviceInfo`` instance

Returns:
        Manufacturer name.


def attention_bias_same_segment(query_segment_id, memory_segment_id):

  ret = (tf.to_float(
      tf.not_equal(
          tf.expand_dims(query_segment_id, 2),
          tf.expand_dims(memory_segment_id, 1))) *
         large_compatible_negative(memory_segment_id.dtype))
  return tf.expand_dims(ret, axis=1)

Create an bias tensor to be added to attention logits.

    Positions with the same segment_ids can see each other.

Args:
        query_segment_id: a float `Tensor` with shape [batch, query_length].
        memory_segment_id: a float `Tensor` with shape [batch, memory_length].

Returns:
        a `Tensor` with shape [batch, 1, query_length, memory_length].


def __init__(self, _args):

        super(TcExPackage, self).__init__(_args)

        # properties
        self.features = ['aotExecutionEnabled', 'secureParams']

        # properties
        self._app_packages = []
        self.package_data = {'errors': [], 'updates': [], 'bundle': [], 'package': []}
        self.validation_data = {}

Initialize Class properties.

Args:
        _args (namespace): The argparser args Namespace.


def _GetApprovals(self,
                    approval_type,
                    offset,
                    count,
                    filter_func=None,
                    token=None):

    approvals_base_urn = aff4.ROOT_URN.Add("users").Add(
        token.username).Add("approvals").Add(approval_type)

    all_children = aff4.FACTORY.RecursiveMultiListChildren([approvals_base_urn])

    approvals_urns = []
    for subject, children in all_children:
      # We only want to process leaf nodes.
      if children:
        continue
      approvals_urns.append(subject)

    approvals_urns.sort(key=lambda x: x.age, reverse=True)
    approvals = list(
        aff4.FACTORY.MultiOpen(
            approvals_urns,
            mode="r",
            aff4_type=aff4_security.Approval,
            age=aff4.ALL_TIMES,
            token=token))
    approvals_by_urn = {}
    for approval in approvals:
      approvals_by_urn[approval.symlink_urn or approval.urn] = approval

    cur_offset = 0
    sorted_approvals = []
    for approval_urn in approvals_urns:
      try:
        approval = approvals_by_urn[approval_urn]
      except KeyError:
        continue

      if filter_func is not None and not filter_func(approval):
        continue
      cur_offset += 1
      if cur_offset <= offset:
        continue
      if count and len(sorted_approvals) >= count:
        break
      sorted_approvals.append(approval)

    subjects_urns = [a.Get(a.Schema.SUBJECT) for a in approvals]
    subjects_by_urn = {}
    for subject in aff4.FACTORY.MultiOpen(subjects_urns, mode="r", token=token):
      subjects_by_urn[subject.urn] = subject

    return sorted_approvals, subjects_by_urn

Gets all approvals for a given user and approval type.

Args:
        approval_type: The type of approvals to get.
        offset: The starting index within the collection.
        count: The number of items to return.
        filter_func: A predicate function, returning True if a specific approval
        should be included in the result and False otherwise.
        token: The token identifying the user.

Returns:
        A list of approvals of the given approval type.


def parse_mapreduce_yaml(contents):

  try:
    builder = yaml_object.ObjectBuilder(MapReduceYaml)
    handler = yaml_builder.BuilderHandler(builder)
    listener = yaml_listener.EventListener(handler)
    listener.Parse(contents)

    mr_info = handler.GetResults()
  except (ValueError, yaml_errors.EventError), e:
    raise errors.BadYamlError(e)

  if len(mr_info) < 1:
    raise errors.BadYamlError("No configs found in mapreduce.yaml")
  if len(mr_info) > 1:
    raise errors.MultipleDocumentsInMrYaml("Found %d YAML documents" %
                                           len(mr_info))

  jobs = mr_info[0]
  job_names = set(j.name for j in jobs.mapreduce)
  if len(jobs.mapreduce) != len(job_names):
    raise errors.BadYamlError(
        "Overlapping mapreduce names; names must be unique")

  return jobs

Parses mapreduce.yaml file contents.

Args:
        contents: mapreduce.yaml file contents.

Returns:
        MapReduceYaml object with all the data from original file.

Raises:
        errors.BadYamlError: when contents is not a valid mapreduce.yaml file.


def resolution(self, indicator=None):

        self._request_entity = 'dnsResolution'
        self._request_uri = '{}/dnsResolutions'.format(self._request_uri)
        if indicator is not None:
            self._request_uri = '{}/{}/dnsResolutions'.format(self._api_uri, indicator)

Update the URI to retrieve host resolutions for the provided indicator.

Args:
        indicator (string): The indicator to retrieve resolutions.


def get_wallace_tensor(self, tau):

        b = 0.5 * (np.einsum("ml,kn->klmn", tau, np.eye(3)) +
                   np.einsum("km,ln->klmn", tau, np.eye(3)) +
                   np.einsum("nl,km->klmn", tau, np.eye(3)) +
                   np.einsum("kn,lm->klmn", tau, np.eye(3)) +
                   -2*np.einsum("kl,mn->klmn", tau, np.eye(3)))
        strain = self.get_strain_from_stress(tau)
        b += self.get_effective_ecs(strain)
        return b

Gets the Wallace Tensor for determining yield strength
    criteria.

Args:
        tau (3x3 array-like): stress at which to evaluate
            the wallace tensor


def _validate_user_inputs(self, attributes=None, event_tags=None):

    if attributes and not validator.are_attributes_valid(attributes):
      self.logger.error('Provided attributes are in an invalid format.')
      self.error_handler.handle_error(exceptions.InvalidAttributeException(enums.Errors.INVALID_ATTRIBUTE_FORMAT))
      return False

    if event_tags and not validator.are_event_tags_valid(event_tags):
      self.logger.error('Provided event tags are in an invalid format.')
      self.error_handler.handle_error(exceptions.InvalidEventTagException(enums.Errors.INVALID_EVENT_TAG_FORMAT))
      return False

    return True

Helper method to validate user inputs.

Args:
        attributes: Dict representing user attributes.
        event_tags: Dict representing metadata associated with an event.

Returns:
        Boolean True if inputs are valid. False otherwise.


def _edit_tags(self, tag, items, locked=True, remove=False):

        if not isinstance(items, list):
            items = [items]
        value = getattr(self, tag + 's')
        existing_cols = [t.tag for t in value if t and remove is False]
        d = tag_helper(tag, existing_cols + items, locked, remove)
        self.edit(**d)
        self.refresh()

Helper to edit and refresh a tags.

    Parameters:
        tag (str): tag name
        items (list): list of tags to add
        locked (bool): lock this field.
        remove (bool): If this is active remove the tags in items.


def swd_read16(self, offset):

        value = self._dll.JLINK_SWD_GetU16(offset)
        return ctypes.c_uint16(value).value

Gets a unit of ``16`` bits from the input buffer.

Args:
        self (JLink): the ``JLink`` instance
        offset (int): the offset (in bits) from which to start reading

Returns:
        The integer read from the input buffer.


def supervised_to_dict(dataset, text2self):

  def my_fn(inputs, targets):
    if text2self:
      return {"targets": targets}
    else:
      return {"inputs": inputs, "targets": targets}
  return dataset.map(my_fn, num_parallel_calls=tf.data.experimental.AUTOTUNE)

Turns a supervised dataset into a dataset with a feature dictionary.

    if text2self, then the features dictionary contains a "targets" key.
    else, the features dictionary contains "inputs" and "targets" keys.

Args:
        dataset: a tf.data.Dataset
        text2self: a boolean

Returns:
        a tf.data.Dataset


def add(self, username, user_api, filename=None):

        keys = API.__get_keys(filename)
        user = user_api.find(username)[0]
        distinguished_name = user.entry_dn
        if 'ldapPublicKey' not in user.objectClass:
            raise ldap3.core.exceptions.LDAPNoSuchAttributeResult(
                'LDAP Public Key Object Class not found. ' +
                'Please ensure user was created correctly.')
        else:
            for key in list(set(keys)):  # prevents duplicate insertion
                print(key)
                try:
                    SSHKey(key).parse()
                except Exception as err:
                    raise err from None
                else:
                    operation = {'sshPublicKey': [(ldap3.MODIFY_ADD, [key])]}
                    self.client.modify(distinguished_name, operation)

Add SSH public key to a user's profile.

Args:
        username: Username to attach SSH public key to
        filename: Filename containing keys to add (optional)

Raises:
        ldap3.core.exceptions.LDAPNoSuchAttributeResult:
            ldapPublicKey isn't attached to objectClass


def __init__(self, cache_file_name=None, update_cache=True, req_timeout=90.0):

        # TODO - lookup request rate limit
        # By observation, ShadowServer can be quite slow, so give it 90 seconds before it times out.
        self._requests = MultiRequest(max_requests=2, req_timeout=req_timeout)

        # Create an ApiCache if instructed to
        self._cache = ApiCache(cache_file_name, update_cache) if cache_file_name else None

Establishes basic HTTP params and loads a cache.

Args:
        cache_file_name: String file name of cache.
        update_cache: Determines whether cache should be written out back to the disk when closing it.
                    Default is `True`.
        req_timeout: Maximum number of seconds to wait without reading a response byte before deciding an error has occurred.
                    Default is 90.0 seconds.


def __init__(self, parent=None):

        super(CSVImportDialog, self).__init__(parent)
        self._modal = True
        self._windowTitle = 'Import CSV'
        self._encodingKey = None
        self._filename = None
        self._delimiter = None
        self._header = None
        # self._detector = Detector()
        self._initUI()

Constructs the object with the given parent.

Args:
        parent (QObject, optional): Causes the objected to be owned
            by `parent` instead of Qt. Defaults to `None`.


def wigner_data(q_result, meas_qubits, labels, shots=None):

    num = len(meas_qubits)

    dim = 2**num
    p = [0.5 + 0.5 * np.sqrt(3), 0.5 - 0.5 * np.sqrt(3)]
    parity = 1

    for i in range(num):
        parity = np.kron(parity, p)

    w = [0] * len(labels)
    wpt = 0
    counts = [marginal_counts(q_result.get_counts(circ), meas_qubits)
              for circ in labels]
    for entry in counts:
        x = [0] * dim

        for i in range(dim):
            if bin(i)[2:].zfill(num) in entry:
                x[i] = float(entry[bin(i)[2:].zfill(num)])

        if shots is None:
            shots = np.sum(x)

        for i in range(dim):
            w[wpt] = w[wpt] + (x[i] / shots) * parity[i]
        wpt += 1

    return w

Get the value of the Wigner function from measurement results.

Args:
        q_result (Result): Results from execution of a state tomography
                            circuits on a backend.
        meas_qubits (list[int]): a list of the qubit indexes measured.
        labels (list[str]): a list of names of the circuits
        shots (int): number of shots

Returns:
        list: The values of the Wigner function at measured points in
            phase space


def AssignTasksToClient(self, client_id):

    rules = self.Get(self.Schema.RULES)
    if not rules:
      return 0

    if data_store.RelationalDBEnabled():
      last_foreman_run = self._GetLastForemanRunTimeRelational(client_id)
    else:
      last_foreman_run = self._GetLastForemanRunTime(client_id)

    latest_rule = max(rule.created for rule in rules)

    if latest_rule <= last_foreman_run:
      return 0

    # Update the latest checked rule on the client.
    if data_store.RelationalDBEnabled():
      try:
        self._SetLastForemanRunTimeRelational(client_id, latest_rule)
      except db.UnknownClientError:
        pass

    # If the relational db is used for reads, we don't have to update the
    # aff4 object.
    if not data_store.RelationalDBEnabled():
      self._SetLastForemanRunTime(client_id, latest_rule)

    relevant_rules = []
    expired_rules = False

    now = time.time() * 1e6

    for rule in rules:
      if rule.expires < now:
        expired_rules = True
        continue
      if rule.created <= int(last_foreman_run):
        continue

      relevant_rules.append(rule)

    if data_store.RelationalDBEnabled():
      client_data = data_store.REL_DB.ReadClientFullInfo(client_id)
      if client_data is None:
        return
    else:
      client_data = aff4.FACTORY.Open(client_id, mode="rw", token=self.token)

    actions_count = 0
    for rule in relevant_rules:
      if self._EvaluateRules(rule, client_data):
        actions_count += self._RunActions(rule, client_id)

    if expired_rules:
      self.ExpireRules()

    return actions_count

Examines our rules and starts up flows based on the client.

Args:
        client_id: Client id of the client for tasks to be assigned.

Returns:
        Number of assigned tasks.