code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def keyDown(key, pause=None, _pause=True): if len(key) > 1: key = key.lower() _failSafeCheck() platformModule._keyDown(key) _autoPause(pause, _pause)
Performs a keyboard key press without the release. This will put that key in a held down state. NOTE: For some reason, this does not seem to cause key repeats like would happen if a keyboard key was held down on a text field. Args: key (str): The key to be pressed down. The valid names are listed in KEYBOARD_KEYS. R...
juraj-google-style
def read(self, size): now = time.time() missing_dt = self._sleep_until - now if missing_dt > 0: time.sleep(missing_dt) self._sleep_until = time.time() + self._sleep_time(size) data = (self._wavep.readframes(size) if self._wavep ...
Read bytes from the stream and block until sample rate is achieved. Args: size: number of bytes to read from the stream.
juraj-google-style
def merge_resources(resource1, resource2): merged = resource1.copy() merged.update(resource2) return merged
Updates a copy of resource1 with resource2 values and returns the merged dictionary. Args: resource1: original resource resource2: resource to update resource1 Returns: dict: merged resource
codesearchnet
def get_image_features(self, pixel_values: torch.FloatTensor, pixel_mask: Optional[torch.FloatTensor]=None, vision_feature_layer: int=-1): vision_feature_layer = vision_feature_layer if vision_feature_layer is not None else self.config.vision_feature_layer patch_attention_mask = self._create_patch_attention_mas...
Obtains image last hidden states from the vision tower and apply multimodal projection. Args: pixel_values (`torch.FloatTensor]` of shape `(batch_size, channels, height, width)`): The tensors corresponding to the input images. pixel_mask (`torch.FloatTensor]`, *optional*): The tensors corresponding to the input image ...
github-repos
def __init__(self, url, params, name=None, eta=None, countdown=None, parent=None, headers=None): self.url = url self.name = name self.eta = eta self.countdown = countdown self._headers = { ...
Init. Args: url: task url in str. params: a dict from str to str. name: task name. eta: task eta. countdown: task countdown. parent: parent entity of huge task's payload. headers: a dict of headers for the task. Raises: ValueError: when payload is too big even for datastore, or parent is not specified when payload is...
juraj-google-style
def Serialize(self, writer): self.SerializeUnsigned(writer) writer.WriteByte(1) self.Script.Serialize(writer)
Serialize full object. Args: writer (neo.IO.BinaryWriter):
juraj-google-style
def post_async(self, path, params=None): request = Post(self._get_next_id(), path, params) request.set_callback(self._q.put) future = self._dispatch_request(request) return future
Asynchronously calls a function on a child block Args: path (list): The path to post to params (dict): parameters for the call Returns: Future: as single Future that will resolve to the result
codesearchnet
def __init__(self, channel): self.BatchAnnotateImages = channel.unary_unary( "/google.cloud.vision.v1p4beta1.ImageAnnotator/BatchAnnotateImages", request_serializer=google_dot_cloud_dot_vision__v1p4beta1_dot_proto_dot_image__annotator__pb2.BatchAnnotateImagesRequest.SerializeToS...
Constructor. Args: channel: A grpc.Channel.
juraj-google-style
def verify(self, byts, sign): try: chosen_hash = c_hashes.SHA256() hasher = c_hashes.Hash(chosen_hash, default_backend()) hasher.update(byts) digest = hasher.finalize() self.publ.verify(sign, digest, ...
Verify the signature for the given bytes using the ECC public key. Args: byts (bytes): The data bytes. sign (bytes): The signature bytes. Returns: bool: True if the data was verified, False otherwise.
juraj-google-style
def get_op(self, id: str, **kwargs: str) -> dict: path = self._get_path_for_op_id(id) return self.get_path(path, kwargs)
Queries the ESI by looking up an operation id. Endpoints are cached, so calls to this method for the same op and args will return the data from the cache instead of making the API call. Args: id: operation id kwargs: data to populate the endpoint's URL variables Returns: ESI data
codesearchnet
def _UpdateSudoer(self, user, sudoer=False): if sudoer: self.logger.info('Adding user %s to the Google sudoers group.', user) command = self.gpasswd_add_cmd.format( user=user, group=self.google_sudoers_group) else: self.logger.info('Removing user %s from the Google sudoers group...
Update sudoer group membership for a Linux user account. Args: user: string, the name of the Linux user account. sudoer: bool, True if the user should be a sudoer. Returns: bool, True if user update succeeded.
juraj-google-style
def dump_values(self, with_defaults=True, dict_cls=dict, flat=False): values = dict_cls() if flat: for (str_path, item) in self.iter_items(recursive=True, key='str_path'): if item.has_value: if (with_defaults or (not item.is_default)): values[str_path] = i...
Export values of all items contained in this section to a dictionary. Items with no values set (and no defaults set if ``with_defaults=True``) will be excluded. Returns: dict: A dictionary of key-value pairs, where for sections values are dictionaries of their contents.
codesearchnet
def get_boards(self, **query_params): boards = self.get_boards_json(self.base_uri, query_params=query_params) boards_list = [] for board_json in boards: boards_list.append(self.create_board(board_json)) return boards_list
Get all the boards for this organisation. Returns a list of Board s. Returns: list(Board): The boards attached to this organisation
codesearchnet
def find_file_in_load_dirs(relpath): if relpath.startswith(os.path.sep): relpath = relpath.lstrip(os.path.sep) for ld in settings.DATA_DIRECTORIES: possible_path = os.path.join(ld, relpath) if os.path.exists(possible_path): return possible_path
If given relative path exists in one of DevAssistant load paths, return its full path. Args: relpath: a relative path, e.g. "assitants/crt/test.yaml" Returns: absolute path of the file, e.g. "/home/x/.devassistant/assistanta/crt/test.yaml or None if file is not found
codesearchnet
def execute_rex_code(self, code, filename=None, shell=None, parent_environ=None, **Popen_args): def _actions_callback(executor): executor.execute_code(code, filename=filename) return self.execute_shell(shell=shell, parent_environ=parent_environ, command='', block=False, actions_callback=_actions_callba...
Run some rex code in the context. Note: This is just a convenience form of `execute_shell`. Args: code (str): Rex code to execute. filename (str): Filename to report if there are syntax errors. shell: Shell type, for eg 'bash'. If None, the current shell type is used. parent_environ: Environment to run the shell proc...
codesearchnet
def retry(self, **kwargs): path = ('%s/%s/retry' % (self.manager.path, self.get_id())) self.manager.gitlab.http_post(path)
Retry the job. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabJobRetryError: If the job could not be retried
codesearchnet
def build_graph(path, term_depth=1000, skim_depth=10, d_weights=False, **kwargs): click.echo('\nTokenizing text...') t = Text.from_file(path) click.echo('Extracted %d tokens' % len(t.tokens)) m = Matrix() click.echo('\nIndexing terms:') m.index(t, t.most_freque...
Tokenize a text, index a term matrix, and build out a graph. Args: path (str): The file path. term_depth (int): Consider the N most frequent terms. skim_depth (int): Connect each word to the N closest siblings. d_weights (bool): If true, give "close" nodes low weights. Returns: Skimmer: The indexed graph.
juraj-google-style
def MakeSelfExtractingZip(self, payload_data, output_path): context = (self.context + ['Client Context']) src_zip = zipfile.ZipFile(io.BytesIO(payload_data), mode='r') zip_data = io.BytesIO() output_zip = zipfile.ZipFile(zip_data, mode='w', compression=zipfile.ZIP_DEFLATED) config_file_name = config...
Repack the installer into the payload. Args: payload_data: data payload for zip file output_path: filename for the zip output Raises: RuntimeError: if the ClientBuilder.unzipsfx_stub doesn't require admin. Returns: output_path: filename string of zip output file
codesearchnet
def combine_heads(self, x): with tf.name_scope('combine_heads'): batch_size = tf.shape(x)[0] length = tf.shape(x)[2] x = tf.transpose(x, [0, 2, 1, 3]) return tf.reshape(x, [batch_size, length, self.hidden_size])
Combine tensor that has been split. Args: x: A tensor [batch_size, num_heads, length, hidden_size/num_heads] Returns: A tensor with shape [batch_size, length, hidden_size]
codesearchnet
def connect_async(self, connection_id, connection_string, callback): if callback is not None: callback(connection_id, self.id, False, "connect command is not supported in device adapter")
Asynchronously connect to a device Args: connection_id (int): A unique identifier that will refer to this connection connection_string (string): A DeviceAdapter specific string that can be used to connect to a device using this DeviceAdapter. callback (callable): A function that will be called when the connection atte...
juraj-google-style
def pack_eager_tensors(self, tensors): self.ensure_initialized() return pywrap_tfe.TFE_Py_PackEagerTensors(self._handle, tensors)
Pack multiple `EagerTensor`s of the same dtype and shape. Args: tensors: a list of EagerTensors to pack. Returns: A packed EagerTensor.
github-repos
def objects_delete(self, bucket, key): url = (Api._ENDPOINT + (Api._OBJECT_PATH % (bucket, Api._escape_key(key)))) datalab.utils.Http.request(url, method='DELETE', credentials=self._credentials, raw_response=True)
Deletes the specified object. Args: bucket: the name of the bucket. key: the key of the object within the bucket. Raises: Exception if there is an error performing the operation.
codesearchnet
def configure(self, sbi_config: str): config_dict = json.loads(sbi_config) self.debug_stream('SBI configuration:\n%s', json.dumps(config_dict, indent=2)) try: sbi = Subarray(self.get_name()).configure_sbi(config_dict) except jsonschema.exceptions.ValidationError as error: return json.dum...
Configure an SBI for this subarray. Args: sbi_config (str): SBI configuration JSON Returns: str,
codesearchnet
def prod(x, axis=None, keepdims=False, dtype=None): if any_symbolic_tensors((x,)): return Prod(axis=axis, keepdims=keepdims, dtype=dtype).symbolic_call(x) return backend.numpy.prod(x, axis=axis, keepdims=keepdims, dtype=dtype)
Return the product of tensor elements over a given axis. Args: x: Input tensor. axis: Axis or axes along which a product is performed. The default, `axis=None`, will compute the product of all elements in the input tensor. keepdims: If this is set to `True`, the axes which are reduce are left in the result as dimensio...
github-repos
def _make_model_class(message_type, indexed_fields, **props): analyzed = _analyze_indexed_fields(indexed_fields) for (field_name, sub_fields) in analyzed.iteritems(): if (field_name in props): raise ValueError(('field name %s is reserved' % field_name)) try: field = messa...
Construct a Model subclass corresponding to a Message subclass. Args: message_type: A Message subclass. indexed_fields: A list of dotted and undotted field names. **props: Additional properties with which to seed the class. Returns: A Model subclass whose properties correspond to those fields of message_type whose fi...
codesearchnet
def _update_annotations(discretized_pulse: Callable) -> Callable: undecorated_annotations = list(discretized_pulse.__annotations__.items()) decorated_annotations = undecorated_annotations[1:] decorated_annotations.insert(0, ('duration', int)) discretized_pulse.__annotations__ = dict(decorated_annot...
Update annotations of discretized continuous pulse function with duration. Args: discretized_pulse: Discretized decorated continuous pulse.
juraj-google-style
def setNetworkKey(self, key): masterKey = '' print '%s call setNetworkKey' % self.port try: if not isinstance(key, str): masterKey = self.__convertLongToString(key) if len(masterKey) < 32: masterKey = mas...
set Thread Network master key Args: key: Thread Network master key used in secure the MLE/802.15.4 packet Returns: True: successful to set the Thread Network master key False: fail to set the Thread Network master key
juraj-google-style
def markdown_to_text(body): md = markdown.markdown(body, extensions=['markdown.extensions.extra']) soup = BeautifulSoup(md, 'html.parser') return soup.get_text()
Converts markdown to text. Args: body: markdown (or plaintext, or maybe HTML) input Returns: Plaintext with all tags and frills removed
codesearchnet
def intraday(ticker, dt, session='', **kwargs) -> pd.DataFrame: from xbbg.core import intervals cur_data = bdib(ticker=ticker, dt=dt, typ=kwargs.get('typ', 'TRADE')) if cur_data.empty: return pd.DataFrame() fmt = '%H:%M:%S' ss = intervals.SessNA ref = kwargs.get('ref', None) exch = (...
Bloomberg intraday bar data within market session Args: ticker: ticker dt: date session: examples include day_open_30, am_normal_30_30, day_close_30, allday_exact_0930_1000 **kwargs: ref: reference ticker or exchange for timezone keep_tz: if keep tz if reference ticker / exchange is given start_time: start time end_ti...
codesearchnet
def pop(self, identifier, default=None): if (identifier in self.children): item = self[identifier] self.__delitem__(identifier) return item else: return default
Pop a node of the AttrTree using its path string. Args: identifier: Path string of the node to return default: Value to return if no node is found Returns: The node that was removed from the AttrTree
codesearchnet
def get_index(self, prefix=''): if prefix: prefixed = ('%s_index' % prefix) else: prefixed = 'index' if ((prefixed in self.__cli) and self.__cli[prefixed]): index = self.__cli.get(prefixed) from_conf = False else: index = self.__config.get(prefixed) from_c...
Retrieve the absolute path to an index, according to `prefix`. Args: prefix: str, the desired prefix or `None`. Returns: str: An absolute path, or `None`
codesearchnet
def _get_no_split_modules(self, device_map: str): _no_split_modules = set() modules_to_check = [self] while len(modules_to_check) > 0: module = modules_to_check.pop(-1) if module.__class__.__name__ not in _no_split_modules: if isinstance(module, PreTrainedModel): ...
Get the modules of the model that should not be spit when using device_map. We iterate through the modules to get the underlying `_no_split_modules`. Args: device_map (`str`): The device map value. Options are ["auto", "balanced", "balanced_low_0", "sequential"] Returns: `List[str]`: List of modules that should not b...
github-repos
def submodules(self): return tuple(self._flatten(predicate=_is_module))
Sequence of all sub-modules. Submodules are modules which are properties of this module, or found as properties of modules which are properties of this module (and so on). >>> a = tf.Module() >>> b = tf.Module() >>> c = tf.Module() >>> a.b = b >>> b.c = c >>> list(a.submodules) == [b, c] True >>> list(b.submodules) =...
github-repos
async def update_state(self, name, state): await self.send_command(OPERATIONS.CMD_UPDATE_STATE, {'name': name, 'new_status': state}, MESSAGES.UpdateStateResponse, timeout=5.0)
Update the state for a service. Args: name (string): The name of the service state (int): The new state of the service
juraj-google-style
def mnist_common_generator(tmp_dir, training, how_many, data_filename, label_filename, start_from=0): data_path = os.path.join(tmp_dir, data_filename) labels_path = os.path.join(...
Image generator for MNIST. Args: tmp_dir: path to temporary storage directory. training: a Boolean; if true, we use the train set, otherwise the test set. how_many: how many images and labels to generate. data_filename: file that contains features data. label_filename: file that contains labels. start_from: from which...
juraj-google-style
def __init__(self, latent_size, hidden_size): super(EncoderDynamicFactorized, self).__init__() self.latent_size = latent_size self.hidden_size = hidden_size self.dense = tf.keras.layers.Dense(hidden_size, activation=tf.nn.leaky_relu) self.output_layer = tf.keras.layers.Dense(2*latent_size)
Constructs a "factorized" encoder for `z_t`. Args: latent_size: An integer corresponding to the dimensionality of the distribution. hidden_size: Dimensionality of the affine function parameters.
juraj-google-style
def _create_hash_str(self, input_arg, output_arg, node_def): hasher = hashlib.sha1() def update_num(n): hasher.update(compat.as_bytes('%x' % n)) def update_str(s): update_num(len(s)) hasher.update(compat.as_bytes(s)) def update_strs(slist): update_num(len(slist)) ...
Creates an 8-character string unique to this input. Args: input_arg: the input_arg field of an OpDef (e.g. self._definition.signature.input_arg) output_arg: the output_arg field of an OpDef (e.g. self._definition.signature.output_arg) node_def: the node_def field of a FunctionDef (e.g. self._definition.node_def) Retu...
github-repos
def __init__(self, semantic_config: Optional[Dict]=None, coarse_acoustics_config: Optional[Dict]=None, fine_acoustics_config: Optional[Dict]=None, sample_rate=24000, codebook_size=1024, **kwargs): if semantic_config is None: semantic_config = {} logger.info('semantic_config is None. initializing the...
Class that holds a generation configuration for [`BarkModel`]. The [`BarkModel`] does not have a `generate` method, but uses this class to generate speeches with a nested [`BarkGenerationConfig`] which uses [`BarkSemanticGenerationConfig`], [`BarkCoarseGenerationConfig`], [`BarkFineGenerationConfig`]. This configurat...
github-repos
def speed_metrics(split, start_time, num_samples=None, num_steps=None, num_tokens=None): runtime = time.time() - start_time result = {f'{split}_runtime': round(runtime, 4)} if runtime == 0: return result if num_samples is not None: samples_per_second = num_samples / runtime resul...
Measure and return speed performance metrics. This function requires a time snapshot `start_time` before the operation to be measured starts and this function should be run immediately after the operation to be measured has completed. Args: - split: name to prefix metric (like train, eval, test...) - start_time: oper...
github-repos
def setModelData(self, editor, model, index): model.setData(index, editor.itemText(editor.currentIndex()))
Updates the model after changing data in the editor. Args: editor (QtGui.QComboBox): The current editor for the item. Should be a `QtGui.QComboBox` as defined in `createEditor`. model (ColumnDtypeModel): The model which holds the displayed data. index (QtCore.QModelIndex): The index of the current item of the model.
juraj-google-style
def ValidateServiceGaps(self, problems, validation_start_date, validation_end_date, service_gap_interval): if (service_gap_interval is None): return departures = self.GenerateDateTripsDeparturesList(validation_start_date, validation_end_date) first_day_without_service = validation_start_date las...
Validate consecutive dates without service in the feed. Issue a warning if it finds service gaps of at least "service_gap_interval" consecutive days in the date range [validation_start_date, last_service_date) Args: problems: The problem reporter object validation_start_date: A date object representing the date from w...
codesearchnet
def add_edge_bias(x, filter_size): x_shape = common_layers.shape_list(x) if filter_size[0] == 1 and filter_size[1] == 1: return x a = (filter_size[0] - 1) b = (filter_size[1] - 1) padding = [[0, 0], [a, a], [b, b], [0, 0]] x_bias = tf.zeros(x_shape[:-1] + [1]) x = tf.pad(x, padding) x_pad = tf...
Pad x and concatenates an edge bias across the depth of x. The edge bias can be thought of as a binary feature which is unity when the filter is being convolved over an edge and zero otherwise. Args: x: Input tensor, shape (NHWC) filter_size: filter_size to determine padding. Returns: x_pad: Input tensor, shape (NHW(...
juraj-google-style
def generate_states(state_count, process_matrix, process_covariance, initial_state=None): process_matrix = np.atleast_2d(process_matrix) process_covariance = np.atleast_2d(process_covariance) state_dim = process_matrix.shape[0] if (process_matrix.shape != (state_dim, state_dim)): raise ValueErro...
Generate states by simulating a linear system with constant process matrix and process noise covariance. Args: state_count (int): Number of states to generate. process_matrix (array): Square array process_covariance (array): Square array specifying process noise covariance. initial_state (array or None): If omitted, u...
codesearchnet
def curie_search(self, curie:str) -> dict: ilx_row = self.curie2row.get(curie) if not ilx_row: return None else: return ilx_row
Returns the row in InterLex associated with the curie Note: Pressumed to not have duplicate curies in InterLex Args: curie: The "prefix:fragment_id" of the existing_id pertaining to the ontology Returns: None or dict
juraj-google-style
def generate_code(max_length, max_nest, ops): stack = [] def fetch_one(): if stack: return stack.pop() else: value = random.randint(10 ** (max_length - 1), 10 ** max_length - 1) code = str(value) return value, code def fetch(num_operands): values, codes = zip(*[...
Generates code samples. Args: max_length: int. max literal length. max_nest: int. max nesting level. ops: CodeOp. set of allowable operations. Returns: 1. (str) output value. 2. (str) Code operation.
juraj-google-style
def read_committed_file(gitref, filename): repo = Repo() commitobj = repo.commit(gitref) blob = commitobj.tree[(_delta_dir() + filename)] return blob.data_stream.read()
Retrieve the content of a file in an old commit and returns it. Ketword Arguments: :gitref: (str) -- full reference of the git commit :filename: (str) -- name (full path) of the file Returns: str -- content of the file
codesearchnet
def get_records(self, name): if (name in self._cache): return self._cache[name].values() else: return []
Return all the records for the given name in the cache. Args: name (string): The name which the required models are stored under. Returns: list: A list of :class:`cinder_data.model.CinderModel` models.
codesearchnet
def _get_storage_model(): storage_model_settings = getattr(django.conf.settings, 'GOOGLE_OAUTH2_STORAGE_MODEL', None) if (storage_model_settings is not None): return (storage_model_settings['model'], storage_model_settings['user_property'], storage_model_settings['credentials_property']) else: ...
This configures whether the credentials will be stored in the session or the Django ORM based on the settings. By default, the credentials will be stored in the session, unless `GOOGLE_OAUTH2_STORAGE_MODEL` is found in the settings. Usually, the ORM storage is used to integrate credentials into an existing Django user ...
codesearchnet
def encode_json_body(data): if hasattr(data, "read"): return data response.content_type = "application/json; charset=utf-8" return json.dumps( data, indent=4, separators=(',', ': ') )
Return prettified JSON `data`, set ``response.content_type`` to ``application/json; charset=utf-8``. Args: data (any): Any basic python data structure. Returns: str: Data converted to prettified JSON.
juraj-google-style
def GetEntries(self, parser_mediator, match=None, **unused_kwargs): if ('RememberedNetworks' not in match): return for wifi in match['RememberedNetworks']: ssid = wifi.get('SSIDString', 'UNKNOWN_SSID') security_type = wifi.get('SecurityType', 'UNKNOWN_SECURITY_TYPE') event_data =...
Extracts relevant Airport entries. Args: parser_mediator (ParserMediator): mediates interactions between parsers and other components, such as storage and dfvfs. match (Optional[dict[str: object]]): keys extracted from PLIST_KEYS.
codesearchnet
def list_offers(access_token, subscription_id, location, publisher): endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/providers/Microsoft.Compute/', 'locations/', location, '/publishers/', publisher, '/artifacttypes/vmimage/offers?api-version=', COMP_API]) return do_get(endpoint, acc...
List available VM image offers from a publisher. Args: access_token (str): A valid Azure authentication token. subscription_id (str): Azure subscription id. location (str): Azure data center location. E.g. westus. publisher (str): Publisher name, e.g. Canonical. Returns: HTTP response with JSON list of image offers.
codesearchnet
def _get_batch_data(self, batch_size, num_objects, num_features): all_inputs = [] all_labels = [] for _ in six.moves.range(batch_size): inputs, labels = self._get_single_set(num_objects, num_features) all_inputs += [inputs] all_labels += [labels] input_data = np.concatenate(all_in...
Assembles a batch of input tensors and output labels. Args: batch_size: int. number of sequence batches. num_objects: int. number of objects in the sequence. num_features: int. feature size of each object. Returns: 1. np.ndarray (`batch_size`, `num_objects`, (`num_features` + 3 * `num_objects`)). 2. np.ndarray (`batc...
juraj-google-style
def write_top_half(f, row_metadata_df, col_metadata_df, metadata_null, filler_null): size_of_top_half_df = (1 + col_metadata_df.shape[1], 1 + row_metadata_df.shape[1] + col_metadata_df.shape[0]) top_half_df = pd.DataFrame(np.full(size_of_top_half_df, filler_null, dtype=obje...
Write the top half of the gct file: top-left filler values, row metadata headers, and top-right column metadata. Args: f (file handle): handle for output file row_metadata_df (pandas df) col_metadata_df (pandas df) metadata_null (string): how to represent missing values in the metadata filler_null (string): what value...
juraj-google-style
def _fn(arg0, arg1, deprecated=True): return arg0 + arg1 if deprecated else arg1 + arg0
fn doc. Args: arg0: Arg 0. arg1: Arg 1. deprecated: Deprecated! Returns: Sum of args.
github-repos
def add_request(self, request): queue_item = QueueItem(request, Response(request.url)) self.add(queue_item) return queue_item
Add a request to the queue. Args: request (:class:`nyawc.http.Request`): The request to add. Returns: :class:`nyawc.QueueItem`: The created queue item.
codesearchnet
def __init__(self, options, queue_item): self.__options = options self.__queue_item = queue_item self.__queue_item.response = self.__make_request( self.__queue_item.request.url, self.__queue_item.request.method, self.__queue_item.request.data, ...
Construct the HTTP handler. Args: options (:class:`nyawc.Options`): The settins/options object. queue_item (:class:`nyawc.QueueItem`): The queue item containing the request.
juraj-google-style
def _add_result(self, dict_entry, entry, dt, start_time): time_entry = {} time_entry['dt'] = dt time_entry['start_time'] = start_time dict_entry[entry] = time_entry
Adds a result to the dictionary. Args: dict_entry: main dict to add entry entry: slot for this entry (likely an integer) dt: the timing for the entry start_time: when the entry started unix time float
juraj-google-style
def __init__(self, name, lim_low=85., lim_high=95., **kwargs): self.lim_low = lim_low self.lim_high = lim_high super(DayNightCompositor, self).__init__(name, **kwargs)
Collect custom configuration values. Args: lim_low (float): lower limit of Sun zenith angle for the blending of the given channels lim_high (float): upper limit of Sun zenith angle for the blending of the given channels
juraj-google-style
def __init__(self, parent=None): super(DelimiterSelectionWidget, self).__init__(parent) self.semicolonRadioButton = None self.commaRadioButton = None self.tabRadioButton = None self.otherRadioButton = None self.otherSeparatorLineEdit = None self._initUI()
Constructs the object with the given parent. Args: parent (QObject, optional): Causes the objected to be owned by `parent` instead of Qt. Defaults to `None`.
juraj-google-style
def get_battery_level(self): battery_level = self.get_characteristic_handle_from_uuid(UUID_BATTERY_LEVEL) if (battery_level is None): logger.warn('Failed to find handle for battery level') return None level = self.dongle._read_attribute(self.conn_handle, battery_level) if (level is None)...
Reads the battery level descriptor on the device. Returns: int. If successful this will be a positive value representing the current battery level as a percentage. On error, -1 is returned.
codesearchnet
def _get_output_tensors(self, interpreter: _interpreter.Interpreter) -> List[np.ndarray]: outputs = [] for output_detail in interpreter.get_output_details(): tensor = interpreter.get_tensor(output_detail['index']) if output_detail['dtype'] == np.int8: quant_params = _get_quant_params...
Returns output tensors of given TFLite model Interpreter. Args: interpreter: a tf.lite.Interpreter object with allocated tensors. Returns: a list of numpy arrays representing output tensor results.
github-repos
def getattr_sdk(attr, name): if inspect.isroutine(attr): if hasattr(attr, '_sdkmeta'): return attr raise AttributeError(name)
Filter SDK attributes Args: attr(attribute): Attribute as returned by :func:`getattr`. name(str): Attribute name. Returns: `attr` if passed.
codesearchnet
def _UpdateCounters(self, event): self._session.parsers_counter['total'] += 1 parser_name = getattr(event, 'parser', '') _, _, parser_name = parser_name.rpartition('/') if not parser_name: parser_name = 'N/A' self._session.parsers_counter[parser_name] += 1
Updates the counters. Args: event (EventObject): event.
juraj-google-style
def __init__(self, initializer=None): if initializer is None: self.data = [] return if isinstance(initializer, Timeseries): self.data = copy.deepcopy(initializer.data) return raise RuntimeError("Unrecognized initializer.")
Create a timeseries with an optional initializer. Args: initializer: An optional Timeseries to clone. Raises: RuntimeError: If initializer is not understood.
juraj-google-style
def put(cls, obj): return PyarrowOnRayFramePartition(ray.put(pyarrow.Table.from_pandas(obj)))
Put an object in the Plasma store and wrap it in this object. Args: obj: The object to be put. Returns: A `RayRemotePartition` object.
juraj-google-style
def dot(A, B): try: result = A.__matmul__(B) if result is NotImplemented: result = B.__rmatmul__(A) except AttributeError: result = B.__rmatmul__(A) return result
Matrix multiplication between A and B This function is equivalent to ``A @ B``, which is unfortunately not possible under python 2.x. Args: A (sequence): B (sequence): Returns: sequence:
juraj-google-style
def dframe(self, dimensions=None, multi_index=False): import pandas as pd if dimensions is None: outer_dimensions = self.kdims inner_dimensions = None else: outer_dimensions = [self.get_dimension(d) for d in dimensions ...
Convert dimension values to DataFrame. Returns a pandas dataframe of columns along each dimension, either completely flat or indexed by key dimensions. Args: dimensions: Dimensions to return as columns multi_index: Convert key dimensions to (multi-)index Returns: DataFrame of columns corresponding to each dimension
juraj-google-style
def tcp_ping( task: Task, ports: List[int], timeout: int = 2, host: Optional[str] = None ) -> Result: if isinstance(ports, int): ports = [ports] if isinstance(ports, list): if not all(isinstance(port, int) for port in ports): raise ValueError("Invalid value for 'ports'") ...
Tests connection to a tcp port and tries to establish a three way handshake. To be used for network discovery or testing. Arguments: ports (list of int): tcp ports to ping timeout (int, optional): defaults to 2 host (string, optional): defaults to ``hostname`` Returns: Result object with the following attributes set...
juraj-google-style
def formula_html(self, reversed_=False): if (self.H_count == 1): text = 'H' elif (self.H_count > 1): text = 'H<sub>{}</sub>'.format(self.H_count) else: text = '' seq = [self.symbol, text, self.charge_sign_html()] if reversed_: seq = reversed(seq) return ''.join(se...
Chemical formula HTML Args: reversed (bool): reversed text for leftmost atom groups
codesearchnet
def _add_collection_def(meta_graph_def, key, export_scope=None): meta_graph.add_collection_def(meta_graph_def, key, export_scope=export_scope)
Adds a collection to MetaGraphDef protocol buffer. Args: meta_graph_def: MetaGraphDef protocol buffer. key: One of the GraphKeys or user-defined string. export_scope: Optional `string`. Name scope to remove.
github-repos
def __getattr__(cls, item): if item in cls._meta.settings.keys(): return cls._meta.settings[item] raise AttributeError("'%s' class has no attribute '%s'" % (cls.__name__, item))
Return a setting object if it is in the ``_meta.settings`` dictionary. Args: item (str): the name of the setting variable (not the setting's name). Returns: ``Setting``: the setting object. Raises: AttributeError if the setting does not exist.
juraj-google-style
def load_img(path, grayscale=False, target_size=None): img = io.imread(path, grayscale) if target_size: img = transform.resize(img, target_size, preserve_range=True).astype('uint8') return img
Utility function to load an image from disk. Args: path: The image file path. grayscale: True to convert to grayscale image (Default value = False) target_size: (w, h) to resize. (Default value = None) Returns: The loaded numpy image.
juraj-google-style
def set_mac_addr_adv_interval(self, name, vrid, value=None, disable=False, default=False, run=True): if ((not default) and (not disable)): if ((not int(value)) or (int(value) < 1) or (int(value) > 3600)): raise ValueError("vrrp property 'mac_addr_adv_interval' must be in the range 1-3600") c...
Set the mac_addr_adv_interval property of the vrrp Args: name (string): The interface to configure. vrid (integer): The vrid number for the vrrp to be managed. value (integer): mac-address advertisement-interval value to assign to the vrrp. disable (boolean): Unset mac-address advertisement-interval if True. default (...
codesearchnet
def is_table(engine, sql): if engine.dialect.has_table(engine, sql): return True return False
Check with the given sql arg is query or table Args: engine: SQLAlchemy connection engine sql: SQL query or table name Returns: True for table or False if not
codesearchnet
def root_cause(binding, node, seen=()): if isinstance(binding, (list, tuple)): bindings = list(binding) else: bindings = [binding] del binding key = frozenset(bindings) if key in seen: return (next(iter(bindings), None), node) for b in bindings: if not node.HasCom...
Tries to determine why a binding isn't possible at a node. This tries to find the innermost source that's still impossible. It only works if the failure isn't due to a combination of bindings. Args: binding: A binding, or a list of bindings. node: The node at which (one of the) binding(s) is impossible. seen: Interna...
github-repos
def EnrolFleetspeakClient(self, client_id): client_urn = rdf_client.ClientURN(client_id) if data_store.RelationalDBEnabled(): try: data_store.REL_DB.ReadClientMetadata(client_id) return False except db.UnknownClientError: pass else: if aff4.FACTORY.Exists...
Enrols a Fleetspeak-enabled client for use with GRR. Args: client_id: GRR client-id for the client. Returns: True if the client is new, and actually got enrolled. This method is a no-op if the client already exists (in which case False is returned).
juraj-google-style
def min_sequence_length(self, dataset_split): return {problem.DatasetSplit.TRAIN: 8, problem.DatasetSplit.EVAL: 65, problem.DatasetSplit.TEST: 65}[dataset_split]
Determine the minimum sequence length given a dataset_split. Args: dataset_split: A problem.DatasetSplit. Returns: The minimum length that a sequence can be for this dataset_split.
codesearchnet
def rApply(d, f): remainingDicts = [(d, ())] while len(remainingDicts) > 0: current, prevKeys = remainingDicts.pop() for k, v in current.iteritems(): keys = prevKeys + (k,) if isinstance(v, dict): remainingDicts.insert(0, (v, keys)) else: f(v, keys)
Recursively applies f to the values in dict d. Args: d: The dict to recurse over. f: A function to apply to values in d that takes the value and a list of keys from the root of the dict to the value.
juraj-google-style
def run(self, feed_dict=None, session=None) -> None: _run_using_default_session(self, feed_dict, self.graph, session)
Runs this operation in a `Session`. Calling this method will execute all preceding operations that produce the inputs needed for this operation. *N.B.* Before invoking `Operation.run()`, its graph must have been launched in a session, and either a default session must be available, or `session` must be specified expl...
github-repos
def stop(self): self.log.debug('Stopping snippet package %s.', self.package) self.close_connection() self._stop_server() self._destroy_event_client() self.log.debug('Snippet package %s stopped.', self.package)
Releases all the resources acquired in `initialize`. This function releases following resources: * Close the socket connection. * Stop forwarding the device port to host. * Stop the standing server subprocess running on the host side. * Stop the snippet server running on the device side. * Stop the event client and se...
github-repos
def __init__(self, code, message=None, command=None): super().__init__(message) self.code = code self.command = command
Initializes a new instance of SMTPCommandFailedError. Args: code (int): Error code returned by the SMTP server. message (str): Exception message, ideally providing help for the user. command (str): Command sent to the server that originated the exception.
juraj-google-style
def run(components=None, broker=None): components = (components or COMPONENTS[GROUPS.single]) components = _determine_components(components) broker = (broker or Broker()) for component in run_order(components): start = time.time() try: if ((component not in broker) and (compo...
Executes components in an order that satisfies their dependency relationships. Keyword Args: components: Can be one of a dependency graph, a single component, a component group, or a component type. If it's anything other than a dependency graph, the appropriate graph is built for you and before evaluation. broker (Br...
codesearchnet
def create_raw(self, key, value): data = None if key is not None and value is not None: data = self.db.create(key.strip(), value) else: self.tcex.log.warning(u'The key or value field was None.') return data
Create method of CRUD operation for raw data. Args: key (string): The variable to write to the DB. value (any): The data to write to the DB. Returns: (string): Result of DB write.
juraj-google-style
def create(self, algorithm, length, operation_policy_name=None, name=None, cryptographic_usage_mask=None): if (not isinstance(algorithm, enums.CryptographicAlgorithm)): raise TypeError('algorithm must be a CryptographicAlgorithm enumeration') elif ((not isinstance(length, six.integer_types)) or (length ...
Create a symmetric key on a KMIP appliance. Args: algorithm (CryptographicAlgorithm): An enumeration defining the algorithm to use to generate the symmetric key. length (int): The length in bits for the symmetric key. operation_policy_name (string): The name of the operation policy to use for the new symmetric key. Op...
codesearchnet
def search(self, filepath=None, basedir=None, kind=None): if (filepath is None): filepath = '' if (basedir is None): basedir = '.' if ((not basedir) and (not filepath)): msg = 'Either basedir or filepath is required for discovering' raise SettingsDiscoveryError(msg) if (k...
Search for a settings file. Keyword Arguments: filepath (string): Path to a config file, either absolute or relative. If absolute set its directory as basedir (omitting given basedir argument). If relative join it to basedir. basedir (string): Directory path where to search for. kind (string): Backend engine kind name...
codesearchnet
def _parse_trunk_native_vlan(self, config): match = re.search('switchport trunk native vlan (\\d+)', config) return dict(trunk_native_vlan=match.group(1))
Scans the specified config and parse the trunk native vlan value Args: config (str): The interface configuration block to scan Returns: dict: A Python dict object with the value of switchport trunk native vlan value. The dict returned is intended to be merged into the resource dict
codesearchnet
def get_video_features(self, pixel_values_videos: torch.FloatTensor, vision_feature_layer: Optional[Union[int, List[int]]]=None): vision_feature_layer = vision_feature_layer if vision_feature_layer is not None else self.config.vision_feature_layer batch_size_vid, num_frames, channels, height, width = pixel_valu...
Obtains video last hidden states from the vision tower and apply multimodal projection. Args: pixel_values_videos (`torch.FloatTensor]` of shape `(batch_size, num_frames, channels, height, width)`) The tensors corresponding to the input videos. vision_feature_layer (`Union[int, List[int]]`, *optional*): The index of t...
github-repos
def _schema_line(args): name = args['table'] if args['table'] else args['view'] if name is None: raise Exception('No table or view specified; cannot show schema') schema = _get_schema(name) if schema: html = _repr_html_table_schema(schema) return IPython.core.display.HTML(html) else: ra...
Implements the BigQuery schema magic used to display table/view schemas. Args: args: the arguments following '%bigquery schema'. Returns: The HTML rendering for the schema.
juraj-google-style
def get_file(self, url, path_or_file=None, headers=None, filename=None): path_or_file = (path_or_file or filename) if self.debug: print(('GET FILE: %s, headers=%s' % (url, headers))) self.headers = self._get_default_headers() if (headers is not None): self.headers.update(headers) res...
Get a file from a url and save it as `filename` Args: url (str): URL to send the request to path_or_file (str or file): A writable File-like object or a path to save the file to. filename (str): [DEPRECATED] File name to save the file as, this can be either a full path or a relative path headers (str, optional): cu...
codesearchnet
def pipelines(self, **kwargs): path = '%s/%s/pipelines' % (self.manager.path, self.get_id()) return self.manager.gitlab.http_get(path, **kwargs)
List the merge request pipelines. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabListError: If the list could not be retrieved Returns: RESTObjectList: List of changes
juraj-google-style
def mount(self, app=None): for endpoint in self._routes: endpoint.register_app(app) return self
Mounts all registered routes to a bottle.py application instance. Args: app (instance): A `bottle.Bottle()` application instance. Returns: The Router instance (for chaining purposes).
codesearchnet
def get_mysql_vars(mysql: str, host: str, port: int, user: str) -> Dict[(str, str)]: cmdargs = [mysql, '-h', host, '-P', str(port), '-e', 'SHOW VARIABLES; SHOW STATUS', '-u', user, '-p'] log.info('Connecting to MySQL with user: {}', user) log.debug(cmdargs) process = subprocess.Popen(cmdargs, stdout=sub...
Asks MySQL for its variables and status. Args: mysql: ``mysql`` executable filename host: host name port: TCP/IP port number user: username Returns: dictionary of MySQL variables/values
codesearchnet
def proc_ovrds(**kwargs): return [ (k, v) for k, v in kwargs.items() if k not in list(ELEM_KEYS.keys()) + list(ELEM_KEYS.values()) + PRSV_COLS ]
Bloomberg overrides Args: **kwargs: overrides Returns: list of tuples Examples: >>> proc_ovrds(DVD_Start_Dt='20180101') [('DVD_Start_Dt', '20180101')] >>> proc_ovrds(DVD_Start_Dt='20180101', cache=True, has_date=True) [('DVD_Start_Dt', '20180101')]
juraj-google-style
def unshare(self, group_id, **kwargs): path = '/projects/%s/share/%s' % (self.get_id(), group_id) self.manager.gitlab.http_delete(path, **kwargs)
Delete a shared project link within a group. Args: group_id (int): ID of the group. **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabDeleteError: If the server failed to perform the request
juraj-google-style
def ones_like(array, dtype=None, keepmeta=True): if keepmeta: return xr.ones_like(array, dtype) else: return dc.ones(array.shape, dtype)
Create an array of ones with the same shape and type as the input array. Args: array (xarray.DataArray): The shape and data-type of it define these same attributes of the output array. dtype (data-type, optional): If spacified, this function overrides the data-type of the output array. keepmeta (bool, optional): Wheth...
codesearchnet
def initGP(self,fast=False): if fast: assert self.n_terms==2, 'CVarianceDecomposition: for fast inference number of terms must be == 2' assert self.P>1, 'CVarianceDecomposition: for fast inference number of traits must be > 1' self.vd.initGPkronSum() e...
Initialize GP objetct Args: fast: if fast==True initialize gpkronSum gp
juraj-google-style
def call_requests( requests: Union[Request, Iterable[Request]], methods: Methods, debug: bool ) -> Response: if isinstance(requests, collections.Iterable): return BatchResponse(safe_call(r, methods, debug=debug) for r in requests) return safe_call(requests, methods, debug=debug)
Takes a request or list of Requests and calls them. Args: requests: Request object, or a collection of them. methods: The list of methods that can be called. debug: Include more information in error responses.
juraj-google-style
def _bit_list_to_bytes(bit_list): num_bits = len(bit_list) byte_vals = bytearray() for start in six.moves.xrange(0, num_bits, 8): curr_bits = bit_list[start:(start + 8)] char_val = sum(((val * digit) for (val, digit) in six.moves.zip(_POW2, curr_bits))) byte_vals.append(char_val) ...
Converts an iterable of 1s and 0s to bytes. Combines the list 8 at a time, treating each group of 8 bits as a single byte. Args: bit_list (Sequence): Sequence of 1s and 0s. Returns: bytes: The decoded bytes.
codesearchnet
def _assert_splits_match(nested_splits_lists): error_msg = 'Inputs must have identical ragged splits' for splits_list in nested_splits_lists: if len(splits_list) != len(nested_splits_lists[0]): raise ValueError(error_msg) return [check_ops.assert_equal(s1, s2, message=error_msg) for spli...
Checks that the given splits lists are identical. Performs static tests to ensure that the given splits lists are identical, and returns a list of control dependency op tensors that check that they are fully identical. Args: nested_splits_lists: A list of nested_splits_lists, where each split_list is a list of `split...
github-repos
def load_fasta_file(filename): with open(filename, 'r') as handle: records = list(SeqIO.parse(handle, 'fasta')) return records
Load a FASTA file and return the sequences as a list of SeqRecords Args: filename (str): Path to the FASTA file to load Returns: list: list of all sequences in the FASTA file as Biopython SeqRecord objects
codesearchnet