code
stringlengths
51
2.38k
docstring
stringlengths
4
15.2k
def close(self): if self.is_connected: self.client.close() if self.forward_agent and self._agent_handler is not None: self._agent_handler.close()
Terminate the network connection to the remote end, if open. If no connection is open, this method does nothing. .. versionadded:: 2.0
def attach(func, params): sig = inspect.signature(func) params = Projection(sig.parameters.keys(), params) return functools.partial(func, **params)
Given a function and a namespace of possible parameters, bind any params matching the signature of the function to that function.
def request_data(key, url, file, string_content, start, end, fix_apple): data = [] try: data += events(url=url, file=file, string_content=string_content, start=start, end=end, fix_apple=fix_apple) finally: update_events(key, data) request_finished(key)
Request data, update local data cache and remove this Thread form queue. :param key: key for data source to get result later :param url: iCal URL :param file: iCal file path :param string_content: iCal content as string :param start: start date :param end: end date :param fix_apple: fix kno...
def intern(obj, timeout): core.gear.timeout = timeout core.gear.pool.append(obj)
Tell untwisted to process an extern event loop.
def text(self, prompt, default=None): prompt = prompt if prompt is not None else 'Enter some text' prompt += " [{0}]: ".format(default) if default is not None else ': ' return self.input(curry(filter_text, default=default), prompt)
Prompts the user for some text, with optional default
def reshape(self, *shape): if prod(self.shape) != prod(shape): raise ValueError("Reshaping must leave the number of elements unchanged") if self.shape[-1] != shape[-1]: raise ValueError("Reshaping cannot change the size of the constituent series (last dimension)") if self...
Reshape the Series object Cannot change the last dimension. Parameters ---------- shape: one or more ints New shape
def apply_default_constraints(self): try: self.apply_secthresh(pipeline_weaksec(self.koi)) except NoWeakSecondaryError: logging.warning('No secondary eclipse threshold set for {}'.format(self.koi)) self.set_maxrad(default_r_exclusion(self.koi))
Applies default secthresh & exclusion radius constraints
def future_set_exception_unless_cancelled( future: "Union[futures.Future[_T], Future[_T]]", exc: BaseException ) -> None: if not future.cancelled(): future.set_exception(exc) else: app_log.error("Exception after Future was cancelled", exc_info=exc)
Set the given ``exc`` as the `Future`'s exception. If the Future is already canceled, logs the exception instead. If this logging is not desired, the caller should explicitly check the state of the Future and call ``Future.set_exception`` instead of this wrapper. Avoids ``asyncio.InvalidStateError...
def image_url(self): return construct_api_url(self.input, 'image', self.resolvers, False, self.get3d, False, **self.kwargs)
URL of a GIF image.
def drop(self, *column_or_columns): exclude = _varargs_labels_as_list(column_or_columns) return self.select([c for (i, c) in enumerate(self.labels) if i not in exclude and c not in exclude])
Return a Table with only columns other than selected label or labels. Args: ``column_or_columns`` (string or list of strings): The header names or indices of the columns to be dropped. ``column_or_columns`` must be an existing header name, or a valid col...
def get_comment_collection(cmt_id): query = recid = run_sql(query, (cmt_id,)) record_primary_collection = guess_primary_collection_of_a_record( recid[0][0]) return record_primary_collection
Extract the collection where the comment is written
def sign(self, payload): if self.authenticator: return self.authenticator.signed(payload) return payload
Sign payload using the supplied authenticator
def _clean_schema_fields(self, fields): fields_sorted = sorted(fields, key=lambda field: field["name"]) return [ {"name": field["name"], "type": field["type"]} for field in fields_sorted ]
Return a sanitized version of the schema for comparisons.
def missing_db_response(func): @wraps(func) def with_exception_handling(*args, **kwargs): try: return func(*args, **kwargs) except ConnectionError as error: return (dict(error='Unable to connect to Configuration Db.', error_message=str(error), ...
Decorator to check connection exceptions
def wait(self): self.thread.join() if self.error is not None: return self.error return self.result
Wait for the request to finish and return the result or error when finished :returns: result or error :type: result tyoe or Error
def languages(self, **kwargs): path = '/projects/%s/languages' % self.get_id() return self.manager.gitlab.http_get(path, **kwargs)
Get languages used in the project with percentage value. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabGetError: If the server failed to perform the request
def pngout(ext_args): args = _PNGOUT_ARGS + [ext_args.old_filename, ext_args.new_filename] extern.run_ext(args) return _PNG_FORMAT
Run the external program pngout on the file.
def specs_to_ir(specs, version='0.1b1', debug=False, route_whitelist_filter=None): parser_factory = ParserFactory(debug=debug) partial_asts = [] for path, text in specs: logger.info('Parsing spec %s', path) parser = parser_factory.get_parser() if debug: parser.test_lexing...
Converts a collection of Stone specifications into the intermediate representation used by Stone backends. The process is: Lexer -> Parser -> Semantic Analyzer -> IR Generator. The code is structured as: 1. Parser (Lexer embedded within) 2. IR Generator (Semantic Analyzer embedded within) ...
def _alter_umask(self): if self.umask is None: yield else: prev_umask = os.umask(self.umask) try: yield finally: os.umask(prev_umask)
Temporarily alter umask to custom setting, if applicable
def remove_column(table, remove_index): for row_index in range(len(table)): old_row = table[row_index] new_row = [] for column_index in range(len(old_row)): if column_index != remove_index: new_row.append(old_row[column_index]) ...
Removes the specified column from the table.
def setTargetRange(self, targetRange, padding=None): if self.axisNumber == X_AXIS: xRange, yRange = targetRange, None else: xRange, yRange = None, targetRange self.viewBox.setRange(xRange = xRange, yRange=yRange, padding=padding, update=False...
Sets the range of the target.
def iter_items(self, depth: int = 1): if depth is not None and not isinstance(depth, int): raise TypeError def itor(root, d): if d is not None: d -= 1 if d < 0: return for name in os.listdir(root): pa...
get items from directory.
def __check_right_side_conflict(x, y, dfs_data): r = dfs_data['FG']['r'] w, z = dfs_data['RF'][r] return __check_conflict_fronds(x, y, w, z, dfs_data)
Checks to see if the frond xy will conflict with a frond on the right side of the embedding.
def maybe_coroutine(obj): if six.PY3 and asyncio.iscoroutine(obj): return defer.ensureDeferred(obj) return obj
If 'obj' is a coroutine and we're using Python3, wrap it in ensureDeferred. Otherwise return the original object. (This is to insert in all callback chains from user code, in case that user code is Python3 and used 'async def')
def get_tags(self, use_cached=True): device_json = self.get_device_json(use_cached) potential_tags = device_json.get("dpTags") if potential_tags: return list(filter(None, potential_tags.split(","))) else: return []
Get the list of tags for this device
def threeD_gridplot(nodes, **kwargs): from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt lats = [] longs = [] depths = [] for node in nodes: lats.append(float(node[0])) longs.append(float(node[1])) depths.append(float(node[2])) fig = plt.figure() ...
Plot in a series of grid points in 3D. :type nodes: list :param nodes: List of tuples of the form (lat, long, depth) :returns: :class:`matplotlib.figure.Figure` .. rubric:: Example >>> from eqcorrscan.utils.plotting import threeD_gridplot >>> nodes = [(-43.5, 170.4, 4), (-43.3, 170.8, 12), (...
def temperature(self): ut = self.get_raw_temp() x1 = ((ut - self.cal['AC6']) * self.cal['AC5']) >> 15 x2 = (self.cal['MC'] << 11) // (x1 + self.cal['MD']) b5 = x1 + x2 return ((b5 + 8) >> 4) / 10
Get the temperature from the sensor. :returns: The temperature in degree celcius as a float :example: >>> sensor = BMP180(gw) >>> sensor.load_calibration() >>> sensor.temperature() 21.4
def _save_subimports(self, code, top_level_dependencies): for x in top_level_dependencies: if isinstance(x, types.ModuleType) and hasattr(x, '__package__') and x.__package__: prefix = x.__name__ + '.' for name, module in sys.modules.items(): if nam...
Ensure de-pickler imports any package child-modules that are needed by the function
def list_adb_devices_by_usb_id(): out = adb.AdbProxy().devices(['-l']) clean_lines = new_str(out, 'utf-8').strip().split('\n') results = [] for line in clean_lines: tokens = line.strip().split() if len(tokens) > 2 and tokens[1] == 'device': results.append(tokens[2]) retur...
List the usb id of all android devices connected to the computer that are detected by adb. Returns: A list of strings that are android device usb ids. Empty if there's none.
def check_tx(self, raw_transaction): self.abort_if_abci_chain_is_not_synced() logger.debug('check_tx: %s', raw_transaction) transaction = decode_transaction(raw_transaction) if self.bigchaindb.is_valid_transaction(transaction): logger.debug('check_tx: VALID') retu...
Validate the transaction before entry into the mempool. Args: raw_tx: a raw string (in bytes) transaction.
def set_impact_state(self): cls = self.__class__ if cls.enable_problem_impacts_states_change: logger.debug("%s is impacted and goes UNREACHABLE", self) self.state_before_impact = self.state self.state_id_before_impact = self.state_id self.state_changed_sin...
We just go an impact, so we go unreachable But only if we enable this state change in the conf :return: None
def _encode_dask_array(values, uniques=None, encode=False, onehot_dtype=None): if uniques is None: if encode and onehot_dtype: raise ValueError("Cannot use 'encode` and 'onehot_dtype' simultaneously.") if encode: uniques, encoded = da.unique(values, return_inverse=True) ...
One-hot or label encode a dask array. Parameters ---------- values : da.Array, shape [n_samples,] unqiques : np.ndarray, shape [n_uniques,] encode : bool, default False Whether to encode the values (True) or just discover the uniques. onehot_dtype : np.dtype, optional Optional d...
def delete_cached_branch_info(self): if os.path.isfile(constants.cached_branch_info): logger.debug('Deleting cached branch_info file...') os.remove(constants.cached_branch_info) else: logger.debug('Cached branch_info file does not exist.')
Deletes cached branch_info file
def connect(self, signal, **kwargs): signal.connect(self, **kwargs) self.connections.append((signal, kwargs))
Connect a specific signal type to this receiver.
def _get_debug_context(debug_port, debug_args, debugger_path): if debug_port and debugger_path: try: debugger = Path(debugger_path).resolve(strict=True) except OSError as error: if error.errno == errno.ENOENT: raise DebugContextExceptio...
Creates a DebugContext if the InvokeContext is in a debugging mode Parameters ---------- debug_port int Port to bind the debugger to debug_args str Additional arguments passed to the debugger debugger_path str Path to the directory of the deb...
def _add_event_in_element(self, element, event): if not self.main_script_added: self._generate_main_scripts() if self.script_list is not None: self.id_generator.generate_id(element) self.script_list.append_text( event + "Elements.push('...
Add a type of event in element. :param element: The element. :type element: hatemile.util.html.htmldomelement.HTMLDOMElement :param event: The type of event. :type event: str
def forward(self, actions, batch_info): while len(self.processes) < actions.shape[0]: len_action_space = self.action_space.shape[-1] self.processes.append( OrnsteinUhlenbeckNoiseProcess( np.zeros(len_action_space), float(self.std_dev) * np.ones(len_act...
Return model step after applying noise
def register_token(self, token_class, regexp=None): if regexp is None: regexp = token_class.regexp self.tokens.register(token_class, regexp)
Register a token class. Args: token_class (tdparser.Token): the token class to register regexp (optional str): the regexp for elements of that token. Defaults to the `regexp` attribute of the token class.
def plotnoisecum(noisepkl, fluxscale=1, plot_width=450, plot_height=400): noises = read_noise(noisepkl) imnoise = np.sort(fluxscale*noises[4]) frac = [float(count)/len(imnoise) for count in reversed(range(1, len(imnoise)+1))] noiseplot = Figure(plot_width=plot_width, plot_height=plot_height, toolbar_loc...
Merged noise pkl converted to interactive cumulative histogram noisepkl is standard noise pickle file. fluxscale is scaling applied by gain calibrator. telcal solutions have fluxscale=1. also returns corrected imnoise values if non-unity fluxscale provided
def monitor(self, listener): for line in self._stream(): self._record.append(line) if self.verbose: self.out.blather(line) if listener(line) is self.MONITOR_STOP: return
Relay the stream to listener until told to stop.
def ApplyPluginToTypedCollection(plugin, type_names, fetch_fn): for chunk in plugin.Start(): yield chunk def GetValues(tn): for v in fetch_fn(tn): yield v for type_name in sorted(type_names): stored_cls = rdfvalue.RDFValue.classes[type_name] for chunk in plugin.ProcessValues(stored_cls, ...
Applies instant output plugin to a collection of results. Args: plugin: InstantOutputPlugin instance. type_names: List of type names (strings) to be processed. fetch_fn: Function that takes a type name as an argument and returns available items (FlowResult) corresponding to this type. Items are ...
def indent(self, value): if isinstance(value, str): if value.isspace() or len(value) == 0: self._indent = value else: raise ValueError('String indentation can only contain ' 'whitespace.') elif isinstance(value, int...
Validate and set the indent width.
def add_layer_item(self, layer): if not layer.is_draft_version: raise ValueError("Layer isn't a draft version") self.items.append(layer.latest_version)
Adds a Layer to the publish group.
def print_status(self): tweets = self.received now = time.time() diff = now - self.since self.since = now self.received = 0 if diff > 0: logger.info("Receiving tweets at %s tps", tweets / diff)
Print out the current tweet rate and reset the counter
def save(self): result = yield gen.Task(RedisSession._redis_client.set, self._key, self.dumps()) LOGGER.debug('Saved session %s (%r)', self.id, result) raise gen.Return(result)
Store the session data in redis :param method callback: The callback method to invoke when done
def this(func, cache_obj=CACHE_OBJ, key=None, ttl=None, *args, **kwargs): key = key or (func.__name__ + str(args) + str(kwargs)) if cache_obj.has(key): return cache_obj.get(key) value = func(*args, **kwargs) cache_obj.upsert(key, value, ttl) return value
Store the output from the decorated function in the cache and pull it from the cache on future invocations without rerunning. Normally, the value will be stored under a key which takes into account all of the parameters that are passed into it, thereby caching different invocations separately. If you s...
def group_required(groups=None): def wrapper(func): @wraps(func) def wrapped(*args, **kwargs): if g.user is None: return redirect( url_for(current_app.config['LDAP_LOGIN_VIEW'], next=request.path)...
When applied to a view function, any unauthenticated requests will be redirected to the view named in LDAP_LOGIN_VIEW. Authenticated requests are only permitted if they belong to one of the listed groups. The login view is responsible for asking for credentials, checking them, and setti...
def version_info(self): if self._api_version is None: self.query_api_version() return self._api_version['api-major-version'],\ self._api_version['api-minor-version']
Returns API version information for the HMC. This operation does not require authentication. Returns: :term:`HMC API version`: The HMC API version supported by the HMC. Raises: :exc:`~zhmcclient.HTTPError` :exc:`~zhmcclient.ParseError` :exc:`~zhmcclie...
def get_did_providers(self, did): register_values = self.contract_concise.getDIDRegister(did) if register_values and len(register_values) == 5: return DIDRegisterValues(*register_values).providers return None
Return the list providers registered on-chain for the given did. :param did: hex str the id of an asset on-chain :return: list of addresses None if asset has no registerd providers
def compile(self, db): sql = self.expression if self.alias: sql += (' AS ' + db.quote_column(self.alias)) return sql
Building the sql expression :param db: the database instance
def _is_readable(self, obj): try: read = getattr(obj, 'read') except AttributeError: return False else: return is_method(read, max_arity=1)
Check if the argument is a readable file-like object.
def text(self, text): ret = u"".join(text.content) if 'url' in text.properties: return u"`%s`_" % ret if 'bold' in text.properties: return u"**%s**" % ret if 'italic' in text.properties: return u"*%s*" % ret if 'sub' in text.properties: ...
process a pyth text and return the formatted string
def threadsafe_call(self, fn, *args, **kwargs): def handler(): try: fn(*args, **kwargs) except Exception: warn("error caught while excecuting async callback\n%s\n", format_exc()) def greenlet_wrapper(): gr = greenle...
Wrapper around `AsyncSession.threadsafe_call`.
def soldOutForRole(event, role): if not isinstance(event, Event) or not isinstance(role, DanceRole): return None return event.soldOutForRole(role)
This tag allows one to determine whether any event is sold out for any particular role.
def connectRelay(self): self.protocol = self.connector.buildProtocol(None) self.connected = True self.protocol.makeConnection(self)
Builds the target protocol and connects it to the relay transport.
def broadcast(self, fcn, args): results = self.map(_lockstep_fcn, [(len(self), fcn, args)] * len(self)) _numdone.value = 0 return results
Do a function call on every worker. Parameters ---------- fcn: funtion Function to call. args: tuple The arguments for Pool.map
def dispatch(self, request, *args, **kwargs): if request.GET.get(self.xeditable_fieldname_param): return self.get_ajax_xeditable_choices(request, *args, **kwargs) return super(XEditableMixin, self).dispatch(request, *args, **kwargs)
Introduces the ``ensure_csrf_cookie`` decorator and handles xeditable choices ajax.
def get_env_str(env): return ' '.join("{0}='{1}'".format(k, v) for k, v in env.items())
Gets a string representation of a dict as though it contained environment variable values.
def tzname(self, dt): tt = _localtime(_mktime((dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.weekday(), 0, -1))) return _time.tzname[tt.tm_isdst > 0]
datetime -> string name of time zone.
def upload_GitHub_deploy_key(deploy_repo, ssh_key, *, read_only=False, title="Doctr deploy key for pushing to gh-pages from Travis", **login_kwargs): DEPLOY_KEY_URL = "https://api.github.com/repos/{deploy_repo}/keys".format(deploy_repo=deploy_repo) data = { "title": title, "key": ssh_key, ...
Uploads a GitHub deploy key to ``deploy_repo``. If ``read_only=True``, the deploy_key will not be able to write to the repo.
def load_plugin_classes(classes, category=None, overwrite=False): load_errors = [] for klass in classes: for pcat, pinterface in _plugins_interface.items(): if category is not None and not pcat == category: continue if all([hasattr(klass, attr) for attr in pinterf...
load plugins from class objects Parameters ---------- classes: list list of classes category : None or str if str, apply for single plugin category overwrite : bool if True, allow existing plugins to be overwritten Examples -------- >>> from pprint import pprin...
def get_version(self, service_id, version_number): content = self._fetch("/service/%s/version/%d" % (service_id, version_number)) return FastlyVersion(self, content)
Get the version for a particular service.
def compute_statistic(self, layout): data = self.data if not len(data): return type(data)() params = self.stat.setup_params(data) data = self.stat.use_defaults(data) data = self.stat.setup_data(data) data = self.stat.compute_layer(data, params, layout) ...
Compute & return statistics for this layer
def load(file): with open(file, 'r') as f: contents = f.read() lambder.load_events(contents)
Load events from a json file
def get_special_location(self, special_location=0): try: return(self.process.GetSpecialLocation(special_location)) except Exception as e: print(e) print("Could not retreive special location")
SpecialLocation 0 - Gets the path to the Backup Folders folder location. 1 - Gets the path to the Unfiled Notes folder location. 2 - Gets the path to the Default Notebook folder location.
def add(self, type, orig, replace): ret = libxml2mod.xmlACatalogAdd(self._o, type, orig, replace) return ret
Add an entry in the catalog, it may overwrite existing but different entries.
def clear_knowledge_category(self): if (self.get_knowledge_category_metadata().is_read_only() or self.get_knowledge_category_metadata().is_required()): raise errors.NoAccess() self._my_map['knowledgeCategoryId'] = self._knowledge_category_default
Clears the knowledge category. raise: NoAccess - ``Metadata.isRequired()`` or ``Metadata.isReadOnly()`` is ``true`` *compliance: mandatory -- This method must be implemented.*
def _get_editable(self, request): try: editable_settings = self._editable_caches[request] except KeyError: editable_settings = self._editable_caches[request] = self._load() return editable_settings
Get the dictionary of editable settings for a given request. Settings are fetched from the database once per request and then stored in ``_editable_caches``, a WeakKeyDictionary that will automatically discard each entry when no more references to the request exist.
def render(self, rect, data): num_elements = len(self.elements) col_width = (rect.w-self.margin*(num_elements-1)) / float(num_elements) x = rect.x for element in self.elements: if element is not None: element.render(datatypes.Rectangle( ...
Draws the columns.
def set_brightness(self, brightness): brightness = min([1.0, max([brightness, 0.0])]) self.state.brightness = brightness self._repeat_last_frame() sequence_number = self.zmq_publisher.publish_brightness(brightness) logging.debug("Set brightness to {brightPercent:05.1f}%".format(b...
set general brightness in range 0...1
def attach_issue(resource_id, table, user_id): data = schemas.issue.post(flask.request.json) issue = _get_or_create_issue(data) if table.name == 'jobs': join_table = models.JOIN_JOBS_ISSUES else: join_table = models.JOIN_COMPONENTS_ISSUES key = '%s_id' % table.name[0:-1] query = ...
Attach an issue to a specific job.
def publish_properties(self): publish = self.publish publish(b"$homie", b"3.0.1") publish(b"$name", self.settings.DEVICE_NAME) publish(b"$state", b"init") publish(b"$fw/name", b"Microhomie") publish(b"$fw/version", __version__) publish(b"$implementation", bytes(sy...
publish device and node properties
def _get_fields_info(self, cols, model_schema, filter_rel_fields, **kwargs): ret = list() for col in cols: page = page_size = None col_args = kwargs.get(col, {}) if col_args: page = col_args.get(API_PAGE_INDEX_RIS_KEY, None) page_size =...
Returns a dict with fields detail from a marshmallow schema :param cols: list of columns to show info for :param model_schema: Marshmallow model schema :param filter_rel_fields: expects add_query_rel_fields or edit_query_rel_fields :param ...
def resume(self, obj): if isinstance(obj, str): savefile = open(obj, 'rb') else: savefile = obj game = pickle.loads(zlib.decompress(savefile.read())) if savefile is not obj: savefile.close() game.random_generator = random.Random() game....
Returns an Adventure game saved to the given file.
def get_next_slip(raw): if not is_slip(raw): return None, raw length = raw[1:].index(SLIP_END) slip_packet = decode(raw[1:length+1]) new_raw = raw[length+2:] return slip_packet, new_raw
Get the next slip packet from raw data. Returns the extracted packet plus the raw data with the remaining data stream.
def draw(self, labels): y_lower = 10 colors = color_palette(self.colormap, self.n_clusters_) for idx in range(self.n_clusters_): values = self.silhouette_samples_[labels == idx] values.sort() size = values.shape[0] y_upper = y_lower + size ...
Draw the silhouettes for each sample and the average score. Parameters ---------- labels : array-like An array with the cluster label for each silhouette sample, usually computed with ``predict()``. Labels are not stored on the visualizer so that the figure ...
def make(parser): s = parser.add_subparsers( title='commands', metavar='COMMAND', help='description', ) def gen_pass_f(args): gen_pass() gen_pass_parser = s.add_parser('gen-pass', help='generate the password') gen_pass_parser.set_defaults(func=gen_pass_f) def ...
DEPRECATED prepare OpenStack basic environment
def get_graph(cls, response): if cls.is_graph(response): return response if hasattr(response, '__getitem__'): if len(response) > 0 and \ cls.is_graph(response[0]): return response[0]
Given a Flask response, find the rdflib Graph
def enable(self): payload = { "new_state": "1" } data = json.dumps(payload) req = self.request(self.mist_client.uri+'/clouds/'+self.id, data=data) req.post() self.enabled = True self.mist_client.update_clouds()
Enable the Cloud. :returns: A list of mist.clients' updated clouds.
def _normalize(parsed, **options): if options.get("exact"): return parsed if isinstance(parsed, time): now = options["now"] or datetime.now() return datetime( now.year, now.month, now.day, parsed.hour, parsed.minute, ...
Normalizes the parsed element. :param parsed: The parsed elements. :type parsed: Parsed :rtype: Parsed
def get_default_runner(udf_class, input_col_delim=',', null_indicator='NULL', stdin=None): proto = udf.get_annotation(udf_class) in_types, out_types = parse_proto(proto) stdin = stdin or sys.stdin arg_parser = ArgParser(in_types, stdin, input_col_delim, null_indicator) stdin_feed = make_feed(arg_par...
Create a default runner with specified udf class.
def _ReceiveOp(self): try: fs_msg, received_bytes = self._fs.Recv() except (IOError, struct.error): logging.critical("Broken local Fleetspeak connection (read end).") raise received_type = fs_msg.data.TypeName() if not received_type.endswith("grr.GrrMessage"): raise ValueError( ...
Receives a single message through Fleetspeak.
def _extract_local_archive(working_dir, cleanup_functions, env_name, local_archive): with zipfile.ZipFile(local_archive) as z: z.extractall(working_dir) archive_filenames = z.namelist() root_elements = {m.split(posixpath.sep, 1)[0] for m in archive_filenames} abs_archive_filenames = [os.path...
Helper internal function for extracting a zipfile and ensure that a cleanup is queued. Parameters ---------- working_dir : str cleanup_functions : List[() -> NoneType] env_name : str local_archive : str
def launch_run(self, command, project=None, entity=None, run_id=None): query = gql( ) patch = BytesIO() if self.git.dirty: self.git.repo.git.execute(['git', 'diff'], output_stream=patch) patch.seek(0) cwd = "." if self.git.enabled: cwd = cwd + ...
Launch a run in the cloud. Args: command (str): The command to run program (str): The file to run project (str): The project to scope the runs to entity (str, optional): The entity to scope this project to. Defaults to public models run_id (str, opti...
def close(self): if self.fileobj is None: return if self.mode == WRITE: self.close_member() self.fileobj = None elif self.mode == READ: self.fileobj = None if self.myfileobj: self.myfileobj.close() self.myfileobj = N...
Closes the gzip with care to handle multiple members.
def can_create_objective_bank_with_record_types(self, objective_bank_record_types): if self._catalog_session is not None: return self._catalog_session.can_create_catalog_with_record_types(catalog_record_types=objective_bank_record_types) return True
Tests if this user can create a single ``ObjectiveBank`` using the desired record types. While ``LearningManager.getObjectiveBankRecordTypes()`` can be used to examine which records are supported, this method tests which record(s) are required for creating a specific ``ObjectiveBank``. ...
def declareProvisioner(self, *args, **kwargs): return self._makeApiCall(self.funcinfo["declareProvisioner"], *args, **kwargs)
Update a provisioner Declare a provisioner, supplying some details about it. `declareProvisioner` allows updating one or more properties of a provisioner as long as the required scopes are possessed. For example, a request to update the `aws-provisioner-v1` provisioner with a body `{de...
def _read_config_file(args): stage = args.stage with open(args.config, 'rt') as f: config = yaml.safe_load(f.read()) STATE['stages'] = config['stages'] config['config'] = _decrypt_item(config['config'], stage=stage, key='', render=True) return config['sta...
Decrypt config file, returns a tuple with stages and config.
def recv(self, timeout=None): if timeout: try: testsock = self._zmq.select([self.socket], [], [], timeout)[0] except zmq.ZMQError as e: if e.errno == errno.EINTR: testsock = None else: raise ...
Overwrite standard recv for timeout calls to catch interrupt errors.
def ot_tnrs_match_names(name_list, context_name=None, do_approximate_matching=True, include_dubious=False, include_deprecated=True, tnrs_wrapper=None): if tnrs_wrapper is None: from peyotl...
Uses a peyotl wrapper around an Open Tree web service to get a list of OTT IDs matching the `name_list`. The tnrs_wrapper can be None (in which case the default wrapper from peyotl.sugar will be used. All other arguments correspond to the arguments of the web-service call. A ValueError will be raised if...
def get_service_resources(cls, model): key = cls.get_model_key(model) return cls.get_service_name_resources(key)
Get resource models by service model
def paginate(self, request, offset=0, limit=None): return self.collection.offset(offset).limit(limit), self.collection.count()
Paginate queryset.
def set(self, attr_dict): for key in attr_dict: if key == self._id_attribute: setattr(self, self._id_attribute, attr_dict[key]) else: setattr(self, u"_" + key, attr_dict[key]) return self
Sets attributes of this user object. :type attr_dict: dict :param attr_dict: Parameters to set, with attribute keys. :rtype: :class:`.Base` :return: The current object.
def _processChanges(self, unused_output): for branch in self.branches + self.bookmarks: rev = yield self._getHead(branch) if rev is None: continue yield self._processBranchChanges(rev, branch)
Send info about pulled changes to the master and record current. HgPoller does the recording by moving the working dir to the head of the branch. We don't update the tree (unnecessary treatment and waste of space) instead, we simply store the current rev number in a file. Recall...
def strip_command(self, command_string, output): backspace_char = "\x08" if backspace_char in output: output = output.replace(backspace_char, "") output_lines = output.split(self.RESPONSE_RETURN) new_output = output_lines[1:] return self.RESPONSE_RETURN.jo...
Strip command_string from output string Cisco IOS adds backspaces into output for long commands (i.e. for commands that line wrap) :param command_string: The command string sent to the device :type command_string: str :param output: The returned output as a result of the command strin...
def _handle_uninitialized_read(self, addr, inspect=True, events=True): if self._uninitialized_read_handler is None: v = self.state.solver.Unconstrained("%s_%s" % (self.id, addr), self.width*self.state.arch.byte_width, key=self.variable_key_prefix + (addr,), inspect=inspect, events=events) ...
The default uninitialized read handler. Returns symbolic bytes.
def get_shiftfile_row(self): if self.fit is not None: rowstr = '%s %0.6f %0.6f %0.6f %0.6f %0.6f %0.6f\n'%( self.name,self.fit['offset'][0],self.fit['offset'][1], self.fit['rot'],self.fit['scale'][0], self.fit['rms'][0],self.f...
Return the information for a shiftfile for this image to provide compatability with the IRAF-based MultiDrizzle.
def random_split(valid_pct:float, *arrs:NPArrayableList)->SplitArrayList: "Randomly split `arrs` with `valid_pct` ratio. good for creating validation set." assert (valid_pct>=0 and valid_pct<=1), 'Validation set percentage should be between 0 and 1' is_train = np.random.uniform(size=(len(arrs[0]),)) > valid...
Randomly split `arrs` with `valid_pct` ratio. good for creating validation set.
def WaitForSnapshotCompleted(snapshot): print 'Waiting for snapshot %s to be completed...' % (snapshot) while True: snapshot.update() sys.stdout.write('.') sys.stdout.flush() if snapshot.status == 'completed': break time.sleep(5) return
Blocks until snapshot is complete.
def rename(self, name): r = self._h._http_resource( method='PUT', resource=('apps', self.name), data={'app[name]': name} ) return r.ok
Renames app to given name.