Unnamed: 0 int64 0 389k | code stringlengths 26 79.6k | docstring stringlengths 1 46.9k |
|---|---|---|
13,700 | def load_spacy_rule(file_path: str) -> Dict:
with open(file_path) as fp:
return json.load(fp) | A spacy rule file is a json file.
Args:
file_path (str): path to a text file containing a spacy rule sets.
Returns: Dict as the representation of spacy rules |
13,701 | def _generate_union_cstor_funcs(self, union):
for field in union.all_fields:
enum_field_name = fmt_enum_name(field.name, union)
func_args = [] if is_void_type(
field.data_type) else fmt_func_args_from_fields([field])
with self.block_func(
... | Emits standard union constructor. |
13,702 | def pick_config_ids(device_type, os, navigator):
if os is None:
default_dev_types = []
else:
default_dev_types = list(DEVICE_TYPE_OS.keys())
dev_type_choices = get_option_choices(
, device_type, default_dev_types,
list(DEVICE_TYPE_OS.keys())
)
os_choices = get_... | Select one random pair (device_type, os_id, navigator_id) from
all possible combinations matching the given os and
navigator filters.
:param os: allowed os(es)
:type os: string or list/tuple or None
:param navigator: allowed browser engine(s)
:type navigator: string or list/tuple or None
:p... |
13,703 | def gsea_compute(data, gmt, n, weighted_score_type, permutation_type,
method, pheno_pos, pheno_neg, classes, ascending,
processes=1, seed=None, single=False, scale=False):
w = weighted_score_type
subsets = sorted(gmt.keys())
es = []
RES=[]
hit_ind=[]
e... | compute enrichment scores and enrichment nulls.
:param data: preprocessed expression dataframe or a pre-ranked file if prerank=True.
:param dict gmt: all gene sets in .gmt file. need to call load_gmt() to get results.
:param int n: permutation number. default: 1000.
:param str method: r... |
13,704 | def count(cls, slug):
from .models import Content
cnt = cls._cache.get(slug)
if cnt is None:
cnt = Content.search_objects.search(tags=[slug]).count()
cls._cache[slug] = cnt
return cnt | get the number of objects in the cache for a given slug
:param slug: cache key
:return: `int` |
13,705 | def find_sanitizer(self, name):
name_parts = name.split(".")
if len(name_parts) < 2:
raise ConfigurationError(
"Unable to separate module name from function name in " % (
name,
),
)
m... | Searches for a sanitizer function with given name. The name should
contain two parts separated from each other with a dot, the first
part being the module name while the second being name of the function
contained in the module, when it's being prefixed with "sanitize_".
The lookup proc... |
13,706 | def GetList(self):
soap_request = soap()
soap_request.add_parameter(, self.listName)
self.last_request = str(soap_request)
response = self._session.post(url=self._url(),
headers=self._headers(),
... | Get Info on Current List
This is run in __init__ so you don't
have to run it again.
Access from self.schema |
13,707 | def com_google_fonts_check_name_postscriptname(ttFont, style, familyname):
from fontbakery.utils import name_entry_id
failed = False
for name in ttFont[].names:
if name.nameID == NameID.POSTSCRIPT_NAME:
expected_value = f"{familyname}-{style}"
string = name.string.decode(name.getEncoding()).s... | Check name table: POSTSCRIPT_NAME entries. |
13,708 | def hydrate(self, values):
def hydrate_(obj):
if isinstance(obj, Structure):
try:
f = self.hydration_functions[obj.tag]
except KeyError:
return obj
else:
return ... | Convert PackStream values into native values. |
13,709 | def get_alias(self,
alias=None,
manifest=None,
verify=True,
sizes=False,
dcd=None):
return self._get_alias(alias, manifest, verify, sizes, dcd, False) | Get the blob hashes assigned to an alias.
:param alias: Alias name. You almost definitely will only need to pass this argument.
:type alias: str
:param manifest: If you previously obtained a manifest, specify it here instead of ``alias``. You almost definitely won't need to do this.
:t... |
13,710 | def parse_value(self, tup_tree):
self.check_node(tup_tree, , (), (), (), allow_pcdata=True)
return self.pcdata(tup_tree) | Parse a VALUE element and return its text content as a unicode string.
Whitespace is preserved.
The conversion of the text representation of the value to a CIM data
type object requires CIM type information which is not available on the
VALUE element and therefore will be done when pars... |
13,711 | def html(self):
try:
from lxml import html
return html.fromstring(self.content)
except ImportError as ie:
raise DependencyException(ie) | Create an ``lxml``-based HTML DOM from the response. The tree
will not have a root, so all queries need to be relative
(i.e. start with a dot). |
13,712 | def _execute_callback(self, status, message, job, res, err, stacktrace):
if self._callback is not None:
try:
self._logger.info()
self._callback(status, message, job, res, err, stacktrace)
except Exception as e:
self._logger.excepti... | Execute the callback.
:param status: Job status. Possible values are "invalid" (job could not
be deserialized or was malformed), "failure" (job raised an error),
"timeout" (job timed out), or "success" (job finished successfully
and returned a result).
:type status: ... |
13,713 | def parse(self):
result = []
z = None
before_line_number, after_line_number = 0, 0
position = 0
for line in self.diff_text.splitlines():
match = re.search(r
r, line)
if match is not None:
... | Parses everyting into a datastructure that looks like:
result = [{
'origin_filename': '',
'result_filename': '',
'origin_lines': [], // all lines of the original file
'result_lines': [], // all lines of the newest file
'added_l... |
13,714 | def check_tweet(tweet, validation_checking=False):
if "id" not in tweet:
raise NotATweetError("This text has no key")
original_format = is_original_format(tweet)
if original_format:
_check_original_format_tweet(tweet, validation_checking=validation_checking)
else:
_check... | Ensures a tweet is valid and determines the type of format for the tweet.
Args:
tweet (dict/Tweet): the tweet payload
validation_checking (bool): check for valid key structure in a tweet. |
13,715 | def _marshall_value(value):
if PYTHON3 and isinstance(value, bytes):
return {: base64.b64encode(value).decode()}
elif PYTHON3 and isinstance(value, str):
return {: value}
elif not PYTHON3 and isinstance(value, str):
if is_binary(value):
return {: base64.b64encode(va... | Recursively transform `value` into an AttributeValue `dict`
:param mixed value: The value to encode
:rtype: dict
:raises ValueError: for unsupported types
Return the value as dict indicating the data type and transform or
recursively process the value if required. |
13,716 | def resourceprep(string, allow_unassigned=False):
chars = list(string)
_resourceprep_do_mapping(chars)
do_normalization(chars)
check_prohibited_output(
chars,
(
stringprep.in_table_c12,
stringprep.in_table_c21,
stringprep.in_table_c22,
... | Process the given `string` using the Resourceprep (`RFC 6122`_) profile. In
the error cases defined in `RFC 3454`_ (stringprep), a :class:`ValueError`
is raised. |
13,717 | def _client_wrapper(attr, *args, **kwargs):
catch_api_errors = kwargs.pop(, True)
func = getattr(__context__[], attr, None)
if func is None or not hasattr(func, ):
raise SaltInvocationError({0}\.format(attr))
if attr in (, ):
try:
__context__[].reload_config... | Common functionality for running low-level API calls |
13,718 | def __clear_bp(self, aProcess):
lpAddress = self.get_address()
flNewProtect = aProcess.mquery(lpAddress).Protect
flNewProtect = flNewProtect & (0xFFFFFFFF ^ win32.PAGE_GUARD)
aProcess.mprotect(lpAddress, self.get_size(), flNewProtect) | Restores the original permissions of the target pages.
@type aProcess: L{Process}
@param aProcess: Process object. |
13,719 | def cache_url(url, model_dir=None, progress=True):
r
if model_dir is None:
torch_home = os.path.expanduser(os.getenv(, ))
model_dir = os.getenv(, os.path.join(torch_home, ))
if not os.path.exists(model_dir):
os.makedirs(model_dir)
parts = urlparse(url)
filename = os.path.base... | r"""Loads the Torch serialized object at the given URL.
If the object is already present in `model_dir`, it's deserialized and
returned. The filename part of the URL should follow the naming convention
``filename-<sha256>.ext`` where ``<sha256>`` is the first eight or more
digits of the SHA256 hash of t... |
13,720 | def extract(self, member, path="", set_attrs=True):
self._check("r")
if isinstance(member, str):
tarinfo = self.getmember(member)
else:
tarinfo = member
if tarinfo.islnk():
tarinfo._link_target = os.path.join(path, tarinfo.linkname)... | Extract a member from the archive to the current working directory,
using its full name. Its file information is extracted as accurately
as possible. `member' may be a filename or a TarInfo object. You can
specify a different directory using `path'. File attributes (owner,
mt... |
13,721 | def is_compatible_assembly_level(self, ncbi_assembly_level):
configured_ncbi_strings = [self._LEVELS[level] for level in self.assembly_level]
return ncbi_assembly_level in configured_ncbi_strings | Check if a given ncbi assembly level string matches the configured assembly levels. |
13,722 | def add(self, game_object: Hashable, tags: Iterable[Hashable]=()) -> None:
if isinstance(tags, (str, bytes)):
raise TypeError("You passed a string instead of an iterable, this probably isn't what you intended.\n\nTry making it a tuple.")
self.all.add(game_object)
for kind i... | Add a game_object to the container.
game_object: Any Hashable object. The item to be added.
tags: An iterable of Hashable objects. Values that can be used to
retrieve a group containing the game_object.
Examples:
container.add(MyObject())
container.add(My... |
13,723 | def spkcov(spk, idcode, cover=None):
spk = stypes.stringToCharP(spk)
idcode = ctypes.c_int(idcode)
if cover is None:
cover = stypes.SPICEDOUBLE_CELL(2000)
else:
assert isinstance(cover, stypes.SpiceCell)
assert cover.is_double()
libspice.spkcov_c(spk, idcode, ctypes.byre... | Find the coverage window for a specified ephemeris object in a
specified SPK file.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/spkcov_c.html
:param spk: Name of SPK file.
:type spk: str
:param idcode: ID code of ephemeris object.
:type idcode: int
:param cover: Optional SPICE W... |
13,724 | def preTranslate(self, tx, ty):
self.e += tx * self.a + ty * self.c
self.f += tx * self.b + ty * self.d
return self | Calculate pre translation and replace current matrix. |
13,725 | def _quantile_function(self, alpha=0.5, smallest_count=None):
total = float(self.total())
smallest_observed_count = min(itervalues(self))
if smallest_count is None:
smallest_count = smallest_observed_count
else:
smallest_count = min(smallest_count, small... | Return a function that returns the quantile values for this
histogram. |
13,726 | def catch(ignore=[],
was_doing="something important",
helpfull_tips="you should use a debugger",
gbc=None):
exc_cls, exc, tb=sys.exc_info()
if exc_cls in ignore:
msg=
gbc.say(+str(exc_cls))
return
ex_message = traceback.format_exception_o... | Catch, prepare and log error
:param exc_cls: error class
:param exc: exception
:param tb: exception traceback |
13,727 | def list_resources_with_long_filters(list_method,
filter_attr, filter_values, **params):
try:
params[filter_attr] = filter_values
return list_method(**params)
except neutron_exc.RequestURITooLong as uri_len_exc:
... | List neutron resources with handling RequestURITooLong exception.
If filter parameters are long, list resources API request leads to
414 error (URL is too long). For such case, this method split
list parameters specified by a list_field argument into chunks
and call the specified list_method repeatedly... |
13,728 | def all_resource_urls(query):
urls = []
next = True
while next:
response = requests.get(query)
json_data = json.loads(response.content)
for resource in json_data[]:
urls.append(resource[])
if bool(json_data[]):
query = json_data[]
else:
... | Get all the URLs for every resource |
13,729 | def _create(cls, repo, path, resolve, reference, force, logmsg=None):
git_dir = _git_dir(repo, path)
full_ref_path = cls.to_full_path(path)
abs_ref_path = osp.join(git_dir, full_ref_path)
target = reference
if resolve:
target = repo.rev_parse(str(re... | internal method used to create a new symbolic reference.
If resolve is False, the reference will be taken as is, creating
a proper symbolic reference. Otherwise it will be resolved to the
corresponding object and a detached symbolic reference will be created
instead |
13,730 | def _conf(cls, opts):
logging_conf = cls.config.get(, , None)
if logging_conf is None:
return False
if not os.path.exists(logging_conf):
raise OSError("Error: Unable to locate specified logging configuration file!")
logging.con... | Setup logging via ini-file from logging_conf_file option. |
13,731 | def add_term(self,term_obj):
if self.term_layer is None:
self.term_layer = Cterms(type=self.type)
self.root.append(self.term_layer.get_node())
self.term_layer.add_term(term_obj) | Adds a term to the term layer
@type term_obj: L{Cterm}
@param term_obj: the term object |
13,732 | def get_active(cls, database, conditions=""):
if conditions:
conditions +=
conditions +=
return SystemPart.get(database, conditions=conditions) | Gets active data from system.parts table
:param database: A database object to fetch data from.
:param conditions: WHERE clause conditions. Database and active conditions are added automatically
:return: A list of SystemPart objects |
13,733 | def read_range(self, begin: str, end: str) -> int:
if self.read_eof():
return False
c = self._stream.peek_char
if begin <= c <= end:
self._stream.incpos()
return True
return False | Consume head byte if it is >= begin and <= end else return false
Same as 'a'..'z' in BNF |
13,734 | def wait_for_close(
raiden: ,
payment_network_id: PaymentNetworkID,
token_address: TokenAddress,
channel_ids: List[ChannelID],
retry_timeout: float,
) -> None:
return wait_for_channel_in_states(
raiden=raiden,
payment_network_id=payment_network_id,
... | Wait until all channels are closed.
Note:
This does not time out, use gevent.Timeout. |
13,735 | def delete_comment(self, project, work_item_id, comment_id):
route_values = {}
if project is not None:
route_values[] = self._serialize.url(, project, )
if work_item_id is not None:
route_values[] = self._serialize.url(, work_item_id, )
if comment_id is n... | DeleteComment.
[Preview API] Delete a comment on a work item.
:param str project: Project ID or project name
:param int work_item_id: Id of a work item.
:param int comment_id: |
13,736 | def build_def_use(graph, lparams):
analysis = reach_def_analysis(graph, lparams)
UD = defaultdict(list)
for node in graph.rpo:
for i, ins in node.get_loc_with_ins():
for var in ins.get_used_vars():
... | Builds the Def-Use and Use-Def (DU/UD) chains of the variables of the
method. |
13,737 | def ConvertValues(default_metadata, values, token=None, options=None):
batch_data = [(default_metadata, obj) for obj in values]
return ConvertValuesWithMetadata(batch_data, token=token, options=options) | Converts a set of RDFValues into a set of export-friendly RDFValues.
Args:
default_metadata: export.ExportedMetadata instance with basic information
about where the values come from. This metadata will be passed to
exporters.
values: Values to convert. They should be of the same type.
token: ... |
13,738 | def login(self):
form = self._get_form()
if form.validate_on_submit():
try:
self.security_service.login_user(form.user, form.remember.data)
except AuthenticationError as e:
form._errors = {: [str(e)]}
else:
self... | View function to log a user in. Supports html and json requests. |
13,739 | def split(*items):
out = []
for data in [x[0] for x in items]:
dis_orgs = data["config"]["algorithm"].get("disambiguate")
if dis_orgs:
if not data.get("disambiguate", None):
data["disambiguate"] = {"genome_build": data["genome_build"],
... | Split samples into all possible genomes for alignment. |
13,740 | def refresh_rooms(self):
for room_id in self.user_api.get_joined_rooms()["joined_rooms"]:
self._rooms[room_id] = MatrixRoom(room_id, self.user_api) | Calls GET /joined_rooms to refresh rooms list. |
13,741 | def __get_average_inter_cluster_distance(self, entry):
linear_part_distance = sum(list_math_multiplication(self.linear_sum, entry.linear_sum));
return ( (entry.number_points * self.square_sum - 2.0 * linear_part_distance + self.number_points * entry.square_sum) / (self.nu... | !
@brief Calculates average inter cluster distance between current and specified clusters.
@param[in] entry (cfentry): Clustering feature to which distance should be obtained.
@return (double) Average inter cluster distance. |
13,742 | def close(self):
self._logger.info("Closing")
if self._opened:
self._opened = False
else:
self._logger.warning(
"close() called, but connection policy was alredy closed")
return | Close the policy instance. |
13,743 | def setex(self, key, seconds, value):
if isinstance(seconds, float):
return self.psetex(key, int(seconds * 1000), value)
if not isinstance(seconds, int):
raise TypeError("milliseconds argument must be int")
fut = self.execute(b, key, seconds, value)
retur... | Set the value and expiration of a key.
If seconds is float it will be multiplied by 1000
coerced to int and passed to `psetex` method.
:raises TypeError: if seconds is neither int nor float |
13,744 | def process_xlsx(content):
data = {}
workbook = xlrd.open_workbook(file_contents=content)
worksheets = [w for w in workbook.sheet_names() if not w.startswith()]
for worksheet_name in worksheets:
if worksheet_name.startswith():
continue
worksheet = workbook.sheet_by_name... | Turn Excel file contents into Tarbell worksheet data |
13,745 | def _get_ignore_from_manifest_lines(lines):
ignore = []
ignore_regexps = []
for line in lines:
try:
cmd, rest = line.split(None, 1)
except ValueError:
continue
for part in rest.split():
if part.startswith():
... | Gather the various ignore patterns from a MANIFEST.in.
'lines' should be a list of strings with comments removed
and continuation lines joined.
Returns a list of standard ignore patterns and a list of regular
expressions to ignore. |
13,746 | def save_scenario(self, scenario_file_path=None):
warning_title = tr()
is_valid, warning_message = self.validate_input()
if not is_valid:
QMessageBox.warning(self, warning_title, warning_message)
return
i... | Save current scenario to a text file.
You can use the saved scenario with the batch runner.
:param scenario_file_path: A path to the scenario file.
:type scenario_file_path: str |
13,747 | def __create_core_and_model_object_copies(self, selection, smart_selection_adaption):
all_models_selected = selection.get_all()
if not all_models_selected:
logger.warning("Nothing to copy because state machine selection is empty.")
return
parent_m = self.do_sel... | Copy all elements of a selection.
The method copies all objects and modifies the selection before copying the elements if the smart flag is true.
The smart selection adaption is by default enabled. In any case the selection is reduced to have one parent
state that is used as the root of copy... |
13,748 | def validate(collection, onerror: Callable[[str, List], None] = None):
BioCValidator(onerror).validate(collection) | Validate BioC data structure. |
13,749 | def fromPy(cls, val, typeObj, vldMask=None):
vld = int(val is not None)
if not vld:
assert vldMask is None or vldMask == 0
val = False
else:
if vldMask == 0:
val = False
vld = 0
else:
val = b... | :param val: value of python type bool or None
:param typeObj: instance of HdlType
:param vldMask: None vldMask is resolved from val,
if is 0 value is invalidated
if is 1 value has to be valid |
13,750 | def bind_env(self, action, env):
if env in self._env_actions:
raise ValueError( % env)
self._env_actions[env] = action
action.env = env | Bind an environment variable to an argument action. The env
value will traditionally be something uppercase like `MYAPP_FOO_ARG`.
Note that the ENV value is assigned using `set_defaults()` and as such
it will be overridden if the argument is set via `parse_args()` |
13,751 | def str_dict_keys(a_dict):
new_dict = {}
for key in a_dict:
if six.PY2 and isinstance(key, six.text_type):
new_dict[str(key)] = a_dict[key]
else:
new_dict[key] = a_dict[key]
return new_dict | return a modified dict where all the keys that are anything but str get
converted to str.
E.g.
>>> result = str_dict_keys({u'name': u'Peter', u'age': 99, 1: 2})
>>> # can't compare whole dicts in doctests
>>> result['name']
u'Peter'
>>> result['age']
99
>>> result[1]
... |
13,752 | def handle_timeouts(self):
now = getnow()
while self.timeouts and self.timeouts[0].timeout <= now:
op = heapq.heappop(self.timeouts)
coro = op.coro
if op.weak_timeout and hasattr(op, ):
if op.last_update > op.last_checkpoint:... | Handle timeouts. Raise timeouted operations with a OperationTimeout
in the associated coroutine (if they are still alive and the operation
hasn't actualy sucessfuly completed) or, if the operation has a
weak_timeout flag, update the timeout point and add it back in the
heapq.
... |
13,753 | def _chk_type(recdef, rec):
if len(recdef) != len(rec):
raise TypeError("Number of columns (%d) is different from RecordDef (%d)" % (len(rec), len(recdef)))
for i in xrange(len(recdef)):
try:
def_type = recdef[i].type
col_type = Type.equi... | Checks if type of `rec` matches `recdef`
:param recdef: instance of RecordDef
:param rec: instance of Record
:raises: `TypeError` |
13,754 | def result(self, wait=0):
if self.started:
return result(self.id, wait=wait, cached=self.cached) | return the full list of results.
:param int wait: how many milliseconds to wait for a result
:return: an unsorted list of results |
13,755 | def _checkResponseWriteData(payload, writedata):
_checkString(payload, minlength=4, description=)
_checkString(writedata, minlength=2, maxlength=2, description=)
BYTERANGE_FOR_WRITEDATA = slice(2, 4)
receivedWritedata = payload[BYTERANGE_FOR_WRITEDATA]
if receivedWritedata != writedata:
... | Check that the write data as given in the response is correct.
The bytes 2 and 3 (zero based counting) in the payload holds the write data.
Args:
* payload (string): The payload
* writedata (string): The data to write, length should be 2 bytes.
Raises:
TypeError, ValueError |
13,756 | def stop_recording(self):
self._stop_recording.set()
with self._source_lock:
self._source.stop()
self._recording = False | Stop recording from the audio source. |
13,757 | def add_episode(self, text, text_format, title, author, summary=None,
publish_date=None, synthesizer=, synth_args=None, sentence_break=):
if title in self.episodes:
raise ValueError( + title + )
link = self.output_path + + title.replace(, ).lower() +
e... | Add a new episode to the podcast.
:param text:
See :meth:`Episode`.
:param text_format:
See :meth:`Episode`.
:param title:
See :meth:`Episode`.
:param author:
See :meth:`Episode`.
:param summary:
See :meth:`Episode`.
... |
13,758 | def ls(ctx, name):
session = create_session(ctx.obj[])
client = session.client()
results = client.list_clusters(
ClusterStates=[, , , ]
)
for cluster in results[]:
click.echo("{0}\t{1}\t{2}".format(cluster[], cluster[], cluster[][])) | List EMR instances |
13,759 | def apply_vcc(self,vcc):
if not in self.constraints:
self.constraints.append()
for pop in self.poplist:
if not pop.is_specific:
try:
pop.apply_vcc(vcc)
except:
logging.info( % (pop.model)) | Applies velocity contrast curve constraint to each population
See :func:`vespa.stars.StarPopulation.apply_vcc`;
all arguments passed to that function for each population. |
13,760 | def _validate_importers(importers):
if importers is None:
return None
def _to_importer(priority, func):
assert isinstance(priority, int), priority
assert callable(func), func
return (priority, _importer_callback_wrapper(func))
return tuple(_to_importer(priori... | Validates the importers and decorates the callables with our output
formatter. |
13,761 | def GetEntries(
self, parser_mediator, cookie_data=None, url=None, **kwargs):
fields = cookie_data.split()
number_of_fields = len(fields)
if number_of_fields not in (1, 4):
parser_mediator.ProduceExtractionWarning(
.format(
number_of_fields, self.COOKIE_NAME))
... | Extracts event objects from the cookie.
Args:
parser_mediator (ParserMediator): parser mediator.
cookie_data (bytes): cookie data.
url (str): URL or path where the cookie got set. |
13,762 | def hide(self):
for widget in self.replace_widgets:
widget.hide()
QWidget.hide(self)
self.visibility_changed.emit(False)
if self.editor is not None:
self.editor.setFocus()
self.clear_matches() | Overrides Qt Method |
13,763 | def get_groups_by_userid(cls, userid, request):
try:
cache_request_user(cls, request, userid)
except Exception as ex:
log.error(str(ex))
forget(request)
else:
if request._user:
return [ % g for g in request._user.groups] | Return group identifiers of user with id :userid:
Used by Ticket-based auth as `callback` kwarg. |
13,764 | def get_root_url(url, warn=True):
parsed_url = urlparse(url)
root_url = % (parsed_url.scheme, parsed_url.netloc)
if warn and not parsed_url.path.startswith():
logger.warning( % root_url)
return root_url | Get the "root URL" for a URL, as described in the LuminosoClient
documentation. |
13,765 | def seek(self, offset, whence=os.SEEK_SET):
pos = None
if whence == os.SEEK_SET:
pos = self.offset + offset
elif whence == os.SEEK_CUR:
pos = self.tell() + offset
elif whence == os.SEEK_END:
pos = self.offset + self.len + offset
else:... | Seek to position in stream, see file.seek |
13,766 | def as_string(self, default_from=None):
encoding = self.charset or
attachments = self.attachments or []
if len(attachments) == 0 and not self.html:
msg = self._mimetext(self.body)
elif len(attachments) > 0 and not self.html:
... | Creates the email |
13,767 | def td_waveform_to_fd_waveform(waveform, out=None, length=None,
buffer_length=100):
if out is None:
if length is None:
N = pnutils.nearest_larger_binary_number(len(waveform) + \
buffer_length)
... | Convert a time domain into a frequency domain waveform by FFT.
As a waveform is assumed to "wrap" in the time domain one must be
careful to ensure the waveform goes to 0 at both "boundaries". To
ensure this is done correctly the waveform must have the epoch set such
the merger time is at... |
13,768 | def approve(self, peer_jid):
self.client.enqueue(
stanza.Presence(type_=structs.PresenceType.SUBSCRIBED,
to=peer_jid)
) | (Pre-)approve a subscription request from `peer_jid`.
:param peer_jid: The peer to (pre-)approve.
This sends a ``"subscribed"`` presence to the peer; if the peer has
previously asked for a subscription, this will seal the deal and create
the subscription.
If the peer has not r... |
13,769 | def save_state(self, fname=None):
if not fname:
date = datetime.datetime.now().strftime("%Y-%m-%dT%Hh%Mm%Ss")
fname = date + "_energy_" + str(self.energy()) + ".state"
with open(fname, "wb") as fh:
pickle.dump(self.state, fh) | Saves state to pickle |
13,770 | def _read(self):
raw_response = self.transport.receive()
response = Packet.parse(raw_response)
if response.response_type == Packet.EVENT and response.event_type == "log":
self.log_events.append(response)
self._read()
el... | Get next packet from transport.
:return: parsed packet in a tuple with message type and payload
:rtype: :py:class:`collections.namedtuple` |
13,771 | def get_paths_from_to(self, goobj_start, goid_end=None, dn0_up1=True):
paths = []
working_q = cx.deque([[goobj_start]])
adjfnc = self.adjdir[dn0_up1]
while working_q:
path_curr = working_q.popleft()
goobj_curr = path_curr[-1... | Get a list of paths from goobj_start to either top or goid_end. |
13,772 | def has(self, relation, operator=">=", count=1, boolean="and", extra=None):
if relation.find(".") >= 0:
return self._has_nested(relation, operator, count, boolean, extra)
relation = self._get_has_relation_query(relation)
query = relation.get_relation_count_query(
... | Add a relationship count condition to the query.
:param relation: The relation to count
:type relation: str
:param operator: The operator
:type operator: str
:param count: The count
:type count: int
:param boolean: The boolean value
:type boolean: str
... |
13,773 | def _include_exclude(file_path, include=None, exclude=None):
if exclude is not None and exclude:
for pattern in exclude:
if file_path.match(pattern):
return False
if include is not None and include:
for pattern in include:
if file_path.match(pattern)... | Check if file matches one of include filters and not in exclude filter.
:param file_path: Path to the file.
:param include: Tuple containing patterns to which include from result.
:param exclude: Tuple containing patterns to which exclude from result. |
13,774 | def make_links_absolute(self, base_url=None, resolve_base_href=True,
handle_failures=None):
if base_url is None:
base_url = self.base_url
if base_url is None:
raise TypeError(
"No base_url given, and the document ha... | Make all links in the document absolute, given the
``base_url`` for the document (the full URL where the document
came from), or if no ``base_url`` is given, then the ``.base_url``
of the document.
If ``resolve_base_href`` is true, then any ``<base href>``
tags in the document a... |
13,775 | def execute_operation(self, method="GET", ops_path="", payload=""):
operation_path_URL = "".join([self.api_server, ops_path])
logging.debug("%s %s" %(method, operation_path_URL))
if payload == "":
res = requests.request(method, operation_path_URL)
else:
l... | Executes a Kubernetes operation using the specified method against a path.
This is part of the low-level API.
:Parameters:
- `method`: The HTTP method to use, defaults to `GET`
- `ops_path`: The path of the operation, for example, `/api/v1/events` which would result in an overall:... |
13,776 | def convertToPDF(self, from_page=0, to_page=-1, rotate=0):
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_convertToPDF(self, from_page, to_page, rotate) | Convert document to PDF selecting page range and optional rotation. Output bytes object. |
13,777 | def get_pages_from_id_list(id_list):
page_list = []
for id_ in id_list:
try:
page_list.append(
Page.objects.get(id=id_).specific)
except ObjectDoesNotExist:
logging.error(
"Attempted to fetch non-existent"
" page with i... | Accepts: list of page ids
Returns: list of specific page objects |
13,778 | def is_error(self):
qstat = self._grep_qstat()
err = self._grep_status()
if qstat and err:
return True
return False | Checks to see if the job errored out. |
13,779 | def connect(self):
logger.info("Connecting to Redis on {host}:{port}...".format(
host=self.host, port=self.port))
super(RedisSubscriber, self).connect()
logger.info("Successfully connected to Redis")
self.pubsub = self.client.pubsub()
self.pubsub.s... | Connects to Redis |
13,780 | def _to_dict(self):
_dict = {}
if hasattr(self, ) and self.id is not None:
_dict[] = self.id
if hasattr(self, ) and self.metadata is not None:
_dict[] = self.metadata
if hasattr(self, ) and self.collection_id is not None:
_dict[] = self.collec... | Return a json dictionary representing this model. |
13,781 | def collapse_spaces(text):
if not isinstance(text, six.string_types):
return text
return COLLAPSE_RE.sub(WS, text).strip(WS) | Remove newlines, tabs and multiple spaces with single spaces. |
13,782 | def _reverse_index(self):
if self.y == 0:
self.display = [u" " * self.size[1]] + self.display[:-1]
else:
self.y -= 1 | Move the cursor up one row in the same column. If the cursor is at the
first row, create a new row at the top. |
13,783 | def thumbnail(self, img_url, size, crop=None, bg=None, quality=85,
storage_type=None, bucket_name=None):
width, height = [int(x) for x in size.split()]
thumb_size = (width, height)
url_path, img_name = os.path.split(img_url)
name, fm = os.path.splitext(img_nam... | :param img_url: url img - '/assets/media/summer.jpg'
:param size: size return thumb - '100x100'
:param crop: crop return thumb - 'fit' or None
:param bg: tuple color or None - (255, 255, 255, 0)
:param quality: JPEG quality 1-100
:param storage_type: either 's3' or None
:... |
13,784 | def _parse_variable(s: str, curr_row: int, curr_col: int) -> Tuple:
def parse_expression(ss, curr_row, curr_col):
ss = ss.replace(, str(curr_row))
ss = ss.replace(, str(curr_col))
ss = ExcelExtractor._re_row_identifier.sub(
lambda x: str(ExcelExtract... | $A,$2 <- constant col and row
$row,$2 <- current col, row 2
$A+1,$2 <- col A + 1 = 2, row 2
$row+1,$2 <- current col + 1, row 2
$A,$2-1 <-- col A, row 2 - 1 = 1 |
13,785 | def edit(self, **kwargs):
if not in kwargs:
kwargs[] = self.ratingKey
if not in kwargs:
kwargs[] = utils.searchType(self.type)
part = % (self.librarySectionID,
urlencode(kwargs))
self._server.query(part,... | Edit an object.
Parameters:
kwargs (dict): Dict of settings to edit.
Example:
{'type': 1,
'id': movie.ratingKey,
'collection[0].tag.tag': 'Super',
'collection.locked': 0} |
13,786 | def extend_course(course, enterprise_customer, request):
course_run_id = course[][0][]
try:
catalog_api_client = CourseCatalogApiServiceClient(enterprise_customer.site)
except ImproperlyConfigured:
error_code =
LOGGER.error(
... | Extend a course with more details needed for the program landing page.
In particular, we add the following:
* `course_image_uri`
* `course_title`
* `course_level_type`
* `course_short_description`
* `course_full_description`
* `course_effort`
* `expected... |
13,787 | def render(self, context, instance, placeholder):
context = super(LocationListPlugin,self).render(context,instance,placeholder)
context[] = Location.objects.filter(status=Location.StatusChoices.active)
return context | Allows this plugin to use templates designed for a list of locations. |
13,788 | def make_backups(self, block_id):
assert self.setup, "Not set up yet. Call .db_setup() first!"
if self.backup_frequency is not None:
if (block_id % self.backup_frequency) == 0:
backup_dir = config.get_backups_directory(self.impl, self.working_dir)
... | If we're doing backups on a regular basis, then
carry them out here if it is time to do so.
This method does nothing otherwise.
Return None on success
Abort on failure |
13,789 | def run(self, host=None, port=None, debug=None, use_reloader=None,
open_browser=False):
if host is None:
host = self.config[]
if port is None:
port = self.config[]
if debug is None:
debug = self.debug
if use_reloader is None:
... | Starts a server to render the README. |
13,790 | def select_inverse(self, name="default", executor=None):
def create(current):
return selections.SelectionInvert(current)
self._selection(create, name, executor=executor) | Invert the selection, i.e. what is selected will not be, and vice versa
:param str name:
:param executor:
:return: |
13,791 | def do_set_logical_switch_config(self, line):
def f(p, args):
try:
target, lsw, key, value = args
except:
print("argument error")
return
o = p.get_config(target)
capable_switch_id = o.id
... | set_logical_switch_config <peer> <logical switch> <key> <value>
eg. set_logical_switch_config sw1 running LogicalSwitch7 \
lost-connection-behavior failStandaloneMode |
13,792 | async def load_message(obj, msg_type, msg=None, field_archiver=None):
msg = msg_type() if msg is None else msg
fields = msg_type.f_specs() if msg_type else msg.__class__.f_specs()
for field in fields:
await load_message_field(obj, msg, field, field_archiver=field_archiver)
return msg | Loads message if the given type from the object.
Supports reading directly to existing message.
:param obj:
:param msg_type:
:param msg:
:param field_archiver:
:return: |
13,793 | def _run_with_retries(cmd, max_retries=CMD_RETRY_COUNT, retry_exitcodes=(1,),
retry_message="", cmd_env=None):
env = None
kwargs = {}
if cmd_env:
env = os.environ.copy()
env.update(cmd_env)
kwargs[] = env
if not retry_message:
retry_message = ... | Run a command and retry until success or max_retries is reached.
:param: cmd: str: The apt command to run.
:param: max_retries: int: The number of retries to attempt on a fatal
command. Defaults to CMD_RETRY_COUNT.
:param: retry_exitcodes: tuple: Optional additional exit codes to retry.
Def... |
13,794 | def _set_rsvp(self, v, load=False):
if hasattr(v, "_utype"):
v = v._utype(v)
try:
t = YANGDynClass(v,base=rsvp.rsvp, is_container=, presence=False, yang_name="rsvp", rest_name="rsvp", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, extensions={u: {u... | Setter method for rsvp, mapped from YANG variable /mpls_state/rsvp (container)
If this variable is read-only (config: false) in the
source YANG file, then _set_rsvp is considered as a private
method. Backends looking to populate this variable should
do so via calling thisObj._set_rsvp() directly.
Y... |
13,795 | def queue(p_queue, host=None):
if host is not None:
return _path(_c.FSQ_QUEUE, root=_path(host, root=hosts(p_queue)))
return _path(p_queue, _c.FSQ_QUEUE) | Construct a path to the queue dir for a queue |
13,796 | def strace_set_buffer_size(self, size):
size = ctypes.c_uint32(size)
res = self._dll.JLINK_STRACE_Control(enums.JLinkStraceCommand.SET_BUFFER_SIZE, size)
if res < 0:
raise errors.JLinkException()
return None | Sets the STRACE buffer size.
Args:
self (JLink): the ``JLink`` instance.
Returns:
``None``
Raises:
JLinkException: on error. |
13,797 | def allocate_port():
sock = socket.socket()
try:
sock.bind(("localhost", 0))
return get_port(sock)
finally:
sock.close() | Allocate an unused port.
There is a small race condition here (between the time we allocate the
port, and the time it actually gets used), but for the purposes for which
this function gets used it isn't a problem in practice. |
13,798 | def getNetworkSummary(self, suid, verbose=None):
surl=self.___url
sv=surl.split()[-1]
surl=surl.rstrip(sv+)
response=api(url=surl++sv++str(suid)+, method="GET", verbose=verbose, parse_params=False)
return response | Returns summary of collection containing the specified network.
:param suid: Cytoscape Collection/Subnetwork SUID
:param verbose: print more
:returns: 200: successful operation |
13,799 | def js_click(self, selector, by=By.CSS_SELECTOR):
selector, by = self.__recalculate_selector(selector, by)
if by == By.LINK_TEXT:
message = (
"Pure JavaScript doesnt blocked. "
"For now, self.js_click() will use a regular WebDriver click.")
... | Clicks an element using pure JS. Does not use jQuery. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.