code stringlengths 51 2.38k | docstring stringlengths 4 15.2k |
|---|---|
def provide_label(self):
return [(k, tuple([self.batch_size] + list(v.shape[1:]))) for k, v in self.label] | The name and shape of label provided by this iterator |
def cli_reload(self, event):
self.log('Reloading all components.')
self.update_components(forcereload=True)
initialize()
from hfos.debugger import cli_compgraph
self.fireEvent(cli_compgraph()) | Experimental call to reload the component tree |
def get_records_with_attachments(attachment_table, rel_object_field="REL_OBJECTID"):
if arcpyFound == False:
raise Exception("ArcPy is required to use this function")
OIDs = []
with arcpy.da.SearchCursor(attachment_table,
[rel_object_field]) as rows:
for row in... | returns a list of ObjectIDs for rows in the attachment table |
def create_objective_bank(self, *args, **kwargs):
return ObjectiveBank(
self._provider_manager,
self._get_provider_session('objective_bank_admin_session').create_objective_bank(*args, **kwargs),
self._runtime,
self._proxy) | Pass through to provider ObjectiveBankAdminSession.create_objective_bank |
def iterintervals(self, n=2):
streams = tee(iter(self), n)
for stream_index, stream in enumerate(streams):
for i in range(stream_index):
next(stream)
for intervals in zip(*streams):
yield intervals | Iterate over groups of `n` consecutive measurement points in the
time series. |
def filter_create(self, phrase, context, irreversible = False, whole_word = True, expires_in = None):
params = self.__generate_params(locals())
for context_val in context:
if not context_val in ['home', 'notifications', 'public', 'thread']:
raise MastodonIllegalArgumentError(... | Creates a new keyword filter. `phrase` is the phrase that should be
filtered out, `context` specifies from where to filter the keywords.
Valid contexts are 'home', 'notifications', 'public' and 'thread'.
Set `irreversible` to True if you want the filter to just delete statuses
s... |
def parse(self, type, data):
try:
return self.registered_formats[type]['parser'](data)
except KeyError:
raise NotImplementedError("No parser found for "
"type '{type}'".format(type=type)) | Parse text as a format.
:param type: The unique name of the format
:param data: The text to parse as the format |
def add_view(self, *args, **kwargs):
try:
singleton = self.model.objects.get()
except (self.model.DoesNotExist, self.model.MultipleObjectsReturned):
kwargs.setdefault("extra_context", {})
kwargs["extra_context"]["singleton"] = True
response = super(Singlet... | Redirect to the change view if the singleton instance exists. |
def imageFields(self):
if self._imageFields is None:
ctx = SparkContext._active_spark_context
self._imageFields = list(ctx._jvm.org.apache.spark.ml.image.ImageSchema.imageFields())
return self._imageFields | Returns field names of image columns.
:return: a list of field names.
.. versionadded:: 2.3.0 |
def get_tensor_num_entries(self, tensor_name, partial_layout=None,
mesh_dimension_to_size=None):
shape = self.get_tensor_shape(tensor_name)
num_entries = 1
for dim in shape.dims:
num_entries = num_entries * dim.value
if not partial_layout:
return num_entries
... | The number of entries in a tensor.
If partial_layout is specified, then mesh_dimension_to_size must also be. In
this case, the number of entries on a single device is returned.
Args:
tensor_name: a string, name of a tensor in the graph.
partial_layout: an optional {string: string}, from MTF di... |
def _get_folds(n_rows, n_folds, use_stored):
if use_stored is not None:
with open(os.path.expanduser(use_stored)) as json_file:
json_data = json.load(json_file)
if json_data['N_rows'] != n_rows:
raise Exception('N_rows from folds doesnt match the number of... | Get the used CV folds |
def cpu_count(logical=True):
if logical:
from multiprocessing import cpu_count
ncpu=cpu_count()
else:
import psutil
ncpu=psutil.cpu_count(logical=False)
return ncpu | Return system CPU count |
def set_codes(self, codes, reject=False):
self.codes = set(codes)
self.reject = reject | Set the accepted or rejected codes codes list.
:param codes: A list of the response codes.
:param reject: If True, the listed codes will be rejected, and
the conversion will format as "-"; if False,
only the listed codes will be accepted, and the
... |
def initialize_unbounded(obj, dimensions, key):
select = dict(zip([d.name for d in dimensions], key))
try:
obj.select([DynamicMap], **select)
except KeyError:
pass | Initializes any DynamicMaps in unbounded mode. |
def runcmds_plus_hooks(self, cmds: List[str]) -> bool:
stop = False
self.cmdqueue = list(cmds) + self.cmdqueue
try:
while self.cmdqueue and not stop:
line = self.cmdqueue.pop(0)
if self.echo and line != 'eos':
self.poutput('{}{}'.fo... | Convenience method to run multiple commands by onecmd_plus_hooks.
This method adds the given cmds to the command queue and processes the
queue until completion or an error causes it to abort. Scripts that are
loaded will have their commands added to the queue. Scripts may even
load othe... |
def args(self):
return (self.base, self.item, self.leng, self.refs,
self.both, self.kind, self.type) | Return all attributes as arguments tuple. |
def energy_upperbound(self, spins):
subtheta = self.theta.copy()
subtheta.fix_variables(spins)
trees = self._trees
if not trees:
assert not subtheta.linear and not subtheta.quadratic
return subtheta.offset
energy = Plus(self.message_upperbound(trees, {}, s... | A formula for an upper bound on the energy of Theta with spins fixed.
Args:
spins (dict): Spin values for a subset of the variables in Theta.
Returns:
Formula that upper bounds the energy with spins fixed. |
def load_emacs_open_in_editor_bindings():
registry = Registry()
registry.add_binding(Keys.ControlX, Keys.ControlE,
filter=EmacsMode() & ~HasSelection())(
get_by_name('edit-and-execute-command'))
return registry | Pressing C-X C-E will open the buffer in an external editor. |
def sync_focus(self, *_):
if self.display_popup:
self.app.layout.focus(self.layout_manager.popup_dialog)
return
if self.confirm_text:
return
if self.prompt_command:
return
if self.command_mode:
return
if not self.pymux.a... | Focus the focused window from the pymux arrangement. |
def describe_db_subnet_groups(name=None, filters=None, jmespath='DBSubnetGroups',
region=None, key=None, keyid=None, profile=None):
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
pag = conn.get_paginator('describe_db_subnet_groups')
args = {}
args.up... | Return a detailed listing of some, or all, DB Subnet Groups visible in the
current scope. Arbitrary subelements or subsections of the returned dataset
can be selected by passing in a valid JMSEPath filter as well.
CLI example::
salt myminion boto_rds.describe_db_subnet_groups |
def get_link(self, task_id):
links = [x for x in self.links if x.task_id == task_id]
if len(links) != 1:
raise CoTError("No single Link matches task_id {}!\n{}".format(task_id, self.dependent_task_ids()))
return links[0] | Get a ``LinkOfTrust`` by task id.
Args:
task_id (str): the task id to find.
Returns:
LinkOfTrust: the link matching the task id.
Raises:
CoTError: if no ``LinkOfTrust`` matches. |
def is_ready(self):
response = self.get()
if response.status == 204:
return False
self._state = self.read(response)
ready = self._state.content['dispatchState'] not in ['QUEUED', 'PARSING']
return ready | Indicates whether this job is ready for querying.
:return: ``True`` if the job is ready, ``False`` if not.
:rtype: ``boolean`` |
def to_trip(
self,
smooth,
smooth_strategy,
smooth_noise,
seg,
seg_eps,
seg_min_time,
simplify,
simplify_max_dist_error,
simplify_max_speed_error
):
self.compute_metrics()
self... | In-place, transformation of a track into a trip
A trip is a more accurate depiction of reality than a
track.
For a track to become a trip it need to go through the
following steps:
+ noise removal
+ smoothing
+ spatio-temporal segmentation
... |
def coerce(value):
if isinstance(value, ListCell):
return value
elif isinstance(value, (list)):
return ListCell(value)
else:
return ListCell([value]) | Turns a value into a list |
def relpath_to_site(lang, target_lang):
path = _SITES_RELPATH_DB.get((lang, target_lang), None)
if path is None:
siteurl = _SITE_DB.get(lang, _MAIN_SITEURL)
target_siteurl = _SITE_DB.get(target_lang, _MAIN_SITEURL)
path = posixpath.relpath(get_site_path(target_siteurl),
... | Get relative path from siteurl of lang to siteurl of base_lang
the output is cached in _SITES_RELPATH_DB |
def command(cls, command, stdin=None, shell=False):
if not shell and isinstance(command, str):
command = cls.shlex.split(command)
collate_original = None
try:
collate_original = cls.os.environ['LC_ALL']
except KeyError:
pass
cls.os.environ['LC_... | Runs specified command.
The command can be fed with data on stdin with parameter ``stdin``.
The command can also be treated as a shell command with parameter ``shell``.
Please refer to subprocess.Popen on how does this stuff work
:returns: Run() instance with resulting data |
def activate_boost_by_name(self,
zone_name,
target_temperature,
num_hours=1):
zone = self.get_zone(zone_name)
if zone is None:
raise RuntimeError("Unknown zone")
return self.activate_boost_by... | Activate boost by the name of the zone |
def _check_arg_length(fname, args, max_fname_arg_count, compat_args):
if max_fname_arg_count < 0:
raise ValueError("'max_fname_arg_count' must be non-negative")
if len(args) > len(compat_args):
max_arg_count = len(compat_args) + max_fname_arg_count
actual_arg_count = len(args) + max_fnam... | Checks whether 'args' has length of at most 'compat_args'. Raises
a TypeError if that is not the case, similar to in Python when a
function is called with too many arguments. |
def getPos(position, pagesize):
position = str(position).split()
if len(position) != 2:
raise Exception("position not defined right way")
x, y = [getSize(pos) for pos in position]
return getCoords(x, y, None, None, pagesize) | Pair of coordinates |
def run_job(self, job=None):
if job is None:
if not self.queue:
return None
job = self.queue.popleft()
start = timer()
func, args = job
reply = func(*args)
end = timer()
if end - start > 0.1:
_LOGGER.debug(
... | Run a job, either passed in or from the queue.
A job is a tuple of function and optional args. Keyword arguments
can be passed via use of functools.partial. The job should return a
string that should be sent by the gateway protocol. The function will
be called with the arguments and the... |
def hvenvup(package, directory):
pip = Command(DIR.gen.joinpath("hvenv", "bin", "pip"))
pip("uninstall", package, "-y").run()
pip("install", DIR.project.joinpath(directory).abspath()).run() | Install a new version of a package in the hitch venv. |
def save(self):
with open(self.filename, 'w') as plist_file:
plist_file.write(str(self.soup)) | Save current property list representation to the original file. |
def split(self):
self._annotate_groups()
index = 0
for group in range(self._max_group):
subgraph = copy(self)
subgraph.metadata = self.metadata[:]
subgraph.edges = self.edges.copy()
if subgraph._filter_group(group):
subgraph.total_s... | Split the graph into sub-graphs. Only connected objects belong to the
same graph. `split` yields copies of the Graph object. Shallow copies
are used that only replicate the meta-information, but share the same
object list ``self.objects``.
>>> from pympler.refgraph import ReferenceGraph... |
def delete_row(self, index):
body = {
"requests": [{
"deleteDimension": {
"range": {
"sheetId": self.id,
"dimension": "ROWS",
"startIndex": index - 1,
"endIndex": index
... | Deletes the row from the worksheet at the specified index.
:param index: Index of a row for deletion.
:type index: int |
def get_other_keys(self, key, including_current=False):
other_keys = []
if key in self:
other_keys.extend(self.__dict__[str(type(key))][key])
if not including_current:
other_keys.remove(key)
return other_keys | Returns list of other keys that are mapped to the same value as specified key.
@param key - key for which other keys should be returned.
@param including_current if set to True - key will also appear on this list. |
def get_secret_registration_block_by_secrethash(
self,
secrethash: SecretHash,
block_identifier: BlockSpecification,
) -> Optional[BlockNumber]:
result = self.proxy.contract.functions.getSecretRevealBlockHeight(
secrethash,
).call(block_identifier=bloc... | Return the block number at which the secret for `secrethash` was
registered, None if the secret was never registered. |
def im_detect(self, im_list, root_dir=None, extension=None, show_timer=False):
test_db = TestDB(im_list, root_dir=root_dir, extension=extension)
test_iter = DetIter(test_db, 1, self.data_shape, self.mean_pixels,
is_train=False)
return self.detect_iter(test_iter, show_... | wrapper for detecting multiple images
Parameters:
----------
im_list : list of str
image path or list of image paths
root_dir : str
directory of input images, optional if image path already
has full directory information
extension : str
... |
def arbitrary_object_to_string(a_thing):
if a_thing is None:
return ''
if isinstance(a_thing, six.string_types):
return a_thing
if six.PY3 and isinstance(a_thing, six.binary_type):
try:
return a_thing.decode('utf-8')
except UnicodeDecodeError:
pass
... | take a python object of some sort, and convert it into a human readable
string. this function is used extensively to convert things like "subject"
into "subject_key, function -> function_key, etc. |
def chdir(new_dir):
cur_dir = os.getcwd()
_mkdir(new_dir)
os.chdir(new_dir)
try:
yield
finally:
os.chdir(cur_dir) | stolen from bcbio.
Context manager to temporarily change to a new directory.
http://lucentbeing.com/blog/context-managers-and-the-with-statement-in-python/ |
def check_if_not(x, *checks, **params):
for p in params:
if params[p] is not x and params[p] != x:
[check(**{p: params[p]}) for check in checks] | Run checks only if parameters are not equal to a specified value
Parameters
----------
x : excepted value
Checks not run if parameters equal x
checks : function
Unnamed arguments, check functions to be run
params : object
Named arguments, parameters to be checked
Rai... |
def spin_gen_op(oper, gauge):
slaves = len(gauge)
oper['O'] = np.array([spin_gen(slaves, i, c) for i, c in enumerate(gauge)])
oper['O_d'] = np.transpose(oper['O'], (0, 2, 1))
oper['O_dO'] = np.einsum('...ij,...jk->...ik', oper['O_d'], oper['O'])
oper['Sfliphop'] = spinflipandhop(slaves) | Generates the generic spin matrices for the system |
def circulation(self):
L = self.angular_momentum()
if L.ndim == 2:
single_orbit = True
L = L[...,None]
else:
single_orbit = False
ndim,ntimes,norbits = L.shape
L0 = L[:,0]
circ = np.ones((ndim,norbits))
for ii in range(ndim):
... | Determine which axes the Orbit circulates around by checking
whether there is a change of sign of the angular momentum
about an axis. Returns a 2D array with ``ndim`` integers per orbit
point. If a box orbit, all integers will be 0. A 1 indicates
circulation about the corresponding axis.... |
def getSampleTypeTitles(self):
sample_types = self.getSampleTypes()
sample_type_titles = map(lambda obj: obj.Title(), sample_types)
if not sample_type_titles:
return [""]
return sample_type_titles | Returns a list of sample type titles |
def get_by_id(self, reply_id):
reply = MReply.get_by_uid(reply_id)
logger.info('get_reply: {0}'.format(reply_id))
self.render('misc/reply/show_reply.html',
reply=reply,
username=reply.user_name,
date=reply.date,
vote... | Get the reply by id. |
def linreg_mle(y, X, algorithm='Nelder-Mead', debug=False):
import numpy as np
import scipy.stats as sstat
import scipy.optimize as sopt
def objective_nll_linreg(theta, y, X):
yhat = np.dot(X, theta[:-1])
return -1.0 * sstat.norm.logpdf(y, loc=yhat, scale=theta[-1]).sum()
if algorith... | MLE for Linear Regression Model
Parameters:
-----------
y : ndarray
target variable with N observations
X : ndarray
The <N x C> design matrix with C independent
variables, features, factors, etc.
algorithm : str
Optional. Default 'Nelder-Mead' (Simplex).
Th... |
def _load_lib():
lib_path = find_lib_path()
if len(lib_path) == 0:
return None
lib = ctypes.cdll.LoadLibrary(lib_path[0])
lib.LGBM_GetLastError.restype = ctypes.c_char_p
return lib | Load LightGBM library. |
def to_numpy(self):
assert HAS_NUMPY, 'numpy is not installed.'
import numpy
return numpy.transpose(numpy.asarray([self[x] for x in self.column_names()])) | Converts this SFrame to a numpy array
This operation will construct a numpy array in memory. Care must
be taken when size of the returned object is big.
Returns
-------
out : numpy.ndarray
A Numpy Array containing all the values of the SFrame |
def project_hidden(x, projection_tensors, hidden_size, num_blocks):
batch_size, latent_dim, _ = common_layers.shape_list(x)
x = tf.reshape(x, shape=[1, -1, hidden_size])
x_tiled = tf.reshape(
tf.tile(x, multiples=[num_blocks, 1, 1]),
shape=[num_blocks, -1, hidden_size])
x_projected = tf.matmul(x_til... | Project encoder hidden state under num_blocks using projection tensors.
Args:
x: Encoder hidden state of shape [batch_size, latent_dim, hidden_size].
projection_tensors: Projection tensors used to project the hidden state.
hidden_size: Dimension of the latent space.
num_blocks: Number of blocks in D... |
def insert_table(self, label = None, name = None, **kwargs):
data_frame = kwargs.pop('data_frame', None)
if data_frame is None:
data_frame = kwargs.pop('dataframe', None)
to_hdf_kwargs = kwargs.pop('to_hdf_kwargs', dict())
if data_frame is not None:
assert isinsta... | Insert a table in the Survey object |
def iters(cls, batch_size=32, device=0, root='.data',
vectors=None, trees=False, **kwargs):
if trees:
TEXT = ParsedTextField()
TRANSITIONS = ShiftReduceField()
else:
TEXT = data.Field(tokenize='spacy')
TRANSITIONS = None
LABEL = data.... | Create iterator objects for splits of the SNLI dataset.
This is the simplest way to use the dataset, and assumes common
defaults for field, vocabulary, and iterator parameters.
Arguments:
batch_size: Batch size.
device: Device to create batches on. Use -1 for CPU and No... |
def train_all(ctx, output):
click.echo('chemdataextractor.pos.train_all')
click.echo('Output: %s' % output)
ctx.invoke(train, output='%s_wsj_nocluster.pickle' % output, corpus='wsj', clusters=False)
ctx.invoke(train, output='%s_wsj.pickle' % output, corpus='wsj', clusters=True)
ctx.invoke(train, out... | Train POS tagger on WSJ, GENIA, and both. With and without cluster features. |
def open(self):
self._connection = \
amqp.Connection(host='%s:%s' % (self.hostname, self.port),
userid=self.username, password=self.password,
virtual_host=self.virtual_host, insist=False)
self.channel = self._connection.channel() | Open a connection to the AMQP compliant broker. |
def _interleave(self):
from pandas.core.dtypes.common import is_sparse
dtype = _interleaved_dtype(self.blocks)
if is_sparse(dtype):
dtype = dtype.subtype
elif is_extension_array_dtype(dtype):
dtype = 'object'
result = np.empty(self.shape, dtype=dtype)
... | Return ndarray from blocks with specified item order
Items must be contained in the blocks |
def remove_this_tlink(self,tlink_id):
for tlink in self.get_tlinks():
if tlink.get_id() == tlink_id:
self.node.remove(tlink.get_node())
break | Removes the tlink for the given tlink identifier
@type tlink_id: string
@param tlink_id: the tlink identifier to be removed |
def to_multidimensional(tpm):
tpm = np.array(tpm)
N = tpm.shape[-1]
return tpm.reshape([2] * N + [N], order="F").astype(float) | Reshape a state-by-node TPM to the multidimensional form.
See documentation for the |Network| object for more information on TPM
formats. |
def synchronise(func):
def inner(request, *args):
lock_id = '%s-%s-built-%s' % (
datetime.date.today(), func.__name__,
",".join([str(a) for a in args]))
if cache.add(lock_id, 'true', LOCK_EXPIRE):
result = func(request, *args)
cache.set(lock_id, result... | If task already queued, running, or finished, don't restart. |
def apply(self, builder, model):
builder.where_null(model.get_qualified_deleted_at_column())
self.extend(builder) | Apply the scope to a given query builder.
:param builder: The query builder
:type builder: orator.orm.builder.Builder
:param model: The model
:type model: orator.orm.Model |
def gfpa(target, illmin, abcorr, obsrvr, relate, refval, adjust, step, nintvals,
cnfine, result=None):
assert isinstance(cnfine, stypes.SpiceCell)
assert cnfine.is_double()
if result is None:
result = stypes.SPICEDOUBLE_CELL(2000)
else:
assert isinstance(result, stypes.SpiceCell... | Determine time intervals for which a specified constraint
on the phase angle between an illumination source, a target,
and observer body centers is met.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/gfpa_c.html
:param target: Name of the target body.
:type target: str
:param illmin: ... |
def get_details(self, jobname, jobkey):
fullkey = JobDetails.make_fullkey(jobname, jobkey)
return self._cache[fullkey] | Get the `JobDetails` associated to a particular job instance |
def get_missing_deps(self, obj):
deps = self.get_deps(obj)
ret = []
for key in deps:
provider = self._providers.get(key)
if provider and provider.providable:
continue
ret.append(key)
return ret | Returns missing dependencies for provider key.
Missing meaning no instance can be provided at this time.
:param key: Provider key
:type key: object
:return: Missing dependencies
:rtype: list |
def db_dp010(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 `db_dp010`'.format(value))
self._db_dp010 = value | Corresponds to IDD Field `db_dp010`
mean coincident dry-bulb temperature to
Dew-point temperature corresponding to 1.0% annual cumulative frequency of occurrence
Args:
value (float): value for IDD Field `db_dp010`
Unit: C
if `value` is None it will no... |
def rolling(self, window, min_periods=None, center=False, win_type=None, on=None, axis=0, closed=None):
kwds = {
"window": window,
"min_periods": min_periods,
"center": center,
"win_type": win_type,
"on": on,
"axis": axis,
"clos... | Create a swifter rolling object |
def find_coord_vars(ncds):
coord_vars = []
for d in ncds.dimensions:
if d in ncds.variables and ncds.variables[d].dimensions == (d,):
coord_vars.append(ncds.variables[d])
return coord_vars | Finds all coordinate variables in a dataset.
A variable with the same name as a dimension is called a coordinate variable. |
def owner_search_fields(self):
try:
from django.contrib.auth import get_user_model
except ImportError:
from django.contrib.auth.models import User
else:
User = get_user_model()
return [
field.name for field in User._meta.fields
... | Returns all the fields that are CharFields except for password from the
User model. For the built-in User model, that means username,
first_name, last_name, and email. |
def get_all_chains(self):
return [self.get_chain(i) for i in range(len(self.leaves))] | Assemble and return a list of all chains for all leaf nodes to the merkle root. |
def notice(self, target, msg):
self.cmd(u'NOTICE', u'{0} :{1}'.format(target, msg)) | Sends a NOTICE to an user or channel.
:param target: user or channel to send to.
:type target: str
:param msg: message to send.
:type msg: basestring |
def dcc_send(self, mask, filepath):
return self.dcc.create('send', mask, filepath=filepath).ready | DCC SEND a file to mask. filepath must be an absolute path to
existing file |
def _check_valid_translation(self, translation):
if not isinstance(translation, np.ndarray) or not np.issubdtype(translation.dtype, np.number):
raise ValueError('Translation must be specified as numeric numpy array')
t = translation.squeeze()
if len(t.shape) != 1 or t.shape[0] != 3:
... | Checks that the translation vector is valid. |
def sync_to(self):
device_group_collection = self._meta_data['container']
cm = device_group_collection._meta_data['container']
sync_cmd = 'config-sync to-group %s' % self.name
cm.exec_cmd('run', utilCmdArgs=sync_cmd) | Wrapper method that synchronizes configuration to DG.
Executes the containing object's cm :meth:`~f5.bigip.cm.Cm.exec_cmd`
method to sync the configuration TO the device-group.
:note:: Both sync_to, and sync_from methods are convenience
methods which usually are not what this ... |
def plot(self, save_path=None, close=False, bbox_inches="tight", pad_inches=1):
for plot in self.subplots.flatten():
plot.set_xlim(-0.1, 1.1)
plot.set_ylim(-0.1, 1.1)
plot.axis("off")
if save_path:
plt.savefig(
save_path,
tr... | Plot figure.
Parameters
----------
save_path : string (optional)
Save path. Default is None.
close : boolean (optional)
Toggle automatic figure closure after plotting.
Default is False.
bbox_inches : number (optional)
Bounding box ... |
def _valid_baremetal_port(port):
if port.get(portbindings.VNIC_TYPE) != portbindings.VNIC_BAREMETAL:
return False
sgs = port.get('security_groups', [])
if len(sgs) == 0:
return False
if len(port.get('security_groups', [])) > 1:
LOG.warning('SG provisio... | Check if port is a baremetal port with exactly one security group |
def load_module(name):
spec = importlib.util.find_spec(name)
mod = importlib.util.module_from_spec(spec)
mod.__spec__ = spec
mod.__loader__ = spec.loader
spec.loader.exec_module(mod)
return mod | Load the named module without registering it in ``sys.modules``.
Parameters
----------
name : string
Module name
Returns
-------
mod : module
Loaded module |
def random(magnitude=1):
theta = random.uniform(0, 2 * math.pi)
return magnitude * Vector(math.cos(theta), math.sin(theta)) | Create a unit vector pointing in a random direction. |
def signal_handler(sig, frame):
print('\nYou pressed Ctrl+C')
if board is not None:
board.send_reset()
board.shutdown()
sys.exit(0) | Helper method to shutdown the RedBot if Ctrl-c is pressed |
def get_available_hashes():
if sys.version_info >= (3,2):
return hashlib.algorithms_available
elif sys.version_info >= (2,7) and sys.version_info < (3,0):
return hashlib.algorithms
else:
return 'md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512' | Returns a tuple of the available hashes |
def _have_conf(self, magic_hash=None):
self.app.have_conf = getattr(self.app, 'cur_conf', None) not in [None, {}]
if magic_hash is not None:
magic_hash = int(magic_hash)
return self.app.have_conf and self.app.cur_conf.magic_hash == magic_hash
return self.app.have_conf | Get the daemon current configuration state
If the daemon has received a configuration from its arbiter, this will
return True
If a `magic_hash` is provided it is compared with the one included in the
daemon configuration and this function returns True only if they match!
:retu... |
def is_pdf(document):
if not executable_exists('pdftotext'):
current_app.logger.warning(
"GNU file was not found on the system. "
"Switching to a weak file extension test."
)
if document.lower().endswith(".pdf"):
return True
return False
file_o... | Check if a document is a PDF file and return True if is is. |
def exit_if_path_exists(self):
if os.path.exists(self.output_path):
ui.error(c.MESSAGES["path_exists"], self.output_path)
sys.exit(1) | Exit early if the path cannot be found. |
def purge_items(app, env, docname):
keys = list(env.traceability_all_items.keys())
for key in keys:
if env.traceability_all_items[key]['docname'] == docname:
del env.traceability_all_items[key] | Clean, if existing, ``item`` entries in ``traceability_all_items``
environment variable, for all the source docs being purged.
This function should be triggered upon ``env-purge-doc`` event. |
def on_nicknameinuse(self, connection, event):
digits = ""
while self.nickname[-1].isdigit():
digits = self.nickname[-1] + digits
self.nickname = self.nickname[:-1]
digits = 1 if not digits else int(digits) + 1
self.nickname += str(digits)
self.connect(sel... | Increment a digit on the nickname if it's in use, and
re-connect. |
def logit(self, msg, pid, user, cname, priority=None):
if self.stream:
print(msg, file=self.stream)
elif priority == logging.WARNING:
self.logger.warning("{0}[pid:{1}] user:{2}: WARNING - {3}".format(cname, pid, user, msg))
elif priority == logging.ERROR:
self... | Function for formatting content and logging to syslog |
def answered_by(self, rec):
return self.clazz == rec.clazz and \
(self.type == rec.type or self.type == _TYPE_ANY) and \
self.name == rec.name | Returns true if the question is answered by the record |
def transform_incoming(self, son, collection):
def transform_value(value):
if isinstance(value, collections.MutableMapping):
if "_id" in value and "_ns" in value:
return DBRef(value["_ns"], transform_value(value["_id"]))
else:
r... | Replace embedded documents with DBRefs. |
def transformToNative(obj):
if obj.isNative:
return obj
obj.isNative = True
if obj.value == '':
return obj
obj.value=obj.value
obj.value=parseDtstart(obj, allowSignatureMismatch=True)
if getattr(obj, 'value_param', 'DATE-TIME').upper() == 'DATE-TIM... | Turn obj.value into a date or datetime. |
def sorensen(seq1, seq2):
set1, set2 = set(seq1), set(seq2)
return 1 - (2 * len(set1 & set2) / float(len(set1) + len(set2))) | Compute the Sorensen distance between the two sequences `seq1` and `seq2`.
They should contain hashable items.
The return value is a float between 0 and 1, where 0 means equal, and 1 totally different. |
def set_credentials(self, client_id=None, client_secret=None):
self._client_id = client_id
self._client_secret = client_secret
self._session = None | set given credentials and reset the session |
def merge_extends(self, target, extends, inherit_key="inherit", inherit=False):
if isinstance(target, dict):
if inherit and inherit_key in target and not to_boolean(target[inherit_key]):
return
if not isinstance(extends, dict):
raise ValueError("Unable to ... | Merge extended dicts |
def set_permitted_ip(address=None, deploy=False):
if not address:
raise CommandExecutionError("Address option must not be empty.")
ret = {}
query = {'type': 'config',
'action': 'set',
'xpath': '/config/devices/entry[@name=\'localhost.localdomain\']/deviceconfig/system/permi... | Add an IPv4 address or network to the permitted IP list.
CLI Example:
Args:
address (str): The IPv4 address or network to allow access to add to the Palo Alto device.
deploy (bool): If true then commit the full candidate configuration, if false only set pending change.
.. code-block:: ba... |
def set_user_presence(self, userid, presence):
response, status_code = self.__pod__.Presence.post_v2_user_uid_presence(
sessionToken=self.__session__,
uid=userid,
presence=presence
).result()
self.logger.debug('%s: %s' % (status_code, response))
return... | set presence of user |
def build_url_request(self):
params = {}
headers = {}
self._authenticator(params, headers)
self._grant(params)
return Request(self._endpoint, urlencode(params), headers) | Consults the authenticator and grant for HTTP request parameters and
headers to send with the access token request, builds the request using
the stored endpoint and returns it. |
def choices(self):
model_parent_part = self.part.model()
property_model = model_parent_part.property(self.name)
referenced_model = self._client.model(pk=property_model._value['id'])
possible_choices = self._client.parts(model=referenced_model)
return possible_choices | Retrieve the parts that you can reference for this `ReferenceProperty`.
This method makes 2 API calls: 1) to retrieve the referenced model, and 2) to retrieve the instances of
that model.
:return: the :class:`Part`'s that can be referenced as a :class:`~pykechain.model.PartSet`.
:raise... |
def encrypt(message, modN, e, blockSize):
numList = string2numList(message)
numBlocks = numList2blocks(numList, blockSize)
message = numBlocks[0]
return modExp(message, e, modN) | given a string message, public keys and blockSize, encrypt using
RSA algorithms. |
def assert_variable_type(variable, expected_type, raise_exception=True):
if not isinstance(expected_type, list):
expected_type = [expected_type]
for t in expected_type:
if not isinstance(t, type):
raise ValueError('expected_type argument "%s" is not a type' %str(t))
if not isinst... | Return True if a variable is of a certain type or types.
Otherwise raise a ValueError exception.
Positional arguments:
variable -- the variable to be checked
expected_type -- the expected type or types of the variable
raise_exception -- whether to raise an exception or just return
... |
def cmd(name,
tgt,
func,
arg=(),
tgt_type='glob',
ret='',
kwarg=None,
**kwargs):
ret = {'name': name,
'changes': {},
'comment': '',
'result': True}
local = salt.client.get_local_client(mopts=__opts__)
jid = local.cmd_as... | Execute a remote execution command
USAGE:
.. code-block:: yaml
run_remote_ex:
local.cmd:
- tgt: '*'
- func: test.ping
run_remote_ex:
local.cmd:
- tgt: '*'
- func: test.sleep
- arg:
- 30
run... |
def move_by_offset(self, xoffset, yoffset):
if self._driver.w3c:
self.w3c_actions.pointer_action.move_by(xoffset, yoffset)
self.w3c_actions.key_action.pause()
else:
self._actions.append(lambda: self._driver.execute(
Command.MOVE_TO, {
... | Moving the mouse to an offset from current mouse position.
:Args:
- xoffset: X offset to move to, as a positive or negative integer.
- yoffset: Y offset to move to, as a positive or negative integer. |
def set_mode_label_to_ifcw(self):
self.setWindowTitle(self.ifcw_name)
self.lblSubtitle.setText(tr(
'Use this wizard to run a guided impact assessment')) | Set the mode label to the IFCW. |
def process_shells(self, shells):
result = {'success': True, 'output': []}
if self.parallel and len(shells) > 1:
result = self.process_shells_parallel(shells)
elif len(shells) > 0:
result = self.process_shells_ordered(shells)
return result | Processing a list of shells. |
async def set_password(self, password):
await self.controller.change_user_password(self.username, password)
self._user_info.password = password | Update this user's password. |
def cltext(fname):
fnameP = stypes.stringToCharP(fname)
fname_len = ctypes.c_int(len(fname))
libspice.cltext_(fnameP, fname_len) | Internal undocumented command for closing a text file opened by RDTEXT.
No URL available; relevant lines from SPICE source:
FORTRAN SPICE, rdtext.f::
C$Procedure CLTEXT ( Close a text file opened by RDTEXT)
ENTRY CLTEXT ( FILE )
CHARACTER*(*) FILE
C VAR... |
def ndims(self):
if self._dims is None:
return None
else:
if self._ndims is None:
self._ndims = len(self._dims)
return self._ndims | Returns the rank of this shape, or None if it is unspecified. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.