code stringlengths 51 2.38k | docstring stringlengths 4 15.2k |
|---|---|
def get_branding(self, branding_id):
connection = Connection(self.token)
connection.set_url(self.production, self.BRANDINGS_ID_URL % branding_id)
return connection.get_request() | Get a concrete branding
@branding_id: Id of the branding to fetch
@return Branding |
def _event_funcs(self, event: str) -> Iterable[Callable]:
for func in self._events[event]:
yield func | Returns an Iterable of the functions subscribed to a event.
:param event: Name of the event.
:type event: str
:return: A iterable to do things with.
:rtype: Iterable |
def _api_itemvalue(self, plugin, item, value=None, history=False, nb=0):
response.content_type = 'application/json; charset=utf-8'
if plugin not in self.plugins_list:
abort(400, "Unknown plugin %s (available plugins: %s)" % (plugin, self.plugins_list))
self.__update__()
if va... | Father method for _api_item and _api_value. |
def nonoverlap(item_a, time_a, item_b, time_b, max_value):
return np.minimum(1 - item_a.count_overlap(time_a, item_b, time_b), max_value) / float(max_value) | Percentage of pixels in each object that do not overlap with the other object
Args:
item_a: STObject from the first set in ObjectMatcher
time_a: Time integer being evaluated
item_b: STObject from the second set in ObjectMatcher
time_b: Time integer being evaluated
max_value:... |
def focus_first_child(self):
w, focuspos = self.get_focus()
child = self._tree.first_child_position(focuspos)
if child is not None:
self.set_focus(child) | move focus to first child of currently focussed one |
def languages(self, key, value):
languages = self.get('languages', [])
values = force_list(value.get('a'))
for value in values:
for language in RE_LANGUAGE.split(value):
try:
name = language.strip().capitalize()
languages.append(pycountry.languages.get(nam... | Populate the ``languages`` key. |
def rightStatus(self, sheet):
'Compose right side of status bar.'
if sheet.currentThreads:
gerund = (' '+sheet.progresses[0].gerund) if sheet.progresses else ''
status = '%9d %2d%%%s' % (len(sheet), sheet.progressPct, gerund)
else:
status = '%9d %s' % (len(sh... | Compose right side of status bar. |
def get_consensus_at(self, block_id):
query = 'SELECT consensus_hash FROM snapshots WHERE block_id = ?;'
args = (block_id,)
con = self.db_open(self.impl, self.working_dir)
rows = self.db_query_execute(con, query, args, verbose=False)
res = None
for r in rows:
... | Get the consensus hash at a given block.
Return the consensus hash if we have one for this block.
Return None if we don't |
def search(self, params, standardize=False):
resp = self._request(ENDPOINTS['SEARCH'], params)
if not standardize:
return resp
for res in resp['result_data']:
res = self.standardize(res)
return resp | Get a list of person objects for the given search params.
:param params: Dictionary specifying the query parameters
:param standardize: Whether to standardize names and other features,
currently disabled for backwards compatibility. Currently
standardizes names, lowercases email... |
def bs_values_df(run_list, estimator_list, estimator_names, n_simulate,
**kwargs):
tqdm_kwargs = kwargs.pop('tqdm_kwargs', {'desc': 'bs values'})
assert len(estimator_list) == len(estimator_names), (
'len(estimator_list) = {0} != len(estimator_names = {1}'
.format(len(estimator_... | Computes a data frame of bootstrap resampled values.
Parameters
----------
run_list: list of dicts
List of nested sampling run dicts.
estimator_list: list of functions
Estimators to apply to runs.
estimator_names: list of strs
Name of each func in estimator_list.
n_simul... |
def createThreeObjects():
objectA = zip(range(10), range(10))
objectB = [(0, 0), (2, 2), (1, 1), (1, 4), (4, 2), (4, 1)]
objectC = [(0, 0), (1, 1), (3, 1), (0, 1)]
return [objectA, objectB, objectC] | Helper function that creates a set of three objects used for basic
experiments.
:return: (list(list(tuple)) List of lists of feature / location pairs. |
def _update_quoting_state(self, ch):
is_escaped = self.escaped
self.escaped = (not self.escaped and
ch == '\\' and
self.quotes != self.SQUOTE)
if self.escaped:
return ''
if is_escaped:
if self.quotes == self.DQUOTE:
... | Update self.quotes and self.escaped
:param ch: str, current character
:return: ch if it was not used to update quoting state, else '' |
def handle(self, data, **kwargs):
try:
if self.many:
return self.mapper.many(raw=self.raw, **self.mapper_kwargs).marshal(
data, role=self.role
)
else:
return self.mapper(
data=data,
... | Run marshalling for the specified mapper_class.
Supports both .marshal and .many().marshal Kim interfaces. Handles errors raised
during marshalling and automatically returns a HTTP error response.
:param data: Data to be marshaled.
:returns: Marshaled object according to mapper config... |
def path_from_row_pks(row, pks, use_rowid, quote=True):
if use_rowid:
bits = [row['rowid']]
else:
bits = [
row[pk]["value"] if isinstance(row[pk], dict) else row[pk]
for pk in pks
]
if quote:
bits = [urllib.parse.quote_plus(str(bit)) for bit in bits]
... | Generate an optionally URL-quoted unique identifier
for a row from its primary keys. |
def get_int(self):
token = self.get().unescape()
if not token.is_identifier():
raise dns.exception.SyntaxError('expecting an identifier')
if not token.value.isdigit():
raise dns.exception.SyntaxError('expecting an integer')
return int(token.value) | Read the next token and interpret it as an integer.
@raises dns.exception.SyntaxError:
@rtype: int |
def watch(self, keys, on_watch, filters=None, start_revision=None, return_previous=None):
d = self._start_watching(keys, on_watch, filters, start_revision, return_previous)
def on_err(*args):
if args[0].type not in [CancelledError, ResponseFailed]:
self.log.warn('etcd watch t... | Watch one or more keys or key sets and invoke a callback.
Watch watches for events happening or that have happened. The entire event history
can be watched starting from the last compaction revision.
:param keys: Watch these keys / key sets.
:type keys: list of bytes or list of instanc... |
def _checkReturnTo(self, message, return_to):
try:
self._verifyReturnToArgs(message.toPostArgs())
except ProtocolError as why:
logging.exception("Verifying return_to arguments: %s" % (why, ))
return False
msg_return_to = message.getArg(OPENID_NS, 'return_to')
... | Check an OpenID message and its openid.return_to value
against a return_to URL from an application. Return True on
success, False on failure. |
def structure_repr(self):
ret = '{%s}' % ', '.join([str(x) for x in self.elements])
return self._wrap_packed(ret) | Return the LLVM IR for the structure representation |
def in_group(self, group, dn=False):
if dn:
return group in self.groups()
return group.check_member(self) | Get whether or not the bound CSH LDAP member object is part of a
group.
Arguments:
group -- the CSHGroup object (or distinguished name) of the group to
check membership for |
def set_pending_symbol(self, pending_symbol=None):
if pending_symbol is None:
pending_symbol = CodePointArray()
self.value = bytearray()
self.pending_symbol = pending_symbol
self.line_comment = False
return self | Sets the context's ``pending_symbol`` with the given unicode sequence and resets the context's ``value``.
If the input is None, an empty :class:`CodePointArray` is used. |
def write_params(path, *args, **dicts):
path = Path(path)
if not path.parent.is_dir():
path.parent.mkdir(parents=True)
if len(args) == 1:
d = args[0]
with path.open('w') as f:
for key in d:
f.write(key + ' = ' + str(d[key]) + '\n')
else:
with p... | Write parameters to file, so that it's readable by read_params.
Uses INI file format. |
def check_for_stalled_tasks():
from api.models.tasks import Task
for task in Task.objects.filter(status_is_running=True):
if not task.is_responsive():
task.system_error()
if task.is_timed_out():
task.timeout_error() | Check for tasks that are no longer sending a heartbeat |
def all(self, paths, access=None):
self.failures = [path for path in paths if not
isvalid(path, access, filetype='all')]
return not self.failures | Verify list of paths |
def expanduser(path):
if hdfs_fs.default_is_local():
return os.path.expanduser(path)
m = re.match(r'^~([^/]*)', path)
if m is None:
return path
user = m.groups()[0] or common.DEFAULT_USER
return '/user/%s%s' % (user, path[m.end(1):]) | Replace initial ``~`` or ``~user`` with the user's home directory.
**NOTE:** if the default file system is HDFS, the ``~user`` form is
expanded regardless of the user's existence. |
def to_dict(obj):
json_obj = {'type' : repr(obj)}
if obj.is_failed:
json_obj['errors'] = obj.errors
elif obj.is_success:
json_obj['modelOutput'] = obj.model_output
return json_obj | Generate a JSON serialization for the run state object.
Returns
-------
Json-like object
Json serialization of model run state object |
def _has_argument(func):
if hasattr(inspect, 'signature'):
sig = inspect.signature(func)
return bool(sig.parameters)
else:
return bool(inspect.getargspec(func).args) | Test whether a function expects an argument.
:param func:
The function to be tested for existence of an argument. |
def authInsert(user, role, group, site):
if not role: return True
for k, v in user['roles'].iteritems():
for g in v['group']:
if k in role.get(g, '').split(':'):
return True
return False | Authorization function for general insert |
def register_metric_descriptor(self, oc_md):
metric_type = self.get_metric_type(oc_md)
with self._md_lock:
if metric_type in self._md_cache:
return self._md_cache[metric_type]
descriptor = self.get_metric_descriptor(oc_md)
project_name = self.client.project_pa... | Register a metric descriptor with stackdriver. |
def group(self):
"Group inherited from items"
if self._group:
return self._group
group = get_ndmapping_label(self, 'group') if len(self) else None
if group is None:
return type(self).__name__
return group | Group inherited from items |
def triads(key):
if _triads_cache.has_key(key):
return _triads_cache[key]
res = map(lambda x: triad(x, key), keys.get_notes(key))
_triads_cache[key] = res
return res | Return all the triads in key.
Implemented using a cache. |
def _create_storage_profile(self):
if self.image_publisher:
storage_profile = {
'image_reference': {
'publisher': self.image_publisher,
'offer': self.image_offer,
'sku': self.image_sku,
'version': self.im... | Create the storage profile for the instance.
Image reference can be a custom image name or a published urn. |
def install_extension(conn, extension: str):
query = 'CREATE EXTENSION IF NOT EXISTS "%s";'
with conn.cursor() as cursor:
cursor.execute(query, (AsIs(extension),))
installed = check_extension(conn, extension)
if not installed:
raise psycopg2.ProgrammingError(
'Postgres extens... | Install Postgres extension. |
def __get_jp(self, extractor_processor, sub_output=None):
if sub_output is None and extractor_processor.output_field is None:
raise ValueError(
"ExtractorProcessors input paths cannot be unioned across fields. Please specify either a sub_output or use a single scalar output_field")
... | Tries to get name from ExtractorProcessor to filter on first.
Otherwise falls back to filtering based on its metadata |
def roll(self, shifts=None, roll_coords=None, **shifts_kwargs):
ds = self._to_temp_dataset().roll(
shifts=shifts, roll_coords=roll_coords, **shifts_kwargs)
return self._from_temp_dataset(ds) | Roll this array by an offset along one or more dimensions.
Unlike shift, roll may rotate all variables, including coordinates
if specified. The direction of rotation is consistent with
:py:func:`numpy.roll`.
Parameters
----------
roll_coords : bool
Indicates... |
def append_surface(self, name, surface, alpha=1.):
self.insert_surface(position=self.df_surfaces.index.shape[0],
name=name, surface=surface, alpha=alpha) | Append Cairo surface as new layer on top of existing layers.
Args
----
name (str) : Name of layer.
surface (cairo.ImageSurface) : Surface to render.
alpha (float) : Alpha/transparency level in the range `[0, 1]`. |
def resize(self, targ_sz, new_path='tmp', resume=True, fn=None):
new_ds = []
dls = [self.trn_dl,self.val_dl,self.fix_dl,self.aug_dl]
if self.test_dl: dls += [self.test_dl, self.test_aug_dl]
else: dls += [None,None]
t = tqdm_notebook(dls)
for dl in t: new_ds.append(self.re... | Resizes all the images in the train, valid, test folders to a given size.
Arguments:
targ_sz (int): the target size
new_path (str): the path to save the resized images (default tmp)
resume (bool): if True, check for images in the DataSet that haven't been resized yet (useful if a previo... |
def deploy(self, machine):
log.debug("machine id: %s." % machine)
path = self.path + "/machines"
value, metadata = yield self.client.get(path)
machines = json.loads(value)
machines.append(machine)
yield self.client.set(path, json.dumps(machines)) | Deploy service. |
def query_all(kind='1', by_count=False, by_order=True):
if by_count:
recs = TabTag.select().where(TabTag.kind == kind).order_by(TabTag.count.desc())
elif by_order:
recs = TabTag.select().where(TabTag.kind == kind).order_by(TabTag.order)
else:
recs = TabTag.sel... | Qeury all the categories, order by count or defined order. |
def sample(self, fraction, seed=None, exact=False):
if (fraction > 1 or fraction < 0):
raise ValueError('Invalid sampling rate: ' + str(fraction))
if (len(self) == 0):
return SArray()
if seed is None:
seed = abs(hash("%0.20f" % time.time())) % (2 ** 31)
... | Create an SArray which contains a subsample of the current SArray.
Parameters
----------
fraction : float
Fraction of the rows to fetch. Must be between 0 and 1.
if exact is False (default), the number of rows returned is
approximately the fraction times the ... |
def create(self, unique_name, domain_suffix=values.unset):
data = values.of({'UniqueName': unique_name, 'DomainSuffix': domain_suffix, })
payload = self._version.create(
'POST',
self._uri,
data=data,
)
return EnvironmentInstance(self._version, payload,... | Create a new EnvironmentInstance
:param unicode unique_name: The unique_name
:param unicode domain_suffix: The domain_suffix
:returns: Newly created EnvironmentInstance
:rtype: twilio.rest.serverless.v1.service.environment.EnvironmentInstance |
def findCampaigns(ra, dec):
logger.disabled = True
campaigns_visible = []
for c in fields.getFieldNumbers():
fovobj = fields.getKeplerFov(c)
if onSiliconCheck(ra, dec, fovobj):
campaigns_visible.append(c)
logger.disabled = True
return campaigns_visible | Returns a list of the campaigns that cover a given position.
Parameters
----------
ra, dec : float, float
Position in decimal degrees (J2000).
Returns
-------
campaigns : list of int
A list of the campaigns that cover the given position. |
def get_aa_code(aa_letter):
aa_code = None
if aa_letter != 'X':
for key, val in standard_amino_acids.items():
if key == aa_letter:
aa_code = val
return aa_code | Get three-letter aa code if possible. If not, return None.
If three-letter code is None, will have to find this later from the filesystem.
Parameters
----------
aa_letter : str
One-letter amino acid code.
Returns
-------
aa_code : str, or None
Three-letter aa code. |
def make_bubble_surface(dims=DEFAULT_DIMS, repeat=3):
gradients = make_gradients(dims)
return (
np.sin((gradients[0] - 0.5) * repeat * np.pi) *
np.sin((gradients[1] - 0.5) * repeat * np.pi)) | Makes a surface from the product of sine functions on each axis.
Args:
dims (pair): the dimensions of the surface to create
repeat (int): the frequency of the waves is set to ensure this many
repetitions of the function
Returns:
surface: A surface. |
def relpath(self):
cwd = self.__class__(os.getcwd())
return cwd.relpathto(self) | Return this path as a relative path,
based from the current working directory. |
def process_template(self, sql, **kwargs):
template = self.env.from_string(sql)
kwargs.update(self.context)
return template.render(kwargs) | Processes a sql template
>>> sql = "SELECT '{{ datetime(2017, 1, 1).isoformat() }}'"
>>> process_template(sql)
"SELECT '2017-01-01T00:00:00'" |
def _update_feature_log_prob(self, alpha):
smoothed_fc = self.feature_count_ + alpha
smoothed_cc = self.class_count_ + alpha * 2
self.feature_log_prob_ = (np.log(smoothed_fc) -
np.log(smoothed_cc.reshape(-1, 1))) | Apply smoothing to raw counts and recompute log probabilities |
def _options(self):
if self._options_cache is None:
target_url = self.client.get_url(self._URL_KEY, 'OPTIONS', 'options')
r = self.client.request('OPTIONS', target_url)
self._options_cache = r.json()
return self._options_cache | Returns a raw options object
:rtype: dict |
def _output(self, s):
if s.lower().startswith(b'host: '):
self._buffer.insert(1, s)
else:
self._buffer.append(s) | Host header should always be first |
def format_explanation(explanation, original_msg=None):
if not conf.is_message_introspection_enabled() and original_msg:
return original_msg
explanation = ecu(explanation)
lines = _split_explanation(explanation)
result = _format_lines(lines)
return u('\n').join(result) | This formats an explanation
Normally all embedded newlines are escaped, however there are
three exceptions: \n{, \n} and \n~. The first two are intended
cover nested explanations, see function and attribute explanations
for examples (.visit_Call(), visit_Attribute()). The last one is
for when one... |
def packageGraph(self, packagelevel=None):
packages = {}
for module in self.listModules():
package_name = self.packageOf(module.modname, packagelevel)
if package_name not in packages:
dirname = os.path.dirname(module.filename)
packages[package_name... | Convert a module graph to a package graph. |
def register_path(self, path, modified_time=None):
if not foundations.common.path_exists(path):
raise foundations.exceptions.PathExistsError("{0} | '{1}' path doesn't exists!".format(
self.__class__.__name__, path))
if path in self:
raise umbra.exceptions.PathRegi... | Registers given path.
:param path: Path name.
:type path: unicode
:param modified_time: Custom modified time.
:type modified_time: int or float
:return: Method success.
:rtype: bool |
def change_and_save(self, update_only_changed_fields=False, **changed_fields):
bulk_change_and_save(self, update_only_changed_fields=update_only_changed_fields, **changed_fields)
return self.filter() | Changes a given `changed_fields` on each object in the queryset, saves objects
and returns the changed objects in the queryset. |
def build_pages(self):
for root, _, files in os.walk(self.pages_dir):
base_dir = root.replace(self.pages_dir, "").lstrip("/")
if not base_dir.startswith("_"):
for f in files:
src_file = os.path.join(base_dir, f)
self._build_page(src... | Iterate over the pages_dir and build the pages |
def _pass_variable(self):
pass_var = []
for var in os.environ.keys():
expVAR = var.split("_")
if expVAR[0] == self.prgnam.upper() and expVAR[1] != "PATH":
pass_var.append("{0}={1}".format(expVAR[1], os.environ[var]))
return pass_var | Return enviroment variables |
def getAllSecrets(version="", region=None, table="credential-store",
context=None, credential=None, session=None, **kwargs):
if session is None:
session = get_session(**kwargs)
dynamodb = session.resource('dynamodb', region_name=region)
kms = session.client('kms', region_name=regio... | fetch and decrypt all secrets |
def is_gentarget(self, target):
if self.gentarget_type:
return isinstance(target, self.gentarget_type)
else:
raise NotImplementedError | Predicate which determines whether the target in question is relevant to this codegen task.
E.g., the JaxbGen task considers JaxbLibrary targets to be relevant, and nothing else.
:API: public
:param Target target: The target to check.
:return: True if this class can generate code for the given target... |
def _parse_throttle(self, tablename, throttle):
amount = []
desc = self.describe(tablename)
throughputs = [desc.read_throughput, desc.write_throughput]
for value, throughput in zip(throttle[1:], throughputs):
if value == "*":
amount.append(0)
elif ... | Parse a 'throttle' statement and return a RateLimit |
def _reset(self, force=False):
if not self._closed and (force or self._transaction):
try:
self.rollback()
except Exception:
pass | Reset a tough connection.
Rollback if forced or the connection was in a transaction. |
def perimeter(self):
if self._is_completely_masked:
return np.nan * u.pix
else:
from skimage.measure import perimeter
return perimeter(~self._total_mask, neighbourhood=4) * u.pix | The total perimeter of the source segment, approximated lines
through the centers of the border pixels using a 4-connectivity.
If any masked pixels make holes within the source segment, then
the perimeter around the inner hole (e.g. an annulus) will also
contribute to the total perimete... |
def make_json_formatter(graph):
return {
"()": graph.config.logging.json_formatter.formatter,
"fmt": graph.config.logging.json_required_keys,
} | Create the default json formatter. |
def vault_file(env, default):
home = os.environ['HOME'] if 'HOME' in os.environ else \
os.environ['USERPROFILE']
filename = os.environ.get(env, os.path.join(home, default))
filename = abspath(filename)
if os.path.exists(filename):
return filename
return None | The path to a misc Vault file
This function will check for the env override on a file
path, compute a fully qualified OS appropriate path to
the desired file and return it if it exists. Otherwise
returns None |
def parse_routing_info(cls, records):
if len(records) != 1:
raise RoutingProtocolError("Expected exactly one record")
record = records[0]
routers = []
readers = []
writers = []
try:
servers = record["servers"]
for server in servers:
... | Parse the records returned from a getServers call and
return a new RoutingTable instance. |
def average_sharded_losses(sharded_losses):
losses = {}
for loss_name in sorted(sharded_losses[0]):
all_shards = [shard_losses[loss_name] for shard_losses in sharded_losses]
if isinstance(all_shards[0], tuple):
sharded_num, sharded_den = zip(*all_shards)
mean_loss = (
tf.add_n(sharded_... | Average losses across datashards.
Args:
sharded_losses: list<dict<str loss_name, Tensor loss>>. The loss
can be a single Tensor or a 2-tuple (numerator and denominator).
Returns:
losses: dict<str loss_name, Tensor avg_loss> |
def load_scene(self, item):
scene = Scene.from_config(self.pyvlx, item)
self.add(scene) | Load scene from json. |
def get_errors(self):
return [{cr.component_name: cr.get_error()}
for cr in self.component_results if cr.has_error()] | If there were any business errors fetching data for this property,
returns the error messages.
Returns:
string - the error message, or None if there was no error. |
def delete_multireddit(self, name, *args, **kwargs):
url = self.config['multireddit_about'].format(user=self.user.name,
multi=name)
if not self._use_oauth:
self.http.headers['x-modhash'] = self.modhash
try:
self.reques... | Delete a Multireddit.
Any additional parameters are passed directly into
:meth:`~praw.__init__.BaseReddit.request` |
def update(self):
args = {attr: getattr(self, attr) for attr in self.to_update}
_perform_command(self, 'user_update', args) | Update the user's details on Todoist.
This method must be called to register any local attribute changes
with Todoist.
>>> from pytodoist import todoist
>>> user = todoist.login('john.doe@gmail.com', 'password')
>>> user.full_name = 'John Smith'
>>> # At this point Todo... |
def enable_key(self):
print("This command will enable a disabled key.")
apiKeyID = input("API Key ID: ")
try:
key = self._curl_bitmex("/apiKey/enable",
postdict={"apiKeyID": apiKeyID})
print("Key with ID %s enabled." % key["id"])
... | Enable an existing API Key. |
def upload_keys(self, device_keys=None, one_time_keys=None):
content = {}
if device_keys:
content["device_keys"] = device_keys
if one_time_keys:
content["one_time_keys"] = one_time_keys
return self._send("POST", "/keys/upload", content=content) | Publishes end-to-end encryption keys for the device.
Said device must be the one used when logging in.
Args:
device_keys (dict): Optional. Identity keys for the device. The required
keys are:
| user_id (str): The ID of the user the device belongs to. Must m... |
def form(cls, name, type_=Type.String, description=None, required=None, default=None,
minimum=None, maximum=None, enum=None, **options):
if minimum is not None and maximum is not None and minimum > maximum:
raise ValueError("Minimum must be less than or equal to the maximum.")
r... | Define form parameter. |
def answer_approval(self, issue_id_or_key, approval_id, decision):
url = 'rest/servicedeskapi/request/{0}/approval/{1}'.format(issue_id_or_key, approval_id)
data = {'decision': decision}
return self.post(url, headers=self.experimental_headers, data=data) | Answer a pending approval
:param issue_id_or_key: str
:param approval_id: str
:param decision: str
:return: |
def html_to_text(html, base_url='', bodywidth=CONFIG_DEFAULT):
def _patched_handle_charref(c):
self = h
charref = self.charref(c)
if self.code or self.pre:
charref = cgi.escape(charref)
self.o(charref, 1)
def _patched_handle_entityref(c):
self = h
enti... | Convert a HTML mesasge to plain text. |
def importTTX(self):
import os
import re
prefix = "com.github.fonttools.ttx"
sfntVersionRE = re.compile('(^<ttFont\s+)(sfntVersion=".*"\s+)(.*>$)',
flags=re.MULTILINE)
if not hasattr(self.ufo, "data"):
return
if not self.ufo.... | Merge TTX files from data directory "com.github.fonttools.ttx"
**This should not be called externally.** Subclasses
may override this method to handle the bounds creation
in a different way if desired. |
def FoldValue(self, value):
if value is False and self._data_type_definition.false_value is not None:
return self._data_type_definition.false_value
if value is True and self._data_type_definition.true_value is not None:
return self._data_type_definition.true_value
raise ValueError('No matching T... | Folds the data type into a value.
Args:
value (object): value.
Returns:
object: folded value.
Raises:
ValueError: if the data type definition cannot be folded into the value. |
def bounding_ellipses(self):
if (self.linear_growth):
a1 = self.sma - self.astep / 2.
a2 = self.sma + self.astep / 2.
else:
a1 = self.sma * (1. - self.astep / 2.)
a2 = self.sma * (1. + self.astep / 2.)
return a1, a2 | Compute the semimajor axis of the two ellipses that bound the
annulus where integrations take place.
Returns
-------
sma1, sma2 : float
The smaller and larger values of semimajor axis length that
define the annulus bounding ellipses. |
def vectorize_utterance_ohe(self, utterance):
for i, word in enumerate(utterance):
if not word in self.vocab_list:
utterance[i] = '<unk>'
ie_utterance = self.swap_pad_and_zero(self.ie.transform(utterance))
ohe_utterance = np.array(self.ohe.transform(ie_utterance.resha... | Take in a tokenized utterance and transform it into a sequence of one-hot vectors |
def add_data(self, rawdata):
for data in rawdata:
try:
item = data[0]
if item[0] == 2:
continue
if item[0] != 0:
warnings.warn(f"Unknown message type '{item[0]}'", Warning)
continue
... | Add data to given room's state |
def get_high_water_mark(self, mark_type, obstory_name=None):
if obstory_name is None:
obstory_name = self.obstory_name
obstory = self.get_obstory_from_name(obstory_name)
key_id = self.get_hwm_key_id(mark_type)
self.con.execute('SELECT time FROM archive_highWaterMarks WHERE ma... | Retrieves the high water mark for a given obstory, defaulting to the current installation ID
:param string mark_type:
The type of high water mark to set
:param string obstory_name:
The obstory ID to check for, or the default installation ID if not specified
:return:
... |
def active_serving_watcher(backend, kitchen, period):
err_str, use_kitchen = Backend.get_kitchen_from_user(kitchen)
if use_kitchen is None:
raise click.ClickException(err_str)
click.secho('%s - Watching Active OrderRun Changes in Kitchen %s' % (get_datetime(), use_kitchen), fg='green')
DKCloudCo... | Watches all cooking Recipes in a Kitchen
Provide the kitchen name as an argument or be in a Kitchen folder. |
def register_phonon_task(self, *args, **kwargs):
kwargs["task_class"] = PhononTask
return self.register_task(*args, **kwargs) | Register a phonon task. |
def set_blocking(fd, blocking=True):
old_flag = fcntl.fcntl(fd, fcntl.F_GETFL)
if blocking:
new_flag = old_flag & ~ os.O_NONBLOCK
else:
new_flag = old_flag | os.O_NONBLOCK
fcntl.fcntl(fd, fcntl.F_SETFL, new_flag)
return not bool(old_flag & os.O_NONBLOCK) | Set the given file-descriptor blocking or non-blocking.
Returns the original blocking status. |
def posttrans_hook(conduit):
if 'SALT_RUNNING' not in os.environ:
with open(CK_PATH, 'w') as ck_fh:
ck_fh.write('{chksum} {mtime}\n'.format(chksum=_get_checksum(), mtime=_get_mtime())) | Hook after the package installation transaction.
:param conduit:
:return: |
def create_magic_packet(macaddress):
if len(macaddress) == 12:
pass
elif len(macaddress) == 17:
sep = macaddress[2]
macaddress = macaddress.replace(sep, '')
else:
raise ValueError('Incorrect MAC address format')
data = b'FFFFFFFFFFFF' + (macaddress * 16).encode()
send... | Create a magic packet.
A magic packet is a packet that can be used with the for wake on lan
protocol to wake up a computer. The packet is constructed from the
mac address given as a parameter.
Args:
macaddress (str): the mac address that should be parsed into a
magic packet. |
def parse_chains(data):
chains = odict()
for line in data.splitlines(True):
m = re_chain.match(line)
if m:
policy = None
if m.group(2) != '-':
policy = m.group(2)
chains[m.group(1)] = {
'policy': policy,
'packets... | Parse the chain definitions. |
def stress(ref_cds, est_cds):
ref_dists = pdist(ref_cds)
est_dists = pdist(est_cds)
return np.sqrt(((ref_dists - est_dists)**2).sum() / (ref_dists**2).sum()) | Kruskal's stress |
def response(self, component_id, component=None, **kwargs):
if component_id in self._responses:
raise DuplicateComponentNameError(
'Another response with name "{}" is already registered.'.format(
component_id
)
)
component = com... | Add a response which can be referenced.
:param str component_id: ref_id to use as reference
:param dict component: response fields
:param dict kwargs: plugin-specific arguments |
def DomainFactory(domain_name, cmds):
klass = type(str(domain_name), (BaseDomain,), {})
for c in cmds:
command = get_command(domain_name, c['name'])
setattr(klass, c['name'], classmethod(command))
return klass | Dynamically create Domain class and set it's methods. |
def zpopmax(self, name, count=None):
args = (count is not None) and [count] or []
options = {
'withscores': True
}
return self.execute_command('ZPOPMAX', name, *args, **options) | Remove and return up to ``count`` members with the highest scores
from the sorted set ``name``. |
async def restart(request):
def wait_and_restart():
log.info('Restarting server')
sleep(1)
os.system('kill 1')
Thread(target=wait_and_restart).start()
return web.json_response({"message": "restarting"}) | Returns OK, then waits approximately 1 second and restarts container |
def com_google_fonts_check_glyf_unused_data(ttFont):
try:
expected_glyphs = len(ttFont.getGlyphOrder())
actual_glyphs = len(ttFont['glyf'].glyphs)
diff = actual_glyphs - expected_glyphs
if diff < 0:
yield FAIL, Message("unreachable-data",
("Glyf table has unreachable da... | Is there any unused data at the end of the glyf table? |
def create_with_dst_resource_provisioning(
cls, cli, src_resource_id, dst_resource_config,
max_time_out_of_sync, name=None, remote_system=None,
src_spa_interface=None, src_spb_interface=None,
dst_spa_interface=None, dst_spb_interface=None,
dst_resource_element... | Create a replication session along with destination resource
provisioning.
:param cli: the rest cli.
:param src_resource_id: id of the replication source, could be
lun/fs/cg.
:param dst_resource_config: `UnityResourceConfig` object. The user
chosen config for des... |
def render_tree(root, child_func, prune=0, margin=[0], visited=None):
rname = str(root)
if visited is None:
visited = {}
children = child_func(root)
retval = ""
for pipe in margin[:-1]:
if pipe:
retval = retval + "| "
else:
retval = retval + " "
i... | Render a tree of nodes into an ASCII tree view.
:Parameters:
- `root`: the root node of the tree
- `child_func`: the function called to get the children of a node
- `prune`: don't visit the same node twice
- `margin`: the format of the left margin to use for children ... |
def setups(self):
result = []
has_options = self.base_object.is_optionhandler
enm = javabridge.get_enumeration_wrapper(javabridge.call(self.jobject, "setups", "()Ljava/util/Enumeration;"))
while enm.hasMoreElements():
if has_options:
result.append(OptionHandle... | Generates and returns all the setups according to the parameter search space.
:return: the list of configured objects (of type JavaObject)
:rtype: list |
def solution_violations(solution, events, slots):
array = converter.solution_to_array(solution, events, slots)
return array_violations(array, events, slots) | Take a solution and return a list of violated constraints
Parameters
----------
solution: list or tuple
a schedule in solution form
events : list or tuple
of resources.Event instances
slots : list or tuple
of resources.Slot instances
Returns
... |
def temp_path(file_name=None):
if file_name is None:
file_name = generate_timestamped_string("wtf_temp_file")
return os.path.join(tempfile.gettempdir(), file_name) | Gets a temp path.
Kwargs:
file_name (str) : if file name is specified, it gets appended to the temp dir.
Usage::
temp_file_path = temp_path("myfile")
copyfile("myfile", temp_file_path) # copies 'myfile' to '/tmp/myfile' |
def flush(self):
for key in self.grouping_info.keys():
if self._should_flush(key):
self._write_current_buffer_for_group_key(key) | Ensure all remaining buffers are written. |
def screenshot(self):
b64data = self.http.get('/screenshot').value
raw_data = base64.b64decode(b64data)
from PIL import Image
buff = io.BytesIO(raw_data)
return Image.open(buff) | Take screenshot with session check
Returns:
PIL.Image |
def load(path, service=None, hostport=None, module_name=None):
if not path.endswith('.thrift'):
service, path = path, service
module = thriftrw.load(path=path, name=module_name)
return TChannelThriftModule(service, module, hostport) | Loads the Thrift file at the specified path.
The file is compiled in-memory and a Python module containing the result
is returned. It may be used with ``TChannel.thrift``. For example,
.. code-block:: python
from tchannel import TChannel, thrift
# Load our server's interface definition.
... |
def fix_facets(self):
facets = self.facets
for key in list(facets.keys()):
_type = facets[key].get("_type", "unknown")
if _type == "date_histogram":
for entry in facets[key].get("entries", []):
for k, v in list(entry.items()):
... | This function convert date_histogram facets to datetime |
def convert_units_to_base_units(units):
total_factor = 1
new_units = []
for unit in units:
if unit not in BASE_UNIT_CONVERSIONS:
continue
factor, new_unit = BASE_UNIT_CONVERSIONS[unit]
total_factor *= factor
new_units.append(new_unit)
new_units.sort()
retu... | Convert a set of units into a set of "base" units.
Returns a 2-tuple of `factor, new_units`. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.