code stringlengths 51 2.38k | docstring stringlengths 4 15.2k |
|---|---|
def load_config(self, config_path=None):
self.loaded = True
config = copy.deepcopy(DEFAULTS)
if config_path is None:
if "FEDORA_MESSAGING_CONF" in os.environ:
config_path = os.environ["FEDORA_MESSAGING_CONF"]
else:
config_path = "/etc/fedor... | Load application configuration from a file and merge it with the default
configuration.
If the ``FEDORA_MESSAGING_CONF`` environment variable is set to a
filesystem path, the configuration will be loaded from that location.
Otherwise, the path defaults to ``/etc/fedora-messaging/config.... |
def get_density(self, compound='', element=''):
_stack = self.stack
if compound == '':
_list_compounds = _stack.keys()
list_all_dict = {}
for _compound in _list_compounds:
_list_element = _stack[_compound]['elements']
list_all_dict[_com... | returns the list of isotopes for the element of the compound defined with their density
Parameters:
===========
compound: string (default is empty). If empty, all the stoichiometric will be displayed
element: string (default is same as compound).
Raises:
=======
... |
def connect(self, host, port):
self._connected = False
self._host = "%s:%d" % (host, port)
self._closed = False
self._close_info = {
'reply_code': 0,
'reply_text': 'failed to connect to %s' % (self._host),
'class_id': 0,
'method_id': 0
... | Connect to a host and port. |
def getReaderNames(self):
hresult, pcscreaders = SCardListReaders(self.hcontext, [])
if 0 != hresult and SCARD_E_NO_READERS_AVAILABLE != hresult:
raise ListReadersException(hresult)
readers = []
if None == self.readersAsked:
readers = pcscreaders
else:
... | Returns the list or PCSC readers on which to wait for cards. |
def _prep_smooth(t, y, dy, span, t_out, span_out, period):
if period:
t = t % period
if t_out is not None:
t_out = t_out % period
t, y, dy = validate_inputs(t, y, dy, sort_by=t)
if span_out is not None:
if t_out is None:
raise ValueError("Must specify t_out wh... | Private function to prepare & check variables for smooth utilities |
def cleanup():
if _output_dir and os.path.exists(_output_dir):
log.msg_warn("Cleaning up output directory at '{output_dir}' ..."
.format(output_dir=_output_dir))
if not _dry_run:
shutil.rmtree(_output_dir) | Cleanup the output directory |
def _get_level_values(self, level, unique=False):
values = self.levels[level]
level_codes = self.codes[level]
if unique:
level_codes = algos.unique(level_codes)
filled = algos.take_1d(values._values, level_codes,
fill_value=values._na_value)
... | Return vector of label values for requested level,
equal to the length of the index
**this is an internal method**
Parameters
----------
level : int level
unique : bool, default False
if True, drop duplicated values
Returns
-------
v... |
def encode_events(self, duration, events, values, dtype=np.bool):
frames = time_to_frames(events, sr=self.sr,
hop_length=self.hop_length)
n_total = int(time_to_frames(duration, sr=self.sr,
hop_length=self.hop_length))
n_alloc =... | Encode labeled events as a time-series matrix.
Parameters
----------
duration : number
The duration of the track
events : ndarray, shape=(n,)
Time index of the events
values : ndarray, shape=(n, m)
Values array. Must have the same first ind... |
def downgrade(engine, desired_version):
with engine.begin() as conn:
metadata = sa.MetaData(conn)
metadata.reflect()
version_info_table = metadata.tables['version_info']
starting_version = sa.select((version_info_table.c.version,)).scalar()
if starting_version < desired_versi... | Downgrades the assets db at the given engine to the desired version.
Parameters
----------
engine : Engine
An SQLAlchemy engine to the assets database.
desired_version : int
The desired resulting version for the assets database. |
def run_linter(self, linter) -> None:
self.current = linter.name
if (linter.name not in self.parser["all"].as_list("linters")
or linter.base_pyversion > sys.version_info):
return
if any(x not in self.installed for x in linter.requires_install):
raise Modul... | Run a checker class |
def on_menu(self, event):
state = self.state
ret = self.menu.find_selected(event)
if ret is None:
return
ret.call_handler()
state.child_pipe_send.send(ret) | handle menu selections |
def accumulate(a_generator, cooperator=None):
if cooperator:
own_cooperate = cooperator.cooperate
else:
own_cooperate = cooperate
spigot = ValueBucket()
items = stream_tap((spigot,), a_generator)
d = own_cooperate(items).whenDone()
d.addCallback(accumulation_handler, spigot)
... | Start a Deferred whose callBack arg is a deque of the accumulation
of the values yielded from a_generator.
:param a_generator: An iterator which yields some not None values.
:return: A Deferred to which the next callback will be called with
the yielded contents of the generator function. |
def uniform_crossover(random, mom, dad, args):
ux_bias = args.setdefault('ux_bias', 0.5)
crossover_rate = args.setdefault('crossover_rate', 1.0)
children = []
if random.random() < crossover_rate:
bro = copy.copy(dad)
sis = copy.copy(mom)
for i, (m, d) in enumerate(zip(mom, dad)):... | Return the offspring of uniform crossover on the candidates.
This function performs uniform crossover (UX). For each element
of the parents, a biased coin is flipped to determine whether
the first offspring gets the 'mom' or the 'dad' element. An
optional keyword argument in args, ``ux_bias``, deter... |
def _initialize_applicationUiFile():
RuntimeGlobals.ui_file = umbra.ui.common.get_resource_path(UiConstants.ui_file)
if not foundations.common.path_exists(RuntimeGlobals.ui_file):
raise foundations.exceptions.FileExistsError("'{0}' ui file is not available, {1} will now close!".format(
UiCon... | Initializes the Application ui file. |
async def run_async(self):
try:
await self.run_loop_async()
except Exception as err:
_logger.error("Run loop failed %r", err)
try:
_logger.info("Shutting down all pumps %r", self.host.guid)
await self.remove_all_pumps_async("Shutdown")
exce... | Starts the run loop and manages exceptions and cleanup. |
def create(cls, job_id, spider, workflow, results=None,
logs=None, status=JobStatus.PENDING):
obj = cls(
job_id=job_id,
spider=spider,
workflow=workflow,
results=results,
logs=logs,
status=status,
)
db.session... | Create a new entry for a scheduled crawler job. |
def reparse(self, unsaved_files=None, options=0):
if unsaved_files is None:
unsaved_files = []
unsaved_files_array = 0
if len(unsaved_files):
unsaved_files_array = (_CXUnsavedFile * len(unsaved_files))()
for i,(name,value) in enumerate(unsaved_files):
... | Reparse an already parsed translation unit.
In-memory contents for files can be provided by passing a list of pairs
as unsaved_files, the first items should be the filenames to be mapped
and the second should be the contents to be substituted for the
file. The contents may be passed as ... |
def create_pairwise_bilateral(sdims, schan, img, chdim=-1):
if chdim == -1:
im_feat = img[np.newaxis].astype(np.float32)
else:
im_feat = np.rollaxis(img, chdim).astype(np.float32)
if isinstance(schan, Number):
im_feat /= schan
else:
for i, s in enumerate(schan):
... | Util function that create pairwise bilateral potentials. This works for
all image dimensions. For the 2D case does the same as
`DenseCRF2D.addPairwiseBilateral`.
Parameters
----------
sdims: list or tuple
The scaling factors per dimension. This is referred to `sxy` in
`DenseCRF2D.ad... |
def GetValidHostsForCert(cert):
if 'subjectAltName' in cert:
return [x[1] for x in cert['subjectAltName'] if x[0].lower() == 'dns']
else:
return [x[0][1] for x in cert['subject']
if x[0][0].lower() == 'commonname'] | Returns a list of valid host globs for an SSL certificate.
Args:
cert: A dictionary representing an SSL certificate.
Returns:
list: A list of valid host globs. |
def configure(self, options=None, attribute_options=None):
self._mapping.update(options=options,
attribute_options=attribute_options) | Configures the options and attribute options of the mapping associated
with this representer with the given dictionaries.
:param dict options: configuration options for the mapping associated
with this representer.
:param dict attribute_options: attribute options for the mapping
... |
def xor_app(parser, cmd, args):
parser.add_argument(
'-d', '--dec',
help='interpret the key as a decimal integer',
dest='type',
action='store_const',
const=int
)
parser.add_argument(
'-x', '--hex',
help='interpret the key as an hexadecimal integer',
... | Xor a value with a key. |
def make(class_name, base, schema):
return type(class_name, (base,), dict(SCHEMA=schema)) | Create a new schema aware type. |
def iterpws(self, n):
for _id in np.argsort(self._freq_list)[::-1][:n]:
pw = self._T.restore_key(_id)
if self._min_pass_len <= len(pw) <= self._max_pass_len:
yield _id, pw, self._freq_list[_id] | Returns passwords in order of their frequencies.
@n: The numebr of passwords to return
Return: pwid, password, frequency
Every password is assigned an uniq id, for efficient access. |
def InitializeUpload(self, http_request, http=None, client=None):
if self.strategy is None:
raise exceptions.UserError(
'No upload strategy set; did you call ConfigureRequest?')
if http is None and client is None:
raise exceptions.UserError('Must provide client or... | Initialize this upload from the given http_request. |
def parse(cls, backend, ik, spk, spk_signature, otpks):
ik = backend.decodePublicKey(ik)[0]
spk["key"] = backend.decodePublicKey(spk["key"])[0]
otpks = list(map(lambda otpk: {
"key" : backend.decodePublicKey(otpk["key"])[0],
"id" : otpk["id"]
}, otpks))
r... | Use this method when creating a bundle from data you retrieved directly from some
PEP node. This method applies an additional decoding step to the public keys in
the bundle. Pass the same structure as the constructor expects. |
def update_state(self, state):
if not isinstance(state, MachineState):
raise TypeError("state can only be an instance of type MachineState")
self._call("updateState",
in_p=[state]) | Updates the VM state.
This operation will also update the settings file with the correct
information about the saved state file and delete this file from disk
when appropriate.
in state of type :class:`MachineState` |
def full_rule(self):
return join(self.bp_prefix, self.rule, trailing_slash=self.rule.endswith('/')) | The full url rule for this route, including any blueprint prefix. |
def collect(self):
def traverse(d, metric_name=''):
for key, value in d.iteritems():
if isinstance(value, dict):
if metric_name == '':
metric_name_next = key
else:
metric_name_next = metric_name +... | Publish all mdstat metrics. |
def convert_to_str(d):
d2 = {}
for k, v in d.items():
k = str(k)
if type(v) in [list, tuple]:
d2[k] = [str(a) for a in v]
elif type(v) is dict:
d2[k] = convert_to_str(v)
else:
d2[k] = str(v)
return d2 | Recursively convert all values in a dictionary to strings
This is required because setup() does not like unicode in
the values it is supplied. |
def add_force_flaky_options(add_option):
add_option(
'--force-flaky',
action="store_true",
dest="force_flaky",
default=False,
help="If this option is specified, we will treat all tests as "
"flaky."
)
add_option(
... | Add options to the test runner that force all tests to be flaky.
:param add_option:
A function that can add an option to the test runner.
Its argspec should equal that of argparse.add_option.
:type add_option:
`callable` |
def get_calling_namespaces():
try: 1//0
except ZeroDivisionError:
frame = sys.exc_info()[2].tb_frame.f_back
while frame.f_globals.get("__name__") == __name__:
frame = frame.f_back
return frame.f_locals, frame.f_globals | Return the locals and globals for the function that called
into this module in the current call stack. |
def all(self, archived=False, limit=None, page=None):
path = partial(_path, self.adapter)
if not archived:
path = _path(self.adapter)
else:
path = _path(self.adapter, 'archived')
return self._get(path, limit=limit, page=page) | get all adapter data. |
def render_crispy_form(form, helper=None, context=None):
from crispy_forms.templatetags.crispy_forms_tags import CrispyFormNode
if helper is not None:
node = CrispyFormNode('form', 'helper')
else:
node = CrispyFormNode('form', None)
node_context = Context(context)
node_context.update... | Renders a form and returns its HTML output.
This function wraps the template logic in a function easy to use in a Django view. |
def streamify(self, state, frame):
pieces = frame.split(self.prefix)
return '%s%s%s%s%s' % (self.prefix, self.begin,
(self.prefix + self.nop).join(pieces),
self.prefix, self.end) | Prepare frame for output as a byte-stuffed stream. |
def _stop(self):
self._pause()
self._cmds_q.put(("stop",))
try:
self._recorder.terminate()
except Exception:
pass
self._recording = False | Stops recording. Returns all recorded data and their timestamps. Destroys recorder process. |
def get_connection(self, command, args=()):
command = command.upper().strip()
is_pubsub = command in _PUBSUB_COMMANDS
if is_pubsub and self._pubsub_conn:
if not self._pubsub_conn.closed:
return self._pubsub_conn, self._pubsub_conn.address
self._pubsub_conn... | Get free connection from pool.
Returns connection. |
def setup_benchbuild():
LOG.debug("Setting up Benchbuild...")
venv_dir = local.path("/benchbuild")
prefixes = CFG["container"]["prefixes"].value
prefixes.append(venv_dir)
CFG["container"]["prefixes"] = prefixes
src_dir = str(CFG["source_dir"])
have_src = src_dir is not None
if have_src:
... | Setup benchbuild inside a container.
This will query a for an existing installation of benchbuild and
try to upgrade it to the latest version, if possible. |
def api_headers_tween_factory(handler, registry):
def api_headers_tween(request):
response = handler(request)
set_version(request, response)
set_req_guid(request, response)
return response
return api_headers_tween | This tween provides necessary API headers |
def unrecord(plugin_or_specs, filename):
plugin, filename = normalize_migration(plugin_or_specs, filename)
migration = get_migration(plugin, filename)
if migration:
log.info('Removing migration %s:%s', plugin, filename)
db = get_db()
db.eval(UNRECORD_WRAPPER, migration['_id'])
el... | Remove a database migration record.
\b
A record can be expressed with the following syntaxes:
- plugin filename
- plugin fliename.js
- plugin:filename
- plugin:fliename.js |
def load_diagram_from_csv(filepath, bpmn_diagram):
sequence_flows = bpmn_diagram.sequence_flows
process_elements_dict = bpmn_diagram.process_elements
diagram_attributes = bpmn_diagram.diagram_attributes
plane_attributes = bpmn_diagram.plane_attributes
process_dict = BpmnDiagramGr... | Reads an CSV file from given filepath and maps it into inner representation of BPMN diagram.
Returns an instance of BPMNDiagramGraph class.
:param filepath: string with output filepath,
:param bpmn_diagram: an instance of BpmnDiagramGraph class. |
def frontiers_style():
inchpercm = 2.54
frontierswidth=8.5
textsize = 5
titlesize = 7
plt.rcdefaults()
plt.rcParams.update({
'figure.figsize' : [frontierswidth/inchpercm, frontierswidth/inchpercm],
'figure.dpi' : 160,
'xtick.labelsize' : textsize,
'ytick.labelsiz... | Figure styles for frontiers |
def absolute_urls(html):
from bs4 import BeautifulSoup
from yacms.core.request import current_request
request = current_request()
if request is not None:
dom = BeautifulSoup(html, "html.parser")
for tag, attr in ABSOLUTE_URL_TAGS.items():
for node in dom.findAll(tag):
... | Converts relative URLs into absolute URLs. Used for RSS feeds to
provide more complete HTML for item descriptions, but could also
be used as a general richtext filter. |
def realtime_comment_classifier(sender, instance, created, **kwargs):
if created:
moderator_settings = getattr(settings, 'MODERATOR', None)
if moderator_settings:
if 'REALTIME_CLASSIFICATION' in moderator_settings:
if not moderator_settings['REALTIME_CLASSIFICATION']:
... | Classifies a comment after it has been created.
This behaviour is configurable by the REALTIME_CLASSIFICATION MODERATOR,
default behaviour is to classify(True). |
def assoc(objects, sitecol, assoc_dist, mode, asset_refs=()):
if isinstance(objects, numpy.ndarray) or hasattr(objects, 'lons'):
return _GeographicObjects(objects).assoc(sitecol, assoc_dist, mode)
else:
return _GeographicObjects(sitecol).assoc2(
objects, assoc_dist, mode, asset_refs) | Associate geographic objects to a site collection.
:param objects:
something with .lons, .lats or ['lon'] ['lat'], or a list of lists
of objects with a .location attribute (i.e. assets_by_site)
:param assoc_dist:
the maximum distance for association
:param mode:
if 'strict' ... |
def prj_remove_user(self, *args, **kwargs):
if not self.cur_prj:
return
i = self.prj_user_tablev.currentIndex()
item = i.internalPointer()
if item:
user = item.internal_data()
log.debug("Removing user %s.", user.username)
item.set_parent(No... | Remove the, in the user table view selected, user.
:returns: None
:rtype: None
:raises: None |
def get_bpf_pointer(tcpdump_lines):
if conf.use_pypy:
return _legacy_bpf_pointer(tcpdump_lines)
size = int(tcpdump_lines[0])
bpf_insn_a = bpf_insn * size
bip = bpf_insn_a()
tcpdump_lines = tcpdump_lines[1:]
i = 0
for line in tcpdump_lines:
values = [int(v) for v in line.split... | Create a BPF Pointer for TCPDump filter |
def wait(self, timeout=None):
if timeout is None:
timeout = self._timeout
with self._cond:
self._enter()
index = self._count
self._count += 1
try:
if index + 1 == self._parties:
self._release()
... | Wait for the barrier.
When the specified number of threads have started waiting, they are all
simultaneously awoken. If an 'action' was provided for the barrier, one
of the threads will have executed that callback prior to returning.
Returns an individual index number from 0 to 'parties... |
def save_xml(self, doc, element):
super(TargetExecutionContext, self).save_xml(doc, element)
element.setAttributeNS(RTS_NS, RTS_NS_S + 'id', self.id) | Save this target execution context into an xml.dom.Element
object. |
def request_slot(client,
service: JID,
filename: str,
size: int,
content_type: str):
payload = Request(filename, size, content_type)
return (yield from client.send(IQ(
type_=IQType.GET,
to=service,
payload=payload
))... | Request an HTTP upload slot.
:param client: The client to request the slot with.
:type client: :class:`aioxmpp.Client`
:param service: Address of the HTTP upload service.
:type service: :class:`~aioxmpp.JID`
:param filename: Name of the file (without path), may be used by the server
to gene... |
def _handle_calls(self, alts, format_, format_str, arr):
if format_str not in self._format_cache:
self._format_cache[format_str] = list(map(self.header.get_format_field_info, format_))
calls = []
for sample, raw_data in zip(self.samples.names, arr[9:]):
if self.samples.is... | Handle FORMAT and calls columns, factored out of parse_line |
def check(self, action, page=None, lang=None, method=None):
if self.user.is_superuser:
return True
if action == 'change':
return self.has_change_permission(page, lang, method)
if action == 'delete':
if not self.delete_page():
return False
... | Return ``True`` if the current user has permission on the page. |
def _get_cl_dependency_code(self):
code = ''
for d in self._dependencies:
code += d.get_cl_code() + "\n"
return code | Get the CL code for all the CL code for all the dependencies.
Returns:
str: The CL code with the actual code. |
def warning(self):
signals, docs, overs = self.expandedStim()
if np.any(np.array(overs) > 0):
msg = 'Stimuli in this test are over the maximum allowable \
voltage output. They will be rescaled with a maximum \
undesired attenuation of {:.2f}dB.'.format(np.amax... | Checks Stimulus for any warning conditions
:returns: str -- warning message, if any, 0 otherwise |
def openall(self, title=None):
spreadsheet_files = self.list_spreadsheet_files()
return [
Spreadsheet(self, dict(title=x['name'], **x))
for x in spreadsheet_files
] | Opens all available spreadsheets.
:param title: (optional) If specified can be used to filter
spreadsheets by title.
:type title: str
:returns: a list of :class:`~gspread.models.Spreadsheet` instances. |
def enterabs(self, time, priority, action, argument=(), kwargs=_sentinel):
if kwargs is _sentinel:
kwargs = {}
event = Event(time, priority, action, argument, kwargs)
with self._lock:
heapq.heappush(self._queue, event)
return event | Enter a new event in the queue at an absolute time.
Returns an ID for the event which can be used to remove it,
if necessary. |
def from_json(cls, json_data):
new_instance = cls()
for field_name, field_obj in cls._get_fields().items():
if isinstance(field_obj, NestedDocumentField):
if field_name in json_data:
nested_field = field_obj.__get__(new_instance, new_instance.__class__)
... | Converts json data to a new document instance |
def min_weighted_vertex_cover(G, weight=None, sampler=None, **sampler_args):
indep_nodes = set(maximum_weighted_independent_set(G, weight, sampler, **sampler_args))
return [v for v in G if v not in indep_nodes] | Returns an approximate minimum weighted vertex cover.
Defines a QUBO with ground states corresponding to a minimum weighted
vertex cover and uses the sampler to sample from it.
A vertex cover is a set of vertices such that each edge of the graph
is incident with at least one vertex in the set. A minim... |
def _fit_m(D, a0, logp, tol=1e-7, maxiter=1000):
N,K = D.shape
s = a0.sum()
for i in xrange(maxiter):
m = a0 / s
a1 = _ipsi(logp + (m*(psi(a0) - logp)).sum())
a1 = a1/a1.sum() * s
if norm(a1 - a0) < tol:
return a1
a0 = a1
raise Exception('Failed to con... | With fixed precision s, maximize mean m |
def isosurface_from_data(data, isolevel, origin, spacing):
spacing = np.array(extent/resolution)
if isolevel >= 0:
triangles = marching_cubes(data, isolevel)
else:
triangles = marching_cubes(-data, -isolevel)
faces = []
verts = []
for i, t in enumerate(triangles):
faces.ap... | Small wrapper to get directly vertices and faces to feed into programs |
def get_guts(self, last_build, missing='missing or bad'):
try:
data = _load_data(self.out)
except:
logger.info("building because %s %s", os.path.basename(self.out), missing)
return None
if len(data) != len(self.GUTS):
logger.info("building because ... | returns None if guts have changed |
def itemgetter_handle(tokens):
internal_assert(len(tokens) == 2, "invalid implicit itemgetter args", tokens)
op, args = tokens
if op == "[":
return "_coconut.operator.itemgetter(" + args + ")"
elif op == "$[":
return "_coconut.functools.partial(_coconut_igetitem, index=" + args + ")"
... | Process implicit itemgetter partials. |
def plot(self, xmin, xmax, idx_input=0, idx_output=0, points=100,
**kwargs) -> None:
for toy, ann_ in self:
ann_.plot(xmin, xmax,
idx_input=idx_input, idx_output=idx_output,
points=points,
label=str(toy),
... | Call method |anntools.ANN.plot| of all |anntools.ANN| objects
handled by the actual |anntools.SeasonalANN| object. |
def release(self, connection):
"Releases the connection back to the pool."
self._checkpid()
if connection.pid != self.pid:
return
try:
self.pool.put_nowait(connection)
except Full:
pass | Releases the connection back to the pool. |
def generated_passphrase_entropy(self) -> float:
if (
self.amount_w is None
or self.amount_n is None
or not self.wordlist
):
raise ValueError("Can't calculate the passphrase entropy: "
"wordlist is empty or amount_n... | Calculate the entropy of a passphrase that would be generated. |
def less(environment, opts):
require_extra_image(LESSC_IMAGE)
print 'Converting .less files to .css...'
for log in environment.compile_less():
print log | Recompiles less files in an environment.
Usage:
datacats less [ENVIRONMENT]
ENVIRONMENT may be an environment name or a path to an environment directory.
Default: '.' |
def panic(self, *args):
self._err("fatal", *args)
if self.test_errs_mode is False:
sys.exit(1) | Creates a fatal error and exit |
def iter_work_specs(self, limit=None, start=None):
count = 0
ws_list, start = self.list_work_specs(limit, start)
while True:
for name_spec in ws_list:
yield name_spec[1]
count += 1
if (limit is not None) and (count >= limit):
... | yield work spec dicts |
def set_defaults(self):
rfields, sfields = self.get_write_fields()
for f in rfields:
self.set_default(f)
for f in sfields:
self.set_default(f) | Set defaults for fields needed to write the header if they have
defaults.
Notes
-----
- This is NOT called by `rdheader`. It is only automatically
called by the gateway `wrsamp` for convenience.
- This is also not called by `wrheader` since it is supposed to
... |
def gregorian_to_julian(day):
before_march = 1 if day.month < MARCH else 0
month_index = day.month + MONTHS_PER_YEAR * before_march - MARCH
years_elapsed = day.year - JULIAN_START_YEAR - before_march
total_days_in_previous_months = (153 * month_index + 2) // 5
total_days_in_previous_years = 365 * ye... | Convert a datetime.date object to its corresponding Julian day.
:param day: The datetime.date to convert to a Julian day
:returns: A Julian day, as an integer |
async def enable_analog_reporting(self, pin):
command = [PrivateConstants.REPORT_ANALOG + pin,
PrivateConstants.REPORTING_ENABLE]
await self._send_command(command) | Enables analog reporting. By turning reporting on for a single pin,
:param pin: Analog pin number. For example for A0, the number is 0.
:returns: No return value |
def get_module_classes(node):
return [
child
for child in ast.walk(node)
if isinstance(child, ast.ClassDef)
] | Return classes associated with a given module |
def write8(self, offset, value):
if not isinstance(offset, (int, long)):
raise TypeError("Invalid offset type, should be integer.")
if not isinstance(value, (int, long)):
raise TypeError("Invalid value type, should be integer.")
if value < 0 or value > 0xff:
r... | Write 8-bits to the specified `offset` in bytes, relative to the
base physical address of the MMIO region.
Args:
offset (int, long): offset from base physical address, in bytes.
value (int, long): 8-bit value to write.
Raises:
TypeError: if `offset` or `valu... |
def delete_job(name=None):
if not name:
raise SaltInvocationError('Required parameter \'name\' is missing')
server = _connect()
if not job_exists(name):
raise CommandExecutionError('Job \'{0}\' does not exist'.format(name))
try:
server.delete_job(name)
except jenkins.JenkinsE... | Return true is job is deleted successfully.
:param name: The name of the job to delete.
:return: Return true if job is deleted successfully.
CLI Example:
.. code-block:: bash
salt '*' jenkins.delete_job jobname |
def iters(cls, batch_size=32, bptt_len=35, device=0, root='.data',
vectors=None, **kwargs):
TEXT = data.Field()
train, val, test = cls.splits(TEXT, root=root, **kwargs)
TEXT.build_vocab(train, vectors=vectors)
return data.BPTTIterator.splits(
(train, val, test),... | Create iterator objects for splits of the WikiText-2 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.
bptt_len: Length of sequences for backpropagation th... |
def get_postgame(self):
if self._cache['postgame'] is not None:
return self._cache['postgame']
self._handle.seek(0)
try:
self._cache['postgame'] = parse_postgame(self._handle, self.size)
return self._cache['postgame']
except IOError:
self._... | Get postgame structure. |
def versions(self):
versions = []
for v, _ in self.restarts:
if len(versions) == 0 or v != versions[-1]:
versions.append(v)
return versions | Return all version changes. |
def applyReq(self, request: Request, cons_time: int):
self.execute_hook(NodeHooks.PRE_REQUEST_APPLICATION, request=request,
cons_time=cons_time)
req_handler = self.get_req_handler(txn_type=request.operation[TXN_TYPE])
seq_no, txn = req_handler.apply(request, cons_time)
... | Apply request to appropriate ledger and state. `cons_time` is the
UTC epoch at which consensus was reached. |
def nova_services_up(self):
required = set(['nova-conductor', 'nova-cert', 'nova-scheduler',
'nova-compute'])
try:
services = self._nclient.services.list()
except Exception as e:
LOG.error('Failure determining running Nova services: %s', e)
... | Checks if required Nova services are up and running.
returns: True if all needed Nova services are up, False otherwise |
def warn(self, cmd, desc=''):
return self._label_desc(cmd, desc, self.warn_color) | Style for warning message. |
def triangle_area(e1, e2, e3):
e1_length = numpy.sqrt(numpy.sum(e1 * e1, axis=-1))
e2_length = numpy.sqrt(numpy.sum(e2 * e2, axis=-1))
e3_length = numpy.sqrt(numpy.sum(e3 * e3, axis=-1))
s = (e1_length + e2_length + e3_length) / 2.0
return numpy.sqrt(s * (s - e1_length) * (s - e2_length) * (s - e3_l... | Get the area of triangle formed by three vectors.
Parameters are three three-dimensional numpy arrays representing
vectors of triangle's edges in Cartesian space.
:returns:
Float number, the area of the triangle in squared units of coordinates,
or numpy array of shape of edges with one dim... |
def _temp_filename(contents):
fp = tempfile.NamedTemporaryFile(
prefix='codequalitytmp', delete=False)
name = fp.name
fp.write(contents)
fp.close()
_files_to_cleanup.append(name)
return name | Make a temporary file with `contents`.
The file will be cleaned up on exit. |
def yield_for_all_futures(result):
while True:
if result is None:
break
try:
future = gen.convert_yielded(result)
except gen.BadYieldError:
break
else:
result = yield future
raise gen.Return(result) | Converts result into a Future by collapsing any futures inside result.
If result is a Future we yield until it's done, then if the value inside
the Future is another Future we yield until it's done as well, and so on. |
def collections(self, values):
if self.cache:
self.cache.set(
self.app.config['COLLECTIONS_CACHE_KEY'], values) | Set list of collections. |
def _bse_cli_list_ref_formats(args):
all_refformats = api.get_reference_formats()
if args.no_description:
liststr = all_refformats.keys()
else:
liststr = format_columns(all_refformats.items())
return '\n'.join(liststr) | Handles the list-ref-formats subcommand |
def dump_part(part, total_segments=None):
try:
connection = Connection(host=config['host'], region=config['region'])
filename = ".".join([config['table_name'], str(part), "dump"])
if config['compress']:
opener = gzip.GzipFile
filename += ".gz"
else:
... | 'part' may be the hash_key if we are dumping just a few hash_keys - else
it will be the segment number |
def all_editable_exts():
exts = []
for (language, extensions) in languages.ALL_LANGUAGES.items():
exts.extend(list(extensions))
return ['.' + ext for ext in exts] | Return a list of all editable extensions |
def is_running(self) -> bool:
return (
self._has_started and
self.is_alive() or
self.completed_at is None or
(datetime.utcnow() - self.completed_at).total_seconds() < 0.5
) | Specifies whether or not the thread is running |
def create_snapshot(self, snapshot_size, snapshot_suffix):
size_extent = math.ceil(self.extents_count() * snapshot_size)
size_kb = self.volume_group().extent_size() * size_extent
snapshot_name = self.volume_name() + snapshot_suffix
lvcreate_cmd = ['sudo'] if self.lvm_command().sudo() is True else []
lvcreate_... | Create snapshot for this logical volume.
:param snapshot_size: size of newly created snapshot volume. This size is a fraction of the source \
logical volume space (of this logical volume)
:param snapshot_suffix: suffix for logical volume name (base part is the same as the original volume \
name)
:return: WL... |
def unsubscribe_all(self):
topics = list(self.topics.keys())
for topic in topics:
self.unsubscribe(topic) | Unsubscribe from all topics. |
def transpose_list(list_of_dicts):
res = {}
for d in list_of_dicts:
for k, v in d.items():
if k in res:
res[k].append(v)
else:
res[k] = [v]
return res | Transpose a list of dicts to a dict of lists
:param list_of_dicts: to transpose, as in the output from a parse call
:return: Dict of lists |
def firmware_version(self):
buf = (ctypes.c_char * self.MAX_BUF_SIZE)()
self._dll.JLINKARM_GetFirmwareString(buf, self.MAX_BUF_SIZE)
return ctypes.string_at(buf).decode() | Returns a firmware identification string of the connected J-Link.
It consists of the following:
- Product Name (e.g. J-Link)
- The string: compiled
- Compile data and time.
- Optional additional information.
Args:
self (JLink): the ``JLink`` instance
... |
def _get_num_pass(data, n):
numpass = tz.get_in(["config", "algorithm", "ensemble", "numpass"], data)
if numpass:
return int(numpass)
trusted_pct = tz.get_in(["config", "algorithm", "ensemble", "trusted_pct"], data)
if trusted_pct:
return int(math.ceil(float(trusted_pct) * n))
return... | Calculate the number of samples needed to pass ensemble calling. |
def _create_ip_report(self):
try:
ip_report_name = os.path.join(self.report_dir, "%s-ip.csv" % self.session)
self.logger.con_out('Creating IP Report - %s', ip_report_name)
ip_report = open(ip_report_name, 'wt')
ip_report.write('Obfuscated IP,Original IP\n')
... | this will take the obfuscated ip and hostname databases and output csv files |
def namespace_for_prefix(self, prefix):
try:
ni = self.__lookup_prefix(prefix)
except PrefixNotFoundError:
return None
else:
return ni.uri | Get the namespace the given prefix maps to.
Args:
prefix (str): The prefix
Returns:
str: The namespace, or None if the prefix isn't mapped to
anything in this set. |
def generate(env):
try:
bld = env['BUILDERS']['Rpm']
except KeyError:
bld = RpmBuilder
env['BUILDERS']['Rpm'] = bld
env.SetDefault(RPM = 'LC_ALL=C rpmbuild')
env.SetDefault(RPMFLAGS = SCons.Util.CLVar('-ta'))
env.SetDefault(RPMCOM = rpmAction)
env.SetDe... | Add Builders and construction variables for rpm to an Environment. |
def info(self, account_id, resource_id, parent_id):
resource = self.record(account_id, resource_id)
if resource is None and not parent_id:
return {'ResourceId': resource_id,
'LockStatus': self.STATE_UNLOCKED}
elif resource is None:
parent = self.record... | Check if a resource is locked.
If a resource has an explicit status we use that, else
we defer to the parent resource lock status. |
def upload(self, filename, **kwargs):
kwargs['index'] = self.name
path = 'data/inputs/oneshot'
self.service.post(path, name=filename, **kwargs)
return self | Uploads a file for immediate indexing.
**Note**: The file must be locally accessible from the server.
:param filename: The name of the file to upload. The file can be a
plain, compressed, or archived file.
:type filename: ``string``
:param kwargs: Additional arguments (opti... |
def _require_bucket(self, bucket_name):
if not self.exists(bucket_name) and not self.claim_bucket(bucket_name):
raise OFSException("Invalid bucket: %s" % bucket_name)
return self._get_bucket(bucket_name) | Also try to create the bucket. |
def rescan_images(registry):
with Session() as session:
try:
result = session.Image.rescanImages(registry)
except Exception as e:
print_error(e)
sys.exit(1)
if result['ok']:
print("kernel image metadata updated")
else:
print... | Update the kernel image metadata from all configured docker registries. |
def auto_batch_size(sequence_length,
mesh_shape,
layout_rules,
tokens_per_split=2048):
num_splits = mtf.tensor_dim_to_mesh_dim_size(
layout_rules, mesh_shape, mtf.Dimension("batch", 0))
ret = max(1, tokens_per_split // sequence_length) * num_splits
... | Automatically compute batch size.
Args:
sequence_length: an integer
mesh_shape: an input to mtf.convert_to_shape()
layout_rules: an input to mtf.convert_to_layout_rules()
tokens_per_split: an integer
Returns:
an integer |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.