code stringlengths 51 2.38k | docstring stringlengths 4 15.2k |
|---|---|
def drp_load(package, resource, confclass=None):
data = pkgutil.get_data(package, resource)
return drp_load_data(package, data, confclass=confclass) | Load the DRPS from a resource file. |
def get_matrix(self, indices):
new = numpy.empty(self.samples1.shape)
for idx in range(len(indices)):
if indices[idx]:
new[idx] = self.samples1[idx]
else:
new[idx] = self.samples2[idx]
if self.poly:
new = self.poly(*new)
... | Retrieve Saltelli matrix. |
def __insert_frond_RF(d_w, d_u, dfs_data):
dfs_data['RF'].append( (d_w, d_u) )
dfs_data['FG']['r'] += 1
dfs_data['last_inserted_side'] = 'RF' | Encapsulates the process of inserting a frond uw into the right side frond group. |
def get_all_stations(self, station_type=None):
params = None
if station_type and station_type in STATION_TYPE_TO_CODE_DICT:
url = self.api_base_url + 'getAllStationsXML_WithStationType'
params = {
'stationType': STATION_TYPE_TO_CODE_DICT[station_type]
... | Returns information of all stations.
@param<optional> station_type: ['mainline', 'suburban', 'dart'] |
def fetchUrls(cls, url, data, urlSearch):
searchUrls = []
if cls.css:
searchFun = data.cssselect
else:
searchFun = data.xpath
searches = makeSequence(urlSearch)
for search in searches:
for match in searchFun(search):
try:
... | Search all entries for given XPath in a HTML page. |
def get_stats_display_height(self, curse_msg):
r
try:
c = [i['msg'] for i in curse_msg['msgdict']].count('\n')
except Exception as e:
logger.debug('ERROR: Can not compute plugin height ({})'.format(e))
return 0
else:
return c + 1 | r"""Return the height of the formatted curses message.
The height is defined by the number of '\n' (new line). |
def _find_log_index(f):
global _last_asked, _log_cache
(begin, end) = (0, 128)
if _last_asked is not None:
(lastn, lastval) = _last_asked
if f >= lastval:
if f <= _log_cache[lastn]:
_last_asked = (lastn, f)
return lastn
elif f <= _log_c... | Look up the index of the frequency f in the frequency table.
Return the nearest index. |
def diskwarp_multi_fn(src_fn_list, res='first', extent='intersection', t_srs='first', r='cubic', verbose=True, outdir=None, dst_ndv=None):
if not iolib.fn_list_check(src_fn_list):
sys.exit('Missing input file(s)')
src_ds_list = [gdal.Open(fn, gdal.GA_ReadOnly) for fn in src_fn_list]
return diskwarp_... | Helper function for diskwarp of multiple input filenames |
def split_signature(klass, signature):
if signature == '()':
return []
if not signature.startswith('('):
return [signature]
result = []
head = ''
tail = signature[1:-1]
while tail:
c = tail[0]
head += c
tail = ta... | Return a list of the element signatures of the topmost signature tuple.
If the signature is not a tuple, it returns one element with the entire
signature. If the signature is an empty tuple, the result is [].
This is useful for e. g. iterating over method parameters which are
passed as... |
def _perform_merge(self, other):
if len(other.value) > len(self.value):
self.value = other.value[:]
return True | Merges the longer string |
def SetWriteBack(self, filename):
try:
self.writeback = self.LoadSecondaryConfig(filename)
self.MergeData(self.writeback.RawData(), self.writeback_data)
except IOError as e:
logging.error("Unable to read writeback file: %s", e)
return
except Exception as we:
if os.path.exists(f... | Sets the config file which will receive any modifications.
The main config file can be made writable, but directing all Set()
operations into a secondary location. This secondary location will
receive any updates and will override the options for this file.
Args:
filename: A filename which will ... |
def fetch(self, async=False, callback=None):
request = NURESTRequest(method=HTTP_METHOD_GET, url=self.get_resource_url())
if async:
return self.send_request(request=request, async=async, local_callback=self._did_fetch, remote_callback=callback)
else:
connection = self.sen... | Fetch all information about the current object
Args:
async (bool): Boolean to make an asynchronous call. Default is False
callback (function): Callback method that will be triggered in case of asynchronous call
Returns:
tuple: (current_fetcher, c... |
def setup_logging(self):
self.logger = logging.getLogger()
if os.path.exists('/dev/log'):
handler = SysLogHandler('/dev/log')
else:
handler = SysLogHandler()
self.logger.addHandler(handler) | Set up self.logger
This function is called after load_configuration() and after changing
to new user/group IDs (if configured). Logging to syslog using the
root logger is configured by default, you can override this method if
you want something else. |
def get_field_label(self, field_name, field=None):
label = None
if field is not None:
label = getattr(field, 'verbose_name', None)
if label is None:
label = getattr(field, 'name', None)
if label is None:
label = field_name
return label.... | Return a label to display for a field |
def append(self, frame_p):
return lib.zmsg_append(self._as_parameter_, byref(zframe_p.from_param(frame_p))) | Add frame to the end of the message, i.e. after all other frames.
Message takes ownership of frame, will destroy it when message is sent.
Returns 0 on success. Deprecates zmsg_add, which did not nullify the
caller's frame reference. |
def get_numeric_feature_names(example):
numeric_features = ('float_list', 'int64_list')
features = get_example_features(example)
return sorted([
feature_name for feature_name in features
if features[feature_name].WhichOneof('kind') in numeric_features
]) | Returns a list of feature names for float and int64 type features.
Args:
example: An example.
Returns:
A list of strings of the names of numeric features. |
def get_access_tokens(self, authorization_code):
response = self.box_request.get_access_token(authorization_code)
try:
att = response.json()
except Exception, ex:
raise BoxHttpResponseError(ex)
if response.status_code >= 400:
raise BoxError(response.st... | From the authorization code, get the "access token" and the "refresh token" from Box.
Args:
authorization_code (str). Authorisation code emitted by Box at the url provided by the function :func:`get_authorization_url`.
Returns:
tuple. (access_token, refresh_token)
Rais... |
def clean_html(context, data):
doc = _get_html_document(context, data)
if doc is None:
context.emit(data=data)
return
remove_paths = context.params.get('remove_paths')
for path in ensure_list(remove_paths):
for el in doc.findall(path):
el.drop_tree()
html_text = h... | Clean an HTML DOM and store the changed version. |
def cleanup_defenses(self):
print_header('CLEANING UP DEFENSES DATA')
work_ancestor_key = self.datastore_client.key('WorkType', 'AllDefenses')
keys_to_delete = [
e.key
for e in self.datastore_client.query_fetch(kind=u'ClassificationBatch')
] + [
e.key
for e in self.datast... | Cleans up all data about defense work in current round. |
async def _delete_agent(self, agent_addr):
self._available_agents = [agent for agent in self._available_agents if agent != agent_addr]
del self._registered_agents[agent_addr]
await self._recover_jobs(agent_addr) | Deletes an agent |
def core_profile_check(self) -> None:
profile_mask = self.info['GL_CONTEXT_PROFILE_MASK']
if profile_mask != 1:
warnings.warn('The window should request a CORE OpenGL profile')
version_code = self.version_code
if not version_code:
major, minor = map(int, self.info... | Core profile check.
FOR DEBUG PURPOSES ONLY |
def get_uint_info(self, field):
length = ctypes.c_ulong()
ret = ctypes.POINTER(ctypes.c_uint)()
_check_call(_LIB.XGDMatrixGetUIntInfo(self.handle,
c_str(field),
ctypes.byref(length),
... | Get unsigned integer property from the DMatrix.
Parameters
----------
field: str
The field name of the information
Returns
-------
info : array
a numpy array of float information of the data |
def get_path(dest, file, cwd = None):
if callable(dest):
return dest(file)
if not cwd:
cwd = file.cwd
if not os.path.isabs(dest):
dest = os.path.join(cwd, dest)
relative = os.path.relpath(file.path, file.base)
return os.path.join(dest, relative) | Get the writing path of a file. |
def metalarchives(song):
artist = normalize(song.artist)
title = normalize(song.title)
url = 'https://www.metal-archives.com/search/ajax-advanced/searching/songs'
url += f'/?songTitle={title}&bandName={artist}&ExactBandMatch=1'
soup = get_url(url, parser='json')
if not soup:
return ''
... | Returns the lyrics found in MetalArchives for the specified mp3 file or an
empty string if not found. |
def get_system_config_directory():
if platform.system().lower() == 'windows':
_cfg_directory = Path(os.getenv('APPDATA') or '~')
elif platform.system().lower() == 'darwin':
_cfg_directory = Path('~', 'Library', 'Preferences')
else:
_cfg_directory = Path(os.getenv('XDG_CONFIG_HO... | Return platform specific config directory. |
def _speak_none(self, element):
element.set_attribute('role', 'presentation')
element.set_attribute('aria-hidden', 'true')
element.set_attribute(AccessibleCSSImplementation.DATA_SPEAK, 'none') | No speak any content of element only.
:param element: The element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement |
def save(self, filename=None, tc=None):
if filename is None:
filename = self.filename
for sub in self.sub_workflows:
sub.save()
if tc is None:
tc = '{}.tc.txt'.format(filename)
p = os.path.dirname(tc)
f = os.path.basename(tc)
if not p:
... | Write this workflow to DAX file |
def strip_encoding_cookie(filelike):
it = iter(filelike)
try:
first = next(it)
if not cookie_comment_re.match(first):
yield first
second = next(it)
if not cookie_comment_re.match(second):
yield second
except StopIteration:
return
for line i... | Generator to pull lines from a text-mode file, skipping the encoding
cookie if it is found in the first two lines. |
def patch(self, url, callback,
params=None, json=None, headers=None):
return self.adapter.patch(url, callback,
params=params, json=json, headers=headers) | Patch a URL.
Args:
url(string): URL for the request
callback(func): The response callback function
headers(dict): HTTP headers for the request
Keyword Args:
params(dict): Parameters for the request
json(dict): JSON body for the request
... |
def intersects(self, other_grid_coordinates):
ogc = other_grid_coordinates
ax1, ay1, ax2, ay2 = self.ULC.lon, self.ULC.lat, self.LRC.lon, self.LRC.lat
bx1, by1, bx2, by2 = ogc.ULC.lon, ogc.ULC.lat, ogc.LRC.lon, ogc.LRC.lat
if ((ax1 <= bx2) and (ax2 >= bx1) and (ay1 >= by2) and (ay2 <= by... | returns True if the GC's overlap. |
def specAutoRange(self):
trace_range = self.responsePlots.values()[0].viewRange()[0]
vb = self.specPlot.getViewBox()
vb.autoRange(padding=0)
self.specPlot.setXlim(trace_range) | Auto adjusts the visible range of the spectrogram |
def fix_missing_lang_tags(marc_xml, dom):
def get_lang_tag(lang):
lang_str = '\n <mods:language>\n'
lang_str += ' <mods:languageTerm authority="iso639-2b" type="code">'
lang_str += lang
lang_str += '</mods:languageTerm>\n'
lang_str += ' </mods:language>\n\n'
lang... | If the lang tags are missing, add them to the MODS. Lang tags are parsed
from `marc_xml`. |
def removeActor(self, a):
if not self.initializedPlotter:
save_int = self.interactive
self.show(interactive=0)
self.interactive = save_int
return
if self.renderer:
self.renderer.RemoveActor(a)
if hasattr(a, 'renderedAt'):
... | Remove ``vtkActor`` or actor index from current renderer. |
def sanity(request, sysmeta_pyxb):
_does_not_contain_replica_sections(sysmeta_pyxb)
_is_not_archived(sysmeta_pyxb)
_obsoleted_by_not_specified(sysmeta_pyxb)
if 'HTTP_VENDOR_GMN_REMOTE_URL' in request.META:
return
_has_correct_file_size(request, sysmeta_pyxb)
_is_supported_checksum_algori... | Check that sysmeta_pyxb is suitable for creating a new object and matches the
uploaded sciobj bytes. |
def get_children(self, id_):
id_list = []
for r in self._rls.get_relationships_by_genus_type_for_source(id_, self._relationship_type):
id_list.append(r.get_destination_id())
return IdList(id_list) | Gets the children of the given ``Id``.
arg: id (osid.id.Id): the ``Id`` to query
return: (osid.id.IdList) - the children of the ``id``
raise: NotFound - ``id`` is not found
raise: NullArgument - ``id`` is ``null``
raise: OperationFailed - unable to complete request
... |
def connect(cls, dbname):
test_times_schema =
setup_times_schema =
schemas = [test_times_schema,
setup_times_schema]
db_file = '{}.db'.format(dbname)
cls.connection = sqlite3.connect(db_file)
for s in schemas:
cls.connection.execute(s) | Create a new connection to the SQLite3 database.
:param dbname: The database name
:type dbname: str |
def holiday_description(self):
entry = self._holiday_entry()
desc = entry.description
return desc.hebrew.long if self.hebrew else desc.english | Return the holiday description.
In case none exists will return None. |
def open_url(self, url):
try:
c = pycurl.Curl()
c.setopt(pycurl.FAILONERROR, True)
c.setopt(pycurl.URL, "%s/api/v0/%s" % (self.url, url))
c.setopt(pycurl.HTTPHEADER, ["User-Agent: %s" % self.userAgent,
"apiToken: %s" % self... | Open's URL with apiToken in the headers |
def _build_generator_list(network):
genos_mv = pd.DataFrame(columns=
('id', 'obj'))
genos_lv = pd.DataFrame(columns=
('id', 'obj'))
genos_lv_agg = pd.DataFrame(columns=
('la_id', 'id', 'obj'))
for geno in network.mv_... | Builds DataFrames with all generators in MV and LV grids
Returns
-------
:pandas:`pandas.DataFrame<dataframe>`
A DataFrame with id of and reference to MV generators
:pandas:`pandas.DataFrame<dataframe>`
A DataFrame with id of and reference to LV generators
:pandas:`pandas.Da... |
def is_open(self, refresh=False):
if refresh:
self.refresh()
return self.get_level(refresh) > 0 | Get curtains state.
Refresh data from Vera if refresh is True, otherwise use local cache.
Refresh is only needed if you're not using subscriptions. |
def rotate(self):
item = self._address_infos.pop(0)
self._address_infos.append(item) | Move the first address to the last position. |
def format_op_hdr():
txt = 'Base Filename'.ljust(36) + ' '
txt += 'Lines'.rjust(7) + ' '
txt += 'Words'.rjust(7) + ' '
txt += 'Unique'.ljust(8) + ''
return txt | Build the header |
def write_networking_file(version, pairs):
vmnets = OrderedDict(sorted(pairs.items(), key=lambda t: t[0]))
try:
with open(VMWARE_NETWORKING_FILE, "w", encoding="utf-8") as f:
f.write(version)
for key, value in vmnets.items():
f.write("answer {} {}\n".format(key, v... | Write the VMware networking file. |
def get_command(self, ctx, cmd_name):
if cmd_name not in self.all_cmds:
return None
return EventTypeSubCommand(self.events_lib, cmd_name, self.all_cmds[cmd_name]) | gets the subcommands under the service name
Parameters
----------
ctx : Context
the context object passed into the method
cmd_name : str
the service name
Returns
-------
EventTypeSubCommand:
returns subcommand if successful, No... |
def from_grpc(operation, operations_stub, result_type, **kwargs):
refresh = functools.partial(_refresh_grpc, operations_stub, operation.name)
cancel = functools.partial(_cancel_grpc, operations_stub, operation.name)
return Operation(operation, refresh, cancel, result_type, **kwargs) | Create an operation future using a gRPC client.
This interacts with the long-running operations `service`_ (specific
to a given API) via gRPC.
.. _service: https://github.com/googleapis/googleapis/blob/\
050400df0fdb16f63b63e9dee53819044bffc857/\
google/longrunning/operat... |
def generateAcceptHeader(*elements):
parts = []
for element in elements:
if type(element) is str:
qs = "1.0"
mtype = element
else:
mtype, q = element
q = float(q)
if q > 1 or q <= 0:
raise ValueError('Invalid preference ... | Generate an accept header value
[str or (str, float)] -> str |
def set_mtime(self, name, mtime, size):
self.check_write(name)
os.utime(os.path.join(self.cur_dir, name), (-1, mtime)) | Set modification time on file. |
def send_async(
self,
queue_identifier: QueueIdentifier,
message: Message,
):
recipient = queue_identifier.recipient
if not is_binary_address(recipient):
raise ValueError('Invalid address {}'.format(pex(recipient)))
if isinstance(message, (Deli... | Send a new ordered message to recipient.
Messages that use the same `queue_identifier` are ordered. |
def liouvillian(H, Ls=None):
r
if Ls is None:
Ls = []
elif isinstance(Ls, Matrix):
Ls = Ls.matrix.ravel().tolist()
summands = [-I * commutator(H), ]
summands.extend([lindblad(L) for L in Ls])
return SuperOperatorPlus.create(*summands) | r"""Return the Liouvillian super-operator associated with `H` and `Ls`
The Liouvillian :math:`\mathcal{L}` generates the Markovian-dynamics of a
system via the Master equation:
.. math::
\dot{\rho} = \mathcal{L}\rho
= -i[H,\rho] + \sum_{j=1}^n \mathcal{D}[L_j] \rho
Args:
H... |
def ignore_code(self, code):
if len(code) < 4 and any(s.startswith(code)
for s in self.options.select):
return False
return (code.startswith(self.options.ignore) and
not code.startswith(self.options.select)) | Check if the error code should be ignored.
If 'options.select' contains a prefix of the error code,
return False. Else, if 'options.ignore' contains a prefix of
the error code, return True. |
def put_path(self, url, path):
cache_path = self._url_to_path(url)
try:
dir = os.path.dirname(cache_path)
os.makedirs(dir)
except OSError as e:
if e.errno != errno.EEXIST:
raise Error('Failed to create cache directories for ' % cache_path)
... | Puts a resource already on disk into the disk cache.
Args:
url: The original url of the resource
path: The resource already available on disk
Raises:
CacheError: If the file cannot be put in cache |
def get_suggested_repositories(self):
if self.suggested_repositories is None:
repository_set = list()
for term_count in range(5, 2, -1):
query = self.__get_query_for_repos(term_count=term_count)
repository_set.extend(self.__get_repos_for_query(query))
... | Method to procure suggested repositories for the user.
:return: Iterator to procure suggested repositories for the user. |
def get_object_by_record(record):
if not record:
return None
if record.get("uid"):
return get_object_by_uid(record["uid"])
if record.get("path"):
return get_object_by_path(record["path"])
if record.get("parent_path") and record.get("id"):
path = "/".join([record["parent_p... | Find an object by a given record
Inspects request the record to locate an object
:param record: A dictionary representation of an object
:type record: dict
:returns: Found Object or None
:rtype: object |
def createLocationEncoder(t, w=15):
encoder = CoordinateEncoder(name="positionEncoder", n=t.l6CellCount, w=w)
return encoder | A default coordinate encoder for encoding locations into sparse
distributed representations. |
def _update_evaluated_individuals_(self, result_score_list, eval_individuals_str, operator_counts, stats_dicts):
for result_score, individual_str in zip(result_score_list, eval_individuals_str):
if type(result_score) in [float, np.float64, np.float32]:
self.evaluated_individuals_[ind... | Update self.evaluated_individuals_ and error message during pipeline evaluation.
Parameters
----------
result_score_list: list
A list of CV scores for evaluated pipelines
eval_individuals_str: list
A list of strings for evaluated pipelines
operator_counts... |
def _read_stc(stc_file):
hdr = _read_hdr_file(stc_file)
stc_dtype = dtype([('segment_name', 'a256'),
('start_stamp', '<i'),
('end_stamp', '<i'),
('sample_num', '<i'),
('sample_span', '<i')])
with stc_file.open('rb') ... | Read Segment Table of Contents file.
Returns
-------
hdr : dict
- next_segment : Sample frequency in Hertz
- final : Number of channels stored
- padding : Padding
stamps : ndarray of dtype
- segment_name : Name of ERD / ETC file segment
- start_stamp : First samp... |
def requires_auth(func):
@six.wraps(func)
def wrapper(self, *args, **kwargs):
if self.token_expired:
self.authenticate()
return func(self, *args, **kwargs)
return wrapper | Handle authentication checks.
.. py:decorator:: requires_auth
Checks if the token has expired and performs authentication if needed. |
def do_proplist(self, subcmd, opts, *args):
print "'svn %s' opts: %s" % (subcmd, opts)
print "'svn %s' args: %s" % (subcmd, args) | List all properties on files, dirs, or revisions.
usage:
1. proplist [PATH...]
2. proplist --revprop -r REV [URL]
1. Lists versioned props in working copy.
2. Lists unversioned remote props on repos revision.
${cmd_option_list} |
def distribution(self, **slice_kwargs):
values = []
keys = []
for key, size in self.slice(count_only=True, **slice_kwargs):
values.append(size)
keys.append(key)
return keys, values | Calculates the number of papers in each slice, as defined by
``slice_kwargs``.
Examples
--------
.. code-block:: python
>>> corpus.distribution(step_size=1, window_size=1)
[5, 5]
Parameters
----------
slice_kwargs : kwargs
Keyw... |
def stream(
self,
accountID,
**kwargs
):
request = Request(
'GET',
'/v3/accounts/{accountID}/transactions/stream'
)
request.set_path_param(
'accountID',
accountID
)
request.set_stream(True)
class ... | Get a stream of Transactions for an Account starting from when the
request is made.
Args:
accountID:
Account Identifier
Returns:
v20.response.Response containing the results from submitting the
request |
def flatten(input_list):
for el in input_list:
if isinstance(el, collections.Iterable) \
and not isinstance(el, basestring):
for sub in flatten(el):
yield sub
else:
yield el | Return a flattened genertor from an input list.
Usage:
input_list = [['a'], ['b', 'c', 'd'], [['e']], ['f']]
list(flatten(input_list))
>> ['a', 'b', 'c', 'd', 'e', 'f'] |
def search_shell(self):
with self._lock:
if self._shell is not None:
return
reference = self._context.get_service_reference(SERVICE_SHELL)
if reference is not None:
self.set_shell(reference) | Looks for a shell service |
def create_assign_context_menu(self):
menu = QMenu("AutoKey")
self._build_menu(menu)
self.setContextMenu(menu) | Create a context menu, then set the created QMenu as the context menu.
This builds the menu with all required actions and signal-slot connections. |
def write_terminal(matrix, version, out, border=None):
with writable(out, 'wt') as f:
write = f.write
colours = ['\033[{0}m'.format(i) for i in (7, 49)]
for row in matrix_iter(matrix, version, scale=1, border=border):
prev_bit = -1
cnt = 0
for bit in row:
... | \
Function to write to a terminal which supports ANSI escape codes.
:param matrix: The matrix to serialize.
:param int version: The (Micro) QR code version.
:param out: Filename or a file-like object supporting to write text.
:param int border: Integer indicating the size of the quiet zone.
... |
def XstarT_dot(self,M):
if 0:
pass
else:
RV = np.dot(self.Xstar().T,M)
return RV | get dot product of Xhat and M |
def flatten(l):
for el in l:
if _iterable_not_string(el):
for s in flatten(el):
yield s
else:
yield el | Flatten an arbitrarily nested sequence.
Parameters
----------
l : sequence
The non string sequence to flatten
Notes
-----
This doesn't consider strings sequences.
Returns
-------
flattened : generator |
def check_web_config(config_fname):
print("Looking for config file at {0} ...".format(config_fname))
config = RawConfigParser()
try:
config.readfp(open(config_fname))
return config
except IOError:
print("ERROR: Seems like the config file does not exist. Please call 'opensubmit-we... | Try to load the Django settings.
If this does not work, than settings file does not exist.
Returns:
Loaded configuration, or None. |
def root_parent(self, category=None):
return next(filter(lambda c: c.is_root, self.hierarchy())) | Returns the topmost parent of the current category. |
def apply(self, func, *args, **kwds):
wrapped = self._wrapped_apply(func, *args, **kwds)
n_repeats = 3
timed = timeit.timeit(wrapped, number=n_repeats)
samp_proc_est = timed / n_repeats
est_apply_duration = samp_proc_est / self._SAMP_SIZE * self._nrows
if est_apply_durati... | Apply the function to the transformed swifter object |
def run(self):
if not (self.table):
raise Exception("table need to be specified")
path = self.s3_load_path()
output = self.output()
connection = output.connect()
cursor = connection.cursor()
self.init_copy(connection)
self.copy(cursor, path)
se... | If the target table doesn't exist, self.create_table
will be called to attempt to create the table. |
def add_waveform(self, waveform):
if not isinstance(waveform, PlotWaveform):
self.log_exc(u"waveform must be an instance of PlotWaveform", None, True, TypeError)
self.waveform = waveform
self.log(u"Added waveform") | Add a waveform to the plot.
:param waveform: the waveform to be added
:type waveform: :class:`~aeneas.plotter.PlotWaveform`
:raises: TypeError: if ``waveform`` is not an instance of :class:`~aeneas.plotter.PlotWaveform` |
def next(self):
try:
results = self._stride_buffer.pop()
except (IndexError, AttributeError):
self._rebuffer()
results = self._stride_buffer.pop()
if not results:
raise StopIteration
return results | Returns the next sequence of results, given stride and n. |
def warning(self, amplexception):
msg = '\t'+str(amplexception).replace('\n', '\n\t')
print('Warning:\n{:s}'.format(msg)) | Receives notification of a warning. |
def append(self, ldap_filter):
if not isinstance(ldap_filter, (LDAPFilter, LDAPCriteria)):
raise TypeError(
"Invalid filter type: {0}".format(type(ldap_filter).__name__)
)
if len(self.subfilters) >= 1 and self.operator == NOT:
raise ValueError("Not ope... | Appends a filter or a criterion to this filter
:param ldap_filter: An LDAP filter or criterion
:raise TypeError: If the parameter is not of a known type
:raise ValueError: If the more than one filter is associated to a
NOT operator |
def current(cls):
name = socket.getfqdn()
ip = socket.gethostbyname(name)
return cls(name, ip) | Helper method for getting the current peer of whichever host we're
running on. |
def align(self, input_path, output_path, directions, pipeline,
filter_minimum):
with tempfile.NamedTemporaryFile(prefix='for_conv_file', suffix='.fa') as fwd_fh:
fwd_conv_file = fwd_fh.name
with tempfile.NamedTemporaryFile(prefix='rev_conv_file', suffix='.fa') as rev_fh:
... | align - Takes input path to fasta of unaligned reads, aligns them to
a HMM, and returns the aligned reads in the output path
Parameters
----------
input_path : str
output_path : str
reverse_direction : dict
A dictionary of read names, with the entries being t... |
def _process_added_port_event(self, port_name):
LOG.info("Hyper-V VM vNIC added: %s", port_name)
self._added_ports.add(port_name) | Callback for added ports. |
def set_components(self, params):
for key, value in params.items():
if isinstance(value, pd.Series):
new_function = self._timeseries_component(value)
elif callable(value):
new_function = value
else:
new_function = self._constant... | Set the value of exogenous model elements.
Element values can be passed as keyword=value pairs in the function call.
Values can be numeric type or pandas Series.
Series will be interpolated by integrator.
Examples
--------
>>> model.set_components({'birth_rate': 10})
... |
def add(self, rd, ttl=None):
if self.rdclass != rd.rdclass or self.rdtype != rd.rdtype:
raise IncompatibleTypes
if not ttl is None:
self.update_ttl(ttl)
if self.rdtype == dns.rdatatype.RRSIG or \
self.rdtype == dns.rdatatype.SIG:
covers = rd.covers(... | Add the specified rdata to the rdataset.
If the optional I{ttl} parameter is supplied, then
self.update_ttl(ttl) will be called prior to adding the rdata.
@param rd: The rdata
@type rd: dns.rdata.Rdata object
@param ttl: The TTL
@type ttl: int |
def _get_user(self, user):
return ' '.join([user.username, user.first_name, user.last_name]) | Generate user filtering tokens. |
def merge_query(path, postmap, force_unicode=True):
if postmap:
p = postmap.copy()
else:
p = {}
p.update(get_query(path, force_unicode=False))
if force_unicode:
p = _unicode(p)
return p | Merges params parsed from the URI into the mapping from the POST body and
returns a new dict with the values.
This is a convenience function that gives use a dict a bit like PHP's $_REQUEST
array. The original 'postmap' is preserved so the caller can identify a
param's source if necessary. |
def get_correctness_for_response(self, response):
for answer in self.my_osid_object.get_answers():
if self._is_match(response, answer):
try:
return answer.get_score()
except AttributeError:
return 100
for answer in self.... | get measure of correctness available for a particular response |
def scan_file(self, this_file):
params = {'apikey': self.api_key}
try:
if type(this_file) == str and os.path.isfile(this_file):
files = {'file': (this_file, open(this_file, 'rb'))}
elif isinstance(this_file, StringIO.StringIO):
files = {'file': thi... | Submit a file to be scanned by VirusTotal
:param this_file: File to be scanned (32MB file size limit)
:return: JSON response that contains scan_id and permalink. |
def _get_websocket(self, reuse=True):
if self.ws and reuse:
if self.ws.connected:
return self.ws
logging.debug("Stale connection, reconnecting.")
self.ws = self._create_connection()
return self.ws | Reuse existing connection or create a new connection. |
def cli(conf):
try:
config = init_config(conf)
debug = config.getboolean('DEFAULT', 'debug')
conn = get_conn(config.get('DEFAULT','statusdb'))
cur = conn.cursor()
sqlstr =
try:
cur.execute('drop table client_status')
except:
pass
... | OpenVPN status initdb method |
def log_status (self):
duration = time.time() - self.start_time
checked, in_progress, queue = self.aggregator.urlqueue.status()
num_urls = len(self.aggregator.result_cache)
self.logger.log_status(checked, in_progress, queue, duration, num_urls) | Log a status message. |
def find_log_dir(log_dir=None):
if log_dir:
dirs = [log_dir]
elif FLAGS['log_dir'].value:
dirs = [FLAGS['log_dir'].value]
else:
dirs = ['/tmp/', './']
for d in dirs:
if os.path.isdir(d) and os.access(d, os.W_OK):
return d
_absl_logger.fatal("Can't find a writable directory for logs, trie... | Returns the most suitable directory to put log files into.
Args:
log_dir: str|None, if specified, the logfile(s) will be created in that
directory. Otherwise if the --log_dir command-line flag is provided,
the logfile will be created in that directory. Otherwise the logfile
will be crea... |
def addLNT(LocalName, phenoId, predicate, g=None):
if g is None:
s = inspect.stack(0)
checkCalledInside('LocalNameManager', s)
g = s[1][0].f_locals
addLN(LocalName, Phenotype(phenoId, predicate), g) | Add a local name for a phenotype from a pair of identifiers |
def close(self):
try:
self.sock.shutdown(socket.SHUT_RDWR)
self.sock.close()
except socket.error:
pass | Closes the tunnel. |
def write(self, src, dest=None):
if not src or not isinstance(src, string_types):
raise ValueError('The src path must be a non-empty string, got {} of type {}.'.format(
src, type(src)))
if dest and not isinstance(dest, string_types):
raise ValueError('The dest entry path must be a non-empty ... | Schedules a write of the file at ``src`` to the ``dest`` path in this jar.
If the ``src`` is a file, then ``dest`` must be specified.
If the ``src`` is a directory then by default all descendant files will be added to the jar as
entries carrying their relative path. If ``dest`` is specified it will be pr... |
def put(self, key, val, minutes):
minutes = self._get_minutes(minutes)
if minutes is not None:
self._store.put(key, val, minutes) | Store an item in the cache.
:param key: The cache key
:type key: str
:param val: The cache value
:type val: mixed
:param minutes: The lifetime in minutes of the cached value
:type minutes: int|datetime |
def _set_ip(self):
self._ip = socket.gethostbyname(self._fqdn)
log.debug('IP: %s' % self._ip) | Resolve FQDN to IP address |
def flatten_reducer(
flattened_list: list,
entry: typing.Union[list, tuple, COMPONENT]
) -> list:
if hasattr(entry, 'includes') and hasattr(entry, 'files'):
flattened_list.append(entry)
elif entry:
flattened_list.extend(entry)
return flattened_list | Flattens a list of COMPONENT instances to remove any lists or tuples
of COMPONENTS contained within the list
:param flattened_list:
The existing flattened list that has been populated from previous
calls of this reducer function
:param entry:
An entry to be reduced. Either a COMPONE... |
def add_pyspark_path():
try:
spark_home = os.environ['SPARK_HOME']
sys.path.append(os.path.join(spark_home, 'python'))
py4j_src_zip = glob(os.path.join(spark_home, 'python',
'lib', 'py4j-*-src.zip'))
if len(py4j_src_zip) == 0:
rais... | Add PySpark to the library path based on the value of SPARK_HOME. |
def provide_session(self, start_new=False):
if self.is_global:
self._session_info = self._global_session_info
self._session_start = self._global_session_start
if self._session_info is None or start_new or \
datetime.datetime.now() > self._session_start + self.SESS... | Makes sure that session is still valid and provides session info
:param start_new: If `True` it will always create a new session. Otherwise it will create a new
session only if no session exists or the previous session timed out.
:type start_new: bool
:return: Current session info
... |
def ctr_geom(geom, masses):
import numpy as np
shift = np.tile(ctr_mass(geom, masses), geom.shape[0] / 3)
ctr_geom = geom - shift
return ctr_geom | Returns geometry shifted to center of mass.
Helper function to automate / encapsulate translation of a geometry to its
center of mass.
Parameters
----------
geom
length-3N |npfloat_| --
Original coordinates of the atoms
masses
length-N OR length-3N |npfloat_| --
... |
def supply(self, issuer):
def _retrieve_jwks():
jwks_uri = self._key_uri_supplier.supply(issuer)
if not jwks_uri:
raise UnauthenticatedException(u"Cannot find the `jwks_uri` for issuer "
u"%s: either the issuer is unknown or ... | Supplies the `Json Web Key Set` for the given issuer.
Args:
issuer: the issuer.
Returns:
The successfully retrieved Json Web Key Set. None is returned if the
issuer is unknown or the retrieval process fails.
Raises:
UnauthenticatedException: When this... |
def remember_forever(self, key, callback):
val = self.get(key)
if val is not None:
return val
val = value(callback)
self.forever(key, val)
return val | Get an item from the cache, or store the default value forever.
:param key: The cache key
:type key: str
:param callback: The default function
:type callback: mixed
:rtype: mixed |
def calculate_input(self, buffer):
if TriggerMode.ABBREVIATION in self.modes:
if self._should_trigger_abbreviation(buffer):
if self.immediate:
return len(self._get_trigger_abbreviation(buffer))
else:
return len(self._get_trigger... | Calculate how many keystrokes were used in triggering this phrase. |
def access_service_descriptor(price, consume_endpoint, service_endpoint, timeout, template_id):
return (ServiceTypes.ASSET_ACCESS,
{'price': price, 'consumeEndpoint': consume_endpoint,
'serviceEndpoint': service_endpoint,
'timeout': timeout, 'templateId': templa... | Access service descriptor.
:param price: Asset price, int
:param consume_endpoint: url of the service provider, str
:param service_endpoint: identifier of the service inside the asset DDO, str
:param timeout: amount of time in seconds before the agreement expires, int
:param tem... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.