code stringlengths 51 2.38k | docstring stringlengths 4 15.2k |
|---|---|
def load_config(fname: str) -> ModelConfig:
config = ModelConfig.load(fname)
logger.info('ModelConfig loaded from "%s"', fname)
return cast(ModelConfig, config) | Loads model configuration.
:param fname: Path to load model configuration from.
:return: Model configuration. |
def parse_connection_string(self, connection):
if connection == 'c2s_tls':
return CONNECTION_XMPP, True, False
elif connection == 'c2s_compressed_tls':
return CONNECTION_XMPP, True, True
elif connection == 'http_bind':
return CONNECTION_HTTP_BINDING, None, Non... | Parse string as returned by the ``connected_users_info`` or ``user_sessions_info`` API calls.
>>> EjabberdBackendBase().parse_connection_string('c2s_tls')
(0, True, False)
>>> EjabberdBackendBase().parse_connection_string('c2s_compressed_tls')
(0, True, True)
>>> EjabberdBackend... |
def _str(self, name, val):
s = ''
v = Value(val)
if name:
logger.debug("{} is type {}".format(name, v.typename))
try:
count = len(val)
s = "{} ({}) = {}".format(name, count, v.string_value())
except (TypeError, KeyError, Attribu... | return a string version of name = val that can be printed
example --
_str('foo', 'bar') # foo = bar
name -- string -- the variable name that was passed into one of the public methods
val -- mixed -- the variable at name's value
return -- string |
def get_creation_date_tags(url, domain, as_dicts=False):
creation_date_tags = [
mementoweb_api_tags(url),
get_whois_tags(domain),
]
creation_date_tags = sorted(
sum(creation_date_tags, []),
key=lambda x: x.date
)
if not as_dicts:
return creation_date_tags
... | Put together all data sources in this module and return it's output.
Args:
url (str): URL of the web. With relative paths and so on.
domain (str): Just the domain of the web.
as_dicts (bool, default False): Convert output to dictionaries
compatible with :class:`.SourceString`?
... |
def _write_migration(self, creator, name, table, create, path):
file_ = os.path.basename(creator.create(name, path, table, create))
return file_ | Write the migration file to disk. |
def is_subfeature_of (parent_property, f):
if __debug__:
from .property import Property
assert isinstance(parent_property, Property)
assert isinstance(f, Feature)
if not f.subfeature:
return False
p = f.parent
if not p:
return False
parent_feature = p[0]
p... | Return true iff f is an ordinary subfeature of the parent_property's
feature, or if f is a subfeature of the parent_property's feature
specific to the parent_property's value. |
def prepare_allseries(self, ramflag: bool = True) -> None:
for element in printtools.progressbar(self):
element.prepare_allseries(ramflag) | Call method |Element.prepare_allseries| of all handled
|Element| objects. |
def format_image(path, options):
image = Image.open(path)
image_pipeline_results = __pipeline_image(image, options)
return image_pipeline_results | Formats an image.
Args:
path (str): Path to the image file.
options (dict): Options to apply to the image.
Returns:
(list) A list of PIL images. The list will always be of length
1 unless resolutions for resizing are provided in the options. |
def format_assistants_lines(cls, assistants):
lines = cls._format_files(assistants, 'assistants')
if assistants:
lines.append('')
assistant = strip_prefix(random.choice(assistants), 'assistants').replace(os.path.sep, ' ').strip()
if len(assistants) == 1:
... | Return formatted assistants from the given list in human readable form. |
def _setup_params(self_,**params):
self = self_.param.self
params_to_instantiate = {}
for class_ in classlist(type(self)):
if not issubclass(class_, Parameterized):
continue
for (k,v) in class_.__dict__.items():
if isinstance(v,Parameter) a... | Initialize default and keyword parameter values.
First, ensures that all Parameters with 'instantiate=True'
(typically used for mutable Parameters) are copied directly
into each object, to ensure that there is an independent copy
(to avoid suprising aliasing errors). Then sets each of ... |
def parse_json(self, page):
if not isinstance(page, basestring):
page = util.decode_page(page)
self.doc = json.loads(page)
results = self.doc.get(self.result_name, [])
if not results:
self.check_status(self.doc.get('status'))
return None
return... | Returns json feed. |
def identify_datafiles(root,
extensions_to_ignore=None,
directories_to_ignore=None,
files_to_ignore=None):
for dirpath, dirnames, filenames in walk(root):
for ignore in directories_to_ignore:
if ignore in dirnames:
... | Identify files that might contain data
See function IP_verified() for details about optinoal parmeters |
def transform(fields, function, *tables):
"Return a new table based on other tables and a transformation function"
new_table = Table(fields=fields)
for table in tables:
for row in filter(bool, map(lambda row: function(row, table), table)):
new_table.append(row)
return new_table | Return a new table based on other tables and a transformation function |
def service_executions(self, name=None, pk=None, scope=None, service=None, **kwargs):
request_params = {
'name': name,
'id': pk,
'service': service,
'scope': scope
}
if kwargs:
request_params.update(**kwargs)
r = self._request('... | Retrieve Service Executions.
If additional `keyword=value` arguments are provided, these are added to the request parameters. Please
refer to the documentation of the KE-chain API for additional query parameters.
:param name: (optional) name to limit the search for
:type name: basestri... |
def _parse_references(xml):
references = []
ref_finder = HTMLReferenceFinder(xml)
for elm, uri_attr in ref_finder:
type_ = _discover_uri_type(elm.get(uri_attr))
references.append(Reference(elm, type_, uri_attr))
return references | Parse the references to ``Reference`` instances. |
def unoptimize_scope(self, frame):
if frame.identifiers.declared:
self.writeline('%sdummy(%s)' % (
unoptimize_before_dead_code and 'if 0: ' or '',
', '.join('l_' + name for name in frame.identifiers.declared)
)) | Disable Python optimizations for the frame. |
def _is_autonomous(indep, exprs):
if indep is None:
return True
for expr in exprs:
try:
in_there = indep in expr.free_symbols
except:
in_there = expr.has(indep)
if in_there:
return False
return True | Whether the expressions for the dependent variables are autonomous.
Note that the system may still behave as an autonomous system on the interface
of :meth:`integrate` due to use of pre-/post-processors. |
def _encode_params(kw):
args = []
for k, v in kw.items():
try:
qv = v.encode('utf-8') if isinstance(v, unicode) else str(v)
except:
qv = v
args.append('%s=%s' % (k, urlquote(qv)))
return '&'.join(args) | Encode parameters. |
def buildingname(ddtt):
idf = ddtt.theidf
building = idf.idfobjects['building'.upper()][0]
return building.Name | return building name |
def shorten_type(typ):
offset = 0
for prefix in SHORTEN_TYPE_PREFIXES:
if typ.startswith(prefix):
if len(prefix) > offset:
offset = len(prefix)
return typ[offset:] | Shorten a type. E.g. drops 'System.' |
def _fetch_all(self):
if self._result_cache is None:
self._result_cache = list(self.iterator())
if self._iterable_class == ModelIterable:
for x in self._result_cache:
self._set_item_querytime(x)
if self._prefetch_related_lookups and not self._p... | Completely overrides the QuerySet._fetch_all method by adding the
timestamp to all objects
:return: See django.db.models.query.QuerySet._fetch_all for return
values |
def _split_lines(self):
parsed_lines = {}
for rt in all_record_types:
parsed_lines[rt] = []
parsed_lines[0] = []
for line in self.lines:
linetype = line[0:6]
if linetype in all_record_types:
parsed_lines[linetype].append(line)
... | Creates the parsed_lines dict which keeps all record data in document order indexed by the record type. |
def _expand_sequence(self, seq: List[GridQubit]) -> List[GridQubit]:
i = 1
while i < len(seq):
path = self._find_path_between(seq[i - 1], seq[i], set(seq))
if path:
seq = seq[:i] + path + seq[i:]
else:
i += 1
return seq | Tries to expand given sequence with more qubits.
Args:
seq: Linear sequence of qubits.
Returns:
New continuous linear sequence which contains all the qubits from
seq and possibly new qubits inserted in between. |
def bounds(self, thr=0):
min_lat = float("inf")
min_lon = float("inf")
max_lat = -float("inf")
max_lon = -float("inf")
for segment in self.segments:
milat, milon, malat, malon = segment.bounds(thr=thr)
min_lat = min(milat, min_lat)
min_lon = mi... | Gets the bounds of this segment
Returns:
(float, float, float, float): Bounds, with min latitude, min longitude,
max latitude and max longitude |
def load_configuration(self):
filename = os.path.join(os.path.dirname(__file__), 'templates/spline-loc.yml.j2')
with open(filename) as handle:
return Adapter(safe_load(handle)).configuration | Loading configuration. |
def events(self, year, simple=False, keys=False):
if keys:
return self._get('events/%s/keys' % year)
else:
return [Event(raw) for raw in self._get('events/%s%s' % (year, '/simple' if simple else ''))] | Get a list of events in a given year.
:param year: Year to get events from.
:param keys: Get only keys of the events rather than full data.
:param simple: Get only vital data.
:return: List of string event keys or Event objects. |
def cublasZherk(handle, uplo, trans, n, k, alpha, A, lda, beta, C, ldc):
status = _libcublas.cublasZherk_v2(handle,
_CUBLAS_FILL_MODE[uplo],
_CUBLAS_OP[trans],
n, k, ctypes.byref(ctypes.c_double(alp... | Rank-k operation on Hermitian matrix. |
def _prepare_tmp_directory(self, tmp_dir):
if tmp_dir:
if os.path.exists(tmp_dir):
raise SquashError(
"The '%s' directory already exists, please remove it before you proceed" % tmp_dir)
os.makedirs(tmp_dir)
else:
tmp_dir = tempfile.... | Creates temporary directory that is used to work on layers |
def strip_spaces(value, sep=None, join=True):
value = value.strip()
value = [v.strip() for v in value.split(sep)]
join_sep = sep or ' '
return join_sep.join(value) if join else value | Cleans trailing whitespaces and replaces also multiple whitespaces with a single space. |
def parse_first_row(row, url_instance):
tags = row.xpath(Parser.FIRST_ROW_XPATH)
category_url = url_instance.combine(tags[0].get('href'))
title = unicode(tags[1].text)
torrent_url = tags[1].get('href')
str_id = torrent_url.split('details/')[1]
str_id = str_id[:-1] if str_... | Static method that parses a given table row element by executing `Parser.FIRST_ROW_XPATH` and scrapping torrent's
id, title, tracked by status, category url and torrent url. Used specifically with a torrent's first table row.
:param lxml.HtmlElement row: row to parse
:param urls.Url url_instanc... |
def count(self, stats, value, sample_rate=1):
self.update_stats(stats, value, self.SC_COUNT, sample_rate) | Updates one or more stats counters by arbitrary value
>>> client = StatsdClient()
>>> client.count('example.counter', 17) |
def remove_tar_files(file_list):
for f in file_list:
if file_exists(f) and f.endswith('.tar'):
os.remove(f) | Public function that removes temporary tar archive files in a local directory |
def _from_dict(cls, _dict):
args = {}
if 'authors' in _dict:
args['authors'] = [
Author._from_dict(x) for x in (_dict.get('authors'))
]
if 'publication_date' in _dict:
args['publication_date'] = _dict.get('publication_date')
if 'title' ... | Initialize a AnalysisResultsMetadata object from a json dictionary. |
def handle(self, args):
salutation = {
'french': 'Bonjour',
'spanish': 'Hola',
'english': 'Hello',
}[args.lang.lower()]
output = []
for name in args.name:
output.append("{} {}!".format(salutation, name))
return "\n".join(output) | Greet each person by name. |
def _one_q_state_prep(oneq_state: _OneQState):
label = oneq_state.label
if label == 'SIC':
return _one_q_sic_prep(oneq_state.index, oneq_state.qubit)
elif label in ['X', 'Y', 'Z']:
return _one_q_pauli_prep(label, oneq_state.index, oneq_state.qubit)
else:
raise ValueError(f"Bad st... | Prepare a one qubit state.
Either SIC[0-3], X[0-1], Y[0-1], or Z[0-1]. |
def process_dataset(dataset, models, **kargs):
dset = collections.OrderedDict()
for m in MultiFitter.flatten_models(models):
dset[m.datatag] = (
m.builddataset(dataset) if m.ncg <= 1 else
MultiFitter.coarse_grain(m.builddataset(dataset), ncg=m.ncg)
... | Convert ``dataset`` to processed data using ``models``.
:class:`gvar.dataset.Dataset` (or similar dictionary) object
``dataset`` is processed by each model in list ``models``,
and the results collected into a new dictionary ``pdata`` for use in
:meth:`MultiFitter.lsqfit` and :meth:`Mult... |
def _get_version():
version_string = __salt__['cmd.run'](
[_check_xbps(), '--version'],
output_loglevel='trace')
if version_string is None:
return False
VERSION_MATCH = re.compile(r'(?:XBPS:[\s]+)([\d.]+)(?:[\s]+.*)')
version_match = VERSION_MATCH.search(version_string)
if no... | Get the xbps version |
def compliance_report(filepath=None,
string=None,
renderer='jinja|yaml',
**kwargs):
validation_string = __salt__['slsutil.renderer'](path=filepath,
string=string,
... | Return the compliance report.
filepath
The absolute path to the validation file.
.. versionchanged:: 2019.2.0
Beginning with release codename ``2019.2.0``, this function has been
enhanced, to be able to leverage the multi-engine template rendering
of Salt, besides the poss... |
def op_at_on(operation: ops.Operation,
time: Timestamp,
device: Device):
return ScheduledOperation(time,
device.duration_of(operation),
operation) | Creates a scheduled operation with a device-determined duration. |
def add_coreference(self, coreference):
if self.coreference_layer is None:
self.coreference_layer = Ccoreferences(type=self.type)
self.root.append(self.coreference_layer.get_node())
self.coreference_layer.add_coreference(coreference) | Adds an coreference to the coreference layer
@type coreference: L{Ccoreference}
@param coreference: the coreference object |
def number(self):
return int(math.ceil(self.total_size / float(self.size))) | Returns the number of batches the batched sequence contains.
:rtype: integer. |
def get_single_keywords(skw_db, fulltext):
timer_start = time.clock()
records = []
for single_keyword in skw_db.values():
for regex in single_keyword.regex:
for match in regex.finditer(fulltext):
span = (match.span()[0], match.span()[1] - 1)
records = [rec... | Find single keywords in the fulltext.
:param skw_db: list of KeywordToken objects
:param fulltext: string, which will be searched
:return : dictionary of matches in a format {
<keyword object>, [[position, position...], ],
..
} |
def create(dataset, target, features=None, validation_set = 'auto',
verbose=True):
dataset, validation_set = _validate_data(dataset, target, features,
validation_set)
if validation_set is None:
validation_set = _turicreate.SFrame()
model_proxy = _... | Automatically create a suitable regression model based on the provided
training data.
To use specific options of a desired model, use the ``create`` function
of the corresponding model.
Parameters
----------
dataset : SFrame
Dataset for training the model.
target : str
The... |
def snappy_encode(payload, xerial_compatible=False, xerial_blocksize=32 * 1024):
if not has_snappy():
raise NotImplementedError("Snappy codec is not available")
if xerial_compatible:
def _chunker():
for i in xrange(0, len(payload), xerial_blocksize):
yield payload[i:i... | Encodes the given data with snappy if xerial_compatible is set then the
stream is encoded in a fashion compatible with the xerial snappy library
The block size (xerial_blocksize) controls how frequent the blocking
occurs 32k is the default in the xerial library.
The format winds up being
... |
def _get_pdb_id(self, elem, **kwargs):
id = elem.attrib['ID']
if self.restrict_to_transmembrane_proteins:
tmp = elem.attrib['TMP']
assert(tmp == 'no' or tmp == 'yes' or tmp == 'not')
if tmp == 'yes':
self.ids[id] = PDBTM._get_tm_type(elem)
else... | If self.restrict_to_transmembrane_proteins is False then this adds all ids to self.ids. Otherwise, only transmembrane protein ids are added. |
def create_redis_client(self):
return ray.services.create_redis_client(
self._redis_address, self._ray_params.redis_password) | Create a redis client. |
def do_authenticate_account(self, authc_token):
try:
realms = self.token_realm_resolver[authc_token.__class__]
except KeyError:
raise KeyError('Unsupported Token Type Provided: ', authc_token.__class__.__name__)
if (len(self.realms) == 1):
account = self.authe... | Returns an account object only when the current token authenticates AND
the authentication process is complete, raising otherwise
:returns: Account
:raises AdditionalAuthenticationRequired: when additional tokens are required,
passing the accou... |
def connect_reftrack_scenenode(self, refobj, scenenode):
conns = [("%s.scenenode" % refobj, "%s.reftrack" % scenenode),
("%s.taskfile_id" % scenenode, "%s.taskfile_id" % refobj)]
for src, dst in conns:
if not cmds.isConnected(src, dst):
cmds.connectAttr(src, ... | Connect the given reftrack node with the given scene node
:param refobj: the reftrack node to connect
:type refobj: str
:param scenenode: the jb_sceneNode to connect
:type scenenode: str
:returns: None
:rtype: None
:raises: None |
def download_and_extract_to_mkdtemp(bucket, key, session=None):
if session:
s3_client = session.client('s3')
else:
s3_client = boto3.client('s3')
transfer = S3Transfer(s3_client)
filedes, temp_file = tempfile.mkstemp()
os.close(filedes)
transfer.download_file(bucket, key, temp_fi... | Download zip archive and extract it to temporary directory. |
def _speak_as_spell_out_inherit(self, element):
self._reverse_speak_as(element, 'spell-out')
self._isolate_text_node(element)
self._visit(element, self._speak_as_spell_out) | Speak one letter at a time for each word for elements and descendants.
:param element: The element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement |
def plot_soma3d(ax, soma, color=None, alpha=_ALPHA):
color = _get_color(color, tree_type=NeuriteType.soma)
if isinstance(soma, SomaCylinders):
for start, end in zip(soma.points, soma.points[1:]):
common.plot_cylinder(ax,
start=start[COLS.XYZ], end=end[COLS.XY... | Generates a 3d figure of the soma.
Args:
ax(matplotlib axes): on what to plot
soma(neurom.core.Soma): plotted soma
color(str or None): Color of plotted values, None corresponds to default choice
alpha(float): Transparency of plotted values |
def convert_value(value, source_currency, target_currency):
if source_currency == target_currency:
return value
rate = get_rate(source_currency, target_currency)
return value * rate | Converts the price of a currency to another one using exchange rates
:param price: the price value
:param type: decimal
:param source_currency: source ISO-4217 currency code
:param type: str
:param target_currency: target ISO-4217 currency code
:param type: str
:returns: converted price ... |
def gsr_path(self):
try:
return self._gsr_path
except AttributeError:
path = self.outdir.has_abiext("GSR")
if path: self._gsr_path = path
return path | Absolute path of the GSR file. Empty string if file is not present. |
def bind_download_buttons(cls):
def on_click(ev):
button_el = ev.target
form_el = button_el.parent.parent.parent
content = form_el.get(selector="textarea")[0].text
suffix = form_el.name
download_path = "as_file/%s.%s" % (cls.filename, suffix)
... | Bind buttons to callbacks. |
def namedtuple_storable(namedtuple, *args, **kwargs):
return default_storable(namedtuple, namedtuple._fields, *args, **kwargs) | Storable factory for named tuples. |
def get_total_time(self):
first_step = self.steps[0]
last_step = self.steps[-1]
seconds = self.history[last_step]["__timestamp__"] \
- self.history[first_step]["__timestamp__"]
return datetime.timedelta(seconds=seconds) | Returns the total period between when the first and last steps
where logged. This usually correspnods to the total training time
if there were no gaps in the training. |
def _py3_crc16(value):
crc = 0
for byte in value:
crc = ((crc << 8) & 0xffff) ^ _CRC16_LOOKUP[((crc >> 8) ^ byte) & 0xff]
return crc | Calculate the CRC for the value in Python 3
:param bytes value: The value to return for the CRC Checksum
:rtype: int |
def rename_keys(record: Mapping, key_map: Mapping) -> dict:
new_record = dict()
for k, v in record.items():
key = key_map[k] if k in key_map else k
new_record[key] = v
return new_record | New record with same keys or renamed keys if key found in key_map. |
def blob(self, sha):
url = self._build_url('git', 'blobs', sha, base_url=self._api)
json = self._json(self._get(url), 200)
return Blob(json) if json else None | Get the blob indicated by ``sha``.
:param str sha: (required), sha of the blob
:returns: :class:`Blob <github3.git.Blob>` if successful, otherwise
None |
def merge_chunk_data(output_file="merged_idx_contig_hit_size_cov.txt", *files):
chunks = dict()
for chunk_file in files:
with open(chunk_file) as chunk_file_handle:
for line in chunk_file_handle:
chunk_id, chunk_name, hit, size, cov = line.split("\t")
try:
... | Merge chunk data from different networks
Similarly to merge_network, this merges any number of chunk data files.
Parameters
---------
output_file : file, str, or pathlib.Path, optional
The output file to write the merged chunk data files into. Default is
merged_idx_contig_hit_size_cov.... |
def delete_intf_router(self, name, tenant_id, rout_id, subnet_lst):
try:
for subnet_id in subnet_lst:
body = {'subnet_id': subnet_id}
intf = self.neutronclient.remove_interface_router(rout_id,
body=body... | Delete the openstack router and remove the interfaces attached. |
def convert_ascii_field(string):
values = []
for codepoint in [s for s in string.split(DATA_FILE_CODEPOINT_SEPARATOR) if (s != DATA_FILE_VALUE_NOT_AVAILABLE) and (len(s) > 0)]:
if (codepoint.startswith(DATA_FILE_ASCII_NUMERICAL_CODEPOINT_START)) or (codepoint.startswith(DATA_FILE_ASCII_UNICODE_CODEPOINT... | Convert an ASCII field into the corresponding list of Unicode strings.
The (input) ASCII field is a Unicode string containing
one or more ASCII codepoints (``00xx`` or ``U+00xx`` or
an ASCII string not starting with ``00`` or ``U+``),
separated by a space.
:param str string: the (input) ASCII fiel... |
def get_service_types(self):
resp = self._get_resource_root().get(self._path() + '/serviceTypes')
return resp[ApiList.LIST_KEY] | Get all service types supported by this cluster.
@return: A list of service types (strings) |
def body_kwargs(self):
body_kwargs = {}
ct = self.get_header("content-type")
if ct:
ct = ct.lower()
if ct.rfind("json") >= 0:
body = self.body
if body:
body_kwargs = json.loads(body)
else:
if ... | the request body, if this is a POST request
this tries to do the right thing with the body, so if you have set the body and
the content type is json, then it will return the body json decoded, if you need
the original string body, use body
example --
self.body = '{"foo":{"... |
def set_cursor_pos_callback(window, cbfun):
window_addr = ctypes.cast(ctypes.pointer(window),
ctypes.POINTER(ctypes.c_long)).contents.value
if window_addr in _cursor_pos_callback_repository:
previous_callback = _cursor_pos_callback_repository[window_addr]
else:
... | Sets the cursor position callback.
Wrapper for:
GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow* window, GLFWcursorposfun cbfun); |
def substitute_values(self, vect):
try:
unique = np.unique(vect)
except:
unique = set(vect)
unique = [
x for x in unique if not isinstance(x, float) or not isnan(x)
]
arr = np.copy(vect)
for new_id, value in enumerate(unique):
... | Internal method to substitute integers into the vector, and construct
metadata to convert back to the original vector.
np.nan is always given -1, all other objects are given integers in
order of apperence.
Parameters
----------
vect : np.array
the vector in ... |
def reconstitute_path(drive, folders):
reconstituted = os.path.join(drive, os.path.sep, *folders)
return reconstituted | Reverts a tuple from `get_path_components` into a path.
:param drive: A drive (eg 'c:'). Only applicable for NT systems
:param folders: A list of folder names
:return: A path comprising the drive and list of folder names. The path terminate
with a `os.path.sep` *only* if it is a root directory |
def select(self, limit=0):
if limit < 1:
limit = None
for child in self.get_descendants(self.tag):
if self.match(child):
yield child
if limit is not None:
limit -= 1
if limit < 1:
brea... | Match all tags under the targeted tag. |
def crypto_sign(msg, sk):
if len(sk) != SECRETKEYBYTES:
raise ValueError("Bad signing key length %d" % len(sk))
vkbytes = sk[PUBLICKEYBYTES:]
skbytes = sk[:PUBLICKEYBYTES]
sig = djbec.signature(msg, skbytes, vkbytes)
return sig + msg | Return signature+message given message and secret key.
The signature is the first SIGNATUREBYTES bytes of the return value.
A copy of msg is in the remainder. |
def format(self, *args, **kwargs):
return self.__class__(super(ColorStr, self).format(*args, **kwargs), keep_tags=True) | Return a formatted version, using substitutions from args and kwargs.
The substitutions are identified by braces ('{' and '}'). |
def parse_rule(name, rule_text, do_raise=False):
try:
return rule.parseString(rule_text, parseAll=True)[0]
except pyparsing.ParseException as exc:
if do_raise:
raise
log = logging.getLogger('policies')
log.warn("Failed to parse rule %r: %s" % (name, exc))
log.... | Parses the given rule text.
:param name: The name of the rule. Used when emitting log
messages regarding a failure to parse the rule.
:param rule_text: The text of the rule to parse.
:param do_raise: If ``False`` and the rule fails to parse, a log
message is emitted t... |
def get_relationship(self, attribute):
rel = self.__relationships.get(attribute.entity_attr)
if rel is None:
rel = LazyDomainRelationship(self, attribute,
direction=
self.relationship_direction)
... | Returns the domain relationship object for the given resource
attribute. |
def wrap(start: str, string: str, end: str = "") -> str:
return f"{start}{string}{end}" if string else "" | Wrap string inside other strings at start and end.
If the string is not None or empty, then wrap with start and end, otherwise return
an empty string. |
def send_msg(app, msg, reply_cls=None, reply_multi=False):
return app.send_request(event.SendMsgRequest(msg=msg,
reply_cls=reply_cls,
reply_multi=reply_multi))() | Send an OpenFlow message and wait for reply messages.
:param app: Client RyuApp instance
:param msg: An OpenFlow controller-to-switch message to send
:param reply_cls: OpenFlow message class for expected replies.
None means no replies are expected. The default is None.
:param reply_multi: True... |
def is_castable(src, dst):
if ((src in [int, bool]) or rdltypes.is_user_enum(src)) and (dst in [int, bool]):
return True
elif (src == rdltypes.ArrayPlaceholder) and (dst == rdltypes.ArrayPlaceholder):
if src.element_type is None:
return True
elif src.element_type == dst.eleme... | Check if src type can be cast to dst type |
async def finish_authentication(self, username, password):
self.srp.step1(username, password)
data = await self._send_plist(
'step1', method='pin', user=username)
resp = plistlib.loads(data)
pub_key, key_proof = self.srp.step2(resp['pk'], resp['salt'])
await self._sen... | Finish authentication process.
A username (generated by new_credentials) and the PIN code shown on
screen must be provided. |
def _get_section(self, name, create=True):
try:
return self.sections[name]
except KeyError:
if not create:
raise
section = Section(name)
self.sections[name] = section
return section | Retrieve a section by name. Create it on first access. |
def get_iso2_from_iso3(cls, iso3, use_live=True, exception=None):
countriesdata = cls.countriesdata(use_live=use_live)
iso2 = countriesdata['iso2iso3'].get(iso3.upper())
if iso2 is not None:
return iso2
if exception is not None:
raise exception
return None | Get ISO2 from ISO3 code
Args:
iso3 (str): ISO3 code for which to get ISO2 code
use_live (bool): Try to get use latest data from web rather than file in package. Defaults to True.
exception (Optional[ExceptionUpperBound]): An exception to raise if country not found. Defaults ... |
def get_service_id_list() -> List[tuple]:
keys = DB.get_keys('states*')
services = []
for key in keys:
values = key.split(':')
if len(values) == 4:
services.append(':'.join(values[1:]))
return services | Return list of Services. |
def get_plural_name(cls):
if not hasattr(cls.Meta, 'plural_name'):
setattr(
cls.Meta,
'plural_name',
inflection.pluralize(cls.get_name())
)
return cls.Meta.plural_name | Get the serializer's plural name.
The plural name may be defined on the Meta class.
If the plural name is not defined,
the pluralized form of the name will be returned. |
def get_all_published_ships_basic(db_connection):
if not hasattr(get_all_published_ships_basic, '_results'):
sql = 'CALL get_all_published_ships_basic();'
results = execute_sql(sql, db_connection)
get_all_published_ships_basic._results = results
return get_all_published_ships_basic._resu... | Gets a list of all published ships and their basic information.
:return: Each result has a tuple of (typeID, typeName, groupID, groupName, categoryID, and categoryName).
:rtype: list |
def _resample_residuals(self, stars, epsf):
shape = (stars.n_good_stars, epsf.shape[0], epsf.shape[1])
star_imgs = np.zeros(shape)
for i, star in enumerate(stars.all_good_stars):
star_imgs[i, :, :] = self._resample_residual(star, epsf)
return star_imgs | Compute normalized residual images for all the input stars.
Parameters
----------
stars : `EPSFStars` object
The stars used to build the ePSF.
epsf : `EPSFModel` object
The ePSF model.
Returns
-------
star_imgs : 3D `~numpy.ndarray`
... |
def resource_create_ticket(self, token, id, scopes, **kwargs):
data = dict(resource_id=id, resource_scopes=scopes, **kwargs)
return self._realm.client.post(
self.well_known['permission_endpoint'],
data=self._dumps([data]),
headers=self.get_headers(token)
) | Create a ticket form permission to resource.
https://www.keycloak.org/docs/latest/authorization_services/index.html#_service_protection_permission_api_papi
:param str token: user access token
:param str id: resource id
:param list scopes: scopes access is wanted
:param dict cla... |
def prebuild_arch(self, arch):
path = self.get_build_dir(arch.arch)
if not exists(path):
info("creating {}".format(path))
shprint(sh.mkdir, '-p', path) | Make the build and target directories |
def do_propset(self, subcmd, opts, *args):
print "'svn %s' opts: %s" % (subcmd, opts)
print "'svn %s' args: %s" % (subcmd, args) | Set PROPNAME to PROPVAL on files, dirs, or revisions.
usage:
1. propset PROPNAME [PROPVAL | -F VALFILE] PATH...
2. propset PROPNAME --revprop -r REV [PROPVAL | -F VALFILE] [URL]
1. Creates a versioned, local propchange in working copy.
2. Creates an unversioned,... |
def delete(self, story, params={}, **options):
path = "/stories/%s" % (story)
return self.client.delete(path, params, **options) | Deletes a story. A user can only delete stories they have created. Returns an empty data record.
Parameters
----------
story : {Id} Globally unique identifier for the story. |
def _createMagConversionDict():
magnitude_conversion_filepath = resource_stream(__name__, 'data/magnitude_conversion.dat')
raw_table = np.loadtxt(magnitude_conversion_filepath, '|S5')
magDict = {}
for row in raw_table:
if sys.hexversion >= 0x03000000:
starClass = row[1].decode("utf-8... | loads magnitude_conversion.dat which is table A% 1995ApJS..101..117K |
def poll_events(self):
while self.started:
event_obj = None
event_name = None
try:
event_obj = self._sl4a.eventWait(50000)
except:
if self.started:
print("Exception happened during polling.")
... | Continuously polls all types of events from sl4a.
Events are sorted by name and store in separate queues.
If there are registered handlers, the handlers will be called with
corresponding event immediately upon event discovery, and the event
won't be stored. If exceptions occur, stop the... |
def pop(self):
if self._length == 0:
raise IndexError()
newvec = ImmutableVector()
newvec.tree = self.tree.remove(self._length-1)
newvec._length = self._length-1
return newvec | Return a new ImmutableVector with the last item removed. |
def dpotri(A, lower=1):
A = force_F_ordered(A)
R, info = lapack.dpotri(A, lower=lower)
symmetrify(R)
return R, info | Wrapper for lapack dpotri function
DPOTRI - compute the inverse of a real symmetric positive
definite matrix A using the Cholesky factorization A =
U**T*U or A = L*L**T computed by DPOTRF
:param A: Matrix A
:param lower: is matrix lower (true) or upper (false)
:returns: A inverse |
def required(cls):
columns = []
for column in cls.__table__.columns:
is_autoincrement = 'int' in str(column.type).lower() and column.autoincrement
if (not column.nullable and not column.primary_key) or (column.primary_key and not is_autoincrement):
columns.append(... | Return a list of all columns required by the database to create the
resource.
:param cls: The Model class to gather attributes from
:rtype: list |
def GetDataStream(self, name, case_sensitive=True):
if not isinstance(name, py2to3.STRING_TYPES):
raise ValueError('Name is not a string.')
name_lower = name.lower()
matching_data_stream = None
for data_stream in self._GetDataStreams():
if data_stream.name == name:
return data_stream... | Retrieves a data stream by name.
Args:
name (str): name of the data stream.
case_sensitive (Optional[bool]): True if the name is case sensitive.
Returns:
DataStream: a data stream or None if not available.
Raises:
ValueError: if the name is not string. |
async def scan(self):
atvs = await pyatv.scan_for_apple_tvs(
self.loop, timeout=self.args.scan_timeout, only_usable=False)
_print_found_apple_tvs(atvs)
return 0 | Scan for Apple TVs on the network. |
def getIRThreshold(self):
command = '$GO'
threshold = self.sendCommand(command)
if threshold[0] == 'NK':
return 0
else:
return float(threshold[2])/10 | Returns the IR temperature threshold in degrees Celcius, or 0 if no Threshold is set |
def removeReliableListener(self, listener):
self.store.query(_ReliableListener,
attributes.AND(_ReliableListener.processor == self,
_ReliableListener.listener == listener)).deleteFromStore()
self.store.query(BatchProcessingError,
... | Remove a previously added listener. |
def exp2(x, context=None):
return _apply_function_in_current_context(
BigFloat,
mpfr.mpfr_exp2,
(BigFloat._implicit_convert(x),),
context,
) | Return two raised to the power x. |
def __edge_weight(edge_id, dfs_data):
graph = dfs_data['graph']
edge_lookup = dfs_data['edge_lookup']
edge = graph.get_edge(edge_id)
u, v = edge['vertices']
d_u = D(u, dfs_data)
d_v = D(v, dfs_data)
lp_1 = L1(v, dfs_data)
d_lp_1 = D(lp_1, dfs_data)
if edge_lookup[edge_id] == 'backedg... | Calculates the edge weight used to sort edges. |
def make_summaries(self):
self.summary_df = save_summaries(self.frames, self.keys,
self.selected_summaries,
self.batch_dir, self.name)
logger.debug("made and saved summaries") | Make and save summary csv files,
each containing values from all cells |
async def fetch_api_description(
url: typing.Union[str, ParseResult, SplitResult],
insecure: bool = False):
url_describe = urljoin(_ensure_url_string(url), "describe/")
connector = aiohttp.TCPConnector(verify_ssl=(not insecure))
session = aiohttp.ClientSession(connector=connector)
async ... | Fetch the API description from the remote MAAS instance. |
def _connect(self, key, spec, via=None):
try:
method = getattr(self.router, spec['method'])
except AttributeError:
raise Error('unsupported method: %(transport)s' % spec)
context = method(via=via, unidirectional=True, **spec['kwargs'])
if via and spec.get('enable_... | Actual connect implementation. Arranges for the Mitogen connection to
be created and enqueues an asynchronous call to start the forked task
parent in the remote context.
:param key:
Deduplication key representing the connection configuration.
:param spec:
Connect... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.