code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def from_der(der): d = get_bytes(der) if len(d) < 8: raise ValueError("DER signature string is too short.") if len(d) > 72: raise ValueError("DER signature string ...
Decodes a Signature that was DER-encoded. Args: der (bytes or str): The DER encoding to be decoded. Returns: Signature: The deserialized signature.
juraj-google-style
def WriteEventBody(self, event): inode = getattr(event, 'inode', None) if inode is None: event.inode = 0 json_dict = self._JSON_SERIALIZER.WriteSerializedDict(event) json_string = json.dumps(json_dict, sort_keys=True) if self._event_counter != 0: self._output_writer.Write(', ') ...
Writes the body of an event object to the output. Args: event (EventObject): event.
juraj-google-style
def _ReadFileEntries(self, file_object): self._file_entries = {} file_offset = 0 while file_offset < self._file_size or self._file_size == 0: file_entry = self._ReadFileEntry(file_object, file_offset) file_offset += file_entry.size if file_entry.path == 'TRAILER!!!': break ...
Reads the file entries from the cpio archive. Args: file_object (FileIO): file-like object.
juraj-google-style
def _GenerateSection(self, problem_type): if (problem_type == transitfeed.TYPE_WARNING): dataset_problems = self._dataset_warnings heading = 'Warnings' else: dataset_problems = self._dataset_errors heading = 'Errors' if (not dataset_problems): return '' prefix = (...
Generate a listing of the given type of problems. Args: problem_type: The type of problem. This is one of the problem type constants from transitfeed. Returns: The generated HTML as a string.
codesearchnet
def get_service_name(self, service_id: str) -> str: if not self._manager: raise RuntimeError('Only the Swarm manager node can retrieve all' ' the services details.') service = self._client.services.get(service_id) return service.name
Get the name of the docker service. Only the manager nodes can retrieve service name Args: service_id (string): List of service ID Returns: string, name of the docker service
juraj-google-style
def terminate(self, nowait=False): logger.debug("Acquiring lock for service termination") with self.lock: logger.debug("Terminating service") if not self.listener: logger.warning("Service already stopped.") return self.listen...
Finalize and stop service Args: nowait: set to True to terminate immediately and skip processing messages still in the queue
juraj-google-style
def get_axis(self, undefined=np.zeros(3)): tolerance = 1e-17 self._normalise() norm = np.linalg.norm(self.vector) if (norm < tolerance): return undefined else: return (self.vector / norm)
Get the axis or vector about which the quaternion rotation occurs For a null rotation (a purely real quaternion), the rotation angle will always be `0`, but the rotation axis is undefined. It is by default assumed to be `[0, 0, 0]`. Params: undefined: [optional] specify the axis vector that should define a null rotat...
codesearchnet
def is_method_call(func, types=(), methods=()): return (isinstance(func, astroid.BoundMethod) and isinstance(func.bound, astroid.Instance) and ((func.bound.name in types) if types else True) and ((func.name in methods) if methods else True))
Determines if a BoundMethod node represents a method call. Args: func (astroid.BoundMethod): The BoundMethod AST node to check. types (Optional[String]): Optional sequence of caller type names to restrict check. methods (Optional[String]): Optional sequence of method names to restrict check. Returns: bool: true if th...
codesearchnet
def get(self, file_path, ref, **kwargs): file_path = file_path.replace('/', '%2F') return GetMixin.get(self, file_path, ref=ref, **kwargs)
Retrieve a single file. Args: file_path (str): Path of the file to retrieve ref (str): Name of the branch, tag or commit **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabGetError: If the file could not be retrieved Returns: object: Th...
codesearchnet
def compute_effective_axis_dimension(dimension: int, fixed_dimension: int, num_token_to_add: int=0) -> int: if dimension <= 0: dimension = fixed_dimension dimension -= num_token_to_add return dimension
Args: dimension: fixed_dimension: num_token_to_add: Returns:
github-repos
def GetMACBRepresentationFromDescriptions(self, timestamp_descriptions): macb_representation = [] if (('mtime' in timestamp_descriptions) or (definitions.TIME_DESCRIPTION_MODIFICATION in timestamp_descriptions)): macb_representation.append('M') else: macb_representation.append('.') if ((...
Determines the MACB representation from the timestamp descriptions. MACB representation is a shorthand for representing one or more of modification, access, change, birth timestamp descriptions as the letters "MACB" or a "." if the corresponding timestamp is not set. Note that this is an output format shorthand and d...
codesearchnet
def default_storable(python_type, exposes=None, version=None, storable_type=None, peek=default_peek): if (not exposes): for extension in expose_extensions: try: exposes = extension(python_type) except (SystemExit, KeyboardInterrupt): raise ...
Default mechanics for building the storable instance for a type. Arguments: python_type (type): type. exposes (iterable): attributes exposed by the type. version (tuple): version number. storable_type (str): universal string identifier for the type. peek (callable): peeking routine. Returns: Storable: storable ...
codesearchnet
def docs(recreate, gen_index, run_doctests): build_dir = conf.get_path('build_dir', '.build') docs_dir = conf.get_path('docs.path', 'docs') refdoc_paths = conf.get('docs.reference', []) docs_html_dir = conf.get_path('docs.out', os.path.join(docs_dir, 'html')) docs_tests_dir = conf.get_path('docs.tes...
Build the documentation for the project. Args: recreate (bool): If set to **True**, the build and output directories will be cleared prior to generating the docs. gen_index (bool): If set to **True**, it will generate top-level index file for the reference documentation. run_doctests (bool): Set to **True** if you wan...
codesearchnet
def get_output_slot(element_name): _, output_slot = parse_node_or_tensor_name(element_name) return output_slot if output_slot is not None else 0
Get the output slot number from the name of a graph element. If element_name is a node name without output slot at the end, 0 will be assumed. Args: element_name: (`str`) name of the graph element in question. Returns: (`int`) output slot number.
github-repos
def compute_mu(L_aug, Y, k, p): n, d = L_aug.shape assert Y.shape[0] == n mu = np.zeros((d, k)) for y in range(1, k + 1): L_y = L_aug[Y == y] mu[:, y - 1] = L_y.sum(axis=0) / L_y.shape[0] return mu
Given label matrix L_aug and labels Y, compute the true mu params. Args: L: (np.array {0,1}) [n, d] The augmented (indicator) label matrix Y: (np.array int) [n] The true labels in {1,...,k} k: (int) Cardinality p: (np.array float) [k] The class balance
juraj-google-style
def Query(self, query, parameters=None): if parameters: self._cursor.execute(query, parameters) else: self._cursor.execute(query) return self._cursor.fetchall()
Queries the database file. Args: query (str): SQL query. parameters (Optional[dict|tuple]): query parameters. Returns: list[sqlite3.Row]: rows resulting from the query.
codesearchnet
def filter_data(self, field, filter_value, filter_operator, field_converter=None): data = [] if (self._indexes.get(field) is not None): data = self._index_filter(self._indexes.get(field), filter_value, filter_operator, field_converter) return set(data)
Filter the data given the provided. Args: field (string): The field to filter on. filter_value (string | list): The value to match. filter_operator (string): The operator for comparison. field_converter (method): A method used to convert the field before comparison. Returns: (set): List of matching data objects
codesearchnet
def refresh_access_token(self, refresh_token): request = self._get_request() response = request.post(self.OAUTH_TOKEN_URL, { "grant_type": "refresh_token", "refresh_token": refresh_token }) self.auth = HSAccessTokenAuth.from_response(response) ret...
Refreshes the current access token. Gets a new access token, updates client auth and returns it. Args: refresh_token (str): Refresh token to use Returns: The new access token
juraj-google-style
def delete_all(self, filter=None, timeout=-1): return self._client.delete_all(filter=filter, timeout=timeout)
Delete an SNMPv3 User based on User name specified in filter. The user will be deleted only if it has no associated destinations. Args: username: ID or URI of SNMPv3 user. filter: A general filter/query string to narrow the list of items returned. The default is no filter - all resources are returned. Returns: bool: ...
juraj-google-style
def encode(cls, command): args = [] for arg in command.args: if (not isinstance(arg, str)): arg = str(arg) if ((',' in arg) or arg.startswith(' ') or arg.endswith(' ') or arg.startswith('hex:')): arg = 'hex:{}'.format(hexlify(arg.encode('utf-8')).decode('utf-8')) ...
Encode a command as an unambiguous string. Args: command (Command): The command to encode. Returns: str: The encoded command
codesearchnet
def repeat(self, count=None, name=None) -> 'DatasetV2': from tensorflow.python.data.ops import repeat_op return repeat_op._repeat(self, count, name)
Repeats this dataset so each original value is seen `count` times. >>> dataset = tf.data.Dataset.from_tensor_slices([1, 2, 3]) >>> dataset = dataset.repeat(3) >>> [a.item() for a in dataset.as_numpy_iterator()] [1, 2, 3, 1, 2, 3, 1, 2, 3] Note: If the input dataset depends on global state (e.g. a random number genera...
github-repos
def _wrap_section(source, width): if _get_section('usage', source): return _wrap_usage_section(source, width) if _is_definition_section(source): return _wrap_definition_section(source, width) lines = inspect.cleandoc(source).splitlines() paragraphs = (textwrap.wrap(line, width,...
Wrap the given section string to the current terminal size. Intelligently wraps the section string to the given width. When wrapping section lines, it auto-adjusts the spacing between terms and definitions. It also adjusts commands the fit the correct length for the arguments. Args: source: The section string to wrap...
juraj-google-style
def sign_hash(private_key, hash, hash_algo): hash_algo = _hash_algorithms[hash_algo] return get_privatekey(private_key).sign(hash, padding.PKCS1v15(), utils.Prehashed(hash_algo))
Sign the given hash with the given private key. Args: private_key (str): PEM enoded private key hash (byte str): hash to sign hash_algo (str): name of hash algorithm used Returns: byte string representing the signature
codesearchnet
def aggregate_scores(weights: typing.List[str]) -> typing.Dict[str, typing.Dict[str, float]]: decision_trees: typing.Dict[str, typing.Dict[str, float]] = dict() for row in weights: row = row.strip() if not row: continue feature = row.split('\t')[0] feature_group, feat...
Exports the model by aggregating the weight scores. Args: weights (List[str]): The lines of exported weight score file. Returns: model (Dict[string, Dict[string, float]]) The exported model.
github-repos
def init_app(self, app): self._key = app.config.get(CONF_KEY) or getenv(CONF_KEY) if not self._key: return self._endpoint_uri = app.config.get(CONF_ENDPOINT_URI) sender = AsynchronousSender(self._endpoint_uri) queue = AsynchronousQueue(sender) self...
Initializes the extension for the provided Flask application. Args: app (flask.Flask). the Flask application for which to initialize the extension.
juraj-google-style
def submit_snl(self, snl): try: snl = snl if isinstance(snl, list) else [snl] jsondata = [s.as_dict() for s in snl] payload = {"snl": json.dumps(jsondata, cls=MontyEncoder)} response = self.session.post("{}/snl/submit".format(self.preamble), ...
Submits a list of StructureNL to the Materials Project site. .. note:: As of now, this MP REST feature is open only to a select group of users. Opening up submissions to all users is being planned for the future. Args: snl (StructureNL/[StructureNL]): A single StructureNL, or a list of StructureNL objects Returns: ...
juraj-google-style
def run(argv=None, save_main_session=True, test_pipeline=None) -> PipelineResult: known_args, pipeline_args = parse_known_args(argv) pipeline_options = PipelineOptions(pipeline_args) pipeline_options.view_as(SetupOptions).save_main_session = save_main_session class OnnxNoBatchModelHandler(OnnxModelHand...
Args: argv: Command line arguments defined for this example. save_main_session: Used for internal testing. test_pipeline: Used for internal testing.
github-repos
def vectorize(self, token_list): vector_list = [self.__collection.tf_idf(token, self.__collection) for token in token_list] return vector_list
Tokenize token list. Args: token_list: The list of tokens.. Returns: [vector of token, vector of token, vector of token, ...]
juraj-google-style
def xmon_op_from_proto_dict(proto_dict: Dict) -> ops.Operation: def raise_missing_fields(gate_name: str): raise ValueError('{} missing required fields: {}'.format(gate_name, proto_dict)) param = _parameterized_value_from_proto_dict qubit = devices.GridQubit.from_proto_dict if ('exp_w' in proto_...
Convert the proto dictionary to the corresponding operation. See protos in api/google/v1 for specification of the protos. Args: proto_dict: Dictionary representing the proto. Keys are always strings, but values may be types correspond to a raw proto type or another dictionary (for messages). Returns: The operation. ...
codesearchnet
def get_block_hash(self, height, id=None, endpoint=None): return self._call_endpoint(GET_BLOCK_HASH, params=[height], id=id, endpoint=endpoint)
Get hash of a block by its height Args: height: (int) height of the block to lookup id: (int, optional) id to use for response tracking endpoint: (RPCEndpoint, optional) endpoint to specify to use Returns: json object of the result or the error encountered in the RPC call
juraj-google-style
def output_file(self, filename, title='Bokeh Plot', mode='cdn', root_dir=None): self._file = {'filename': filename, 'resources': Resources(mode=mode, root_dir=root_dir), 'title': title} if os.path.isfile(filename): log.info(("Session output file '%s' already exists, will be overwritten." % filename))
Configure output to a standalone HTML file. Calling ``output_file`` not clear the effects of any other calls to ``output_notebook``, etc. It adds an additional output destination (publishing to HTML files). Any other active output modes continue to be active. Args: filename (str) : a filename for saving the HTML docu...
codesearchnet
def _io_write_test_preprocessor(test_spec: dict, expected: List[str], env: TestEnvironment): if (pipeline := test_spec.get('pipeline', None)): for transform in pipeline.get('transforms', []): if transform.get('type', '').startswith('WriteTo'): transform['type'] = 'LogForTesting' ...
Preprocessor for tests that involve writing to IO. This preprocessor replaces any WriteTo transform with a LogForTesting transform. This allows the test to verify the data being written without actually writing to an external system. Args: test_spec: The dictionary representation of the YAML pipeline specification. e...
github-repos
def get_all_resource_ids_in_datastore(configuration=None): resource = Resource(configuration=configuration) (success, result) = resource._read_from_hdx('datastore', '_table_metadata', 'resource_id', Resource.actions()['datastore_search'], limit=10000) resource_ids = list() if (not success): logg...
Get list of resources that have a datastore returning their ids. Args: configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration. Returns: List[str]: List of resource ids that are in the datastore
codesearchnet
def _from_base_type(self, value): if (not value): return None try: credentials = client.Credentials.new_from_json(value) except ValueError: credentials = None return credentials
Converts our stored JSON string back to the desired type. Args: value: A value from the datastore to be converted to the desired type. Returns: A deserialized Credentials (or subclass) object, else None if the value can't be parsed.
codesearchnet
def clinsig_query(self, query, mongo_query): LOG.debug('clinsig is a query parameter') trusted_revision_level = ['mult', 'single', 'exp', 'guideline'] rank = [] str_rank = [] clnsig_query = {} for item in query['clinsig']: rank.append(int(item)) rank.append(CLINSIG_MAP[int(item)]...
Add clinsig filter values to the mongo query object Args: query(dict): a dictionary of query filters specified by the users mongo_query(dict): the query that is going to be submitted to the database Returns: clinsig_query(dict): a dictionary with clinsig key-values
codesearchnet
def ValidateToken(token, targets): def GetSubjectForError(): if (len(targets) == 1): return list(targets)[0] else: return None if (not token): raise access_control.UnauthorizedAccess(('Must give an authorization token for %s' % targets), subject=GetSubjectForErro...
Does basic token validation. Args: token: User's credentials as access_control.ACLToken. targets: List of targets that were meant to be accessed by the token. This is used for logging purposes only. Returns: True if token is valid. Raises: access_control.UnauthorizedAccess: if token is not valid. ValueError: if targ...
codesearchnet
def collection(self, *collection_path): if (len(collection_path) == 1): path = collection_path[0].split(_helpers.DOCUMENT_PATH_DELIMITER) else: path = collection_path return CollectionReference(*path, client=self)
Get a reference to a collection. For a top-level collection: .. code-block:: python >>> client.collection('top') For a sub-collection: .. code-block:: python >>> client.collection('mydocs/doc/subcol') >>> # is the same as >>> client.collection('mydocs', 'doc', 'subcol') Sub-collections can be nested deeper in a ...
codesearchnet
def __build_cmd_maps(cls): cmd_map_all = {} cmd_map_visible = {} cmd_map_internal = {} for name in dir(cls): obj = getattr(cls, name) if iscommand(obj): for cmd in getcommands(obj): if (cmd in cmd_map_all.keys()): raise PyShellError("The co...
Build the mapping from command names to method names. One command name maps to at most one method. Multiple command names can map to the same method. Only used by __init__() to initialize self._cmd_map. MUST NOT be used elsewhere. Returns: A tuple (cmd_map, hidden_cmd_map, internal_cmd_map).
codesearchnet
def get_seed(op_seed): eager = context.executing_eagerly() if eager: global_seed = context.global_seed() else: global_seed = ops.get_default_graph().seed if global_seed is not None: if op_seed is None: if hasattr(ops.get_default_graph(), '_seed_used'): ...
Returns the local seeds an operation should use given an op-specific seed. Given operation-specific seed, `op_seed`, this helper function returns two seeds derived from graph-level and op-level seeds. Many random operations internally use the two seeds to allow user to change the seed globally for a graph, or for only...
github-repos
def take_while(self, predicate): if self.closed(): raise ValueError('Attempt to call take_while() on a closed Queryable.') if (not is_callable(predicate)): raise TypeError('take_while() parameter predicate={0} is not callable'.format(repr(predicate))) return self._create(self._generate_take_...
Returns elements from the start while the predicate is True. Note: This method uses deferred execution. Args: predicate: A function returning True or False with which elements will be tested. Returns: A Queryable over the elements from the beginning of the source sequence for which predicate is True. Raises: ValueE...
codesearchnet
def render(self, link_url, image_url, **kwargs): path = ('%s/render' % self.path) data = {'link_url': link_url, 'image_url': image_url} return self.gitlab.http_get(path, data, **kwargs)
Preview link_url and image_url after interpolation. Args: link_url (str): URL of the badge link image_url (str): URL of the badge image **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabRenderError: If the rendering failed Returns: dic...
codesearchnet
def put_archive(self, path, data): return self.client.api.put_archive(self.id, path, data)
Insert a file or folder in this container using a tar archive as source. Args: path (str): Path inside the container where the file(s) will be extracted. Must exist. data (bytes): tar data to be extracted Returns: (bool): True if the call succeeds. Raises: :py:class:`~docker.errors.APIError` If an error occurs.
codesearchnet
def __fetch_route53_zone_records(self, zone_id): route53 = self.session.client('route53') done = False nextName = nextType = None records = {} try: while not done: if nextName and nextType: response = route53.list_resourc...
Return all resource records for a specific Route53 zone Args: zone_id (`str`): Name / ID of the hosted zone Returns: `dict`
juraj-google-style
def __sweeten(self, dumper: 'Dumper', class_: Type, node: Node) -> None: for base_class in class_.__bases__: if base_class in dumper.yaml_representers: logger.debug('Sweetening for class {}'.format( self.class_.__name__)) self.__sweeten(du...
Applies the user's yatiml_sweeten() function(s), if any. Sweetening is done for the base classes first, then for the \ derived classes, down the hierarchy to the class we're \ constructing. Args: dumper: The dumper that is dumping this object. class_: The type of the object to be dumped. represented_object: The objec...
juraj-google-style
def get_node_list(self) -> list: nodes = [] if (not self._manager): raise RuntimeError('Only the Swarm manager node can retrieve all the nodes.') node_list = self._client.nodes.list() for n_list in node_list: nodes.append(n_list.id) return nodes
Get a list of nodes. Only the manager nodes can retrieve all the nodes Returns: list, all the ids of the nodes in swarm
codesearchnet
def _create_single_feature_method(feature): fx_name = feature.name.lower() if "detection" in fx_name: fx_doc = "Perform {0}.".format(fx_name.replace("_", " ")) else: fx_doc = "Return {desc} information.".format(desc=fx_name.replace("_", " ")) fx_doc += fea...
Return a function that will detect a single feature. Args: feature (enum): A specific feature defined as a member of :class:`~enums.Feature.Type`. Returns: function: A helper function to detect just that feature.
juraj-google-style
def log_warning(self, msg): if self.__logger: self.__logger.warning(msg) if self.__raise_exception_on_warning: raise RuntimeError(msg)
Log a warning if ``logger`` exists. Args: msg: Warning to log. Warning: Can raise a ``RuntimeError`` if this was asked in the constructor.
juraj-google-style
def save_aggregate_reports_to_kafka(self, aggregate_reports, aggregate_topic): if ((type(aggregate_reports) == dict) or (type(aggregate_reports) == OrderedDict)): aggregate_reports = [aggregate_reports] if (len(aggregate_reports) < 1): return for report in aggregate_reports: report['...
Saves aggregate DMARC reports to Kafka Args: aggregate_reports (list): A list of aggregate report dictionaries to save to Kafka aggregate_topic (str): The name of the Kafka topic
codesearchnet
def weCanCheckTheseDomains(email): notWorking = ['@aol.com', '@bk.ru', '@breakthru.com', '@gmx.', '@hotmail.co', '@inbox.com', '@latinmail.com', '@libero.it', '@mail.ru', '@mail2tor.com', '@outlook.com', '@rambler.ru', '@rocketmail.com', '@starmedia.com', '@ukr.net@yahoo.', '@ymail.'] for n in notWorking: ...
Method that verifies if a domain can be safely verified. Args: ----- email: the email whose domain will be verified. Returns: -------- bool: it represents whether the domain can be verified.
codesearchnet
def new_cells(self, name=None, formula=None): return self._impl.new_cells(name, formula).interface
Create a cells in the space. Args: name: If omitted, the model is named automatically ``CellsN``, where ``N`` is an available number. func: The function to define the formula of the cells. Returns: The new cells.
codesearchnet
def get_attr_info(binary_view): global _ATTR_BASIC (attr_type, attr_len, non_resident) = _ATTR_BASIC.unpack(binary_view[:9]) return (AttrTypes(attr_type), attr_len, bool(non_resident))
Gets basic information from a binary stream to allow correct processing of the attribute header. This function allows the interpretation of the Attribute type, attribute length and if the attribute is non resident. Args: binary_view (memoryview of bytearray) - A binary stream with the information of the attribute Re...
codesearchnet
def get_namespaces(start=None, end=None): q = Namespace.query() if start is not None: q = q.filter(Namespace.key >= Namespace.key_for_namespace(start)) if end is not None: q = q.filter(Namespace.key < Namespace.key_for_namespace(end)) return [x.namespace_name for x in q]
Return all namespaces in the specified range. Args: start: only return namespaces >= start if start is not None. end: only return namespaces < end if end is not None. Returns: A list of namespace names between the (optional) start and end values.
juraj-google-style
def create_submission(self, user_id, institute_id): submission_obj = { 'status' : 'open', 'created_at' : datetime.now(), 'user_id' : user_id, 'institute_id' : institute_id } LOG.info("Creating a new clinvar submission for user '%s' and in...
Create an open clinvar submission for a user and an institute Args: user_id(str): a user ID institute_id(str): an institute ID returns: submission(obj): an open clinvar submission object
juraj-google-style
def expand_source_files(filenames, cwd=None): out = [] for f in expand_paths(filenames, cwd): if os.path.isdir(f): out += collect_files(f, '.py') elif f.endswith('.py'): out.append(f) return sorted(set(out))
Expand a list of filenames passed in as sources. This is a helper function for handling command line arguments that specify a list of source files and directories. Any directories in filenames will be scanned recursively for .py files. Any files that do not end with ".py" will be dropped. Args: filenames: A list of ...
codesearchnet
def format_page(text): width = max(map(len, text.splitlines())) page = "+-" + "-" * width + "-+\n" for line in text.splitlines(): page += "| " + line.ljust(width) + " |\n" page += "+-" + "-" * width + "-+\n" return page
Format the text for output adding ASCII frame around the text. Args: text (str): Text that needs to be formatted. Returns: str: Formatted string.
juraj-google-style
def assert_title(self, title, **kwargs): query = TitleQuery(title, **kwargs) @self.synchronize(wait=query.wait) def assert_title(): if (not query.resolves_for(self)): raise ExpectationNotMet(query.failure_message) return True return assert_title()
Asserts that the page has the given title. Args: title (str | RegexObject): The string or regex that the title should match. **kwargs: Arbitrary keyword arguments for :class:`TitleQuery`. Returns: True Raises: ExpectationNotMet: If the assertion hasn't succeeded during the wait time.
codesearchnet
def _GetResolverHelper(cls, type_indicator): if not cls._resolver_helpers_manager: from dfvfs.resolver_helpers import manager cls._resolver_helpers_manager = manager.ResolverHelperManager return cls._resolver_helpers_manager.GetHelper(type_indicator)
Retrieves the path specification resolver helper for the specified type. Args: type_indicator (str): type indicator. Returns: ResolverHelper: a resolver helper.
juraj-google-style
def add_case(self, case, update=False): existing_case = self.case(case) if existing_case and not update: raise CaseError("Case {} already exists".format(case['case_id'])) if existing_case: self.db.case.find_one_and_replace( {'case_id': case['case_...
Add a case to the case collection If the case exists and update is False raise error. Args: db (MongoClient): A connection to the mongodb case (dict): A case dictionary update(bool): If existing case should be updated Returns: mongo_case_id(ObjectId)
juraj-google-style
def register_repeating_metric(self, metric_name, frequency, getter): l = task.LoopingCall(self._publish_repeating_metric, metric_name, getter) repeating_metric_handle = RepeatingMetricHandle(l, frequency) self._repeating_metric_handles.append(repeating_metric_handle) if self.run...
Record hits to a metric at a specified interval. Args: metric_name: The name of the metric to record with Carbon. frequency: The frequency with which to poll the getter and record the value with Carbon. getter: A function which takes no arguments and returns the value to record with Carbon. Returns: RepeatingMetricHa...
juraj-google-style
def count_true_positive(truth, recommend): tp = 0 for r in recommend: if (r in truth): tp += 1 return tp
Count number of true positives from given sets of samples. Args: truth (numpy 1d array): Set of truth samples. recommend (numpy 1d array): Ordered set of recommended samples. Returns: int: Number of true positives.
codesearchnet
def __init__(self, caller: Caller[RequestT, ResponseT], timeout: Optional[float]=DEFAULT_TIMEOUT_SECS, should_backoff: Optional[ShouldBackOff]=None, repeater: Repeater=ExponentialBackOffRepeater(), cache: Optional[Cache]=None, throttler: PreCallThrottler=DefaultThrottler()): self._caller = caller self._timeout ...
Instantiates a RequestResponseIO transform. Args: caller: an implementation of `Caller` object that makes call to the API. timeout (float): timeout value in seconds to wait for response from API. should_backoff: (Optional) provides methods for backoff. repeater: provides method to repeat failed requests to API due to ...
github-repos
def _call_with_flat_signature(self, args, kwargs): if len(args) > self._num_positional_args: raise TypeError(f'{self._flat_signature_summary()} takes {self._num_positional_args} positional arguments, got {len(args)}.') args = list(args) kwargs = dict(kwargs) kwargs = {function_type_lib.sanitize_...
Executes the wrapped function with the flat signature. Args: args: Positional arguments to the concrete function. kwargs: Keyword arguments to the concrete function. Returns: The result of applying the function on the Tensors/Variables contained in `args` and `kwargs`. Raises: TypeError: if `args` and `kwargs` do not...
github-repos
def _CompareFwdValues(self, tensor_in_sizes, filter_in_sizes, conv_strides, padding): x1 = np.random.rand(*tensor_in_sizes).astype(np.float32) x2 = np.random.rand(*filter_in_sizes).astype(np.float32) def _setup_val(data_format, use_gpu): with test_util.device(use_gpu): t1 = constant_op....
Verifies that CPU and GPU produce the same values. Args: tensor_in_sizes: Input tensor dimensions in [batch, input_rows, input_cols, input_depth]. filter_in_sizes: Filter tensor dimensions in [kernel_rows, kernel_cols, input_depth, output_depth]. conv_strides: [row_stride, col_stride] for the convolution; padding: Pad...
github-repos
def _ScanVolumeSystemRootNode(self, scan_context, scan_node, auto_recurse=True): if (scan_node.type_indicator == definitions.TYPE_INDICATOR_VSHADOW): path_spec = self.ScanForFileSystem(scan_node.path_spec.parent) if path_spec: scan_context.AddScanNode(path_spec, scan_node.parent_node) ...
Scans a volume system root node for supported formats. Args: scan_context (SourceScannerContext): source scanner context. scan_node (SourceScanNode): source scan node. auto_recurse (Optional[bool]): True if the scan should automatically recurse as far as possible. Raises: ValueError: if the scan context or scan node ...
codesearchnet
def concatenate(xs, axis=0): if any_symbolic_tensors(xs): return Concatenate(axis=axis).symbolic_call(xs) return backend.numpy.concatenate(xs, axis=axis)
Join a sequence of tensors along an existing axis. Args: xs: The sequence of tensors to concatenate. axis: The axis along which the tensors will be joined. Defaults to `0`. Returns: The concatenated tensor.
github-repos
def impersonate(self, user, enterprise): if not user or not enterprise: raise ValueError('You must set a user name and an enterprise name to begin impersonification') self._is_impersonating = True self._impersonation = "%s@%s" % (user, enterprise)
Impersonate a user in a enterprise Args: user: the name of the user to impersonate enterprise: the name of the enterprise where to use impersonation
juraj-google-style
def run(self, inputs=None, warmup_iterations: int=10, benchmark_iterations: int=100, enable_gpu: bool=True) -> TestResult:
Runs the model with provided or randomly generated input tensors. Args: inputs: Mapping from names to input ndarrays in TF1, or a sequence of tensors in TF2. If `None`, ramdomly generated inputs will be used instead. warmup_iterations: Number of inferences to warm up the runtime. benchmark_iterations: Number of infere...
github-repos
def _HandleMetadataUpdate(self, metadata_key='', recursive=True, wait=True, timeout=None, retry=True): exception = None while True: try: return self._GetMetadataUpdate(metadata_key=metadata_key, recursive=recursive, wait=wait, timeout=timeout) except (httpclient.HTTPException, socket...
Wait for a successful metadata response. Args: metadata_key: string, the metadata key to watch for changes. recursive: bool, True if we should recursively watch for metadata changes. wait: bool, True if we should wait for a metadata change. timeout: int, timeout in seconds for returning metadata output. retry: bool, T...
codesearchnet
def is_dir(self, follow_symlinks=True): try: return (self._system.isdir( path=self._path, client_kwargs=self._client_kwargs, virtual_dir=False) or bool(S_ISDIR(self.stat().st_mode))) except ObjectPer...
Return True if this entry is a directory or a symbolic link pointing to a directory; return False if the entry is or points to any other kind of file, or if it doesn’t exist anymore. The result is cached on the os.DirEntry object. Args: follow_symlinks (bool): Follow symlinks. Not supported on cloud storage objects. ...
juraj-google-style
def find_elements_by_class(self, class_, update=False) -> Elements: return self.find_elements(by=By.CLASS, value=class_, update=update)
Finds multiple elements by class. Args: class_: The class of the elements to be found. update: If the interface has changed, this option should be True. Returns: A list with elements if any was found. An empty list if not. Raises: NoSuchElementException - If the element wasn't found. Usage: elements = driver.find_e...
juraj-google-style
def prob(self, value, name='prob'): return self._call_prob(value, name)
Probability density/mass function. Args: value: `float` or `double` `Tensor`. name: Python `str` prepended to names of ops created by this function. Returns: prob: a `Tensor` of shape `sample_shape(x) + self.batch_shape` with values of type `self.dtype`.
github-repos
def SetServerInformation(self, server, port): self._host = server self._port = port
Sets the server information. Args: server (str): hostname or IP address of the database server. port (int): port number of the database server.
codesearchnet
def has_unitary(val: Any) -> bool: from cirq.protocols.decompose import decompose_once, decompose_once_with_qubits from cirq import Gate, Operation, LineQubit getter = getattr(val, '_has_unitary_', None) result = (NotImplemented if (getter is None) else getter()) if (result is not NotImplemented): ...
Returns whether the value has a unitary matrix representation. Returns: If `val` has a _has_unitary_ method and its result is not NotImplemented, that result is returned. Otherwise, if `val` is a cirq.Gate or cirq.Operation, a decomposition is attempted and the resulting unitary is returned if has_unitary is True for ...
codesearchnet
def __ge__(self, other): if self.index_type is not None: expr = grizzly_impl.get_field(self.expr, 1) else: expr = self.expr return SeriesWeld( grizzly_impl.compare( expr, other, ">=", sel...
Summary Args: other (TYPE): Description Returns: TYPE: Description
juraj-google-style
def __init__(self, window_fn, main_receivers, tagged_receivers, per_element_output_counter, output_batch_converter, process_yields_batches, process_batch_yields_elements): self.window_fn = window_fn self.main_receivers = main_receivers self.tagged_receivers = tagged_receivers if per_element_output_count...
Initializes ``_OutputHandler``. Args: window_fn: a windowing function (WindowFn). main_receivers: a dict of tag name to Receiver objects. tagged_receivers: main receiver object. per_element_output_counter: per_element_output_counter of one work_item. could be none if experimental flag turn off
github-repos
def normpath(self, path): path = self.normcase(path) (drive, path) = self.splitdrive(path) sep = self._path_separator(path) is_absolute_path = path.startswith(sep) path_components = path.split(sep) collapsed_path_components = [] dot = self._matching_string(path, '.') dotdot = self._match...
Mimic os.path.normpath using the specified path_separator. Mimics os.path.normpath using the path_separator that was specified for this FakeFilesystem. Normalizes the path, but unlike the method absnormpath, does not make it absolute. Eliminates dot components (. and ..) and combines repeated path separators (//). I...
codesearchnet
def load_from_file(filepath, format_=FileFormat.py, update_data_callback=None, disable_memcache=False): filepath = os.path.realpath(filepath) cache_filepath = file_cache.get(filepath) if cache_filepath: return _load_file(filepath=cache_filepath, ...
Load data from a file. Note: Any functions from a .py file will be converted to `SourceCode` objects. Args: filepath (str): File to load. format_ (`FileFormat`): Format of file contents. update_data_callback (callable): Used to change data before it is returned or cached. disable_memcache (bool): If True, don't r/w t...
juraj-google-style
def package_in_memory(cls, workflow_name, workflow_files): s = StringIO() p = cls(s, workflow_name, meta_data=[]) p.add_bpmn_files_by_glob(workflow_files) p.create_package() return s.getvalue()
Generates wf packages from workflow diagrams. Args: workflow_name: Name of wf workflow_files: Diagram file. Returns: Workflow package (file like) object
codesearchnet
def find_call(self, path, method): if not path.endswith('/'): path += '/' path = path.split('/')[1:] return self._recursive_route_match(self._routes, path, method, [])
Find callable for the specified URL path and HTTP method. Args: path (:obj:`str`): URL path to match method (:obj:`str`): HTTP method Note: A trailing '/' is always assumed in the path.
juraj-google-style
def get_path_from_query_string(req): if (req.args.get('path') is None): raise exceptions.UserError('Path not found in query string') return req.args.get('path')
Gets path from query string Args: req (flask.request): Request object from Flask Returns: path (str): Value of "path" parameter from query string Raises: exceptions.UserError: If "path" is not found in query string
codesearchnet
def _shapes(tensor_list_list, shapes, enqueue_many): if shapes is None: len0 = len(tensor_list_list[0]) for tl in tensor_list_list: for i in range(len0): if tl[i].shape.ndims is None: raise ValueError("Cannot infer Tensor's rank: %s" % tl[i]) s...
Calculate and merge the shapes of incoming tensors. Args: tensor_list_list: List of tensor lists. shapes: List of shape tuples corresponding to tensors within the lists. enqueue_many: Boolean describing whether shapes will be enqueued as batches or individual entries. Returns: A list of shapes aggregating shape infer...
github-repos
def _get_access_from_refresh(self) -> Tuple[str, float]: headers = self._get_authorization_headers() data = { 'grant_type': 'refresh_token', 'refresh_token': self.refresh_token } r = self.session.post(self.TOKEN_URL, headers=headers, data=data) re...
Uses the stored refresh token to get a new access token. This method assumes that the refresh token exists. Args: None Returns: new access token and expiration time (from now)
juraj-google-style
def __init__(self, message, exc=None): super(WorkerError, self).__init__() self.msg = message self.exc = exc
Initializes WorkerError. Args: message: error message exc: optional underlying exception.
juraj-google-style
def _emit_with_loc(self, op_str, node=None): loc = '' if node: loc = self._create_mlir_loc(anno.getanno(node, anno.Basic.ORIGIN, default=None)) self.emit(op_str + ' ' + loc)
Emit the mlir operation with the location associated with the node. Args: op_str: The mlir operation string to be emitted. node: The node of the AST tree, the mlir operation translated from.
github-repos
def balance(self, as_of=None, raw=False, leg_query=None, **kwargs): balances = [account.simple_balance(as_of=as_of, raw=raw, leg_query=leg_query, **kwargs) for account in self.get_descendants(include_self=True)] return sum(balances, Balance())
Get the balance for this account, including child accounts Args: as_of (Date): Only include transactions on or before this date raw (bool): If true the returned balance should not have its sign adjusted for display purposes. kwargs (dict): Will be used to filter the transaction legs Returns: Balance See Also: :meth:...
codesearchnet
def snyder_ac(self, structure): nsites = structure.num_sites volume = structure.volume natoms = structure.composition.num_atoms num_density = 1e30 * nsites / volume tot_mass = sum([e.atomic_mass for e in structure.species]) avg_mass = 1.6605e-27 * tot_mass / nato...
Calculates Snyder's acoustic sound velocity (in SI units) Args: structure: pymatgen structure object Returns: Snyder's acoustic sound velocity (in SI units)
juraj-google-style
def error_messages(self, driver_id=None): if (driver_id is not None): assert isinstance(driver_id, ray.DriverID) return self._error_messages(driver_id) error_table_keys = self.redis_client.keys((ray.gcs_utils.TablePrefix_ERROR_INFO_string + '*')) driver_ids = [key[len(ray.gcs_utils.TablePref...
Get the error messages for all drivers or a specific driver. Args: driver_id: The specific driver to get the errors for. If this is None, then this method retrieves the errors for all drivers. Returns: A dictionary mapping driver ID to a list of the error messages for that driver.
codesearchnet
def ms_to_times(ms): ms = int(round(ms)) h, ms = divmod(ms, 3600000) m, ms = divmod(ms, 60000) s, ms = divmod(ms, 1000) return Times(h, m, s, ms)
Convert milliseconds to normalized tuple (h, m, s, ms). Arguments: ms: Number of milliseconds (may be int, float or other numeric class). Should be non-negative. Returns: Named tuple (h, m, s, ms) of ints. Invariants: ``ms in range(1000) and s in range(60) and m in range(60)``
juraj-google-style
def json(self, ondemand=False): self._request_entity = 'indicator' self._request_uri = '{}/{}'.format(self._api_uri, 'json') self._stream = True if ondemand: self._request.add_payload('runNow', True)
Update request URI to return JSON data. For onDemand bulk generation to work it must first be enabled in the ThreatConnect platform under System settings. Args: ondemand (boolean): Enable on demand bulk generation.
codesearchnet
def add(self, obj): if not isinstance(obj, dict): raise TypeError("Add object should be a dict object") obj = self.validation(obj) obj["id"] = self.maxId + 1 obj = self._cast_model(obj) self.model.db.append(obj) if not self._batch.enable.is_set(): ...
Add a object Args: Object: Object will be added Returns: Object: Object with id Raises: TypeError: If add object is not a dict MultipleInvalid: If input object is invaild
juraj-google-style
def infer_from_frame_stack(self, ob_stack): logits, vf = self.sess.run([self.logits_t, self.value_function_t], feed_dict={self.obs_t: ob_stack}) return logits, vf
Infer policy from stack of observations. Args: ob_stack: array of shape (1, frame_stack_size, height, width, channels) Returns: logits and vf.
juraj-google-style
def get_batch_strategy_instance(strategy, splitter): if strategy == 'SingleRecord': return SingleRecordStrategy(splitter) elif strategy == 'MultiRecord': return MultiRecordStrategy(splitter) else: raise ValueError('Invalid Batch Strategy: %s - Valid Strategies: "SingleRecord", "...
Return an Instance of :class:`sagemaker.local.data.BatchStrategy` according to `strategy` Args: strategy (str): Either 'SingleRecord' or 'MultiRecord' splitter (:class:`sagemaker.local.data.Splitter): splitter to get the data from. Returns :class:`sagemaker.local.data.BatchStrategy`: an Instance of a BatchStrategy
juraj-google-style
def get_meshes_fld(step, var): fld = step.fields[var] if step.geom.twod_xz: xmesh, ymesh = step.geom.x_mesh[:, 0, :], step.geom.z_mesh[:, 0, :] fld = fld[:, 0, :, 0] elif step.geom.cartesian and step.geom.twod_yz: xmesh, ymesh = step.geom.y_mesh[0, :, :], step.geom.z_mesh[0, :, ...
Return scalar field along with coordinates meshes. Only works properly in 2D geometry. Args: step (:class:`~stagpy.stagyydata._Step`): a step of a StagyyData instance. var (str): scalar field name. Returns: tuple of :class:`numpy.array`: xmesh, ymesh, fld 2D arrays containing respectively the x position, y position, ...
juraj-google-style
def __del__(self): if self._initialized: if self.connected(): if self.swo_enabled(): self.swo_stop() if self.opened(): self.close()
Destructor for the ``JLink`` instance. Closes the J-Link connection if one exists. Args: self (JLink): the ``JLink`` instance Returns: ``None``
juraj-google-style
def __init__(self, datastore_client, storage_client, round_name): self._datastore_client = datastore_client self._storage_client = storage_client self._round_name = round_name self._attacks = None self._targeted_attacks = None self._defenses = None
Initializes CompetitionSubmissions. Args: datastore_client: instance of CompetitionDatastoreClient storage_client: instance of CompetitionStorageClient round_name: name of the round
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 == 103) and (response.sw2 == 0)): self.use_legacy_format = True return self.I...
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.
codesearchnet
def generate_skip_gram_data_set(self, token_list): n_gram_tuple_zip = self.generate_tuple_zip(token_list, 3) skip_gram_list = [] for pre, point, post in n_gram_tuple_zip: skip_gram_list.append((point, pre)) skip_gram_list.append((point, post)) return zip(...
Generate the Skip-gram's pair. Args: token_list: The list of tokens. Returns: zip of Tuple(Training N-gram data, Target N-gram data)
juraj-google-style
def __find_incongruities(self, op, index): if len(self) == 1: return hits = [] intervals = [] if self.order == 'depth': one, two = 'base', 'top' else: one, two = 'top', 'base' for i, iv in enumerate(self[:-1]): n...
Private method. Finds gaps and overlaps in a striplog. Called by find_gaps() and find_overlaps(). Args: op (operator): ``operator.gt`` or ``operator.lt`` index (bool): If ``True``, returns indices of intervals with gaps after them. Returns: Striplog: A striplog of all the gaps. A sort of anti-striplog.
juraj-google-style
def tv_list(self, **kwargs): path = self._get_path('tv_list') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
Get the list of TV genres. Args: language: (optional) ISO 639-1 code. Returns: A dict respresentation of the JSON returned from the API.
codesearchnet
def __new__(cls, *args, **kwargs) -> Any: dynamic_evaluate_fn = get_dynamic_evaluate_fn() if dynamic_evaluate_fn is None: return super().__new__(cls) else: hyper_value = object.__new__(cls) cls.__init__(hyper_value, *args, **kwargs) return dynamic_evaluate_fn(hyper_value)
Overrides __new__ for supporting dynamic evaluation mode. Args: *args: Positional arguments passed to init the custom hyper. **kwargs: Keyword arguments passed to init the custom hyper. Returns: A dynamic evaluated value according to current `dynamic_evaluate` context.
github-repos