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

Approves or rejects a pending build. If approved, the returned LRO will be analogous to the LRO returned from a CreateBuild call. If rejected, the returned LRO will be immediately done.

Args:
        request: (CloudbuildProjectsBuildsApproveRequest) input message
        global_params: (StandardQueryParameters, default: None) global arguments

Returns:
        (Operation) The response message.


def parse_ranges(range_string):
    range_string = range_string.strip()
    if not range_string:
        return []
    if 'inf' in range_string:
        range_string = re.sub('inf', repr(sys.float_info.max), range_string)
    ranges = ast.literal_eval(range_string)
    if isinstance(ranges, list) and (not isinstance(ranges[0], list)):
        ranges = [ranges]
    for item in ranges:
        if len(item) != 2:
            raise ValueError('Incorrect number of elements in range')
        elif not isinstance(item[0], (int, float)):
            raise ValueError('Incorrect type in the 1st element of range: %s' % type(item[0]))
        elif not isinstance(item[1], (int, float)):
            raise ValueError('Incorrect type in the 2nd element of range: %s' % type(item[0]))
    return ranges

Parse a string representing numerical range(s).

Args:
        range_string: (str) A string representing a numerical range or a list of
        them. For example:
        "[-1.0,1.0]", "[-inf, 0]", "[[-inf, -1.0], [1.0, inf]]"

Returns:
        (list of list of float) A list of numerical ranges parsed from the input
        string.

Raises:
        ValueError: If the input doesn't represent a range or a list of ranges.


def is_tf_type(x):
    return isinstance(x, tf_type_classes)

Checks whether `x` is a TF-native type that can be passed to many TF ops.

    Use `is_tensor` to differentiate types that can ingested by TensorFlow ops
    without any conversion (e.g., `tf.Tensor`, `tf.SparseTensor`, and
    `tf.RaggedTensor`) from types that need to be converted into tensors before
    they are ingested (e.g., numpy `ndarray` and Python scalars).

    For example, in the following code block:

    ```python
    if not tf.is_tensor(t):
        t = tf.convert_to_tensor(t)
    return t.shape, t.dtype
    ```

    we check to make sure that `t` is a tensor (and convert it if not) before
    accessing its `shape` and `dtype`.  (But note that not all TensorFlow native
    types have shapes or dtypes; `tf.data.Dataset` is an example of a TensorFlow
    native type that has neither shape nor dtype.)

Args:
        x: A python object to check.

Returns:
        `True` if `x` is a TensorFlow-native type.


def forward(self, hidden_states: torch.Tensor, attention_mask: Optional[torch.Tensor]=None, encoder_hidden_states: Optional[torch.Tensor]=None, encoder_attention_mask: Optional[torch.Tensor]=None, layer_head_mask: Optional[torch.Tensor]=None, cross_attn_layer_head_mask: Optional[torch.Tensor]=None, past_key_value: Optional[Tuple[torch.Tensor]]=None, output_attentions: Optional[bool]=False, use_cache: Optional[bool]=True) -> torch.Tensor:
    residual = hidden_states
    hidden_states = self.self_attn_layer_norm(hidden_states)
    self_attn_past_key_value = past_key_value[:2] if past_key_value is not None else None
    hidden_states, self_attn_weights, present_key_value = self.self_attn(hidden_states=hidden_states, past_key_value=self_attn_past_key_value, attention_mask=attention_mask, layer_head_mask=layer_head_mask, output_attentions=output_attentions)
    hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
    hidden_states = residual + hidden_states
    cross_attn_present_key_value = None
    cross_attn_weights = None
    if encoder_hidden_states is not None:
        residual = hidden_states
        hidden_states = self.encoder_attn_layer_norm(hidden_states)
        cross_attn_past_key_value = past_key_value[-2:] if past_key_value is not None else None
        hidden_states, cross_attn_weights, cross_attn_present_key_value = self.encoder_attn(hidden_states=hidden_states, key_value_states=encoder_hidden_states, attention_mask=encoder_attention_mask, layer_head_mask=cross_attn_layer_head_mask, past_key_value=cross_attn_past_key_value, output_attentions=output_attentions)
        hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
        hidden_states = residual + hidden_states
        present_key_value = present_key_value + cross_attn_present_key_value
    residual = hidden_states
    hidden_states = self.final_layer_norm(hidden_states)
    hidden_states = self.activation_fn(self.fc1(hidden_states))
    hidden_states = nn.functional.dropout(hidden_states, p=self.activation_dropout, training=self.training)
    hidden_states = self.fc2(hidden_states)
    hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
    hidden_states = residual + hidden_states
    outputs = (hidden_states,)
    if output_attentions:
        outputs += (self_attn_weights, cross_attn_weights)
    if use_cache:
        outputs += (present_key_value,)
    return outputs

