code stringlengths 51 2.38k | docstring stringlengths 4 15.2k |
|---|---|
def serialized_task(self, task: Task) -> Tuple[str, str]:
return f"{task.hash}.json", task.json | Returns the name of the task definition file and its contents. |
def map_aliases_to_device_objects(self):
all_devices = self.get_all_devices_in_portal()
for dev_o in all_devices:
dev_o['portals_aliases'] = self.get_portal_by_name(
self.portal_name()
)[2... | A device object knows its rid, but not its alias.
A portal object knows its device rids and aliases.
This function adds an 'portals_aliases' key to all of the
device objects so they can be sorted by alias. |
def remove_subkey(self, subkey):
if len(self.subkeys) > 0:
key = subkey if isinstance(subkey, str) else subkey.key
for i in range(len(self.subkeys)):
if self.subkeys[i].key == key:
self.subkeys.pop(i)
break | Remove the given subkey, if existed, from this AdfKey.
Parameters
----------
subkey : str or AdfKey
The subkey to remove. |
async def mutation_resolver(self, mutation_name, args, fields):
try:
mutation_summary = [mutation for mutation in \
self._external_service_data['mutations'] \
if mutation['name'] == mutation_name][0]
exce... | the default behavior for mutations is to look up the event,
publish the correct event type with the args as the body,
and return the fields contained in the result |
def post_process(self, indices):
array = javabridge.call(self.jobject, "postProcess", "([I)[I", indices)
if array is None:
return None
else:
return javabridge.get_env().get_int_array_elements(array) | Post-processes the evaluator with the selected attribute indices.
:param indices: the attribute indices list to use
:type indices: ndarray
:return: the processed indices
:rtype: ndarray |
def from_traverse(cls, traverse_block):
if isinstance(traverse_block, Traverse):
return cls(traverse_block.direction, traverse_block.edge_name)
else:
raise AssertionError(u'Tried to initialize an instance of GremlinFoldedTraverse '
u'with block of... | Create a GremlinFoldedTraverse block as a copy of the given Traverse block. |
def set_eng_float_format(accuracy=3, use_eng_prefix=False):
set_option("display.float_format", EngFormatter(accuracy, use_eng_prefix))
set_option("display.column_space", max(12, accuracy + 9)) | Alter default behavior on how float is formatted in DataFrame.
Format float in engineering format. By accuracy, we mean the number of
decimal digits after the floating point.
See also EngFormatter. |
def is_valid(self):
if not isinstance(self._expiration, datetime.datetime):
raise InvalidArgumentError('Expiration datetime must be specified.')
if 'key' not in self.form_data:
raise InvalidArgumentError('object key must be specified.')
if 'bucket' not in self.form_data:
... | Validate for required parameters. |
def stream_bytes(data, chunk_size=default_chunk_size):
stream = BytesStream(data, chunk_size=chunk_size)
return stream.body(), stream.headers | Gets a buffered generator for streaming binary data.
Returns a buffered generator which encodes binary data as
:mimetype:`multipart/form-data` with the corresponding headers.
Parameters
----------
data : bytes
The data bytes to stream
chunk_size : int
The maximum size of each s... |
def _raise_error_if_column_exists(dataset, column_name = 'dataset',
dataset_variable_name = 'dataset',
column_name_error_message_name = 'column_name'):
err_msg = 'The SFrame {0} must contain the column {1}.'.format(
... | Check if a column exists in an SFrame with error message. |
def add_gemini_query(self, name, query):
logger.info("Adding query {0} with text {1}".format(name, query))
new_query = GeminiQuery(name=name, query=query)
self.session.add(new_query)
self.save()
return new_query | Add a user defined gemini query
Args:
name (str)
query (str) |
def plot(self, dimension):
import matplotlib.pyplot as plt
life_lines = self.get_life_lines(dimension)
x, y = zip(*life_lines)
plt.scatter(x, y)
plt.xlabel("Birth")
plt.ylabel("Death")
if self.max_life is not None:
plt.xlim([0, self.max_life])
... | Plot barcode using matplotlib. |
def send_frame(self, frame):
if self.closed:
if self.close_info and len(self.close_info['reply_text']) > 0:
raise ChannelClosed(
"channel %d is closed: %s : %s",
self.channel_id,
self.close_info['reply_code'],
... | Queue a frame for sending. Will send immediately if there are no
pending synchronous transactions on this connection. |
def add_vhost(vhost, runas=None):
if runas is None and not salt.utils.platform.is_windows():
runas = salt.utils.user.get_user()
res = __salt__['cmd.run_all'](
[RABBITMQCTL, 'add_vhost', vhost],
reset_system_locale=False,
runas=runas,
python_shell=False)
msg = 'Added'
... | Adds a vhost via rabbitmqctl add_vhost.
CLI Example:
.. code-block:: bash
salt '*' rabbitmq add_vhost '<vhost_name>' |
def load_wav(path, mono=True):
fs, audio_data = scipy.io.wavfile.read(path)
if audio_data.dtype == 'int8':
audio_data = audio_data/float(2**8)
elif audio_data.dtype == 'int16':
audio_data = audio_data/float(2**16)
elif audio_data.dtype == 'int32':
audio_data = audio_data/float(2*... | Loads a .wav file as a numpy array using ``scipy.io.wavfile``.
Parameters
----------
path : str
Path to a .wav file
mono : bool
If the provided .wav has more than one channel, it will be
converted to mono if ``mono=True``. (Default value = True)
Returns
-------
audi... |
def get_monotone_constraints(self):
if self.monotone_constraints is None:
self.monotone_constraints = self.get_field('monotone_constraints')
return self.monotone_constraints | Get the monotone constraints of the Dataset.
Returns
-------
monotone_constraints : numpy array or None
Monotone constraints: -1, 0 or 1, for each feature in the Dataset. |
def create_bmi_config_file(self, filename: str = "bmi_config.txt") -> None:
s0 = self.construct_default_initial_state()
s0.to_csv(filename, index_label="variable") | Create a BMI config file to initialize the model.
Args:
filename: The filename with which the config file should be saved. |
def check_metric(self, metric):
if metric not in self.VALID_METRICS:
raise ValueError(
f"`{self.__class__.__name__}` does not support the `{metric}` "
f"metric. Please choose one of the supported metrics: "
f"{', '.join(self.VALID_METRICS)}."
... | Check that the metric is supported by the KNNIndex instance. |
def encode(self, data, size):
return return_fresh_string(lib.zarmour_encode(self._as_parameter_, data, size)) | Encode a stream of bytes into an armoured string. Returns the armoured
string, or NULL if there was insufficient memory available to allocate
a new string. |
def ElectronIC(pars, data):
ECPL = ExponentialCutoffPowerLaw(
pars[0] / u.eV, 10.0 * u.TeV, pars[1], 10 ** pars[2] * u.TeV
)
IC = InverseCompton(ECPL, seed_photon_fields=["CMB"])
return IC.flux(data, distance=1.0 * u.kpc) | Define particle distribution model, radiative model, and return model flux
at data energy values |
def GetDateRange(self):
start = self.start_date
end = self.end_date
for date, (exception_type, _) in self.date_exceptions.items():
if exception_type == self._EXCEPTION_TYPE_REMOVE:
continue
if not start or (date < start):
start = date
if not end or (date > end):
end... | Return the range over which this ServicePeriod is valid.
The range includes exception dates that add service outside of
(start_date, end_date), but doesn't shrink the range if exception
dates take away service at the edges of the range.
Returns:
A tuple of "YYYYMMDD" strings, (start date, end da... |
def read(*components, **kwargs):
rstrip = kwargs.get("rstrip", True)
comment_char = kwargs.get("comment_char", None)
ignore_comments = comment_char is not None
file = open(path(*components))
lines = file.readlines()
file.close()
if ignore_comments:
comment_line_re = re.compile("^\s*{... | Read file and return a list of lines. If comment_char is set, ignore the
contents of lines following the comment_char.
Raises:
IOError: if reading path fails |
def register_plugin(host, plugin):
class OriginalMethods(object):
def __getattr__(self, name):
return lambda *args, **kwargs: getattr(host, name).original(host, *args, **kwargs)
if not hasattr(host, "_plugins"):
host._plugins = [OriginalMethods()]
plugin.parent = host._plugins[-1... | Register a plugin with a host object. Some @pluggable methods in the host
will have their behaviour altered by the plugin. |
def setup_logger(log_level, log_file=None):
level = getattr(logging, log_level.upper(), None)
if not level:
color_print("Invalid log level: %s" % log_level, "RED")
sys.exit(1)
if level >= logging.INFO:
sys.tracebacklimit = 0
formatter = ColoredFormatter(
u"%(log_color)s%(... | setup root logger with ColoredFormatter. |
def list_keyvaults(access_token, subscription_id, rgname):
endpoint = ''.join([get_rm_endpoint(),
'/subscriptions/', subscription_id,
'/resourcegroups/', rgname,
'/providers/Microsoft.KeyVault/vaults',
'?api-version=', K... | Lists key vaults in the named resource group.
Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
rgname (str): Azure resource group name.
Returns:
HTTP response. 200 OK. |
def get_true_capacity(self):
c = self.capacity
if c is not None:
return c
else:
if self.rooms.count() == 0 and self.activity.default_capacity:
return self.activity.default_capacity
rooms = self.get_true_rooms()
return EighthRoom.tot... | Get the capacity for the scheduled activity, taking into account activity defaults and
overrides. |
def get_group_details(group):
result = []
for datastore in _get_datastores():
value = datastore.get_group_details(group)
value['datastore'] = datastore.config['DESCRIPTION']
result.append(value)
return result | Get group details. |
def _ReadPresetsFromFileObject(self, file_object):
yaml_generator = yaml.safe_load_all(file_object)
last_preset_definition = None
for yaml_definition in yaml_generator:
try:
preset_definition = self._ReadParserPresetValues(yaml_definition)
except errors.MalformedPresetError as exception:... | Reads parser and parser plugin presets from a file-like object.
Args:
file_object (file): file-like object containing the parser and parser
plugin presets definitions.
Yields:
ParserPreset: a parser preset.
Raises:
MalformedPresetError: if one or more plugin preset definitions... |
def _replace_with_new_dims(
self: T,
variables: 'OrderedDict[Any, Variable]' = None,
coord_names: set = None,
attrs: 'Optional[OrderedDict]' = __default,
indexes: 'Optional[OrderedDict[Any, pd.Index]]' = __default,
inplace: bool = False,
) -> T:
dims = dict(ca... | Replace variables with recalculated dimensions. |
def street_address(self, address):
address = self.street_addresses([address])
if not len(address):
return None
return Address(address[0]) | Geocode one and only address, get a single Address object back
>>> client.street_address("100 Main St, Anywhere, USA")
>>> client.street_address({"street": "100 Main St, anywhere USA"})
:param address: string or dictionary with street address information
:return: an Address object or N... |
def _check_error(response):
if 'error' in response:
raise InfluxDBError(response['error'])
elif 'results' in response:
for statement in response['results']:
if 'error' in statement:
msg = '{d[error]} (statement {d[statement_id]})'
... | Checks for JSON error messages and raises Python exception |
def _displaystr2num(st):
num = None
for s, n in [('DFP-', 16), ('TV-', 8), ('CRT-', 0)]:
if st.startswith(s):
try:
curnum = int(st[len(s):])
if 0 <= curnum <= 7:
num = n + curnum
break
except Exception:
... | Return a display number from a string |
def call_state(self, addr, *args, **kwargs):
return self.project.simos.state_call(addr, *args, **kwargs) | Returns a state object initialized to the start of a given function, as if it were called with given parameters.
:param addr: The address the state should start at instead of the entry point.
:param args: Any additional positional arguments will be used as arguments to the functio... |
def build_uri(secret, name, initial_count=None, issuer_name=None):
is_initial_count_present = (initial_count is not None)
otp_type = 'hotp' if is_initial_count_present else 'totp'
base = 'otpauth://%s/' % otp_type
if issuer_name:
issuer_name = quote(issuer_name)
base += '%s:' % issuer_na... | Returns the provisioning URI for the OTP; works for either TOTP or HOTP.
This can then be encoded in a QR Code and used to provision the Google
Authenticator app.
For module-internal use.
See also:
http://code.google.com/p/google-authenticator/wiki/KeyUriFormat
@param [String] the hotp/t... |
def on_show(request, page_name):
revision_id = request.args.get("rev", type=int)
query = RevisionedPage.query.filter_by(name=page_name)
if revision_id:
query = query.filter_by(revision_id=revision_id)
revision_requested = True
else:
query = query.order_by(RevisionedPage.revision_... | Displays the page the user requests. |
def state(self, new_state: bool):
self._lutron.send(Lutron.OP_EXECUTE, Keypad._CMD_TYPE, self._keypad.id,
self.component_number, Led._ACTION_LED_STATE,
int(new_state))
self._state = new_state | Sets the new led state.
new_state: bool |
def start_worker(which_worker, config={}):
if which_worker == 'multi_worker':
cls = MultiWorker
elif which_worker == 'fork_worker':
cls = ForkWorker
else:
cls = ForkWorker
return run_worker(cls, config) | Start some worker class.
:param str which_worker: name of the worker
:param dict config: ``rejester`` config block |
def deployment_groups(self):
if not self.__deployment_groups:
self.__deployment_groups = DeploymentGroups(self.__connection)
return self.__deployment_groups | Gets the Deployment Groups API client.
Returns:
DeploymentGroups: |
def loss(self, x_data, y_true):
y_pred = self(x_data)
return y_pred, self.loss_value(x_data, y_true, y_pred) | Forward propagate network and return a value of loss function |
def is_multicast(text):
try:
first = ord(dns.ipv4.inet_aton(text)[0])
return (first >= 224 and first <= 239)
except Exception:
try:
first = ord(dns.ipv6.inet_aton(text)[0])
return (first == 255)
except Exception:
raise ValueError | Is the textual-form network address a multicast address?
@param text: the textual address
@raises ValueError: the address family cannot be determined from the input.
@rtype: bool |
def get_logfile_name(tags):
if not os.path.exists(sd.LOG_DIR):
os.mkdir(sd.LOG_DIR)
filename = "log"
for tag in tags:
filename += "_{}".format(tag)
filename += ".txt"
filename = os.path.join(sd.LOG_DIR,filename)
return filename | Formulates a log file name that incorporates the provided tags.
The log file will be located in ``scgpm_seqresults_dnanexus.LOG_DIR``.
Args:
tags: `list` of tags to append to the log file name. Each tag will be '_' delimited. Each tag
will be added in the same order as provided. |
def no_duplicates_constructor(loader, node, deep=False):
mapping = {}
for key_node, value_node in node.value:
key = loader.construct_object(key_node, deep=deep)
value = loader.construct_object(value_node, deep=deep)
if key in mapping:
from intake.catalog.exceptions import Dup... | Check for duplicate keys while loading YAML
https://gist.github.com/pypt/94d747fe5180851196eb |
def wifi_status(self):
return self._info_json.get(CONST.STATUS, {}).get(CONST.WIFI_LINK) | Get the wifi status. |
def add_object(self, obj, properties=()):
self._objects.add(obj)
self._properties |= properties
self._pairs.update((obj, p) for p in properties) | Add an object to the definition and add ``properties`` as related. |
def create_group(self, trigger):
data = self._serialize_object(trigger)
return Trigger(self._post(self._service_url(['triggers', 'groups']), data)) | Create a new group trigger.
:param trigger: Group member trigger to be created
:return: The created group Trigger |
def squeeze(self, array):
if not self._squeeze:
return array
array = array.copy()
array = array.squeeze()
if array.ndim == 0:
array = array[()]
return array | Simplify the given array as much as possible - squeeze out all singleton
dimensions and also convert a zero dimensional array into array scalar |
def get_device_topology(self, id_or_uri):
uri = self._client.build_uri(id_or_uri) + "/deviceTopology"
return self._client.get(uri) | Retrieves the topology information for the rack resource specified by ID or URI.
Args:
id_or_uri: Can be either the resource ID or the resource URI.
Return:
dict: Device topology. |
def get_external_commands_from_arbiters(self):
for arbiter_link_uuid in self.arbiters:
link = self.arbiters[arbiter_link_uuid]
if not link.active:
logger.debug("The arbiter '%s' is not active, it is not possible to get "
"its external commands... | Get external commands from our arbiters
As of now, only the arbiter are requested to provide their external commands that
the receiver will push to all the known schedulers to make them being executed.
:return: None |
def handle_address_save(self, sender, instance, **kwargs):
objects = self.find_associated_with_address(instance)
for obj in objects:
self.handle_save(obj.__class__, obj) | Custom handler for address save |
def move_out_16(library, session, space, offset, length, data, extended=False):
converted_buffer = (ViUInt16 * length)(*tuple(data))
if extended:
return library.viMoveOut16Ex(session, space, offset, length, converted_buffer)
else:
return library.viMoveOut16(session, space, offset, length, co... | Moves an 16-bit block of data from local memory to the specified address space and offset.
Corresponds to viMoveOut16* functions of the VISA library.
:param library: the visa library wrapped by ctypes.
:param session: Unique logical identifier to a session.
:param space: Specifies the address space. (... |
def _set_input(el, value):
if isinstance(value, dict):
el.value = value["val"]
elif type(value) in [list, tuple]:
el.value = ", ".join(item["val"] for item in value)
else:
el.value = value | Set content of given `el` to `value`.
Args:
el (obj): El reference to input you wish to set.
value (obj/list): Value to which the `el` will be set. |
def wp_is_loiter(self, i):
loiter_cmds = [mavutil.mavlink.MAV_CMD_NAV_LOITER_UNLIM,
mavutil.mavlink.MAV_CMD_NAV_LOITER_TURNS,
mavutil.mavlink.MAV_CMD_NAV_LOITER_TIME,
mavutil.mavlink.MAV_CMD_NAV_LOITER_TO_ALT]
if (self.wpoints[i].command in loiter_cmds):
... | return true if waypoint is a loiter waypoint |
def backlinks(
self,
page: 'WikipediaPage',
**kwargs
) -> PagesDict:
params = {
'action': 'query',
'list': 'backlinks',
'bltitle': page.title,
'bllimit': 500,
}
used_params = kwargs
used_params.update... | Returns backlinks from other pages with respect to parameters
API Calls for parameters:
- https://www.mediawiki.org/w/api.php?action=help&modules=query%2Bbacklinks
- https://www.mediawiki.org/wiki/API:Backlinks
:param page: :class:`WikipediaPage`
:param kwargs: parameters used... |
def get_states(self, devices):
header = BASE_HEADERS.copy()
header['Cookie'] = self.__cookie
json_data = self._create_get_state_request(devices)
request = requests.post(
BASE_URL + 'getStates',
headers=header,
data=json_data,
timeout=10)
... | Get States of Devices. |
def _subtoken_ids_to_tokens(self, subtokens):
concatenated = "".join(
[self._subtoken_id_to_subtoken_string(s) for s in subtokens])
split = concatenated.split("_")
ret = []
for t in split:
if t:
unescaped = _unescape_token(t + "_")
if unescaped:
ret.append(unescap... | Converts a list of subtoken ids to a list of tokens.
Args:
subtokens: a list of integers in the range [0, vocab_size)
Returns:
a list of strings. |
def _try_parse_basic_number(self, data):
try:
return int(data)
except ValueError:
pass
try:
return float(data)
except ValueError:
pass
return data | Try to convert the data into ``int`` or ``float``.
:returns: ``Decimal`` or ``data`` if conversion fails. |
def _ParseEventData(self, variable_length_section):
event_data = WinJobEventData()
event_data.application = (
variable_length_section.application_name.rstrip('\x00'))
event_data.comment = variable_length_section.comment.rstrip('\x00')
event_data.parameters = (
variable_length_section.par... | Parses the event data form a variable-length data section.
Args:
variable_length_section (job_variable_length_data_section): a
Windows Scheduled Task job variable-length data section.
Returns:
WinJobEventData: event data of the job file. |
def init(args=None):
if args is None:
args = []
arr = (ctypes.c_char_p * len(args))()
arr[:] = args
_LIB.RabitInit(len(arr), arr) | Initialize the rabit library with arguments |
def create_chunked_list(in_dir, size, out_dir, out_name):
create_dirs(out_dir)
in_files = get_files(in_dir)
chunks = chunk(in_files, size)
division = {}
for i, files in enumerate(chunks):
division[i] = [os.path.basename(f) for f in files]
out_file = os.path.join(out_dir, out_name)
wi... | Create a division of the input files in chunks.
The result is stored to a JSON file. |
def _nose_tools_functions():
module = _BUILDER.string_build(
textwrap.dedent(
)
)
try:
case = next(module["a"].infer())
except astroid.InferenceError:
return
for method in case.methods():
if method.name.startswith("assert") and "_" not in method.name:
... | Get an iterator of names and bound methods. |
def child_link_extent(self):
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('Rock Ridge extension not yet initialized')
if self.dr_entries.cl_record is not None:
return self.dr_entries.cl_record.child_log_block_num
if self.ce_entries.cl_record is no... | Get the extent of the child of this entry if it has one.
Parameters:
None.
Returns:
The logical block number of the child if it exists. |
def _allows_url (self, url_data, roboturl):
with cache_lock:
if roboturl in self.cache:
self.hits += 1
rp = self.cache[roboturl]
return rp.can_fetch(self.useragent, url_data.url)
self.misses += 1
kwargs = dict(auth=url_data.auth, se... | Ask robots.txt allowance. Assumes only single thread per robots.txt
URL calls this function. |
def attach(self, num_name, write=0):
if isinstance(num_name, bytes):
num = self.find(num_name)
else:
num = num_name
vg_id = _C.Vattach(self._hdf_inst._id, num,
write and 'w' or 'r')
_checkErr('vattach', vg_id, "cannot attach Vgroup")
... | Open an existing vgroup given its name or its reference
number, or create a new vgroup, returning a VG instance for
that vgroup.
Args::
num_name reference number or name of the vgroup to open,
or -1 to create a new vgroup; vcreate() can also
... |
def _postback(self):
return requests.post(self.get_endpoint(),
data=dict(cmd="_notify-synch", at=IDENTITY_TOKEN, tx=self.tx)).content | Perform PayPal PDT Postback validation.
Sends the transaction ID and business token to PayPal which responses with
SUCCESS or FAILED. |
def list_files(dirname, extension=None):
f = []
for (dirpath, dirnames, filenames) in os.walk(dirname):
f.extend(filenames)
break
if extension is not None:
filtered = []
for filename in f:
fn, ext = os.path.splitext(filename)
if ext.lower() == '.' + ex... | List all files in directory `dirname`, option to filter on file extension |
def get_log_metric(
self,
metric_name,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
if "get_log_metric" not in self._inner_api_calls:
self._inner_api_calls[
"get_log_metri... | Gets a logs-based metric.
Example:
>>> from google.cloud import logging_v2
>>>
>>> client = logging_v2.MetricsServiceV2Client()
>>>
>>> metric_name = client.metric_path('[PROJECT]', '[METRIC]')
>>>
>>> response = client.get_log... |
def size_on_disk(self, start_pos=0):
size = 1
fmts = opcode_table[self.opcode]['operands']
if self.wide:
size += 2
if self.opcode == 0x84:
size += 2
elif fmts:
for fmt, _ in fmts:
size += fmt.value.size
elif self... | Returns the size of this instruction and its operands when
packed. `start_pos` is required for the `tableswitch` and
`lookupswitch` instruction as the padding depends on alignment. |
def setup_sanitize_files(self):
for fname in self.get_sanitize_files():
with open(fname, 'r') as f:
self.sanitize_patterns.update(get_sanitize_patterns(f.read())) | For each of the sanitize files that were specified as command line options
load the contents of the file into the sanitise patterns dictionary. |
def delete(self, request, **resources):
resource = resources.get(self._meta.name)
if not resource:
raise HttpError("Bad request", status=status.HTTP_404_NOT_FOUND)
for o in as_tuple(resource):
o.delete()
return HttpResponse("") | Default DELETE method. Allow bulk delete.
:return django.http.response: empty response |
def init_db():
db.drop_all()
db.create_all()
title = "de Finibus Bonorum et Malorum - Part I"
text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor \
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud \
exe... | Populate a small db with some example entries. |
def print_email(message, app):
invenio_mail = app.extensions['invenio-mail']
with invenio_mail._lock:
invenio_mail.stream.write(
'{0}\n{1}\n'.format(message.as_string(), '-' * 79))
invenio_mail.stream.flush() | Print mail to stream.
Signal handler for email_dispatched signal. Prints by default the output
to the stream specified in the constructor of InvenioMail.
:param message: Message object.
:param app: Flask application object. |
def license_fallback(vendor_dir, sdist_name):
libname = libname_from_dir(sdist_name)
if libname not in HARDCODED_LICENSE_URLS:
raise ValueError('No hardcoded URL for {} license'.format(libname))
url = HARDCODED_LICENSE_URLS[libname]
_, _, name = url.rpartition('/')
dest = license_destination... | Hardcoded license URLs. Check when updating if those are still needed |
def get_time_period(value):
for time_period in TimePeriod:
if time_period.period == value:
return time_period
raise ValueError('{} is not a valid TimePeriod'.format(value)) | Get the corresponding TimePeriod from the value.
Example values: 'all', 'hour', 'day', 'week', or 'month'. |
def _groupby_new_state(index, outputs, decisions):
output_map = {o: i for i, o in enumerate(outputs)}
groups = pd.Series(index).groupby([output_map[d] for d in decisions])
results = [(outputs[i], pd.Index(sub_group.values)) for i, sub_group in groups]
selected_outputs = [o for o, _ in results]
for o... | Groups the simulants in the index by their new output state.
Parameters
----------
index : iterable of ints
An iterable of integer labels for the simulants.
outputs : iterable
A list of possible output states.
decisions : `pandas.Series`
A series containing the name of the n... |
def qs_add(self, *args, **kwargs):
query = self.query.copy()
if args:
mdict = MultiDict(args[0])
for k, v in mdict.items():
query.add(k, v)
for k, v in kwargs.items():
query.add(k, v)
return self._copy(query=query) | Add value to QuerySet MultiDict |
def _is_valid_index(self, index):
if isinstance(index, int):
return (index >= 0) and (index < len(self))
if isinstance(index, list):
valid = True
for i in index:
valid = valid or self._is_valid_index(i)
return valid
return False | Return ``True`` if and only if the given ``index``
is valid. |
def render(self, obj, name, context):
if self.value_lambda is not None:
val = self.value_lambda(obj)
else:
attr_name = name
if self.property_name is not None:
attr_name = self.property_name
if isinstance(obj, dict):
val = ob... | The default field renderer.
This basic renderer assumes that the object has an attribute with
the same name as the field, unless a different field is specified
as a `property_name`.
The renderer is also passed the context so that it can be
propagated to the `_render_serializabl... |
def _validate_prepare_time(self, t, pos_c):
if hasattr(t, 'unit'):
t = t.decompose(self.units).value
if not isiterable(t):
t = np.atleast_1d(t)
t = np.ascontiguousarray(t.ravel())
if len(t) > 1:
if len(t) != pos_c.shape[0]:
raise ValueE... | Make sure that t is a 1D array and compatible with the C position array. |
def _get_mapping_for_table(self, table):
for mapping in self.mappings.values():
if mapping["table"] == table:
return mapping | Returns the first mapping for a table name |
def _parse_statements(lines):
lines = (l.strip() for l in lines if l)
lines = (l for l in lines if l and not l.startswith('--'))
parts = []
for line in lines:
parts.append(line.rstrip(';'))
if line.endswith(';'):
yield '\n'.join(parts)
parts[:] = []
if parts:
... | Return a generator of statements
Args: A list of strings that can contain one or more statements.
Statements are separated using ';' at the end of a line
Everything after the last ';' will be treated as the last statement.
>>> list(_parse_statements(['select * from ', 't1;', 'select name']... |
def vector_args(self, args):
for i in reversed(range(self._vector_count)):
pieces = []
for vec in args:
pieces.append(vec[(i+1) * self._vector_size - 1 : i * self._vector_size])
yield pieces | Yields each of the individual lane pairs from the arguments, in
order from most significan to least significant |
def str_args(args):
res = []
for x in args:
if isinstance(x, tuple) and len(x) == 2:
key, value = x
if value and str_arg(value):
res += ["%s=%s" % (key, str_arg(value))]
else:
res += [str_arg(x)]
return ', '.join(res) | formats a list of function arguments prettily not as code
(kwargs are tuples (argname, argvalue) |
def ratio_to_ave(window, eqdata, **kwargs):
_selection = kwargs.get('selection', 'Volume')
_skipstartrows = kwargs.get('skipstartrows', 0)
_skipendrows = kwargs.get('skipendrows', 0)
_outputcol = kwargs.get('outputcol', 'Ratio to Ave')
_size = len(eqdata.index)
_eqdata = eqdata.loc[:, _selection... | Return values expressed as ratios to the average over some number
of prior sessions.
Parameters
----------
eqdata : DataFrame
Must contain a column with name matching `selection`, or, if
`selection` is not specified, a column named 'Volume'
window : int
Interval over which t... |
def create_pgm_dict(
lambdaFile: str,
asts: List,
file_name: str,
mode_mapper_dict: dict,
save_file=False,
) -> Dict:
lambdaStrings = ["import math\n\n"]
state = PGMState(lambdaStrings)
generator = GrFNGenerator()
generator.mode_mapper = mode_mapper_dict
pgm = generator.genPgm(as... | Create a Python dict representing the PGM, with additional metadata for
JSON output. |
def db_validate_yubikey_otp(self, public_id, otp):
return pyhsm.db_cmd.YHSM_Cmd_DB_Validate_OTP( \
self.stick, public_id, otp).execute() | Request the YubiHSM to validate an OTP for a YubiKey stored
in the internal database.
@param public_id: The six bytes public id of the YubiKey
@param otp: The OTP from a YubiKey in binary form (16 bytes)
@type public_id: string
@type otp: string
@returns: validation res... |
def size(self):
old = self.__file.tell()
self.__file.seek(0, 2)
n_bytes = self.__file.tell()
self.__file.seek(old)
return n_bytes | Calculate and return the file size in bytes. |
def _get_token(self, oauth_request, token_type='access'):
token_field = oauth_request.get_parameter('oauth_token')
token = self.data_store.lookup_token(token_type, token_field)
if not token:
raise OAuthError('Invalid %s token: %s' % (token_type, token_field))
return token | Try to find the token for the provided request token key. |
def consume_keys_asynchronous_processes(self):
print("\nLooking up " + self.input_queue.qsize().__str__() + " keys from " + self.source_name + "\n")
jobs = multiprocessing.cpu_count()*4 if (multiprocessing.cpu_count()*4 < self.input_queue.qsize()) \
else self.input_queue.qsize()
pool... | Work through the keys to look up asynchronously using multiple processes |
def bulk_copy(self, ids):
schema = UserSchema()
return self.service.bulk_copy(self.base, self.RESOURCE, ids, schema) | Bulk copy a set of users.
:param ids: Int list of user IDs.
:return: :class:`users.User <users.User>` list |
def _get_I(self, a, b, size, plus_transpose=True):
r_sum = np.zeros((3, 3), dtype='double', order='C')
for r in self._rotations_cartesian:
for i in range(3):
for j in range(3):
r_sum[i, j] += r[a, i] * r[b, j]
if plus_transpose:
r_sum +... | Return I matrix in Chaput's PRL paper.
None is returned if I is zero matrix. |
def get_link_map(self, nslave):
tree_map, parent_map = self.get_tree(nslave)
ring_map = self.get_ring(tree_map, parent_map)
rmap = {0 : 0}
k = 0
for i in range(nslave - 1):
k = ring_map[k][1]
rmap[k] = i + 1
ring_map_ = {}
tree_map_ = {}
... | get the link map, this is a bit hacky, call for better algorithm
to place similar nodes together |
def detach_disk(name=None, kwargs=None, call=None):
if call != 'action':
raise SaltCloudSystemExit(
'The detach_Disk action must be called with -a or --action.'
)
if not name:
log.error(
'Must specify an instance name.'
)
return False
if not kw... | Detach a disk from an instance.
CLI Example:
.. code-block:: bash
salt-cloud -a detach_disk myinstance disk_name=mydisk |
def set_random_state(state):
randgen.state_set = True
randgen.setstate(state)
faker.generator.random.setstate(state) | Force-set the state of factory.fuzzy's random generator. |
def package_releases(request, package_name, show_hidden=False):
session = DBSession()
package = Package.by_name(session, package_name)
return [rel.version for rel in package.sorted_releases] | Retrieve a list of the releases registered for the given package_name.
Returns a list with all version strings if show_hidden is True or
only the non-hidden ones otherwise. |
def right(self):
if self._has_real():
return self._data.real_right
return self._data.right | Right coordinate. |
def compare_wfns(cls, source, target):
for att in CPEComponent.CPE_COMP_KEYS_EXTENDED:
value_src = source.get_attribute_values(att)[0]
if value_src.find('"') > -1:
value_src = value_src[1:-1]
value_tar = target.get_attribute_values(att)[0]
if value... | Compares two WFNs and returns a generator of pairwise attribute-value
comparison results. It provides full access to the individual
comparison results to enable use-case specific implementations
of novel name-comparison algorithms.
Compare each attribute of the Source WFN to the Target ... |
def _platform(self) -> Optional[str]:
try:
return str(self.journey.MainStop.BasicStop.Dep.Platform.text)
except AttributeError:
return None | Extract platform. |
def bschoc(value, ndim, lenvals, array, order):
value = stypes.stringToCharP(value)
ndim = ctypes.c_int(ndim)
lenvals = ctypes.c_int(lenvals)
array = stypes.listToCharArrayPtr(array, xLen=lenvals, yLen=ndim)
order = stypes.toIntVector(order)
return libspice.bschoc_c(value, ndim, lenvals, array, ... | Do a binary search for a given value within a character string array,
accompanied by an order vector. Return the index of the matching array
entry, or -1 if the key value is not found.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/bschoc_c.html
:param value: Key value to be found in array.
... |
def by_ip(self, ip):
try:
number = inet_aton(ip)
except Exception:
raise IpRange.DoesNotExist
try:
return self.filter(start_ip__lte=number, end_ip__gte=number)\
.order_by('end_ip', '-start_ip')[0]
except IndexError:
r... | Find the smallest range containing the given IP. |
def set_contourf_properties(stroke_width, fcolor, fill_opacity, contour_levels, contourf_idx, unit):
return {
"stroke": fcolor,
"stroke-width": stroke_width,
"stroke-opacity": 1,
"fill": fcolor,
"fill-opacity": fill_opacity,
"title": "%.2f" % contour_levels[contourf_i... | Set property values for Polygon. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.