code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def __add_kickoff_task(cls, job_config, mapreduce_spec): params = {"mapreduce_id": job_config.job_id} kickoff_task = taskqueue.Task( url=job_config._base_path + "/kickoffjob_callback/" + job_config.job_id, headers=util._get_task_headers(job_config.job_id), params=param...
Add kickoff task to taskqueue. Args: job_config: map_job.JobConfig. mapreduce_spec: model.MapreduceSpec,
juraj-google-style
def update(self, data): for key, value in data.items(): setattr(self, key, value)
Update the current memory record with the given data dict. Args: data (dict): Data dictionary to update the record attributes with.
juraj-google-style
def InternalSendApdu(self, apdu_to_send): response = None if not self.use_legacy_format: response = apdu.ResponseApdu(self.transport.SendMsgBytes( apdu_to_send.ToByteArray())) if response.sw1 == 0x67 and response.sw2 == 0x00: self.use_legacy_format = True ...
Send an APDU to the device. Sends an APDU to the device, possibly falling back to the legacy encoding format that is not ISO7816-4 compatible. Args: apdu_to_send: The CommandApdu object to send Returns: The ResponseApdu object constructed out of the devices reply.
juraj-google-style
def from_string(rxn_string): rct_str, prod_str = rxn_string.split("->") def get_comp_amt(comp_str): return {Composition(m.group(2)): float(m.group(1) or 1) for m in re.finditer(r"([\d\.]*(?:[eE]-?[\d\.]+)?)\s*([A-Z][\w\.\(\)]*)", ...
Generates a balanced reaction from a string. The reaction must already be balanced. Args: rxn_string: The reaction string. For example, "4 Li + O2-> 2Li2O" Returns: BalancedReaction
juraj-google-style
def assert_not_present(self, selector, testid=None, **kwargs): self.info_log(('Assert not present selector(%s) testid(%s)' % (selector, testid))) wait_until_not_present = kwargs.get('wait_until_not_present', BROME_CONFIG['proxy_driver']['wait_until_not_present_before_assert_not_present']) self.debug_log(('e...
Assert that the element is not present in the dom Args: selector (str): the selector used to find the element test_id (str): the test_id or a str Kwargs: wait_until_not_present (bool) Returns: bool: True is the assertion succeed; False otherwise.
codesearchnet
def get_maybe_abstract_instance(self, data): if data.is_concrete: data_type = type(data.pyval) if data_type in self.primitive_instances: return self.primitive_instances[data_type] return data
Get an instance of the same type as the given data, abstract if possible. Get an abstract instance of primitive data stored as a ConcreteValue. Return any other data as-is. This is used by constant_to_var to discard concrete values that have been kept around for InterpreterFunction. This method intentionally does not...
github-repos
def _get_api_version(self): url = '{base_url}/api/server_info'.format(base_url=self._base_url()) server_info = self._make_request(url=url, method='get') return server_info['latest_api_version']
Fetches the most recent API version Returns: str
codesearchnet
def _ConvertValueBinaryDataToUBInt64(self, value): if not value: return None integer_map = self._GetDataTypeMap('uint64be') try: return self._ReadStructureFromByteStream(value, 0, integer_map) except (ValueError, errors.ParseError) as exception: raise errors.ParseError( ...
Converts a binary data value into an integer. Args: value (bytes): binary data value containing an unsigned 64-bit big-endian integer. Returns: int: integer representation of binary data value or None if value is not set. Raises: ParseError: if the integer value cannot be parsed.
juraj-google-style
def get_opt_val(obj_pyxb, attr_str, default_val=None): try: return get_req_val(getattr(obj_pyxb, attr_str)) except (ValueError, AttributeError): return default_val
Get an optional Simple Content value from a PyXB element. The attributes for elements that are optional according to the schema and not set in the PyXB object are present and set to None. PyXB validation will fail if required elements are missing. Args: obj_pyxb: PyXB object attr_str: str Name of an attribute that ...
codesearchnet
def output(self, _filename): txt = "" for contract in self.contracts: print('Contract {}'.format(contract.name)) for function in contract.functions: if function.contract == contract: print('\tFunction {}'.format(function.full_name)) ...
_filename is not used Args: _filename(string)
juraj-google-style
def write_to_file(path, contents, file_type='text'): FILE_TYPES = ('json', 'text', 'binary') if (file_type not in FILE_TYPES): raise ScriptWorkerException('Unknown file_type {} not in {}!'.format(file_type, FILE_TYPES)) if (file_type == 'json'): contents = format_json(contents) if (file_...
Write ``contents`` to ``path`` with optional formatting. Small helper function to write ``contents`` to ``file`` with optional formatting. Args: path (str): the path to write to contents (str, object, or bytes): the contents to write to the file file_type (str, optional): the type of file. Currently accepts ``text`` ...
codesearchnet
def get_fleet(self, airline_key): url = AIRLINE_FLEET_BASE.format(airline_key) return self._fr24.get_airline_fleet_data(url, (self.AUTH_TOKEN != ''))
Get the fleet for a particular airline. Given a airline code form the get_airlines() method output, this method returns the fleet for the airline. Args: airline_key (str): The code for the airline on flightradar24 Returns: A list of dicts, one for each aircraft in the airlines fleet Example:: from pyflightdata impo...
codesearchnet
def HasExactlyCalls(self, *calls): if len(calls) == 1 and _IsIterable(calls[0]) and (not isinstance(calls[0], mock._Call)): calls = calls[0] return AssertThat(self._actual.mock_calls).ContainsExactlyElementsIn(calls)
Assert that the mocked function was called with exactly the given calls. Args: *calls: iterable of mock.call objects. Developers may also pass a single iterable of mock.call objects, for compatibility with mock's assert_has_calls() method, although this form is not preferred. Returns: If the mocked function was calle...
github-repos
def main(argv=None): args = None cmd = None try: args = parse_args(argv) if args.quiet: logger.setLevel(logging.CRITICAL) elif args.verbose: logger.setLevel(logging.DEBUG) cmd = args.func(args) ret = cmd.run_cmd() except KeyboardIn...
Run dvc CLI command. Args: argv: optional list of arguments to parse. sys.argv is used by default. Returns: int: command's return code.
juraj-google-style
def generate_sb(date: datetime.datetime, project: str, programme_block: str) -> dict: date = date.strftime('%Y%m%d') instance_id = randint(0, 9999) sb_id = 'SB-{}-{}-{:04d}'.format(date, project, instance_id) return dict(id=sb_id, project=project, programme_block=programme_block)
Generate a Scheduling Block data object. Args: date (datetime.datetime): UTC date of the SBI project (str): Project Name programme_block (str): Programme Returns: str, Scheduling Block Instance (SBI) ID.
juraj-google-style
def get_releasenotes(repo_path, from_commit=None, bugtracker_url=''): repo = dulwich.repo.Repo(repo_path) tags = get_tags(repo) refs = get_refs(repo) maj_version = 0 feat_version = 0 fix_version = 0 start_including = False release_notes_per_major = OrderedDict() cur_line = '' if ...
Given a repo and optionally a base revision to start from, will return a text suitable for the relase notes announcement, grouping the bugs, the features and the api-breaking changes. Args: repo_path(str): Path to the code git repository. from_commit(str): Refspec of the commit to start aggregating the authors from. b...
codesearchnet
def set_custom_getter_compose(custom_getter): tf.get_variable_scope().set_custom_getter( _compose_custom_getters(tf.get_variable_scope().custom_getter, custom_getter))
Set a custom getter in the current variable scope. Do not overwrite the existing custom getter - rather compose with it. Args: custom_getter: a custom getter.
juraj-google-style
def swap(self, left, right): if type(left) is not type(right): raise LayoutError('The method swap only works with elements of the same type.') temp = self[left] self[left] = self[right] self[right] = temp
Swaps the map between left and right. Args: left (tuple or int): Item to swap with right. right (tuple or int): Item to swap with left. Raises: LayoutError: If left and right have not the same type.
juraj-google-style
def get_mask(self, layers=None, output='vector', in_global_mask=True): if in_global_mask: output = 'vector' if layers is None: layers = self.layers.keys() elif not isinstance(layers, list): layers = [layers] layers = map(lambda x: x if isins...
Set the current mask by taking the conjunction of all specified layers. Args: layers: Which layers to include. See documentation for add() for format. include_global_mask: Whether or not to automatically include the global mask (i.e., self.volume) in the conjunction.
juraj-google-style
def CreateTaskCompletion(self): self.completion_time = int((time.time() * definitions.MICROSECONDS_PER_SECOND)) task_completion = TaskCompletion() task_completion.aborted = self.aborted task_completion.identifier = self.identifier task_completion.session_identifier = self.session_identifier task...
Creates a task completion. Returns: TaskCompletion: task completion attribute container.
codesearchnet
def fetch_url(self, url): url_path = urlparse.urlsplit(url).path dst_path = os.path.basename(url_path) dst_path = self.paths.prefixed(dst_path) with LogTask('Downloading %s' % url): urllib.urlretrieve(url=os.path.expandvars(url), filename=dst_path) return ds...
Retrieves the given url to the prefix Args: url(str): Url to retrieve Returns: str: path to the downloaded file
juraj-google-style
def override_from_dict(self, values_dict): for (name, value) in values_dict.items(): self.set_hparam(name, value) return self
Override existing hyperparameter values, parsing new values from a dictionary. Args: values_dict: Dictionary of name:value pairs. Returns: The `HParams` instance. Raises: KeyError: If a hyperparameter in `values_dict` doesn't exist. ValueError: If `values_dict` cannot be parsed.
codesearchnet
def score_and_learn(self, data): assert self._underlying if self._underlying._features is not None: x = beam.Row(**{f: getattr(data, f) for f in self._underlying._features}) else: x = beam.Row(**data._asdict()) y_pred = self._underlying.score_one(x) self._underlying.learn_one(x) ...
Scores and learns from a single data point. Args: data: A `beam.Row` representing the input data point. Returns: float: The anomaly score predicted by the model.
github-repos
def _rapply(input_layer, operation, *op_args, **op_kwargs): op_args = list(op_args) op_args.append(input_layer.tensor) return input_layer.with_tensor(operation(*op_args, **op_kwargs))
Applies the given operation to this after expanding op_args. Args: input_layer: The input layer for this op. operation: An operation that takes a tensor and the supplied args. *op_args: Extra arguments for operation. **op_kwargs: Keyword arguments for the operation. Returns: A new layer with operation applied.
juraj-google-style
def process_rule(edges: Edges, ast: Function, rule: Mapping[str, Any], spec: BELSpec): ast_type = ast.__class__.__name__ trigger_functions = rule.get("trigger_function", []) trigger_types = rule.get("trigger_type", []) rule_subject = rule.get("subject") rule_relation = rule.get("relation") ...
Process computed edge rule Recursively processes BELAst versus a single computed edge rule Args: edges (List[Tuple[Union[Function, str], str, Function]]): BEL Edge ASTs ast (Function): BEL Function AST rule (Mapping[str, Any]: computed edge rule
juraj-google-style
def _update_services_target_state(sdp_target_state: str): service_states = get_service_state_list() for service in service_states: if (service.current_state != sdp_target_state): LOG.debug('Setting the target state of %s to be %s', service.id, sdp_target_state) service.update_tar...
Update the target states of services based on SDP target state. When we get a new target state this function is called to ensure components receive the target state(s) and/or act on them. Args: sdp_target_state (str): Target state of SDP
codesearchnet
def save(self, response_choice=None, async=False, callback=None): return self._manage_child_object(nurest_object=self, method=HTTP_METHOD_PUT, async=async, callback=callback, response_choice=response_choice)
Update object and call given callback in case of async call Args: async (bool): Boolean to make an asynchronous call. Default is False callback (function): Callback method that will be triggered in case of asynchronous call Example: >>> entity.name = "My Super Object" >>> entity.save() # will save the new name in the...
juraj-google-style
def split_window(self, fpath, vertical=False, size=None, bufopts=None): command = 'split {}'.format(fpath) if fpath else 'new' if vertical: command = 'v' + command if size: command = str(size) + command self._vim.command(command) if bufopts: ...
Open file in a new split window. Args: fpath (str): Path of the file to open. If ``None``, a new empty split is created. vertical (bool): Whether to open a vertical split. size (Optional[int]): The height (or width) to set for the new window. bufopts (Optional[dict]): Buffer-local options to set in the split window. S...
juraj-google-style
def load_parameters(path, proto=None, needs_proto=False): _, ext = os.path.splitext(path) if ext == '.h5': import warnings warnings.simplefilter('ignore', category=FutureWarning) import h5py with h5py.File(path, 'r') as hd: keys = [] def _g...
Load parameters from a file with the specified format. Args: path : path or file object
juraj-google-style
def InsertMessage(self, message, timeout=None): if (not isinstance(message, common_pb2.Message)): raise InvalidArgument(('Attempt to send unexpected message type: %s' % message.__class__.__name__)) if (not message.HasField('source')): message.source.service_name = self._service_name if (not ...
Inserts a message into the Fleetspeak server. Sets message.source, if unset. Args: message: common_pb2.Message The message to send. timeout: How many seconds to try for. Raises: grpc.RpcError: if the RPC fails. InvalidArgument: if message is not a common_pb2.Message.
codesearchnet
def _client_send(self, msg): try: self._client.write(msg.encode('utf8') + b'\n') self._client.flush() self.log.debug('Snippet sent %s.', msg) except socket.error as e: raise Error(self._ad, 'Encountered socket error "%s" sending RPC message "%s"' % (e, msg))
Sends an Rpc message through the connection. Args: msg: string, the message to send. Raises: Error: a socket error occurred during the send.
github-repos
def create_message(self, channel_id, text): baseurl = (self.rest_baseurl + '/channels/{}/messages'.format(channel_id)) requests.post(baseurl, headers=self.headers, data=json.dumps({'content': text}))
Sends a message to a Discord channel or user via REST API Args: channel_id (string): ID of destingation Discord channel text (string): Content of message
codesearchnet
def _open_interface(self, client, uuid, iface, key): conn_id = self._validate_connection('open_interface', uuid, key) if (conn_id is None): return conn_data = self._connections[uuid] conn_data['last_touch'] = monotonic() slug = self._build_device_slug(uuid) try: resp = (yield sel...
Open an interface on a connected device. Args: client (string): The client id who is requesting this operation uuid (int): The id of the device we're opening the interface on iface (string): The name of the interface that we're opening key (string): The key to authenticate the caller
codesearchnet
def get_cloudflare_records(self, *, account): zones = [] for zobj in self.__cloudflare_list_zones(account=account): try: self.log.debug('Processing DNS zone CloudFlare/{}'.format(zobj['name'])) zone = {'zone_id': get_resource_id('cfz', zobj['name']), 'name': zobj['name'], 'source...
Return a `list` of `dict`s containing the zones and their records, obtained from the CloudFlare API Returns: account (:obj:`CloudFlareAccount`): A CloudFlare Account object :obj:`list` of `dict`
codesearchnet
def create_repository(cls, repository_data): location = ('memory{%s}' % hex(id(repository_data))) resource_pool = ResourcePool(cache_size=None) repo = MemoryPackageRepository(location, resource_pool) repo.data = repository_data return repo
Create a standalone, in-memory repository. Using this function bypasses the `package_repository_manager` singleton. This is usually desired however, since in-memory repositories are for temporarily storing programmatically created packages, which we do not want to cache and that do not persist. Args: repository_data ...
codesearchnet
def decode(self, decoder_input_ids, encoder_outputs, encoder_attention_mask: Optional[jnp.ndarray]=None, decoder_attention_mask: Optional[jnp.ndarray]=None, decoder_position_ids: Optional[jnp.ndarray]=None, past_key_values: Optional[dict]=None, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool...
Returns: Example: ```python >>> import jax.numpy as jnp >>> from transformers import AutoTokenizer, FlaxPegasusForConditionalGeneration >>> model = FlaxPegasusForConditionalGeneration.from_pretrained("google/pegasus-large") >>> tokenizer = AutoTokenizer.from_pretrained("google/pegasus-large") >>> text = "My friends...
github-repos
def all_label_values(self, label_list_ids=None): values = set() for utterance in self.utterances.values(): values = values.union(utterance.all_label_values(label_list_ids=label_list_ids)) return values
Return a set of all label-values occurring in this corpus. Args: label_list_ids (list): If not None, only labels from label-lists with an id contained in this list are considered. Returns: :class:`set`: A set of distinct label-values.
juraj-google-style
def ListFileEntries(self, base_path_specs, output_writer): for base_path_spec in base_path_specs: file_system = resolver.Resolver.OpenFileSystem(base_path_spec) file_entry = resolver.Resolver.OpenFileEntry(base_path_spec) if file_entry is None: logging.warning( 'Unable to ...
Lists file entries in the base path specification. Args: base_path_specs (list[dfvfs.PathSpec]): source path specification. output_writer (StdoutWriter): output writer.
juraj-google-style
def random_unitary(dim, seed=None): if ((dim == 0) or (not math.log2(dim).is_integer())): raise QiskitError('Desired unitary dimension not a positive power of 2.') matrix = np.zeros([dim, dim], dtype=complex) for j in range(dim): if (j == 0): a = random_state(dim, seed) e...
Return a random dim x dim unitary Operator from the Haar measure. Args: dim (int): the dim of the state space. seed (int): Optional. To set a random seed. Returns: Operator: (dim, dim) unitary operator. Raises: QiskitError: if dim is not a positive power of 2.
codesearchnet
def __init__(self, tcex, domain, data_type, ttl_minutes=None, mapping=None): self.tcex = tcex self.ttl = None if ttl_minutes is not None: self.ttl = self._dt_to_epoch(datetime.now() - timedelta(minutes=int(ttl_minutes))) self.ds = self.tcex.datastore(domain...
Initialize class properties. Args: tcex (object): An instance of TcEx. domain (): [description] data_type ([type]): [description] ttl_minutes (int, optional): Defaults to None. Number of minutes the cache is valid. mapping ([type], optional): Defaults to None. [description]
juraj-google-style
def to_api(self): vals = {} for (attribute, attribute_type) in self._props.items(): prop = getattr(self, attribute) vals[self._to_camel_case(attribute)] = self._to_api_value(attribute_type, prop) return vals
Return a dictionary to send to the API. Returns: dict: Mapping representing this object that can be sent to the API.
codesearchnet
def set_category(self, category): pcategory = self.find('general/category') pcategory.clear() name = ElementTree.SubElement(pcategory, 'name') if isinstance(category, Category): id_ = ElementTree.SubElement(pcategory, 'id') id_.text = category.id name.text = category.name eli...
Set the policy's category. Args: category: A category object.
codesearchnet
def get_revisions(page): start_string = " <revision>\n" end_string = " </revision>\n" ret = [] current_pos = 0 while True: start_pos = page.find(start_string, current_pos) if start_pos == -1: break end_pos = page.find(end_string, start_pos) assert end_pos != -1 ret.append(pa...
Extract the revisions of a page. Args: page: a string Returns: a list of strings
juraj-google-style
def _CaptureExpression(self, frame, expression): rc, value = _EvaluateExpression(frame, expression) if not rc: return {'name': expression, 'status': value} return self.CaptureNamedVariable(expression, value, 0, self.expression_capture_limits)
Evalutes the expression and captures it into a Variable object. Args: frame: evaluation context. expression: watched expression to compile and evaluate. Returns: Variable object (which will have error status if the expression fails to evaluate).
juraj-google-style
def in_test_phase(x, alt, training=None): return in_train_phase(alt, x, training=training)
Selects `x` in test phase, and `alt` otherwise. Note that `alt` should have the *same shape* as `x`. Args: x: What to return in test phase (tensor or callable that returns a tensor). alt: What to return otherwise (tensor or callable that returns a tensor). training: Optional scalar tensor (or Python boolean, or Pytho...
github-repos
def iaf_hparams(hidden_size=512, filter_size=4096): hparams = common_hparams.basic_params1() hparams.hidden_size = hidden_size hparams.add_hparam('attention_key_channels', None) hparams.add_hparam('attention_value_channels', None) hparams.add_hparam('num_heads', 4) hparams.add_hparam('attention_...
Create hyperpameters for inverse autoregressive flows. Args: hidden_size: Width of attention layers and neural network output layer. filter_size: Hidden layer width for neural network. Returns: hparams: Hyperpameters with basic presets for inverse autoregressive flows.
codesearchnet
def UploadFile(self, fd, offset=0, amount=None): return self._UploadChunkStream(self._streamer.StreamFile(fd, offset=offset, amount=amount))
Uploads chunks of a given file descriptor to the transfer store flow. Args: fd: A file descriptor to upload. offset: An integer offset at which the file upload should start on. amount: An upper bound on number of bytes to stream. If it is `None` then the whole file is uploaded. Returns: A `BlobImageDescriptor` object...
codesearchnet
def clone(self, callable=None, **overrides): old = {k: v for (k, v) in self.get_param_values() if (k not in ['callable', 'name'])} params = dict(old, **overrides) callable = (self.callable if (callable is None) else callable) return self.__class__(callable, **params)
Clones the Callable optionally with new settings Args: callable: New callable function to wrap **overrides: Parameter overrides to apply Returns: Cloned Callable object
codesearchnet
def _ParseFValue(self, registry_key): registry_value = registry_key.GetValueByName('F') if (not registry_value): raise errors.ParseError('missing value: "F" in Windows Registry key: {0:s}.'.format(registry_key.name)) f_value_map = self._GetDataTypeMap('f_value') try: return self._ReadStr...
Parses an F value. Args: registry_key (dfwinreg.WinRegistryKey): Windows Registry key. Returns: f_value: F value stored in the Windows Registry key. Raises: ParseError: if the Windows Registry key does not contain an F value or F value cannot be parsed.
codesearchnet
def remove_acl(path): if ((platform.system() == constants.PLATFORM_DARWIN) and os.path.isfile('/bin/chmod')): subprocess.call(['/bin/chmod', '-R', '-N', path]) elif ((platform.system() == constants.PLATFORM_LINUX) and os.path.isfile('/bin/setfacl')): subprocess.call(['/bin/setfacl', '-R', '-b', ...
Remove the ACL of the file or folder located on the given path. Also remove the ACL of any file and folder below the given one, recursively. Args: path (str): Path to the file or folder to remove the ACL for, recursively.
codesearchnet
def dump_database_as_insert_sql(engine: Engine, fileobj: TextIO = sys.stdout, include_ddl: bool = False, multirow: bool = False) -> None: for tablename in get_table_names(engine): dump_table_as_insert_sql( ...
Reads an entire database and writes SQL to replicate it to the output file-like object. Args: engine: SQLAlchemy :class:`Engine` fileobj: file-like object to write to include_ddl: if ``True``, include the DDL to create the table as well multirow: write multi-row ``INSERT`` statements
juraj-google-style
def enum_value_descriptor_to_code_string(enum_value_descriptor: descriptor.EnumValueDescriptor) -> str: original_code = annotation_utils.get_enum_value_original_code(enum_value_descriptor) return original_code if original_code is not None else enum_value_descriptor.name.lower().replace('_', '-')
Returns the code string describing the enum value. Args: enum_value_descriptor: The EnumValueDescriptor to convert. Returns: The code string describing the enum value.
github-repos
def rollaxis(a, axis, start=0): if isinstance(a, np.ndarray): return np.rollaxis(a, axis, start) if (axis not in range(a.ndim)): raise ValueError(('rollaxis: axis (%d) must be >=0 and < %d' % (axis, a.ndim))) if (start not in range((a.ndim + 1))): raise ValueError(('rollaxis: start (...
Roll the specified axis backwards, until it lies in a given position. Args: a (array_like): Input array. axis (int): The axis to roll backwards. The positions of the other axes do not change relative to one another. start (int, optional): The axis is rolled until it lies before this position. The default, 0, results...
codesearchnet
def issubset(self, other): other = self._cast_to_frameset(other) if (other is NotImplemented): return NotImplemented return (self.items <= other.items)
Check if the contents of `self` is a subset of the contents of `other.` Args: other (:class:`FrameSet`): Returns: bool: :class:`NotImplemented`: if `other` fails to convert to a :class:`FrameSet`
codesearchnet
def compute_jaccard_index(x_set, y_set): if ((not x_set) or (not y_set)): return 0.0 intersection_cardinal = len((x_set & y_set)) union_cardinal = len((x_set | y_set)) return (intersection_cardinal / float(union_cardinal))
Return the Jaccard similarity coefficient of 2 given sets. Args: x_set (set): first set. y_set (set): second set. Returns: float: Jaccard similarity coefficient.
codesearchnet
def create_symmetric_key(self, algorithm, length): if (algorithm not in self._symmetric_key_algorithms.keys()): raise exceptions.InvalidField('The cryptographic algorithm {0} is not a supported symmetric key algorithm.'.format(algorithm)) cryptography_algorithm = self._symmetric_key_algorithms.get(algor...
Create a symmetric key. Args: algorithm(CryptographicAlgorithm): An enumeration specifying the algorithm for which the created key will be compliant. length(int): The length of the key to be created. This value must be compliant with the constraints of the provided algorithm. Returns: dict: A dictionary containing th...
codesearchnet
def set_el(cls, el, value): if (not el): return tag_name = el.elt.tagName.lower() if (tag_name == 'textarea'): cls._set_textarea(el, value) elif (tag_name == 'input'): if ('typeahead' in el.class_name.lower()): cls._set_typeahead(el, value) else: c...
Set given `el` tag element to `value`. Automatically choose proper method to set the `value` based on the type of the `el`. Args: el (obj): Element reference to the input you want to convert to typeahead. value (list): List of dicts with two keys: ``source`` and ``val``.
codesearchnet
def submit(self): if (self._future is not None): raise JobError('We have already submitted the job!') validate_qobj_against_schema(self._qobj) self._future = self._executor.submit(self._fn, self._job_id, self._qobj)
Submit the job to the backend for execution. Raises: QobjValidationError: if the JSON serialization of the Qobj passed during construction does not validate against the Qobj schema. JobError: if trying to re-submit the job.
codesearchnet
def _ExtractWithFilter(self, source_path_specs, destination_path, output_writer, artifact_filters, filter_file, artifact_definitions_path, custom_artifacts_path, skip_duplicates=True): extraction_engine = engine.BaseEngine() if (self._source_type in self._SOURCE_TYPES_TO_PREPROCESS): self._PreprocessSou...
Extracts files using a filter expression. This method runs the file extraction process on the image and potentially on every VSS if that is wanted. Args: source_path_specs (list[dfvfs.PathSpec]): path specifications to extract. destination_path (str): path where the extracted files should be stored. output_writer (CL...
codesearchnet
def _UpdateLatestProcessingTime(self, task): self._latest_task_processing_time = max( self._latest_task_processing_time, task.last_processing_time)
Updates the latest processing time of the task manager from the task. This method does not lock the manager and should be called by a method holding the manager lock. Args: task (Task): task to update the processing time of.
juraj-google-style
def read_int64(self, little_endian=True): if little_endian: endian = '<' else: endian = '>' return self.unpack(('%sq' % endian), 8)
Read 8 bytes as a signed integer value from the stream. Args: little_endian (bool): specify the endianness. (Default) Little endian. Returns: int:
codesearchnet
def _maybe_commit(self, transaction): try: transaction._commit() return True except exceptions.GoogleAPICallError as exc: if transaction._read_only: raise if isinstance(exc, exceptions.Aborted): re...
Try to commit the transaction. If the transaction is read-write and the ``Commit`` fails with the ``ABORTED`` status code, it will be retried. Any other failure will not be caught. Args: transaction (~.firestore_v1beta1.transaction.Transaction): The transaction to be ``Commit``-ed. Returns: bool: Indicating if the c...
juraj-google-style
def allconcat_ring(xs, devices, concat_axis): n = len(xs) if n == 1: return xs parts = [[xs[target] if target == source else None for source in xrange(n)] for target in xrange(n)] for distance in xrange(1, n for target in xrange(n): source = (target + distance) % n if parts...
Concatenate all Tensors everywhere. Performance-optimized for a ring of devices. Args: xs: a list of n tf.Tensors devices: a list of n strings concat_axis: an integer Returns: a list of n Tensors
juraj-google-style
def get_slab(self, shift=0, tol=0.1, energy=None): h = self._proj_height p = (h / self.parent.lattice.d_hkl(self.miller_index)) if self.in_unit_planes: nlayers_slab = int(math.ceil((self.min_slab_size / p))) nlayers_vac = int(math.ceil((self.min_vac_size / p))) else: nlayers_slab...
This method takes in shift value for the c lattice direction and generates a slab based on the given shift. You should rarely use this method. Instead, it is used by other generation algorithms to obtain all slabs. Arg: shift (float): A shift value in Angstrom that determines how much a slab should be shifted. tol (fl...
codesearchnet
def _DecodeURL(self, url): if not url: return '' decoded_url = urlparse.unquote(url) if isinstance(decoded_url, py2to3.BYTES_TYPE): try: decoded_url = decoded_url.decode('utf-8') except UnicodeDecodeError as exception: decoded_url = decoded_url.decode('utf-8', errors=...
Decodes the URL, replaces %XX to their corresponding characters. Args: url (str): encoded URL. Returns: str: decoded URL.
juraj-google-style
def recall_at_precision(y_true, y_pred, precision): (y_true, y_pred) = _mask_value_nan(y_true, y_pred) (precision, recall, _) = skm.precision_recall_curve(y_true, y_pred) return recall[np.searchsorted((precision - precision), 0)]
Recall at a certain precision threshold Args: y_true: true labels y_pred: predicted labels precision: resired precision level at which where to compute the recall
codesearchnet
def __init__(self, channel): self.AnalyzeSentiment = channel.unary_unary( "/google.cloud.language.v1beta2.LanguageService/AnalyzeSentiment", request_serializer=google_dot_cloud_dot_language__v1beta2_dot_proto_dot_language__service__pb2.AnalyzeSentimentRequest.SerializeToString, ...
Constructor. Args: channel: A grpc.Channel.
juraj-google-style
def reqHeadTimeStamp(self, contract: Contract, whatToShow: str, useRTH: bool, formatDate: int=1) -> datetime.datetime: return self._run(self.reqHeadTimeStampAsync(contract, whatToShow, useRTH, formatDate))
Get the datetime of earliest available historical data for the contract. Args: contract: Contract of interest. useRTH: If True then only show data from within Regular Trading Hours, if False then show all data. formatDate: If set to 2 then the result is returned as a timezone-aware datetime.datetime with UTC timezone.
codesearchnet
def GetMessages(self, formatter_mediator, event): if self.DATA_TYPE != event.data_type: raise errors.WrongFormatter('Unsupported data type: {0:s}.'.format( event.data_type)) event_values = event.CopyToDict() file_entry_type = event_values.get('file_entry_type', None) if file_entry...
Determines the formatted message strings for an event object. Args: formatter_mediator (FormatterMediator): mediates the interactions between formatters and other components, such as storage and Windows EventLog resources. event (EventObject): event. Returns: tuple(str, str): formatted message string and short messag...
juraj-google-style
def save(self, recipe): if 'id' in recipe and recipe['id'] is not None: self.logger.debug("Updating existing recipe: " + json.dumps(recipe)) url = '%(base_url)s/recipe/json/%(recipe_id)s' % { 'base_url': self.base_url, 'recipe_id': recipe['i...
Saves an AnswerFactory Recipe Args: recipe (dict): Dictionary specifying a recipe Returns: AnswerFactory Recipe id
juraj-google-style
def _inf_or_operator_handler_factory(c_start, is_delegate=True): @coroutine def inf_or_operator_handler(c, ctx): next_ctx = None if not is_delegate: ctx.value.append(c_start) c, self = yield else: assert ctx.value[0] == c_start assert ...
Generates handler co-routines for values that may be `+inf` or `-inf`. Args: c_start (int): The ordinal of the character that starts this token (either `+` or `-`). is_delegate (bool): True if a different handler began processing this token; otherwise, False. This will only be true for `-inf`, because it is not the on...
juraj-google-style
def _create_filters(col_params, extractors): result = [] for col_param, extractor in zip(col_params, extractors): a_filter = _create_filter(col_param, extractor) if a_filter: result.append(a_filter) return result
Creates filters for the given col_params. Args: col_params: List of ListSessionGroupsRequest.ColParam protobufs. extractors: list of extractor functions of the same length as col_params. Each element should extract the column described by the corresponding element of col_params. Returns: A list of filter functions. Ea...
juraj-google-style
def add(x1, x2): if any_symbolic_tensors((x1, x2)): return Add().symbolic_call(x1, x2) return backend.numpy.add(x1, x2)
Add arguments element-wise. Args: x1: First input tensor. x2: Second input tensor. Returns: The tensor containing the element-wise sum of `x1` and `x2`. Examples: >>> x1 = keras.ops.convert_to_tensor([1, 4]) >>> x2 = keras.ops.convert_to_tensor([5, 6]) >>> keras.ops.add(x1, x2) array([6, 10], dtype=int32) `keras.op...
github-repos
def _buckets_nearly_equal(a_dist, b_dist): (a_type, a_buckets) = _detect_bucket_option(a_dist) (b_type, b_buckets) = _detect_bucket_option(b_dist) if (a_type != b_type): return False elif (a_type == u'linearBuckets'): return _linear_buckets_nearly_equal(a_buckets, b_buckets) elif (a_...
Determines whether two `Distributions` are nearly equal. Args: a_dist (:class:`Distribution`): an instance b_dist (:class:`Distribution`): another instance Return: boolean: `True` if the two instances are approximately equal, otherwise False
codesearchnet
def handle_triple(self, lhs, relation, rhs): relation = relation.replace(':', '', 1) if self.is_relation_inverted(relation): (source, target, inverted) = (rhs, lhs, True) relation = self.invert_relation(relation) else: (source, target, inverted) = (lhs, rhs, False) source = _defa...
Process triples before they are added to the graph. Note that *lhs* and *rhs* are as they originally appeared, and may be inverted. Inversions are detected by is_relation_inverted() and de-inverted by invert_relation(). By default, this function: * removes initial colons on relations * de-inverts all inverted relatio...
codesearchnet
def get_http_raw(self, url=None, retry_count=3, headers=None, request_type='GET', form_data=None): if (headers is None): headers = {'Accept': 'text/html'} enc_form_data = None if form_data: enc_form_data = urlencode(form_data) try: enc_form_data = bytes(enc_form_data, enc...
The function for retrieving a raw HTML result via HTTP. Args: url (:obj:`str`): The URL to retrieve (required). retry_count (:obj:`int`): The number of times to retry in case socket errors, timeouts, connection resets, etc. are encountered. Defaults to 3. headers (:obj:`dict`): The HTTP headers. The Accept header defa...
codesearchnet
def get_json_files(files, recursive=False): json_files = [] if not files: return json_files for fn in files: if os.path.isdir(fn): children = list_json_files(fn, recursive) json_files.extend(children) elif is_json(fn): json_files.append(fn) ...
Return a list of files to validate from `files`. If a member of `files` is a directory, its children with a ``.json`` extension will be added to the return value. Args: files: A list of file paths and/or directory paths. recursive: If ``true``, this will descend into any subdirectories of input directories. Returns: ...
juraj-google-style
def _GetLinkedPath(self, event): if hasattr(event, 'local_path'): return event.local_path if hasattr(event, 'network_path'): return event.network_path if hasattr(event, 'relative_path'): paths = [] if hasattr(event, 'working_directory'): paths.append(event.working...
Determines the linked path. Args: event (EventObject): event that contains a linked path. Returns: str: linked path.
codesearchnet
def query_google(point, max_distance, key): if (not key): return [] if from_cache(GG_CACHE, point, max_distance): return from_cache(GG_CACHE, point, max_distance) req = requests.get((GOOGLE_PLACES_URL % (point.lat, point.lon, max_distance, key))) if (req.status_code != 200): retu...
Queries google maps API for a location Args: point (:obj:`Point`): Point location to query max_distance (float): Search radius, in meters key (str): Valid google maps api key Returns: :obj:`list` of :obj:`dict`: List of locations with the following format: { 'label': 'Coffee house', 'types': 'Commerce', 'suggestion_ty...
codesearchnet
def find_proxy_plugin(component, plugin_name): reg = ComponentRegistry() plugins = reg.load_extensions('iotile.proxy_plugin', comp_filter=component, class_filter=TileBusProxyPlugin, product_name='proxy_plugin') for (_name, plugin) in plugins: if (plugin.__name__ == plugin_name): return p...
Attempt to find a proxy plugin provided by a specific component Args: component (string): The name of the component that provides the plugin plugin_name (string): The name of the plugin to load Returns: TileBuxProxyPlugin: The plugin, if found, otherwise raises DataError
codesearchnet
def create_alias(target_path, alias_path): if ((platform.system() == 'Windows') and (not alias_path.endswith('.lnk'))): alias_path += '.lnk' if os.path.lexists(alias_path): os.remove(alias_path) if (platform.system() == 'Windows'): from win32com import client shell = client.D...
Creates an alias at 'alias_path' pointing to the file 'target_path'. On Unix, this is implemented via symlink. On Windows, this is done by creating a Windows shortcut file. Args: target_path: Destination path that the alias should point to. alias_path: Path at which to create the new alias.
codesearchnet
def from_scf_task(cls, scf_task, ddk_tolerance=None, manager=None): if (not isinstance(scf_task, ScfTask)): raise TypeError(('task `%s` does not inherit from ScfTask' % scf_task)) new = cls(manager=manager) multi_ddk = scf_task.input.make_ddk_inputs(tolerance=ddk_tolerance) ddk_tasks = [] fo...
Build a DteWork from a ground-state task. Args: scf_task: ScfTask object. ddk_tolerance: tolerance used in the DDK run if with_becs. None to use AbiPy default. manager: :class:`TaskManager` object.
codesearchnet
def __init__(self, action, chunk_size=None): chunk_size = chunk_size or self.DEFAULT_CHUNK_SIZE self._action = action self._streamer = streaming.Streamer(chunk_size=chunk_size)
Initializes the uploader. Args: action: A parent action that creates the uploader. Used to communicate with the parent flow. chunk_size: A number of (uncompressed) bytes per a chunk.
juraj-google-style
def shift(self, time: int) -> 'Interval': return Interval(self._begin + time, self._end + time)
Return a new interval shifted by `time` from self Args: time: time to be shifted Returns: Interval: interval shifted by `time`
juraj-google-style
def explicit(fixed_qubits: Iterable[raw_types.Qid], fallback: Optional['QubitOrder']=None) -> 'QubitOrder': result = tuple(fixed_qubits) if (len(set(result)) < len(result)): raise ValueError('Qubits appear in fixed_order twice: {}.'.format(result)) def func(qubits): remaining = (set(qubits)...
A basis that contains exactly the given qubits in the given order. Args: fixed_qubits: The qubits in basis order. fallback: A fallback order to use for extra qubits not in the fixed_qubits list. Extra qubits will always come after the fixed_qubits, but will be ordered based on the fallback. If no fallback is specified...
codesearchnet
def compare_modules(file_, imports): modules = parse_requirements(file_) imports = [imports[i]['name'] for i in range(len(imports))] modules = [modules[i]['name'] for i in range(len(modules))] modules_not_imported = (set(modules) - set(imports)) return modules_not_imported
Compare modules in a file to imported modules in a project. Args: file_ (str): File to parse for modules to be compared. imports (tuple): Modules being imported in the project. Returns: tuple: The modules not imported in the project, but do exist in the specified file.
codesearchnet
def __init__(self, funcs, trackable_obj=None): super(TFLiteConverterV2, self).__init__(funcs, trackable_obj)
Constructor for TFLiteConverter. Args: funcs: List of TensorFlow ConcreteFunctions. The list should not contain duplicate elements. trackable_obj: tf.AutoTrackable object associated with `funcs`. A reference to this object needs to be maintained so that Variables do not get garbage collected since functions have a wea...
github-repos
def __parse_tostr(self, text, **kwargs): n = self.options.get('nbest', 1) if self._KW_BOUNDARY in kwargs: patt = kwargs.get(self._KW_BOUNDARY, '.') tokens = list(self.__split_pattern(text, patt)) text = ''.join([t[0] for t in tokens]) btext = se...
Builds and returns the MeCab function for parsing Unicode text. Args: fn_name: MeCab function name that determines the function behavior, either 'mecab_sparse_tostr' or 'mecab_nbest_sparse_tostr'. Returns: A function definition, tailored to parsing Unicode text and returning the result as a string suitable for displa...
juraj-google-style
def pytest_terminal_summary_main(tr, id): from _pytest.config import create_terminal_writer if not len(id): id = 'tests' config = tr.config orig_writer = config.get_terminal_writer() orig_tbstyle = config.option.tbstyle orig_reportchars = tr.reportchars dir = f'reports/{id}' Path...
Generate multiple reports at the end of test suite run - each report goes into a dedicated file in the current directory. The report files are prefixed with the test suite name. This function emulates --duration and -rA pytest arguments. This function is to be called from `conftest.py` via `pytest_terminal_summary` w...
github-repos
def with_claims(self, additional_claims): new_additional_claims = copy.deepcopy(self._additional_claims) new_additional_claims.update(additional_claims or {}) return self.__class__( self._signer, service_account_email=self._service_account_email, sco...
Returns a copy of these credentials with modified claims. Args: additional_claims (Mapping[str, str]): Any additional claims for the JWT payload. This will be merged with the current additional claims. Returns: google.auth.service_account.Credentials: A new credentials instance.
juraj-google-style
def add_variable(self, feature_column, var): del feature_column, var raise NotImplementedError('StateManager.add_variable')
Adds an existing variable to the state. Args: feature_column: A `FeatureColumn` object to associate this variable with. var: The variable.
github-repos
def create_exception_by_name(name, detailCode='0', description='', traceInformation=None, identifier=None, nodeId=None): try: dataone_exception = globals()[name] except LookupError: dataone_exception = ServiceFailure return dataone_exception(detailCode, description, traceInformation, identif...
Create a DataONEException based object by name. Args: name: str The type name of a DataONE Exception. E.g. NotFound. If an unknown type name is used, it is automatically set to ServiceFailure. As the XML Schema for DataONE Exceptions does not restrict the type names, this may occur when deserializing an exception not...
codesearchnet
def evaluate(conditions, leaf_evaluator): if isinstance(conditions, list): if conditions[0] in list(EVALUATORS_BY_OPERATOR_TYPE.keys()): return EVALUATORS_BY_OPERATOR_TYPE[conditions[0]](conditions[1:], leaf_evaluator) else: return EVALUATORS_BY_OPERATOR_TYPE[ConditionOperatorTypes.OR](...
Top level method to evaluate conditions. Args: conditions: Nested array of and/or conditions, or a single leaf condition value of any type. Example: ['and', '0', ['or', '1', '2']] leaf_evaluator: Function which will be called to evaluate leaf condition values. Returns: Boolean: Result of evaluating the conditions usi...
juraj-google-style
def optional(name, default) -> 'Wildcard': return Wildcard(min_count=1, fixed_size=True, variable_name=name, optional=default)
Create a `Wildcard` that matches a single argument with a default value. If the wildcard does not match, the substitution will contain the default value instead. Args: name: The name for the wildcard. default: The default value of the wildcard. Returns: A n optional wildcard.
codesearchnet
def select(self, selector): if self._is_single_string_selector(selector, 'name'): return self._all_models_by_name.get_all(selector['name']) else: return find(self._all_models.values(), selector)
Query this document for objects that match the given selector. Args: selector (JSON-like query dictionary) : you can query by type or by name, e.g. ``{"type": HoverTool}``, ``{"name": "mycircle"}`` Returns: seq[Model]
juraj-google-style
def _extract_type_spec_recursively(value): if isinstance(value, composite_tensor.CompositeTensor): return value._type_spec if isinstance(value, variables.Variable): return resource_variable_ops.VariableSpec(value.shape, dtype=value.dtype, trainable=value.trainable) if tensor_util.is_tensor(v...
Return (collection of) `TypeSpec`(s) for `value` if it includes `Tensor`s. If `value` is a `Tensor` or `CompositeTensor`, return its `TypeSpec`. If `value` is a collection containing `Tensor` values, recursively supplant them with their respective `TypeSpec`s in a collection of parallel stucture. If `value` is none o...
github-repos
def track_event(self, name, properties=None, measurements=None): data = channel.contracts.EventData() data.name = (name or NULL_CONSTANT_STRING) if properties: data.properties = properties if measurements: data.measurements = measurements self.track(data, self._context)
Send information about a single event that has occurred in the context of the application. Args: name (str). the data to associate to this event.\n properties (dict). the set of custom properties the client wants attached to this data item. (defaults to: None)\n measurements (dict). the set of custom measurements the ...
codesearchnet
def head(self, n=10): r = self.__repr__().split('\n') print('\n'.join(r[:n]), end=' ')
Display the top of the file. Args: n (int): Number of lines to display
juraj-google-style
def __getitem__(self, key): if key in self._layout_map: return self._layout_map[key] matching_keys = [] for k in self._layout_map: if re.search(k, key): matching_keys.append(k) if len(matching_keys) > 1: raise ValueError(f"Path '{key}' matches multiple layout specific...
Retrieves the corresponding layout by the string key. When there isn't an exact match, all the existing keys in the layout map will be treated as a regex and map against the input key again. When there are multiple matches for the regex, an `ValueError` will be raised. Returns `None` if there isn't any match found. A...
github-repos
def run(self, test_config, ref_dir, tmp_dir, mode, heartbeat=None, num_attempts=0): assert 'name' in test_config name = test_config['name'] if 'ref' in test_config: assert 'run' in test_config arm_config = { 'name': name } if mode == 'te...
Build a CaptureAndDiffWorkflowItem for a test. Args: test_config: See test.yaml for structure of test_config. Returns: A CaptureAndDiffWorkflowItem
juraj-google-style