code stringlengths 51 2.38k | docstring stringlengths 4 15.2k |
|---|---|
def from_span(cls, inputs, window_length, span, **kwargs):
if span <= 1:
raise ValueError(
"`span` must be a positive number. %s was passed." % span
)
decay_rate = (1.0 - (2.0 / (1.0 + span)))
assert 0.0 < decay_rate <= 1.0
return cls(
... | Convenience constructor for passing `decay_rate` in terms of `span`.
Forwards `decay_rate` as `1 - (2.0 / (1 + span))`. This provides the
behavior equivalent to passing `span` to pandas.ewma.
Examples
--------
.. code-block:: python
# Equivalent to:
# ... |
def load(self, name=None, *args, **kwargs):
"Load the instance of the object from the stash."
inst = self.stash.load(name)
if inst is None:
inst = self.instance(name, *args, **kwargs)
logger.debug(f'loaded (conf mng) instance: {inst}')
return inst | Load the instance of the object from the stash. |
def search(query, query_type=DEFAULT_QUERY_TYPE):
statement, arguments = _build_search(query)
if statement is None and arguments is None:
return QueryResults([], [], 'AND')
with db_connect() as db_connection:
with db_connection.cursor() as cursor:
cursor.execute(statement, argume... | Search database using parsed query.
Executes a database search query from the given ``query``
(a ``Query`` object) and optionally accepts a list of search weights.
By default, the search results are ordered by weight.
:param query: containing terms, filters, and sorts.
:type query: Query
:retu... |
def get_png_data_url(blob: Optional[bytes]) -> str:
return BASE64_PNG_URL_PREFIX + base64.b64encode(blob).decode('ascii') | Converts a PNG blob into a local URL encapsulating the PNG. |
def cluster_get_keys_in_slots(self, slot, count, *, encoding):
return self.execute(b'CLUSTER', b'GETKEYSINSLOT', slot, count,
encoding=encoding) | Return local key names in the specified hash slot. |
def get_recirc_content(self, published=True, count=3):
query = self.get_query()
if not query.get('included_ids'):
qs = Content.search_objects.search()
qs = qs.query(
TagBoost(slugs=self.tags.values_list("slug", flat=True))
).filter(
~Id... | gets the first 3 content objects in the `included_ids` |
def rescale(self, fun):
if self.bands != 1:
raise ValueError('only single band images are currently supported')
mat = self.matrix()
scaled = fun(mat)
self.assign(scaled, band=0) | perform raster computations with custom functions and assign them to the existing raster object in memory
Parameters
----------
fun: function
the custom function to compute on the data
Examples
--------
>>> with Raster('filename') as ras:
>>> ras... |
def data_duration(self, data):
lengths = []
for key in self._time:
for idx in self._time.get(key, []):
lengths.append(data[key].shape[idx])
return min(lengths) | Compute the valid data duration of a dict
Parameters
----------
data : dict
As produced by pumpp.transform
Returns
-------
length : int
The minimum temporal extent of a dynamic observation in data |
def get_3_3_tuple_list(self,obj,default=None):
if is_sequence3(obj):
return [self.get_3_3_tuple(o,default) for o in obj]
return [self.get_3_3_tuple(obj,default)] | Return list of 3x3-tuples. |
def get_block_type(self, def_id):
try:
return self._definitions[def_id]
except KeyError:
try:
return def_id.aside_type
except AttributeError:
raise NoSuchDefinition(repr(def_id)) | Get a block_type by its definition id. |
def download(self, url, output_path):
request_failed_message = self.tr(
"Can't access PetaBencana API: {source}").format(
source=url)
downloader = FileDownloader(url, output_path)
result, message = downloader.download()
if not result:
display_warning_m... | Download file from API url and write to output path.
:param url: URL of the API.
:type url: str
:param output_path: Path of output file,
:type output_path: str |
def parse_opera (url_data):
from ..bookmarks.opera import parse_bookmark_data
for url, name, lineno in parse_bookmark_data(url_data.get_content()):
url_data.add_url(url, line=lineno, name=name) | Parse an opera bookmark file. |
def assign_to_all_link_group(self, group=0x01):
msg = StandardSend(self._address,
COMMAND_ASSIGN_TO_ALL_LINK_GROUP_0X01_NONE,
cmd2=group)
self._send_msg(msg) | Assign a device to an All-Link Group.
The default is group 0x01. |
def insert(self, iterable, data=None, weight=1.0):
self.root.insert(iterable, index=0, data=data, weight=1.0) | Used to insert into he root node
Args
iterable(hashable): index or key used to identify
data(object): data to be paired with the key |
def cli(ctx, config, debug):
ctx.obj['config'] = config
ctx.obj['engine'] = stex.SnakeTeX(config_file=config, debug=debug) | SnakTeX command line interface - write LaTeX faster through templating. |
def parse(cls, msg):
lines = msg.splitlines()
method, uri, version = lines[0].split()
headers = cls.parse_headers('\r\n'.join(lines[1:]))
return cls(version=version, uri=uri, method=method, headers=headers) | Parse message string to request object. |
def job_data(job_id):
job_dict = db.get_job(job_id)
if not job_dict:
return json.dumps({'error': 'job_id not found'}), 404, headers
if not is_authorized(job_dict):
return json.dumps({'error': 'not authorized'}), 403, headers
if job_dict['error']:
return json.dumps({'error': job_d... | Get the raw data that the job returned. The mimetype
will be the value provided in the metdata for the key ``mimetype``.
**Results:**
:rtype: string
:statuscode 200: no error
:statuscode 403: not authorized to view the job's data
:statuscode 404: job id not found
:statuscode 409: an error... |
def add_scanner_param(self, name, scanner_param):
assert name
assert scanner_param
self.scanner_params[name] = scanner_param
command = self.commands.get('start_scan')
command['elements'] = {
'scanner_params':
{k: v['name'] for k, v in self.scanner_para... | Add a scanner parameter. |
def build_sensors_list(self, type):
ret = []
if type == SENSOR_TEMP_UNIT and self.init_temp:
input_list = self.stemps
self.stemps = psutil.sensors_temperatures()
elif type == SENSOR_FAN_UNIT and self.init_fan:
input_list = self.sfans
self.sfans = p... | Build the sensors list depending of the type.
type: SENSOR_TEMP_UNIT or SENSOR_FAN_UNIT
output: a list |
def _find_playlist(self):
data = None
if self.id:
data = self.connection.get_item(
'find_playlist_by_id', playlist_id=self.id)
elif self.reference_id:
data = self.connection.get_item(
'find_playlist_by_reference_id',
referen... | Internal method to populate the object given the ``id`` or
``reference_id`` that has been set in the constructor. |
def process_delta(delta):
kwargs = {
"type": delta["type"],
"date": datetime.datetime.utcfromtimestamp(delta["date"]),
"object_id": delta["object_data"]["id"],
}
print(" * {type} at {date} with ID {object_id}".format(**kwargs)) | This is the part of the code where you would process the information
from the webhook notification. Each delta is one change that happened,
and might require fetching message IDs, updating your database,
and so on.
However, because this is just an example project, we'll just print
out information a... |
def _buildDict(self):
lexDict = {}
with io.open(self.islePath, "r", encoding='utf-8') as fd:
wordList = [line.rstrip('\n') for line in fd]
for row in wordList:
word, pronunciation = row.split(" ", 1)
word, extraInfo = word.split("(", 1)
extraInfo =... | Builds the isle textfile into a dictionary for fast searching |
def __parse_affiliations_yml(self, affiliations):
enrollments = []
for aff in affiliations:
name = self.__encode(aff['organization'])
if not name:
error = "Empty organization name"
msg = self.GRIMOIRELAB_INVALID_FORMAT % {'error': error}
... | Parse identity's affiliations from a yaml dict. |
def convex_hull(self):
if self._faces is None:
if self._vertices is None:
return None
self.triangulate()
return self._convex_hull | Return an array of vertex indexes representing the convex hull.
If faces have not been computed for this mesh, the function
computes them.
If no vertices or faces are specified, the function returns None. |
def _init_message(self):
try:
self.message = compat.text_type(self.error)
except UnicodeError:
try:
self.message = str(self.error)
except UnicodeEncodeError:
self.message = self.error.args[0]
if not isinstance(self.message, comp... | Find a unicode representation of self.error |
def skip(self, length):
if length >= self.__size:
skip_amount = self.__size
rem = length - skip_amount
self.__segments.clear()
self.__offset = 0
self.__size = 0
self.position += skip_amount
else:
rem = 0
self... | Removes ``length`` bytes and returns the number length still required to skip |
def _mosaik_args_from_config(config):
multi_mappers = config["algorithm"].get("multiple_mappers", True)
multi_flags = ["-m", "all"] if multi_mappers else ["-m", "unique"]
error_flags = ["-mm", "2"]
num_cores = config["algorithm"].get("num_cores", 1)
core_flags = ["-p", str(num_cores)] if num_cores >... | Configurable high level options for mosaik. |
def get_pub_str(self, name='master'):
path = os.path.join(self.opts['pki_dir'],
name + '.pub')
if not os.path.isfile(path):
key = self.__get_keys()
if HAS_M2:
key.save_pub_key(path)
else:
with salt.utils.file... | Return the string representation of a public key
in the pki-directory |
def setup_config(epab_version: str):
logger = logging.getLogger('EPAB')
logger.debug('setting up config')
elib_config.ELIBConfig.setup(
app_name='EPAB',
app_version=epab_version,
config_file_path='pyproject.toml',
config_sep_str='__',
root_path=['tool', 'epab']
)
... | Set up elib_config package
:param epab_version: installed version of EPAB as as string |
def start(self, container, instances=None, map_name=None, **kwargs):
return self.run_actions('start', container, instances=instances, map_name=map_name, **kwargs) | Starts instances for a container configuration.
:param container: Container name.
:type container: unicode | str
:param instances: Instance names to start. If not specified, will start all instances as specified in the
configuration (or just one default instance).
:param map_na... |
def connect_redis(redis_client, name=None, transaction=False):
return ConnectionManager.connect_redis(
redis_client=redis_client, name=name, transaction=transaction) | Connect your redis-py instance to redpipe.
Example:
.. code:: python
redpipe.connect_redis(redis.StrictRedis(), name='users')
Do this during your application bootstrapping.
You can also pass a redis-py-cluster instance to this method.
.. code:: python
redpipe.connect_redis(re... |
def list_diff(list_a, list_b):
result = []
for item in list_b:
if not item in list_a:
result.append(item)
return result | Return the items from list_b that differ from list_a |
def _mean_square_error(y, y_pred, w):
return np.average(((y_pred - y) ** 2), weights=w) | Calculate the mean square error. |
def valgrind(command, env={}):
xml_file = tempfile.NamedTemporaryFile()
internal.register.after_check(lambda: _check_valgrind(xml_file))
return run(f"valgrind --show-leak-kinds=all --xml=yes --xml-file={xml_file.name} -- {command}", env=env) | Run a command with valgrind.
:param command: command to be run
:type command: str
:param env: environment in which to run command
:type env: str
:raises check50.Failure: if, at the end of the check, valgrind reports any errors
This function works exactly like :func:`check50.run`, with the addi... |
def has_prev(self):
if self._result_cache:
return self._result_cache.has_prev
return self.all().has_prev | Return True if there are previous values present |
def add_edge(self, from_node, to_node):
if to_node not in self.nodes:
self.add_node(to_node)
try:
self.nodes[from_node]["sons"].append(to_node)
except KeyError:
self.nodes[from_node] = {"dfs_loop_status": "", "sons": [to_node]} | Add edge between two node
The edge is oriented
:param from_node: node where edge starts
:type from_node: object
:param to_node: node where edge ends
:type to_node: object
:return: None |
def get_service(station: str) -> Service:
for prefix in PREFERRED:
if station.startswith(prefix):
return PREFERRED[prefix]
return NOAA | Returns the preferred service for a given station |
def load_nddata(self, ndd, naxispath=None):
self.clear_metadata()
ahdr = self.get_header()
ahdr.update(ndd.meta)
self.setup_data(ndd.data, naxispath=naxispath)
if ndd.wcs is None:
self.wcs = wcsmod.WCS(logger=self.logger)
self.wcs.load_header(ahdr)
... | Load from an astropy.nddata.NDData object. |
def add_external_reference_to_term(self,term_id, external_ref):
if self.term_layer is not None:
self.term_layer.add_external_reference(term_id, external_ref) | Adds an external reference to the given term identifier
@type term_id: string
@param term_id: the term identifier
@param external_ref: an external reference object
@type external_ref: L{CexternalReference} |
def Group(items, key):
result = {}
for item in items:
result.setdefault(key(item), []).append(item)
return result | Groups items by given key function.
Args:
items: An iterable or an iterator of items.
key: A function which given each item will return the key.
Returns:
A dict with keys being each unique key and values being a list of items of
that key. |
def _resolve(self, spec):
if not spec.remote:
return spec
try:
resolved_urls = self._resolver.resolve(spec.remote)
if resolved_urls:
return CacheSpec(local=spec.local, remote='|'.join(resolved_urls))
return spec
except Resolver.ResolverError as e:
self._log.warn('Error ... | Attempt resolving cache URIs when a remote spec is provided. |
def images(language, word, n = 20, *args, **kwargs):
from lltk.images import google
return google(language, word, n, *args, **kwargs) | Returns a list of URLs to suitable images for a given word. |
def is_transition(self):
return self.is_snv and is_purine(self.ref) == is_purine(self.alt) | Is this variant and pyrimidine to pyrimidine change or purine to purine change |
def set_goid2color_pval(self, goid2color):
alpha2col = self.alpha2col
if self.pval_name is not None:
pval_name = self.pval_name
for goid, res in self.go2res.items():
pval = getattr(res, pval_name, None)
if pval is not None:
for ... | Fill missing colors based on p-value of an enriched GO term. |
def load_configuration(linter):
name_checker = get_checker(linter, NameChecker)
name_checker.config.good_names += ('qs', 'urlpatterns', 'register', 'app_name', 'handler500')
linter.config.black_list += ('migrations', 'south_migrations') | Amend existing checker config. |
def get_pmg_structure(phonopy_structure):
lattice = phonopy_structure.get_cell()
frac_coords = phonopy_structure.get_scaled_positions()
symbols = phonopy_structure.get_chemical_symbols()
masses = phonopy_structure.get_masses()
mms = phonopy_structure.get_magnetic_moments()
mms = mms or [0] * len... | Convert a PhonopyAtoms object to pymatgen Structure object.
Args:
phonopy_structure (PhonopyAtoms): A phonopy structure object. |
def orchestration(self):
if self._orchestration is not None:
return self._orchestration
API_VERSIONS = {
'1': 'heatclient.v1.client.Client',
}
heat_client = utils.get_client_class(
API_NAME,
self._instance._api_version[API_NAME],
... | Returns an orchestration service client |
def _render(roster_file, **kwargs):
renderers = salt.loader.render(__opts__, {})
domain = __opts__.get('roster_domain', '')
try:
result = salt.template.compile_template(roster_file,
renderers,
__opts__['r... | Render the roster file |
def to_ccw(geom):
if isinstance(geom, sgeom.Polygon) and not geom.exterior.is_ccw:
geom = sgeom.polygon.orient(geom)
return geom | Reorients polygon to be wound counter-clockwise. |
def getPhotosets(self):
method = 'flickr.photosets.getList'
data = _doget(method, user_id=self.id)
sets = []
if isinstance(data.rsp.photosets.photoset, list):
for photoset in data.rsp.photosets.photoset:
sets.append(Photoset(photoset.id, photoset.title.text,\
... | Returns a list of Photosets. |
def create_scree_plot(in_filename, out_filename, plot_title):
scree_plot_args = ("--evec", in_filename, "--out", out_filename,
"--scree-plot-title", plot_title)
try:
PlotEigenvalues.main(argString=scree_plot_args)
except PlotEigenvalues.ProgramError as e:
msg = "PlotEi... | Creates a scree plot using smartpca results.
:param in_filename: the name of the input file.
:param out_filename: the name of the output file.
:param plot_title: the title of the scree plot.
:type in_filename: str
:type out_filename: str
:type plot_title: str |
def unlock_swarm(self, key):
if isinstance(key, dict):
if 'UnlockKey' not in key:
raise errors.InvalidArgument('Invalid unlock key format')
else:
key = {'UnlockKey': key}
url = self._url('/swarm/unlock')
res = self._post_json(url, data=key)
... | Unlock a locked swarm.
Args:
key (string): The unlock key as provided by
:py:meth:`get_unlock_key`
Raises:
:py:class:`docker.errors.InvalidArgument`
If the key argument is in an incompatible format
:py:cla... |
def add_result(self, values):
idx = [values['host']]
for gid in self.key_gids[1:]:
idx.append(values[gid])
idx = tuple(idx)
try:
self.results[idx] += 1
except KeyError:
self.results[idx] = 1
self._last_idx = idx | Add a tuple or increment the value of an existing one
in the rule results dictionary. |
def parse_eprocess(self, eprocess_data):
Name = eprocess_data['_EPROCESS']['Cybox']['Name']
PID = eprocess_data['_EPROCESS']['Cybox']['PID']
PPID = eprocess_data['_EPROCESS']['Cybox']['Parent_PID']
return {'Name': Name, 'PID': PID, 'PPID': PPID} | Parse the EProcess object we get from some rekall output |
def chat(self, message):
if message:
action_chat = sc_pb.ActionChat(
channel=sc_pb.ActionChat.Broadcast, message=message)
action = sc_pb.Action(action_chat=action_chat)
return self.act(action) | Send chat message as a broadcast. |
def put(src_path, dest_hdfs_path, **kwargs):
cp(path.abspath(src_path, local=True), dest_hdfs_path, **kwargs) | \
Copy the contents of ``src_path`` to ``dest_hdfs_path``.
``src_path`` is forced to be interpreted as an ordinary local path
(see :func:`~path.abspath`). The source file is opened for reading
and the copy is opened for writing. Additional keyword arguments,
if any, are handled like in :func:`open`... |
def select_where(self, where_col_list, where_value_list, col_name=''):
res = []
col_ids = []
for col_id, col in enumerate(self.header):
if col in where_col_list:
col_ids.append([col_id, col])
for row_num, row in enumerate(self.arr):
keep_this_row =... | selects rows from the array where col_list == val_list |
def save(self, path_info, checksum):
assert path_info["scheme"] == "local"
assert checksum is not None
path = path_info["path"]
assert os.path.exists(path)
actual_mtime, actual_size = get_mtime_and_size(path)
actual_inode = get_inode(path)
existing_record = self.g... | Save checksum for the specified path info.
Args:
path_info (dict): path_info to save checksum for.
checksum (str): checksum to save. |
def _remove_ordered_from_queue(self, last_caught_up_3PC=None):
to_remove = []
for i, msg in enumerate(self.outBox):
if isinstance(msg, Ordered) and \
(not last_caught_up_3PC or
compare_3PC_keys((msg.viewNo, msg.ppSeqNo), last_caught_up_3PC) >= 0):
... | Remove any Ordered that the replica might be sending to node which is
less than or equal to `last_caught_up_3PC` if `last_caught_up_3PC` is
passed else remove all ordered, needed in catchup |
def callback(newstate):
print('callback: ', newstate)
if newstate == modem.STATE_RING:
if state == modem.STATE_IDLE:
att = {"cid_time": modem.get_cidtime,
"cid_number": modem.get_cidnumber,
"cid_name": modem.get_cidname}
print('Ringing', att)... | Callback from modem, process based on new state |
def parse_venue(data):
return MeetupVenue(
id=data.get('id', None),
name=data.get('name', None),
address_1=data.get('address_1', None),
address_2=data.get('address_2', None),
address_3=data.get('address_3', None),
city=data.get('city', None),
state=data.get('s... | Parse a ``MeetupVenue`` from the given response data.
Returns
-------
A `pythonkc_meetups.types.`MeetupVenue``. |
def acquire_multi(self, n=1):
browsers = []
with self._lock:
if len(self._in_use) >= self.size:
raise NoBrowsersAvailable
while len(self._in_use) < self.size and len(browsers) < n:
browser = self._fresh_browser()
browsers.append(bro... | Returns a list of up to `n` browsers.
Raises:
NoBrowsersAvailable if none available |
def set_layout(wlayout, callback):
global display_size
global window_list
global loaded_layout
global pending_load
global vehiclename
if not wlayout.name in window_list and loaded_layout is not None and wlayout.name in loaded_layout:
callback(loaded_layout[wlayout.name])
window_list[... | set window layout |
def create_destination(flowable, container, at_top_of_container=False):
vertical_position = 0 if at_top_of_container else container.cursor
ids = flowable.get_ids(container.document)
destination = NamedDestination(*(str(id) for id in ids))
container.canvas.annotate(destination, 0, vertical_position,
... | Create a destination anchor in the `container` to direct links to
`flowable` to. |
def _parse_status(self, output):
parsed = self._parse_machine_readable_output(output)
statuses = []
for target, tuples in itertools.groupby(parsed, lambda tup: tup[1]):
info = {kind: data for timestamp, _, kind, data in tuples}
status = Status(name=target, state=info.get(... | Unit testing is so much easier when Vagrant is removed from the
equation. |
def parse(self, argv):
rv = {}
for pattern in self.patterns:
pattern.apply(rv, argv)
return rv | Parses the given `argv` and returns a dictionary mapping argument names
to the values found in `argv`. |
def update(self, key, value):
if not isinstance(value, dict):
raise BadValueError(
'The value {} is incorrect.'
' Values should be strings'.format(value))
if key in self.data:
v = self.get(key)
v.update(value)
else:
... | Update a `key` in the keystore.
If the key is non-existent, it's being created |
def decode_osgi_props(input_props):
result_props = {}
intfs = decode_list(input_props, OBJECTCLASS)
result_props[OBJECTCLASS] = intfs
for intf in intfs:
package_key = ENDPOINT_PACKAGE_VERSION_ + package_name(intf)
intfversionstr = input_props.get(package_key, None)
if intfversion... | Decodes the OSGi properties of the given endpoint properties |
def _on_process_error(self, error):
if self is None:
return
err = PROCESS_ERROR_STRING[error]
self._formatter.append_message(err + '\r\n', output_format=OutputFormat.ErrorMessageFormat) | Display child process error in the text edit. |
def make_pizzly_gtf(gtf_file, out_file, data):
if file_exists(out_file):
return out_file
db = gtf.get_gtf_db(gtf_file)
with file_transaction(data, out_file) as tx_out_file:
with open(tx_out_file, "w") as out_handle:
for gene in db.features_of_type("gene"):
childre... | pizzly needs the GTF to be in gene -> transcript -> exon order for each
gene. it also wants the gene biotype set as the source |
def get_adj_records(results, min_ratio=None, pval=0.05):
records = []
for rec in results:
rec.update_remaining_fldsdefprt(min_ratio=min_ratio)
if pval is not None and rec.p_uncorrected >= pval:
continue
if rec.is_ratio_different:
record... | Return GOEA results with some additional statistics calculated. |
def find_library_linux(cls):
dll = Library.JLINK_SDK_NAME
root = os.path.join('/', 'opt', 'SEGGER')
for (directory_name, subdirs, files) in os.walk(root):
fnames = []
x86_found = False
for f in files:
path = os.path.join(directory_name, f)
... | Loads the SEGGER DLL from the root directory.
On Linux, the SEGGER tools are installed under the ``/opt/SEGGER``
directory with versioned directories having the suffix ``_VERSION``.
Args:
cls (Library): the ``Library`` class
Returns:
The paths to the J-Link library... |
def luns(self):
lun_list, smp_list = [], []
if self.ioclass_luns:
lun_list = map(lambda l: VNXLun(lun_id=l.lun_id, name=l.name,
cli=self._cli), self.ioclass_luns)
if self.ioclass_snapshots:
smp_list = map(lambda smp: VNXLun(name... | Aggregator for ioclass_luns and ioclass_snapshots. |
def decimate(self, fraction=0.5, N=None, boundaries=False, verbose=True):
poly = self.polydata(True)
if N:
Np = poly.GetNumberOfPoints()
fraction = float(N) / Np
if fraction >= 1:
return self
decimate = vtk.vtkDecimatePro()
decimate.Set... | Downsample the number of vertices in a mesh.
:param float fraction: the desired target of reduction.
:param int N: the desired number of final points (**fraction** is recalculated based on it).
:param bool boundaries: (True), decide whether to leave boundaries untouched or not.
.. note... |
def minimum_image_dr( self, r1, r2, cutoff=None ):
delta_r_vector = self.minimum_image( r1, r2 )
return( self.dr( np.zeros( 3 ), delta_r_vector, cutoff ) ) | Calculate the shortest distance between two points in the cell,
accounting for periodic boundary conditions.
Args:
r1 (np.array): fractional coordinates of point r1.
r2 (np.array): fractional coordinates of point r2.
cutoff (:obj: `float`, optional): if set, return ... |
def use_comparative_asseessment_part_item_view(self):
self._object_views['asseessment_part_item'] = COMPARATIVE
for session in self._get_provider_sessions():
try:
session.use_comparative_asseessment_part_item_view()
except AttributeError:
pass | Pass through to provider AssessmentPartItemSession.use_comparative_asseessment_part_item_view |
def new_keys(self):
if self._new_keys is None:
self._new_keys = NewKeyList(self._version, account_sid=self._solution['sid'], )
return self._new_keys | Access the new_keys
:returns: twilio.rest.api.v2010.account.new_key.NewKeyList
:rtype: twilio.rest.api.v2010.account.new_key.NewKeyList |
def set_min_level_to_mail(self, level):
self.min_log_level_to_mail = level
handler_class = AlkiviEmailHandler
self._set_min_level(handler_class, level) | Allow to change mail level after creation |
def email_type(arg):
if not is_valid_email_address(arg):
raise argparse.ArgumentTypeError("{0} is not a valid email address".format(repr(arg)))
return arg | An argparse type representing an email address. |
def prepare_schemes(self, req):
ret = sorted(self.__schemes__ & set(req.schemes), reverse=True)
if len(ret) == 0:
raise ValueError('No schemes available: {0}'.format(req.schemes))
return ret | make sure this client support schemes required by current request
:param pyswagger.io.Request req: current request object |
def _clean(self):
if CleanupPolicy.EVERYTHING in self.cleanup:
self.cleanup_containers()
self.cleanup_volumes()
self.cleanup_images()
self._clean_tmp_dirs()
else:
if CleanupPolicy.CONTAINERS in self.cleanup:
self... | Method for cleaning according to object cleanup policy value
:return: None |
def asdict(self):
timestamp_str = None
if self.reading_time is not None:
timestamp_str = self.reading_time.isoformat()
return {
'stream': self.stream,
'device_timestamp': self.raw_time,
'streamer_local_id': self.reading_id,
'timestamp':... | Encode the data in this reading into a dictionary.
Returns:
dict: A dictionary containing the information from this reading. |
def dropdb():
manager.db.engine.echo = True
if prompt_bool("Are you sure you want to lose all your data"):
manager.db.drop_all()
metadata, alembic_version = alembic_table_metadata()
alembic_version.drop()
manager.db.session.commit() | Drop database tables |
def ms_pan(self, viewer, event, data_x, data_y):
if not self.canpan:
return True
x, y = viewer.get_last_win_xy()
if event.state == 'move':
data_x, data_y = self.get_new_pan(viewer, x, y,
ptype=self._pantype)
viewer... | A 'drag' or proportional pan, where the image is panned by
'dragging the canvas' up or down. The amount of the pan is
proportionate to the length of the drag. |
def _ParseCachedEntry2003(self, value_data, cached_entry_offset):
try:
cached_entry = self._ReadStructureFromByteStream(
value_data[cached_entry_offset:], cached_entry_offset,
self._cached_entry_data_type_map)
except (ValueError, errors.ParseError) as exception:
raise errors.Pars... | Parses a Windows 2003 cached entry.
Args:
value_data (bytes): value data.
cached_entry_offset (int): offset of the first cached entry data
relative to the start of the value data.
Returns:
AppCompatCacheCachedEntry: cached entry.
Raises:
ParseError: if the value data cou... |
def read_secret(path, key=None):
log.debug('Reading Vault secret for %s at %s', __grains__['id'], path)
try:
url = 'v1/{0}'.format(path)
response = __utils__['vault.make_request']('GET', url)
if response.status_code != 200:
response.raise_for_status()
data = response.... | Return the value of key at path in vault, or entire secret
Jinja Example:
.. code-block:: jinja
my-secret: {{ salt['vault'].read_secret('secret/my/secret', 'some-key') }}
.. code-block:: jinja
{% set supersecret = salt['vault'].read_secret('secret/my/secret') %}
secrets:
... |
def parseerror(self, msg, line=None):
if line is None:
line = self.sline
error('parse error: ' + msg + ' on line {}'.format(line))
sys.exit(-2) | Emit parse error and abort assembly. |
def emitCurrentRecordEdited(self):
if self._changedRecord == -1:
return
if self.signalsBlocked():
return
record = self._changedRecord
self._changedRecord = -1
self.currentRecordEdited.emit(record) | Emits the current record edited signal for this combobox, provided the
signals aren't blocked and the record has changed since the last time. |
def transition_to_add(self):
assert self.state in [AQStateMachineStates.init, AQStateMachineStates.add]
self.state = AQStateMachineStates.add | Transition to add |
def sizeof_fmt(num):
units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB']
decimals = [0, 0, 1, 2, 2, 2]
if num > 1:
exponent = min(int(log(num, 1024)), len(units) - 1)
quotient = float(num) / 1024 ** exponent
unit = units[exponent]
num_decimals = decimals[exponent]
format_... | Turn number of bytes into human-readable str.
Parameters
----------
num : int
The number of bytes.
Returns
-------
size : str
The size in human-readable format. |
def save(self, filename, image_format="eps", width=8, height=6):
self.get_plot(width, height).savefig(filename, format=image_format) | Save the plot to an image file.
Args:
filename: Filename to save to.
image_format: Format to save to. Defaults to eps. |
def random_hex(length):
charset = ''.join(set(string.hexdigits.lower()))
return random_string(length, charset) | Return a random hex string.
:param int length: The length of string to return
:returns: A random string
:rtype: str |
def add_host_with_group(self, ip, mac, groupname):
msg = OmapiMessage.open(b"host")
msg.message.append(("create", struct.pack("!I", 1)))
msg.message.append(("exclusive", struct.pack("!I", 1)))
msg.obj.append(("hardware-address", pack_mac(mac)))
msg.obj.append(("hardware-type", struct.pack("!I", 1)))
msg.obj... | Adds a host with given ip and mac in a group named groupname
@type ip: str
@type mac: str
@type groupname: str |
def pop_scope(self, aliases, frame):
for name, alias in aliases.iteritems():
self.writeline('l_%s = %s' % (name, alias))
to_delete = set()
for name in frame.identifiers.declared_locally:
if name not in aliases:
to_delete.add('l_' + name)
if to_dele... | Restore all aliases and delete unused variables. |
def to_dict(self, index=True, ordered=False):
result = OrderedDict() if ordered else dict()
if index:
result.update({self._index_name: self._index})
if ordered:
data_dict = [(column, self._data[i]) for i, column in enumerate(self._columns)]
else:
data_... | Returns a dict where the keys are the column names and the values are lists of the values for that column.
:param index: If True then include the index in the dict with the index_name as the key
:param ordered: If True then return an OrderedDict() to preserve the order of the columns in the DataFrame
... |
def trace_region(self, region_index):
cmd = enums.JLinkTraceCommand.GET_REGION_PROPS_EX
region = structs.JLinkTraceRegion()
region.RegionIndex = int(region_index)
res = self._dll.JLINKARM_TRACE_Control(cmd, ctypes.byref(region))
if (res == 1):
raise errors.JLinkExcept... | Retrieves the properties of a trace region.
Args:
self (JLink): the ``JLink`` instance.
region_index (int): the trace region index.
Returns:
An instance of ``JLinkTraceRegion`` describing the specified region. |
def is_closest_date_parameter(task, param_name):
for name, obj in task.get_params():
if name == param_name:
return hasattr(obj, 'use_closest_date')
return False | Return the parameter class of param_name on task. |
def model_sizes(m:nn.Module, size:tuple=(64,64))->Tuple[Sizes,Tensor,Hooks]:
"Pass a dummy input through the model `m` to get the various sizes of activations."
with hook_outputs(m) as hooks:
x = dummy_eval(m, size)
return [o.stored.shape for o in hooks] | Pass a dummy input through the model `m` to get the various sizes of activations. |
def get_resource_value(self, device_id, resource_path, fix_path=True, timeout=None):
return self.get_resource_value_async(device_id, resource_path, fix_path).wait(timeout) | Get a resource value for a given device and resource path by blocking thread.
Example usage:
.. code-block:: python
try:
v = api.get_resource_value(device_id, path)
print("Current value", v)
except CloudAsyncError, e:
print("Erro... |
def automatic_density_by_vol(structure, kppvol, force_gamma=False):
vol = structure.lattice.reciprocal_lattice.volume
kppa = kppvol * vol * structure.num_sites
return Kpoints.automatic_density(structure, kppa,
force_gamma=force_gamma) | Returns an automatic Kpoint object based on a structure and a kpoint
density per inverse Angstrom^3 of reciprocal cell.
Algorithm:
Same as automatic_density()
Args:
structure (Structure): Input structure
kppvol (int): Grid density per Angstrom^(-3) of recipr... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.