Args:
    hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
    attention_mask (`torch.FloatTensor`): attention mask of size
        `(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
    encoder_hidden_states (`torch.FloatTensor`):
        cross attention input to the layer of shape `(batch, seq_len, embed_dim)`
    encoder_attention_mask (`torch.FloatTensor`): encoder attention mask of size
        `(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
    layer_head_mask (`torch.FloatTensor`): mask for attention heads in a given layer of size
        `(encoder_attention_heads,)`.
    cross_attn_layer_head_mask (`torch.FloatTensor`): mask for cross-attention heads in a given layer of
        size `(decoder_attention_heads,)`.
    past_key_value (`Tuple(torch.FloatTensor)`): cached past key and value projection states
    output_attentions (`bool`, *optional*):
        Whether or not to return the attentions tensors of all attention layers. See `attentions` under
        returned tensors for more detail.


def _find_executable_or_die(executable_name: str, executable_path: Optional[str]=None) -> str:
    if executable_path:
        return str(pathlib.Path(executable_path).resolve(strict=True))
    resolved_path_to_exe = _find_executable(executable_name)
    if resolved_path_to_exe is None:
        raise RuntimeError(f'Could not find executable `{executable_name}`! Please change your $PATH or pass the path directly like`--{executable_name}_path=path/to/executable.')
    logging.info('Found path to %s at %s', executable_name, resolved_path_to_exe)
    return resolved_path_to_exe

Finds executable and resolves symlinks or raises RuntimeError.

    Resolving symlinks is sometimes necessary for finding system headers.

Args:
        executable_name: The name of the executable that we want to find.
        executable_path: If not None, the path to the executable.

Returns:
        The path to the executable we are looking for, after symlinks are resolved.

Raises:
        RuntimeError: if path to the executable cannot be found.


def AddBackpropAccumulatedValue(self, history_value, value, dead_branch=False):
    history_ctxt = history_value.op._get_control_flow_context()
    cond_ctxt = None
    value_ctxt = value.op._get_control_flow_context()
    while value_ctxt and value_ctxt != history_ctxt:
        if isinstance(value_ctxt, control_flow_ops.CondContext):
            cond_ctxt = value_ctxt
            break
        value_ctxt = value_ctxt.outer_context
    with ops.control_dependencies(None):
        self.grad_context.Enter()
        if cond_ctxt:
            grad_state = self
            pred = None
            while pred is None and grad_state:
                pred = grad_state.history_map.get(cond_ctxt.pred.name)
                grad_state = grad_state.outer_grad_state
            if pred is None:
                pred = cond_ctxt.pred
            branch = 1 - cond_ctxt.branch if dead_branch else cond_ctxt.branch
            history_value = control_flow_ops._SwitchRefOrTensor(history_value, pred)[branch]
        pop = gen_data_flow_ops.stack_pop_v2(history_value, value.dtype.base_dtype)
        pop.set_shape(value.get_shape())
        self.grad_context.Exit()
    parallel_iterations = self.grad_context.parallel_iterations
    if parallel_iterations > 1:
        self.grad_sync._add_control_input(pop.op)
    return pop

Add the getter for an accumulated value in the grad context.

    This is added to the backprop loop. Called in the grad context to
    get the value of an accumulated value. The stack pop op must be guarded
    by the pred of the controlling cond.

Args:
        history_value: The history (a stack) of a value.
        value: The value that is pushed onto the stack.
        dead_branch: True iff the tensor is on a dead branch of a cond.

Returns:
        The current value (the top of the stack).


def _consume_line(line_info, state):
    _update_section_state(line_info, state)
    if state.section.title is None:
        if state.summary.permitted:
            if line_info.remaining:
                state.summary.lines.append(line_info.remaining)
            elif state.summary.lines:
                state.summary.permitted = False
        else:
            state.description.lines.append(line_info.remaining_raw)
    else:
        state.summary.permitted = False
    if state.section.new and state.section.format == Formats.RST:
        directive = _get_directive(line_info)
        directive_tokens = directive.split()
        if state.section.title == Sections.ARGS:
            name = directive_tokens[-1]
            arg = _get_or_create_arg_by_name(state, name, is_kwarg=directive_tokens[0] == 'key')
            if len(directive_tokens) == 3:
                arg.type.lines.append(directive_tokens[1])
            state.current_arg = arg
        elif state.section.title == Sections.TYPE:
            name = directive_tokens[-1]
            arg = _get_or_create_arg_by_name(state, name)
            state.current_arg = arg
    if state.section.format == Formats.NUMPY and _line_is_hyphens(line_info.remaining):
        return
    if state.section.title == Sections.ARGS:
        if state.section.format == Formats.GOOGLE:
            _consume_google_args_line(line_info, state)
        elif state.section.format == Formats.RST:
            state.current_arg.description.lines.append(line_info.remaining.strip())
        elif state.section.format == Formats.NUMPY:
            line_stripped = line_info.remaining.strip()
            if _is_arg_name(line_stripped):
                arg = _get_or_create_arg_by_name(state, line_stripped)
                state.current_arg = arg
            elif _line_is_numpy_parameter_type(line_info):
                possible_args, type_data = line_stripped.split(':', 1)
                arg_names = _as_arg_names(possible_args)
                if arg_names:
                    for arg_name in arg_names:
                        arg = _get_or_create_arg_by_name(state, arg_name)
                        arg.type.lines.append(type_data)
                        state.current_arg = arg
                elif state.current_arg:
                    state.current_arg.description.lines.append(line_info.remaining.strip())
                else:
                    pass
            elif state.current_arg:
                state.current_arg.description.lines.append(line_info.remaining.strip())
            else:
                pass
    elif state.section.title == Sections.RETURNS:
        state.returns.lines.append(line_info.remaining.strip())
    elif state.section.title == Sections.YIELDS:
        state.yields.lines.append(line_info.remaining.strip())
    elif state.section.title == Sections.RAISES:
        state.raises.lines.append(line_info.remaining.strip())
    elif state.section.title == Sections.TYPE:
        if state.section.format == Formats.RST:
            assert state.current_arg is not None
            state.current_arg.type.lines.append(line_info.remaining.strip())
        else:
            pass

Consumes one line of text, updating the state accordingly.

    When _consume_line is called, part of the line may already have been processed
    for header information.

Args:
        line_info: Information about the current and next line of the docstring.
        state: The state of the docstring parser.


def decode_raw_v1(input_bytes=None, out_type=None, little_endian=True, name=None, bytes=None):
    input_bytes = deprecation.deprecated_argument_lookup('input_bytes', input_bytes, 'bytes', bytes)
    if out_type is None:
        raise ValueError("decode_raw_v1() missing 1 positional argument: 'out_type'")
    return gen_parsing_ops.decode_raw(input_bytes, out_type, little_endian=little_endian, name=name)

Convert raw byte strings into tensors.

Args:
        input_bytes:
        Each element of the input Tensor is converted to an array of bytes.
        out_type:
        `DType` of the output. Acceptable types are `half`, `float`, `double`,
        `int32`, `uint16`, `uint8`, `int16`, `int8`, `int64`.
        little_endian:
        Whether the `input_bytes` data is in little-endian format. Data will be
        converted into host byte order if necessary.
        name: A name for the operation (optional).
        bytes: Deprecated parameter. Use `input_bytes` instead.

Returns:
        A `Tensor` object storing the decoded bytes.


def __init__(self, shape=None, dtype=dtypes.float32):
    self._shape = tensor_shape.as_shape(shape)
    self._dtype = dtypes.as_dtype(dtype)

Constructs a type specification for a `tf.sparse.SparseTensor`.

Args:
        shape: The dense shape of the `SparseTensor`, or `None` to allow any dense
        shape.
        dtype: `tf.DType` of values in the `SparseTensor`.


def report_build(config, auth, body):
    report = report_get(config, auth, name=body['metadata']['title'])
    if not report:
        body.setdefault('schedule', {})
        body['schedule'].setdefault('nextRunTimezoneCode', str(config.timezone))
        body['schedule'].setdefault('frequency', 'DAILY')
        if body['schedule']['frequency'] != 'ONE_TIME':
            body['schedule'].setdefault('startDate', {'day': config.date.day, 'month': config.date.month, 'year': config.date.year})
            body['schedule'].setdefault('endDate', {'day': config.date.day, 'month': config.date.month, 'year': config.date.year + 1})
        report = API_DBM(config, auth).queries().create(body=body).execute()
        API_DBM(config, auth).queries().run(queryId=report['queryId'], synchronous=False).execute()
    elif config.verbose:
        print('DBM Report Exists:', body['metadata']['title'])
    return report

Creates a DBM report given a JSON definition.

    The report will be automatically run the first time.

    The body JSON provided will have the following fields added if not present:
        * schedule - set to run daily and expire in one year.

Args:
        * auth: (string) Either user or service.
        * body: (json) As defined in:
        https://developers.google.com/doubleclick-advertisers/v3.2/reports#resource

Returns:
        * JSON definition of report created or existing.


def from_numbers(cls, dna_values: List[Union[int, float, str]], dna_spec: DNASpec) -> 'DNA':
    context = dict(index=0)

    def _next_decision():
        if context['index'] >= len(dna_values):
            raise ValueError(f'The input {dna_values!r} is too short for {dna_spec!r}.')
        decision = dna_values[context['index']]
        context['index'] += 1
        return decision

    def _bind_decisions(dna_spec):
        value = None
        children = None
        if dna_spec.is_space:
            children = [_bind_decisions(elem) for elem in dna_spec.elements]
        elif dna_spec.is_categorical:
            if dna_spec.num_choices == 1:
                value = _next_decision()
                if value < 0 or value >= len(dna_spec.candidates):
                    raise ValueError(f"Candidate index out of range at choice '{dna_spec.name or dna_spec.id}'. Index={value}, Number of candidates={len(dna_spec.candidates)}.")
                children = [_bind_decisions(dna_spec.candidates[value])]
            else:
                children = [_bind_decisions(spec) for spec in dna_spec.choice_specs]
        else:
            value = _next_decision()
        return DNA(value, children, spec=dna_spec)
    dna = _bind_decisions(dna_spec)
    if context['index'] != len(dna_values):
        end_pos = context['index']
        raise ValueError(f'The input {dna_values!r} is too long for {dna_spec!r}. Remaining: {dna_values[end_pos:]!r}.')
    return dna

Create a DNA from a flattened list of dna values.

Args:
        dna_values: A list of DNA values.
        dna_spec: DNASpec that interprets the dna values.

Returns:
        A DNA object.


def main():
    pip_package_dependencies = subprocess.check_output(['bazel', 'cquery', '--experimental_cc_shared_library', PIP_PACKAGE_QUERY_EXPRESSION])
    if isinstance(pip_package_dependencies, bytes):
        pip_package_dependencies = pip_package_dependencies.decode('utf-8')
    pip_package_dependencies_list = pip_package_dependencies.strip().split('\n')
    pip_package_dependencies_list = [x.split()[0] for x in pip_package_dependencies_list]
    print('Pip package superset size: %d' % len(pip_package_dependencies_list))
    tf_py_test_dependencies = subprocess.check_output(['bazel', 'cquery', '--experimental_cc_shared_library', PY_TEST_QUERY_EXPRESSION])
    if isinstance(tf_py_test_dependencies, bytes):
        tf_py_test_dependencies = tf_py_test_dependencies.decode('utf-8')
    tf_py_test_dependencies_list = tf_py_test_dependencies.strip().split('\n')
    tf_py_test_dependencies_list = [x.split()[0] for x in tf_py_test_dependencies.strip().split('\n')]
    print('Pytest dependency subset size: %d' % len(tf_py_test_dependencies_list))
    missing_dependencies = []
    ignore_extensions = ['_test', '_test.py', '_test_cpu', '_test_cpu.py', '_test_gpu', '_test_gpu.py', '_test_lib']
    ignored_files_count = 0
    denylisted_dependencies_count = len(DEPENDENCY_DENYLIST)
    for dependency in tf_py_test_dependencies_list:
        if dependency and dependency.startswith('//tensorflow'):
            ignore = False
            if any((dependency.endswith(ext) for ext in ignore_extensions)):
                ignore = True
                ignored_files_count += 1
            if not (ignore or dependency in pip_package_dependencies_list or dependency in DEPENDENCY_DENYLIST):
                missing_dependencies.append(dependency)
    print('Ignored files count: %d' % ignored_files_count)
    print('Denylisted dependencies count: %d' % denylisted_dependencies_count)
    if missing_dependencies:
        print('Missing the following dependencies from pip_packages:')
        for missing_dependency in missing_dependencies:
            print('\nMissing dependency: %s ' % missing_dependency)
            print('Affected Tests:')
            rdep_query = 'rdeps(kind(py_test, %s), %s)' % (' + '.join(PYTHON_TARGETS), missing_dependency)
            affected_tests = subprocess.check_output(['bazel', 'cquery', '--experimental_cc_shared_library', rdep_query])
            affected_tests_list = affected_tests.split('\n')[:-2]
            print('\n'.join(affected_tests_list))
        raise RuntimeError('\n    One or more added test dependencies are not in the pip package.\nIf these test dependencies need to be in TensorFlow pip package, please add them to //tensorflow/tools/pip_package/BUILD.\nElse add no_pip tag to the test.')
    else:
        print('TEST PASSED')

This script runs the pip smoke test.

Raises:
        RuntimeError: If any dependencies for py_tests exist in subSet

    Prerequisites:
        1. Bazel is installed.
        2. Running in github repo of tensorflow.
        3. Configure has been run.


def __init__(self, config: Idefics3Config):
    super().__init__()
    self.config = config
    self.layers = nn.ModuleList([Idefics3EncoderLayer(config) for _ in range(config.num_hidden_layers)])
    self.gradient_checkpointing = False

Transformer encoder consisting of `config.num_hidden_layers` self attention layers. Each layer is a
    [`Idefics3EncoderLayer`].

Args:
        config: Idefics3Config


def get(self, path):
    if self.mode != 'r':
        raise ValueError('`get` is only allowed in read mode.')
    self._h5_entry_path = path
    self._h5_entry_group = {}
    if not path:
        if 'vars' in self.h5_file:
            self._h5_entry_group = self.h5_file['vars']
    elif path in self.h5_file and 'vars' in self.h5_file[path]:
        self._h5_entry_group = self.h5_file[path]['vars']
    elif '_layer_checkpoint_dependencies' in self.h5_file:
        path = path.replace('layers', '_layer_checkpoint_dependencies')
        if path in self.h5_file and 'vars' in self.h5_file[path]:
            self._h5_entry_group = self.h5_file[path]['vars']
    self._h5_entry_initialized = True
    return self

Get the H5 entry group.

    This method is only available in read mode.

Args:
        path: `str`. The variable path.


def policy_scope(policy):
    old_policy = _global_policy
    try:
        set_global_policy(policy)
        yield
    finally:
        set_global_policy(old_policy)

A context manager that sets the global Policy under it.

Args:
        policy: A Policy, or a string that will be converted to a Policy..

Yields:
        Nothing.


def GetTestConfigs(include_nchw_vect_c=False, one_dimensional=False):
    if one_dimensional:
        test_configs = [('NWC', False), ('NWC', True)]
        if test.is_gpu_available(cuda_only=True):
            test_configs += [('NCW', True)]
        return test_configs
    test_configs = [('NHWC', False), ('NHWC', True)]
    if not test.is_gpu_available(cuda_only=True):
        tf_logging.info('NCHW and NCHW_VECT_C tests skipped because not run with --config=cuda or no GPUs available.')
        return test_configs
    test_configs += [('NCHW', True)]
    if include_nchw_vect_c:
        if test.is_gpu_available(cuda_only=True, min_cuda_compute_capability=(6, 1)):
            test_configs += [('NCHW_VECT_C', True)]
        else:
            tf_logging.info('NCHW_VECT_C test skipped because no GPUs with compute capability >= 6.1 are available.')
    return test_configs

Get all the valid tests configs to run.

Args:
        include_nchw_vect_c: Whether to include NCHW_VECT_C in the test configs.
        one_dimensional: If it's a 1D test

Returns:
        all the valid test configs as tuples of data_format and use_gpu.


def partition_graphs(self):
    if not self._debug_graphs:
        raise LookupError('No partition graphs have been loaded.')
    return [self._debug_graphs[key].debug_graph_def for key in self._debug_graphs]

Get the partition graphs.

Returns:
        Partition graphs as a list of GraphDef.

Raises:
        LookupError: If no partition graphs have been loaded.


def queryString_required_ClassVersion(strList):

	def _dec(function):
		@wraps(function)
		def _wrap(classInstance, request, *args, **kwargs):
			for i in strList:
				if i not in request.GET:
					raise Http404("api does not exist")
			return function(classInstance, request, *args, **kwargs)
		return _wrap
	return _dec

An decorator checking whether queryString key is valid or not

Args:
    str: allowed queryString key

Returns:
    if contains invalid queryString key, it will raise exception.


def ignore_path(path):

        ignore = False
        for name in ['.tox', 'dist', 'build', 'node_modules', 'htmlcov']:
            if path.find(name) >= 0:
                ignore = True
                break
        return ignore

Verify whether to ignore a path.

Args:
        path (str): path to check.

Returns:
        bool: True when to ignore given path.


def claim(self, unclaimed_file_readers):

        claimed_vcf_readers = []
        for caller in self._callers:
            (unclaimed_file_readers,
             translated_vcf_readers) = caller.claim(unclaimed_file_readers)
            claimed_vcf_readers.extend(translated_vcf_readers)

        return unclaimed_file_readers, claimed_vcf_readers

Allows each caller to claim incoming files as they are recognized.

Args:
        unclaimed_file_readers: Usually, all files in the input dir.

Returns:
        A tuple of unclaimed file readers and claimed VcfReaders. The
        presence of any unclaimed file readers could indicate stray files
        in the input dir.


def change_t(self, t):

        t = super().change_t(t)
        self.__now_cycles += 1
        if self.__now_cycles % self.__reannealing_per == 0:
            t = t * self.__thermostat

            if t < self.__t_min:
                t = self.__t_default
        return t

Change temperature.

    Override.

Args:
        t:    Now temperature.

Returns:
        Next temperature.


def connection_made(self, transport):

        self.transport = transport
        self.responders = [self.make_responder(self)]

        try:
            good_func = callable(self.responders[0].on_data)
        except AttributeError:
            good_func = False

        if not good_func:
            err_str = "Provided responder MUST implement an 'on_data' method"
            raise TypeError(err_str)

        log_info = (id(self), self.remote_hostname, self.remote_port)
        log.info("{:d} connection from {}:{}", *log_info)

(asyncio.Protocol member)

    Called upon when there is a new socket connection.
    This creates a new responder (as determined by the member
    'responder_type') and stores in a list.
    Incoming data from this connection will always call on_data
    to the last element of this list.

Args:
        transport (asyncio.Transport): The Transport handling the
            socket communication


def get_country_name_from_iso2(cls, iso2, use_live=True, exception=None):
        # type: (str, bool, Optional[ExceptionUpperBound]) -> Optional[str]

        iso3 = cls.get_iso3_from_iso2(iso2, use_live=use_live, exception=exception)
        if iso3 is not None:
            return cls.get_country_name_from_iso3(iso3, exception=exception)
        return None

Get country name from ISO2 code

Args:
        iso2 (str): ISO2 code for which to get country name
        use_live (bool): Try to get use latest data from web rather than file in package. Defaults to True.
        exception (Optional[ExceptionUpperBound]): An exception to raise if country not found. Defaults to None.

Returns:
        Optional[str]: Country name


def devno_free_if_allocated(self, devno):

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

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

    If the device number is not currently allocated or not in the pool
    range, nothing happens.

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


def get_varname_from_locals(val, locals_, default='varname-not-found',
                            strict=False, cmpfunc_=operator.is_):

    if val is None or isinstance(val, (int, float, bool)):
        # Cannot work on primative types
        return default
    try:
        for count, val_ in enumerate(six.itervalues(locals_)):
            if cmpfunc_(val, val_):
                index_ = count
        varname = six.text_type(list(locals_.keys())[index_])
    except NameError:
        varname = default
        if strict:
            raise
    return varname

Finds the string name which has where locals_[name] is val

    Check the varname is in the parent namespace
    This will only work with objects not primatives

Args:
        val (): some value
        locals_ (dict): local dictionary to search
        default (str):
        strict (bool):

Returns:
        str: the varname which is Val (if it exists)


def get_subscribers(object_type: str) -> List[str]:

    return DB.get_list(_keys.subscribers(object_type))

Get the list of subscribers to events of the object type.

Args:
        object_type (str): Type of object.

Returns:
        List[str], list of subscriber names.


def group_device_names(devices, group_size):

    num_devices = len(devices)
    if group_size > num_devices:
        raise ValueError(
            "only %d devices, but group_size=%d" % (num_devices, group_size))
    num_groups = (
        num_devices // group_size + (1 if
                                     (num_devices % group_size != 0) else 0))
    groups = [[] for i in range(num_groups)]
    for i in range(0, num_groups * group_size):
        groups[i % num_groups].append(devices[i % num_devices])
    return groups

