Unnamed: 0 int64 0 389k | code stringlengths 26 79.6k | docstring stringlengths 1 46.9k |
|---|---|---|
5,100 | def synset(self, synset_repr):
funktionieren.v.2
parts = synset_repr.split()
if len(parts) != 3:
return None
lemma, pos, sensenum = parts
if not sensenum.isdigit() or pos not in SHORT_POS_TO_LONG:
return None
sensenum = int(sensenum, 10)
... | Looks up a synset in GermaNet using its string representation.
Arguments:
- `synset_repr`: a unicode string containing the lemma, part
of speech, and sense number of the first lemma of the synset
>>> gn.synset(u'funktionieren.v.2')
Synset(funktionieren.v.2) |
5,101 | def open_file(self, title="Open File", initialDir="~", fileTypes="*|All Files", rememberAs=None, **kwargs):
if rememberAs is not None:
return self._run_kdialog(title, ["--getopenfilename", initialDir, fileTypes, ":" + rememberAs], kwargs)
else:
return self._run_kdialog(t... | Show an Open File dialog
Usage: C{dialog.open_file(title="Open File", initialDir="~", fileTypes="*|All Files", rememberAs=None, **kwargs)}
@param title: window title for the dialog
@param initialDir: starting directory for the file dialog
@param fileTypes: file type fil... |
5,102 | def _distance_matrix(self, a, b):
def sq(x): return (x * x)
matrix = sq(a[:, 0][:, None] - b[:, 0][None, :])
for x, y in zip(a.T[1:], b.T[1:]):
matrix += sq(x[:, None] - y[None, :])
return matrix | Pairwise distance between each point in `a` and each point in `b` |
5,103 | def analyse_text(text):
result = 0.0
lines = text.split()
hasEndProc = False
hasHeaderComment = False
hasFile = False
hasJob = False
hasProc = False
hasParm = False
hasReport = False
def isCommentLine(line):
return Eas... | Perform a structural analysis for basic Easytrieve constructs. |
5,104 | def verification_email_body(case_name, url, display_name, category, subcategory, breakpoint_1, breakpoint_2, hgnc_symbol, panels, gtcalls, tx_changes, name, comment):
html = .format(
case_name=case_name,
url=url,
display_name=display_name,
category=category,
subcategory=... | Builds the html code for the variant verification emails (order verification and cancel verification)
Args:
case_name(str): case display name
url(str): the complete url to the variant, accessible when clicking on the email link
display_name(str): a display name for the varia... |
5,105 | def clear(self):
self._wlock.acquire()
try:
self._mapping.clear()
self._queue.clear()
finally:
self._wlock.release() | Clear the cache. |
5,106 | def create_trie(self):
trie = SourceRootTrie(self.source_root_factory)
options = self.get_options()
for category in SourceRootCategories.ALL:
for pattern in options.get(.format(category), []):
trie.add_pattern(pattern, category)
for path, langs in options.get(.format(... | Create a trie of source root patterns from options.
:returns: :class:`SourceRootTrie` |
5,107 | def edit_project(self, id_, **kwargs):
data = self._wrap_dict("project", kwargs)
return self.patch("/projects/{}.json".format(id_), data=data) | Edits a project by ID. All fields available at creation can be updated
as well. If you want to update hourly rates retroactively, set the
argument `update_hourly_rate_on_time_entries` to True. |
5,108 | def get_least_common_subsumer(self,from_tid,to_tid):
termid_from = self.terminal_for_term.get(from_tid)
termid_to = self.terminal_for_term.get(to_tid)
path_from = self.paths_for_terminal[termid_from][0]
path_to = self.paths_for_terminal[termid_to][0]
common_node... | Returns the deepest common subsumer among two terms
@type from_tid: string
@param from_tid: one term id
@type to_tid: string
@param to_tid: another term id
@rtype: string
@return: the term identifier of the common subsumer |
5,109 | def config_control(inherit_napalm_device=None, **kwargs):
*
result = True
comment =
changed, not_changed_rsn = config_changed(inherit_napalm_device=napalm_device)
if not changed:
return (changed, not_changed_rsn)
Will try to rollback now!commentresult\nCannot rollback! ... | Will check if the configuration was changed.
If differences found, will try to commit.
In case commit unsuccessful, will try to rollback.
:return: A tuple with a boolean that specifies if the config was changed/committed/rollbacked on the device.\
And a string that provides more details of the reason w... |
5,110 | def sam_readline(sock, partial = None):
response = b
exception = None
while True:
try:
c = sock.recv(1)
if not c:
raise EOFError( % (partial, response))
elif c == b:
break
else:
response += c
... | read a line from a sam control socket |
5,111 | def __tag_repo(self, data, repository):
assert self.__tag_name not in [t.name for t in repository.tags]
return TagReference.create(repository, self.__tag_name, message=json.dumps(data)) | Tag the current repository.
:param data: a dictionary containing the data about the experiment
:type data: dict |
5,112 | def is_user(value, min=None, max=None):
if type(value) == str:
try:
entry = pwd.getpwnam(value)
value = entry.pw_uid
except KeyError:
err_message = (.format(value))
raise validate.VdtValueError(err_message)
return value
elif type(va... | Check whether username or uid as argument exists.
if this function recieved username, convert uid and exec validation. |
5,113 | def _get_cibfile_cksum(cibname):
cibfile_cksum = .format(_get_cibfile(cibname))
log.trace(, cibfile_cksum)
return cibfile_cksum | Get the full path of the file containing a checksum of a CIB-file with the name of the CIB |
5,114 | def derive_random_states(random_state, n=1):
seed_ = random_state.randint(SEED_MIN_VALUE, SEED_MAX_VALUE, 1)[0]
return [new_random_state(seed_+i) for i in sm.xrange(n)] | Create N new random states based on an existing random state or seed.
Parameters
----------
random_state : numpy.random.RandomState
Random state or seed from which to derive new random states.
n : int, optional
Number of random states to derive.
Returns
-------
list of num... |
5,115 | def get_phrases(self, ns=None, layer=, cat_key=, cat_val=):
if not ns:
ns = self.ns
for node_id in select_nodes_by_layer(self, .format(ns, layer)):
if self.node[node_id][self.ns++cat_key] == cat_val:
yield node_id | yield all node IDs that dominate the given phrase type, e.g. all NPs |
5,116 | def parseExternalSubset(self, ExternalID, SystemID):
libxml2mod.xmlParseExternalSubset(self._o, ExternalID, SystemID) | parse Markup declarations from an external subset [30]
extSubset ::= textDecl? extSubsetDecl [31] extSubsetDecl
::= (markupdecl | conditionalSect | PEReference | S) * |
5,117 | def __last_commit(self):
cmd = [, ]
op = self.sh(cmd, shell=False)
if not op:
return None
author, rev, datestr = op.split()[7:10]
author = author.split(, 1)[1].strip()
rev = rev.split(, 1)[1].strip()
datestr = datestr.split(, 1)[1].split(, 1)[... | Retrieve the most recent commit message (with ``svn info``)
Returns:
tuple: (datestr, (revno, user, None, desc))
$ svn info
Path: .
URL: http://python-dlp.googlecode.com/svn/trunk/layercake-python
Repository Root: http://python-dlp.googlecode.com/svn
Reposit... |
5,118 | def find_tool(name, additional_paths = [], path_last = False):
assert isinstance(name, basestring)
assert is_iterable_typed(additional_paths, basestring)
assert isinstance(path_last, (int, bool))
programs = path.programs_path()
match = path.glob(programs, [name, name + ])
additional_match ... | Attempts to find tool (binary) named 'name' in PATH and in
'additional-paths'. If found in path, returns 'name'. If
found in additional paths, returns full name. If the tool
is found in several directories, returns the first path found.
Otherwise, returns the empty string. If 'path_l... |
5,119 | def resolve_relative_paths(paths: List[str]) -> Dict[str, str]:
buck_root = find_buck_root(os.getcwd())
if buck_root is None:
LOG.error(
"Buck root couldn't be found. Returning empty analysis directory mapping."
)
return {}
command = [
"buck",
"query"... | Query buck to obtain a mapping from each absolute path to the relative
location in the analysis directory. |
5,120 | def get_spam_checker(backend_path):
try:
backend_module = import_module(backend_path)
backend = getattr(backend_module, )
except (ImportError, AttributeError):
warnings.warn( % backend_path,
RuntimeWarning)
backend = None
except ImproperlyConfigured... | Return the selected spam checker backend. |
5,121 | def ssh_file(opts, dest_path, contents=None, kwargs=None, local_file=None):
if opts.get(, ) == :
return sftp_file(dest_path, contents, kwargs, local_file)
return scp_file(dest_path, contents, kwargs, local_file) | Copies a file to the remote SSH target using either sftp or scp, as
configured. |
5,122 | def unique_list(input_list):
r
output_list = []
if len(input_list) > 0:
dim = _sp.shape(input_list)[1]
for i in input_list:
match = False
for j in output_list:
if dim == 3:
if i[0] == j[0] and i[1] == j[1] and i[2] == j[2]:
... | r"""
For a given list (of points) remove any duplicates |
5,123 | def _tensor_product(t1, t2):
return tf.matmul(tf.expand_dims(t1, axis=-1), tf.expand_dims(t2, axis=-2)) | Computes the outer product of two possibly batched vectors.
Args:
t1: A `tf.Tensor` of shape `[..., n]`.
t2: A `tf.Tensor` of shape `[..., m]`.
Returns:
A tensor of shape `[..., n, m]` with matching batch dimensions, let's call
it `r`, whose components are:
```None
r[..., i, j] = t1[...... |
5,124 | def _set_kernel_manager(self, kernel_manager):
old_manager = self._kernel_manager
if old_manager is not None:
old_manager.started_kernel.disconnect(self._started_kernel)
old_manager.started_channels.disconnect(self._started_channels)
old_manager.stop... | Disconnect from the current kernel manager (if any) and set a new
kernel manager. |
5,125 | def inserir(self, name):
division_dc_map = dict()
division_dc_map[] = name
code, xml = self.submit(
{: division_dc_map}, , )
return self.response(code, xml) | Inserts a new Division Dc and returns its identifier.
:param name: Division Dc name. String with a minimum 2 and maximum of 80 characters
:return: Dictionary with the following structure:
::
{'division_dc': {'id': < id_division_dc >}}
:raise InvalidParameterError: Name i... |
5,126 | def _write_zip(self, func_src, fpath):
now = datetime.now()
zi_tup = (now.year, now.month, now.day, now.hour, now.minute,
now.second)
logger.debug(, zi_tup)
zinfo = zipfile.ZipInfo(, zi_tup)
zinfo.external_attr = 0x0755 << 16
... | Write the function source to a zip file, suitable for upload to
Lambda.
Note there's a bit of undocumented magic going on here; Lambda needs
the execute bit set on the module with the handler in it (i.e. 0755
or 0555 permissions). There doesn't seem to be *any* documentation on
... |
5,127 | def add_key_filters(self, key_filters):
if self._input_mode == :
raise ValueError()
self._key_filters.extend(key_filters)
return self | Adds key filters to the inputs.
:param key_filters: a list of filters
:type key_filters: list
:rtype: :class:`RiakMapReduce` |
5,128 | def pretty_print(rows, keyword, domain):
if isinstance(rows, dict):
pretty_print_domain(rows, keyword, domain)
elif isinstance(rows, list):
pretty_print_zones(rows) | rows is
list when get domains
dict when get specific domain |
5,129 | def get_common_path(pathlist):
common = osp.normpath(osp.commonprefix(pathlist))
if len(common) > 1:
if not osp.isdir(common):
return abspardir(common)
else:
for path in pathlist:
if not osp.isdir(osp.join(common, path[len(common)+1:])):
... | Return common path for all paths in pathlist |
5,130 | def process_ipvsix_frame(self,
id=None,
msg=None):
df = json_normalize(msg)
dt = json.loads(df.to_json())
flat_msg = {}
for k in dt:
new_key = "ipv6_{}".format(k)
flat_msg[new_... | process_ipvsix_frame
Convert a complex nested json dictionary
to a flattened dictionary and capture
all unique keys for table construction
:param id: key for this msg
:param msg: ipv6 frame for packet |
5,131 | def GetFeatureService(self, itemId, returnURLOnly=False):
admin = None
item = None
try:
admin = arcrest.manageorg.Administration(securityHandler=self._securityHandler)
if self._securityHandler.valid == False:
self._valid = self._securityHandler.va... | Obtains a feature service by item ID.
Args:
itemId (str): The feature service's item ID.
returnURLOnly (bool): A boolean value to return the URL of the feature service. Defaults to ``False``.
Returns:
When ``returnURLOnly`` is ``True``, the URL of the feature service... |
5,132 | def source_csv_to_pandas(path, table, read_csv_args=None):
if not in table:
table +=
if isinstance(path, dict):
data_obj = path[table]
f = data_obj.split("\n")
else:
if os.path.isdir(path):
f = open(os.path.join(path, table))
else:
z ... | Parameters
----------
path: str
path to directory or zipfile
table: str
name of table
read_csv_args:
string arguments passed to the read_csv function
Returns
-------
df: pandas:DataFrame |
5,133 | def _init_goslims(self, dagslim):
go2obj_main = self.gosubdag.go2obj
go2obj_slim = {go for go, o in dagslim.items() if go in go2obj_main}
if self.gosubdag.relationships:
return self._get_goslimids_norel(go2obj_slim)
return set(dagslim.keys()) | Get GO IDs in GO slims. |
5,134 | def as_dict(self):
d = {"@module": self.__class__.__module__,
"@class": self.__class__.__name__}
if self.x is not None: d["x"] = self.x.as_dict()
if self.c is not None: d["c"] = self.c.as_dict()
if self.xc is not None: d["xc"] = self.xc.as_dict()
re... | Makes XcFunc obey the general json interface used in pymatgen for easier serialization. |
5,135 | def get_week_URL(date, day=0):
if day < 1:
day = 1
date = datetime(year=date.year, month=date.month, day=day, tzinfo=utc)
return reverse(, kwargs={: date.isocalendar()[0],
: date.isocalendar()[1]}) | Returns the week view URL for a given date.
:param date: A date instance.
:param day: Day number in a month. |
5,136 | def number(self, assignment_class=None, namespace=):
if assignment_class == :
n = str(DatasetNumber())
return n | Return a new number.
:param assignment_class: Determines the length of the number. Possible values are 'authority' (3 characters) ,
'registered' (5) , 'unregistered' (7) and 'self' (9). Self assigned numbers are random and acquired locally,
while the other assignment classes use the nu... |
5,137 | def gauss_fit(X, Y):
X = np.asarray(X)
Y = np.asarray(Y)
Y[Y < 0] = 0
def gauss(x, a, x0, sigma):
return a * np.exp(-(x - x0)**2 / (2 * sigma**2))
mean = (X * Y).sum() / Y.sum()
sigma = np.sqrt((Y * ((X - mean)**2)).sum() / Y.sum())
height = Y.max()
retu... | Fit the function to a gaussian.
Parameters
----------
X: 1d array
X values
Y: 1d array
Y values
Returns
-------
(The return from scipy.optimize.curve_fit)
popt : array
Optimal values for the parameters
pcov : 2d array
The estimated covariance of popt... |
5,138 | def get_raw_data(self, url, *args, **kwargs):
res = self._conn.get(url, headers=self._prepare_headers(**kwargs))
if res.status_code == 200:
return res.content
else:
return None | Gets data from url as bytes
Returns content under the provided url as bytes
ie. for binary data
Args:
**url**: address of the wanted data
.. versionadded:: 0.3.2
**additional_headers**: (optional) Additional headers
to be used with reque... |
5,139 | def GetAttachmentIdFromMediaId(media_id):
altchars =
if not six.PY2:
altchars = altchars.encode()
buffer = base64.b64decode(str(media_id), altchars)
resoure_id_length = 20
attachment_id =
if len(buffer) > resoure_id_length:
attachment_id = base64.b64encode(bu... | Gets attachment id from media id.
:param str media_id:
:return:
The attachment id from the media id.
:rtype: str |
5,140 | def read(self, size=None):
if not self._is_open:
raise IOError()
if self._current_offset < 0:
raise IOError()
if self._current_offset >= self._size:
return b
if size is None or self._current_offset + size > self._size:
size = self._size - self._current_offset
... | Reads a byte string from the file-like object at the current offset.
The function will read a byte string of the specified size or
all of the remaining data if no size was specified.
Args:
size (Optional[int]): number of bytes to read, where None is all
remaining data.
Returns:
... |
5,141 | def _listen(self):
def _listen():
for line in iter(sys.stdin.readline, b""):
try:
response = json.loads(line)
except Exception as e:
thread = threading.Thread(target=_listen... | Listen for messages passed from parent
This method distributes messages received via stdin to their
corresponding channel. Based on the format of the incoming
message, the message is forwarded to its corresponding channel
to be processed by its corresponding handler. |
5,142 | def delete_affinity_group(self, affinity_group_name):
_validate_not_none(, affinity_group_name)
return self._perform_delete( + self.subscription_id + \
+ \
_str(affinity_group_name)) | Deletes an affinity group in the specified subscription.
affinity_group_name:
The name of the affinity group. |
5,143 | def error_codes(self):
if self._error_codes is None:
from .tcex_error_codes import TcExErrorCodes
self._error_codes = TcExErrorCodes()
return self._error_codes | ThreatConnect error codes. |
5,144 | def decrypt(self, msg):
error = False
signature = msg[0:SHA256.digest_size]
iv = msg[SHA256.digest_size:SHA256.digest_size + AES.block_size]
cipher_text = msg[SHA256.digest_size + AES.block_size:]
if self.sign(iv + cipher_text) != signature:
error = True
... | decrypt a message |
5,145 | def info(model=None, markdown=False, silent=False):
msg = Printer()
if model:
if util.is_package(model):
model_path = util.get_package_path(model)
else:
model_path = util.get_data_path() / model
meta_path = model_path / "meta.json"
if not meta_path.is... | Print info about spaCy installation. If a model shortcut link is
speficied as an argument, print model information. Flag --markdown
prints details in Markdown for easy copy-pasting to GitHub issues. |
5,146 | def logical_chassis_fwdl_status_output_cluster_fwdl_entries_rbridge_id(self, **kwargs):
config = ET.Element("config")
logical_chassis_fwdl_status = ET.Element("logical_chassis_fwdl_status")
config = logical_chassis_fwdl_status
output = ET.SubElement(logical_chassis_fwdl_status, ... | Auto Generated Code |
5,147 | def is_address_here(self, address):
base = self.get_base()
size = self.get_size()
if base and size:
return base <= address < (base + size)
return None | Tries to determine if the given address belongs to this module.
@type address: int
@param address: Memory address.
@rtype: bool or None
@return: C{True} if the address belongs to the module,
C{False} if it doesn't,
and C{None} if it can't be determined. |
5,148 | def get_msms_df_on_file(pdb_file, outfile=None, outdir=None, outext=, force_rerun=False):
outfile = ssbio.utils.outfile_maker(inname=pdb_file, outname=outfile, outdir=outdir, outext=outext)
if ssbio.utils.force_rerun(flag=force_rerun, outfile=outfile):
my_structure = StructureIO(pdb_... | Run MSMS (using Biopython) on a PDB file.
Saves a CSV file of:
chain: chain ID
resnum: residue number (PDB numbering)
icode: residue insertion code
res_depth: average depth of all atoms in a residue
ca_depth: depth of the alpha carbon atom
Depths are in units Angstroms.... |
5,149 | def msg_curse(self, args=None, max_width=None):
ret = []
if not self.stats or self.args.percpu or self.is_disable():
return ret
idle_tag = not in self.stats
msg = .format()
ret.append(self.curse_add_li... | Return the list to display in the UI. |
5,150 | def translate_exception(exc_info, initial_skip=0):
tb = exc_info[2]
frames = []
for x in range(initial_skip):
if tb is not None:
tb = tb.tb_next
initial_tb = tb
while tb is not None:
if not frames:
reraise(exc_info[0], exc_info[1], exc_in... | If passed an exc_info it will automatically rewrite the exceptions
all the way down to the correct line numbers and frames. |
5,151 | def parse_from_json(json_str):
try:
message_dict = json.loads(json_str)
except ValueError:
raise ParseError("Mal-formed JSON input.")
upload_keys = message_dict.get(, False)
if upload_keys is False:
raise ParseError(
"uploadKeys does not exist. At minimum, an em... | Given a Unified Uploader message, parse the contents and return a
MarketOrderList or MarketHistoryList instance.
:param str json_str: A Unified Uploader message as a JSON string.
:rtype: MarketOrderList or MarketHistoryList
:raises: MalformedUploadError when invalid JSON is passed in. |
5,152 | def create_unary_node(self, operator, child, param=None, schema=None):
if operator == self.grammar.syntax.select_op:
conditions = .join(flatten(param))
node = SelectNode(child, conditions)
elif operator == self.grammar.syntax.project_op:
node = ProjectNode(... | Return a Unary Node whose type depends on the specified operator.
:param schema:
:param child:
:param operator: A relational algebra operator (see constants.py)
:param param: A list of parameters for the operator.
:return: A Unary Node. |
5,153 | def get_translatable_children(self, obj):
collector = NestedObjects(using=)
collector.collect([obj])
object_list = collector.nested()
items = self.get_elements(object_list)
return items[1:] | Obtain all the translatable children from "obj"
:param obj:
:return: |
5,154 | def package(self):
cmake = self.configure_cmake()
cmake.install()
self.copy(pattern="LICENSE.txt", dst="licenses")
self.copy(pattern="FindFlatBuffers.cmake", dst=os.path.join("lib", "cmake", "flatbuffers"), src="CMake")
self.copy(pattern="flathash*", dst="bin", src="bin"... | Copy Flatbuffers' artifacts to package folder |
5,155 | def _get_sorted_action_keys(self, keys_list):
action_list = []
for key in keys_list:
if key.startswith():
action_list.append(key)
action_list.sort()
return action_list | This function returns only the elements starting with 'action-' in
'keys_list'. The returned list is sorted by the index appended to
the end of each element |
5,156 | def update(self, prms):
with self.sess.as_default():
fetches = []
feeds = {}
for name, value in six.iteritems(prms):
assert name in self.name_map
var = self.name_map[name]
fetches.append(var.initializer)
... | Args:
prms(dict): dict of {variable name: value}
Any name in prms must be in the graph and in vars_to_update. |
5,157 | def zip_job(job_ini, archive_zip=, risk_ini=, oq=None, log=logging.info):
if not os.path.exists(job_ini):
sys.exit( % job_ini)
archive_zip = archive_zip or
if isinstance(archive_zip, str):
if not archive_zip.endswith():
sys.exit( % archive_zip)
if os.path.exists(a... | Zip the given job.ini file into the given archive, together with all
related files. |
5,158 | def get_dataset(self, key, info):
if key.name in [, ]:
logger.debug()
if self.lons is None or self.lats is None:
self.lons, self.lats = self.get_lonlats()
if key.name == :
proj = Dataset(self.lats, id=key, **info)
else:
... | Read data from file and return the corresponding projectables. |
5,159 | def separator_line(cls, sep=, size=10):
if cls.intty():
cls.echo(sep * size) | Display a separator line. |
5,160 | def open(self, pathobj):
url = str(pathobj)
raw, code = self.rest_get_stream(url, auth=pathobj.auth, verify=pathobj.verify,
cert=pathobj.cert)
if not code == 200:
raise RuntimeError("%d" % code)
return raw | Opens the remote file and returns a file-like object HTTPResponse
Given the nature of HTTP streaming, this object doesn't support
seek() |
5,161 | def put(self, url, json=None, data=None, **kwargs):
check_type(url, basestring, may_be_none=False)
erc = kwargs.pop(, EXPECTED_RESPONSE_CODE[])
response = self.request(, url, erc, json=json, data=data,
**kwargs)
return extract_and_parse... | Sends a PUT request.
Args:
url(basestring): The URL of the API endpoint.
json: Data to be sent in JSON format in tbe body of the request.
data: Data to be sent in the body of the request.
**kwargs:
erc(int): The expected (success) response code fo... |
5,162 | def create(self, deal_id, *args, **kwargs):
if not args and not kwargs:
raise Exception()
attributes = args[0] if args else kwargs
attributes = dict((k, v) for k, v in attributes.iteritems() if k in self.OPTS_KEYS_TO_PERSIST)
_, _, associated_contact = self.http_c... | Create an associated contact
Creates a deal's associated contact and its role
If the specified deal or contact does not exist, the request will return an error
:calls: ``post /deals/{deal_id}/associated_contacts``
:param int deal_id: Unique identifier of a Deal.
:param tuple *a... |
5,163 | def envGet(self, name, default=None, conv=None):
if self._env.has_key(name):
if conv is not None:
return conv(self._env.get(name))
else:
return self._env.get(name)
else:
return default | Return value for environment variable or None.
@param name: Name of environment variable.
@param default: Default value if variable is undefined.
@param conv: Function for converting value to desired type.
@return: Value of environment variable. |
5,164 | def crop_at_zero_crossing(gen, seconds=5, error=0.1):
source = iter(gen)
buffer_length = int(2 * error * sampler.FRAME_RATE)
start = itertools.islice(source, 0, int((seconds - error) * sampler.FRAME_RATE))
end = itertools.islice(source, 0, buffer_length)
for sample in start:
yield sample
end =... | Crop the generator, ending at a zero-crossing
Crop the generator to produce approximately seconds seconds
(default 5s) of audio at the provided FRAME_RATE, attempting
to end the clip at a zero crossing point to avoid clicking. |
5,165 | def chunkify(chunksize):
def chunkifier(func):
def wrap(*args):
assert len(args) > 0
assert all(len(a.flat) == len(args[0].flat) for a in args)
nelements = len(args[0].flat)
nchunks, remain = divmod(nelements, chunksize)
out = np.ndarray(... | Very stupid "chunk vectorizer" which keeps memory use down.
This version requires all inputs to have the same number of elements,
although it shouldn't be that hard to implement simple broadcasting. |
5,166 | def to_nullable_map(value):
if value == None:
return None
try:
value = json.loads(value)
return RecursiveMapConverter.to_nullable_map(value)
except:
return None | Converts JSON string into map object or returns null when conversion is not possible.
:param value: the JSON string to convert.
:return: Map object value or null when conversion is not supported. |
5,167 | def uninstall(pkg):
*
ret = {: None, : }
out = __salt__[](FLATPAK_BINARY_NAME + + pkg)
if out[] and out[]:
ret[] = out[].strip()
ret[] = False
else:
ret[] = out[].strip()
ret[] = True
return ret | Uninstall the specified package.
Args:
pkg (str): The package name.
Returns:
dict: The ``result`` and ``output``.
CLI Example:
.. code-block:: bash
salt '*' flatpak.uninstall org.gimp.GIMP |
5,168 | def get_fallback_coord(self,isotope=,masslimit=0.1,masscutlim=False,delay=True):
s prescription.
MINImass cutNi-56O-16found new remnantni56:Ni-56 does not reach 0.1Msun, take old remnant
return minis, fallback_coords | Returns fallback mass coordinate so that the amount of masslimit
of the isotope isotope is ejected. Explosion type chosen with delay option.
masscutlim: If true, new fallback coordinate can only as small as the original fallback
prescription by C. Fryer. Useful for more massive stars which would not eje... |
5,169 | def decode_devid(devid, pname):
devid
devid = int(devid)
if devid == 0:
return
bus_type=devid & 0x07
bus=(devid>>3) & 0x1F
address=(devid>>8)&0xFF
devtype=(devid>>16)
bustypes = {
1: "I2C",
2: "SPI",
3: "UAVCAN",
4: "SITL"
}
compass_... | decode one device ID. Used for 'devid' command in mavproxy and MAVExplorer |
5,170 | def set_mode_loiter(self):
if self.mavlink10():
self.mav.command_long_send(self.target_system, self.target_component,
mavlink.MAV_CMD_NAV_LOITER_UNLIM, 0, 0, 0, 0, 0, 0, 0, 0)
else:
MAV_ACTION_LOITER = 27
self.mav.action... | enter LOITER mode |
5,171 | def rvs(self, size=1, param=None):
if param is not None:
dtype = [(param, float)]
else:
dtype = [(p, float) for p in self.params]
arr = numpy.zeros(size, dtype=dtype)
for (p,_) in dtype:
offset = numpy.power(self._bounds[p][0], self.dim)
... | Gives a set of random values drawn from this distribution.
Parameters
----------
size : {1, int}
The number of values to generate; default is 1.
param : {None, string}
If provided, will just return values for the given parameter.
Otherwise, returns ra... |
5,172 | def create_supercut_in_batches(composition, outputfile, padding):
total_clips = len(composition)
start_index = 0
end_index = BATCH_SIZE
batch_comp = []
while start_index < total_clips:
filename = outputfile + + str(start_index) +
try:
create_supercut(composition[st... | Create & concatenate video clips in groups of size BATCH_SIZE and output
finished video file to output directory. |
5,173 | def execute(self):
from ambry.mprlib import execute_sql
execute_sql(self._bundle.library, self.record_content) | Executes all sql statements from bundle.sql. |
5,174 | def take_snapshot(self, entity_id, entity, last_event_version):
snapshot = Snapshot(
originator_id=entity_id,
originator_version=last_event_version,
topic=get_topic(entity.__class__),
state=None if entity is None else deepcopy(entity.__dict__)
... | Creates a Snapshot from the given state, and appends it
to the snapshot store.
:rtype: Snapshot |
5,175 | def p(i, sample_size, weights):
weight_i = weights[i]
weights_sum = sum(weights)
other_weights = list(weights)
del other_weights[i]
probability_of_i = 0
for picks in range(0, sample_size):
permutati... | Given a weighted set and sample size return the probabilty that the
weight `i` will be present in the sample.
Created to test the output of the `SomeOf` maker class. The math was
provided by Andy Blackshaw - thank you dad :) |
5,176 | def jsonify(self, obj, many=sentinel, *args, **kwargs):
if many is sentinel:
many = self.many
if _MARSHMALLOW_VERSION_INFO[0] >= 3:
data = self.dump(obj, many=many)
else:
data = self.dump(obj, many=many).data
return flask.jsonify(data, *args, ... | Return a JSON response containing the serialized data.
:param obj: Object to serialize.
:param bool many: Whether `obj` should be serialized as an instance
or as a collection. If unset, defaults to the value of the
`many` attribute on this Schema.
:param kwargs: Additio... |
5,177 | def ExamineEvent(self, mediator, event):
event_data_type = getattr(event, , )
if event_data_type == :
service = WindowsService.FromEvent(event)
self._service_collection.AddService(service) | Analyzes an event and creates Windows Services as required.
At present, this method only handles events extracted from the Registry.
Args:
mediator (AnalysisMediator): mediates interactions between analysis
plugins and other components, such as storage and dfvfs.
event (EventObject): e... |
5,178 | def hdict(self, hashroot):
hfiles = self.keys(hashroot + "/*")
hfiles.sort()
last = len(hfiles) and hfiles[-1] or
if last.endswith():
hfiles = [last] + hfiles[:-1]
all = {}
for f in hfiles:
try:
... | Get all data contained in hashed category 'hashroot' as dict |
5,179 | def build_masters(
filename,
master_dir,
designspace_instance_dir=None,
designspace_path=None,
family_name=None,
propagate_anchors=True,
minimize_glyphs_diffs=False,
normalize_ufos=False,
create_background_layers=False,
generate_GDEF=True,
store_editor_state=True,
):
... | Write and return UFOs from the masters and the designspace defined in a
.glyphs file.
Args:
master_dir: Directory where masters are written.
designspace_instance_dir: If provided, a designspace document will be
written alongside the master UFOs though no instances will be built.
... |
5,180 | def push(self, line):
self.buffer.append(line)
source = "\n".join(self.buffer)
more = self.runsource(source, self.filename)
if not more:
self.resetbuffer()
return more | Push a line to the interpreter.
The line should not have a trailing newline; it may have
internal newlines. The line is appended to a buffer and the
interpreter's runsource() method is called with the
concatenated contents of the buffer as source. If this
indicates that the co... |
5,181 | def overview():
search = Credential.search()
search.aggs.bucket(, , field=, order={: }, size=20)\
.metric(, , field=) \
.metric(, , field=) \
.metric(, , docvalue_fields=[], size=100)
response = search.execute()
print_line("{0:65} {1:5} {2:5} {3:5} {4}".format("Secret", "Cou... | Provides an overview of the duplicate credentials. |
5,182 | def launch_svc_event_handler(self, service):
service.get_event_handlers(self.hosts, self.daemon.macromodulations,
self.daemon.timeperiods, ext_cmd=True) | Launch event handler for a service
Format of the line that triggers function call::
LAUNCH_SVC_EVENT_HANDLER;<host_name>;<service_description>
:param service: service to execute the event handler
:type service: alignak.objects.service.Service
:return: None |
5,183 | def appendGraph(self, graph_name, graph):
self._graphDict[graph_name] = graph
self._graphNames.append(graph_name)
if not self.isMultigraph and len(self._graphNames) > 1:
raise AttributeError("Simple Munin Plugins cannot have more than one graph.") | Utility method to associate Graph Object to Plugin.
This utility method is for use in constructor of child classes for
associating a MuninGraph instances to the plugin.
@param graph_name: Graph Name
@param graph: MuninGraph Instance |
5,184 | def _run_single(self, thread_id, agent, environment, deterministic=False,
max_episode_timesteps=-1, episode_finished=None, testing=False, sleep=None):
old_episode_finished = False
if episode_finished is not None and len(getargspec(episode_finished).args) == 1:
... | The target function for a thread, runs an agent and environment until signaled to stop.
Adds rewards to shared episode rewards list.
Args:
thread_id (int): The ID of the thread that's running this target function.
agent (Agent): The Agent object that this particular thread uses.... |
5,185 | def get_python(self):
cursor = super(ReferenceField, self).get_python()
if self.multiselect:
return cursor
else:
try:
return cursor[0]
except IndexError:
return None | Return cursor if multi-select, direct value if single-select |
5,186 | def write_result(self, data):
data[] = ujson.dumps(data[])
self.results.append(data)
if len(self.results) >= 150:
with db.execution_context():
with db.atomic():
Result.insert_many(self.results).execute()
del self.results... | Write the results received to the database
:param dict data: the data to save in database
:return: None |
5,187 | def create_custom_trees(cls, obj, options=None):
clones, id_mapping = {}, []
obj_ids = cls.get_object_ids(obj)
offset = cls.id_offset()
obj_ids = [None] if len(obj_ids)==0 else obj_ids
for tree_id in obj_ids:
if tree_id is not None and tree_id in Store.custom... | Returns the appropriate set of customized subtree clones for
an object, suitable for merging with Store.custom_options (i.e
with the ids appropriately offset). Note if an object has no
integer ids a new OptionTree is built.
The id_mapping return value is a list mapping the ids that
... |
5,188 | def security(self, domain):
uri = self._uris["security"].format(domain)
return self.get_parse(uri) | Get the Security Information for the given domain.
For details, see https://investigate.umbrella.com/docs/api#securityInfo |
5,189 | def _load_cache(self, filename):
try:
with open(filename + self.CACHE_EXTENSION, ) as file:
prev_number_of_pages, prev_page_references = pickle.load(file)
except (IOError, TypeError):
prev_number_of_pages, prev_page_references = {}, {}
return prev... | Load the cached page references from `<filename>.ptc`. |
5,190 | def on_site(self):
return super(EntryPublishedManager, self).get_queryset().filter(
sites=Site.objects.get_current()) | Return entries published on current site. |
5,191 | def print(self, indent=0):
LOG.info("%s:: %s", indent * " ", self.__class__)
for ext in self.next_extensions:
ext.print(indent=indent + 2) | Print a structural view of the registered extensions. |
5,192 | def bitcount(self, key, start=None, end=None):
if start is None and end is not None:
raise TypeError("both start and stop must be specified")
elif start is not None and end is None:
raise TypeError("both start and stop must be specified")
elif start is not None a... | Count set bits in a string.
:raises TypeError: if only start or end specified. |
5,193 | def put_meta(request):
if django.conf.settings.REQUIRE_WHITELIST_FOR_UPDATE:
d1_gmn.app.auth.assert_create_update_delete_permission(request)
d1_gmn.app.util.coerce_put_post(request)
d1_gmn.app.views.assert_db.post_has_mime_parts(
request, ((, ), (, ))
)
pid = request.POST[]
... | MNStorage.updateSystemMetadata(session, pid, sysmeta) → boolean.
TODO: Currently, this call allows making breaking changes to SysMeta. We need to
clarify what can be modified and what the behavior should be when working with SIDs
and chains. |
5,194 | def ConsumeByteString(self):
the_list = [self._ConsumeSingleByteString()]
while self.token and self.token[0] in _QUOTES:
the_list.append(self._ConsumeSingleByteString())
return b.join(the_list) | Consumes a byte array value.
Returns:
The array parsed (as a string).
Raises:
ParseError: If a byte array value couldn't be consumed. |
5,195 | def libvlc_video_get_logo_int(p_mi, option):
f = _Cfunctions.get(, None) or \
_Cfunction(, ((1,), (1,),), None,
ctypes.c_int, MediaPlayer, ctypes.c_uint)
return f(p_mi, option) | Get integer logo option.
@param p_mi: libvlc media player instance.
@param option: logo option to get, values of libvlc_video_logo_option_t. |
5,196 | def send_dictation_result(self, result, sentences=None, app_uuid=None):
assert self._session_id != VoiceService.SESSION_ID_INVALID
assert isinstance(result, TranscriptionResult)
transcription = None
if result == TranscriptionResult.Success:
if len(sentences) > 0:
... | Send the result of a dictation session
:param result: Result of the session
:type result: DictationResult
:param sentences: list of sentences, each of which is a list of words and punctuation
:param app_uuid: UUID of app that initiated the session
:type app_uuid: uuid.UUID |
5,197 | def create_from_pybankid_exception(cls, exception):
return cls(
"{0}: {1}".format(exception.__class__.__name__, str(exception)),
_exception_class_to_status_code.get(exception.__class__),
) | Class method for initiating from a `PyBankID` exception.
:param bankid.exceptions.BankIDError exception:
:return: The wrapped exception.
:rtype: :py:class:`~FlaskPyBankIDError` |
5,198 | def get_config_path(appdirs=DEFAULT_APPDIRS, file_name=DEFAULT_CONFIG_FILENAME):
return os.path.join(appdirs.user_config_dir, file_name) | Return the path where the config file is stored.
Args:
app_name (text_type, optional): Name of the application, defaults to
``'projecthamster``. Allows you to use your own application specific
namespace if you wish.
file_name (text_type, optional): Name of the config file. Defaults ... |
5,199 | def _get_entity_by_class(self, entity_cls):
entity_qualname = fully_qualified_name(entity_cls)
if entity_qualname in self._registry:
return self._registry[entity_qualname]
else:
return self._find_entity_in_records_by_class_name(entity_cls.__name__) | Fetch Entity record with Entity class details |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.