code stringlengths 51 2.38k | docstring stringlengths 4 15.2k |
|---|---|
def _initialize_tables(self):
self.table_struct, self.idnt_struct_size = self._create_struct_table()
self.table_values, self.idnt_values_size = self._create_values_table() | Create tables for structure and values, word->vocabulary |
def decode_offset_response(cls, response):
return [
kafka.structs.OffsetResponsePayload(topic, partition, error, tuple(offsets))
for topic, partitions in response.topics
for partition, error, offsets in partitions
] | Decode OffsetResponse into OffsetResponsePayloads
Arguments:
response: OffsetResponse
Returns: list of OffsetResponsePayloads |
def aggregate_history(slugs, granularity="daily", since=None, with_data_table=False):
r = get_r()
slugs = list(slugs)
try:
if since and len(since) == 10:
since = datetime.strptime(since, "%Y-%m-%d")
elif since and len(since) == 19:
since = datetime.strptime(since, "%Y... | Template Tag to display history for multiple metrics.
* ``slug_list`` -- A list of slugs to display
* ``granularity`` -- the granularity: seconds, minutes, hourly,
daily, weekly, monthly, yearly
* ``since`` -- a datetime object or a string string matching one of the
following... |
def translate_month_abbr(
date_str,
source_lang=DEFAULT_DATE_LANG,
target_lang=DEFAULT_DATE_LANG):
month_num, month_abbr = get_month_from_date_str(date_str, source_lang)
with calendar.different_locale(LOCALES[target_lang]):
translated_abbr = calendar.month_abbr[month_num]
... | Translate the month abbreviation from one locale to another. |
def discretize(value, factor=100):
if not isinstance(value, Iterable):
return int(value * factor)
int_value = list(deepcopy(value))
for i in range(len(int_value)):
int_value[i] = int(int_value[i] * factor)
return int_value | Discretize the given value, pre-multiplying by the given factor |
def drain_to(self, list, max_size=-1):
def drain_result(f):
resp = f.result()
list.extend(resp)
return len(resp)
return self._encode_invoke(queue_drain_to_max_size_codec, max_size=max_size).continue_with(
drain_result) | Transfers all available items to the given `list`_ and removes these items from this queue. If a max_size is
specified, it transfers at most the given number of items. In case of a failure, an item can exist in both
collections or none of them.
This operation may be more efficient than polling ... |
def get_limit(self, request):
if self.limit_query_param:
try:
return _positive_int(
get_query_param(request, self.limit_query_param),
strict=True,
cutoff=self.max_limit
)
except (KeyError, ValueEr... | Return limit parameter. |
def _reset_plain(self):
if self._text:
self._blocks.append(BlockText('\n'.join(self._text)))
self._text.clear() | Create a BlockText from the captured lines and clear _text. |
def validate(self):
super().validate()
nb_entities = len(self.entities)
if nb_entities != self.rows + self.columns:
raise self.error(
'Number of entities: %s != number of rows + '
'number of columns: %s+%s=%s' % (
nb_entities, self.... | Base validation + entities = rows + columns. |
def get_hosting_devices_for_agent(self, context):
cctxt = self.client.prepare()
return cctxt.call(context,
'get_hosting_devices_for_agent',
host=self.host) | Get a list of hosting devices assigned to this agent. |
def _one_or_more_stages_remain(self, deploymentId):
stages = __salt__['boto_apigateway.describe_api_stages'](restApiId=self.restApiId,
deploymentId=deploymentId,
**self._common_aws_a... | Helper function to find whether there are other stages still associated with a deployment |
def check_package_exists(package, lib_dir):
try:
req = pkg_resources.Requirement.parse(package)
except ValueError:
req = pkg_resources.Requirement.parse(urlparse(package).fragment)
if lib_dir is not None:
if any(dist in req for dist in
pkg_resources.find_distributions(... | Check if a package is installed globally or in lib_dir.
Returns True when the requirement is met.
Returns False when the package is not installed or doesn't meet req. |
def myGrades(year, candidateNumber, badFormat, length):
weights1 = [1, 1, 1, 1, 0.5, 0.5, 0.5, 0.5]
weights2 = [1, 1, 1, 1, 1, 1, 0.5, 0.5]
if year == 1:
myFinalResult = sum([int(badFormat[candidateNumber][2*(i + 1)])
* weights1[i] for i in range(length-1)]) / 6
elif... | returns final result of candidateNumber in year
Arguments:
year {int} -- the year candidateNumber is in
candidateNumber {str} -- the candidateNumber of candidateNumber
badFormat {dict} -- candNumber : [results for candidate]
length {int} -- length of each row in badFormat divided by... |
async def probe_message(self, _message, context):
client_id = context.user_data
await self.probe(client_id) | Handle a probe message.
See :meth:`AbstractDeviceAdapter.probe`. |
def page(request):
context = {}
page = getattr(request, "page", None)
if isinstance(page, Page):
context = {"request": request, "page": page, "_current_page": page}
page.set_helpers(context)
return context | Adds the current page to the template context and runs its
``set_helper`` method. This was previously part of
``PageMiddleware``, but moved to a context processor so that
we could assign these template context variables without
the middleware depending on Django's ``TemplateResponse``. |
def build_relation_predicate(relations: Strings) -> EdgePredicate:
if isinstance(relations, str):
@edge_predicate
def relation_predicate(edge_data: EdgeData) -> bool:
return edge_data[RELATION] == relations
elif isinstance(relations, Iterable):
relation_set = set(relations)
... | Build an edge predicate that passes for edges with the given relation. |
def _check_pub_data(self, pub_data, listen=True):
if pub_data == '':
raise EauthAuthenticationError(
'Failed to authenticate! This is most likely because this '
'user is not permitted to execute commands, but there is a '
'small possibility that a disk... | Common checks on the pub_data data structure returned from running pub |
def resolve_input_references(to_resolve, inputs_to_reference):
splitted = split_input_references(to_resolve)
result = []
for part in splitted:
if is_input_reference(part):
result.append(str(resolve_input_reference(part, inputs_to_reference)))
else:
result.append(part)... | Resolves input references given in the string to_resolve by using the inputs_to_reference.
See http://www.commonwl.org/user_guide/06-params/index.html for more information.
Example:
"$(inputs.my_file.nameroot).md" -> "filename.md"
:param to_resolve: The path to match
:param inputs_to_reference: I... |
def __update(self):
width, height = self.size
super(BaseWidget, self).__setattr__("width", width)
super(BaseWidget, self).__setattr__("height", height)
super(BaseWidget, self).__setattr__(self.anchor, self.pos) | This is called each time an attribute is asked, to be sure every params are updated, beceause of callbacks. |
def _process_remove_objects_batch(self, bucket_name, objects_batch):
content = xml_marshal_delete_objects(objects_batch)
headers = {
'Content-Md5': get_md5_base64digest(content),
'Content-Length': len(content)
}
query = {'delete': ''}
content_sha256_hex = ... | Requester and response parser for remove_objects |
def get_mor_by_name(si, obj_type, obj_name):
inventory = get_inventory(si)
container = inventory.viewManager.CreateContainerView(inventory.rootFolder, [obj_type], True)
for item in container.view:
if item.name == obj_name:
return item
return None | Get reference to an object of specified object type and name
si
ServiceInstance for the vSphere or ESXi server (see get_service_instance)
obj_type
Type of the object (vim.StoragePod, vim.Datastore, etc)
obj_name
Name of the object |
def create_columns(self):
reader = self._get_csv_reader()
headings = six.next(reader)
try:
examples = six.next(reader)
except StopIteration:
examples = []
found_fields = set()
for i, value in enumerate(headings):
if i >= 20:
... | For each column in file create a TransactionCsvImportColumn |
def body(self):
content = []
length = 0
for chunk in self:
content.append(chunk)
length += len(chunk)
if self.length_limit and length > self.length_limit:
self.close()
raise ContentLimitExceeded("Content length is more than %d "... | Response body.
:raises: :class:`ContentLimitExceeded`, :class:`ContentDecodingError` |
def fit(self, X, y):
if not isinstance(X, pd.DataFrame):
X = pd.DataFrame(X.copy())
if not isinstance(y, pd.Series):
y = pd.Series(y.copy())
relevance_table = calculate_relevance_table(
X, y, ml_task=self.ml_task, n_jobs=self.n_jobs,
... | Extract the information, which of the features are relevent using the given target.
For more information, please see the :func:`~tsfresh.festure_selection.festure_selector.check_fs_sig_bh`
function. All columns in the input data sample are treated as feature. The index of all
rows in X must be ... |
def get_disease_mappings(self, att_ind_start):
all_disease_ids = self.get_all_unique_diseases()
disease_enum = enumerate(all_disease_ids, start=att_ind_start)
disease_mappings = {}
for num, dis in disease_enum:
disease_mappings[dis] = num
return disease_mappings | Get a dictionary of enumerations for diseases.
:param int att_ind_start: Starting index for enumeration.
:return: Dictionary of disease, number pairs. |
def change_message_visibility(self, queue, receipt_handle,
visibility_timeout, callback=None):
params = {'ReceiptHandle' : receipt_handle,
'VisibilityTimeout' : visibility_timeout}
return self.get_status('ChangeMessageVisibility', params, queue.id, cal... | Extends the read lock timeout for the specified message from
the specified queue to the specified value.
:type queue: A :class:`boto.sqs.queue.Queue` object
:param queue: The Queue from which messages are read.
:type receipt_handle: str
:param queue: The receipt handle ... |
def _chk_docopt_exit(self, args, exp_letters):
if args is None:
args = sys.argv[1:]
keys_all = self.exp_keys.union(self.exp_elems)
if exp_letters:
keys_all |= exp_letters
unknown_args = self._chk_docunknown(args, keys_all)
if unknown_args:
rais... | Check if docopt exit was for an unknown argument. |
def has_option(self, option):
if len(self.options) == 0:
return False
for op in self.options:
if (self._sized_op and op[0] == option) or (op == option):
return True
return False | Return True if the option is included in this key.
Parameters
----------
option : str
The option.
Returns
-------
has : bool
True if the option can be found. Otherwise False will be returned. |
def register_project(self, path, ensure_uniqueness=False):
if ensure_uniqueness:
if self.get_project_nodes(path):
raise foundations.exceptions.ProgrammingError("{0} | '{1}' project is already registered!".format(
self.__class__.__name__, path))
LOGGER.debu... | Registers given path in the Model as a project.
:param path: Project path to register.
:type path: unicode
:param ensure_uniqueness: Ensure registrar uniqueness.
:type ensure_uniqueness: bool
:return: ProjectNode.
:rtype: ProjectNode |
def list_instances(self):
response = self.get_proto(path='/instances')
message = rest_pb2.ListInstancesResponse()
message.ParseFromString(response.content)
instances = getattr(message, 'instance')
return iter([Instance(instance) for instance in instances]) | Lists the instances.
Instances are returned in lexicographical order.
:rtype: ~collections.Iterable[.Instance] |
def get_count(self,name):
if name not in self.mlt_counter:
self.mlt_counter[name] = 1
c = 0
else:
c = self.mlt_counter[name]
self.mlt_counter[name] += 1
return c | get the latest counter for a certain parameter type.
Parameters
----------
name : str
the parameter type
Returns
-------
count : int
the latest count for a parameter type
Note
----
calling this function increments the cou... |
def n_frames_total(self, stride=1, skip=0):
r
if not IteratorState.is_uniform_stride(stride):
return len(stride)
return sum(self.trajectory_lengths(stride=stride, skip=skip)) | r"""Returns total number of frames.
Parameters
----------
stride : int
return value is the number of frames in trajectories when
running through them with a step size of `stride`.
skip : int, default=0
skip the first initial n frames per trajectory.
... |
def startsafter(self, other):
if self.is_valid_range(other):
if self.lower == other.lower:
return other.lower_inc or not self.lower_inc
elif self.lower_inf:
return False
elif other.lower_inf:
return True
else:
... | Test if this range starts after `other`. `other` may be either range or
scalar. This only takes the lower end of the ranges into consideration.
If the scalar or the lower end of the given range is greater than or
equal to this range's lower end, ``True`` is returned.
>>> intrange(1,... |
def list_files(dir_path, recursive=True):
for root, dirs, files in os.walk(dir_path):
file_list = [os.path.join(root, f) for f in files]
if recursive:
for dir in dirs:
dir = os.path.join(root, dir)
file_list.extend(list_files(dir, recursive=True))
... | Return a list of files in dir_path. |
def publish_scene_velocity(self, scene_id, velocity):
self.sequence_number += 1
self.publisher.send_multipart(msgs.MessageBuilder.scene_velocity(self.sequence_number, scene_id, velocity))
return self.sequence_number | publish a changed scene velovity |
def _new_java_array(pylist, java_class):
sc = SparkContext._active_spark_context
java_array = None
if len(pylist) > 0 and isinstance(pylist[0], list):
inner_array_length = 0
for i in xrange(len(pylist)):
inner_array_length = max(inner_array_length, len(pyl... | Create a Java array of given java_class type. Useful for
calling a method with a Scala Array from Python with Py4J.
If the param pylist is a 2D array, then a 2D java array will be returned.
The returned 2D java array is a square, non-jagged 2D array that is big
enough for all elements. T... |
def make_dbsource(**kwargs):
if 'spatialite' in connection.settings_dict.get('ENGINE'):
kwargs.setdefault('file', connection.settings_dict['NAME'])
return mapnik.SQLite(wkb_format='spatialite', **kwargs)
names = (('dbname', 'NAME'), ('user', 'USER'),
('password', 'PASSWORD'), ('host... | Returns a mapnik PostGIS or SQLite Datasource. |
def save(self, outfile, close_file=True, **kwargs):
if isinstance(outfile, text_type) or isinstance(outfile, binary_type):
fid = open(outfile, 'wb')
else:
fid = outfile
root = self.get_root()
html = root.render(**kwargs)
fid.write(html.encode('utf8'))
... | Saves an Element into a file.
Parameters
----------
outfile : str or file object
The file (or filename) where you want to output the html.
close_file : bool, default True
Whether the file has to be closed after write. |
def as_singular(result_key):
if result_key.endswith('ies'):
return re.sub('ies$', 'y', result_key)
elif result_key.endswith('uses'):
return re.sub("uses$", "us", result_key)
elif result_key.endswith('addresses'):
return result_key[:-2]
elif result_key.endswith('s'):
retur... | Given a result key, return in the singular form |
def frange(start, stop, step, digits_to_round=3):
while start < stop:
yield round(start, digits_to_round)
start += step | Works like range for doubles
:param start: starting value
:param stop: ending value
:param step: the increment_value
:param digits_to_round: the digits to which to round \
(makes floating-point numbers much easier to work with)
:return: generator |
def hasIP(self, ip):
for f in self.features:
if (f.prop.startswith("net_interface.") and
f.prop.endswith(".ip") and f.value == ip):
return True
return False | Return True if some system has this IP. |
def compute_convex_hull(feed: "Feed") -> Polygon:
m = sg.MultiPoint(feed.stops[["stop_lon", "stop_lat"]].values)
return m.convex_hull | Return a Shapely Polygon representing the convex hull formed by
the stops of the given Feed. |
def parse_collection(obj: dict) -> BioCCollection:
collection = BioCCollection()
collection.source = obj['source']
collection.date = obj['date']
collection.key = obj['key']
collection.infons = obj['infons']
for doc in obj['documents']:
collection.add_document(parse_doc(doc))
... | Deserialize a dict obj to a BioCCollection object |
def parse_colors(s, length=1):
if length and length > 1:
return parse_ctuple(s,length=length);
if re.match('^ *{} *$'.format(isrx_s), s):
return [s];
elif re.match('^ *{} *$'.format(rgbrx_s), s):
return [eval(s)];
else:
return parse_ctuple(s,length=length); | helper for parsing a string that can be either a matplotlib
color or be a tuple of colors. Returns a tuple of them either
way. |
def remove_population(self,pop):
iremove=None
for i in range(len(self.poplist)):
if self.modelnames[i]==self.poplist[i].model:
iremove=i
if iremove is not None:
self.modelnames.pop(i)
self.shortmodelnames.pop(i)
self.poplist.pop(i) | Removes population from PopulationSet |
def _normalize_xml_search_response(self, xml):
target = XMLSearchResult()
parser = ElementTree.XMLParser(target=target)
parser.feed(xml)
return parser.close() | Normalizes an XML search response so that PB and HTTP have the
same return value |
def _adjust_regs(self):
if not self.adjust_stack:
return
bp = self.state.arch.register_names[self.state.arch.bp_offset]
sp = self.state.arch.register_names[self.state.arch.sp_offset]
stack_shift = self.state.arch.initial_sp - self.real_stack_top
self.state.registers.s... | Adjust bp and sp w.r.t. stack difference between GDB session and angr.
This matches sp and bp registers, but there is a high risk of pointers inconsistencies. |
def refer(self, text):
data = self.reply(text)
data['refer_key'] = self['key']
return data | Refers current message and replys a new message
Args:
text(str): message content
Returns:
RTMMessage |
def endGroup(self):
if self._customFormat:
self._customFormat.endGroup()
else:
super(XSettings, self).endGroup() | Ends the current group of xml data. |
def GET_save_conditionvalues(self) -> None:
state.conditions[self._id] = state.conditions.get(self._id, {})
state.conditions[self._id][state.idx2] = state.hp.conditions | Save the |StateSequence| and |LogSequence| object values of the
current |HydPy| instance for the current simulation endpoint. |
def to_tex(self, text_size='large', table_width=5, clear_pages = False):
max_ex_scheme = 0
if self._rendered:
for (week, day, dynamic_ex) in self._yield_week_day_dynamic():
lengths = [len(s) for s in
self._rendered[week][day][dynamic_ex]['strings']]... | Write the program information to a .tex file, which can be
rendered to .pdf running pdflatex. The program can then be
printed and brought to the gym.
Parameters
----------
text_size
The tex text size, e.g. '\small', 'normalsize', 'large', 'Large'
or 'LARG... |
def patch(self, delta):
"Applies delta for local file to remote file via API."
return self.api.post('path/sync/patch', self.path, delta=delta) | Applies delta for local file to remote file via API. |
def run(self):
self.busy = True
for i in range(9):
self.counter += 1
time.sleep(0.5)
pass
self.counter += 1
self.busy = False
return | This method is run by a separated thread |
def _parse_size(self, size, has_time=False):
if has_time:
size = size or 4
else:
size = size or 10
if isinstance(size, str):
size = {'column': size}
if isinstance(size, dict):
if 'column' not in size:
raise ValueError("`size... | Parse size inputs |
def main():
trig_pin = 17
echo_pin = 27
hole_depth = 31.5
value = sensor.Measurement(trig_pin,
echo_pin,
temperature=68,
unit='imperial',
round_to=2
... | Calculate the depth of a liquid in inches using a HCSR04 sensor
and a Raspberry Pi |
def url_builder(self, endpoint, *, root=None, params=None, url_params=None):
if root is None:
root = self.ROOT
return ''.join([
root,
endpoint,
'?' + urlencode(url_params) if url_params else '',
]).format(**params or {}) | Create a URL for the specified endpoint.
Arguments:
endpoint (:py:class:`str`): The API endpoint to access.
root: (:py:class:`str`, optional): The root URL for the
service API.
params: (:py:class:`dict`, optional): The values for format
into the created URL... |
def future_check_sensor(self, name, update=None):
exist = False
yield self.until_data_synced()
if name in self._sensors_index:
exist = True
else:
if update or (update is None and self._update_on_lookup):
yield self.inspect_sensors(name)
... | Check if the sensor exists.
Used internally by future_get_sensor. This method is aware of
synchronisation in progress and if inspection of the server is allowed.
Parameters
----------
name : str
Name of the sensor to verify.
update : bool or None, optional
... |
def spawn(mode, func, *args, **kwargs):
if mode is None:
mode = 'threading'
elif mode not in spawn.modes:
raise ValueError('Invalid spawn mode: %s' % mode)
if mode == 'threading':
return spawn_thread(func, *args, **kwargs)
elif mode == 'gevent':
import gevent
impo... | Spawns a thread-like object which runs the given function concurrently.
Available modes:
- `threading`
- `greenlet`
- `eventlet` |
def makeLabel(self, value):
value, prefix = format_units(value, self.step,
system=self.unitSystem)
span, spanPrefix = format_units(self.span, self.step,
system=self.unitSystem)
if prefix:
prefix += " "
... | Create a label for the specified value.
Create a label string containing the value and its units (if any),
based on the values of self.step, self.span, and self.unitSystem. |
def map2matrix(data_map, layout):
r
layout = np.array(layout)
n_obj = np.prod(layout)
image_shape = (np.array(data_map.shape) // layout)[0]
data_matrix = []
for i in range(n_obj):
lower = (image_shape * (i // layout[1]),
image_shape * (i % layout[1]))
upper = (im... | r"""Map to Matrix
This method transforms a 2D map to a 2D matrix
Parameters
----------
data_map : np.ndarray
Input data map, 2D array
layout : tuple
2D layout of 2D images
Returns
-------
np.ndarray 2D matrix
Raises
------
ValueError
For invalid la... |
def strip_masked(fasta, min_len, print_masked):
for seq in parse_fasta(fasta):
nm, masked = parse_masked(seq, min_len)
nm = ['%s removed_masked >=%s' % (seq[0], min_len), ''.join(nm)]
yield [0, nm]
if print_masked is True:
for i, m in enumerate([i for i in masked if i != ... | remove masked regions from fasta file as long as
they are longer than min_len |
def configure_root_iam_credentials(self, access_key, secret_key, region=None, iam_endpoint=None, sts_endpoint=None,
max_retries=-1, mount_point=DEFAULT_MOUNT_POINT):
params = {
'access_key': access_key,
'secret_key': secret_key,
'region'... | Configure the root IAM credentials to communicate with AWS.
There are multiple ways to pass root IAM credentials to the Vault server, specified below with the highest
precedence first. If credentials already exist, this will overwrite them.
The official AWS SDK is used for sourcing credentials... |
def is_to_be_built_or_is_installed(self, shutit_module_obj):
shutit_global.shutit_global_object.yield_to_draw()
cfg = self.cfg
if cfg[shutit_module_obj.module_id]['shutit.core.module.build']:
return True
return self.is_installed(shutit_module_obj) | Returns true if this module is configured to be built, or if it is already installed. |
def get(self, filename):
params = {
"v": 'dreambox',
"kolejka": "false",
"nick": "",
"pass": "",
"napios": sys.platform,
"l": self.language.upper(),
"f": self.prepareHash(filename),
}
params['t'] = self.discombob... | returns subtitles as string |
def confirm_updated(value, check_fun, normalize_ret=False, wait=5):
for i in range(wait):
state = validate_enabled(check_fun()) if normalize_ret else check_fun()
if value in state:
return True
time.sleep(1)
return False | Wait up to ``wait`` seconds for a system parameter to be changed before
deciding it hasn't changed.
:param str value: The value indicating a successful change
:param function check_fun: The function whose return is compared with
``value``
:param bool normalize_ret: Whether to normalize the re... |
def parse_z(cls, offset):
assert len(offset) == 5, 'Invalid offset string format, must be "+HHMM"'
return timedelta(hours=int(offset[:3]), minutes=int(offset[0] + offset[3:])) | Parse %z offset into `timedelta` |
def get_endpoint_server_root(self):
parsed = urlparse(self._endpoint)
root = parsed.scheme + "://" + parsed.hostname
if parsed.port is not None:
root += ":" + unicode(parsed.port)
return root | Parses RemoteLRS object's endpoint and returns its root
:return: Root of the RemoteLRS object endpoint
:rtype: unicode |
def do_serialize(self, line):
opts = self.SERIALIZE_OPTS
if not self.current:
self._help_noontology()
return
line = line.split()
g = self.current['graph']
if not line:
line = ['turtle']
if line[0] not in opts:
self.help_seri... | Serialize an entity into an RDF flavour |
def get_user(self, username):
sql =
self._db_curs.execute(sql, (username, ))
user = self._db_curs.fetchone()
return user | Fetch the user from the database
The function will return None if the user is not found |
def write(self):
with open(storage.config_file, 'w') as cfg:
yaml.dump(self.as_dict(), cfg, default_flow_style=False)
storage.refresh() | write the current settings to the config file |
def remove_from_known_hosts(self, hosts, known_hosts=DEFAULT_KNOWN_HOSTS, dry=False):
for host in hosts:
logger.info('[%s] Removing the remote host SSH public key from [%s]...', host.hostname, known_hosts)
cmd = ['ssh-keygen', '-f', known_hosts, '-R', host.hostname]
logger.de... | Remove the remote host SSH public key to the `known_hosts` file.
:param hosts: the list of the remote `Host` objects.
:param known_hosts: the `known_hosts` file to store the SSH public keys.
:param dry: perform a dry run. |
def parse_eddystone_service_data(data):
if data['frame_type'] == EDDYSTONE_UID_FRAME:
return EddystoneUIDFrame(data['frame'])
elif data['frame_type'] == EDDYSTONE_TLM_FRAME:
if data['frame']['tlm_version'] == EDDYSTONE_TLM_ENCRYPTED:
return EddystoneEncryptedTLMFrame(data['frame']['d... | Parse Eddystone service data. |
def check_type_of_param_list_elements(param_list):
try:
assert isinstance(param_list[0], np.ndarray)
assert all([(x is None or isinstance(x, np.ndarray))
for x in param_list])
except AssertionError:
msg = "param_list[0] must be a numpy array."
msg_2 = "All oth... | Ensures that all elements of param_list are ndarrays or None. Raises a
helpful ValueError if otherwise. |
def _subtoken_id_to_subtoken_string(self, subtoken):
if 0 <= subtoken < self.vocab_size:
return self._all_subtoken_strings[subtoken]
return u"" | Converts a subtoken integer ID to a subtoken string. |
async def list(source):
result = []
async with streamcontext(source) as streamer:
async for item in streamer:
result.append(item)
yield result | Generate a single list from an asynchronous sequence. |
def _AsList(arg):
if (isinstance(arg, string_types) or
not isinstance(arg, collections.Iterable)):
return [arg]
else:
return list(arg) | Encapsulates an argument in a list, if it's not already iterable. |
def least_squares(Cui, X, Y, regularization, num_threads=0):
users, n_factors = X.shape
YtY = Y.T.dot(Y)
for u in range(users):
X[u] = user_factor(Y, YtY, Cui, u, regularization, n_factors) | For each user in Cui, calculate factors Xu for them
using least squares on Y.
Note: this is at least 10 times slower than the cython version included
here. |
def StartingAgeEnum(ctx):
return Enum(
ctx,
what=-2,
unset=-1,
dark=0,
feudal=1,
castle=2,
imperial=3,
postimperial=4,
dmpostimperial=6
) | Starting Age Enumeration. |
def show_floating_ip(kwargs=None, call=None):
if call != 'function':
log.error(
'The show_floating_ip function must be called with -f or --function.'
)
return False
if not kwargs:
kwargs = {}
if 'floating_ip' not in kwargs:
log.error('A floating IP is requ... | Show the details of a floating IP
.. versionadded:: 2016.3.0
CLI Examples:
.. code-block:: bash
salt-cloud -f show_floating_ip my-digitalocean-config floating_ip='45.55.96.47' |
def get_inheritors(cls):
subclasses = set()
work = [cls]
while work:
parent = work.pop()
for child in parent.__subclasses__():
if child not in subclasses:
subclasses.add(child)
work.append(child)
return subclasses | Get a set of all classes that inherit from the given class. |
def _parse_incval(incunit, incval):
try:
retn = [int(val) for val in incval.split(',')]
except ValueError:
return None
return retn[0] if len(retn) == 1 else retn | Parse a non-day increment value. Should be an integer or a comma-separated integer list. |
def options(self, context, module_options):
if not 'URL' in module_options:
context.log.error('URL option is required!')
exit(1)
self.url = module_options['URL'] | URL URL for the download cradle |
def getDate():
_ltime = _time.localtime(_time.time())
date_str = _time.strftime('%Y-%m-%dT%H:%M:%S',_ltime)
return date_str | Returns a formatted string with the current date. |
def CheckTaskReadyForMerge(self, task):
if self._storage_type != definitions.STORAGE_TYPE_SESSION:
raise IOError('Unsupported storage type.')
if not self._processed_task_storage_path:
raise IOError('Missing processed task storage path.')
processed_storage_file_path = self._GetProcessedStorageFil... | Checks if a task is ready for merging with this session storage.
If the task is ready to be merged, this method also sets the task's
storage file size.
Args:
task (Task): task.
Returns:
bool: True if the task is ready to be merged.
Raises:
IOError: if the storage type is not su... |
def find_span_linear(degree, knot_vector, num_ctrlpts, knot, **kwargs):
span = 0
while span < num_ctrlpts and knot_vector[span] <= knot:
span += 1
return span - 1 | Finds the span of a single knot over the knot vector using linear search.
Alternative implementation for the Algorithm A2.1 from The NURBS Book by Piegl & Tiller.
:param degree: degree, :math:`p`
:type degree: int
:param knot_vector: knot vector, :math:`U`
:type knot_vector: list, tuple
:param... |
def check_units_and_type(input, expected_units, num=None, is_scalar=False):
if hasattr(input, 'unit'):
if expected_units is None:
raise ValueError('Expecting dimensionless input')
elif input.unit != expected_units:
raise ValueError('Expecting input units of ' + str(expected_u... | Check whether variable has expected units and type.
If input does not have units and expected units is not None, then the
output will be assigned those units. If input has units that conflict
with expected units a ValueError will be raised.
Parameters
----------
input : array_like or float
... |
def linear_gradient(start_hex, finish_hex, n=10):
s = hex2rgb(start_hex)
f = hex2rgb(finish_hex)
gradient = [s]
for t in range(1, n):
curr_vector = [int(s[j] + (float(t)/(n-1))*(f[j]-s[j])) for j in range(3)]
gradient.append(curr_vector)
return [rgb2hex([c/255. for c in rgb]) for rgb... | Interpolates the color gradient between to hex colors |
def combine_recs(rec_list, key):
final_recs = {}
for rec in rec_list:
rec_key = rec[key]
if rec_key in final_recs:
for k, v in rec.iteritems():
if k in final_recs[rec_key] and final_recs[rec_key][k] != v:
raise Exception("Mis-match for key '%s'" % ... | Use a common key to combine a list of recs |
def Pc(x, y):
r
try:
term = exp(-x*(1. - y))
return (1. - term)/(1. - y*term)
except ZeroDivisionError:
return x/(1. + x) | r'''Basic helper calculator which accepts a transformed R1 and NTU1 as
inputs for a common term used in the calculation of the P-NTU method for
plate exchangers.
Returns a value which is normally used in other calculations before the
actual P1 is calculated. Nominally used in counterflow calcula... |
def get_bin_indices(self, values):
return tuple([self.get_axis_bin_index(values[ax_i], ax_i)
for ax_i in range(self.dimensions)]) | Returns index tuple in histogram of bin which contains value |
def replace_with(self, other):
self.after(other)
self.parent.pop(self._own_index)
return other | Replace this element with the given DOMElement. |
def parse_compound(compound_def, context=None):
compound_id = compound_def.get('id')
_check_id(compound_id, 'Compound')
mark = FileMark(context, None, None)
return CompoundEntry(compound_def, mark) | Parse a structured compound definition as obtained from a YAML file
Returns a CompoundEntry. |
def get_section_by_label(label,
include_instructor_not_on_time_schedule=True):
validate_section_label(label)
url = "{}/{}.json".format(course_res_url_prefix,
encode_section_label(label))
return get_section_by_url(url,
inclu... | Returns a uw_sws.models.Section object for
the passed section label. |
def _find_batch_containing_event(self, uuid):
if self.estore.key_exists(uuid):
return self.batchno
else:
for batchno in range(self.batchno - 1, -1, -1):
db = self._open_event_store(batchno)
with contextlib.closing(db):
if db.key... | Find the batch number that contains a certain event.
Parameters:
uuid -- the event uuid to search for.
returns -- a batch number, or None if not found. |
def _get_normalized_args(parser):
env = os.environ
if '_' in env and env['_'] != sys.argv[0] and len(sys.argv) >= 1 and " " in sys.argv[1]:
return parser.parse_args(shlex.split(sys.argv[1]) + sys.argv[2:])
else:
return parser.parse_args() | Return the parsed command line arguments.
Support the case when executed from a shebang, where all the
parameters come in sys.argv[1] in a single string separated
by spaces (in this case, the third parameter is what is being
executed) |
def get_labels(self, field):
return {c: self.cluster_meta.get(field, c)
for c in self.clustering.cluster_ids} | Return the labels of all clusters, for a given field. |
def _write_wrapped(self, line, sep=" ", indent="", width=78):
words = line.split(sep)
lines = []
line = ""
buf = []
while len(words):
buf.append(words.pop(0))
line = sep.join(buf)
if len(line) > width:
words.insert(0, buf.pop... | Word-wrap a line of RiveScript code for being written to a file.
:param str line: The original line of text to word-wrap.
:param str sep: The word separator.
:param str indent: The indentation to use (as a set of spaces).
:param int width: The character width to constrain each line to.
... |
def compute_dual_rmetric(self,Ynew=None):
usedY = self.Y if Ynew is None else Ynew
rieman_metric = RiemannMetric(usedY, self.laplacian_matrix)
return rieman_metric.get_dual_rmetric() | Helper function to calculate the |
def contains_exclusive(self, x, y):
left, bottom, right, top = self._aarect.lbrt()
return (left <= x < right) and (bottom < y <= top) | Return True if the given point is contained within the
bounding box, where the bottom and right boundaries are
considered exclusive. |
def get(cls, object_version, key):
return cls.query.filter_by(
version_id=as_object_version_id(object_version),
key=key,
).one_or_none() | Get the tag object. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.