Group device names into groups of group_size.

Args:
        devices: list of strings naming devices.
        group_size: int >= 1

Returns:
        list of lists of devices, where each inner list is group_size long,
        and each device appears at least once in an inner list.  If
        len(devices) % group_size = 0 then each device will appear
        exactly once.

Raises:
        ValueError: group_size > len(devices)


def poll(self, channel_id=None, json=None, **kwargs):  # pragma: no cover

        path = "/event-service/v1/channels/{}/poll".format(channel_id)
        r = self._httpclient.request(
            method="POST",
            url=self.url,
            json=json,
            path=path,
            **kwargs
        )
        return r

Read one or more events from a channel.

    Reads events (log records) from the identified channel. Events
    are read in chronological order.

Args:
        channel_id (str): The channel ID.
        json (dict): Payload/request body.
        **kwargs: Supported :meth:`~pancloud.httpclient.HTTPClient.request` parameters.

Returns:
        requests.Response: Requests Response() object.

Example:
        Refer to ``event_poll.py`` example.


def delay(self, methodname, *args, **kwargs):

        ID = str(uuid.uuid4())
        self.send_query(ID, methodname, False, *args, **kwargs)
        return ID

调用但不要求返回结果,而是通过系统方法getresult来获取.

    Parameters:
        methodname (str): - 要调用的方法名
        args (Any): - 要调用的方法的位置参数
        kwargs (Any): - 要调用的方法的关键字参数


def source_required(src_file):

    if not src_file.exists():
        return True

    required = True
    hash_file = src_file.with_suffix(".hash", depth=0)
    LOG.debug("Hash file location: %s", hash_file)
    if hash_file.exists():
        new_hash = get_hash_of_dirs(src_file)
        with open(hash_file, 'r') as h_file:
            old_hash = h_file.readline()
        required = not new_hash == old_hash
        if required:
            from benchbuild.utils.cmd import rm
            rm("-r", src_file)
            rm(hash_file)
    if required:
        LOG.info("Source required for: %s", src_file)
        LOG.debug("Reason: src-exists: %s hash-exists: %s", src_file.exists(),
                  hash_file.exists())
    return required

Check, if a download is required.

Args:
        src_file: The filename to check for.
        src_root: The path we find the file in.

Returns:
        True, if we need to download something, False otherwise.


def accuracy(y_true: [list, np.ndarray], y_predicted: [list, np.ndarray]) -> float:

    examples_len = len(y_true)
    correct = sum([y1 == y2 for y1, y2 in zip(y_true, y_predicted)])
    return correct / examples_len if examples_len else 0

Calculate accuracy in terms of absolute coincidence

Args:
        y_true: array of true values
        y_predicted: array of predicted values

Returns:
        portion of absolutely coincidental samples


