code stringlengths 51 2.38k | docstring stringlengths 4 15.2k |
|---|---|
def add_to_document(self, parent):
arg = ET.SubElement(parent, "arg")
arg.set("name", self.name)
if self.title is not None:
ET.SubElement(arg, "title").text = self.title
if self.description is not None:
ET.SubElement(arg, "description").text = self.description
... | Adds an ``Argument`` object to this ElementTree document.
Adds an <arg> subelement to the parent element, typically <args>
and sets up its subelements with their respective text.
:param parent: An ``ET.Element`` to be the parent of a new <arg> subelement
:returns: An ``ET.Element`` obj... |
def root(self):
with self._mutex:
if self._parent:
return self._parent.root
else:
return self | The root node of the tree this node is in. |
def registration_backend(backend=None, namespace=None):
backend = backend or ORGS_REGISTRATION_BACKEND
class_module, class_name = backend.rsplit(".", 1)
mod = import_module(class_module)
return getattr(mod, class_name)(namespace=namespace) | Returns a specified registration backend
Args:
backend: dotted path to the registration backend class
namespace: URL namespace to use
Returns:
an instance of an RegistrationBackend |
def RunInstaller():
try:
os.makedirs(os.path.dirname(config.CONFIG["Installer.logfile"]))
except OSError:
pass
handler = logging.FileHandler(config.CONFIG["Installer.logfile"], mode="wb")
handler.setLevel(logging.DEBUG)
logging.getLogger().addHandler(handler)
config.CONFIG.Initialize(filename=flags.... | Run all registered installers.
Run all the current installers and then exit the process. |
def connection_ok():
try:
urlopen(Dataset.base_url, timeout=1)
return True
except HTTPError:
return True
except URLError:
return False | Check web connection.
Returns True if web connection is OK, False otherwise. |
def _get_values(self):
(gi, _), (ci, _), (si, _) = self._get_dims(self.hmap.last)
ndims = self.hmap.last.ndims
dims = self.hmap.last.kdims
dimensions = []
values = {}
for vidx, vtype in zip([gi, ci, si], self._dimensions):
if vidx < ndims:
dim ... | Get unique index value for each bar |
def sendSignal(self, p, member, signature=None, body=None,
path='/org/freedesktop/DBus',
interface='org.freedesktop.DBus'):
if not isinstance(body, (list, tuple)):
body = [body]
s = message.SignalMessage(path, member, interface,
... | Sends a signal to a specific connection
@type p: L{BusProtocol}
@param p: L{BusProtocol} instance to send a signal to
@type member: C{string}
@param member: Name of the signal to send
@type path: C{string}
@param path: Path of the object emitting the signal. Defaults t... |
def _pidgin_status(status, message):
try:
iface = _dbus_get_interface('im.pidgin.purple.PurpleService',
'/im/pidgin/purple/PurpleObject',
'im.pidgin.purple.PurpleInterface')
if iface:
code = PIDGIN_CODE_MAP[status]
... | Updates status and message for Pidgin IM application.
`status`
Status type.
`message`
Status message. |
def extract_message_info():
base_path = BASE_PACKAGE.replace('.', '/')
filename = os.path.join(base_path, 'ProtocolMessage.proto')
with open(filename, 'r') as file:
types_found = False
for line in file:
stripped = line.lstrip().rstrip()
if stripped == 'enum Type {':
... | Get information about all messages of interest. |
def check_usrmove(self, pkgs):
if 'filesystem' not in pkgs:
return os.path.islink('/bin') and os.path.islink('/sbin')
else:
filesys_version = pkgs['filesystem']['version']
return True if filesys_version[0] == '3' else False | Test whether the running system implements UsrMove.
If the 'filesystem' package is present, it will check that the
version is greater than 3. If the package is not present the
'/bin' and '/sbin' paths are checked and UsrMove is assumed
if both are symbolic links.
... |
def simultaneous_listen(self):
if self.server_con is not None:
self.server_con.s.close()
self.server_con = None
self.mappings = None
self.predictions = None
parts = self.sequential_connect()
if parts is None:
return 0
con, mapp... | This function is called by passive simultaneous nodes who
wish to establish themself as such. It sets up a connection
to the Rendezvous Server to monitor for new hole punching requests. |
def _set_object_view(self, session):
for obj_name in self._object_views:
if self._object_views[obj_name] == PLENARY:
try:
getattr(session, 'use_plenary_' + obj_name + '_view')()
except AttributeError:
pass
else:
... | Sets the underlying object views to match current view |
def uint32_to_uint8(cls, img):
return np.flipud(img.view(dtype=np.uint8).reshape(img.shape + (4,))) | Cast uint32 RGB image to 4 uint8 channels. |
async def get_endpoint_for_did(wallet_handle: int,
pool_handle: int,
did: str) -> (str, Optional[str]):
logger = logging.getLogger(__name__)
logger.debug("get_endpoint_for_did: >>> wallet_handle: %r, pool_handle: %r, did: %r",
wallet... | Returns endpoint information for the given DID.
:param wallet_handle: Wallet handle (created by open_wallet).
:param pool_handle: Pool handle (created by open_pool).
:param did: The DID to resolve endpoint.
:return: (endpoint, transport_vk) |
def upgrade(self, conn, skip_versions=()):
db_versions = self.get_db_versions(conn)
self.starting_version = max(db_versions)
to_skip = sorted(db_versions | set(skip_versions))
scripts = self.read_scripts(None, None, to_skip)
if not scripts:
return []
self.endi... | Upgrade the database from the current version to the maximum
version in the upgrade scripts.
:param conn: a DBAPI 2 connection
:param skip_versions: the versions to skip |
def tparse(instring, lenout=_default_len_out):
errmsg = stypes.stringToCharP(lenout)
lenout = ctypes.c_int(lenout)
instring = stypes.stringToCharP(instring)
sp2000 = ctypes.c_double()
libspice.tparse_c(instring, lenout, ctypes.byref(sp2000), errmsg)
return sp2000.value, stypes.toPythonString(err... | Parse a time string and return seconds past the J2000
epoch on a formal calendar.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/tparse_c.html
:param instring: Input time string, UTC.
:type instring: str
:param lenout: Available space in output error message string.
:type lenout: int
... |
def guess_mode(self, data):
if data.ndim == 2:
return "L"
elif data.shape[-1] == 3:
return "RGB"
elif data.shape[-1] == 4:
return "RGBA"
else:
raise ValueError(
"Un-supported shape for image conversion %s" % list(data.shape)... | Guess what type of image the np.array is representing |
def create_endpoint(service_name: str, *,
ipv4: OptStr = None,
ipv6: OptStr = None,
port: OptInt = None) -> Endpoint:
return Endpoint(service_name, ipv4, ipv6, port) | Factory function to create Endpoint object. |
def validate_card_issue_modes(issue_mode: int, cards: list) -> list:
supported_mask = 63
if not bool(issue_mode & supported_mask):
return []
for i in [1 << x for x in range(len(IssueMode))]:
if bool(i & issue_mode):
try:
parser_fn = cast(
Calla... | validate cards against deck_issue modes |
def update(self, attributes=None):
if attributes is None:
attributes = {}
headers = self.__class__.create_headers(attributes)
headers.update(self._update_headers())
result = self._client._put(
self._update_url(),
self.__class__.create_attributes(attrib... | Updates the resource with attributes. |
def compat_py2_py3():
if (sys.version_info > (3, 0)):
def iteritems(dictionary):
return dictionary.items()
def itervalues(dictionary):
return dictionary.values()
else:
def iteritems(dictionary):
return dictionary.iteritems()
def itervalues(dict... | For Python 2, 3 compatibility. |
def read_meminfo():
data = {}
with open("/proc/meminfo", "rb") as meminfo_file:
for row in meminfo_file:
fields = row.split()
data[fields[0].decode("ascii")[:-1]] = int(fields[1]) * 1024
return data | Returns system memory usage information.
:returns: The system memory usage.
:rtype: dict |
def cookie_to_state(cookie_str, name, encryption_key):
try:
cookie = SimpleCookie(cookie_str)
state = State(cookie[name].value, encryption_key)
except KeyError as e:
msg_tmpl = 'No cookie named {name} in {data}'
msg = msg_tmpl.format(name=name, data=cookie_str)
logger.exc... | Loads a state from a cookie
:type cookie_str: str
:type name: str
:type encryption_key: str
:rtype: satosa.state.State
:param cookie_str: string representation of cookie/s
:param name: Name identifier of the cookie
:param encryption_key: Key to encrypt the state information
:return: A ... |
def register_archive_format(name, function, extra_args=None, description=''):
if extra_args is None:
extra_args = []
if not isinstance(function, collections.Callable):
raise TypeError('The %s object is not callable' % function)
if not isinstance(extra_args, (tuple, list)):
raise Type... | Registers an archive format.
name is the name of the format. function is the callable that will be
used to create archives. If provided, extra_args is a sequence of
(name, value) tuples that will be passed as arguments to the callable.
description can be provided to describe the format, and will be ret... |
def gen_sites(path):
" Seek sites by path. "
for root, _, _ in walklevel(path, 2):
try:
yield Site(root)
except AssertionError:
continue | Seek sites by path. |
def dictionize(fields: Sequence, records: Sequence) -> Generator:
return (dict(zip(fields, rec)) for rec in records) | Create dictionaries mapping fields to record data. |
def rate(self, currency):
if not self._backend:
raise ExchangeBackendNotInstalled()
return self._backend.rate(currency) | Return quotation between the base and another currency |
def subjects(self):
subj = [i["subject_id"] for i in self._cache.find()]
return list(set(subj)) | Return identifiers for all the subjects that are in the cache.
:return: list of subject identifiers |
def delete_auto_scaling_group(self, name, force_delete=False):
if(force_delete):
params = {'AutoScalingGroupName': name, 'ForceDelete': 'true'}
else:
params = {'AutoScalingGroupName': name}
return self.get_object('DeleteAutoScalingGroup', params, Request) | Deletes the specified auto scaling group if the group has no instances
and no scaling activities in progress. |
def set_size(self, size):
buffer_size = self._calculate_zoom_buffer_size(size, self._zoom_level)
self._size = size
self._initialize_buffers(buffer_size) | Set the size of the map in pixels
This is an expensive operation, do only when absolutely needed.
:param size: (width, height) pixel size of camera/view of the group |
def cleanup_tail(options):
if options.kwargs['omode'] == "csv":
options.kwargs['fd'].write("\n")
elif options.kwargs['omode'] == "xml":
options.kwargs['fd'].write("\n</results>\n")
else:
options.kwargs['fd'].write("\n]\n") | cleanup the tail of a recovery |
def get_profile(session):
try:
profile = session.get(PROFILE_URL).json()
if 'errorCode' in profile and profile['errorCode'] == '403':
raise MoparError("not logged in")
return profile
except JSONDecodeError:
raise MoparError("not logged in") | Get complete profile. |
async def hset(self, name, key, value):
return await self.execute_command('HSET', name, key, value) | Set ``key`` to ``value`` within hash ``name``
Returns 1 if HSET created a new field, otherwise 0 |
def add_module_plugin_filters(self, module_plugin_filters):
module_plugin_filters = util.return_list(module_plugin_filters)
self.module_plugin_filters.extend(module_plugin_filters) | Adds `module_plugin_filters` to the internal module filters.
May be a single object or an iterable.
Every module filters must be a callable and take in
a list of plugins and their associated names. |
def normalize_arxiv_category(category):
category = _NEW_CATEGORIES.get(category.lower(), category)
for valid_category in valid_arxiv_categories():
if (category.lower() == valid_category.lower() or
category.lower().replace('-', '.') == valid_category.lower()):
return valid_cat... | Normalize arXiv category to be schema compliant.
This properly capitalizes the category and replaces the dash by a dot if
needed. If the category is obsolete, it also gets converted it to its
current equivalent.
Example:
>>> from inspire_schemas.utils import normalize_arxiv_category
>>... |
def kitchen_delete(backend, kitchen):
click.secho('%s - Deleting kitchen %s' % (get_datetime(), kitchen), fg='green')
master = 'master'
if kitchen.lower() != master.lower():
check_and_print(DKCloudCommandRunner.delete_kitchen(backend.dki, kitchen))
else:
raise click.ClickException('Canno... | Provide the name of the kitchen to delete |
def verify(self):
for row in range(self.nrows()):
result = self.verify_row(row)
if result != 0:
return result
return 0 | Checks all parameters for invalidating conditions
:returns: str -- message if error, 0 otherwise |
def default_value(self):
if self.name in tsdb_coded_attributes:
return tsdb_coded_attributes[self.name]
elif self.datatype == ':integer':
return -1
else:
return '' | Get the default value of the field. |
def init_chain(self):
if not self._hasinit:
self._hasinit = True
self._devices = []
self.jtag_enable()
while True:
idcode = self.rw_dr(bitcount=32, read=True,
lastbit=False)()
if idcode in NULL_ID... | Autodetect the devices attached to the Controller, and initialize a JTAGDevice for each.
This is a required call before device specific Primitives can
be used. |
def genes_with_peak(self, peaks, transform_func=None, split=False,
intersect_kwargs=None, id_attribute='ID', *args,
**kwargs):
def _transform_func(x):
result = transform_func(x)
if isinstance(result, pybedtools.Interval):
re... | Returns a boolean index of genes that have a peak nearby.
Parameters
----------
peaks : string or pybedtools.BedTool
If string, then assume it's a filename to a BED/GFF/GTF file of
intervals; otherwise use the pybedtools.BedTool object directly.
transform_func :... |
def _get_state():
try:
return pyconnman.ConnManager().get_property('State')
except KeyError:
return 'offline'
except dbus.DBusException as exc:
raise salt.exceptions.CommandExecutionError('Connman daemon error: {0}'.format(exc)) | Returns the state of connman |
def remove_tag(self, task, params={}, **options):
path = "/tasks/%s/removeTag" % (task)
return self.client.post(path, params, **options) | Removes a tag from the task. Returns an empty data block.
Parameters
----------
task : {Id} The task to remove a tag from.
[data] : {Object} Data for the request
- tag : {Id} The tag to remove from the task. |
def set_number(self, key, value):
storage = self.storage
if not isinstance(value, int):
logger.error("set_number: Value must be an integer")
return
try:
lock.acquire()
storage[key] = value
finally:
self.storage._p_changed = True... | set a key's value |
def on_load(target: "EncryptableMixin", context):
decrypt, plaintext = decrypt_instance(target)
if decrypt:
target.plaintext = plaintext | Intercept SQLAlchemy's instance load event. |
def removeCallback(cls, eventType, func, record=None):
callbacks = cls.callbacks()
callbacks.setdefault(eventType, [])
for i in xrange(len(callbacks[eventType])):
my_func, my_record, _ = callbacks[eventType][i]
if func == my_func and record == my_record:
d... | Removes a callback from the model's event callbacks.
:param eventType: <str>
:param func: <callable> |
def describe_api_stages(restApiId, deploymentId, region=None, key=None, keyid=None, profile=None):
try:
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
stages = conn.get_stages(restApiId=restApiId, deploymentId=deploymentId)
return {'stages': [_convert_datetime_str(sta... | Get all API stages for a given apiID and deploymentID
CLI Example:
.. code-block:: bash
salt myminion boto_apigateway.describe_api_stages restApiId deploymentId |
def log_parameter_and_gradient_statistics(self,
model: Model,
batch_grad_norm: float) -> None:
if self._should_log_parameter_statistics:
for name, param in model.named_parameters():
self.add_t... | Send the mean and std of all parameters and gradients to tensorboard, as well
as logging the average gradient norm. |
def has_isotropic_cells(self):
return self.is_uniform and np.allclose(self.cell_sides[:-1],
self.cell_sides[1:]) | ``True`` if `grid` is uniform and `cell_sides` are all equal.
Always ``True`` for 1D partitions.
Examples
--------
>>> part = uniform_partition([0, -1], [1, 1], (5, 10))
>>> part.has_isotropic_cells
True
>>> part = uniform_partition([0, -1], [1, 1], (5, 5))
... |
def _set_proxy_filter(warningstuple):
if len(warningstuple) > 5:
key = len(_proxy_map)+1
_proxy_map[key] = warningstuple
return ('always', re_matchall, ProxyWarning, re_matchall, key)
else:
return warningstuple | set up a proxy that store too long warnings in a separate map |
def matches_pattern(self, other):
if hasattr(other, 'messageType'):
messageTypeIsEqual = False
if self.messageType is None or other.messageType is None:
messageTypeIsEqual = True
else:
messageTypeIsEqual = (self.messageType == other.messageType... | Test if current message match a patterns or template. |
def Execute(self, *params, **kw):
fp = self.__expandparamstodict(params, kw)
return self._get_subfolder('execute/', GPExecutionResult, fp) | Synchronously execute the specified GP task. Parameters are passed
in either in order or as keywords. |
def add_bond(self, name, ifaces, bond_mode=None, lacp=None):
assert len(ifaces) >= 2
options = ''
if bond_mode:
options += 'bond_mode=%(bond_mode)s' % locals()
if lacp:
options += 'lacp=%(lacp)s' % locals()
command_add = ovs_vsctl.VSCtlCommand(
... | Creates a bonded port.
:param name: Port name to be created
:param ifaces: List of interfaces containing at least 2 interfaces
:param bond_mode: Bonding mode (active-backup, balance-tcp
or balance-slb)
:param lacp: LACP mode (active, passive or off) |
def _build_install_args(options):
install_args = []
if options.user_install:
if sys.version_info < (2, 6):
log.warn('--user requires Python 2.6 or later')
raise SystemExit(1)
install_args.append('--user')
return install_args | Build the arguments to 'python setup.py install' on the setuptools package |
def delete_content(self, max_chars=100):
def delete_content_element():
chars_deleted = 0
while len(self.get_attribute('value')) > 0 and chars_deleted < max_chars:
self.click()
self.send_keys(Keys.HOME)
self.send_keys(Keys.DELETE)
... | Deletes content in the input field by repeatedly typing HOME, then DELETE
@rtype: WebElementWrapper
@return: Returns itself |
def async_from_options(options):
_type = options.pop('_type', 'furious.async.Async')
_type = path_to_reference(_type)
return _type.from_dict(options) | Deserialize an Async or Async subclass from an options dict. |
def chunks(iterable, size=100):
it = iter(iterable)
size -= 1
for head in it:
yield itertools.chain([head], itertools.islice(it, size)) | Turns the given iterable into chunks of the specified size,
which is 100 by default since that's what Telegram uses the most. |
def write(self, p_todos):
todofile = codecs.open(self.path, 'w', encoding="utf-8")
if p_todos is list:
for todo in p_todos:
todofile.write(str(todo))
else:
todofile.write(p_todos)
todofile.write("\n")
todofile.close() | Writes all the todo items to the todo.txt file.
p_todos can be a list of todo items, or a string that is just written
to the file. |
def createSuperimposedSensorySDRs(sequenceSensations, objectSensations):
assert len(sequenceSensations) == len(objectSensations)
superimposedSensations = []
for i, objectSensation in enumerate(objectSensations):
newSensation = {
0: (objectSensation[0][0],
sequenceSensations[i][0][1].union(obje... | Given two lists of sensations, create a new list where the sensory SDRs are
union of the individual sensory SDRs. Keep the location SDRs from the object.
A list of sensations has the following format:
[
{
0: (set([1, 5, 10]), set([6, 12, 52]), # location, feature for CC0
},
{
0: (set([5,... |
def regions():
return [RDSRegionInfo(name='us-east-1',
endpoint='rds.us-east-1.amazonaws.com'),
RDSRegionInfo(name='eu-west-1',
endpoint='rds.eu-west-1.amazonaws.com'),
RDSRegionInfo(name='us-west-1',
endpoint='rds... | Get all available regions for the RDS service.
:rtype: list
:return: A list of :class:`boto.rds.regioninfo.RDSRegionInfo` |
def render(self, namespace):
return self._text.format_map(namespace.dictionary) \
if self._need_format else self._text | Render template lines.
Note: we only need to parse the namespace if we used variables in
this part of the template. |
def isoformat(self):
text = [self.strftime('%Y-%m-%dT%H:%M:%S'), ]
if self.tzinfo:
text.append(self.tzinfo.as_timezone())
else:
text.append('+00:00')
return ''.join(text) | Generate an ISO 8601 formatted time stamp.
Returns:
str: `ISO 8601`_ formatted time stamp
.. _ISO 8601: http://www.cl.cam.ac.uk/~mgk25/iso-time.html |
def delete_room(room, reason=''):
if room.custom_server:
return
def _delete_room(xmpp):
muc = xmpp.plugin['xep_0045']
muc.destroy(room.jid, reason=reason)
current_plugin.logger.info('Deleting room %s', room.jid)
_execute_xmpp(_delete_room)
delete_logs(room) | Deletes a MUC room from the XMPP server. |
def get_files (dirname):
for entry in os.listdir(dirname):
fullentry = os.path.join(dirname, entry)
if os.path.islink(fullentry):
continue
if os.path.isfile(fullentry):
yield entry
elif os.path.isdir(fullentry):
yield entry+"/" | Get iterator of entries in directory. Only allows regular files
and directories, no symlinks. |
def _getLayer(self, name, **kwargs):
for glyph in self.layers:
if glyph.layer.name == name:
return glyph
raise ValueError("No layer named '%s' in glyph '%s'."
% (name, self.name)) | name will be a string, but there may not be a
layer with a name matching the string. If not,
a ``ValueError`` must be raised.
Subclasses may override this method. |
def _checkResponseNumberOfRegisters(payload, numberOfRegisters):
_checkString(payload, minlength=4, description='payload')
_checkInt(numberOfRegisters, minvalue=1, maxvalue=0xFFFF, description='numberOfRegisters')
BYTERANGE_FOR_NUMBER_OF_REGISTERS = slice(2, 4)
bytesForNumberOfRegisters = payload[BYTERA... | Check that the number of written registers as given in the response is correct.
The bytes 2 and 3 (zero based counting) in the payload holds the value.
Args:
* payload (string): The payload
* numberOfRegisters (int): Number of registers that have been written
Raises:
TypeError, Va... |
def fetch(url, dest, force=False):
cached = True
if force or not os.path.exists(dest):
cached = False
r = requests.get(url, stream=True)
if r.status_code == 200:
with open(dest, 'wb') as f:
for chunk in r.iter_content(1024):
f.write(chunk)
... | Retrieve data from an url and store it into dest.
Parameters
----------
url: str
Link to the remote data
dest: str
Path where the file must be stored
force: bool (default=False)
Overwrite if the file exists
Returns
-------
cached: bool
True if the file a... |
def on_connection_open(self, connection):
LOGGER.debug('Connection opened')
connection.add_on_connection_blocked_callback(
self.on_connection_blocked)
connection.add_on_connection_unblocked_callback(
self.on_connection_unblocked)
connection.add_backpressure_callba... | This method is called by pika once the connection to RabbitMQ has
been established.
:type connection: pika.TornadoConnection |
def _call(self, x):
out = x.asarray().ravel()[self._indices_flat]
if self.variant == 'point_eval':
weights = 1.0
elif self.variant == 'integrate':
weights = getattr(self.domain, 'cell_volume', 1.0)
else:
raise RuntimeError('bad variant {!r}'.format(sel... | Return values at indices, possibly weighted. |
def _next(self, **kwargs):
spec = self._pagination_default_spec(kwargs)
spec.update(kwargs)
query = queries.build_query(spec)
query = queries.where_after_entry(query, self._record)
for record in query.order_by(model.Entry.local_date,
model.Ent... | Get the next item in any particular category |
async def _connect(self, hostname, port, reconnect=False, channels=[],
encoding=protocol.DEFAULT_ENCODING, source_address=None):
if not reconnect or not self.connection:
self._autojoin_channels = channels
self.connection = connection.Connection(hostname, port, sour... | Connect to IRC host. |
def add_patchs_to_build_without_pkg_config(self, lib_dir, include_dir):
additional_patches = [
{
'src': r"pkgconfig\('--libs-only-L'\)",
'dest': "['{0}']".format(lib_dir),
},
{
'src': r"pkgconfig\('--libs(-only-l)?'\)",
... | Add patches to remove pkg-config command and rpm.pc part.
Replace with given library_path: lib_dir and include_path: include_dir
without rpm.pc file. |
def _join_results(self, results, coarse, join):
rval = OrderedDict()
i_keys = set()
for res in results:
i_keys.update( res.keys() )
for i_key in sorted(i_keys):
if coarse:
rval[i_key] = join( [res.get(i_key) for res in results] )
else:
rval[i_key] = OrderedDict()
... | Join a list of results. Supports both get and series. |
def apply_groups(cls, obj, options=None, backend=None, clone=True, **kwargs):
if isinstance(options, basestring):
from ..util.parser import OptsSpec
try:
options = OptsSpec.parse(options)
except SyntaxError:
options = OptsSpec.parse(
... | Applies nested options definition grouped by type.
Applies options on an object or nested group of objects,
returning a new object with the options applied. This method
accepts the separate option namespaces explicitly (i.e 'plot',
'style' and 'norm').
If the options are to be ... |
def flags(flags):
names = sorted(
descr for key, descr in OpCodeDebug.STREAM_CONSTANT.items() if key & flags
)
return ", ".join(names) | Returns the names of the class description flags found in the given
integer
:param flags: A class description flag entry
:return: The flags names as a single string |
def log_warn(message, args):
get_logger(DEFAULT_LOGGER, log_creation=False).log(logging.WARNING, message, *args) | Logs a warning message using the default logger. |
def delete_database(client, db_name, username=None, password=None):
(username, password) = get_user_creds(username, password)
sys_db = client.db("_system", username=username, password=password)
try:
return sys_db.delete_database(db_name)
except Exception:
log.warn("No arango database {db... | Delete Arangodb database |
def addCmdClass(self, ctor, **opts):
item = ctor(self, **opts)
name = item.getCmdName()
self.cmds[name] = item | Add a Cmd subclass to this cli. |
def to_python(value, seen=None):
seen = seen or set()
if isinstance(value, framework.TupleLike):
if value.ident in seen:
raise RecursionException('to_python: infinite recursion while evaluating %r' % value)
new_seen = seen.union([value.ident])
return {k: to_python(value[k], seen=new_seen) for k in... | Reify values to their Python equivalents.
Does recursion detection, failing when that happens. |
def rvs(df, gamma, n):
if type(n) == list:
u = np.random.uniform(size=n[0]*n[1])
result = Skewt.ppf(q=u, df=df, gamma=gamma)
result = np.split(result,n[0])
return np.array(result)
else:
u = np.random.uniform(size=n)
if isinstance(df... | Generates random variables from a Skew t distribution
Parameters
----------
df : float
degrees of freedom parameter
gamma : float
skewness parameter
n : int or list
Number of simulations to perform; if list input, produces array |
async def unload_by_path(self, path):
p, module = findModule(path, False)
if module is None:
raise ModuleLoadException('Cannot find module: ' + repr(path))
return await self.unloadmodule(module) | Unload a module by full path. Dependencies are automatically unloaded if they are marked to be
services. |
def _parse_text(self, element_name, namespace=''):
try:
text = self._channel.find('.//' + namespace + element_name).text
except AttributeError:
raise Exception(
'Element, {0} not found in RSS feed'.format(element_name)
)
return text | Returns the text, as a string, of the specified element in the specified
namespace of the RSS feed.
Takes element_name and namespace as strings. |
def ensure_namespace(self, name):
if name not in self.namespaces:
self.namespaces[name] = ApiNamespace(name)
return self.namespaces[name] | Only creates a namespace if it hasn't yet been defined.
:param str name: Name of the namespace.
:return ApiNamespace: |
def reorder_distance(p_atoms, q_atoms, p_coord, q_coord):
unique_atoms = np.unique(p_atoms)
view_reorder = np.zeros(q_atoms.shape, dtype=int)
for atom in unique_atoms:
p_atom_idx, = np.where(p_atoms == atom)
q_atom_idx, = np.where(q_atoms == atom)
A_coord = p_coord[p_atom_idx]
... | Re-orders the input atom list and xyz coordinates by atom type and then by
distance of each atom from the centroid.
Parameters
----------
atoms : array
(N,1) matrix, where N is points holding the atoms' names
coord : array
(N,D) matrix, where N is points and D is dimension
Retu... |
def by_phone(self, phone, cc=None):
header, content = self._http_request(self.BASE_URL, phone=phone, cc=cc)
return json.loads(content) | Perform a Yelp Phone API Search based on phone number given.
Args:
phone - Phone number to search by
cc - ISO 3166-1 alpha-2 country code. (Optional) |
def reload(self):
try:
data = self._api.get(self.href, append_base=False).json()
resource = File(api=self._api, **data)
except Exception:
try:
data = self._api.get(
self._URL['get'].format(id=self.id)).json()
resourc... | Refreshes the file with the data from the server. |
def save(self, path, group=None):
ext = _os.path.splitext(path)[1]
if ext == '.npy':
_numpy.save(path, self.numpy())
elif ext == '.txt':
if self.kind == 'real':
_numpy.savetxt(path, self.numpy())
elif self.kind == 'complex':
out... | Save array to a Numpy .npy, hdf, or text file. When saving a complex array as
text, the real and imaginary parts are saved as the first and second
column respectively. When using hdf format, the data is stored
as a single vector, along with relevant attributes.
Parameters
------... |
def missed_statements(self, filename):
el = self._get_class_element_by_filename(filename)
lines = el.xpath('./lines/line[@hits=0]')
return [int(l.attrib['number']) for l in lines] | Return a list of uncovered line numbers for each of the missed
statements found for the file `filename`. |
def identical(self, a, b):
return self._identical(self.convert(a), self.convert(b)) | This should return whether `a` is identical to `b`. Of course, this isn't always clear. True should mean that it
is definitely identical. False eans that, conservatively, it might not be.
:param a: an AST
:param b: another AST |
def _get_rev(self, fpath):
rev = None
try:
cmd = ["git", "log", "-n1", "--pretty=format:\"%h\"", fpath]
rev = Popen(cmd, stdout=PIPE, stderr=PIPE).communicate()[0]
except:
pass
if not rev:
try:
cmd = ["svn", "info", fpath]
... | Get an SCM version number. Try svn and git. |
def get_path(self, path, query=None):
return self.get(self.url_path(path), query) | Make a GET request, optionally including a query, to a relative path.
The path of the request includes a path on top of the base URL
assigned to the endpoint.
Parameters
----------
path : str
The path to request, relative to the endpoint
query : DataQuery, o... |
def data(self, data, part=False, dataset=''):
links = self.parser(self.scanner(data, part), part, dataset)
self.storage.add_links(links) | Parse data and update links.
Parameters
----------
data
Data to parse.
part : `bool`, optional
True if data is partial (default: `False`).
dataset : `str`, optional
Dataset key prefix (default: ''). |
def get_prebuilt_targets(build_context):
logger.info('Scanning for cached base images')
contained_deps = set()
required_deps = set()
cached_descendants = CachedDescendants(build_context.target_graph)
for target_name, target in build_context.targets.items():
if 'image_caching_behavior' not in... | Return set of target names that are contained within cached base images
These targets may be considered "pre-built", and skipped during build. |
def runWizard( self ):
plugin = self.currentPlugin()
if ( plugin and plugin.runWizard(self) ):
self.accept() | Runs the current wizard. |
def validate_session(self, client, session):
if session:
if session._client is not client:
raise InvalidOperation(
'Can only use session with the MongoClient that'
' started it')
if session._authset != self.authset:
... | Validate this session before use with client.
Raises error if this session is logged in as a different user or
the client is not the one that created the session. |
def _amplitude_bounds(counts, bkg, model):
if isinstance(counts, list):
counts = np.concatenate([t.flat for t in counts])
bkg = np.concatenate([t.flat for t in bkg])
model = np.concatenate([t.flat for t in model])
s_model = np.sum(model)
s_counts = np.sum(counts)
sn = bkg / model... | Compute bounds for the root of `_f_cash_root_cython`.
Parameters
----------
counts : `~numpy.ndarray`
Count map.
bkg : `~numpy.ndarray`
Background map.
model : `~numpy.ndarray`
Source template (multiplied with exposure). |
def backward(self):
if not self.filt:
self.forward()
self.smth = [self.filt[-1]]
log_trans = np.log(self.hmm.trans_mat)
ctg = np.zeros(self.hmm.dim)
for filt, next_ft in reversed(list(zip(self.filt[:-1],
self.logft[1:]))... | Backward recursion.
Upon completion, the following list of length T is available:
* smth: marginal smoothing probabilities
Note
----
Performs the forward step in case it has not been performed before. |
def returner(ret):
setup = _get_options(ret)
log.debug('highstate setup %s', setup)
report, failed = _generate_report(ret, setup)
if report:
_produce_output(report, failed, setup) | Check highstate return information and possibly fire off an email
or save a file. |
def _Dhcpcd(self, interfaces, logger):
for interface in interfaces:
dhcpcd = ['/sbin/dhcpcd']
try:
subprocess.check_call(dhcpcd + ['-x', interface])
except subprocess.CalledProcessError:
logger.info('Dhcpcd not yet running for interface %s.', interface)
try:
subproces... | Use dhcpcd to activate the interfaces.
Args:
interfaces: list of string, the output device names to enable.
logger: logger object, used to write to SysLog and serial port. |
def _decode_datetime(obj):
if '__datetime__' in obj:
obj = datetime.datetime.strptime(obj['as_str'].decode(), "%Y%m%dT%H:%M:%S.%f")
return obj | Decode a msgpack'ed datetime. |
def _upd_unused(self, what):
builder = getattr(self, '_{}_builder'.format(what))
updtrig = getattr(self, '_trigger_upd_unused_{}s'.format(what))
builder.unbind(decks=updtrig)
funcs = OrderedDict()
cards = list(self._action_builder.decks[1])
cards.reverse()
for car... | Make sure to have exactly one copy of every valid function in the
"unused" pile on the right.
Doesn't read from the database.
:param what: a string, 'trigger', 'prereq', or 'action' |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.