code stringlengths 51 2.38k | docstring stringlengths 4 15.2k |
|---|---|
def push_uci(self, uci: str) -> Move:
move = self.parse_uci(uci)
self.push(move)
return move | Parses a move in UCI notation and puts it on the move stack.
Returns the move.
:raises: :exc:`ValueError` if the move is invalid or illegal in the
current position (but not a null move). |
def lemma(lemma_key):
if lemma_key in LEMMAS_DICT:
return LEMMAS_DICT[lemma_key]
split_lemma_key = lemma_key.split('.')
synset_key = '.'.join(split_lemma_key[:3])
lemma_literal = split_lemma_key[3]
lemma_obj = Lemma(synset_key,lemma_literal)
LEMMAS_DICT[lemma_key] = lemma_obj
return ... | Returns the Lemma object with the given key.
Parameters
----------
lemma_key : str
Key of the returned lemma.
Returns
-------
Lemma
Lemma matching the `lemma_key`. |
def parent_org_sdo_ids(self):
return [sdo.get_owner()._narrow(SDOPackage.SDO).get_sdo_id() \
for sdo in self._obj.get_organizations() if sdo] | The SDO IDs of the compositions this RTC belongs to. |
def _on_shortcut_changed(self, renderer, path, new_shortcuts):
action = self.shortcut_list_store[int(path)][self.KEY_STORAGE_ID]
old_shortcuts = self.gui_config_model.get_current_config_value("SHORTCUTS", use_preliminary=True)[action]
from ast import literal_eval
try:
new_sho... | Callback handling a change of a shortcut
:param Gtk.CellRenderer renderer: Cell renderer showing the shortcut
:param path: Path of shortcuts within the list store
:param str new_shortcuts: New shortcuts |
def mtxvg(m1, v2, ncol1, nr1r2):
m1 = stypes.toDoubleMatrix(m1)
v2 = stypes.toDoubleVector(v2)
ncol1 = ctypes.c_int(ncol1)
nr1r2 = ctypes.c_int(nr1r2)
vout = stypes.emptyDoubleVector(ncol1.value)
libspice.mtxvg_c(m1, v2, ncol1, nr1r2, vout)
return stypes.cVectorToPython(vout) | Multiply the transpose of a matrix and
a vector of arbitrary size.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/mtxvg_c.html
:param m1: Left-hand matrix to be multiplied.
:type m1: NxM-Element Array of floats
:param v2: Right-hand vector to be multiplied.
:type v2: Array of floats
... |
def get_model(app_label, model_name):
try:
from django.apps import apps
from django.core.exceptions import AppRegistryNotReady
except ImportError:
from django.db import models
return models.get_model(app_label, model_name)
try:
return apps.get_model(app_label, model_n... | Fetches a Django model using the app registry.
This doesn't require that an app with the given app label exists, which
makes it safe to call when the registry is being populated. All other
methods to access models might raise an exception about the registry not
being ready yet.
Raises LookupError ... |
def nanstd(values, axis=None, skipna=True, ddof=1, mask=None):
result = np.sqrt(nanvar(values, axis=axis, skipna=skipna, ddof=ddof,
mask=mask))
return _wrap_results(result, values.dtype) | Compute the standard deviation along given axis while ignoring NaNs
Parameters
----------
values : ndarray
axis: int, optional
skipna : bool, default True
ddof : int, default 1
Delta Degrees of Freedom. The divisor used in calculations is N - ddof,
where N represents the number ... |
def explode(col):
sc = SparkContext._active_spark_context
jc = sc._jvm.functions.explode(_to_java_column(col))
return Column(jc) | Returns a new row for each element in the given array or map.
Uses the default column name `col` for elements in the array and
`key` and `value` for elements in the map unless specified otherwise.
>>> from pyspark.sql import Row
>>> eDF = spark.createDataFrame([Row(a=1, intlist=[1,2,3], mapfield={"a": ... |
def variable_summaries(vars_, groups=None, scope='weights'):
groups = groups or {r'all': r'.*'}
grouped = collections.defaultdict(list)
for var in vars_:
for name, pattern in groups.items():
if re.match(pattern, var.name):
name = re.sub(pattern, name, var.name)
grouped[name].append(var)
... | Create histogram summaries for the provided variables.
Summaries can be grouped via regexes matching variables names.
Args:
vars_: List of variables to summarize.
groups: Mapping of name to regex for grouping summaries.
scope: Name scope for this operation.
Returns:
Summary tensor. |
def read_name(source, position):
body = source.body
body_length = len(body)
end = position + 1
while end != body_length:
code = char_code_at(body, end)
if not (
code is not None
and (
code == 95
or 48 <= code <= 57
o... | Reads an alphanumeric + underscore name from the source.
[_A-Za-z][_0-9A-Za-z]* |
def get_lat_lon_time_from_nmea(nmea_file, local_time=True):
with open(nmea_file, "r") as f:
lines = f.readlines()
lines = [l.rstrip("\n\r") for l in lines]
for l in lines:
if "GPRMC" in l:
data = pynmea2.parse(l)
date = data.datetime.date()
break
p... | Read location and time stamps from a track in a NMEA file.
Returns a list of tuples (time, lat, lon).
GPX stores time in UTC, by default we assume your camera used the local time
and convert accordingly. |
def RebuildHttpConnections(http):
if getattr(http, 'connections', None):
for conn_key in list(http.connections.keys()):
if ':' in conn_key:
del http.connections[conn_key] | Rebuilds all http connections in the httplib2.Http instance.
httplib2 overloads the map in http.connections to contain two different
types of values:
{ scheme string: connection class } and
{ scheme + authority string : actual http connection }
Here we remove all of the entries for actual connecti... |
def MakeRequest(self, data):
stats_collector_instance.Get().IncrementCounter("grr_client_sent_bytes",
len(data))
response = self.http_manager.OpenServerEndpoint(
path="control?api=%s" % config.CONFIG["Network.api"],
verify_cb=self.VerifyServerC... | Make a HTTP Post request to the server 'control' endpoint. |
def compute_norrec_differences(df, keys_diff):
raise Exception('This function is depreciated!')
print('computing normal-reciprocal differences')
def norrec_diff(x):
if x.shape[0] != 2:
return np.nan
else:
return np.abs(x.iloc[1] - x.iloc[0])
keys_keep = list(set(d... | DO NOT USE ANY MORE - DEPRECIATED! |
def create(
self,
order_increment_id,
creditmemo_data=None,
comment=None,
email=False,
include_comment=False,
refund_to_store_credit_amount=None):
if comment is None:
comment = ''
return self.call(
... | Create new credit_memo for order
:param order_increment_id: Order Increment ID
:type order_increment_id: str
:param creditmemo_data: Sales order credit memo data (optional)
:type creditmemo_data: associative array as dict
{
'qtys': [
{
... |
def find_d2ifile(flist,detector):
d2ifile = None
for f in flist:
fdet = fits.getval(f, 'detector', memmap=False)
if fdet == detector:
d2ifile = f
return d2ifile | Search a list of files for one that matches the detector specified. |
def get_ride_details(api_client, ride_id):
try:
ride_details = api_client.get_ride_details(ride_id)
except (ClientError, ServerError) as error:
fail_print(error)
else:
success_print(ride_details.json) | Use an UberRidesClient to get ride details and print the results.
Parameters
api_client (UberRidesClient)
An authorized UberRidesClient with 'request' scope.
ride_id (str)
Unique ride identifier. |
def get_python_version(path):
version_cmd = [path, "-c", "import sys; print(sys.version.split()[0])"]
try:
c = vistir.misc.run(
version_cmd,
block=True,
nospin=True,
return_object=True,
combine_stderr=False,
write_to_stdout=False,
... | Get python version string using subprocess from a given path. |
def serialise(self, default_endianness=None):
endianness = (default_endianness or DEFAULT_ENDIANNESS)
if hasattr(self, '_Meta'):
endianness = self._Meta.get('endianness', endianness)
inferred_fields = set()
for k, v in iteritems(self._type_mapping):
inferred_field... | Serialise a message, without including any framing.
:param default_endianness: The default endianness, unless overridden by the fields or class metadata.
Should usually be left at ``None``. Otherwise, use ``'<'`` for little endian and
``'>'`... |
def create(self, parameters={}, create_keys=True, **kwargs):
cs = self._create_service(parameters=parameters, **kwargs)
if create_keys:
cfg = parameters
cfg.update(self._get_service_config())
self.settings.save(cfg) | Create the service. |
def is_filter_tuple(tup):
return isinstance(tup, (tuple, list)) and (
len(tup) == 3 and
isinstance(tup[0], string_types) and
callable(tup[1])) | Return whether a `tuple` matches the format for a column filter |
def _get_path_entry_from_string(self, query_string, first_found=True, full_path=False):
iter_matches = gen_dict_key_matches(query_string, self.config_file_contents, full_path=full_path)
try:
return next(iter_matches) if first_found else iter_matches
except (StopIteration, TypeError):... | Parses a string to form a list of strings that represents a possible config entry header
:param query_string: str, query string we are looking for
:param first_found: bool, return first found entry or entire list
:param full_path: bool, whether to return each entry with their corresponding conf... |
def load_module(self, filename):
if not isinstance(filename, string_types):
return filename
basename = os.path.splitext(os.path.basename(filename))[0]
basename = basename.replace('.bench', '')
modulename = 'benchmarks.{0}'.format(basename)
return load_module(modulenam... | Load a benchmark module from file |
def harvest(self):
if self.perform_initialization() is not None:
self.process_items()
self.finalize()
return self.job | Start the harvesting process |
def fetchText(cls, url, data, textSearch, optional):
if cls.css:
searchFun = data.cssselect
else:
searchFun = data.xpath
if textSearch:
text = ''
for match in searchFun(textSearch):
try:
text += ' ' + match.text_... | Search text entry for given text XPath in a HTML page. |
def deleteCertificate(self, certName):
params = {"f" : "json"}
url = self._url + "/sslCertificates/{cert}/delete".format(
cert=certName)
return self._post(url=url, param_dict=params,
proxy_port=self._proxy_port,
proxy_url=self._prox... | This operation deletes an SSL certificate from the key store. Once
a certificate is deleted, it cannot be retrieved or used to enable
SSL.
Inputs:
certName - name of the cert to delete |
def to_networkx(self):
return nx_util.to_networkx(self.session.get(self.__url).json()) | Return this network in NetworkX graph object.
:return: Network as NetworkX graph object |
def main(port=8222):
loop = asyncio.get_event_loop()
environ = {'hello': 'world'}
def create_server():
return MySSHServer(lambda: environ)
print('Listening on :%i' % port)
print('To connect, do "ssh localhost -p %i"' % port)
loop.run_until_complete(
asyncssh.create_server(create_... | Example that starts the REPL through an SSH server. |
def get_client_class(self, client_class_name):
request_url = self._build_url(['ClientClass', client_class_name])
return self._do_request('GET', request_url) | Returns a specific client class details from CPNR server. |
def build_strings(self):
for idx, dev in enumerate(self.devices):
header = 'system.' + dev
self.gcalls[idx] = header + '.gcall(system.dae)\n'
self.fcalls[idx] = header + '.fcall(system.dae)\n'
self.gycalls[idx] = header + '.gycall(system.dae)\n'
self.f... | build call string for each device |
def _cancel_orphan_orders(self, orderId):
orders = self.ibConn.orders
for order in orders:
order = orders[order]
if order['parentId'] != orderId:
self.ibConn.cancelOrder(order['id']) | cancel child orders when parent is gone |
def update(self, app_model, forbidden_keys=None, inverse=False):
if forbidden_keys is None:
forbidden_keys = []
update_model(self, app_model, forbidden_keys, inverse) | Updates the raw model. Consult `zsl.utils.model_helper.update_model`. |
def ws_db996(self, value=None):
if value is not None:
try:
value = float(value)
except ValueError:
raise ValueError('value {} need to be of type float '
'for field `ws_db996`'.format(value))
self._ws_db996 = value | Corresponds to IDD Field `ws_db996`
Mean wind speed coincident with 99.6% dry-bulb temperature
Args:
value (float): value for IDD Field `ws_db996`
Unit: m/s
if `value` is None it will not be checked against the
specification and is assumed to ... |
def get_first_rec(fastafile):
f = list(SeqIO.parse(fastafile, "fasta"))
if len(f) > 1:
logging.debug("{0} records found in {1}, using the first one".
format(len(f), fastafile))
return f[0] | Returns the first record in the fastafile |
def sizeOfOverlap(self, e):
if not self.intersects(e):
return 0
if e.start >= self.start and e.end <= self.end:
return len(e)
if self.start >= e.start and self.end <= e.end:
return len(self)
if e.start > self.start:
return (self.end - e.start)
if self.start > e.start:
r... | Get the size of the overlap between self and e.
:return: the number of bases that are shared in common between self and e. |
def buffer(self):
if self._buf_in_use:
raise RuntimeError("nested use of buffer() is not supported")
self._buf_in_use = True
old_write = self._write
old_flush = self._flush
if self._buf is None:
self._buf = io.BytesIO()
else:
try:
... | Context manager to temporarily buffer the output.
:raise RuntimeError: If two :meth:`buffer` context managers are used
nestedly.
If the context manager is left without exception, the buffered output
is sent to the actual sink. Otherwise, it is discarded.
I... |
def to_internal_value(self, data):
model = self.Meta.model
if "id" in data:
author = model.objects.get(id=data["id"])
else:
if "username" not in data:
raise ValidationError("Authors must include an ID or a username.")
username = data["username"... | Basically, each author dict must include either a username or id. |
def nodes(self, frequency=None):
if frequency is None:
[]
elif frequency == 'per_session':
return [self]
elif frequency in ('per_visit', 'per_subject'):
return [self.parent]
elif frequency == 'per_study':
return [self.parent.parent] | Returns all nodes of the specified frequency that are related to
the given Session
Parameters
----------
frequency : str | None
The frequency of the nodes to return
Returns
-------
nodes : iterable[TreeNode]
All nodes related to the Sessi... |
def start_virtual_display(self, width=1440, height=900,
colordepth=24, **kwargs):
if self._display is None:
logger.info("Using virtual display: '{0}x{1}x{2}'".format(
width, height, colordepth))
self._display = Xvfb(int(width), int(he... | Starts virtual display which will be
destroyed after test execution will be end
*Arguments:*
- width: a width to be set in pixels
- height: a height to be set in pixels
- color_depth: a color depth to be used
- kwargs: extra parameters
*Example:*
| Sta... |
def get_rows(self, infer_nrows, skiprows=None):
if skiprows is None:
skiprows = set()
buffer_rows = []
detect_rows = []
for i, row in enumerate(self.f):
if i not in skiprows:
detect_rows.append(row)
buffer_rows.append(row)
i... | Read rows from self.f, skipping as specified.
We distinguish buffer_rows (the first <= infer_nrows
lines) from the rows returned to detect_colspecs
because it's simpler to leave the other locations
with skiprows logic alone than to modify them to
deal with the fact we skipped so... |
def resources_after_reservation(res, constraint):
res = res.copy()
res[constraint.resource] -= (constraint.reservation.stop -
constraint.reservation.start)
return res | Return the resources available after a specified
ReserveResourceConstraint has been applied.
Note: the caller is responsible for testing that the constraint is
applicable to the core whose resources are being constrained.
Note: this function does not pay attention to the specific position of the
r... |
def slot(self, slot_index, marshal=None, unmarshal=None, build=None, cast=None, compress=False):
def decorate(o):
assert isinstance(o, PersistentMap)
name = o.__class__.__name__
assert slot_index not in self._index_to_slot
assert name not in self._name_to_slot
... | Decorator for use on classes derived from zlmdb.PersistentMap. The decorator define slots
in a LMDB database schema based on persistent maps, and slot configuration.
:param slot_index:
:param marshal:
:param unmarshal:
:param build:
:param cast:
:param compress:
... |
def upgrade_defaults(self):
self.defaults.upgrade()
self.reset_defaults(self.defaults.filename) | Upgrade config file and reload. |
def set_eep(self, data):
self._bit_data, self._bit_status = self.eep.set_values(self._profile, self._bit_data, self._bit_status, data) | Update packet data based on EEP. Input data is a dictionary with keys corresponding to the EEP. |
def blue_hour(self, direction=SUN_RISING, date=None, local=True, use_elevation=True):
if local and self.timezone is None:
raise ValueError("Local time requested but Location has no timezone set.")
if self.astral is None:
self.astral = Astral()
if date is None:
... | Returns the start and end times of the Blue Hour when the sun is traversing
in the specified direction.
This method uses the definition from PhotoPills i.e. the
blue hour is when the sun is between 6 and 4 degrees below the horizon.
:param direction: Determines whether the time is for... |
def value(self):
if isinstance(self.code, Status):
code = self.code.value
else:
code = self.code
return {'code': code, 'errors': self.errors} | Utility method to retrieve Response Object information |
def contains_version(self, version):
if len(self.bounds) < 5:
for bound in self.bounds:
i = bound.version_containment(version)
if i == 0:
return True
if i == -1:
return False
else:
_, contains... | Returns True if version is contained in this range. |
def _run_cmd(cmds):
if not isinstance(cmds, str):
cmds = "".join(cmds)
print("Execute \"%s\"" % cmds)
try:
subprocess.check_call(cmds, shell=True)
except subprocess.CalledProcessError as err:
print(err)
raise err | Run commands, raise exception if failed |
def _checkMissingParamsFromWorkitem(self, copied_from, keep=False,
**kwargs):
parameters = self.listFieldsFromWorkitem(copied_from,
keep=keep)
self._findMissingParams(parameters, **kwargs) | Check the missing parameters for rendering directly from the
copied workitem |
def get_courses_metadata(self):
metadata = dict(self._mdata['courses'])
metadata.update({'existing_courses_values': self._my_map['courseIds']})
return Metadata(**metadata) | Gets the metadata for the courses.
return: (osid.Metadata) - metadata for the courses
*compliance: mandatory -- This method must be implemented.* |
def portals(self):
url = "%s/portals" % self.root
return _portals.Portals(url=url,
securityHandler=self._securityHandler,
proxy_url=self._proxy_url,
proxy_port=self._proxy_port) | returns the Portals class that provides administration access
into a given organization |
def get_method_docstring(cls, method_name):
method = getattr(cls, method_name, None)
if method is None:
return
docstrign = inspect.getdoc(method)
if docstrign is None:
for base in cls.__bases__:
docstrign = get_method_docstring(base, method_name)
if docstrign:
... | return method docstring
if method docstring is empty we get docstring from parent
:param method:
:type method:
:return:
:rtype: |
def save_inventory(inventory, hosts_file=HOSTS_FILE):
with open(hosts_file, 'w') as f:
inventory.write(f) | Saves Ansible inventory to file.
Parameters
----------
inventory: ConfigParser.SafeConfigParser
content of the `hosts_file`
hosts_file: str, optional
path to Ansible hosts file |
def get_collated_content(ident_hash, context_ident_hash, cursor):
cursor.execute(SQL['get-collated-content'],
(ident_hash, context_ident_hash,))
try:
return cursor.fetchone()[0]
except TypeError:
return | Return collated content for ``ident_hash``. |
def clean_all(self, config_file, region=None, profile_name=None):
logging.info('[begin] Cleaning all provisioned artifacts')
config = GroupConfigFile(config_file=config_file)
if config.is_fresh() is True:
raise ValueError("Config is already clean.")
if region is None:
... | Clean all provisioned artifacts from both the local file and the AWS
Greengrass service.
:param config_file: config file containing the group to clean
:param region: the region in which the group should be cleaned.
[default: us-west-2]
:param profile_name: the name of the `a... |
def websafe(s):
s=s.replace("<","<").replace(">",">")
s=s.replace(r'\x',r' \x')
s=s.replace("\n","<br>")
return s | return a string with HTML-safe text |
def _scons_user_warning(e):
etype, value, tb = sys.exc_info()
filename, lineno, routine, dummy = find_deepest_user_frame(traceback.extract_tb(tb))
sys.stderr.write("\nscons: warning: %s\n" % e)
sys.stderr.write('File "%s", line %d, in %s\n' % (filename, lineno, routine)) | Handle user warnings. Print out a message and a description of
the warning, along with the line number and routine where it occured.
The file and line number will be the deepest stack frame that is
not part of SCons itself. |
def validate_hier_intervals(intervals_hier):
label_top = util.generate_labels(intervals_hier[0])
boundaries = set(util.intervals_to_boundaries(intervals_hier[0]))
for level, intervals in enumerate(intervals_hier[1:], 1):
label_current = util.generate_labels(intervals)
validate_structure(inte... | Validate a hierarchical segment annotation.
Parameters
----------
intervals_hier : ordered list of segmentations
Raises
------
ValueError
If any segmentation does not span the full duration of the top-level
segmentation.
If any segmentation does not start at 0. |
def _expand_parameters(specification, parameters, original=None):
expanded_specification = deepcopy(specification)
try:
for step_num, step in enumerate(expanded_specification['steps']):
current_step = expanded_specification['steps'][step_num]
for command_num, command in enumerate... | Expand parameters inside comands for Serial workflow specifications.
:param specification: Full valid Serial workflow specification.
:param parameters: Parameters to be extended on a Serial specification.
:param original: Flag which, determins type of specifications to return.
:returns: If 'original' p... |
def to_binary(self, threshold=0.0):
data = BINARY_IM_MAX_VAL * (self._data > threshold)
return BinaryImage(data.astype(np.uint8), self._frame) | Creates a BinaryImage from the depth image. Points where the depth
is greater than threshold are converted to ones, and all other points
are zeros.
Parameters
----------
threshold : float
The depth threshold.
Returns
-------
:obj:`BinaryImage... |
def plot_xtb(fignum, XTB, Bs, e, f):
plt.figure(num=fignum)
plt.xlabel('Temperature (K)')
plt.ylabel('Susceptibility (m^3/kg)')
k = 0
Blab = []
for field in XTB:
T, X = [], []
for xt in field:
X.append(xt[0])
T.append(xt[1])
plt.plot(T, X)
... | function to plot series of chi measurements as a function of temperature, holding frequency constant and varying B |
def list_account_admins(self, account_id, user_id=None):
path = {}
data = {}
params = {}
path["account_id"] = account_id
if user_id is not None:
params["user_id"] = user_id
self.logger.debug("GET /api/v1/accounts/{account_id}/admins with query params: {... | List account admins.
List the admins in the account |
def lstm_init_states(batch_size):
hp = Hyperparams()
init_shapes = lstm.init_states(batch_size=batch_size, num_lstm_layer=hp.num_lstm_layer, num_hidden=hp.num_hidden)
init_names = [s[0] for s in init_shapes]
init_arrays = [mx.nd.zeros(x[1]) for x in init_shapes]
return init_names, init_arrays | Returns a tuple of names and zero arrays for LSTM init states |
def index_library_datasets(self, tick_f=None):
dataset_n = 0
partition_n = 0
def tick(d, p):
if tick_f:
tick_f('datasets: {} partitions: {}'.format(d, p))
for dataset in self.library.datasets:
if self.backend.dataset_index.index_one(dataset):
... | Indexes all datasets of the library.
Args:
tick_f (callable, optional): callable of one argument. Gets string with index state. |
def make_signed_token(self, key):
t = JWS(self.claims)
t.add_signature(key, protected=self.header)
self.token = t | Signs the payload.
Creates a JWS token with the header as the JWS protected header and
the claims as the payload. See (:class:`jwcrypto.jws.JWS`) for
details on the exceptions that may be reaised.
:param key: A (:class:`jwcrypto.jwk.JWK`) key. |
def valid_api_plugin(self, plugin):
if (issubclass(plugin, APIPlugin) and
hasattr(plugin, 'plugin_type') and plugin.plugin_type == 'api' and
hasattr(plugin, 'request') and plugin.request != None and
hasattr(plugin, 'request_class') and plugin.request_cl... | Validate an API plugin, ensuring it is an API plugin and has the
necessary fields present.
`plugin` is a subclass of scruffy's Plugin class. |
def compile_bundle_entry(self, spec, entry):
modname, source, target, modpath = entry
bundled_modpath = {modname: modpath}
bundled_target = {modname: target}
export_module_name = []
if isfile(source):
export_module_name.append(modname)
copy_target = join(s... | Handler for each entry for the bundle method of the compile
process. This copies the source file or directory into the
build directory. |
def register_class(self, instance, name=None):
prefix_name = name or instance.__class__.__name__
for e in dir(instance):
if e[0][0] != "_":
self.register_function(
getattr(instance, e),
name="%s.%s" % (prefix_name, e)
) | Add all functions of a class-instance to the RPC-services.
All entries of the instance which do not begin with '_' are added.
:Parameters:
- myinst: class-instance containing the functions
- name: | hierarchical prefix.
| If omitted, the functions are ad... |
def create_from_pybankid_exception(cls, exception):
return cls(
"{0}: {1}".format(exception.__class__.__name__, str(exception)),
_exception_class_to_status_code.get(exception.__class__),
) | Class method for initiating from a `PyBankID` exception.
:param bankid.exceptions.BankIDError exception:
:return: The wrapped exception.
:rtype: :py:class:`~FlaskPyBankIDError` |
def loads(s, single=False):
corpus = etree.fromstring(s)
if single:
ds = _deserialize_mrs(next(corpus))
else:
ds = (_deserialize_mrs(mrs_elem) for mrs_elem in corpus)
return ds | Deserialize MRX string representations
Args:
s (str): a MRX string
single (bool): if `True`, only return the first Xmrs object
Returns:
a generator of Xmrs objects (unless *single* is `True`) |
def wait_for(func, timeout=10, step=1, default=None, func_args=(), func_kwargs=None):
if func_kwargs is None:
func_kwargs = dict()
max_time = time.time() + timeout
step = min(step or 1, timeout) * BLUR_FACTOR
ret = default
while time.time() <= max_time:
call_ret = func(*func_args, **... | Call `func` at regular intervals and Waits until the given function returns
a truthy value within the given timeout and returns that value.
@param func:
@type func: function
@param timeout:
@type timeout: int | float
@param step: Interval at which we should check for the value
@type step: i... |
def _match_tags(repex_tags, path_tags):
if 'any' in repex_tags or (not repex_tags and not path_tags):
return True
elif set(repex_tags) & set(path_tags):
return True
return False | Check for matching tags between what the user provided
and the tags set in the config.
If `any` is chosen, match.
If no tags are chosen and none are configured, match.
If the user provided tags match any of the configured tags, match. |
def insert_data(self, node, data, start, end):
for item in data:
self.recursive_insert(node, [item[0], item[1]], item[-1], start, end) | loops through all the data and inserts them into the empty tree |
def benchmark(self, func, gpu_args, instance, times, verbose):
logging.debug('benchmark ' + instance.name)
logging.debug('thread block dimensions x,y,z=%d,%d,%d', *instance.threads)
logging.debug('grid dimensions x,y,z=%d,%d,%d', *instance.grid)
time = None
try:
time ... | benchmark the kernel instance |
def create(self, credentials, friendly_name=values.unset,
account_sid=values.unset):
data = values.of({
'Credentials': credentials,
'FriendlyName': friendly_name,
'AccountSid': account_sid,
})
payload = self._version.create(
'POST',
... | Create a new AwsInstance
:param unicode credentials: A string that contains the AWS access credentials in the format <AWS_ACCESS_KEY_ID>:<AWS_SECRET_ACCESS_KEY>
:param unicode friendly_name: A string to describe the resource
:param unicode account_sid: The Subaccount this Credential should be a... |
def edterm(trmtyp, source, target, et, fixref, abcorr, obsrvr, npts):
trmtyp = stypes.stringToCharP(trmtyp)
source = stypes.stringToCharP(source)
target = stypes.stringToCharP(target)
et = ctypes.c_double(et)
fixref = stypes.stringToCharP(fixref)
abcorr = stypes.stringToCharP(abcorr)
obsrvr ... | Compute a set of points on the umbral or penumbral terminator of
a specified target body, where the target shape is modeled as an
ellipsoid.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/edterm_c.html
:param trmtyp: Terminator type.
:type trmtyp: str
:param source: Light source.
... |
def timeout(seconds):
def _timeout_error(signal, frame):
raise TimeoutError("Operation did not finish within \
{} seconds".format(seconds))
def timeout_decorator(func):
@wraps(func)
def timeout_wrapper(*args, **kwargs):
signal.signal(signal.SIGALRM, _timeout_error)
... | Raises a TimeoutError if a function does not terminate within
specified seconds. |
def synchronize_resources(self):
if not self._rpc.sync_start():
LOG.info("%(pid)s Failed to grab the sync lock",
{'pid': os.getpid()})
greenthread.sleep(1)
return
for resource in self._resources_to_update:
self.update_neutron_resource(... | Synchronize worker with CVX
All database queries must occur while the sync lock is held. This
tightly couples reads with writes and ensures that an older read
does not result in the last write. Eg:
Worker 1 reads (P1 created)
Worder 2 reads (P1 deleted)
Worker 2 writes ... |
def type(self):
return ffi.string(lib.EnvGetDefmessageHandlerType(
self._env, self._cls, self._idx)).decode() | MessageHandler type. |
def _cldf2wordlist(dataset, row='parameter_id', col='language_id'):
return lingpy.Wordlist(_cldf2wld(dataset), row=row, col=col) | Read worldist object from cldf dataset. |
def trace(fn):
def wrapped(*args, **kwargs):
msg = []
msg.append('Enter {}('.format(fn.__name__))
if args:
msg.append(', '.join([str(x) for x in args]))
if kwargs:
kwargs_str = ', '.join(['{}={}'.format(k, v) for k, v in list(kwargs.items())])
if a... | Prints parameteters and return values of the each call of the wrapped function.
Usage:
decorate appropriate function or method:
@trace
def myf():
... |
def sonos_uri_from_id(self, item_id):
item_id = quote_url(item_id.encode('utf-8'))
account = self.account
result = "soco://{}?sid={}&sn={}".format(
item_id, self.service_id,
account.serial_number
)
return result | Get a uri which can be sent for playing.
Args:
item_id (str): The unique id of a playable item for this music
service, such as that returned in the metadata from
`get_metadata`, eg ``spotify:track:2qs5ZcLByNTctJKbhAZ9JE``
Returns:
str: A URI of t... |
def from_fptr(cls, label, type_, fptr):
return FSEntry(
label=label,
type=type_,
path=fptr.path,
use=fptr.use,
file_uuid=fptr.file_uuid,
derived_from=fptr.derived_from,
checksum=fptr.checksum,
checksumtype=fptr.check... | Return ``FSEntry`` object. |
def select_spread(
list_of_elements = None,
number_of_elements = None
):
if len(list_of_elements) <= number_of_elements:
return list_of_elements
if number_of_elements == 0:
return []
if number_of_elements == 1:
return [list_of_elements[int(round((len(list_of_elements) -... | This function returns the specified number of elements of a list spread
approximately evenly. |
def js_on_change(self, event, *callbacks):
if len(callbacks) == 0:
raise ValueError("js_on_change takes an event name and one or more callbacks, got only one parameter")
from bokeh.models.callbacks import CustomJS
if not all(isinstance(x, CustomJS) for x in callbacks):
ra... | Attach a ``CustomJS`` callback to an arbitrary BokehJS model event.
On the BokehJS side, change events for model properties have the
form ``"change:property_name"``. As a convenience, if the event name
passed to this method is also the name of a property on the model,
then it will be pr... |
def run_process(cwd, args):
try:
process = check_output(args, cwd=cwd, stderr=STDOUT)
return process
except CalledProcessError as e:
log('Uh oh, the teapot broke again! Error:', e, type(e), lvl=verbose, pretty=True)
log(e.cmd, e.returncode, e.output, lvl=verbose)
return e... | Executes an external process via subprocess.Popen |
def append(self, other):
if not isinstance(other, (list, tuple)):
other = [other]
if all((isinstance(o, MultiIndex) and o.nlevels >= self.nlevels)
for o in other):
arrays = []
for i in range(self.nlevels):
label = self._get_level_values(... | Append a collection of Index options together
Parameters
----------
other : Index or list/tuple of indices
Returns
-------
appended : Index |
def _in_valid_interval(self, parameter, value):
if parameter not in self._parameterIntervals:
return True
interval = self._parameterIntervals[parameter]
if interval[2] and interval[3]:
return interval[0] <= value <= interval[1]
if not interval[2] and interval[3]:
... | Returns if the parameter is within its valid interval.
:param string parameter: Name of the parameter that has to be checked.
:param numeric value: Value of the parameter.
:return: Returns :py:const:`True` it the value for the given parameter is valid,
:py:const:`False` ... |
def reset_logformat_timestamped(logger: logging.Logger,
extraname: str = "",
level: int = logging.INFO) -> None:
namebit = extraname + ":" if extraname else ""
fmt = ("%(asctime)s.%(msecs)03d:%(levelname)s:%(name)s:" + namebit +
"%(messa... | Apply a simple time-stamped log format to an existing logger, and set
its loglevel to either ``logging.DEBUG`` or ``logging.INFO``.
Args:
logger: logger to modify
extraname: additional name to append to the logger's name
level: log level to set |
def prune_by_ngram_size(self, minimum=None, maximum=None):
self._logger.info('Pruning results by n-gram size')
if minimum:
self._matches = self._matches[
self._matches[constants.SIZE_FIELDNAME] >= minimum]
if maximum:
self._matches = self._matches[
... | Removes results rows whose n-gram size is outside the
range specified by `minimum` and `maximum`.
:param minimum: minimum n-gram size
:type minimum: `int`
:param maximum: maximum n-gram size
:type maximum: `int` |
def _create_fig(
*,
x_sc=bq.LinearScale,
y_sc=bq.LinearScale,
x_ax=bq.Axis,
y_ax=bq.Axis,
fig=bq.Figure,
options={},
params={}
):
params = _merge_with_defaults(params)
x_sc = x_sc(**_call_params(params['x_sc'], options))
y_sc = y_sc(**_call_params(params['y_sc'], options))
... | Initializes scales and axes for a bqplot figure and returns the resulting
blank figure. Each plot component is passed in as a class. The plot options
should be passed into options.
Any additional parameters to initialize plot components are passed into
params as a dict of { plot_component: { trait: val... |
def _read_words(filename):
with tf.gfile.GFile(filename, "r") as f:
if sys.version_info[0] >= 3:
return f.read().replace("\n", " %s " % EOS).split()
else:
return f.read().decode("utf-8").replace("\n", " %s " % EOS).split() | Reads words from a file. |
def str2tuple(str_in):
tuple_out = safe_eval(str_in)
if not isinstance(tuple_out, tuple):
tuple_out = None
return tuple_out | Extracts a tuple from a string.
Args:
str_in (string) that contains python tuple
Returns:
(dict) or None if no valid tuple was found
Raises:
- |
def pull(rebase=True, refspec=None):
options = rebase and '--rebase' or ''
output = run('pull %s %s' % (options, refspec or ''))
return not re.search('up.to.date', output) | Pull refspec from remote repository to local
If refspec is left as None, then pull current branch
The '--rebase' option is used unless rebase is set to false |
def _build_instance_group_args(self, instance_group):
params = {
'InstanceCount' : instance_group.num_instances,
'InstanceRole' : instance_group.role,
'InstanceType' : instance_group.type,
'Name' : instance_group.name,
'Market' : instance_group.market
... | Takes an InstanceGroup; returns a dict that, when its keys are
properly prefixed, can be used for describing InstanceGroups in
RunJobFlow or AddInstanceGroups requests. |
def getNorthSouthClone(self, i):
north = self.getAdjacentClone(i, south=False)
south = self.getAdjacentClone(i)
return north, south | Returns the adjacent clone name from both sides. |
def get_meter(self, site, start, end, point_type='Green_Button_Meter',
var="meter", agg='MEAN', window='24h', aligned=True, return_names=True):
start = self.convert_to_utc(start)
end = self.convert_to_utc(end)
request = self.compose_MDAL_dic(point_type=point_type, site=site, st... | Get meter data from MDAL.
Parameters
----------
site : str
Building name.
start : str
Start date - 'YYYY-MM-DDTHH:MM:SSZ'
end : str
End date - 'YYYY-MM-DDTHH:MM:SSZ'
point_type : str
Ty... |
def sigma_from_site_prop(self):
num_coi = 0
if None in self.site_properties['grain_label']:
raise RuntimeError('Site were merged, this property do not work')
for tag in self.site_properties['grain_label']:
if 'incident' in tag:
num_coi += 1
return ... | This method returns the sigma value of the gb from site properties.
If the GB structure merge some atoms due to the atoms too closer with
each other, this property will not work. |
def bfill(arr, dim=None, limit=None):
axis = arr.get_axis_num(dim)
_limit = limit if limit is not None else arr.shape[axis]
return apply_ufunc(_bfill, arr,
dask='parallelized',
keep_attrs=True,
output_dtypes=[arr.dtype],
... | backfill missing values |
def dependencies_of(self, address):
assert address in self._target_by_address, (
'Cannot retrieve dependencies of {address} because it is not in the BuildGraph.'
.format(address=address)
)
return self._target_dependencies_by_address[address] | Returns the dependencies of the Target at `address`.
This method asserts that the address given is actually in the BuildGraph.
:API: public |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.