def run_custom_bird_reconfigure(operation):

    log = logging.getLogger(PROGRAM_NAME)
    if isinstance(operation, AddOperation):
        status = 'up'
    else:
        status = 'down'
    cmd = shlex.split(operation.bird_reconfigure_cmd + " " + status)
    log.info("reconfiguring BIRD by running custom command %s", ' '.join(cmd))
    try:
        proc = subprocess.Popen(cmd,
                                start_new_session=True,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        _, errs = proc.communicate(
            timeout=operation.bird_reconfigure_timeout
        )
    except OSError as exc:
        log.error("reconfiguring BIRD failed with: %s", exc)
    except subprocess.TimeoutExpired as exc:
        log.error("reconfiguring bird timed out")
        if proc.poll() is None:  # if process is still alive
            try:
                os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
            except PermissionError as exc:
                log.error("failed to terminate custom bird command: %s", exc)
    else:
        if proc.returncode != 0:
            log.error("reconfiguring BIRD failed with return code: %s and "
                      "stderr: %s", proc.returncode, errs)
        else:
            log.info("custom command successfully reconfigured Bird")

Reconfigure BIRD daemon by running a custom command.

    It adds one argument to the command, either "up" or "down".
    If command times out then we kill it. In order to avoid leaving any orphan
    processes, that may have been started by the command, we start a new
    session when we invoke the command and then we kill process group of that
    session.

Args:
        operation (obj): Either a AddOperation or DeleteOperation object.


def plot_probabilities_histogram(Y_p, title=None):

    if Y_p.ndim > 1:
        msg = (
            f"Arg Y_p should be a 1-dimensional np.ndarray, not of shape "
            f"{Y_p.shape}."
        )
        raise ValueError(msg)
    plt.hist(Y_p, bins=20)
    plt.xlim((0, 1.025))
    plt.xlabel("Probability")
    plt.ylabel("# Predictions")
    if isinstance(title, str):
        plt.title(title)
    plt.show()

Plot a histogram from a numpy array of probabilities

Args:
        Y_p: An [n] or [n, 1] np.ndarray of probabilities (floats in [0,1])


def Main(url):

    # The object of Web-Scraping.
    web_scrape = WebScraping()
    # Execute Web-Scraping.
    document = web_scrape.scrape(url)
    # The object of automatic summarization with N-gram.
    auto_abstractor = NgramAutoAbstractor()
    # n-gram object
    auto_abstractor.n_gram = Ngram()
    # n of n-gram
    auto_abstractor.n = 3
    # Set tokenizer. This is japanese tokenizer with MeCab.
    auto_abstractor.tokenizable_doc = MeCabTokenizer()
    # Object of abstracting and filtering document.
    abstractable_doc = TopNRankAbstractor()
    # Execute summarization.
    result_dict = auto_abstractor.summarize(document, abstractable_doc)

    # Output 3 summarized sentences.
    limit = 3
    i = 1
    for sentence in result_dict["summarize_result"]:
        print(sentence)
        if i >= limit:
            break
        i += 1

Entry Point.

Args:
        url:    target url.


def GetAllUsers(self, pagination_size=10):

    next_page_token, accounts = self.rpc_helper.DownloadAccount(
        None, pagination_size)
    while accounts:
      for account in accounts:
        yield GitkitUser.FromApiResponse(account)
      next_page_token, accounts = self.rpc_helper.DownloadAccount(
          next_page_token, pagination_size)

Gets all user info from Gitkit server.

Args:
        pagination_size: int, how many users should be returned per request.
        The account info are retrieved in pagination.

Yields:
        A generator to iterate all users.


def fill(self, text):

        def _fill(elem):  # pylint: disable=missing-docstring
            elem.clear()
            elem.send_keys(text)

        self.map(_fill, u'fill({!r})'.format(text)).execute()

Set the text value of each matched element to `text`.

    Example usage:

    .. code:: python

        # Set the text of the first element matched by the query to "Foo"
        q.first.fill('Foo')

Args:
        text (str): The text used to fill the element (usually a text field or text area).

Returns:
        None


def pull_datapackage(descriptor, name, backend, **backend_options):

    # Deprecated
    warnings.warn(
        'Functions "push/pull_datapackage" are deprecated. '
        'Please use "Package" class',
        UserWarning)

    # Save datapackage name
    datapackage_name = name

    # Get storage
    plugin = import_module('jsontableschema.plugins.%s' % backend)
    storage = plugin.Storage(**backend_options)

    # Iterate over tables
    resources = []
    for table in storage.buckets:

        # Prepare
        schema = storage.describe(table)
        base = os.path.dirname(descriptor)
        path, name = _restore_path(table)
        fullpath = os.path.join(base, path)

        # Write data
        helpers.ensure_dir(fullpath)
        with io.open(fullpath, 'wb') as file:
            model = Schema(deepcopy(schema))
            data = storage.iter(table)
            writer = csv.writer(file, encoding='utf-8')
            writer.writerow(model.headers)
            for row in data:
                writer.writerow(row)

        # Add resource
        resource = {'schema': schema, 'path': path}
        if name is not None:
            resource['name'] = name
        resources.append(resource)

    # Write descriptor
    mode = 'w'
    encoding = 'utf-8'
    if six.PY2:
        mode = 'wb'
        encoding = None
    resources = _restore_resources(resources)
    helpers.ensure_dir(descriptor)
    with io.open(descriptor,
                 mode=mode,
                 encoding=encoding) as file:
        descriptor = {
            'name': datapackage_name,
            'resources': resources,
        }
        json.dump(descriptor, file, indent=4)
    return storage

Pull Data Package from storage.

    All parameters should be used as keyword arguments.

Args:
        descriptor (str): path where to store descriptor
        name (str): name of the pulled datapackage
        backend (str): backend name like `sql` or `bigquery`
        backend_options (dict): backend options mentioned in backend docs


def mapped_repr_stripping_underscores(
        obj: Any, attrnames: List[str],
        with_addr: bool = False, joiner: str = COMMA_SPACE) -> str:

    attributes = []
    for attr_name in attrnames:
        if attr_name.startswith('_'):
            init_param_name = attr_name[1:]
        else:
            init_param_name = attr_name
        attributes.append((attr_name, init_param_name))
    return mapped_repr(obj, attributes, with_addr=with_addr, joiner=joiner)

Convenience function for :func:`__repr__`.
    Here, you pass a list of internal attributes, and it assumes that the
    :func:`__init__` parameter names have the leading underscore dropped.

Args:
        obj: object to display
        attrnames: list of attribute names
        with_addr: include the memory address of ``obj``
        joiner: string with which to join the elements

Returns:
        string: :func:`repr`-style representation


def pprint_cell(self, row, col):

        ndims = self.ndims
        if col >= self.cols:
            raise Exception("Maximum column index is %d" % self.cols-1)
        elif row >= self.rows:
            raise Exception("Maximum row index is %d" % self.rows-1)
        elif row == 0:
            if col >= ndims:
                if self.vdims:
                    return self.vdims[col - ndims].pprint_label
                else:
                    return ''
            return self.kdims[col].pprint_label
        else:
            dim = self.get_dimension(col)
            return dim.pprint_value(self.iloc[row-1, col])

Formatted contents of table cell.

Args:
        row (int): Integer index of table row
        col (int): Integer index of table column

Returns:
        Formatted table cell contents


def get_upstream_artifacts_full_paths_per_task_id(context):

    upstream_artifacts = context.task['payload']['upstreamArtifacts']
    task_ids_and_relative_paths = [
        (artifact_definition['taskId'], artifact_definition['paths'])
        for artifact_definition in upstream_artifacts
    ]

    optional_artifacts_per_task_id = get_optional_artifacts_per_task_id(upstream_artifacts)

    upstream_artifacts_full_paths_per_task_id = {}
    failed_paths_per_task_id = {}
    for task_id, paths in task_ids_and_relative_paths:
        for path in paths:
            try:
                path_to_add = get_and_check_single_upstream_artifact_full_path(context, task_id, path)
                add_enumerable_item_to_dict(
                    dict_=upstream_artifacts_full_paths_per_task_id,
                    key=task_id, item=path_to_add
                )
            except ScriptWorkerTaskException:
                if path in optional_artifacts_per_task_id.get(task_id, []):
                    log.warning('Optional artifact "{}" of task "{}" not found'.format(path, task_id))
                    add_enumerable_item_to_dict(
                        dict_=failed_paths_per_task_id,
                        key=task_id, item=path
                    )
                else:
                    raise

    return upstream_artifacts_full_paths_per_task_id, failed_paths_per_task_id

List the downloaded upstream artifacts.

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

Returns:
        dict, dict: lists of the paths to upstream artifacts, sorted by task_id.
            First dict represents the existing upstream artifacts. The second one
            maps the optional artifacts that couldn't be downloaded

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


Copolarized correlation (rho_hv) for the current setup.

Args:
        scatterer: a Scatterer instance.

Returns:
        rho_hv.


def transform(self, args):

        if self.parse_error():
            # Write an empty hash so next run will check the config file against the entire command table again
            AliasManager.write_alias_config_hash(empty_hash=True)
            return args

        # Only load the entire command table if it detects changes in the alias config
        if self.detect_alias_config_change():
            self.load_full_command_table()
            self.collided_alias = AliasManager.build_collision_table(self.alias_table.sections())
            build_tab_completion_table(self.alias_table)
        else:
            self.load_collided_alias()

        transformed_commands = []
        alias_iter = enumerate(args, 1)
        for alias_index, alias in alias_iter:
            is_collided_alias = alias in self.collided_alias and alias_index in self.collided_alias[alias]
            # Check if the current alias is a named argument
            # index - 2 because alias_iter starts counting at index 1
            is_named_arg = alias_index > 1 and args[alias_index - 2].startswith('-')
            is_named_arg_flag = alias.startswith('-')
            excluded_commands = is_alias_command(['remove', 'export'], transformed_commands)
            if not alias or is_collided_alias or is_named_arg or is_named_arg_flag or excluded_commands:
                transformed_commands.append(alias)
                continue

            full_alias = self.get_full_alias(alias)

            if self.alias_table.has_option(full_alias, 'command'):
                cmd_derived_from_alias = self.alias_table.get(full_alias, 'command')
                telemetry.set_alias_hit(full_alias)
            else:
                transformed_commands.append(alias)
                continue

            pos_args_table = build_pos_args_table(full_alias, args, alias_index)
            if pos_args_table:
                logger.debug(POS_ARG_DEBUG_MSG, full_alias, cmd_derived_from_alias, pos_args_table)
                transformed_commands += render_template(cmd_derived_from_alias, pos_args_table)

                # Skip the next arg(s) because they have been already consumed as a positional argument above
                for pos_arg in pos_args_table:  # pylint: disable=unused-variable
                    next(alias_iter)
            else:
                logger.debug(DEBUG_MSG, full_alias, cmd_derived_from_alias)
                transformed_commands += shlex.split(cmd_derived_from_alias)

        return self.post_transform(transformed_commands)

Transform any aliases in args to their respective commands.

Args:
        args: A list of space-delimited command input extracted directly from the console.

Returns:
        A list of transformed commands according to the alias configuration file.


def _finish_disconnection_action(self, action):

        success = action.data['success']
        conn_key = action.data['id']

        if self._get_connection_state(conn_key) != self.Disconnecting:
            self._logger.error("Invalid finish_disconnection action on a connection whose state is not Disconnecting, conn_key=%s", str(conn_key))
            return

        # Cannot be None since we checked above to make sure it exists
        data = self._get_connection(conn_key)
        callback = data['callback']

        conn_id = data['conn_id']
        int_id = data['int_id']

        if success is False:
            reason = action.data['reason']
            if reason is None:
                reason = "No reason was given"

            data['state'] = self.Idle
            data['microstate'] = None
            data['callback'] = None
            callback(conn_id, self.id, False, reason)
        else:
            del self._connections[conn_id]
            del self._int_connections[int_id]
            callback(conn_id, self.id, True, None)

Finish a disconnection attempt

    There are two possible outcomes:
    - if we were successful at disconnecting, we transition to disconnected
    - if we failed at disconnecting, we transition back to idle

Args:
        action (ConnectionAction): the action object describing what we are
            disconnecting from and what the result of the operation was


def _find_address_range(addresses):

    it = iter(addresses)
    first = last = next(it)
    for ip in it:
        if ip._ip != last._ip + 1:
            yield first, last
            first = ip
        last = ip
    yield first, last

Find a sequence of sorted deduplicated IPv#Address.

Args:
        addresses: a list of IPv#Address objects.

Yields:
        A tuple containing the first and last IP addresses in the sequence.


def blocks(self, name):

        b = self._blocks(name)
        if b:
            return b
        return self._blocks(name.replace('?>?', ' '))

Search for defined blocks recursively.
    Allow '>' to be ignored. '.a .b' == '.a > .b'

Args:
        name (string): Search term

Returns:
        Block object OR False


def decode_offset_response(cls, data):

        ((correlation_id, num_topics), cur) = relative_unpack('>ii', data, 0)

        for _ in range(num_topics):
            (topic, cur) = read_short_string(data, cur)
            ((num_partitions,), cur) = relative_unpack('>i', data, cur)

            for _ in range(num_partitions):
                ((partition, error, num_offsets,), cur) = \
                    relative_unpack('>ihi', data, cur)

                offsets = []
                for k in range(num_offsets):
                    ((offset,), cur) = relative_unpack('>q', data, cur)
                    offsets.append(offset)

                yield OffsetResponse(topic, partition, error, tuple(offsets))

Decode bytes to an OffsetResponse

Args:
        data: bytes to decode


def set_query_parameter(url, param_name, param_value):

    scheme, netloc, path, query_string, fragment = urlsplit(url)
    query_params = parse_qs(query_string)

    query_params[param_name] = [param_value]
    new_query_string = urlencode(query_params, doseq=True)

    return urlunsplit((scheme, netloc, path, new_query_string, fragment))

Given a URL, set or replace a query parameter and return the modified URL.

Args:
        url: a given  URL
        param_name: the parameter name to add
        param_value: the parameter value

Returns:
        URL with the added parameter


def increment(self, size: int):

        assert size >= 0, size

        self.files += 1
        self.size += size
        self.bandwidth_meter.feed(size)

Increment the number of files downloaded.

Args:
        size: The size of the file


def load_steps(working_dir=None, steps_dir=None, step_file=None,
               step_list=None):

    if steps_dir is not None:
        step_files = glob.glob(os.path.join(steps_dir, '*.cwl'))
    elif step_file is not None:
        step_files = [step_file]
    elif step_list is not None:
        step_files = []
        for path in step_list:
            if os.path.isdir(path):
                step_files += glob.glob(os.path.join(path, '*.cwl'))
            else:
                step_files.append(path)
    else:
        step_files = []

    if working_dir is not None:
        step_files = sort_loading_order(step_files)

    steps = {}
    for f in step_files:
        if working_dir is not None:
            # Copy file to working_dir
            if not working_dir == os.path.dirname(f) and not is_url(f):
                copied_file = os.path.join(working_dir, os.path.basename(f))
                shutil.copy2(f, copied_file)
                f = copied_file

        # Create steps
        try:
            s = Step(f)
            steps[s.name] = s
        except (NotImplementedError, ValidationException,
                PackedWorkflowException) as e:
            logger.warning(e)

    return steps

Return a dictionary containing Steps read from file.

Args:
        steps_dir (str, optional): path to directory containing CWL files.
        step_file (str, optional): path or http(s) url to a single CWL file.
        step_list (list, optional): a list of directories, urls or local file
            paths to CWL files or directories containing CWL files.

Returns:
        dict containing (name, Step) entries.


def dense_message_pass(node_states, edge_matrices):

  batch_size, num_nodes, node_dim = common_layers.shape_list(node_states)

  # Stack the nodes as a big column vector.
  h_flat = tf.reshape(
      node_states, [batch_size, num_nodes * node_dim, 1], name="h_flat")

  messages = tf.reshape(
      tf.matmul(edge_matrices, h_flat), [batch_size * num_nodes, node_dim],
      name="messages_matmul")

  message_bias = tf.get_variable("message_bias", shape=node_dim)
  messages = messages + message_bias
  messages = tf.reshape(messages, [batch_size, num_nodes, node_dim])
  return messages

Computes a_t from h_{t-1}, see bottom of page 3 in the paper.

Args:
        node_states: [B, L, D] tensor (h_{t-1})
        edge_matrices (tf.float32): [B, L*D, L*D]

Returns:
        messages (tf.float32): [B, L, D] For each pair
        of nodes in the graph a message is sent along both the incoming and
        outgoing edge.


def Emulation_setCPUThrottlingRate(self, rate):

		assert isinstance(rate, (float, int)
		    ), "Argument 'rate' must be of type '['float', 'int']'. Received type: '%s'" % type(
		    rate)
		subdom_funcs = self.synchronous_command('Emulation.setCPUThrottlingRate',
		    rate=rate)
		return subdom_funcs

Function path: Emulation.setCPUThrottlingRate
    Domain: Emulation
    Method name: setCPUThrottlingRate

    WARNING: This function is marked 'Experimental'!

    Parameters:
    Required arguments:
        'rate' (type: number) -> Throttling rate as a slowdown factor (1 is no throttle, 2 is 2x slowdown, etc).
    No return value.

    Description: Enables CPU throttling to emulate slow CPUs.


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

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

Pow this DataFrame against another DataFrame/Series/scalar.

Args:
        other: The object to use to apply the pow against this.
        axis: The axis to pow over.
        level: The Multilevel index level to apply pow over.
        fill_value: The value to fill NaNs with.

Returns:
        A new DataFrame with the Pow applied.


def set_inode(self, ino):
        # type: (inode.Inode) -> None

        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError('El Torito Entry not yet initialized')
        self.inode = ino

A method to set the Inode associated with this El Torito Entry.

    Parameters:
    ino - The Inode object corresponding to this entry.

Returns:
    Nothing.


def _write_to_hdx(self, action, data, id_field_name, file_to_upload=None):
        # type: (str, Dict, str, Optional[str]) -> Dict

        file = None
        try:
            if file_to_upload:
                file = open(file_to_upload, 'rb')
                files = [('upload', file)]
            else:
                files = None
            return self.configuration.call_remoteckan(self.actions()[action], data, files=files)
        except Exception as e:
            raisefrom(HDXError, 'Failed when trying to %s %s! (POST)' % (action, data[id_field_name]), e)
        finally:
            if file_to_upload and file:
                file.close()

Creates or updates an HDX object in HDX and return HDX object metadata dict

Args:
        action (str): Action to perform eg. 'create', 'update'
        data (Dict): Data to write to HDX
        id_field_name (str): Name of field containing HDX object identifier or None
        file_to_upload (Optional[str]): File to upload to HDX

Returns:
        Dict: HDX object metadata


def Sign(verifiable, keypair):

        prikey = bytes(keypair.PrivateKey)
        hashdata = verifiable.GetHashData()
        res = Crypto.Default().Sign(hashdata, prikey)
        return res

Sign the `verifiable` object with the private key from `keypair`.

Args:
        verifiable:
        keypair (neocore.KeyPair):

Returns:
        bool: True if successfully signed. False otherwise.


def get_cluster_interfaces(cluster, extra_cond=lambda nic: True):

    nics = get_nics(cluster)
    # NOTE(msimonin): Since 05/18 nics on g5k nodes have predictable names but
    # the api description keep the legacy name (device key) and the new
    # predictable name (key name).  The legacy names is still used for api
    # request to the vlan endpoint This should be fixed in
    # https://intranet.grid5000.fr/bugzilla/show_bug.cgi?id=9272
    # When its fixed we should be able to only use the new predictable name.
    nics = [(nic['device'], nic['name']) for nic in nics
            if nic['mountable']
            and nic['interface'] == 'Ethernet'
            and not nic['management']
            and extra_cond(nic)]
    nics = sorted(nics)
    return nics

Get the network interfaces names corresponding to a criteria.

    Note that the cluster is passed (not the individual node names), thus it is
    assumed that all nodes in a cluster have the same interface names same
    configuration. In addition to ``extra_cond``, only the mountable and
    Ehernet interfaces are returned.

Args:
        cluster(str): the cluster to consider
        extra_cond(lambda): boolean lambda that takes the nic(dict) as
            parameter


def WriteEventBody(self, event):

    if not hasattr(event, 'timestamp'):
      return

    # TODO: preserve dfdatetime as an object.
    date_time = dfdatetime_posix_time.PosixTimeInMicroseconds(
        timestamp=event.timestamp)
    posix_timestamp = date_time.CopyToPosixTimestamp()
    if not posix_timestamp:
      posix_timestamp = 0

    source = self._FormatSource(event)
    hostname = self._FormatHostname(event)
    username = self._FormatUsername(event)
    description = self._FormatDescription(event)
    notes = self._FormatNotes(event)

    out_write = '{0:d}|{1:s}|{2:s}|{3:s}|{4:s}|{5!s}|{6!s}\n'.format(
        posix_timestamp, source, hostname, username, description,
        self._output_mediator.timezone, notes)

    self._output_writer.Write(out_write)

Writes the body of an event object to the output.

Args:
        event (EventObject): event.


def download_file(self, url):

        response = requests.get(url, stream=True)
        response.raise_for_status()
        return (int(response.headers.get('content-length', 0)), response)

Initiate a streaming download

Args:
        url (str): The url to download

Returns:
        A tuple of the content length and the streaming response


def Open(self, file_object):

    self._file_object = file_object
    self._regf_file.open_file_object(self._file_object)
    return True

Opens the Windows Registry file using a file-like object.

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

Returns:
        bool: True if successful or False if not.


def save_images(images, filenames, output_dir):

  for i, filename in enumerate(filenames):
    # Images for inception classifier are normalized to be in [-1, 1] interval,
    # so rescale them back to [0, 1].
    with tf.gfile.Open(os.path.join(output_dir, filename), 'w') as f:
      imsave(f, (images[i, :, :, :] + 1.0) * 0.5, format='png')

Saves images to the output directory.

Args:
        images: array with minibatch of images
        filenames: list of filenames without path
        If number of file names in this list less than number of images in
        the minibatch then only first len(filenames) images will be saved.
        output_dir: directory where to save images


def handle(self, message):

        logger.debug(message)
        if Utilities.isNotEmpty(message['metadata']['opts']):
            target = message['metadata']['opts']['target']
            self.botThread.create_message(target, message['text'])

Attempts to send a message to the specified destination in Discord.
    Extends Legobot.Lego.handle()

Args:
        message (Legobot.Message): message w/ metadata to send.


def state_estimation_ensemble(data, k, n_runs=10, M_list=[], **se_params):

    if len(M_list)==0:
        M_list = []
        for i in range(n_runs):
            M, W, ll = poisson_estimate_state(data, k, **se_params)
            M_list.append(M)
    M_stacked = np.hstack(M_list)
    M_new, W_new, ll = poisson_estimate_state(M_stacked, k, **se_params)
    W_new = np.dot(data.T, M_new)
    W_new = W_new/W_new.sum(0)
    return M_new, W_new, ll

Runs an ensemble method on the list of M results...

Args:
        data: genes x cells array
        k: number of classes
        n_runs (optional): number of random initializations of state estimation
        M_list (optional): list of M arrays from state estimation
        se_params (optional): optional poisson_estimate_state params

Returns:
        M_new
        W_new
        ll


def pxbounds(self, geom, clip=False):

        try:
            if isinstance(geom, dict):
                if 'geometry' in geom:
                    geom = shape(geom['geometry'])
                else:
                    geom = shape(geom)
            elif isinstance(geom, BaseGeometry):
                geom = shape(geom)
            else:
                geom = wkt.loads(geom)
        except:
            raise TypeError ("Invalid geometry object")

        # if geometry doesn't overlap the image, return an error
        if geom.disjoint(shape(self)):
            raise ValueError("Geometry outside of image bounds")
        # clip to pixels within the image
        (xmin, ymin, xmax, ymax) = ops.transform(self.__geo_transform__.rev, geom).bounds
        _nbands, ysize, xsize = self.shape
        if clip:
            xmin = max(xmin, 0)
            ymin = max(ymin, 0)
            xmax = min(xmax, xsize)
            ymax = min(ymax, ysize)

        return (xmin, ymin, xmax, ymax)

Returns the bounds of a geometry object in pixel coordinates

Args:
        geom: Shapely geometry object or GeoJSON as Python dictionary or WKT string
        clip (bool): Clip the bounds to the min/max extent of the image

Returns:
        list: bounds in pixels [min x, min y, max x, max y] clipped to image bounds


def produce_csv_output(filehandle: TextIO,
                       fields: Sequence[str],
                       values: Iterable[str]) -> None:

    output_csv(filehandle, fields)
    for row in values:
        output_csv(filehandle, row)

Produce CSV output, without using ``csv.writer``, so the log can be used
    for lots of things.

    - ... eh? What was I talking about?
    - POOR; DEPRECATED.

Args:
        filehandle: file to write to
        fields: field names
        values: values


def get_user(self, user_id=None, user_name=None):

        if user_id:
            endpoint = '/api/user_id/{0}'.format(user_id)
        elif user_name:
            endpoint = '/api/user_name/{0}'.format(user_name)
        else:
            # Return currently authorized user
            endpoint = '/api/user'

        data = self._make_request(verb="GET", endpoint=endpoint)

        try:
            return User.NewFromJSON(data)
        except:
            return data

Get a user object from the API. If no ``user_id`` or ``user_name``
    is specified, it will return the User object for the currently
    authenticated user.

Args:
        user_id (int): User ID of the user for whom you want to get
            information. [Optional]
        user_name(str): Username for the user for whom you want to get
            information. [Optional]

Returns:
        A User object.


def write_rtt(jlink):

    try:
        while jlink.connected():
            bytes = list(bytearray(input(), "utf-8") + b"\x0A\x00")
            bytes_written = jlink.rtt_write(0, bytes)
    except Exception:
        print("IO write thread exception, exiting...")
        thread.interrupt_main()
        raise

Writes kayboard input to JLink RTT buffer #0.

    This method is a loop that blocks waiting on stdin. When enter is pressed,
    LF and NUL bytes are added to the input and transmitted as a byte list.
    If the JLink is disconnected, it will exit gracefully. If any other
    exceptions are raised, they will be caught and re-raised after interrupting
    the main thread.

Args:
        jlink (pylink.JLink): The JLink to write to.

Raises:
        Exception on error.


def _publish_status(self, slug, data):

        status_topic = self.topics.prefix + 'devices/{}/data/status'.format(slug)

        self._logger.debug("Publishing status message: (topic=%s) (message=%s)", status_topic, str(data))
        self.client.publish(status_topic, data)

Publish a status message for a device

Args:
        slug (string): The device slug that we are publishing on behalf of
        data (dict): The status message data to be sent back to the caller


def _build_encryption_key_information(self, value):

        if value is None:
            return None
        if not isinstance(value, dict):
            raise TypeError("Encryption key information must be a dictionary.")

        cryptographic_parameters = value.get('cryptographic_parameters')
        if cryptographic_parameters:
            cryptographic_parameters = self._build_cryptographic_parameters(
                cryptographic_parameters
            )
        encryption_key_information = cobjects.EncryptionKeyInformation(
            unique_identifier=value.get('unique_identifier'),
            cryptographic_parameters=cryptographic_parameters
        )
        return encryption_key_information

Build an EncryptionKeyInformation struct from a dictionary.

Args:
        value (dict): A dictionary containing the key/value pairs for a
            EncryptionKeyInformation struct.

Returns:
        EncryptionKeyInformation: an EncryptionKeyInformation struct

Raises:
        TypeError: if the input argument is invalid


def __init__(self, connection):

        self._connection = connection

        self._latest_state_delta_event = None
        self._subscribers = []
        self._subscriber_lock = asyncio.Lock()
        self._delta_task = None
        self._listening = False
        self._accepting = True

        self._connection.on_connection_state_change(
            ConnectionEvent.DISCONNECTED,
            self._handle_disconnect)
        self._connection.on_connection_state_change(
            ConnectionEvent.RECONNECTED,
            self._handle_reconnection)

Constructs this handler on a given validator connection.

Args:
        connection (messaging.Connection): the validator connection


def xeval(source, optimize=True):

    native = xcompile(source, optimize=optimize)
    return native()

Compiles to native Python bytecode and runs program, returning the
    topmost value on the stack.

Args:
        optimize: Whether to optimize the code after parsing it.

Returns:
        None: If the stack is empty
        obj: If the stack contains a single value
        [obj, obj, ...]: If the stack contains many values


def write(self, data, report_id=0):

        if not self._is_open:
            raise HIDException("HIDDevice not open")

        write_data = bytearray([report_id]) + bytearray(data)
        cdata = ffi.new("const unsigned char[]", bytes(write_data))
        num_written = hidapi.hid_write(self._device, cdata, len(write_data))
        if num_written < 0:
            raise HIDException("Failed to write to HID device: " + str(num_written))
        else:
            return num_written

Writes data to the HID device on its endpoint.

    Parameters:
        data: data to send on the HID endpoint
        report_id: the report ID to use.

Returns:
        The number of bytes written including the report ID.


def setPadding(self, padding):

        self._pad = padding
        self._zfill = self.__class__.getPaddingNum(self._pad)

Set new padding characters for the sequence.
    i.e. "#" or "@@@" or '%04d', or an empty string to disable range formatting.

Args:
        padding (str): sequence padding to set


def compile_initial_state(self, batch_size: Optional[int] = None) -> Sequence[tf.Tensor]:

        with self.graph.as_default():
            with tf.name_scope('initial_state'):
                self._initialize_initial_state_fluents()
                if batch_size is None:
                    return self.initial_state_fluents
                return self._compile_batch_fluents(self.initial_state_fluents, batch_size)

Returns a tuple of tensors representing the initial state fluents.

Args:
        batch_size (Optional[int]): The batch size.

Returns:
        Sequence[tf.Tensor]: A tuple of tensors.


def compute_output(self, o, output_shape=None):

    if self.combine_dims:
      o = mtf.transpose(o, o.shape - self.o_dims + self.o_dims)
      o = mtf.replace_dimensions(o, self.o_dims, self.wo.shape.dims[0])
      reduced_dims = [self.wo.shape.dims[0]]
    else:
      reduced_dims = self.o_dims
    return mtf.einsum(
        [o, self.wo], output_shape=output_shape, reduced_dims=reduced_dims)

Compute output of multihead attention.

Args:
        o: a Tensor with dimensions
        query_heads_dims + {value_dim} + other_dims
        output_shape: an optional Shape

Returns:
        a Tensor with shape:
        {output_dim} + other_dims


def _batch_transpose(mat):

  n = distribution_util.prefer_static_rank(mat)
  perm = tf.range(n)
  perm = tf.concat([perm[:-2], [perm[-1], perm[-2]]], axis=0)
  return tf.transpose(a=mat, perm=perm)

Transpose a possibly batched matrix.

Args:
        mat: A `tf.Tensor` of shape `[..., n, m]`.

Returns:
        A tensor of shape `[..., m, n]` with matching batch dimensions.


def parse_display_name(chrom, pos, ref, alt, variant_type):

    return '_'.join([chrom, pos, ref, alt, variant_type])

Parse the variant id for a variant

    This is used to display the variant in scout.

Args:
        chrom(str)
        pos(str)
        ref(str)
        alt(str)
        variant_type(str): 'clinical' or 'research'

Returns:
        variant_id(str): The variant id in human readable format


def update_by_id(self, data, table, id_value):

        key_map = {}
        if len(data) == 0:
            print('请确保data被正确传入了')
            return -1
        datas = {}
        updates = ''
        for k, v in data.items():
            # 防止sql注入
            datas.update({k: pymysql.escape_string(str(v))})
        for d in datas:
            updates += "{}='{}',".format(str(d), str(datas[d]))
        if len(updates) <= 0:
            return -1
        # 生成sql语句
        sql = "update {} set {} where id = '{}'".format(
            table, updates[:-1], str(id_value))
        res = self.query(sql)
        return 1 if res != -1 else res

通过id更新记录

Args:
        table: 表名字 str
        data:  记录 dict
        id_value: id值

Returns:
        成功： １
        失败： -1 并打印返回报错信息
    每条记录都以一个字典的形式传进来


def shared_s3_app_bucket(self, include_region=False):

        if include_region:
            shared_s3_app_bucket = self.format['shared_s3_app_region_bucket'].format(**self.data)
        else:
            shared_s3_app_bucket = self.format['shared_s3_app_bucket'].format(**self.data)
        return shared_s3_app_bucket

Generate shared s3 application bucket name.

Args:
        include_region (bool): Include region in the name generation.


def is_user_enrolled(cls, user, course_id, course_mode):

        enrollment_client = EnrollmentApiClient()
        try:
            enrollments = enrollment_client.get_course_enrollment(user.username, course_id)
            if enrollments and course_mode == enrollments.get('mode'):
                return True
        except HttpClientError as exc:
            logging.error(
                'Error while checking enrollment status of user %(user)s: %(message)s',
                dict(user=user.username, message=str(exc))
            )
        except KeyError as exc:
            logging.warning(
                'Error while parsing enrollment data of user %(user)s: %(message)s',
                dict(user=user.username, message=str(exc))
            )
        return False

Query the enrollment API and determine if a learner is enrolled in a given course run track.

Args:
        user: The user whose enrollment needs to be checked
        course_mode: The mode with which the enrollment should be checked
        course_id: course id of the course where enrollment should be checked.

Returns:
        Boolean: Whether or not enrollment exists


def process_links(include_match, block_map, link_stack, source_path):

    leading_whitespace = include_match.group(1)
    include_path = include_match.group(2)

    # Optional block name. If match is None, block name was ommitted (default to 'all').
    block_name = include_match.group(3)
    if block_name is not None:
        block_name = block_name.lstrip(':')
    else:
        block_name = ALL_BLOCK_NAME

    return retrieve_block_from_map(
            source_path,
            include_path.strip(),
            block_name.strip(),
            leading_whitespace,
            block_map,
            link_stack)

Process a string of content for include tags.

    This function assumes there are no blocks in the content. The content is split into segments,
    with include tags being replaced by Block objects.

    PARAMETERS:
    content     -- str; content to be converted into a Block.
    block_map   -- BlockMap
    link_stack  -- LinkStack
    source_path -- str; the filepath of the file from which this content came.

Returns:
    list of str; segments that the comprise the content.


def _update_step(self, sequence):

    observ, action, old_policy_params, reward, advantage = sequence['sequence']
    length = sequence['length']
    old_policy = self._policy_type(**old_policy_params)
    value_loss, value_summary = self._value_loss(observ, reward, length)
    network = self._network(observ, length)
    policy_loss, policy_summary = self._policy_loss(
        old_policy, network.policy, action, advantage, length)
    network_loss = network.get('loss', 0.0)
    loss = policy_loss + value_loss + tf.reduce_mean(network_loss)
    gradients, variables = (
        zip(*self._optimizer.compute_gradients(loss)))
    optimize = self._optimizer.apply_gradients(
        zip(gradients, variables))
    summary = tf.summary.merge([
        value_summary, policy_summary,
        tf.summary.histogram('network_loss', network_loss),
        tf.summary.scalar('avg_network_loss', tf.reduce_mean(network_loss)),
        tf.summary.scalar('gradient_norm', tf.global_norm(gradients)),
        utility.gradient_summaries(zip(gradients, variables))])
    with tf.control_dependencies([optimize]):
      return [tf.identity(x) for x in (value_loss, policy_loss, summary)]

Compute the current combined loss and perform a gradient update step.

    The sequences must be a dict containing the keys `length` and `sequence`,
    where the latter is a tuple containing observations, actions, parameters of
    the behavioral policy, rewards, and advantages.

Args:
        sequence: Sequences of episodes or chunks of episodes.

Returns:
        Tuple of value loss, policy loss, and summary tensor.


def _get_music_services_data_xml(soco=None):

        device = soco or discovery.any_soco()
        log.debug("Fetching music services data from %s", device)
        available_services = device.musicServices.ListAvailableServices()
        descriptor_list_xml = available_services[
            'AvailableServiceDescriptorList']
        log.debug("Services descriptor list: %s", descriptor_list_xml)
        return descriptor_list_xml

Fetch the music services data xml from a Sonos device.

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

Returns:
        str: a string containing the music services data xml


def prepare_minibatch(self, audio_paths, texts, overwrite=False,
                          is_bi_graphemes=False, seq_length=-1, save_feature_as_csvfile=False):

        assert len(audio_paths) == len(texts),\
            "Inputs and outputs to the network must be of the same number"
        # Features is a list of (timesteps, feature_dim) arrays
        # Calculate the features for each audio clip, as the log of the
        # Fourier Transform of the audio
        features = [self.featurize(a, overwrite=overwrite, save_feature_as_csvfile=save_feature_as_csvfile) for a in audio_paths]
        input_lengths = [f.shape[0] for f in features]
        feature_dim = features[0].shape[1]
        mb_size = len(features)
        # Pad all the inputs so that they are all the same length
        if seq_length == -1:
            x = np.zeros((mb_size, self.max_seq_length, feature_dim))
        else:
            x = np.zeros((mb_size, seq_length, feature_dim))
        y = np.zeros((mb_size, self.max_label_length))
        labelUtil = LabelUtil.getInstance()
        label_lengths = []
        for i in range(mb_size):
            feat = features[i]
            feat = self.normalize(feat)  # Center using means and std
            x[i, :feat.shape[0], :] = feat
            if is_bi_graphemes:
                label = generate_bi_graphemes_label(texts[i])
                label = labelUtil.convert_bi_graphemes_to_num(label)
                y[i, :len(label)] = label
            else:
                label = labelUtil.convert_word_to_num(texts[i])
                y[i, :len(texts[i])] = label
            label_lengths.append(len(label))
        return {
            'x': x,  # (0-padded features of shape(mb_size,timesteps,feat_dim)
            'y': y,  # list(int) Flattened labels (integer sequences)
            'texts': texts,  # list(str) Original texts
            'input_lengths': input_lengths,  # list(int) Length of each input
            'label_lengths': label_lengths,  # list(int) Length of each label
        }

Featurize a minibatch of audio, zero pad them and return a dictionary
    Params:
        audio_paths (list(str)): List of paths to audio files
        texts (list(str)): List of texts corresponding to the audio files

Returns:
        dict: See below for contents


def _check_root_tag(self, root):

        supported = self.supported_tags()
        if root.tag in supported:
            return

        error = "Document root element ({0}) not one of ({1})"
        raise UnsupportedRootElementError(
            message=error.format(root.tag, supported),
            expected=supported,
            found=root.tag,
        )

Check that the XML element tree has a supported root element.

Args:
        root (etree.Element)

Raises:
        UnsupportedRootElementError


def _render_fluent_timestep(self,
            fluent_type: str,
            fluents: Sequence[Tuple[str, np.array]],
            fluent_variables: Sequence[Tuple[str, List[str]]]) -> None:

        for fluent_pair, variable_list in zip(fluents, fluent_variables):
            name, fluent = fluent_pair
            _, variables = variable_list
            print(name)
            fluent = fluent.flatten()
            for variable, value in zip(variables, fluent):
                print('- {}: {} = {}'.format(fluent_type, variable, value))
        print()

Prints `fluents` of given `fluent_type` as list of instantiated variables
    with corresponding values.

Args:
        fluent_type (str): Fluent type.
        fluents (Sequence[Tuple[str, np.array]]): List of pairs (fluent_name, fluent_values).
        fluent_variables (Sequence[Tuple[str, List[str]]]): List of pairs (fluent_name, args).


def list2str(self, l: List, joiner: str) -> str:

        result = str()
        for item in l:
            if isinstance(item, list):
                result = result + self.list2str(item, joiner) + joiner
            elif isinstance(item, dict):
                result = result + self.dict2str(item, joiner) + joiner
            elif item:
                result = result + str(item) + joiner
        return result

Convert list to str as input for tokenizer

Args:
        l (list): list for converting
        joiner (str): join the elements using this string to separate them.

    Returns: the value of the list as a string


def _setup_index(index):

    index = int(index)
    if index > 0:
        index -= 1
    elif index == 0:
        # Zero indicies should not be allowed by default.
        raise ValueError
    return index

Shifts indicies as needed to account for one based indexing

    Positive indicies need to be reduced by one to match with zero based
    indexing.

    Zero is not a valid input, and as such will throw a value error.

Args:
        index -     index to shift


def __setstate__(self, state):

    self._api = state['api']
    self._path = state['path']
    self.name = api_utils._unquote_filename(self._path)
    self._buffer_size = state['buffer_size']
    self._max_request_size = state['request_size']
    self._etag = state['etag']
    self._file_size = state['size']
    self._offset = state['offset']
    self._buffer = _Buffer()
    self.closed = state['closed']
    self._buffer_future = None
    if self._remaining() and not self.closed:
      self._request_next_buffer()

Restore state as part of deserialization/unpickling.

Args:
        state: the dictionary from a __getstate__ call

    Along with restoring the state, pre-fetch the next read buffer.


def feed(self, data_len, feed_time=None):

        self._bytes_transferred += data_len
        self._collected_bytes_transferred += data_len

        time_now = feed_time or time.time()
        time_diff = time_now - self._last_feed_time

        if time_diff < self._sample_min_time:
            return

        self._last_feed_time = time.time()

        if data_len == 0 and time_diff >= self._stall_time:
            self._stalled = True
            return

        self._samples.append((time_diff, self._collected_bytes_transferred))
        self._collected_bytes_transferred = 0

Update the bandwidth meter.

Args:
        data_len (int): The number of bytes transfered since the last
            call to :func:`feed`.
        feed_time (float): Current time.


def read_probes(self, key):

        assert key in list(self._PROBES.keys())

        if key == 'output':
            value = self._output

        return value

requestes value from the instrument and returns it

Args:
        key: name of requested value

    Returns: reads values from instrument


def transform_to_mods_multimono(marc_xml, uuid, url):

    marc_xml = _read_content_or_path(marc_xml)

    transformed = xslt_transformation(
        marc_xml,
        _absolute_template_path("MARC21toMultiMonographTitle.xsl")
    )

    return _apply_postprocessing(
        marc_xml=marc_xml,
        xml=transformed,
        func=mods_postprocessor.postprocess_multi_mono,
        uuid=uuid,
        url=url,
    )

Convert `marc_xml` to multimonograph MODS data format.

Args:
        marc_xml (str): Filename or XML string. Don't use ``\\n`` in case of
                        filename.
        uuid (str): UUID string giving the package ID.
        url (str): URL of the publication (public or not).

Returns:
        list: Collection of transformed xml strings.


def _AddExtractionProcessStatusTableRow(self, process_status, table_view):

    used_memory = self._FormatSizeInUnitsOf1024(process_status.used_memory)

    sources = ''
    if (process_status.number_of_produced_sources is not None and
        process_status.number_of_produced_sources_delta is not None):
      sources = '{0:d} ({1:d})'.format(
          process_status.number_of_produced_sources,
          process_status.number_of_produced_sources_delta)

    events = ''
    if (process_status.number_of_produced_events is not None and
        process_status.number_of_produced_events_delta is not None):
      events = '{0:d} ({1:d})'.format(
          process_status.number_of_produced_events,
          process_status.number_of_produced_events_delta)

    # TODO: shorten display name to fit in 80 chars and show the filename.

    table_view.AddRow([
        process_status.identifier, process_status.pid, process_status.status,
        used_memory, sources, events, process_status.display_name])

Adds an extraction process status table row.

Args:
        process_status (ProcessStatus): processing status.
        table_view (CLITabularTableView): table view.


def choose(self, locator=None, allow_label_click=None, **kwargs):

        self._check_with_label(
            "radio_button", True, locator=locator, allow_label_click=allow_label_click, **kwargs)

Find a radio button and mark it as checked. The radio button can be found via name, id, or
    label text. ::

        page.choose("Male")

Args:
        locator (str, optional): Which radio button to choose.
        allow_label_click (bool, optional): Attempt to click the label to toggle state if
            element is non-visible. Defaults to :data:`capybara.automatic_label_click`.
        **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.


def update_variant_rank(self, case_obj, variant_type='clinical', category='snv'):

        # Get all variants sorted by rank score
        variants = self.variant_collection.find({
            'case_id': case_obj['_id'],
            'category': category,
            'variant_type': variant_type,
        }).sort('rank_score', pymongo.DESCENDING)

        LOG.info("Updating variant_rank for all variants")

        requests = []

        for index, var_obj in enumerate(variants):
            if len(requests) > 5000:
                try:
                    self.variant_collection.bulk_write(requests, ordered=False)
                    requests = []
                except BulkWriteError as err:
                    LOG.warning("Updating variant rank failed")
                    raise err

            operation = pymongo.UpdateOne(
                {'_id': var_obj['_id']},
                {
                    '$set': {
                        'variant_rank': index + 1,
                    }
                })
            requests.append(operation)

        #Update the final bulk
        try:
            self.variant_collection.bulk_write(requests, ordered=False)
        except BulkWriteError as err:
            LOG.warning("Updating variant rank failed")
            raise err

        LOG.info("Updating variant_rank done")

Updates the manual rank for all variants in a case

    Add a variant rank based on the rank score
    Whenever variants are added or removed from a case we need to update the variant rank

Args:
        case_obj(Case)
        variant_type(str)


def task_done(self, message):

        topic_partition = (message.topic, message.partition)
        if topic_partition not in self._topics:
            logger.warning('Unrecognized topic/partition in task_done message: '
                           '{0}:{1}'.format(*topic_partition))
            return False

        offset = message.offset

        # Warn on non-contiguous offsets
        prev_done = self._offsets.task_done[topic_partition]
        if prev_done is not None and offset != (prev_done + 1):
            logger.warning('Marking task_done on a non-continuous offset: %d != %d + 1',
                           offset, prev_done)

        # Warn on smaller offsets than previous commit
        # "commit" offsets are actually the offset of the next message to fetch.
        prev_commit = self._offsets.commit[topic_partition]
        if prev_commit is not None and ((offset + 1) <= prev_commit):
            logger.warning('Marking task_done on a previously committed offset?: %d (+1) <= %d',
                           offset, prev_commit)

        self._offsets.task_done[topic_partition] = offset

        # Check for auto-commit
        if self._does_auto_commit_messages():
            self._incr_auto_commit_message_count()

        if self._should_auto_commit():
            self.commit()

        return True

Mark a fetched message as consumed.

    Offsets for messages marked as "task_done" will be stored back
    to the kafka cluster for this consumer group on commit()

Args:
        message (KafkaMessage): the message to mark as complete

Returns:
        True, unless the topic-partition for this message has not
        been configured for the consumer. In normal operation, this
        should not happen. But see github issue 364.


def get_keys(self, alias_name, key_format):

        uri = self.URI + "/keys/" + alias_name + "?format=" + key_format
        return self._client.get(uri)

Retrieves the contents of PKCS12 file in the format specified.
    This PKCS12 formatted file contains both the certificate as well as the key file data.
    Valid key formats are Base64 and PKCS12.

Args:
        alias_name: Key pair associated with the RabbitMQ
        key_format: Valid key formats are Base64 and PKCS12.

Returns:
        dict: RabbitMQ certificate


def _tzinfome(tzinfo):

  if not isinstance(tzinfo, datetime.tzinfo):
    try:
      tzinfo = pytz.timezone(tzinfo)
      assert tzinfo.zone in pytz.all_timezones
    except AttributeError:
      raise pytz.UnknownTimeZoneError("Unknown timezone! %s" % tzinfo)
  return tzinfo

Gets a tzinfo object from a string.

Args:
        tzinfo: A string (or string like) object, or a datetime.tzinfo object.

Returns:
        An datetime.tzinfo object.

Raises:
        UnknownTimeZoneError: If the timezone given can't be decoded.


def append(self, header, f, _left=False):

        self.items_length += len(header)
        if _left:
            self.deque.appendleft((header, f))
        else:
            self.deque.append((header, f))

Add a column to the table.

Args:
        header (str):
            Column header

        f (function(datum)->str):
            Makes the row string from the datum. Str returned by f should
            have the same width as header.


def color_palette_dict(self, alpha=0.35):

        color_dict = {}
        for hkl in self.all_slab_entries.keys():
            rgb_indices = [0, 1, 2]
            color = [0, 0, 0, 1]
            random.shuffle(rgb_indices)
            for i, ind in enumerate(rgb_indices):
                if i == 2:
                    break
                color[ind] = np.random.uniform(0, 1)

            # Get the clean (solid) colors first
            clean_list = np.linspace(0, 1, len(self.all_slab_entries[hkl]))
            for i, clean in enumerate(self.all_slab_entries[hkl].keys()):
                c = copy.copy(color)
                c[rgb_indices[2]] = clean_list[i]
                color_dict[clean] = c

                # Now get the adsorbed (transparent) colors
                for ads_entry in self.all_slab_entries[hkl][clean]:
                    c_ads = copy.copy(c)
                    c_ads[3] = alpha
                    color_dict[ads_entry] = c_ads

        return color_dict

Helper function to assign each facet a unique color using a dictionary.

Args:
        alpha (float): Degree of transparency

    return (dict): Dictionary of colors (r,g,b,a) when plotting surface
        energy stability. The keys are individual surface entries where
        clean surfaces have a solid color while the corresponding adsorbed
        surface will be transparent.


def __str__(self, talker='GP'):

        if not len(talker) == 2:
            raise ValueError('Talker ID must be two characters %r' % talker)
        data = ['%sGLL' % talker]
        data.extend(nmea_latitude(self.latitude))
        data.extend(nmea_longitude(self.longitude))
        data.append('%s.%02i' % (self.time.strftime('%H%M%S'),
                                 self.time.microsecond / 1000000))
        data.append('A' if self.status else 'V')
        if self.mode:
            data.append(self.mode)
        data = ','.join(data)
        return '$%s*%02X\r' % (data, calc_checksum(data))

Pretty printed position string.

Args:
        talker (str): Talker ID

Returns:
        str: Human readable string representation of ``Position`` object


def equal(x, y):

    if PY_3:
        return test_case().assertEqual(x, y) or True

    assert x == y

Shortcut function for ``unittest.TestCase.assertEqual()``.

Args:
        x (mixed)
        y (mixed)

Raises:
        AssertionError: in case of assertion error.

Returns:
        bool


def random( self ):

        j = np.searchsorted( self.cumulative_probabilities(), random.random() )
        return self.jumps[ j ]

Select a jump at random with appropriate relative probabilities.

Args:
        None

Returns:
        (Jump): The randomly selected Jump.


def __init__(self, submission_id, submissions, storage_bucket):

    self.submission_id = submission_id
    self.storage_bucket = storage_bucket
    self.type = None
    self.submission = None
    if submission_id in submissions.attacks:
      self.type = TYPE_NONTARGETED
      self.submission = submissions.attacks[submission_id]
    elif submission_id in submissions.targeted_attacks:
      self.type = TYPE_TARGETED
      self.submission = submissions.targeted_attacks[submission_id]
    elif submission_id in submissions.defenses:
      self.type = TYPE_DEFENSE
      self.submission = submissions.defenses[submission_id]
    else:
      raise WorkerError(
          'Submission with ID "{0}" not found'.format(submission_id))
    self.submission_dir = None
    self.extracted_submission_dir = None

Initializes ExecutableSubmission.

Args:
        submission_id: ID of the submissions
        submissions: instance of CompetitionSubmissions with all submissions
        storage_bucket: storage bucket where all submissions are stored

Raises:
        WorkerError: if submission was not found


def generate_nodes(tpm, cm, network_state, indices, node_labels=None):

    if node_labels is None:
        node_labels = NodeLabels(None, indices)

    node_state = utils.state_of(indices, network_state)

    return tuple(Node(tpm, cm, index, state, node_labels)
                 for index, state in zip(indices, node_state))

Generate |Node| objects for a subsystem.

Args:
        tpm (np.ndarray): The system's TPM
        cm (np.ndarray): The corresponding CM.
        network_state (tuple): The state of the network.
        indices (tuple[int]): Indices to generate nodes for.

    Keyword Args:
        node_labels (|NodeLabels|): Textual labels for each node.

Returns:
        tuple[Node]: The nodes of the system.


def save(self, fname, mode=None, validate=True, encoding='utf-8',
             wd=False, inline=False, relative=False, pack=False):

        self._closed()

        if mode is None:
            mode = 'abs'
            if pack:
                mode = 'pack'
            elif wd:
                mode = 'wd'
            elif relative:
                mode = 'rel'

            msg = 'Using deprecated save method. Please save the workflow ' \
                  'with: wf.save(\'{}\', mode=\'{}\'). Redirecting to new ' \
                  'save method.'.format(fname, mode)
            warnings.warn(msg, DeprecationWarning)

        modes = ('rel', 'abs', 'wd', 'inline', 'pack')
        if mode not in modes:
            msg = 'Illegal mode "{}". Choose one of ({}).'\
                  .format(mode, ','.join(modes))
            raise ValueError(msg)

        if validate:
            self.validate()

        dirname = os.path.dirname(os.path.abspath(fname))
        if not os.path.exists(dirname):
            os.makedirs(dirname)

        if mode == 'inline':
            msg = ('Inline saving is deprecated. Please save the workflow '
                   'using mode=\'pack\'. Setting mode to pack.')
            warnings.warn(msg, DeprecationWarning)
            mode = 'pack'

        if mode == 'rel':
            relpath = dirname
            save_yaml(fname=fname, wf=self, pack=False, relpath=relpath,
                      wd=False)

        if mode == 'abs':
            save_yaml(fname=fname, wf=self, pack=False, relpath=None,
                      wd=False)

        if mode == 'pack':
            self._pack(fname, encoding)

        if mode == 'wd':
            if self.get_working_dir() is None:
                raise ValueError('Working directory not set.')
            else:
                # save in working_dir
                bn = os.path.basename(fname)
                wd_file = os.path.join(self.working_dir, bn)
                save_yaml(fname=wd_file, wf=self, pack=False, relpath=None,
                          wd=True)
                # and copy workflow file to other location (as though all steps
                # are in the same directory as the workflow)
                try:
                    shutil.copy2(wd_file, fname)
                except shutil.Error:
                    pass

Save the workflow to file.

    Save the workflow to a CWL file that can be run with a CWL runner.

Args:
        fname (str): file to save the workflow to.
        mode (str): one of  (rel, abs, wd, inline, pack)
        encoding (str): file encoding to use (default: ``utf-8``).


def find(self, soup):

        for tag in soup.recursiveChildGenerator():
            if self.match_criterion(tag):
                yield tag

Yield tags matching the tag criterion from a soup.

    There is no need to override this if you are satisfied with finding
    tags that match match_criterion.

Args:
        soup: A BeautifulSoup to search through.

Yields:
        BeautifulSoup Tags that match the criterion.


def indicator(self, data):

        # handle hashes in form md5 : sha1 : sha256
        data = self.get_first_hash(data)
        super(File, self).indicator(data)

Update the request URI to include the Indicator for specific indicator retrieval.

Args:
        data (string): The indicator value


def flatten(schedule: ScheduleComponent, name: str = None) -> Schedule:

    if name is None:
        name = schedule.name

    return Schedule(*schedule.instructions, name=name)

Create a flattened schedule.

Args:
        schedule: Schedules to flatten
        name: Name of the new schedule. Defaults to first element of `schedules`


def has_arg(fn, arg_name):

    if sys.version_info < (3,):
        if isinstance(fn, types.FunctionType) or isinstance(fn, types.MethodType):
            arg_spec = inspect.getargspec(fn)
        else:
            try:
                arg_spec = inspect.getargspec(fn.__call__)
            except AttributeError:
                return False
        return (arg_name in arg_spec.args)
    elif sys.version_info < (3, 6):
        arg_spec = inspect.getfullargspec(fn)
        return (arg_name in arg_spec.args or
                arg_name in arg_spec.kwonlyargs)
    else:
        try:
            signature = inspect.signature(fn)
        except ValueError:
            # handling Cython
            signature = inspect.signature(fn.__call__)
        parameter = signature.parameters.get(arg_name)
        if parameter is None:
            return False
        return (parameter.kind in (inspect.Parameter.POSITIONAL_OR_KEYWORD,
                                   inspect.Parameter.KEYWORD_ONLY))

Checks if a callable accepts a given keyword argument.

Args:
        fn: callable to inspect
        arg_name: string, keyword argument name to check

Returns:
        bool, whether `fn` accepts a `arg_name` keyword argument.


def save_images(images, filenames, output_dir):

  for i, filename in enumerate(filenames):
    # Images for inception classifier are normalized to be in [-1, 1] interval,
    # so rescale them back to [0, 1].
    with tf.gfile.Open(os.path.join(output_dir, filename), 'w') as f:
      img = (((images[i, :, :, :] + 1.0) * 0.5) * 255.0).astype(np.uint8)
      Image.fromarray(img).save(f, format='PNG')

Saves images to the output directory.

Args:
        images: array with minibatch of images
        filenames: list of filenames without path
        If number of file names in this list less than number of images in
        the minibatch then only first len(filenames) images will be saved.
        output_dir: directory where to save images