code stringlengths 51 2.38k | docstring stringlengths 4 15.2k |
|---|---|
def signalize_extensions():
warnings.warn("DB-API extension cursor.rownumber used", SalesforceWarning)
warnings.warn("DB-API extension connection.<exception> used", SalesforceWarning)
warnings.warn("DB-API extension cursor.connection used", SalesforceWarning)
warnings.warn("DB-API extension cursor.messa... | DB API 2.0 extension are reported by warnings at run-time. |
def extend(self, delta):
if delta.total_seconds() < 0:
raise ValueError("delta must be a positive timedelta.")
if self.trial_end is not None and self.trial_end > timezone.now():
period_end = self.trial_end
else:
period_end = self.current_period_end
period_end += delta
return self.update(prorate=False... | Extends this subscription by the provided delta.
:param delta: The timedelta by which to extend this subscription.
:type delta: timedelta |
def _set_channel_gain(self, num):
if not 1 <= num <= 3:
raise AttributeError(
)
for _ in range(num):
logging.debug("_set_channel_gain called")
start_counter = time.perf_counter()
GPIO.output(self._pd_sck, True)
GPIO.output(self._pd_... | Finish data transmission from HX711 by setting
next required gain and channel
Only called from the _read function.
:param num: how often so do the set (1...3)
:type num: int
:return True on success
:rtype bool |
def _add_item(self, cls, *args, **kwargs):
box_index = kwargs.pop('box_index', self._default_box_index)
data = cls.validate(*args, **kwargs)
n = cls.vertex_count(**data)
if not isinstance(box_index, np.ndarray):
k = len(self._default_box_index)
box_index = _get_ar... | Add a plot item. |
def _write_plan(self, stream):
if self.plan is not None:
if not self._plan_written:
print("1..{0}".format(self.plan), file=stream)
self._plan_written = True | Write the plan line to the stream.
If we have a plan and have not yet written it out, write it to
the given stream. |
def transform(self, X, y=None, copy=None):
check_is_fitted(self, 'scale_')
copy = copy if copy is not None else self.copy
X = check_array(X, accept_sparse='csr', copy=copy, warn_on_dtype=True,
estimator=self, dtype=FLOAT_DTYPES)
if sparse.issparse(X):
... | Perform standardization by centering and scaling using the parameters.
:param X: Data matrix to scale.
:type X: numpy.ndarray, shape [n_samples, n_features]
:param y: Passthrough for scikit-learn ``Pipeline`` compatibility.
:type y: None
:param bool copy: Copy the X matrix.
... |
def get_offset(cls, info):
assert info.layer == 3
if info.version == 1:
if info.mode != 3:
return 36
else:
return 21
else:
if info.mode != 3:
return 21
else:
return 13 | Calculate the offset to the Xing header from the start of the
MPEG header including sync based on the MPEG header's content. |
def get_password(self):
if self.password is None:
if os.environ.get(self.username+'password'):
self.password = os.environ.get(self.username+'password')
else:
raise PasswordError(self.username) | If password is not provided will look in environment variables
for username+'password'. |
def faces_unique_edges(self):
populate = self.edges_unique
result = self._cache['edges_unique_inverse'].reshape((-1, 3))
return result | For each face return which indexes in mesh.unique_edges constructs
that face.
Returns
---------
faces_unique_edges : (len(self.faces), 3) int
Indexes of self.edges_unique that
construct self.faces
Examples
---------
In [0]: mesh.faces[0:2]
... |
def _init_go_sources(self, go_sources_arg, go2obj_arg):
gos_user = set(go_sources_arg)
if 'children' in self.kws and self.kws['children']:
gos_user |= get_leaf_children(gos_user, go2obj_arg)
gos_godag = set(go2obj_arg)
gos_source = gos_user.intersection(gos_godag)
gos... | Return GO sources which are present in GODag. |
def connect_db(config):
rv = sqlite3.connect(config["database"]["uri"])
rv.row_factory = sqlite3.Row
return rv | Connects to the specific database. |
def _get_ctypes(self):
ctypes = []
for related_object in self.model._meta.get_all_related_objects():
model = getattr(related_object, 'related_model', related_object.model)
ctypes.append(ContentType.objects.get_for_model(model).pk)
if model.__subclasses__():
... | Returns all related objects for this model. |
def argsize(self):
argsize = sum(arg.nbytes for arg in self.argdefns)
return argsize if len(self.argdefns) > 0 else 0 | The total size in bytes of all the command arguments. |
def validate(self, value):
errors = []
self._used_validator = []
for val in self._validators:
try:
val.validate(value)
self._used_validator.append(val)
except ValidatorException as e:
errors.append(e)
except Exce... | validate function form OrValidator
Returns:
True if at least one of the validators
validate function return True |
def render(self, data, accepted_media_type=None, renderer_context=None):
assert yaml, 'YAMLRenderer requires pyyaml to be installed'
if data is None:
return ''
return yaml.dump(
data,
stream=None,
encoding=self.charset,
Dumper=self.enco... | Renders `data` into serialized YAML. |
def set_exception(self, exception):
self._exception = exception
self._result_set = True
self._invoke_callbacks(self) | Set the Future's exception. |
def tune_scale(acceptance, scale):
if acceptance > 0.8:
scale *= 2.0
elif acceptance <= 0.8 and acceptance > 0.4:
scale *= 1.3
elif acceptance < 0.234 and acceptance > 0.1:
scale *= (1/1.3)
elif acceptance <= 0.1 and acceptance > 0.05:
... | Tunes scale for M-H algorithm
Parameters
----------
acceptance : float
The most recent acceptance rate
scale : float
The current scale parameter
Returns
----------
scale : float
An adjusted scale parameter
Notes
... |
def mesh_surface_area(mesh=None, verts=None, faces=None):
r
if mesh:
verts = mesh.verts
faces = mesh.faces
else:
if (verts is None) or (faces is None):
raise Exception('Either mesh or verts and faces must be given')
surface_area = measure.mesh_surface_area(verts, face... | r"""
Calculates the surface area of a meshed region
Parameters
----------
mesh : tuple
The tuple returned from the ``mesh_region`` function
verts : array
An N-by-ND array containing the coordinates of each mesh vertex
faces : array
An N-by-ND array indicating which eleme... |
def split(mesh,
only_watertight=True,
adjacency=None,
engine=None):
if adjacency is None:
adjacency = mesh.face_adjacency
if only_watertight:
min_len = 3
else:
min_len = 1
components = connected_components(edges=adjacency,
... | Split a mesh into multiple meshes from face connectivity.
If only_watertight is true, it will only return watertight meshes
and will attempt single triangle/quad repairs.
Parameters
----------
mesh: Trimesh
only_watertight: if True, only return watertight components
adjacency: (n,2) list o... |
def expand(self, line, do_expand, force=False, vislevels=0, level=-1):
lastchild = self.GetLastChild(line, level)
line += 1
while line <= lastchild:
if force:
if vislevels > 0:
self.ShowLines(line, line)
else:
se... | Multi-purpose expand method from original STC class |
def uncomment_lines(lines):
ret = []
for line in lines:
ws_prefix, rest, ignore = RE_LINE_SPLITTER_UNCOMMENT.match(line).groups()
ret.append(ws_prefix + rest)
return ''.join(ret) | Uncomment the given list of lines and return them. The first hash mark
following any amount of whitespace will be removed on each line. |
def remove_file(self):
if not self.fullpath or not self.archived:
raise RuntimeError()
try:
os.remove(self.fullpath)
except:
print("Error removing %s: %s" % (self.fullpath, sys.exc_info()[1])) | Removes archived file associated with this DP |
def _reset_bbox(self):
scale_x, scale_y = self.get_scale_xy()
pan_x, pan_y = self.get_pan(coord='data')[:2]
win_wd, win_ht = self.get_window_size()
win_wd, win_ht = max(1, win_wd), max(1, win_ht)
self._calc_bg_dimensions(scale_x, scale_y,
pan_x, p... | This function should only be called internally. It resets
the viewers bounding box based on changes to pan or scale. |
def _imm_default_init(self, *args, **kwargs):
for (k,v) in six.iteritems({k:v for dct in (args + (kwargs,)) for (k,v) in dct}):
setattr(self, k, v) | An immutable's defalt initialization function is to accept any number of dictionaries followed
by any number of keyword args and to turn them all into the parameters of the immutable that is
being created. |
def _thumbnail_div(target_dir, src_dir, fname, snippet, is_backref=False,
check=True):
thumb, _ = _find_image_ext(
os.path.join(target_dir, 'images', 'thumb',
'sphx_glr_%s_thumb.png' % fname[:-3]))
if check and not os.path.isfile(thumb):
raise RuntimeError... | Generates RST to place a thumbnail in a gallery |
def ping_interval(self, value):
if not isinstance(value, int):
raise TypeError("ping interval must be int")
if value < 0:
raise ValueError("ping interval must be greater then 0")
self._ping_interval = value | Setter for ping_interval property.
:param int value: interval in sec between two ping values. |
def get_webhook(self):
api = self._get_api(mds.NotificationsApi)
return Webhook(api.get_webhook()) | Get the current callback URL if it exists.
:return: The currently set webhook |
def parse_excel(file_path: str,
entrez_id_header,
log_fold_change_header,
adjusted_p_value_header,
entrez_delimiter,
base_mean_header=None) -> List[Gene]:
logger.info("In parse_excel()")
df = pd.read_excel(file_path)
return hand... | Read an excel file on differential expression values as Gene objects.
:param str file_path: The path to the differential expression file to be parsed.
:param config.Params params: An object that includes paths, cutoffs and other information.
:return list: A list of Gene objects. |
def role_get(auth=None, **kwargs):
cloud = get_operator_cloud(auth)
kwargs = _clean_kwargs(**kwargs)
return cloud.get_role(**kwargs) | Get a single role
CLI Example:
.. code-block:: bash
salt '*' keystoneng.role_get name=role1
salt '*' keystoneng.role_get name=role1 domain_id=b62e76fbeeff4e8fb77073f591cf211e
salt '*' keystoneng.role_get name=1eb6edd5525e4ac39af571adee673559 |
def selectNumber(self):
le = self.lineEdit()
text = asUnicode(le.text())
if self.opts['suffix'] == '':
le.setSelection(0, len(text))
else:
try:
index = text.index(' ')
except ValueError:
return
le.setSelectio... | Select the numerical portion of the text to allow quick editing by the user. |
def __threshold(self, ymx_i):
return ymx_i - (self.S * np.diff(self.xsn).mean()) | Calculates the difference threshold for a
given difference local maximum.
Parameters
-----------
ymx_i : float
The normalized y value of a local maximum. |
def cont_r(self, percent=0.9, N=None):
if not hasattr(self, 'F'):
self.fs_r(N=self.rank)
return apply_along_axis(lambda _: _/self.L[:N], 1,
apply_along_axis(lambda _: _*self.r, 0, self.F[:, :N]**2)) | Return the contribution of each row. |
def get_cod_ids(self, formula):
sql = 'select file from data where formula="- %s -"' % \
Composition(formula).hill_formula
text = self.query(sql).split("\n")
cod_ids = []
for l in text:
m = re.search(r"(\d+)", l)
if m:
cod_ids.append(in... | Queries the COD for all cod ids associated with a formula. Requires
mysql executable to be in the path.
Args:
formula (str): Formula.
Returns:
List of cod ids. |
def dumps():
d = {}
for k, v in FILTERS.items():
d[dr.get_name(k)] = list(v)
return _dumps(d) | Returns a string representation of the FILTERS dictionary. |
def from_lt(rsize, ltm, ltv):
dbinx = rsize / ltm[0]
dbiny = rsize / ltm[1]
dxcorner = (dbinx - rsize) - dbinx * ltv[0]
dycorner = (dbiny - rsize) - dbiny * ltv[1]
bin = (_nint(dbinx), _nint(dbiny))
corner = (_nint(dxcorner), _nint(dycorner))
return bin, corner | Compute the corner location and pixel size in units
of unbinned pixels.
.. note:: Translated from ``calacs/lib/fromlt.c``.
Parameters
----------
rsize : int
Reference pixel size. Usually 1.
ltm, ltv : tuple of float
See :func:`get_lt`.
Returns
-------
bin : tuple ... |
def dec2dec(dec):
d = dec.replace(':', ' ').split()
if len(d) == 2:
d.append(0.0)
if d[0].startswith('-') or float(d[0]) < 0:
return float(d[0]) - float(d[1]) / 60.0 - float(d[2]) / 3600.0
return float(d[0]) + float(d[1]) / 60.0 + float(d[2]) / 3600.0 | Convert sexegessimal RA string into a float in degrees.
Parameters
----------
dec : string
A string separated representing the Dec.
Expected format is `[+- ]hh:mm[:ss.s]`
Colons can be replaced with any whit space character.
Returns
-------
dec : float
The Dec i... |
def get_current(self):
now = dt.now().timestamp()
url = build_url(self.api_key, self.spot_id, self.fields,
self.unit, now, now)
return get_msw(url) | Get current forecast. |
def get_uniprot_evidence_level(header):
header = header.split()
for item in header:
item = item.split('=')
try:
if item[0] == 'PE':
return 5 - int(item[1])
except IndexError:
continue
return -1 | Returns uniprot protein existence evidence level for a fasta header.
Evidence levels are 1-5, but we return 5 - x since sorting still demands
that higher is better. |
def get_entity_type(self,
name,
language_code=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None):
if 'get_entity_type' not in ... | Retrieves the specified entity type.
Example:
>>> import dialogflow_v2
>>>
>>> client = dialogflow_v2.EntityTypesClient()
>>>
>>> name = client.entity_type_path('[PROJECT]', '[ENTITY_TYPE]')
>>>
>>> response = client.get_entity... |
def get_arg_names(target) -> typing.List[str]:
code = getattr(target, '__code__')
if code is None:
return []
arg_count = code.co_argcount
kwarg_count = code.co_kwonlyargcount
args_index = get_args_index(target)
kwargs_index = get_kwargs_index(target)
arg_names = list(code.co_varnames... | Gets the list of named arguments for the target function
:param target:
Function for which the argument names will be retrieved |
def load(uid=None):
app.logger.info("GET /sync route with id: %s" % uid)
try:
user = Participant.query.\
filter(Participant.uniqueid == uid).\
one()
except exc.SQLAlchemyError:
app.logger.error("DB error: Unique user not found.")
try:
resp = json.loads(use... | Load experiment data, which should be a JSON object and will be stored
after converting to string. |
def value_to_datum(self, instance, value):
if value is None:
return None
bound = getattr(instance._origin, self.cls)
if type(value) is bound:
if self.use_data_setter:
return value._data
else:
descriptors, alt_descriptors = get_p... | Convert a given Python-side value to a MAAS-side datum.
:param instance: The `Object` instance on which this field is
currently operating. This method should treat it as read-only, for
example to perform validation with regards to other fields.
:param datum: The Python-side valu... |
def create_open_msg(self):
asnum = self.local_as
if not is_valid_old_asn(asnum):
asnum = bgp.AS_TRANS
bgpid = self._common_conf.router_id
holdtime = self._neigh_conf.hold_time
def flatten(L):
if isinstance(L, list):
for i in range(len(L)):
... | Create `Open` message using current settings.
Current setting include capabilities, timers and ids. |
def create(cls, name, members=None, comment=None):
element = [] if members is None else element_resolver(members)
json = {'name': name,
'element': element,
'comment': comment}
return ElementCreator(cls, json) | Create the TCP Service group
:param str name: name of tcp service group
:param list element: tcp services by element or href
:type element: list(str,Element)
:raises CreateElementFailed: element creation failed with reason
:return: instance with meta
:rtype: TCPServiceGr... |
def satisfiesExternal(cntxt: Context, n: Node, se: ShExJ.ShapeExternal, c: DebugContext) -> bool:
if c.debug:
print(f"id: {se.id}")
extern_shape = cntxt.external_shape_for(se.id)
if extern_shape:
return satisfies(cntxt, n, extern_shape)
cntxt.fail_reason = f"{se.id}: Shape is not in Sche... | Se is a ShapeExternal and implementation-specific mechansims not defined in this specification indicate
success. |
def _get_key_redis_key(bank, key):
opts = _get_redis_keys_opts()
return '{prefix}{separator}{bank}/{key}'.format(
prefix=opts['key_prefix'],
separator=opts['separator'],
bank=bank,
key=key
) | Return the Redis key given the bank name and the key name. |
def update(self, title=None, description=None, images=None, cover=None,
layout=None, privacy=None):
url = (self._imgur._base_url + "/3/album/"
"{0}".format(self._delete_or_id_hash))
is_updated = self._imgur._send_request(url, params=locals(),
... | Update the album's information.
Arguments with the value None will retain their old values.
:param title: The title of the album.
:param description: A description of the album.
:param images: A list of the images we want the album to contain.
Can be Image objects, ids or a... |
def show_plot_methods(self):
print_func = PlotterInterface._print_func
if print_func is None:
print_func = six.print_
s = "\n".join(
"%s\n %s" % t for t in six.iteritems(self._plot_methods))
return print_func(s) | Print the plotmethods of this instance |
def close(self):
_LOGGER.debug("Joining submission queue")
self._submission_queue.join()
_LOGGER.debug("Joining cancel queue")
self._cancel_queue.join()
_LOGGER.debug("Joining poll queue")
self._poll_queue.join()
_LOGGER.debug("Joining load queue")
self._l... | Perform a clean shutdown.
Waits for all the currently scheduled work to finish, kills the workers,
and closes the connection pool.
.. note:: Ensure your code does not submit new work while the connection is closing.
Where possible, it is recommended you use a context manager (a :code:... |
def is_causal_sink(graph: BELGraph, node: BaseEntity) -> bool:
return has_causal_in_edges(graph, node) and not has_causal_out_edges(graph, node) | Return true if the node is a causal sink.
- Does have causal in edge(s)
- Doesn't have any causal out edge(s) |
def verify_signature(public_key, signature, hash, hash_algo):
hash_algo = _hash_algorithms[hash_algo]
try:
return get_publickey(public_key).verify(
signature,
hash,
padding.PKCS1v15(),
utils.Prehashed(hash_algo),
) is None
except InvalidSignatu... | Verify the given signature is correct for the given hash and public key.
Args:
public_key (str): PEM encoded public key
signature (bytes): signature to verify
hash (bytes): hash of data
hash_algo (str): hash algorithm used
Returns:
True if the signature is valid, False ... |
def method2jpg(output, mx, raw=False):
buff = raw
if not raw:
buff = method2dot(mx)
method2format(output, "jpg", mx, buff) | Export method to a jpg file format
:param output: output filename
:type output: string
:param mx: specify the MethodAnalysis object
:type mx: :class:`MethodAnalysis` object
:param raw: use directly a dot raw buffer (optional)
:type raw: string |
def compute_search_volume_in_bins(found, total, ndbins, sim_to_bins_function):
eff, err = compute_search_efficiency_in_bins(
found, total, ndbins, sim_to_bins_function)
dx = ndbins[0].upper() - ndbins[0].lower()
r = ndbins[0].centres()
vol = bin_utils.BinnedArray(bin_... | Calculate search sensitive volume by integrating efficiency in distance bins
No cosmological corrections are applied: flat space is assumed.
The first dimension of ndbins must be bins over injected distance.
sim_to_bins_function must maps an object to a tuple indexing the ndbins. |
def reset_index(self, level=None, drop=False, name=None, inplace=False):
inplace = validate_bool_kwarg(inplace, 'inplace')
if drop:
new_index = ibase.default_index(len(self))
if level is not None:
if not isinstance(level, (tuple, list)):
level ... | Generate a new DataFrame or Series with the index reset.
This is useful when the index needs to be treated as a column, or
when the index is meaningless and needs to be reset to the default
before another operation.
Parameters
----------
level : int, str, tuple, or list... |
def _setup_metric_group_definitions(self):
metric_group_definitions = dict()
for mg_info in self.properties['metric-group-infos']:
mg_name = mg_info['group-name']
mg_def = MetricGroupDefinition(
name=mg_name,
resource_class=_resource_class_from_gro... | Return the dict of MetricGroupDefinition objects for this metrics
context, by processing its 'metric-group-infos' property. |
def _ValidateValue(value, type_check):
if inspect.isclass(type_check):
return isinstance(value, type_check)
if isinstance(type_check, tuple):
return _ValidateTuple(value, type_check)
elif callable(type_check):
return type_check(value)
else:
raise TypeError("Invalid type check '%s'" % repr(type_c... | Validate a single value with type_check. |
def getAspect(obj1, obj2, aspList):
ap = _getActivePassive(obj1, obj2)
aspDict = _aspectDict(ap['active'], ap['passive'], aspList)
if not aspDict:
aspDict = {
'type': const.NO_ASPECT,
'orb': 0,
'separation': 0,
}
aspProp = _aspectProperties(ap['active... | Returns an Aspect object for the aspect between two
objects considering a list of possible aspect types. |
def get_formset(self, request, obj=None, **kwargs):
FormSet = super(TranslatableInlineModelAdmin, self).get_formset(request, obj, **kwargs)
FormSet.language_code = self.get_form_language(request, obj)
if self.inline_tabs:
available_languages = self.get_available_languages(obj, FormSe... | Return the formset, and provide the language information to the formset. |
def cmd(self, cmd, verbose=False):
command = cmd.format(maildir=self.directory)
if verbose:
print(command)
p = Popen([
"ssh",
"-T",
self.host,
command
], stdin=PIPE, stdout=PIPE, stderr=PIPE)
stdo... | Executes the specified command on the remote host.
The cmd must be format safe, this means { and } must be doubled, thusly:
echo /var/local/maildir/{{cur,new}}
the cmd can include the format word 'maildir' to be replaced
by self.directory. eg:
echo {maildir}/{{cur,new}} |
def put_pipeline_definition(pipeline_id, pipeline_objects, parameter_objects=None,
parameter_values=None, region=None, key=None, keyid=None, profile=None):
parameter_objects = parameter_objects or []
parameter_values = parameter_values or []
client = _get_client(region, key, keyi... | Add tasks, schedules, and preconditions to the specified pipeline. This function is
idempotent and will replace an existing definition.
CLI example:
.. code-block:: bash
salt myminion boto_datapipeline.put_pipeline_definition my_pipeline_id my_pipeline_objects |
def add_query_params(url, params):
def encode(s):
return force_bytes(s, settings.DEFAULT_CHARSET)
params = dict([(encode(k), encode(v)) for k, v in params.items() if v])
parts = list(urlparse(url))
query = dict(parse_qsl(parts[4]))
query.update(params)
parts[4] = urlencode(query)
ret... | Inject additional query parameters into an existing URL. If
parameters already exist with the same name, they will be
overwritten. Parameters with empty values are ignored. Return
the modified URL as a string. |
def request(uri, method, data, token=''):
socket.setdefaulttimeout(__timeout__)
obj = urllib.build_opener(urllib.HTTPHandler)
encoded = json.JSONEncoder(object).encode(data)
data_utf8 = encoded.encode('utf-8')
req = urllib.Request(uri, data=data_utf8)
if encoded:
req.add_header('Content-... | Request to TonicDNS API.
Arguments:
uri: TonicDNS API URI
method: TonicDNS API request method
data: Post data to TonicDNS API
token: TonicDNS API authentication token |
def stem_leaf_plot(data, vmin, vmax, bins, digit=1, title=None):
assert bins > 0
range = vmax - vmin
step = range * 1. / bins
if isinstance(range, int):
step = int(ceil(step))
step = step or 1
bins = np.arange(vmin, vmax + step, step)
hist, bin_edges = np.histogram(data, bins=bins)
... | Generate stem and leaf plot given a collection of numbers |
def requiredGPU_MB(self, n):
from darknet.core import darknet_with_cuda
if (darknet_with_cuda()):
free = getFreeGPU_MB()
print("Yolo: requiredGPU_MB: required, free", n, free)
if (free == -1):
return True
return (free>=n)
else:
... | Required GPU memory in MBytes |
def snippets(self):
return [strip_suffix(f, '.yaml') for f in self._stripped_files if self._snippets_pattern.match(f)] | Get all snippets in this DAP |
def covariance(self):
mu = self.moments_central
if mu[0, 0] != 0:
m = mu / mu[0, 0]
covariance = self._check_covariance(
np.array([[m[0, 2], m[1, 1]], [m[1, 1], m[2, 0]]]))
return covariance * u.pix**2
else:
return np.empty((2, 2)) ... | The covariance matrix of the 2D Gaussian function that has the
same second-order moments as the source. |
def _init_sub_dsp(self, dsp, fringe, outputs, no_call, initial_dist, index,
full_name):
sol = self.__class__(
dsp, {}, outputs, False, None, None, no_call, False,
wait_in=self._wait_in.get(dsp, None), index=self.index + index,
full_name=full_name
... | Initialize the dispatcher as sub-dispatcher and update the fringe.
:param fringe:
Heapq of closest available nodes.
:type fringe: list[(float | int, bool, (str, Dispatcher)]
:param outputs:
Ending data nodes.
:type outputs: list[str], iterable
:param no... |
def node_from_nid(self, nid):
for node in self.iflat_nodes():
if node.node_id == nid: return node
raise ValueError("Cannot find node with node id: %s" % nid) | Return the node in the `Flow` with the given `nid` identifier |
def showLicense():
print("Trying to recover the contents of the license...\n")
try:
text = urllib.urlopen(LICENSE_URL).read()
print("License retrieved from " + emphasis(LICENSE_URL) + ".")
raw_input("\n\tPress " + emphasis("<ENTER>") + " to print it.\n")
print(text)
except:
... | Method that prints the license if requested.
It tries to find the license online and manually download it. This method
only prints its contents in plain text. |
def _get_user_agent(self):
user_agent = request.headers.get('User-Agent')
if user_agent:
user_agent = user_agent.encode('utf-8')
return user_agent or '' | Retrieve the request's User-Agent, if available.
Taken from Flask Login utils.py. |
def add_errors(self, *errors: Union[BaseSchemaError, SchemaErrorCollection]) -> None:
for error in errors:
self._error_cache.add(error) | Adds errors to the error store for the schema |
def get_forum(self):
pk = self.kwargs.get(self.forum_pk_url_kwarg, None)
if not pk:
return
if not hasattr(self, '_forum'):
self._forum = get_object_or_404(Forum, pk=pk)
return self._forum | Returns the considered forum. |
def _compute_inter_event_std(self, C, C_PGA, pga1100, mag, vs30):
tau_0 = self._compute_std_0(C['s3'], C['s4'], mag)
tau_b_pga = self._compute_std_0(C_PGA['s3'], C_PGA['s4'], mag)
delta_amp = self._compute_partial_derivative_site_amp(C, pga1100, vs30)
std_inter = np.sqrt(tau_0 ** 2 + (de... | Compute inter event standard deviation, equation 25, page 82. |
def init_backends():
global _BACKENDS, _ACTIVE_BACKENDS
try:
from .cffi_backend import CFFIBackend
except ImportError:
pass
else:
_BACKENDS.append(CFFIBackend)
from .ctypes_backend import CTypesBackend
from .null_backend import NullBackend
_BACKENDS.append(CTypesBacke... | Loads all backends |
def babel_extract(config, input, output, target, keywords):
click.echo(
click.style(
"Starting Extractions config:{0} input:{1} output:{2} keywords:{3}".format(
config, input, output, keywords
),
fg="green",
)
)
keywords = " -k ".join(keywo... | Babel, Extracts and updates all messages marked for translation |
def _restore_counts_maps(self):
for c in self.components:
c.restore_counts_maps()
if hasattr(self.like.components[0].logLike, 'setCountsMap'):
self._init_roi_model()
else:
self.write_xml('tmp')
self._like = SummedLikelihood()
for i, c i... | Revert counts maps to their state prior to injecting any simulated
components. |
def getConfig(self):
config = {}
config["name"] = self.city
config["intervals"] = self.__intervals
config["last_date"] = self.__lastDay
config["excludedUsers"] = []
config["excludedLocations"] = []
for e in self.__excludedUsers:
config["excludedUsers"]... | Return the configuration of the city.
:return: configuration of the city.
:rtype: dict. |
def compute_texptime(imageObjectList):
expnames = []
exptimes = []
start = []
end = []
for img in imageObjectList:
expnames += img.getKeywordList('_expname')
exptimes += img.getKeywordList('_exptime')
start += img.getKeywordList('_expstart')
end += img.getKeywordList(... | Add up the exposure time for all the members in
the pattern, since 'drizzle' doesn't have the necessary
information to correctly set this itself. |
def _readintle(self, length, start):
ui = self._readuintle(length, start)
if not ui >> (length - 1):
return ui
tmp = (~(ui - 1)) & ((1 << length) - 1)
return -tmp | Read bits and interpret as a little-endian signed int. |
def load_robots_txt(self, url_info: URLInfo, text: str):
key = self.url_info_key(url_info)
parser = robotexclusionrulesparser.RobotExclusionRulesParser()
parser.parse(text)
self._parsers[key] = parser | Load the robot.txt file. |
def _list(self, foldername="INBOX", reverse=False, since=None):
folder = self.folder \
if foldername == "INBOX" \
else self._getfolder(foldername)
def sortcmp(d):
try:
return d[1].date
except:
return -1
lst = folder.... | Do structured list output.
Sorts the list by date, possibly reversed, filtered from 'since'.
The returned list is: foldername, message key, message object |
def edge_val_set(self, graph, orig, dest, idx, key, branch, turn, tick, value):
if (branch, turn, tick) in self._btts:
raise TimeError
self._btts.add((branch, turn, tick))
graph, orig, dest, key, value = map(self.pack, (graph, orig, dest, key, value))
self._edgevals2set.appen... | Set this key of this edge to this value. |
def _render(template, callable_, args, data, as_unicode=False):
if as_unicode:
buf = util.FastEncodingBuffer(as_unicode=True)
elif template.bytestring_passthrough:
buf = compat.StringIO()
else:
buf = util.FastEncodingBuffer(
as_unicode=as_unicode,
... | create a Context and return the string
output of the given template and template callable. |
def children(self, vertex):
return [self.head(edge) for edge in self.out_edges(vertex)] | Return the list of immediate children of the given vertex. |
def help_cli_search(self):
help = '%sSearch: %s returns sample_sets, a sample_set is a set/list of md5s.' % (color.Yellow, color.Green)
help += '\n\n\t%sSearch for all samples in the database that are known bad pe files,' % (color.Green)
help += '\n\t%sthis command returns the sample_set conta... | Help for Workbench CLI Search |
def serialize_for_transport(obj_pyxb, pretty=False, strip_prolog=False, xslt_url=None):
return serialize_gen(obj_pyxb, 'utf-8', pretty, strip_prolog, xslt_url) | Serialize PyXB object to XML ``bytes`` with UTF-8 encoding for transport over the
network, filesystem storage and other machine usage.
Args:
obj_pyxb: PyXB object
PyXB object to serialize.
pretty: bool
True: Use pretty print formatting for human readability.
strip_prolog:
... |
def rounder(input_number, digit=5):
if isinstance(input_number, tuple):
tuple_list = list(input_number)
tuple_str = []
for i in tuple_list:
if isfloat(i):
tuple_str.append(str(numpy.around(i, digit)))
else:
tuple_str.append(str(i))
... | Round input number and convert to str.
:param input_number: input number
:type input_number : anything
:param digit: scale (the number of digits to the right of the decimal point in a number.)
:type digit : int
:return: round number as str |
def all_sharded_cluster_links(cluster_id, shard_id=None,
router_id=None, rel_to=None):
return [
sharded_cluster_link(rel, cluster_id, shard_id, router_id,
self_rel=(rel == rel_to))
for rel in (
'get-sharded-clusters', 'get-sharde... | Get a list of all links to be included with ShardedClusters. |
def AllTypes():
return [AssetType.CreditFlag, AssetType.DutyFlag, AssetType.GoverningToken,
AssetType.UtilityToken, AssetType.Currency, AssetType.Share,
AssetType.Invoice, AssetType.Token] | Get a list of all available asset types.
Returns:
list: of AssetType items. |
def choose_form(self, number=None, xpath=None, name=None, **kwargs):
id_ = kwargs.pop('id', None)
if id_ is not None:
try:
self._lxml_form = self.select('//form[@id="%s"]' % id_).node()
except IndexError:
raise DataNotFound("There is no form with i... | Set the default form.
:param number: number of form (starting from zero)
:param id: value of "id" attribute
:param name: value of "name" attribute
:param xpath: XPath query
:raises: :class:`DataNotFound` if form not found
:raises: :class:`GrabMisuseError`
if ... |
def _init_deferred_buffers(self):
self._transfer_list = collections.deque()
self._crnt_cmd = _Command(self._packet_size)
self._commands_to_read = collections.deque()
self._command_response_buf = bytearray() | Initialize or reinitalize all the deferred transfer buffers
Calling this method will drop all pending transactions
so use with care. |
def validate(self, value):
if isinstance(value, (str, unicode)) and not re.match(self.__pattern, value):
raise orb.errors.ColumnValidationError(self, 'The email provided is not valid.')
else:
return super(EmailColumn, self).validate(value) | Validates the value provided is a valid email address,
at least, on paper.
:param value: <str>
:return: <bool> |
def publish(self, topic, message=None, qos=0, retain=False):
logger.info('Publish topic: %s, message: %s, qos: %s, retain: %s'
% (topic, message, qos, retain))
self._mid = -1
self._mqttc.on_publish = self._on_publish
result, mid = self._mqttc.publish(topic, message, int(qos),... | Publish a message to a topic with specified qos and retained flag.
It is required that a connection has been established using `Connect`
keyword before using this keyword.
`topic` topic to which the message will be published
`message` message payload to publish
`qos` qos of th... |
def iterate(self, train=None, valid=None, max_updates=None, **kwargs):
r
self._compile(**kwargs)
if valid is None:
valid = train
iteration = 0
training = validation = None
while max_updates is None or iteration < max_updates:
if not iteration % sel... | r'''Optimize a loss iteratively using a training and validation dataset.
This method yields a series of monitor values to the caller. After every
optimization epoch, a pair of monitor dictionaries is generated: one
evaluated on the training dataset during the epoch, and another
evaluate... |
def _fill_untouched(idx, ret, fill_value):
untouched = np.ones_like(ret, dtype=bool)
untouched[idx] = False
ret[untouched] = fill_value | any elements of ret not indexed by idx are set to fill_value. |
def GetAnalyzersInformation(cls):
analyzer_information = []
for _, analyzer_class in cls.GetAnalyzers():
description = getattr(analyzer_class, 'DESCRIPTION', '')
analyzer_information.append((analyzer_class.NAME, description))
return analyzer_information | Retrieves the analyzers information.
Returns:
list[tuple]: containing:
str: analyzer name.
str: analyzer description. |
def _handle_tag_definetext2(self):
obj = _make_object("DefineText2")
self._generic_definetext_parser(obj, self._get_struct_rgba)
return obj | Handle the DefineText2 tag. |
def _update_length(self):
action_length = 4 + len(self.field.pack())
overflow = action_length % 8
self.length = action_length
if overflow:
self.length = action_length + 8 - overflow | Update the length field of the struct. |
def parse_properties(node):
d = dict()
for child in node.findall('properties'):
for subnode in child.findall('property'):
cls = None
try:
if "type" in subnode.keys():
module = importlib.import_module('builtins')
cls = getatt... | Parse a Tiled xml node and return a dict that represents a tiled "property"
:param node: etree element
:return: dict |
def imports():
from .core.import_hooks import ExtensionImporter
importer = ExtensionImporter()
sys.meta_path.append(importer)
yield
sys.meta_path.remove(importer) | Install the import hook to load python extensions from app's lib folder
during the context of this block.
This method is preferred as it's faster than using install. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.