code stringlengths 51 2.38k | docstring stringlengths 4 15.2k |
|---|---|
def is_zero(self):
for o in self.matrix.ravel():
try:
if not o.is_zero:
return False
except AttributeError:
if not o == 0:
return False
return True | Are all elements of the matrix zero? |
def load_template(self, path):
if not path.startswith('/'):
for folder in self.options['template_folders']:
fullpath = op.join(folder, path)
if op.exists(fullpath):
path = fullpath
break
else:
raise J... | Load and compile a template. |
def make_scrape_request(session, url, mode='get', data=None):
try:
html = session.request(mode, url, data=data)
except RequestException:
raise VooblyError('failed to connect')
if SCRAPE_FETCH_ERROR in html.text:
raise VooblyError('not logged in')
if html.status_code != 200 or SCR... | Make a request to URL. |
def getName(self, innerFlag=False):
if self._currentIdx is None:
raise error.PyAsn1Error('Component not chosen')
else:
if innerFlag:
c = self._componentValues[self._currentIdx]
if isinstance(c, Choice):
return c.getName(innerFla... | Return the name of currently assigned component of the |ASN.1| object.
Returns
-------
: :py:class:`str`
|ASN.1| component name |
def filter_belief(stmts_in, belief_cutoff, **kwargs):
dump_pkl = kwargs.get('save')
logger.info('Filtering %d statements to above %f belief' %
(len(stmts_in), belief_cutoff))
stmts_out = []
for stmt in stmts_in:
if stmt.belief < belief_cutoff:
continue
stmts_o... | Filter to statements with belief above a given cutoff.
Parameters
----------
stmts_in : list[indra.statements.Statement]
A list of statements to filter.
belief_cutoff : float
Only statements with belief above the belief_cutoff will be returned.
Here 0 < belief_cutoff < 1.
sa... |
def get(search="unsigned"):
plugins = []
for i in os.walk('/usr/lib/nagios/plugins'):
for f in i[2]:
plugins.append(f)
return plugins | List all available plugins |
def _draw_binary(self):
self._draw_pr_curve(self.recall_, self.precision_, label="binary PR curve")
self._draw_ap_score(self.score_) | Draw the precision-recall curves in the binary case |
def range(cls, collection, attribute, left, right, closed, index_id, skip=None, limit=None):
kwargs = {
'index': index_id,
'attribute': attribute,
'left': left,
'right': right,
'closed': closed,
'skip': skip,
'limit': limit,
... | This will find all documents within a given range. In order to execute a range query, a
skip-list index on the queried attribute must be present.
:param collection Collection instance
:param attribute The attribute path to check
:param left The lower bound
:p... |
def calc_dist(lamost_point, training_points, coeffs):
diff2 = (training_points - lamost_point)**2
dist = np.sqrt(np.sum(diff2*coeffs, axis=1))
return np.mean(dist[dist.argsort()][0:10]) | avg dist from one lamost point to nearest 10 training points |
def p_debug(self, message):
"Format and print debug messages"
print("{}{} `{}`".format(self._debug_indent * " ",
message, repr(self.p_suffix(10)))) | Format and print debug messages |
def attention_lm_moe_24b_diet():
hparams = attention_lm_moe_large_diet()
hparams.moe_hidden_sizes = "12288"
hparams.moe_num_experts = 1024
hparams.batch_size = 4096
return hparams | Unnecessarily large model with 24B params - because we can. |
def convex_conj(self):
r
if self.quadratic_coeff == 0:
cconj = self.functional.convex_conj.translated(self.linear_term)
if self.constant != 0:
cconj = cconj - self.constant
return cconj
else:
return super(FunctionalQuadraticPerturb,... | r"""Convex conjugate functional of the functional.
Notes
-----
Given a functional :math:`f`, the convex conjugate of a linearly
perturbed version :math:`f(x) + <y, x>` is given by a translation of
the convex conjugate of :math:`f`:
.. math::
(f + \langle y, ... |
def remove_custom_css(destdir, resource=PKGNAME ):
if not os.path.isdir( destdir ):
return False
custom = os.path.join( destdir, 'custom.css' )
copy = True
found = False
prefix = css_frame_prefix(resource)
with io.open(custom + '-new', 'wt') as fout:
with io.open(custom) as fin:
... | Remove the kernel CSS from custom.css |
def restart(self, all=False):
if all:
data = {'type': self.type}
else:
data = {'ps': self.process}
r = self._h._http_resource(
method='POST',
resource=('apps', self.app.name, 'ps', 'restart'),
data=data
)
r.raise_for_sta... | Restarts the given process. |
def make_tarball(src_dir):
if type(src_dir) != str:
raise TypeError('src_dir must be str')
output_file = src_dir + ".tar.gz"
log.msg("Wrapping tarball '{out}' ...".format(out=output_file))
if not _dry_run:
with tarfile.open(output_file, "w:gz") as tar:
tar.add(src_dir, arcnam... | Make gzipped tarball from a source directory
:param src_dir: source directory
:raises TypeError: if src_dir is not str |
def get_sentence_break_property(value, is_bytes=False):
obj = unidata.ascii_sentence_break if is_bytes else unidata.unicode_sentence_break
if value.startswith('^'):
negated = value[1:]
value = '^' + unidata.unicode_alias['sentencebreak'].get(negated, negated)
else:
value = unidata.un... | Get `SENTENCE BREAK` property. |
def show_function_centric_wizard(self):
from safe.gui.tools.wizard.wizard_dialog import WizardDialog
if self.wizard and self.wizard.isVisible():
return
if not self.wizard:
self.wizard = WizardDialog(
self.iface.mainWindow(),
self.iface,
... | Show the function centric wizard. |
def get_system(self, identity):
return system.HPESystem(self._conn, identity,
redfish_version=self.redfish_version) | Given the identity return a HPESystem object
:param identity: The identity of the System resource
:returns: The System object |
def get_android_id(self) -> str:
output, _ = self._execute(
'-s', self.device_sn, 'shell', 'settings', 'get', 'secure', 'android_id')
return output.strip() | Show Android ID. |
def parse(self, text, layers=None):
params = {
"text": text,
"key": self.key,
}
if layers is not None:
if isinstance(layers, six.string_types):
params["layers"] = layers
elif isinstance(layers, collections.Iterable):
... | Parsing passed text to json.
Args:
text: Text to parse.
layers (optional): Special fields. Only one string
or iterable object (e.g "Data", ("Data", "Fio")).
Only these fields will be returned.
Returns:
The parsed text into a json obj... |
def gen_file_lines(path, mode='rUb', strip_eol=True, ascii=True, eol='\n'):
if isinstance(path, str):
path = open(path, mode)
with path:
for line in path:
if ascii:
line = str(line)
if strip_eol:
line = line.rstrip('\n')
yield l... | Generate a sequence of "documents" from the lines in a file
Arguments:
path (file or str): path to a file or an open file_obj ready to be read
mode (str): file mode to open a file in
strip_eol (bool): whether to strip the EOL char from lines as they are read/generated/yielded
ascii (bool): ... |
def raw_query(self, query, query_parameters=None):
self.assert_no_raw_query()
if len(self._where_tokens) != 0 or len(self._select_tokens) != 0 or len(
self._order_by_tokens) != 0 or len(self._group_by_tokens) != 0:
raise InvalidOperationException(
"You can onl... | To get all the document that equal to the query
@param str query: The rql query
@param dict query_parameters: Add query parameters to the query {key : value} |
def _message_received(self, message):
with self.lock:
self._state.receive_message(message)
for callable in chain(self._on_message_received, self._on_message):
callable(message) | Notify the observers about the received message. |
def update(self, egg, permute=False, nperms=1000,
parallel=False):
self.n+=1
next_weights = np.nanmean(_analyze_chunk(egg,
analysis=fingerprint_helper,
analysis_type='fingerprint',
pass_features=True,
... | In-place method that updates fingerprint with new data
Parameters
----------
egg : quail.Egg
Data to update fingerprint
Returns
----------
None |
def origin(self):
with self.selenium.context(self.selenium.CONTEXT_CHROME):
return self.root.get_attribute("origin") | Provide access to the notification origin.
Returns:
str: The notification origin. |
def plot_loss(self, n_skip=10, n_skip_end=5):
if not in_ipynb(): plt.switch_backend('agg')
plt.plot(self.iterations[n_skip:-n_skip_end], self.losses[n_skip:-n_skip_end])
if not in_ipynb():
plt.savefig(os.path.join(self.save_path, 'loss_plot.png'))
np.save(os.path.join(sel... | plots loss function as function of iterations.
When used in Jupyternotebook, plot will be displayed in notebook. Else, plot will be displayed in console and both plot and loss are saved in save_path. |
def get_key():
character_name = chr
codes = _get_keycodes()
if len(codes) == 1:
code = codes[0]
if code >= 32:
return character_name(code)
return control_key_name(code)
return get_extended_key_name(codes) | Get a key from the keyboard as a string
A 'key' will be a single char, or the name of an extended key |
def get_quoted_local_columns(self, platform):
columns = []
for column in self._local_column_names.values():
columns.append(column.get_quoted_name(platform))
return columns | Returns the quoted representation of the referencing table column names
the foreign key constraint is associated with.
But only if they were defined with one or the referencing table column name
is a keyword reserved by the platform.
Otherwise the plain unquoted value as inserted is ret... |
def render_html(self, *args, **kwargs):
static_url = '%s://%s%s' % (self.request.scheme, self.request.get_host(), settings.STATIC_URL)
media_url = '%s://%s%s' % (self.request.scheme, self.request.get_host(), settings.MEDIA_URL)
with override_settings(STATIC_URL=static_url, MEDIA_URL=media_url):
... | Renders the template.
:rtype: str |
def serialize(self, data):
with open(self.dest, 'wb') as fh:
root = et.Element('nrml')
self.add_hazard_curves(root, self.metadata, data)
nrml.write(list(root), fh) | Write a sequence of hazard curves to the specified file.
:param data:
Iterable of hazard curve data. Each datum must be an object with
the following attributes:
* poes: A list of probability of exceedence values (floats).
* location: An object representing the l... |
def render(self, template_name: str, **ctx):
if '.' not in template_name:
template_file_extension = (self.Meta.template_file_extension
or app.config.TEMPLATE_FILE_EXTENSION)
template_name = f'{template_name}{template_file_extension}'
if self... | Convenience method for rendering a template.
:param template_name: The template's name. Can either be a full path,
or a filename in the controller's template folder.
:param ctx: Context variables to pass into the template. |
def get_admins_from_django(homedir):
return ["root@localhost"]
path = homedir + "/settings/basic.py"
if not os.path.exists(path):
path = homedir + "/settings.py"
if not os.path.exists(path):
return
mod = compiler.parseFile(path)
for node in mod.node.nodes:
try:
... | Get admin's emails from django settings |
def pos(self):
pos = self._pos
if pos is None:
return self.p0
pos = {param: self._pos[..., k]
for (k, param) in enumerate(self.sampling_params)}
return pos | A dictionary of the current walker positions.
If the sampler hasn't been run yet, returns p0. |
def get_writable_metadata(self, file_format):
if file_format == 'json':
metadata = self.json
elif file_format == 'xml':
metadata = self.xml
else:
raise TypeError('The requested file type (%s) is not yet supported'
% file_format)
... | Convert the metadata to a writable form.
:param file_format: the needed format can be json or xml
:type file_format: str
:return: the dupled metadata
:rtype: str |
def cli(self):
if self._cli is None:
self._cli = self.create_interface()
return self._cli | Makes the interface or refreshes it |
def get_rand_string(length=12, allowed_chars='0123456789abcdef'):
if not using_sysrandom:
random.seed(
hashlib.sha256(
("%s%s" % (
random.getstate(),
time.time())).encode('utf-8')
).digest())
return ''.join([random.choice(al... | Returns a securely generated random string. Taken from the Django project
The default length of 12 with the a-z, A-Z, 0-9 character set returns
a 71-bit value. log_2((26+26+10)^12) =~ 71 bits |
def _request(self, url, params={}):
r = self._session.get(url=url, params=params, headers=DEFAULT_ORIGIN)
return r | Makes a request using the currently open session.
:param url: A url fragment to use in the creation of the master url |
def focus_next(self, count=1):
" Focus the next pane. "
panes = self.panes
if panes:
self.active_pane = panes[(panes.index(self.active_pane) + count) % len(panes)]
else:
self.active_pane = None | Focus the next pane. |
def get(self, *args, **kwargs):
self.before_get(args, kwargs)
relationship_field, model_relationship_field, related_type_, related_id_field = self._get_relationship_data()
obj, data = self._data_layer.get_relationship(model_relationship_field,
... | Get a relationship details |
def SCISetStyling(self, line: int, col: int,
numChar: int, style: bytearray):
if not self.isPositionValid(line, col):
return
pos = self.positionFromLineIndex(line, col)
self.SendScintilla(self.SCI_STARTSTYLING, pos, 0xFF)
self.SendScintilla(self.SCI_SETS... | Pythonic wrapper for the SCI_SETSTYLING command.
For example, the following code applies style #3
to the first five characters in the second line
of the widget:
SCISetStyling((0, 1), 5, 3)
|Args|
* ``line`` (**int**): line number where to start styling.
* ... |
def browserify_libs(lib_dirs, output_file, babelify=False):
from .modules import browserify
if not isinstance(lib_dirs, (list, tuple)):
raise RuntimeError('Browserify Libs compiler takes a list of library directories as input.')
return {
'dependencies_fn': browserify.browserify_deps_libs,
... | Browserify one or more library directories into a single
javascript file. Generates source maps in debug mode. Minifies the
output in release mode.
The final directory name in each of lib_dirs is the library name
for importing. Eg.::
lib_dirs = ['cordova_libs/jskit']
var MyClass = req... |
def stringc(text, color):
if has_colors:
text = str(text)
return "\033["+codeCodes[color]+"m"+text+"\033[0m"
else:
return text | Return a string with terminal colors. |
def _get_jmx_data(self, instance, jmx_address, tags):
response = self._rest_request_to_json(
instance, jmx_address, self.JMX_PATH, {'qry': self.HDFS_DATANODE_BEAN_NAME}, tags=tags
)
beans = response.get('beans', [])
return beans | Get namenode beans data from JMX endpoint |
def is_circumpolar(self, var):
xcoord = self.get_x(var)
return xcoord is not None and xcoord.ndim == 2 | Test if a variable is on a circumpolar grid
Parameters
----------
%(CFDecoder.is_triangular.parameters)s
Returns
-------
%(CFDecoder.is_triangular.returns)s |
def on_pumprequest(self, event):
self.log("Updating pump status: ", event.controlvalue)
self._set_digital_pin(self._pump_channel, event.controlvalue) | Activates or deactivates a connected pump.
:param event: |
def all_tamil( word_in ):
if isinstance(word_in,list):
word = word_in
else:
word = get_letters( word_in )
return all( [(letter in tamil_letters) for letter in word] ) | predicate checks if all letters of the input word are Tamil letters |
def _itertuples(df):
cols = [df.iloc[:, k] for k in range(len(df.columns))]
return zip(df.index, *cols) | Custom implementation of ``DataFrame.itertuples`` that
returns plain tuples instead of namedtuples. About 50% faster. |
def _get_protocol_tuple(data: Dict[str, Any]) -> Tuple[str, List, Dict]:
return data['function'], data.get('args', []), data.get('kwargs', {}) | Convert a dictionary to a tuple. |
def html_encode(path):
if sys.version_info > (3, 2, 0):
return urllib.parse.quote(utils.ensure_string(path))
else:
return urllib.quote(utils.ensure_string(path)) | Return an HTML encoded Path.
:param path: ``str``
:return: ``str`` |
def timer(fun, *a, **k):
@wraps(fun)
def timer(*a, **k):
start = arrow.now()
ret = fun(*a, **k)
end = arrow.now()
print('timer:fun: %s\n start:%s,end:%s, took [%s]' % (
str(fun), str(start), str(end), str(end - start)))
return ret
return timer | define a timer for a rule function
for log and statistic purposes |
def to_datetimeindex(self, unsafe=False):
nptimes = cftime_to_nptime(self)
calendar = infer_calendar_name(self)
if calendar not in _STANDARD_CALENDARS and not unsafe:
warnings.warn(
'Converting a CFTimeIndex with dates from a non-standard '
'calendar, ... | If possible, convert this index to a pandas.DatetimeIndex.
Parameters
----------
unsafe : bool
Flag to turn off warning when converting from a CFTimeIndex with
a non-standard calendar to a DatetimeIndex (default ``False``).
Returns
-------
pandas... |
def pull(args):
p = OptionParser(pull.__doc__)
opts, args = p.parse_args(args)
if len(args) != 3:
sys.exit(not p.print_help())
prefix = get_prefix()
version, partID, unitigID = args
s = ".".join(args)
cmd = "tigStore"
cmd += " -g ../{0}.gkpStore -t ../{0}.tigStore".format(prefix)... | %prog pull version partID unitigID
For example, `%prog pull 5 530` will pull the utg530 from partition 5
The layout is written to `unitig530` |
def div(self, y):
r
y = np.asanyarray(y)
if y.shape[0] != self.Ne:
raise ValueError('First dimension must be the number of edges '
'G.Ne = {}, got {}.'.format(self.Ne, y.shape))
return self.D.dot(y) | r"""Compute the divergence of a signal defined on the edges.
The divergence :math:`z` of a signal :math:`y` is defined as
.. math:: z = \operatorname{div}_\mathcal{G} y = D y,
where :math:`D` is the differential operator :attr:`D`.
The value of the divergence on the vertex :math:`v_i... |
def load_scheduler_plugins(self):
if not self.scheduler_plugins:
for entry_point in CINQ_PLUGINS['cloud_inquisitor.plugins.schedulers']['plugins']:
cls = entry_point.load()
self.scheduler_plugins[cls.__name__] = cls
if cls.__name__ == self.active_sched... | Refresh the list of available schedulers
Returns:
`list` of :obj:`BaseScheduler` |
def coherence_spectrogram(self, other, stride, fftlength=None,
overlap=None, window='hann', nproc=1):
from ..spectrogram.coherence import from_timeseries
return from_timeseries(self, other, stride, fftlength=fftlength,
overlap=overlap, window=... | Calculate the coherence spectrogram between this `TimeSeries`
and other.
Parameters
----------
other : `TimeSeries`
the second `TimeSeries` in this CSD calculation
stride : `float`
number of seconds in single PSD (column of spectrogram)
fftlengt... |
def _state_connecting(self):
def responseReceived(protocol):
self.makeConnection(protocol)
if self._state == 'aborting':
self._toState('disconnecting')
else:
self._toState('connected')
def trapError(failure):
self._toState('... | A connection is being started.
A succesful attempt results in the state C{'connected'} when the
first response from Twitter has been received. Transitioning
to the state C{'aborting'} will cause an immediate disconnect instead,
by transitioning to C{'disconnecting'}.
Errors wil... |
def explain_prediction_sklearn(estimator, doc,
vec=None,
top=None,
top_targets=None,
target_names=None,
targets=None,
feature_names=No... | Return an explanation of a scikit-learn estimator |
def _conn(commit=False):
defaults = {'host': 'localhost',
'user': 'salt',
'password': 'salt',
'dbname': 'salt',
'port': 5432}
conn_kwargs = {}
for key, value in defaults.items():
conn_kwargs[key] = __opts__.get('queue.{0}.{1}'.format(__... | Return an postgres cursor |
def cli(env, identifier):
vsi = SoftLayer.VSManager(env.client)
vs_id = helpers.resolve_id(vsi.resolve_ids, identifier, 'VS')
instance = vsi.get_instance(vs_id)
table = formatting.Table(['username', 'password'])
for item in instance['operatingSystem']['passwords']:
table.add_row([item['usern... | List virtual server credentials. |
def get_model_class(self):
if getattr(self, 'model', None):
return self.model
elif getattr(self, 'object', None):
return self.object.__class__
elif 'app' in self.kwargs and 'model' in self.kwargs:
return apps.get_model(self.kwargs.get('app'), self.kwargs.get('... | Get model class |
def _validate_json_for_regular_workflow(json_spec, args):
validated = {}
override_project_id, override_folder, override_workflow_name = \
dxpy.executable_builder.get_parsed_destination(args.destination)
validated['project'] = _get_destination_project(json_spec, args, override_project_id)
validat... | Validates fields used only for building a regular, project-based workflow. |
def extend_dict_key_value(
in_dict,
keys,
value,
delimiter=DEFAULT_TARGET_DELIM,
ordered_dict=False):
dict_pointer, last_key = _dict_rpartition(
in_dict,
keys,
delimiter=delimiter,
ordered_dict=ordered_dict)
if last_key not in dict_pointer ... | Ensures that in_dict contains the series of recursive keys defined in keys.
Also extends the list, that is at the end of `in_dict` traversed with `keys`,
with `value`.
:param dict in_dict: The dictionary to work with
:param str keys: The delimited string with one or more keys.
:param any value: The... |
def two_way_portal(self, other, **stats):
return self.character.new_portal(
self, other, symmetrical=True, **stats
) | Connect these nodes with a two-way portal and return it. |
def readCovarianceMatrixFile(cfile,readCov=True,readEig=True):
covFile = cfile+'.cov'
evalFile = cfile+'.cov.eval'
evecFile = cfile+'.cov.evec'
RV = {}
if readCov:
assert os.path.exists(covFile), '%s is missing.'%covFile
RV['K'] = SP.loadtxt(covFile)
if readEig:
assert os... | reading in similarity matrix
cfile File containing the covariance matrix. The corresponding ID file must be specified in cfile.id) |
def parse_args(args=None):
parser = argparse.ArgumentParser()
parser.add_argument(
'-w', '--window',
default="pyqt5",
choices=find_window_classes(),
help='Name for the window type to use',
)
parser.add_argument(
'-fs', '--fullscreen',
action="sto... | Parse arguments from sys.argv |
def copy(self):
df = super(Ensemble,self).copy()
return type(self).from_dataframe(df=df) | make a deep copy of self
Returns
-------
Ensemble : Ensemble |
def _expected_condition_value_in_element_attribute(self, element_attribute_value):
element, attribute, value = element_attribute_value
web_element = self._expected_condition_find_element(element)
try:
return web_element if web_element and web_element.get_attribute(attribute) == value... | Tries to find the element and checks that it contains the requested attribute with the expected value,
but does not thrown an exception if the element is not found
:param element_attribute_value: Tuple with 3 items where:
[0] element: PageElement or element locator as a tuple (locator_ty... |
def horiz_rows(labels, data, normal_dat, args, colors):
val_min = find_min(data)
for i in range(len(labels)):
if args['no_labels']:
label = ''
else:
label = "{:<{x}}: ".format(labels[i],
x=find_max_label_length(labels))
value... | Prepare the horizontal graph.
Each row is printed through the print_row function. |
def formfield_for_foreignkey_helper(inline, *args, **kwargs):
db_field = args[0]
if db_field.name != "related_type":
return args, kwargs
initial_filter = getattr(settings, RELATED_TYPE_INITIAL_FILTER,
False)
if "initial" not in kwargs and initial_filter:
initial = RelatedType... | The implementation for ``RelatedContentInline.formfield_for_foreignkey``
This takes the takes all of the ``args`` and ``kwargs`` from the call to
``formfield_for_foreignkey`` and operates on this. It returns the updated
``args`` and ``kwargs`` to be passed on to ``super``.
This is solely an implement... |
def update_entitlement(owner, repo, identifier, name, token, show_tokens):
client = get_entitlements_api()
data = {}
if name is not None:
data["name"] = name
if token is not None:
data["token"] = token
with catch_raise_api_exception():
data, _, headers = client.entitlements_p... | Update an entitlement in a repository. |
def has_edge(self, edge):
u, v = edge
return (u, v) in self.edge_properties | Return whether an edge exists.
@type edge: tuple
@param edge: Edge.
@rtype: boolean
@return: Truth-value for edge existence. |
def decode(decoder, data, length, frame_size, decode_fec, channels=2):
pcm_size = frame_size * channels * ctypes.sizeof(ctypes.c_int16)
pcm = (ctypes.c_int16 * pcm_size)()
pcm_pointer = ctypes.cast(pcm, c_int16_pointer)
decode_fec = int(bool(decode_fec))
result = _decode(decoder, data, length, pcm_p... | Decode an Opus frame
Unlike the `opus_decode` function , this function takes an additional parameter `channels`,
which indicates the number of channels in the frame |
def get_stats_display_width(self, curse_msg, without_option=False):
try:
if without_option:
c = len(max(''.join([(u(u(nativestr(i['msg'])).encode('ascii', 'replace')) if not i['optional'] else "")
for i in curse_msg['msgdict']]).split('\n'), key=l... | Return the width of the formatted curses message. |
def generate_additional_context(self, matching_datasets):
dataset_ids = [upload.id for upload in matching_datasets]
tags = Tag.objects.filter(
dataset__in=dataset_ids
).distinct().annotate(
Count('word')
).order_by('-word__count')[:5]
hubs = matching_datas... | Return additional information about matching datasets.
Includes upload counts, related hubs, related tags. |
def dirname(self, path):
if self.is_ssh(path):
remotepath = self._get_remote(path)
remotedir = os.path.dirname(remotepath)
return self._get_tramp_path(remotedir)
else:
return os.path.dirname(path) | Returns the full path to the parent directory of the specified
file path. |
def save_region(region, filename):
region.save(filename)
logging.info("Wrote {0}".format(filename))
return | Save the given region to a file
Parameters
----------
region : :class:`AegeanTools.regions.Region`
A region.
filename : str
Output file name. |
def _writeOptionalXsecCards(self, fileObject, xSec, replaceParamFile):
if xSec.erode:
fileObject.write('ERODE\n')
if xSec.maxErosion != None:
fileObject.write('MAX_EROSION %.6f\n' % xSec.maxErosion)
if xSec.subsurface:
fileObject.write('SUBSURFACE\n')
... | Write Optional Cross Section Cards to File Method |
def serialize_cert_to_der(cert_obj):
return cert_obj.public_bytes(
cryptography.hazmat.primitives.serialization.Encoding.DER
) | Serialize certificate to DER.
Args:
cert_obj: cryptography.Certificate
Returns:
bytes: DER encoded certificate |
def update(self, new_keys: Index):
if not self._map.index.intersection(new_keys).empty:
raise KeyError("Non-unique keys in index.")
mapping_update = self.hash_(new_keys)
if self._map.empty:
self._map = mapping_update.drop_duplicates()
else:
self._map =... | Adds the new keys to the mapping.
Parameters
----------
new_keys :
The new index to hash. |
def generate(self, overwrite=False):
super(Upstart, self).generate(overwrite=overwrite)
svc_file_template = self.template_prefix + '.conf'
self.svc_file_path = self.generate_into_prefix + '.conf'
self.generate_file_from_template(svc_file_template, self.svc_file_path)
return self.... | Generate a config file for an upstart service. |
def _example_short_number(region_code):
metadata = PhoneMetadata.short_metadata_for_region(region_code)
if metadata is None:
return U_EMPTY_STRING
desc = metadata.short_code
if desc.example_number is not None:
return desc.example_number
return U_EMPTY_STRING | Gets a valid short number for the specified region.
Arguments:
region_code -- the region for which an example short number is needed.
Returns a valid short number for the specified region. Returns an empty
string when the metadata does not contain such information. |
def get_final_path(path):
r
desired_access = api.NULL
share_mode = (
api.FILE_SHARE_READ | api.FILE_SHARE_WRITE | api.FILE_SHARE_DELETE
)
security_attributes = api.LPSECURITY_ATTRIBUTES()
hFile = api.CreateFile(
path,
desired_access,
share_mode,
security_attributes,
api.OPEN_EXISTING,
api.FILE_FLAG_... | r"""
For a given path, determine the ultimate location of that path.
Useful for resolving symlink targets.
This functions wraps the GetFinalPathNameByHandle from the Windows
SDK.
Note, this function fails if a handle cannot be obtained (such as
for C:\Pagefile.sys on a stock windows system). Consider using
trac... |
def dump(self):
return json.dumps(
self.primitive,
sort_keys=True,
ensure_ascii=False,
separators=(',', ':')) | Item as a JSON representation. |
def delete(self, template_name):
template = db.Template.find_one(template_name=template_name)
if not template:
return self.make_response('No such template found', HTTP.NOT_FOUND)
db.session.delete(template)
db.session.commit()
auditlog(event='template.delete', actor=s... | Delete a template |
def pi (self, data):
data = data.encode(self.encoding, "ignore")
self.fd.write("<?%s?>" % data) | Print HTML pi.
@param data: the tag data
@type data: string
@return: None |
def _get_animation_frames(self, all_datasets, shape, fill_value=None,
ignore_missing=False):
for idx, ds in enumerate(all_datasets):
if ds is None and ignore_missing:
continue
elif ds is None:
log.debug("Missing frame: %d", id... | Create enhanced image frames to save to a file. |
def _emiss_ep(self, Eph):
if self.weight_ep == 0.0:
return np.zeros_like(Eph)
gam = np.vstack(self._gam)
eps = (Eph / mec2).decompose().value
emiss = c.cgs * trapz_loglog(
np.vstack(self._nelec) * self._sigma_ep(gam, eps),
self._gam,
axis=0... | Electron-proton bremsstrahlung emissivity per unit photon energy |
def get_from_ident(self, ident):
model_repr, job_pk = ident.split(':', 1)
klass = import_class(model_repr)
return klass.get(job_pk) | Take a string as returned by get_ident and return a job,
based on the class representation and the job's pk from the ident |
def _idx_table_by_name(tables, crumbs):
_tables = OrderedDict()
try:
for _idx, _table in enumerate(tables):
_name = "{}{}".format(crumbs, _idx)
_tmp = _idx_col_by_name(_table)
if _name in _tables:
_name = "{}_{}".format(_name, _idx)
_tmp["t... | Import summary, ensemble, or distribution data.
:param list tables: Metadata
:return dict _tables: Metadata |
def avail_images(call=None):
all_servers = list_nodes_full()
templates = {}
for server in all_servers:
if server["IsTemplate"]:
templates.update({"Template Name": server["Name"]})
return templates | returns a list of images available to you |
def urls(self):
for base_url, mapping in self.routes.items():
for url, _ in mapping.items():
yield base_url + url | Returns a generator of all URLs attached to this API |
def _valid_headerline(l):
if not l:
return False
headers = l.split('\t')
first_col = headers[0]
tsplit = first_col.split(':')
if len(tsplit) != 2:
return False
if tsplit[0] in ('entity', 'update'):
return tsplit[1] in ('participant_id', 'participant_set_id',
... | return true if the given string is a valid loadfile header |
def remove_interface_router(self, router, body=None):
return self.put((self.router_path % router) +
"/remove_router_interface", body=body) | Removes an internal network interface from the specified router. |
def scan_on_disk(node, env, path=()):
try:
flist = node.fs.listdir(node.get_abspath())
except (IOError, OSError):
return []
e = node.Entry
for f in filter(do_not_scan, flist):
e('./' + f)
return scan_in_memory(node, env, path) | Scans a directory for on-disk files and directories therein.
Looking up the entries will add these to the in-memory Node tree
representation of the file system, so all we have to do is just
that and then call the in-memory scanning function. |
def add_sidebar(self, component: Component) -> None:
if not self.sidebar:
raise NoSidebarError('Set `sidebar=True` if you want to use the sidebar.')
if not isinstance(component, Component):
raise ValueError('component must be Component type, found {}'.format(component))
s... | Add a widget to the sidebar.
Parameters
----------
component : bowtie._Component
Add this component to the sidebar, it will be appended to the end. |
def network_get(auth=None, **kwargs):
cloud = get_operator_cloud(auth)
kwargs = _clean_kwargs(**kwargs)
return cloud.get_network(**kwargs) | Get a single network
filters
A Python dictionary of filter conditions to push down
CLI Example:
.. code-block:: bash
salt '*' neutronng.network_get name=XLB4 |
def notes(self):
return tuple(self._get_note_data(note) for note in self.root.iter('note')) | Tuple of notes.. |
def store_job(self):
try:
class_name = self.__class__.__name__.lower()
except AttributeError:
log.warning(
'Unable to determine class name',
exc_info_on_loglevel=logging.DEBUG
)
return True
try:
return se... | Helper that allows us to turn off storing jobs for different classes
that may incorporate this mixin. |
def size(self, key, resource_type):
with self._objects_queue_lock:
return len(self._objects_queue[key].get(resource_type, [])) | Return the size of the queue for a given key and resource type.
If the key is not in the cache, this will raise a KeyError. |
def get_consumer_info(self, instance, cursor):
cursor.execute(self.CONSUMER_INFO_STATEMENT)
for queue_name, consumer_name, lag, pending_events, last_seen in cursor:
yield queue_name, consumer_name, {
'lag': lag,
'pending_events': pending_events,
... | Collects metrics for all consumers on the connected database. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.