text stringlengths 75 104k | code_tokens list | avg_line_len float64 7.91 980 | score float64 0 0.18 |
|---|---|---|---|
def create_data_and_metadata(self, data: numpy.ndarray, intensity_calibration: CalibrationModule.Calibration = None,
dimensional_calibrations: typing.List[CalibrationModule.Calibration] = None, metadata: dict = None,
timestamp: str = None, data_descripto... | [
"def",
"create_data_and_metadata",
"(",
"self",
",",
"data",
":",
"numpy",
".",
"ndarray",
",",
"intensity_calibration",
":",
"CalibrationModule",
".",
"Calibration",
"=",
"None",
",",
"dimensional_calibrations",
":",
"typing",
".",
"List",
"[",
"CalibrationModule",... | 59.529412 | 0.008755 |
def ping(self):
"""Ping this hook.
:returns: bool
"""
url = self._build_url('pings', base_url=self._api)
return self._boolean(self._post(url), 204, 404) | [
"def",
"ping",
"(",
"self",
")",
":",
"url",
"=",
"self",
".",
"_build_url",
"(",
"'pings'",
",",
"base_url",
"=",
"self",
".",
"_api",
")",
"return",
"self",
".",
"_boolean",
"(",
"self",
".",
"_post",
"(",
"url",
")",
",",
"204",
",",
"404",
")... | 26.714286 | 0.010363 |
def draw_image_color_segments(source, clusters, hide_axes = True):
"""!
@brief Shows image segments using colored image.
@details Each color on result image represents allocated segment. The first image is initial and other is result of segmentation.
@param[in] source (string): Path to image.
... | [
"def",
"draw_image_color_segments",
"(",
"source",
",",
"clusters",
",",
"hide_axes",
"=",
"True",
")",
":",
"image_source",
"=",
"Image",
".",
"open",
"(",
"source",
")",
"image_size",
"=",
"image_source",
".",
"size",
"(",
"fig",
",",
"axarr",
")",
"=",
... | 44.52 | 0.021978 |
def combine_HSPs(a):
"""
Combine HSPs into a single BlastLine.
"""
m = a[0]
if len(a) == 1:
return m
for b in a[1:]:
assert m.query == b.query
assert m.subject == b.subject
m.hitlen += b.hitlen
m.nmismatch += b.nmismatch
m.ngaps += b.ngaps
... | [
"def",
"combine_HSPs",
"(",
"a",
")",
":",
"m",
"=",
"a",
"[",
"0",
"]",
"if",
"len",
"(",
"a",
")",
"==",
"1",
":",
"return",
"m",
"for",
"b",
"in",
"a",
"[",
"1",
":",
"]",
":",
"assert",
"m",
".",
"query",
"==",
"b",
".",
"query",
"ass... | 25.521739 | 0.001642 |
def _process_command(self, command, name=None):
"""Process ``make_ndx`` command and return name and temp index file."""
self._command_counter += 1
if name is None:
name = "CMD{0:03d}".format(self._command_counter)
# Need to build it with two make_ndx calls because I cannot... | [
"def",
"_process_command",
"(",
"self",
",",
"command",
",",
"name",
"=",
"None",
")",
":",
"self",
".",
"_command_counter",
"+=",
"1",
"if",
"name",
"is",
"None",
":",
"name",
"=",
"\"CMD{0:03d}\"",
".",
"format",
"(",
"self",
".",
"_command_counter",
"... | 49.2 | 0.009302 |
def previous_pages_numbers(self):
'A generator of previous page integers.'
count = self._previous_pages_count() + 1
for i in reversed(range(1, count)):
yield i | [
"def",
"previous_pages_numbers",
"(",
"self",
")",
":",
"count",
"=",
"self",
".",
"_previous_pages_count",
"(",
")",
"+",
"1",
"for",
"i",
"in",
"reversed",
"(",
"range",
"(",
"1",
",",
"count",
")",
")",
":",
"yield",
"i"
] | 38.2 | 0.010256 |
async def get_authenticated_user(
self, http_client: httpclient.AsyncHTTPClient = None
) -> Dict[str, Any]:
"""Gets the OAuth authorized user and access token.
This method should be called from the handler for your
OAuth callback URL to complete the registration process. We run the
... | [
"async",
"def",
"get_authenticated_user",
"(",
"self",
",",
"http_client",
":",
"httpclient",
".",
"AsyncHTTPClient",
"=",
"None",
")",
"->",
"Dict",
"[",
"str",
",",
"Any",
"]",
":",
"handler",
"=",
"cast",
"(",
"RequestHandler",
",",
"self",
")",
"reques... | 45.244444 | 0.001442 |
def dump_directory_structure(out = sys.stdout):
"""
Dumps a detailed report of the turicreate/sframe directory structure
and files, along with the output of os.lstat for each. This is useful
for debugging purposes.
"""
"Dumping Installation Directory Structure for Debugging: "
import sys,... | [
"def",
"dump_directory_structure",
"(",
"out",
"=",
"sys",
".",
"stdout",
")",
":",
"\"Dumping Installation Directory Structure for Debugging: \"",
"import",
"sys",
",",
"os",
"from",
"os",
".",
"path",
"import",
"split",
",",
"abspath",
",",
"join",
"from",
"iter... | 31.081081 | 0.012648 |
def pivot_query_as_matrix(facet=None, facet_pivot_fields=None, **kwargs):
"""
Pivot query
"""
if facet_pivot_fields is None:
facet_pivot_fields = []
logging.info("Additional args: {}".format(kwargs))
fp = search_associations(rows=0,
facet_fields=[facet],
... | [
"def",
"pivot_query_as_matrix",
"(",
"facet",
"=",
"None",
",",
"facet_pivot_fields",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"facet_pivot_fields",
"is",
"None",
":",
"facet_pivot_fields",
"=",
"[",
"]",
"logging",
".",
"info",
"(",
"\"Addition... | 27.326087 | 0.016897 |
def _load_config(self, client_secrets_file, client_id, client_secret):
"""Loads oauth2 configuration in order of priority.
Priority:
1. Config passed to the constructor or init_app.
2. Config passed via the GOOGLE_OAUTH2_CLIENT_SECRETS_FILE app
config.
... | [
"def",
"_load_config",
"(",
"self",
",",
"client_secrets_file",
",",
"client_id",
",",
"client_secret",
")",
":",
"if",
"client_id",
"and",
"client_secret",
":",
"self",
".",
"client_id",
",",
"self",
".",
"client_secret",
"=",
"client_id",
",",
"client_secret",... | 40.432432 | 0.001305 |
def next_frame_base():
"""Common HParams for next_frame models."""
hparams = common_hparams.basic_params1()
# Loss cutoff.
hparams.add_hparam("video_modality_loss_cutoff", 0.01)
# Additional resizing the frames before feeding them to model.
hparams.add_hparam("preprocess_resize_frames", None)
# How many d... | [
"def",
"next_frame_base",
"(",
")",
":",
"hparams",
"=",
"common_hparams",
".",
"basic_params1",
"(",
")",
"# Loss cutoff.",
"hparams",
".",
"add_hparam",
"(",
"\"video_modality_loss_cutoff\"",
",",
"0.01",
")",
"# Additional resizing the frames before feeding them to model... | 47.769231 | 0.02131 |
def kde_statsmodels_u(data, grid, **kwargs):
"""
Univariate Kernel Density Estimation with Statsmodels
Parameters
----------
data : numpy.array
Data points used to compute a density estimator. It
has `n x 1` dimensions, representing n points and p
variables.
grid : numpy... | [
"def",
"kde_statsmodels_u",
"(",
"data",
",",
"grid",
",",
"*",
"*",
"kwargs",
")",
":",
"kde",
"=",
"KDEUnivariate",
"(",
"data",
")",
"kde",
".",
"fit",
"(",
"*",
"*",
"kwargs",
")",
"return",
"kde",
".",
"evaluate",
"(",
"grid",
")"
] | 27.434783 | 0.001531 |
def check(self, line_info):
"Check if the initital identifier on the line is an alias."
# Note: aliases can not contain '.'
head = line_info.ifun.split('.',1)[0]
if line_info.ifun not in self.shell.alias_manager \
or head not in self.shell.alias_manager \
or... | [
"def",
"check",
"(",
"self",
",",
"line_info",
")",
":",
"# Note: aliases can not contain '.'",
"head",
"=",
"line_info",
".",
"ifun",
".",
"split",
"(",
"'.'",
",",
"1",
")",
"[",
"0",
"]",
"if",
"line_info",
".",
"ifun",
"not",
"in",
"self",
".",
"sh... | 43.4 | 0.011287 |
def get_cql_models(app, connection=None, keyspace=None):
"""
:param app: django models module
:param connection: connection name
:param keyspace: keyspace
:return: list of all cassandra.cqlengine.Model within app that should be
synced to keyspace.
"""
from .models import DjangoCassandraM... | [
"def",
"get_cql_models",
"(",
"app",
",",
"connection",
"=",
"None",
",",
"keyspace",
"=",
"None",
")",
":",
"from",
".",
"models",
"import",
"DjangoCassandraModel",
"models",
"=",
"[",
"]",
"single_cassandra_connection",
"=",
"len",
"(",
"list",
"(",
"get_c... | 37.103448 | 0.001812 |
def hash_token(token, salt):
'''
Calculates the hash of a token and salt.
input is unhexlified
token and salt must contain an even number of hex digits or
a binascii.Error exception will be raised
'''
digest = hashes.Hash(sha(), backend=default_backend())
digest.update(binascii.unhexlif... | [
"def",
"hash_token",
"(",
"token",
",",
"salt",
")",
":",
"digest",
"=",
"hashes",
".",
"Hash",
"(",
"sha",
"(",
")",
",",
"backend",
"=",
"default_backend",
"(",
")",
")",
"digest",
".",
"update",
"(",
"binascii",
".",
"unhexlify",
"(",
"token",
")"... | 34.833333 | 0.002331 |
def run(
cmd,
shell=False,
cwd=None,
log_in_real_time=True,
check_returncode=True,
callback=None,
):
""" Run 'cmd' in a shell and return the combined contents of stdout and
stderr (Blocking). Throws an exception if the command exits non-zero.
:param cmd: list of str (or single str,... | [
"def",
"run",
"(",
"cmd",
",",
"shell",
"=",
"False",
",",
"cwd",
"=",
"None",
",",
"log_in_real_time",
"=",
"True",
",",
"check_returncode",
"=",
"True",
",",
"callback",
"=",
"None",
",",
")",
":",
"proc",
"=",
"subprocess",
".",
"Popen",
"(",
"cmd... | 37.185714 | 0.000749 |
def cycle(self, *args):
"""Cycles among the arguments with the current loop index."""
if not args:
raise TypeError('no items for cycling given')
return args[self.index0 % len(args)] | [
"def",
"cycle",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"not",
"args",
":",
"raise",
"TypeError",
"(",
"'no items for cycling given'",
")",
"return",
"args",
"[",
"self",
".",
"index0",
"%",
"len",
"(",
"args",
")",
"]"
] | 42.6 | 0.009217 |
def upsert(self, conflict_target: List, fields: Dict, index_predicate: str=None) -> int:
"""Creates a new record or updates the existing one
with the specified data.
Arguments:
conflict_target:
Fields to pass into the ON CONFLICT clause.
fields:
... | [
"def",
"upsert",
"(",
"self",
",",
"conflict_target",
":",
"List",
",",
"fields",
":",
"Dict",
",",
"index_predicate",
":",
"str",
"=",
"None",
")",
"->",
"int",
":",
"self",
".",
"on_conflict",
"(",
"conflict_target",
",",
"ConflictAction",
".",
"UPDATE",... | 34.333333 | 0.009447 |
def user_list(self, name=None, name_matches=None, min_level=None,
max_level=None, level=None, user_id=None, order=None):
"""Function to get a list of users or a specific user.
Levels:
Users have a number attribute called level representing their role.
The curre... | [
"def",
"user_list",
"(",
"self",
",",
"name",
"=",
"None",
",",
"name_matches",
"=",
"None",
",",
"min_level",
"=",
"None",
",",
"max_level",
"=",
"None",
",",
"level",
"=",
"None",
",",
"user_id",
"=",
"None",
",",
"order",
"=",
"None",
")",
":",
... | 41.709677 | 0.002268 |
def value(self):
"""gets the color value"""
if self._outline is None:
return {
"type" : self._type,
"style" : self._style,
"color" : self._color.value,
}
else:
return {
"type" : self._type,
... | [
"def",
"value",
"(",
"self",
")",
":",
"if",
"self",
".",
"_outline",
"is",
"None",
":",
"return",
"{",
"\"type\"",
":",
"self",
".",
"_type",
",",
"\"style\"",
":",
"self",
".",
"_style",
",",
"\"color\"",
":",
"self",
".",
"_color",
".",
"value",
... | 29.666667 | 0.019608 |
def tick(self):
""" Submits all the given jobs in the queue and watches their
progress as they proceed. This function yields at the end of
each iteration of the queue.
:raises RuntimeError: If queue is locked.
"""
self.on_start()
while not self.is_empty:
... | [
"def",
"tick",
"(",
"self",
")",
":",
"self",
".",
"on_start",
"(",
")",
"while",
"not",
"self",
".",
"is_empty",
":",
"cruft",
"=",
"[",
"]",
"for",
"job",
"in",
"self",
".",
"queue",
":",
"if",
"not",
"self",
".",
"ready",
"(",
"job",
")",
":... | 34.574074 | 0.001042 |
def set_ylabel(self, s, delay_draw=False):
"set plot ylabel"
self.conf.relabel(ylabel=s, delay_draw=delay_draw) | [
"def",
"set_ylabel",
"(",
"self",
",",
"s",
",",
"delay_draw",
"=",
"False",
")",
":",
"self",
".",
"conf",
".",
"relabel",
"(",
"ylabel",
"=",
"s",
",",
"delay_draw",
"=",
"delay_draw",
")"
] | 41.666667 | 0.015748 |
def type_name(self) -> T.Optional[str]:
"""Return type name associated with given docstring metadata."""
return self.args[1] if len(self.args) > 1 else None | [
"def",
"type_name",
"(",
"self",
")",
"->",
"T",
".",
"Optional",
"[",
"str",
"]",
":",
"return",
"self",
".",
"args",
"[",
"1",
"]",
"if",
"len",
"(",
"self",
".",
"args",
")",
">",
"1",
"else",
"None"
] | 56.666667 | 0.011628 |
def snapshot_report(result, config=None, html=True):
"""
Generate a snapshot report from a result set and configuration.
Parameters
----------
result : memote.MemoteResult
Nested dictionary structure as returned from the test suite.
config : dict, optional
The final test report ... | [
"def",
"snapshot_report",
"(",
"result",
",",
"config",
"=",
"None",
",",
"html",
"=",
"True",
")",
":",
"if",
"config",
"is",
"None",
":",
"config",
"=",
"ReportConfiguration",
".",
"load",
"(",
")",
"report",
"=",
"SnapshotReport",
"(",
"result",
"=",
... | 31.666667 | 0.00146 |
def filter(self, other):
"""
Throw away those options which are not in the other one.
Returns a new instance with the rejected options.
"""
self.canonify()
other.canonify()
rej = self.__class__()
rej.optlist = self.optlist.difference(other.optlist)
... | [
"def",
"filter",
"(",
"self",
",",
"other",
")",
":",
"self",
".",
"canonify",
"(",
")",
"other",
".",
"canonify",
"(",
")",
"rej",
"=",
"self",
".",
"__class__",
"(",
")",
"rej",
".",
"optlist",
"=",
"self",
".",
"optlist",
".",
"difference",
"(",... | 29.055556 | 0.011111 |
def default(fun, **kwdefault):
"""
change default value for function
ex)
def sample(a, b=1, c=1):
print 'from sample:', a, b, c
return a, b, c
fun = default(sample, b=4,c=5)
print fun.default # get default value dictionary
fun(1) # print 1, 5, 5 and return
:param fun:
... | [
"def",
"default",
"(",
"fun",
",",
"*",
"*",
"kwdefault",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"fun",
")",
"def",
"wrapped",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"merge",
"=",
"wrapped",
".",
"default",
".",
"copy",
"(",... | 22.2 | 0.001727 |
def project_masks_on_boxes(segmentation_masks, proposals, discretization_size):
"""
Given segmentation masks and the bounding boxes corresponding
to the location of the masks in the image, this function
crops and resizes the masks in the position defined by the
boxes. This prepares the masks for the... | [
"def",
"project_masks_on_boxes",
"(",
"segmentation_masks",
",",
"proposals",
",",
"discretization_size",
")",
":",
"masks",
"=",
"[",
"]",
"M",
"=",
"discretization_size",
"device",
"=",
"proposals",
".",
"bbox",
".",
"device",
"proposals",
"=",
"proposals",
".... | 45.470588 | 0.000633 |
def check_bundler(self):
"""
Run the bundler check.
"""
def get_config(name):
return name if self.config('bundler.' + name) else ''
from pkg_resources import Requirement, resource_filename
relative_path = os.path.join('PyGitUp', 'check-bundler.rb')
... | [
"def",
"check_bundler",
"(",
"self",
")",
":",
"def",
"get_config",
"(",
"name",
")",
":",
"return",
"name",
"if",
"self",
".",
"config",
"(",
"'bundler.'",
"+",
"name",
")",
"else",
"''",
"from",
"pkg_resources",
"import",
"Requirement",
",",
"resource_fi... | 38.636364 | 0.002296 |
def _compat_rem_str_id_from_index(self, indexedField, pk, val, conn=None):
'''
_compat_rem_str_id_from_index - Used in compat_convertHashedIndexes to remove the old string repr of a field,
in order to later add the hashed value,
'''
if conn is None:
conn = self._get_connection()
conn.srem(self._compat... | [
"def",
"_compat_rem_str_id_from_index",
"(",
"self",
",",
"indexedField",
",",
"pk",
",",
"val",
",",
"conn",
"=",
"None",
")",
":",
"if",
"conn",
"is",
"None",
":",
"conn",
"=",
"self",
".",
"_get_connection",
"(",
")",
"conn",
".",
"srem",
"(",
"self... | 44.875 | 0.027322 |
def load(
inputobj,
c="gold",
alpha=None,
wire=False,
bc=None,
texture=None,
smoothing=None,
threshold=None,
connectivity=False,
):
"""
Returns a ``vtkActor`` from reading a file, directory or ``vtkPolyData``.
:param c: color in RGB format, hex, symbol or name
:param... | [
"def",
"load",
"(",
"inputobj",
",",
"c",
"=",
"\"gold\"",
",",
"alpha",
"=",
"None",
",",
"wire",
"=",
"False",
",",
"bc",
"=",
"None",
",",
"texture",
"=",
"None",
",",
"smoothing",
"=",
"None",
",",
"threshold",
"=",
"None",
",",
"connectivity",
... | 30.245902 | 0.000525 |
def set_acl(self, **kwargs): # noqa: E501
"""Set ACL for the specified dashboards # noqa: E501
# noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
>>> thread = api.set_acl(async_req=True)
... | [
"def",
"set_acl",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"# noqa: E501",
"kwargs",
"[",
"'_return_http_data_only'",
"]",
"=",
"True",
"if",
"kwargs",
".",
"get",
"(",
"'async_req'",
")",
":",
"return",
"self",
".",
"set_acl_with_http_info",
"(",
"... | 37.761905 | 0.00246 |
def _verify_cas1(ticket, service):
"""
Verifies CAS 1.0 authentication ticket.
:param: ticket
:param: service
Returns username on success and None on failure.
"""
params = {'ticket': ticket, 'service': service}
url = (urljoin(settings.CAS_SERVER_URL, 'validate') + '?' +
url... | [
"def",
"_verify_cas1",
"(",
"ticket",
",",
"service",
")",
":",
"params",
"=",
"{",
"'ticket'",
":",
"ticket",
",",
"'service'",
":",
"service",
"}",
"url",
"=",
"(",
"urljoin",
"(",
"settings",
".",
"CAS_SERVER_URL",
",",
"'validate'",
")",
"+",
"'?'",
... | 23.26087 | 0.001795 |
def Integer(name, base=10, encoding=None):
"""
Match an integer route parameter.
:type name: `bytes`
:param name: Route parameter name.
:type base: `int`
:param base: Base to interpret the value in.
:type encoding: `bytes`
:param encoding: Default encoding to assume if the ``Conten... | [
"def",
"Integer",
"(",
"name",
",",
"base",
"=",
"10",
",",
"encoding",
"=",
"None",
")",
":",
"def",
"_match",
"(",
"request",
",",
"value",
")",
":",
"return",
"name",
",",
"query",
".",
"Integer",
"(",
"value",
",",
"base",
"=",
"base",
",",
"... | 28.090909 | 0.001565 |
def render_summary(self, include_title=True):
"""Render the traceback for the interactive console."""
title = ""
classes = ["traceback"]
if not self.frames:
classes.append("noframe-traceback")
frames = []
else:
library_frames = sum(frame.is_lib... | [
"def",
"render_summary",
"(",
"self",
",",
"include_title",
"=",
"True",
")",
":",
"title",
"=",
"\"\"",
"classes",
"=",
"[",
"\"traceback\"",
"]",
"if",
"not",
"self",
".",
"frames",
":",
"classes",
".",
"append",
"(",
"\"noframe-traceback\"",
")",
"frame... | 38 | 0.00177 |
def get_username(self, user):
"""Retrieve username from user selector."""
if isinstance(user, basestring):
return user
elif isinstance(user, dict) and len(user) == 1:
[(key, val)] = user.items()
if key == 'username' or (key == self.user_model.USERNAME_FIELD):
... | [
"def",
"get_username",
"(",
"self",
",",
"user",
")",
":",
"if",
"isinstance",
"(",
"user",
",",
"basestring",
")",
":",
"return",
"user",
"elif",
"isinstance",
"(",
"user",
",",
"dict",
")",
"and",
"len",
"(",
"user",
")",
"==",
"1",
":",
"[",
"("... | 45.75 | 0.001529 |
def acquire(self, blocking=True,
delay=DELAY_INCREMENT, max_delay=MAX_DELAY,
timeout=None):
"""Attempt to acquire the given lock.
:param blocking: whether to wait forever to try to acquire the lock
:type blocking: bool
:param delay: when blocking this is ... | [
"def",
"acquire",
"(",
"self",
",",
"blocking",
"=",
"True",
",",
"delay",
"=",
"DELAY_INCREMENT",
",",
"max_delay",
"=",
"MAX_DELAY",
",",
"timeout",
"=",
"None",
")",
":",
"if",
"delay",
"<",
"0",
":",
"raise",
"ValueError",
"(",
"\"Delay must be greater... | 42.928571 | 0.002169 |
def post_process(func):
"""Calls the project handler same named function
Note: the project handler may add some extra arguments to the command,
so when use this decorator, add **kwargs to the end of the arguments
"""
@wraps(func)
def wrapper(*args, **kwargs):
res = func(*args, **... | [
"def",
"post_process",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"res",
"=",
"func",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"project_command",
"=",
"args... | 31.368421 | 0.001629 |
def _contribute_to_class(self, mcs_args: McsArgs):
"""
Where the magic happens. Takes one parameter, the :class:`McsArgs` of the
class-under-construction, and processes the declared ``class Meta`` from
it (if any). We fill ourself with the declared meta options' name/value pairs,
... | [
"def",
"_contribute_to_class",
"(",
"self",
",",
"mcs_args",
":",
"McsArgs",
")",
":",
"self",
".",
"_mcs_args",
"=",
"mcs_args",
"Meta",
"=",
"mcs_args",
".",
"clsdict",
".",
"pop",
"(",
"'Meta'",
",",
"None",
")",
"# type: Type[object]",
"base_classes_meta",... | 55.772727 | 0.012019 |
def get_font(section='appearance', option='font', font_size_delta=0):
"""Get console font properties depending on OS and user options"""
font = FONT_CACHE.get((section, option))
if font is None:
families = CONF.get(section, option+"/family", None)
if families is None:
return QF... | [
"def",
"get_font",
"(",
"section",
"=",
"'appearance'",
",",
"option",
"=",
"'font'",
",",
"font_size_delta",
"=",
"0",
")",
":",
"font",
"=",
"FONT_CACHE",
".",
"get",
"(",
"(",
"section",
",",
"option",
")",
")",
"if",
"font",
"is",
"None",
":",
"f... | 32.68 | 0.001189 |
def _weave_conflicting_selectors(prefixes, a, b, suffix=()):
"""Part of the selector merge algorithm above. Not useful on its own. Pay
no attention to the man behind the curtain.
"""
# OK, what this actually does: given a list of selector chains, two
# "conflicting" selector chains, and an optiona... | [
"def",
"_weave_conflicting_selectors",
"(",
"prefixes",
",",
"a",
",",
"b",
",",
"suffix",
"=",
"(",
")",
")",
":",
"# OK, what this actually does: given a list of selector chains, two",
"# \"conflicting\" selector chains, and an optional suffix, return a new list",
"# of chains li... | 43.7 | 0.00112 |
def get_value(self, tag=None, field=None):
"""Generate an integer whose bits are set according to the values of
fields in this bit field. All other bits are set to zero.
Parameters
----------
tag : str
Optionally specifies that the value should only include fields wi... | [
"def",
"get_value",
"(",
"self",
",",
"tag",
"=",
"None",
",",
"field",
"=",
"None",
")",
":",
"assert",
"not",
"(",
"tag",
"is",
"not",
"None",
"and",
"field",
"is",
"not",
"None",
")",
",",
"\"Cannot filter by tag and field simultaneously.\"",
"selected_fi... | 39.041667 | 0.001041 |
def plot_raster(self,cell_dimension='N',time_dimension=0,
resolution=1.0,units=None,min_t=None,max_t=None,
weight_function=None,normalize_time=True,normalize_n=True,
start_units_with_0=True,**kwargs):
"""Plots a raster plot with `cell_di... | [
"def",
"plot_raster",
"(",
"self",
",",
"cell_dimension",
"=",
"'N'",
",",
"time_dimension",
"=",
"0",
",",
"resolution",
"=",
"1.0",
",",
"units",
"=",
"None",
",",
"min_t",
"=",
"None",
",",
"max_t",
"=",
"None",
",",
"weight_function",
"=",
"None",
... | 50.655172 | 0.016032 |
def accuracy(eval_data, predictions, scores='ignored', learner='ignored'):
'''
Return the accuracy of each prediction in `predictions`: 1 if it is equal
to the correct output in `eval_data`, 0 otherwise.
>>> data = [Instance('input', 'correct'),
... Instance('input', 'correct'),
... ... | [
"def",
"accuracy",
"(",
"eval_data",
",",
"predictions",
",",
"scores",
"=",
"'ignored'",
",",
"learner",
"=",
"'ignored'",
")",
":",
"return",
"[",
"int",
"(",
"inst",
".",
"output",
"==",
"pred",
")",
"for",
"inst",
",",
"pred",
"in",
"zip",
"(",
"... | 39.692308 | 0.001894 |
def bell(self, percent = 0, onerror = None):
"""Ring the bell at the volume percent which is relative the base
volume. See XBell(3X11)."""
request.Bell(display = self.display,
onerror = onerror,
percent = percent) | [
"def",
"bell",
"(",
"self",
",",
"percent",
"=",
"0",
",",
"onerror",
"=",
"None",
")",
":",
"request",
".",
"Bell",
"(",
"display",
"=",
"self",
".",
"display",
",",
"onerror",
"=",
"onerror",
",",
"percent",
"=",
"percent",
")"
] | 45.666667 | 0.043011 |
def make_time_tree(self, time_marginal=False, clock_rate=None, **kwargs):
'''
Use the date constraints to calculate the most likely positions of
unconstrained nodes.
Parameters
----------
time_marginal : bool
If true, use marginal reconstruction for node po... | [
"def",
"make_time_tree",
"(",
"self",
",",
"time_marginal",
"=",
"False",
",",
"clock_rate",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"logger",
"(",
"\"ClockTree: Maximum likelihood tree optimization with temporal constraints\"",
",",
"1",
")",
... | 29.6 | 0.009162 |
def element_info_as_json(name):
"""
Get specified element META data based on search query
This is the base level search that returns basic object info
with the following attributes:
* href: link to element
* name: name of element
* type: type of element
:param str name: name of element... | [
"def",
"element_info_as_json",
"(",
"name",
")",
":",
"if",
"name",
":",
"element",
"=",
"fetch_meta_by_name",
"(",
"name",
")",
"if",
"element",
".",
"json",
":",
"return",
"element",
".",
"json"
] | 29.529412 | 0.001931 |
def report(self, report_req):
"""Processes a report request.
It will aggregate it with prior report_requests to be send later
or it will send it immediately if that's appropriate.
"""
self.start()
# no thread running, run the scheduler to ensure any pending
# fl... | [
"def",
"report",
"(",
"self",
",",
"report_req",
")",
":",
"self",
".",
"start",
"(",
")",
"# no thread running, run the scheduler to ensure any pending",
"# flush tasks are executed.",
"if",
"self",
".",
"_run_scheduler_directly",
":",
"self",
".",
"_scheduler",
".",
... | 40.380952 | 0.002304 |
def to_jd2(year, month, day):
'''Gregorian to Julian Day Count for years between 1801-2099'''
# http://quasar.as.utexas.edu/BillInfo/JulianDatesG.html
legal_date(year, month, day)
if month <= 2:
year = year - 1
month = month + 12
a = floor(year / 100)
b = floor(a / 4)
c = ... | [
"def",
"to_jd2",
"(",
"year",
",",
"month",
",",
"day",
")",
":",
"# http://quasar.as.utexas.edu/BillInfo/JulianDatesG.html",
"legal_date",
"(",
"year",
",",
"month",
",",
"day",
")",
"if",
"month",
"<=",
"2",
":",
"year",
"=",
"year",
"-",
"1",
"month",
"... | 26.5625 | 0.002273 |
def show(self):
"""Show the data graphically in a new pop-up window."""
# prevent the following error:
# '_tkinter.TclError: no display name and no $DISPLAY environment
# variable'
# import matplotlib
# matplotlib.use('GTK3Agg', warn=False)
import matplotlib.... | [
"def",
"show",
"(",
"self",
")",
":",
"# prevent the following error:",
"# '_tkinter.TclError: no display name and no $DISPLAY environment",
"# variable'",
"# import matplotlib",
"# matplotlib.use('GTK3Agg', warn=False)",
"import",
"matplotlib",
".",
"pyplot",
"as",
"plt",
"poin... | 39.396226 | 0.000935 |
def parse_extra_model_fields(extra_model_fields):
"""
Parses the value of EXTRA_MODEL_FIELDS, grouping the entries by model
and instantiating the extra fields. Returns a sequence of tuples of
the form (model_key, fields) where model_key is a pair of app_label,
model_name and fields is a list of (fie... | [
"def",
"parse_extra_model_fields",
"(",
"extra_model_fields",
")",
":",
"fields",
"=",
"defaultdict",
"(",
"list",
")",
"for",
"entry",
"in",
"extra_model_fields",
":",
"model_key",
",",
"field_name",
"=",
"parse_field_path",
"(",
"entry",
"[",
"0",
"]",
")",
... | 46.4 | 0.001056 |
def format (self, record):
"""Returns the given LogRecord as formatted text."""
record.hostname = self.hostname
return logging.Formatter.format(self, record) | [
"def",
"format",
"(",
"self",
",",
"record",
")",
":",
"record",
".",
"hostname",
"=",
"self",
".",
"hostname",
"return",
"logging",
".",
"Formatter",
".",
"format",
"(",
"self",
",",
"record",
")"
] | 44.5 | 0.016575 |
def split(compressed_data, segment_size, block_factory):
"""Splits compressed data into blocks.
:param compressed_data: the compressed data to split
:param segment_size: the size of a block in bytes
:param block_factory: a BlockFactory used to construct the blocks
:rtype: a list of block IDs of bl... | [
"def",
"split",
"(",
"compressed_data",
",",
"segment_size",
",",
"block_factory",
")",
":",
"# Split compressed data into blocks",
"segments",
"=",
"[",
"]",
"current_segment_start",
"=",
"0",
"index",
"=",
"0",
"data_size",
"=",
"len",
"(",
"compressed_data",
")... | 30.903226 | 0.000337 |
def _euristic_h_function(self, suffix, index):
"""
Вычисление h-эвристики из работы Hulden,2009 для текущей вершины словаря
Аргументы:
----------
suffix : string
непрочитанный суффикс входного слова
index : int
индекс текущего узла в словаре
... | [
"def",
"_euristic_h_function",
"(",
"self",
",",
"suffix",
",",
"index",
")",
":",
"if",
"self",
".",
"euristics",
">",
"0",
":",
"suffix",
"=",
"suffix",
"[",
":",
"self",
".",
"euristics",
"]",
"# кэширование результатов",
"index_temporary_euristics",
"=",
... | 36.805556 | 0.002206 |
def create(self):
"""Create the required directory structure and admin metadata."""
self._storage_broker.create_structure()
self._storage_broker.put_admin_metadata(self._admin_metadata) | [
"def",
"create",
"(",
"self",
")",
":",
"self",
".",
"_storage_broker",
".",
"create_structure",
"(",
")",
"self",
".",
"_storage_broker",
".",
"put_admin_metadata",
"(",
"self",
".",
"_admin_metadata",
")"
] | 51.5 | 0.009569 |
def GetSizeHint(self, context=None, **unused_kwargs):
"""Retrieves a hint about the size.
Args:
context (Optional[DataTypeMapContext]): data type map context, used to
determine the size hint.
Returns:
int: hint of the number of bytes needed from the byte stream or None.
"""
c... | [
"def",
"GetSizeHint",
"(",
"self",
",",
"context",
"=",
"None",
",",
"*",
"*",
"unused_kwargs",
")",
":",
"context_state",
"=",
"getattr",
"(",
"context",
",",
"'state'",
",",
"{",
"}",
")",
"elements_data_size",
"=",
"self",
".",
"GetByteSize",
"(",
")"... | 29.911765 | 0.008571 |
def wireframe(self, pointsize=0.2, opacity=1.0):
'''Display atoms as points of size *pointsize* and bonds as lines.'''
self.points(pointsize, opacity=opacity)
self.lines() | [
"def",
"wireframe",
"(",
"self",
",",
"pointsize",
"=",
"0.2",
",",
"opacity",
"=",
"1.0",
")",
":",
"self",
".",
"points",
"(",
"pointsize",
",",
"opacity",
"=",
"opacity",
")",
"self",
".",
"lines",
"(",
")"
] | 48 | 0.010256 |
def set_latency(self, latency):
"""Set client latency."""
self._client['config']['latency'] = latency
yield from self._server.client_latency(self.identifier, latency) | [
"def",
"set_latency",
"(",
"self",
",",
"latency",
")",
":",
"self",
".",
"_client",
"[",
"'config'",
"]",
"[",
"'latency'",
"]",
"=",
"latency",
"yield",
"from",
"self",
".",
"_server",
".",
"client_latency",
"(",
"self",
".",
"identifier",
",",
"latenc... | 46.75 | 0.010526 |
def getIDfileDict(files):
"""
given a list of files, return a dict[ID]=[files].
This is made to assign children files to parent ABF IDs.
"""
d={}
orphans=[]
for fname in files:
if fname.endswith(".abf"):
d[os.path.basename(fname)[:-4]]=[]
for fname in files:
i... | [
"def",
"getIDfileDict",
"(",
"files",
")",
":",
"d",
"=",
"{",
"}",
"orphans",
"=",
"[",
"]",
"for",
"fname",
"in",
"files",
":",
"if",
"fname",
".",
"endswith",
"(",
"\".abf\"",
")",
":",
"d",
"[",
"os",
".",
"path",
".",
"basename",
"(",
"fname... | 36.52 | 0.016009 |
def avail_locations(call=None):
'''
Return a dict of all available locations on the provider with
relevant data.
CLI Examples:
.. code-block:: bash
salt-cloud --list-locations my-qingcloud
'''
if call == 'action':
raise SaltCloudSystemExit(
'The avail_locations... | [
"def",
"avail_locations",
"(",
"call",
"=",
"None",
")",
":",
"if",
"call",
"==",
"'action'",
":",
"raise",
"SaltCloudSystemExit",
"(",
"'The avail_locations function must be called with '",
"'-f or --function, or with the --list-locations option'",
")",
"params",
"=",
"{",... | 24.206897 | 0.00137 |
def add_path(self, w, h):
"""Return a newly created `a:path` child element."""
path = self._add_path()
path.w, path.h = w, h
return path | [
"def",
"add_path",
"(",
"self",
",",
"w",
",",
"h",
")",
":",
"path",
"=",
"self",
".",
"_add_path",
"(",
")",
"path",
".",
"w",
",",
"path",
".",
"h",
"=",
"w",
",",
"h",
"return",
"path"
] | 32.8 | 0.011905 |
def generate_flattened_dict(headers, results):
'''extract from results the fields in the headers list'''
for name, values in results.items():
row = []
for header in headers:
if header == 'name':
row.append(name)
elif ':' in header:
neurite_... | [
"def",
"generate_flattened_dict",
"(",
"headers",
",",
"results",
")",
":",
"for",
"name",
",",
"values",
"in",
"results",
".",
"items",
"(",
")",
":",
"row",
"=",
"[",
"]",
"for",
"header",
"in",
"headers",
":",
"if",
"header",
"==",
"'name'",
":",
... | 36.615385 | 0.002049 |
def compress (input_filename, output_filename=None, verbose=False):
"""compress(input_filename, output_filename=None, verbose=False) -> integer
Uses zlib to compress input_filename and store the result in
output_filename. The size of output_filename is returned on
success; zero is returned on failure.
The ... | [
"def",
"compress",
"(",
"input_filename",
",",
"output_filename",
"=",
"None",
",",
"verbose",
"=",
"False",
")",
":",
"input_size",
"=",
"0",
"output_size",
"=",
"0",
"if",
"output_filename",
"is",
"None",
":",
"output_filename",
"=",
"input_fillename",
"+",
... | 28.555556 | 0.014296 |
def get_currencies(self, **params):
"""https://developers.coinbase.com/api/v2#currencies"""
response = self._get('v2', 'currencies', params=params)
return self._make_api_object(response, APIObject) | [
"def",
"get_currencies",
"(",
"self",
",",
"*",
"*",
"params",
")",
":",
"response",
"=",
"self",
".",
"_get",
"(",
"'v2'",
",",
"'currencies'",
",",
"params",
"=",
"params",
")",
"return",
"self",
".",
"_make_api_object",
"(",
"response",
",",
"APIObjec... | 54.5 | 0.00905 |
def clean_data(input_value):
''' a function to transform a value into a json or yaml valid datatype
:param input_value: object of any datatype
:return: object with json valid datatype
'''
# pass normal json/yaml datatypes
if input_value.__class__.__name__ in ['bool', 'str', 'float', 'int', 'NoneT... | [
"def",
"clean_data",
"(",
"input_value",
")",
":",
"# pass normal json/yaml datatypes",
"if",
"input_value",
".",
"__class__",
".",
"__name__",
"in",
"[",
"'bool'",
",",
"'str'",
",",
"'float'",
",",
"'int'",
",",
"'NoneType'",
"]",
":",
"pass",
"# transform byt... | 31.90625 | 0.001901 |
def check_for_upload_create(self, relative_path=None):
"""Traverse the relative_path tree and check for files that need to be uploaded/created.
Relativity here refers to the shared directory tree."""
for f in os.listdir(
path_join(
self.local_path, relative_path) if ... | [
"def",
"check_for_upload_create",
"(",
"self",
",",
"relative_path",
"=",
"None",
")",
":",
"for",
"f",
"in",
"os",
".",
"listdir",
"(",
"path_join",
"(",
"self",
".",
"local_path",
",",
"relative_path",
")",
"if",
"relative_path",
"else",
"self",
".",
"lo... | 46.777778 | 0.009324 |
def download(self, remotepath = '/', localpath = ''):
''' Usage: download [remotepath] [localpath] - \
download a remote directory (recursively) / file
remotepath - remote path at Baidu Yun (after app root directory), if not specified, it is set to the root directory at Baidu Yun
localpath - local path. if not sp... | [
"def",
"download",
"(",
"self",
",",
"remotepath",
"=",
"'/'",
",",
"localpath",
"=",
"''",
")",
":",
"subr",
"=",
"self",
".",
"get_file_info",
"(",
"remotepath",
")",
"if",
"const",
".",
"ENoError",
"==",
"subr",
":",
"if",
"'isdir'",
"in",
"self",
... | 42.227273 | 0.029474 |
def remove_key(self, key):
"""Remove own key, value"""
try:
self._own_keys.discard(key)
if self._parent and self._parent.has_key(key):
self._container[key] = self._parent[key]
else:
del self._container[key]
except KeyError:
... | [
"def",
"remove_key",
"(",
"self",
",",
"key",
")",
":",
"try",
":",
"self",
".",
"_own_keys",
".",
"discard",
"(",
"key",
")",
"if",
"self",
".",
"_parent",
"and",
"self",
".",
"_parent",
".",
"has_key",
"(",
"key",
")",
":",
"self",
".",
"_contain... | 32.3 | 0.009036 |
def comic_archive_compress(args):
"""
Called back by every optimization inside a comic archive.
When they're all done it creates the new archive and cleans up.
"""
try:
filename, old_format, settings, nag_about_gifs = args
Settings.update(settings)
tmp_dir = _get_archive_tmp... | [
"def",
"comic_archive_compress",
"(",
"args",
")",
":",
"try",
":",
"filename",
",",
"old_format",
",",
"settings",
",",
"nag_about_gifs",
"=",
"args",
"Settings",
".",
"update",
"(",
"settings",
")",
"tmp_dir",
"=",
"_get_archive_tmp_dir",
"(",
"filename",
")... | 31.151515 | 0.000943 |
def get_ts(ts):
"""
returns GPTS timescales.
options are: ck95, gts04, and gts12
returns timescales and Chron labels
"""
if ts == 'ck95':
TS = [0, 0.780, 0.990, 1.070, 1.770, 1.950, 2.140, 2.150, 2.581, 3.040, 3.110, 3.220, 3.330, 3.580, 4.180, 4.290, 4.480, 4.620, 4.800, 4.890, 4.980, ... | [
"def",
"get_ts",
"(",
"ts",
")",
":",
"if",
"ts",
"==",
"'ck95'",
":",
"TS",
"=",
"[",
"0",
",",
"0.780",
",",
"0.990",
",",
"1.070",
",",
"1.770",
",",
"1.950",
",",
"2.140",
",",
"2.150",
",",
"2.581",
",",
"3.040",
",",
"3.110",
",",
"3.220"... | 386.961538 | 0.001289 |
def refresh_keys(context, id, etag):
"""refresh_keys(context, id, etag)
Refresh a remoteci key pair.
>>> dcictl remoteci-refresh-keys [OPTIONS]
:param string id: ID of the remote CI [required]
:param string etag: Entity tag of the remote CI resource [required]
"""
result = remoteci.refres... | [
"def",
"refresh_keys",
"(",
"context",
",",
"id",
",",
"etag",
")",
":",
"result",
"=",
"remoteci",
".",
"refresh_keys",
"(",
"context",
",",
"id",
"=",
"id",
",",
"etag",
"=",
"etag",
")",
"utils",
".",
"format_output",
"(",
"result",
",",
"context",
... | 32.5 | 0.002494 |
def create_token(self, obj_id, extra_data):
"""Create a token referencing the object id with extra data."""
return self.engine.encrypt(
super(EncryptedTokenMixIn, self).create_token(obj_id, extra_data)
) | [
"def",
"create_token",
"(",
"self",
",",
"obj_id",
",",
"extra_data",
")",
":",
"return",
"self",
".",
"engine",
".",
"encrypt",
"(",
"super",
"(",
"EncryptedTokenMixIn",
",",
"self",
")",
".",
"create_token",
"(",
"obj_id",
",",
"extra_data",
")",
")"
] | 47 | 0.008368 |
def _source_info():
"""
Get information from the user's code (two frames up)
to leave breadcrumbs for file, line, class and function.
"""
ofi = inspect.getouterframes(inspect.currentframe())[2]
try:
calling_class = ofi[0].f_locals['self'].__class__
except KeyError:
calling_cl... | [
"def",
"_source_info",
"(",
")",
":",
"ofi",
"=",
"inspect",
".",
"getouterframes",
"(",
"inspect",
".",
"currentframe",
"(",
")",
")",
"[",
"2",
"]",
"try",
":",
"calling_class",
"=",
"ofi",
"[",
"0",
"]",
".",
"f_locals",
"[",
"'self'",
"]",
".",
... | 35.083333 | 0.002315 |
def find(self, name, namespace=None):
"""
Find plugin object
Parameters
----------
name : string
A name of the object entry or full namespace
namespace : string, optional
A period separated namespace. E.g. `foo.bar.hogehoge`
Returns
... | [
"def",
"find",
"(",
"self",
",",
"name",
",",
"namespace",
"=",
"None",
")",
":",
"if",
"\".\"",
"in",
"name",
":",
"namespace",
",",
"name",
"=",
"name",
".",
"rsplit",
"(",
"\".\"",
",",
"1",
")",
"caret",
"=",
"self",
".",
"raw",
"if",
"namesp... | 27.454545 | 0.001599 |
def transplant_class(cls, module):
"""
Make a class appear to reside in `module`, rather than the module in which
it is actually defined.
>>> from nose.failure import Failure
>>> Failure.__module__
'nose.failure'
>>> Nf = transplant_class(Failure, __name__)
>>> Nf.__module__
'nose.u... | [
"def",
"transplant_class",
"(",
"cls",
",",
"module",
")",
":",
"class",
"C",
"(",
"cls",
")",
":",
"pass",
"C",
".",
"__module__",
"=",
"module",
"C",
".",
"__name__",
"=",
"cls",
".",
"__name__",
"return",
"C"
] | 22.4 | 0.002141 |
def make_model(self):
"""Return the assembled HTML content as a string.
Returns
-------
str
The assembled HTML as a string.
"""
stmts_formatted = []
stmt_rows = group_and_sort_statements(self.statements,
s... | [
"def",
"make_model",
"(",
"self",
")",
":",
"stmts_formatted",
"=",
"[",
"]",
"stmt_rows",
"=",
"group_and_sort_statements",
"(",
"self",
".",
"statements",
",",
"self",
".",
"ev_totals",
"if",
"self",
".",
"ev_totals",
"else",
"None",
")",
"for",
"key",
"... | 46.840909 | 0.002376 |
def get_ordered_entries(self, queryset=False):
"""
Custom ordering. First we get the average views and rating for
the categories's entries. Second we created a rank by multiplying
both. Last, we sort categories by this rank from top to bottom.
Example:
- Cat_1
... | [
"def",
"get_ordered_entries",
"(",
"self",
",",
"queryset",
"=",
"False",
")",
":",
"if",
"queryset",
":",
"self",
".",
"queryset",
"=",
"queryset",
"else",
":",
"self",
".",
"queryset",
"=",
"EntryCategory",
".",
"objects",
".",
"all",
"(",
")",
"if",
... | 40.642857 | 0.001144 |
def __add_location(self, type, *args):
"""
Defines the slot triggered by **Where_lineEdit** Widget when a context menu entry is clicked.
:param type: Location type.
:type type: unicode
:param \*args: Arguments.
:type \*args: \*
"""
if type == "directory"... | [
"def",
"__add_location",
"(",
"self",
",",
"type",
",",
"*",
"args",
")",
":",
"if",
"type",
"==",
"\"directory\"",
":",
"location",
"=",
"umbra",
".",
"ui",
".",
"common",
".",
"store_last_browsed_path",
"(",
"(",
"QFileDialog",
".",
"getExistingDirectory",... | 57.928571 | 0.009703 |
def get_nucsat_subtrees(parented_tree):
"""Return all direct children of the given tree, that are either
a nucleus, satellite or a leaf node (i.e. all children except
for relation nodes.)
"""
if is_leaf(parented_tree):
return [parented_tree]
nucsat_children = []
for child in par... | [
"def",
"get_nucsat_subtrees",
"(",
"parented_tree",
")",
":",
"if",
"is_leaf",
"(",
"parented_tree",
")",
":",
"return",
"[",
"parented_tree",
"]",
"nucsat_children",
"=",
"[",
"]",
"for",
"child",
"in",
"parented_tree",
":",
"if",
"is_leaf",
"(",
"child",
"... | 34.933333 | 0.009294 |
def sanitize_logger (self):
"""Make logger configuration consistent."""
if not self['output']:
log.warn(LOG_CHECK, _("activating text logger output."))
self['output'] = 'text'
self['logger'] = self.logger_new(self['output']) | [
"def",
"sanitize_logger",
"(",
"self",
")",
":",
"if",
"not",
"self",
"[",
"'output'",
"]",
":",
"log",
".",
"warn",
"(",
"LOG_CHECK",
",",
"_",
"(",
"\"activating text logger output.\"",
")",
")",
"self",
"[",
"'output'",
"]",
"=",
"'text'",
"self",
"["... | 44.5 | 0.011029 |
def resize(self, width, height):
"""
Sets the new size and buffer size internally
"""
self.width = width
self.height = height
self.buffer_width, self.buffer_height = glfw.get_framebuffer_size(self.window)
self.set_default_viewport() | [
"def",
"resize",
"(",
"self",
",",
"width",
",",
"height",
")",
":",
"self",
".",
"width",
"=",
"width",
"self",
".",
"height",
"=",
"height",
"self",
".",
"buffer_width",
",",
"self",
".",
"buffer_height",
"=",
"glfw",
".",
"get_framebuffer_size",
"(",
... | 35.125 | 0.010417 |
def get_template(template):
"""Read the given template file."""
with open(os.path.join(template_dir, template) + template_ext, "r") as template_file:
return template_file.read() | [
"def",
"get_template",
"(",
"template",
")",
":",
"with",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"template_dir",
",",
"template",
")",
"+",
"template_ext",
",",
"\"r\"",
")",
"as",
"template_file",
":",
"return",
"template_file",
".",
"read",
... | 47.5 | 0.010363 |
async def remove_async(self, type_name, entity):
"""Removes an entity asynchronously using the API. Shortcut for using async_call() with the 'Remove' method.
:param type_name: The type of entity.
:param entity: The entity to remove.
:raise MyGeotabException: Raises when an exception occ... | [
"async",
"def",
"remove_async",
"(",
"self",
",",
"type_name",
",",
"entity",
")",
":",
"return",
"await",
"self",
".",
"call_async",
"(",
"'Remove'",
",",
"type_name",
"=",
"type_name",
",",
"entity",
"=",
"entity",
")"
] | 58.333333 | 0.011257 |
def get_security_group_dict():
"""Returns dictionary of named security groups {name: securitygroup}."""
client = get_ec2_client()
response = client.describe_security_groups()
assert is_good_response(response)
result = OrderedDict()
ec2 = get_ec2_resource()
for security_group_response in response['Securi... | [
"def",
"get_security_group_dict",
"(",
")",
":",
"client",
"=",
"get_ec2_client",
"(",
")",
"response",
"=",
"client",
".",
"describe_security_groups",
"(",
")",
"assert",
"is_good_response",
"(",
"response",
")",
"result",
"=",
"OrderedDict",
"(",
")",
"ec2",
... | 37.047619 | 0.015038 |
def load_module(path):
'''
Imports the module specified by the path.
Args :
path : The path to the source file.
'''
with add_to_path(os.path.dirname(path)):
spec = importlib.util.spec_from_file_location(os.path.basename(path).replace('.py',''), path)
modu... | [
"def",
"load_module",
"(",
"path",
")",
":",
"with",
"add_to_path",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"path",
")",
")",
":",
"spec",
"=",
"importlib",
".",
"util",
".",
"spec_from_file_location",
"(",
"os",
".",
"path",
".",
"basename",
"(",... | 37.363636 | 0.011876 |
def from_mpl(fig, savefig_kw=None):
"""Create a SVG figure from a ``matplotlib`` figure.
Parameters
----------
fig : matplotlib.Figure instance
savefig_kw : dict
keyword arguments to be passed to matplotlib's
`savefig`
Returns
-------
SVGFigure
newly create... | [
"def",
"from_mpl",
"(",
"fig",
",",
"savefig_kw",
"=",
"None",
")",
":",
"fid",
"=",
"StringIO",
"(",
")",
"if",
"savefig_kw",
"is",
"None",
":",
"savefig_kw",
"=",
"{",
"}",
"try",
":",
"fig",
".",
"savefig",
"(",
"fid",
",",
"format",
"=",
"'svg'... | 22.037037 | 0.000805 |
def untrace_function(module, function):
"""
Untraces given module function.
:param module: Module of the function.
:type module: object
:param function: Function to untrace.
:type function: object
:return: Definition success.
:rtype: bool
"""
if not is_traced(function):
... | [
"def",
"untrace_function",
"(",
"module",
",",
"function",
")",
":",
"if",
"not",
"is_traced",
"(",
"function",
")",
":",
"return",
"False",
"name",
"=",
"get_object_name",
"(",
"function",
")",
"setattr",
"(",
"module",
",",
"name",
",",
"untracer",
"(",
... | 23.111111 | 0.002309 |
def search_databases(self, search_term, location=None, markets_only=False, databases_to_search=None, allow_internal=False):
"""
Search external databases linked to your lcopt model.
To restrict the search to particular databases (e.g. technosphere or biosphere only) use a list of database name... | [
"def",
"search_databases",
"(",
"self",
",",
"search_term",
",",
"location",
"=",
"None",
",",
"markets_only",
"=",
"False",
",",
"databases_to_search",
"=",
"None",
",",
"allow_internal",
"=",
"False",
")",
":",
"dict_list",
"=",
"[",
"]",
"if",
"allow_inte... | 40.068182 | 0.009413 |
def list_tables(self, num_results=None, marker=None, timeout=None):
'''
Returns a generator to list the tables. The generator will lazily follow
the continuation tokens returned by the service and stop when all tables
have been returned or num_results is reached.
If num_result... | [
"def",
"list_tables",
"(",
"self",
",",
"num_results",
"=",
"None",
",",
"marker",
"=",
"None",
",",
"timeout",
"=",
"None",
")",
":",
"operation_context",
"=",
"_OperationContext",
"(",
"location_lock",
"=",
"True",
")",
"kwargs",
"=",
"{",
"'max_results'",... | 53.878788 | 0.011602 |
def _decode_record(self, s, line=0):
'''Decode one record of HEX file.
@param s line with HEX record.
@param line line number (for error messages).
@raise EndOfFile if EOF record encountered.
'''
s = s.rstrip('\r\n')
if not s:
return ... | [
"def",
"_decode_record",
"(",
"self",
",",
"s",
",",
"line",
"=",
"0",
")",
":",
"s",
"=",
"s",
".",
"rstrip",
"(",
"'\\r\\n'",
")",
"if",
"not",
"s",
":",
"return",
"# empty line",
"if",
"s",
"[",
"0",
"]",
"==",
"':'",
":",
"try",
":",
"bin",... | 36 | 0.001823 |
def strip_number(self):
"""The number of the strip that has changed state,
with 0 being the first strip.
On tablets with only one strip, this method always returns 0.
For events not of type
:attr:`~libinput.constant.EventType.TABLET_PAD_STRIP`, this property
raises :exc:`AttributeError`.
Returns:
in... | [
"def",
"strip_number",
"(",
"self",
")",
":",
"if",
"self",
".",
"type",
"!=",
"EventType",
".",
"TABLET_PAD_STRIP",
":",
"raise",
"AttributeError",
"(",
"_wrong_prop",
".",
"format",
"(",
"self",
".",
"type",
")",
")",
"return",
"self",
".",
"_libinput",
... | 28.35 | 0.02901 |
def stats(self):
"""Return dictionay with all stats at this level."""
assert self.backend.LOAD_count >= 0, "LOAD_count < 0"
assert self.backend.LOAD_byte >= 0, "LOAD_byte < 0"
assert self.backend.STORE_count >= 0, "STORE_count < 0"
assert self.backend.STORE_byte >= 0, "STORE_byte... | [
"def",
"stats",
"(",
"self",
")",
":",
"assert",
"self",
".",
"backend",
".",
"LOAD_count",
">=",
"0",
",",
"\"LOAD_count < 0\"",
"assert",
"self",
".",
"backend",
".",
"LOAD_byte",
">=",
"0",
",",
"\"LOAD_byte < 0\"",
"assert",
"self",
".",
"backend",
"."... | 54.26087 | 0.001575 |
def _extract_word(self, source, position):
"""
Extracts the word that falls at or around a specific position
:param source:
The template source as a unicode string
:param position:
The position where the word falls
:return:
The word
"... | [
"def",
"_extract_word",
"(",
"self",
",",
"source",
",",
"position",
")",
":",
"boundry",
"=",
"re",
".",
"search",
"(",
"'{{|{|\\s|$'",
",",
"source",
"[",
":",
"position",
"]",
"[",
":",
":",
"-",
"1",
"]",
")",
"start_offset",
"=",
"boundry",
".",... | 36.157895 | 0.008511 |
def window_bohman(N):
r"""Bohman tapering window
:param N: window length
.. math:: w(n) = (1-|x|) \cos (\pi |x|) + \frac{1}{\pi} \sin(\pi |x|)
where x is a length N vector of linearly spaced values between
-1 and 1.
.. plot::
:width: 80%
:include-source:
from spectru... | [
"def",
"window_bohman",
"(",
"N",
")",
":",
"x",
"=",
"linspace",
"(",
"-",
"1",
",",
"1",
",",
"N",
")",
"w",
"=",
"(",
"1.",
"-",
"abs",
"(",
"x",
")",
")",
"*",
"cos",
"(",
"pi",
"*",
"abs",
"(",
"x",
")",
")",
"+",
"1.",
"/",
"pi",
... | 23.636364 | 0.001848 |
def get_op_version(name):
'''
.. versionadded:: 2019.2.0
Returns the glusterfs volume op-version
name
Name of the glusterfs volume
CLI Example:
.. code-block:: bash
salt '*' glusterfs.get_op_version <volume>
'''
cmd = 'volume get {0} cluster.op-version'.format(name)... | [
"def",
"get_op_version",
"(",
"name",
")",
":",
"cmd",
"=",
"'volume get {0} cluster.op-version'",
".",
"format",
"(",
"name",
")",
"root",
"=",
"_gluster_xml",
"(",
"cmd",
")",
"if",
"not",
"_gluster_ok",
"(",
"root",
")",
":",
"return",
"False",
",",
"ro... | 22.575758 | 0.001287 |
def merge(self, options):
"""Returns new _CallSettings merged from this and a CallOptions object.
Note that passing if the CallOptions instance specifies a page_token,
the merged _CallSettings will have ``flatten_pages`` disabled. This
permits toggling per-resource/per-page page streami... | [
"def",
"merge",
"(",
"self",
",",
"options",
")",
":",
"if",
"not",
"options",
":",
"return",
"_CallSettings",
"(",
"timeout",
"=",
"self",
".",
"timeout",
",",
"retry",
"=",
"self",
".",
"retry",
",",
"page_descriptor",
"=",
"self",
".",
"page_descripto... | 35.592593 | 0.001013 |
def calculate_set_values(self):
""" Calculate the expected totals based on set allocations """
for ac in self.asset_classes:
ac.alloc_value = self.total_amount * ac.allocation / Decimal(100) | [
"def",
"calculate_set_values",
"(",
"self",
")",
":",
"for",
"ac",
"in",
"self",
".",
"asset_classes",
":",
"ac",
".",
"alloc_value",
"=",
"self",
".",
"total_amount",
"*",
"ac",
".",
"allocation",
"/",
"Decimal",
"(",
"100",
")"
] | 53.75 | 0.009174 |
def enrich(self, sample, ontologyClass, path, callback=None, output='application/json'):
""" Class Enrichment Service from: /analyzer/enrichment
Arguments:
sample: A list of CURIEs for nodes whose attributes are to be tested for enrichment. For example, a list of genes.
ontol... | [
"def",
"enrich",
"(",
"self",
",",
"sample",
",",
"ontologyClass",
",",
"path",
",",
"callback",
"=",
"None",
",",
"output",
"=",
"'application/json'",
")",
":",
"kwargs",
"=",
"{",
"'sample'",
":",
"sample",
",",
"'ontologyClass'",
":",
"ontologyClass",
"... | 63.736842 | 0.013019 |
def read_namespaced_resource_quota_status(self, name, namespace, **kwargs): # noqa: E501
"""read_namespaced_resource_quota_status # noqa: E501
read status of the specified ResourceQuota # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP... | [
"def",
"read_namespaced_resource_quota_status",
"(",
"self",
",",
"name",
",",
"namespace",
",",
"*",
"*",
"kwargs",
")",
":",
"# noqa: E501",
"kwargs",
"[",
"'_return_http_data_only'",
"]",
"=",
"True",
"if",
"kwargs",
".",
"get",
"(",
"'async_req'",
")",
":"... | 53.782609 | 0.001589 |
def paginate(self, url, key, params=None):
"""
Fetch a sequence of paginated resources from the API endpoint. The
initial request to ``url`` and all subsequent requests must respond
with a JSON object; the field specified by ``key`` must be a list,
whose elements will be yielded... | [
"def",
"paginate",
"(",
"self",
",",
"url",
",",
"key",
",",
"params",
"=",
"None",
")",
":",
"if",
"params",
"is",
"None",
":",
"params",
"=",
"{",
"}",
"if",
"self",
".",
"per_page",
"is",
"not",
"None",
"and",
"\"per_page\"",
"not",
"in",
"param... | 46.425 | 0.001582 |
def p_expression_logical(self, p):
"""
expression : expression logical expression
"""
p[0] = Expression(left=p[1], operator=p[2], right=p[3]) | [
"def",
"p_expression_logical",
"(",
"self",
",",
"p",
")",
":",
"p",
"[",
"0",
"]",
"=",
"Expression",
"(",
"left",
"=",
"p",
"[",
"1",
"]",
",",
"operator",
"=",
"p",
"[",
"2",
"]",
",",
"right",
"=",
"p",
"[",
"3",
"]",
")"
] | 33.8 | 0.011561 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.