text stringlengths 75 104k | code_tokens list | avg_line_len float64 7.91 980 | score float64 0 0.18 |
|---|---|---|---|
def get_extension_rights(self):
"""GetExtensionRights.
[Preview API]
:rtype: :class:`<ExtensionRightsResult> <azure.devops.v5_0.licensing.models.ExtensionRightsResult>`
"""
response = self._send(http_method='GET',
location_id='5f1dbe21-f748-47c7-b5fd... | [
"def",
"get_extension_rights",
"(",
"self",
")",
":",
"response",
"=",
"self",
".",
"_send",
"(",
"http_method",
"=",
"'GET'",
",",
"location_id",
"=",
"'5f1dbe21-f748-47c7-b5fd-3770c8bc2c08'",
",",
"version",
"=",
"'5.0-preview.1'",
")",
"return",
"self",
".",
... | 50 | 0.008734 |
def check_symmetric(array, tol=1E-10, raise_warning=True,
raise_exception=False):
"""Make sure that array is 2D, square and symmetric.
If the array is not symmetric, then a symmetrized version is returned.
Optionally, a warning or exception is raised if the matrix is not
symmetric.
... | [
"def",
"check_symmetric",
"(",
"array",
",",
"tol",
"=",
"1E-10",
",",
"raise_warning",
"=",
"True",
",",
"raise_exception",
"=",
"False",
")",
":",
"if",
"(",
"array",
".",
"ndim",
"!=",
"2",
")",
"or",
"(",
"array",
".",
"shape",
"[",
"0",
"]",
"... | 43.382979 | 0.00048 |
def to_underscore_case(camelcase_str):
r"""
References:
http://stackoverflow.com/questions/1175208/convert-camelcase
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> camelcase_str = 'UnderscoreFuncname'
>>> camel_case_str = to_underscore_cas... | [
"def",
"to_underscore_case",
"(",
"camelcase_str",
")",
":",
"s1",
"=",
"re",
".",
"sub",
"(",
"'(.)([A-Z][a-z]+)'",
",",
"r'\\1_\\2'",
",",
"camelcase_str",
")",
"return",
"re",
".",
"sub",
"(",
"'([a-z0-9])([A-Z])'",
",",
"r'\\1_\\2'",
",",
"s1",
")",
".",... | 37 | 0.001647 |
def __LoginBySSPI(host, port, service, adapter, version, path,
keyFile, certFile, thumbprint, sslContext, b64token,
connectionPoolTimeout=CONNECTION_POOL_IDLE_TIMEOUT_SEC):
"""
Private method that performs the actual Connect and returns a
connected service instance object.
... | [
"def",
"__LoginBySSPI",
"(",
"host",
",",
"port",
",",
"service",
",",
"adapter",
",",
"version",
",",
"path",
",",
"keyFile",
",",
"certFile",
",",
"thumbprint",
",",
"sslContext",
",",
"b64token",
",",
"connectionPoolTimeout",
"=",
"CONNECTION_POOL_IDLE_TIMEOU... | 34.44898 | 0.009217 |
def get_sls_opts(opts, **kwargs):
'''
Return a copy of the opts for use, optionally load a local config on top
'''
opts = copy.deepcopy(opts)
if 'localconfig' in kwargs:
return salt.config.minion_config(kwargs['localconfig'], defaults=opts)
if 'saltenv' in kwargs:
saltenv = kwa... | [
"def",
"get_sls_opts",
"(",
"opts",
",",
"*",
"*",
"kwargs",
")",
":",
"opts",
"=",
"copy",
".",
"deepcopy",
"(",
"opts",
")",
"if",
"'localconfig'",
"in",
"kwargs",
":",
"return",
"salt",
".",
"config",
".",
"minion_config",
"(",
"kwargs",
"[",
"'loca... | 35.225806 | 0.000891 |
def _check_scan_dir(self, fs, path, info, depth):
# type: (FS, Text, Info, int) -> bool
"""Check if a directory contents should be scanned."""
if self.max_depth is not None and depth >= self.max_depth:
return False
return self.check_scan_dir(fs, path, info) | [
"def",
"_check_scan_dir",
"(",
"self",
",",
"fs",
",",
"path",
",",
"info",
",",
"depth",
")",
":",
"# type: (FS, Text, Info, int) -> bool",
"if",
"self",
".",
"max_depth",
"is",
"not",
"None",
"and",
"depth",
">=",
"self",
".",
"max_depth",
":",
"return",
... | 49.333333 | 0.009967 |
def create_account(self, username, password, email, agreement=False, locale="en", scopes=__DEFAULT_SCOPES, to_file=None):
"""
Creates a new user account with the given username, password and email. "agreement"
must be set to true (after showing the user the instances user agreement and having
... | [
"def",
"create_account",
"(",
"self",
",",
"username",
",",
"password",
",",
"email",
",",
"agreement",
"=",
"False",
",",
"locale",
"=",
"\"en\"",
",",
"scopes",
"=",
"__DEFAULT_SCOPES",
",",
"to_file",
"=",
"None",
")",
":",
"params",
"=",
"self",
".",... | 49.129032 | 0.009977 |
def _get_permission_description(permission_name):
""" Generate a descriptive string based on the permission name.
For example: 'resource_Order_get' -> 'Can GET order'
todo: add support for the resource name to have underscores
"""
parts = permission_name.split('_')
parts.pop(0)
method =... | [
"def",
"_get_permission_description",
"(",
"permission_name",
")",
":",
"parts",
"=",
"permission_name",
".",
"split",
"(",
"'_'",
")",
"parts",
".",
"pop",
"(",
"0",
")",
"method",
"=",
"parts",
".",
"pop",
"(",
")",
"resource",
"=",
"(",
"'_'",
".",
... | 31.769231 | 0.002353 |
def compile_args(args, kwargs, sep, prefix):
""" takes args and kwargs, as they were passed into the command instance
being executed with __call__, and compose them into a flat list that
will eventually be fed into exec. example:
with this call:
sh.ls("-l", "/tmp", color="never")
this fu... | [
"def",
"compile_args",
"(",
"args",
",",
"kwargs",
",",
"sep",
",",
"prefix",
")",
":",
"processed_args",
"=",
"[",
"]",
"encode",
"=",
"encode_to_py3bytes_or_py2str",
"# aggregate positional args",
"for",
"arg",
"in",
"args",
":",
"if",
"isinstance",
"(",
"ar... | 27.769231 | 0.001784 |
def find_table_file(root_project_dir):
"""Find the EUPS table file for a project.
Parameters
----------
root_project_dir : `str`
Path to the root directory of the main documentation project. This
is the directory containing the ``conf.py`` file and a ``ups``
directory.
Retu... | [
"def",
"find_table_file",
"(",
"root_project_dir",
")",
":",
"ups_dir_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"root_project_dir",
",",
"'ups'",
")",
"table_path",
"=",
"None",
"for",
"name",
"in",
"os",
".",
"listdir",
"(",
"ups_dir_path",
")",
":... | 31.04 | 0.00125 |
def __addUser(self, new_user):
"""Add new users to the list.
:param new_user: name of a GitHub user to include in
the ranking
:type new_user: str.
"""
self.__lockReadAddUser.acquire()
if new_user not in self.__cityUsers and \
new_user not in s... | [
"def",
"__addUser",
"(",
"self",
",",
"new_user",
")",
":",
"self",
".",
"__lockReadAddUser",
".",
"acquire",
"(",
")",
"if",
"new_user",
"not",
"in",
"self",
".",
"__cityUsers",
"and",
"new_user",
"not",
"in",
"self",
".",
"__excludedUsers",
":",
"self",
... | 37.083333 | 0.002191 |
def is_python_script(script_text, filename):
"""Is this text, as a whole, a Python script? (as opposed to shell/bat/etc.
"""
if filename.endswith('.py') or filename.endswith('.pyw'):
return True # extension says it's Python
if is_python(script_text, filename):
return True # it's syntac... | [
"def",
"is_python_script",
"(",
"script_text",
",",
"filename",
")",
":",
"if",
"filename",
".",
"endswith",
"(",
"'.py'",
")",
"or",
"filename",
".",
"endswith",
"(",
"'.pyw'",
")",
":",
"return",
"True",
"# extension says it's Python",
"if",
"is_python",
"("... | 43.75 | 0.001866 |
def check():
"""Command for checking upgrades."""
upgrader = InvenioUpgrader()
logger = upgrader.get_logger()
try:
# Run upgrade pre-checks
upgrades = upgrader.get_upgrades()
# Check if there's anything to upgrade
if not upgrades:
logger.info("All upgrades h... | [
"def",
"check",
"(",
")",
":",
"upgrader",
"=",
"InvenioUpgrader",
"(",
")",
"logger",
"=",
"upgrader",
".",
"get_logger",
"(",
")",
"try",
":",
"# Run upgrade pre-checks",
"upgrades",
"=",
"upgrader",
".",
"get_upgrades",
"(",
")",
"# Check if there's anything ... | 33.178571 | 0.001046 |
def read_apply(lib, symbol, func, chunk_range=None):
"""
Apply `func` to each chunk in lib.symbol
Parameters
----------
lib: arctic library
symbol: str
the symbol for the given item in the DB
chunk_range: None, or a range object
allows you to subset the chunks by range
... | [
"def",
"read_apply",
"(",
"lib",
",",
"symbol",
",",
"func",
",",
"chunk_range",
"=",
"None",
")",
":",
"for",
"chunk",
"in",
"lib",
".",
"iterator",
"(",
"symbol",
",",
"chunk_range",
"=",
"chunk_range",
")",
":",
"yield",
"func",
"(",
"chunk",
")"
] | 24.111111 | 0.002217 |
def has_connection_details_changed(self, req_connection_details):
"""
:param cloudshell.cp.vcenter.models.VCenterConnectionDetails.VCenterConnectionDetails req_connection_details:
:return:
"""
if self.connection_details is None and req_connection_details is None:
retu... | [
"def",
"has_connection_details_changed",
"(",
"self",
",",
"req_connection_details",
")",
":",
"if",
"self",
".",
"connection_details",
"is",
"None",
"and",
"req_connection_details",
"is",
"None",
":",
"return",
"False",
"if",
"self",
".",
"connection_details",
"is"... | 59.615385 | 0.008895 |
def _left_zero_blocks(self, r):
"""Number of blocks with zeros from the left in block row `r`."""
if not self._include_off_diagonal:
return r
elif not self._upper:
return 0
elif self._include_diagonal:
return r
else:
return r + 1 | [
"def",
"_left_zero_blocks",
"(",
"self",
",",
"r",
")",
":",
"if",
"not",
"self",
".",
"_include_off_diagonal",
":",
"return",
"r",
"elif",
"not",
"self",
".",
"_upper",
":",
"return",
"0",
"elif",
"self",
".",
"_include_diagonal",
":",
"return",
"r",
"e... | 26.4 | 0.018315 |
def get_geostationary_bounding_box(geos_area, nb_points=50):
"""Get the bbox in lon/lats of the valid pixels inside *geos_area*.
Args:
nb_points: Number of points on the polygon
"""
xmax, ymax = get_geostationary_angle_extent(geos_area)
# generate points around the north hemisphere in satell... | [
"def",
"get_geostationary_bounding_box",
"(",
"geos_area",
",",
"nb_points",
"=",
"50",
")",
":",
"xmax",
",",
"ymax",
"=",
"get_geostationary_angle_extent",
"(",
"geos_area",
")",
"# generate points around the north hemisphere in satellite projection",
"# make it a bit smaller... | 44.142857 | 0.001056 |
def validate_record(datum, schema, parent_ns=None, raise_errors=True):
"""
Check that the data is a Mapping type with all schema defined fields
validated as True.
Parameters
----------
datum: Any
Data being validated
schema: dict
Schema
parent_ns: str
parent name... | [
"def",
"validate_record",
"(",
"datum",
",",
"schema",
",",
"parent_ns",
"=",
"None",
",",
"raise_errors",
"=",
"True",
")",
":",
"_",
",",
"namespace",
"=",
"schema_name",
"(",
"schema",
",",
"parent_ns",
")",
"return",
"(",
"isinstance",
"(",
"datum",
... | 29.846154 | 0.001248 |
def save(self, async=False, callback=None, encrypted=True):
""" Updates the user and perform the callback method """
if self._new_password and encrypted:
self.password = Sha1.encrypt(self._new_password)
controller = NURESTSession.get_current_session().login_controller
contr... | [
"def",
"save",
"(",
"self",
",",
"async",
"=",
"False",
",",
"callback",
"=",
"None",
",",
"encrypted",
"=",
"True",
")",
":",
"if",
"self",
".",
"_new_password",
"and",
"encrypted",
":",
"self",
".",
"password",
"=",
"Sha1",
".",
"encrypt",
"(",
"se... | 43 | 0.010114 |
def lparss(inlist, delims, NMAX=20, LENGTH=50):
"""
Parse a list of items separated by multiple delimiters, placing the
resulting items into a set.
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/lparss_c.html
:param inlist: list of items delimited by delims.
:type inlist:
:param d... | [
"def",
"lparss",
"(",
"inlist",
",",
"delims",
",",
"NMAX",
"=",
"20",
",",
"LENGTH",
"=",
"50",
")",
":",
"inlist",
"=",
"stypes",
".",
"stringToCharP",
"(",
"inlist",
")",
"delims",
"=",
"stypes",
".",
"stringToCharP",
"(",
"delims",
")",
"returnSet"... | 35.391304 | 0.001196 |
def _ancestors(self):
"""Attribute referencing the tree ancestors of the node instance.
:returns: list of node ancestors in sequence, first item is
the current node instance (`self`), the last item is root.
:rtype: list of Node references
"""
# return list of ancest... | [
"def",
"_ancestors",
"(",
"self",
")",
":",
"# return list of ancestor nodes starting with self.parent and ending with root",
"_ancestors",
"=",
"[",
"]",
"_n",
"=",
"self",
"while",
"_n",
".",
"parent",
":",
"_n",
"=",
"_n",
".",
"parent",
"_ancestors",
".",
"app... | 36.714286 | 0.009488 |
def write_multiple_coils(self, starting_address, values):
"""
Write multiple coils to Master device (Function code 15)
starting_address : First coil to be written
values: Coil Values [0..quantity-1] to be written
"""
self.__transactionIdentifier+=1
if (self.__se... | [
"def",
"write_multiple_coils",
"(",
"self",
",",
"starting_address",
",",
"values",
")",
":",
"self",
".",
"__transactionIdentifier",
"+=",
"1",
"if",
"(",
"self",
".",
"__ser",
"is",
"not",
"None",
")",
":",
"if",
"(",
"self",
".",
"__ser",
".",
"closed... | 48.489796 | 0.012374 |
def _ServerActions(action,alias,servers):
"""Archives the specified servers.
:param action: the server action url to exec against
:param alias: short code for a particular account. If none will use account's default alias
:param servers: list of server names
"""
if alias is None: alias = clc.v1.Account.G... | [
"def",
"_ServerActions",
"(",
"action",
",",
"alias",
",",
"servers",
")",
":",
"if",
"alias",
"is",
"None",
":",
"alias",
"=",
"clc",
".",
"v1",
".",
"Account",
".",
"GetAlias",
"(",
")",
"results",
"=",
"[",
"]",
"for",
"server",
"in",
"servers",
... | 40.692308 | 0.038817 |
def _format_tag(self, name, value, scraper_config):
"""
Lookups the labels_mapper table to see if replacing the tag name is
necessary, then returns a "name:value" tag string
"""
return '%s:%s' % (scraper_config['labels_mapper'].get(name, name), value) | [
"def",
"_format_tag",
"(",
"self",
",",
"name",
",",
"value",
",",
"scraper_config",
")",
":",
"return",
"'%s:%s'",
"%",
"(",
"scraper_config",
"[",
"'labels_mapper'",
"]",
".",
"get",
"(",
"name",
",",
"name",
")",
",",
"value",
")"
] | 47.666667 | 0.010309 |
def automain(self, function):
"""
Decorator that defines *and runs* the main function of the experiment.
The decorated function is marked as the default command for this
experiment, and the command-line interface is automatically run when
the file is executed.
The metho... | [
"def",
"automain",
"(",
"self",
",",
"function",
")",
":",
"captured",
"=",
"self",
".",
"main",
"(",
"function",
")",
"if",
"function",
".",
"__module__",
"==",
"'__main__'",
":",
"# Ensure that automain is not used in interactive mode.",
"import",
"inspect",
"ma... | 35.545455 | 0.00166 |
def ignore_cidr(vm_, ip):
'''
Return True if we are to ignore the specified IP. Compatible with IPv4.
'''
if HAS_NETADDR is False:
log.error('Error: netaddr is not installed')
return 'Error: netaddr is not installed'
cidr = config.get_cloud_config_value(
'ignore_cidr', vm_, ... | [
"def",
"ignore_cidr",
"(",
"vm_",
",",
"ip",
")",
":",
"if",
"HAS_NETADDR",
"is",
"False",
":",
"log",
".",
"error",
"(",
"'Error: netaddr is not installed'",
")",
"return",
"'Error: netaddr is not installed'",
"cidr",
"=",
"config",
".",
"get_cloud_config_value",
... | 32.3125 | 0.00188 |
def build_environ(scope: Scope, body: bytes) -> dict:
"""
Builds a scope and request body into a WSGI environ object.
"""
environ = {
"REQUEST_METHOD": scope["method"],
"SCRIPT_NAME": scope.get("root_path", ""),
"PATH_INFO": scope["path"],
"QUERY_STRING": scope["query_str... | [
"def",
"build_environ",
"(",
"scope",
":",
"Scope",
",",
"body",
":",
"bytes",
")",
"->",
"dict",
":",
"environ",
"=",
"{",
"\"REQUEST_METHOD\"",
":",
"scope",
"[",
"\"method\"",
"]",
",",
"\"SCRIPT_NAME\"",
":",
"scope",
".",
"get",
"(",
"\"root_path\"",
... | 37.534884 | 0.001208 |
def _simulated_chain_result(self, potential_chain, already_used_bonus):
"""Simulate any chain reactions.
Arguments:
potential_chain: a state to be tested for chain reactions
already_used_bonus: boolean indicating whether a bonus turn was already
applied during this action
... | [
"def",
"_simulated_chain_result",
"(",
"self",
",",
"potential_chain",
",",
"already_used_bonus",
")",
":",
"while",
"potential_chain",
":",
"# hook for capture game optimizations. no effect in base",
"# warning: only do this ONCE for any given state or it will",
"# always filter the s... | 48.679245 | 0.00228 |
def writer(f):
'''CSV writer factory for CADA format'''
return unicodecsv.writer(f, encoding='utf-8', delimiter=b',', quotechar=b'"') | [
"def",
"writer",
"(",
"f",
")",
":",
"return",
"unicodecsv",
".",
"writer",
"(",
"f",
",",
"encoding",
"=",
"'utf-8'",
",",
"delimiter",
"=",
"b','",
",",
"quotechar",
"=",
"b'\"'",
")"
] | 46.333333 | 0.014184 |
def compare_signature(expected: Union[str, bytes],
actual: Union[str, bytes]) -> bool:
"""
Compares the given signatures.
:param expected: The expected signature.
:type expected: Union[str, bytes]
:param actual: The actual signature.
:type actual: Union[str, bytes]
:re... | [
"def",
"compare_signature",
"(",
"expected",
":",
"Union",
"[",
"str",
",",
"bytes",
"]",
",",
"actual",
":",
"Union",
"[",
"str",
",",
"bytes",
"]",
")",
"->",
"bool",
":",
"expected",
"=",
"util",
".",
"to_bytes",
"(",
"expected",
")",
"actual",
"=... | 32.266667 | 0.002008 |
def traverse_imports(names):
"""
Walks over all the names imported in a dotted_as_names node.
"""
pending = [names]
while pending:
node = pending.pop()
if node.type == token.NAME:
yield node.value
elif node.type == syms.dotted_name:
yield "".join([ch.v... | [
"def",
"traverse_imports",
"(",
"names",
")",
":",
"pending",
"=",
"[",
"names",
"]",
"while",
"pending",
":",
"node",
"=",
"pending",
".",
"pop",
"(",
")",
"if",
"node",
".",
"type",
"==",
"token",
".",
"NAME",
":",
"yield",
"node",
".",
"value",
... | 34.647059 | 0.001653 |
def _init_metadata(self):
"""stub"""
self._zone_conditions_metadata = {
'zone_matches': Id(self.my_osid_object_form._authority,
self.my_osid_object_form._namespace,
'zone_conditions'),
'element_label': 'zone conditions... | [
"def",
"_init_metadata",
"(",
"self",
")",
":",
"self",
".",
"_zone_conditions_metadata",
"=",
"{",
"'zone_matches'",
":",
"Id",
"(",
"self",
".",
"my_osid_object_form",
".",
"_authority",
",",
"self",
".",
"my_osid_object_form",
".",
"_namespace",
",",
"'zone_c... | 40.756098 | 0.001169 |
def get_docs_label(self, role, name):
"""Get an appropriate label to use in a link to the online docs."""
if role == 'cite':
# Get the string used as the citation label in the text
try:
cstr = self.env.bibtex_cache.get_label_from_key(name)
except Exce... | [
"def",
"get_docs_label",
"(",
"self",
",",
"role",
",",
"name",
")",
":",
"if",
"role",
"==",
"'cite'",
":",
"# Get the string used as the citation label in the text",
"try",
":",
"cstr",
"=",
"self",
".",
"env",
".",
"bibtex_cache",
".",
"get_label_from_key",
"... | 39.625 | 0.002053 |
def add_tracker_url(parser):
""" add optional tracker_url argument """
parser.add_argument(
'--tracker_url',
metavar='(tracker url; default: "' + DEFAULT_TRACKER_URL + '")',
type=str, default=DEFAULT_TRACKER_URL)
return parser | [
"def",
"add_tracker_url",
"(",
"parser",
")",
":",
"parser",
".",
"add_argument",
"(",
"'--tracker_url'",
",",
"metavar",
"=",
"'(tracker url; default: \"'",
"+",
"DEFAULT_TRACKER_URL",
"+",
"'\")'",
",",
"type",
"=",
"str",
",",
"default",
"=",
"DEFAULT_TRACKER_U... | 34.857143 | 0.016 |
def conference_unmute(self, call_params):
"""REST Conference Unmute helper
"""
path = '/' + self.api_version + '/ConferenceUnmute/'
method = 'POST'
return self.request(path, method, call_params) | [
"def",
"conference_unmute",
"(",
"self",
",",
"call_params",
")",
":",
"path",
"=",
"'/'",
"+",
"self",
".",
"api_version",
"+",
"'/ConferenceUnmute/'",
"method",
"=",
"'POST'",
"return",
"self",
".",
"request",
"(",
"path",
",",
"method",
",",
"call_params"... | 38.166667 | 0.008547 |
def separate(self):
'''Return contiguous parts of collection as separate collections.
Return as list of :py:class:`~clique.collection.Collection` instances.
'''
collections = []
start = None
end = None
for index in self.indexes:
if start is None:
... | [
"def",
"separate",
"(",
"self",
")",
":",
"collections",
"=",
"[",
"]",
"start",
"=",
"None",
"end",
"=",
"None",
"for",
"index",
"in",
"self",
".",
"indexes",
":",
"if",
"start",
"is",
"None",
":",
"start",
"=",
"index",
"end",
"=",
"start",
"cont... | 27.472222 | 0.001953 |
def _get_force_constants_disps(force_constants,
supercell,
dataset,
symmetry,
atom_list=None):
"""Calculate force constants Phi = -F / d
Force constants are obtained by one of the followi... | [
"def",
"_get_force_constants_disps",
"(",
"force_constants",
",",
"supercell",
",",
"dataset",
",",
"symmetry",
",",
"atom_list",
"=",
"None",
")",
":",
"symprec",
"=",
"symmetry",
".",
"get_symmetry_tolerance",
"(",
")",
"disp_atom_list",
"=",
"np",
".",
"uniqu... | 32.235294 | 0.00059 |
def uniform(self, axis=None, precision=1E-7):
"""
Return True if the binning is uniform along the specified axis.
If axis is None (the default), then return True if the binning is
uniform along all axes. Otherwise return False.
Parameters
----------
axis : int (... | [
"def",
"uniform",
"(",
"self",
",",
"axis",
"=",
"None",
",",
"precision",
"=",
"1E-7",
")",
":",
"if",
"axis",
"is",
"None",
":",
"for",
"axis",
"in",
"range",
"(",
"self",
".",
"GetDimension",
"(",
")",
")",
":",
"widths",
"=",
"list",
"(",
"se... | 33.645161 | 0.001864 |
def create_namespaced_binding(self, namespace, body, **kwargs): # noqa: E501
"""create_namespaced_binding # noqa: E501
create a Binding # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
>>> t... | [
"def",
"create_namespaced_binding",
"(",
"self",
",",
"namespace",
",",
"body",
",",
"*",
"*",
"kwargs",
")",
":",
"# noqa: E501",
"kwargs",
"[",
"'_return_http_data_only'",
"]",
"=",
"True",
"if",
"kwargs",
".",
"get",
"(",
"'async_req'",
")",
":",
"return"... | 61.72 | 0.001276 |
def full_size(self):
'''show image at full size'''
self.dragpos = wx.Point(0, 0)
self.zoom = 1.0
self.need_redraw = True | [
"def",
"full_size",
"(",
"self",
")",
":",
"self",
".",
"dragpos",
"=",
"wx",
".",
"Point",
"(",
"0",
",",
"0",
")",
"self",
".",
"zoom",
"=",
"1.0",
"self",
".",
"need_redraw",
"=",
"True"
] | 29.6 | 0.013158 |
def backend(self):
"""Returns the backend class"""
from indico_livesync.plugin import LiveSyncPlugin
return LiveSyncPlugin.instance.backend_classes.get(self.backend_name) | [
"def",
"backend",
"(",
"self",
")",
":",
"from",
"indico_livesync",
".",
"plugin",
"import",
"LiveSyncPlugin",
"return",
"LiveSyncPlugin",
".",
"instance",
".",
"backend_classes",
".",
"get",
"(",
"self",
".",
"backend_name",
")"
] | 47.75 | 0.010309 |
def parse_gtf(
filepath_or_buffer,
chunksize=1024 * 1024,
features=None,
intern_columns=["seqname", "source", "strand", "frame"],
fix_quotes_columns=["attribute"]):
"""
Parameters
----------
filepath_or_buffer : str or buffer object
chunksize : int
feat... | [
"def",
"parse_gtf",
"(",
"filepath_or_buffer",
",",
"chunksize",
"=",
"1024",
"*",
"1024",
",",
"features",
"=",
"None",
",",
"intern_columns",
"=",
"[",
"\"seqname\"",
",",
"\"source\"",
",",
"\"strand\"",
",",
"\"frame\"",
"]",
",",
"fix_quotes_columns",
"="... | 30.094737 | 0.000339 |
def get(self, name):
"""Returns a Vxlan interface as a set of key/value pairs
The Vxlan interface resource returns the following:
* name (str): The name of the interface
* type (str): Always returns 'vxlan'
* source_interface (str): The vxlan source-interface value
... | [
"def",
"get",
"(",
"self",
",",
"name",
")",
":",
"config",
"=",
"self",
".",
"get_block",
"(",
"'^interface %s'",
"%",
"name",
")",
"if",
"not",
"config",
":",
"return",
"None",
"response",
"=",
"super",
"(",
"VxlanInterface",
",",
"self",
")",
".",
... | 40.717949 | 0.00123 |
def valid_java_classpath(classpath):
'''
Given a java classpath, check whether the path entries are valid or not
'''
paths = classpath.split(':')
for path_entry in paths:
if not valid_path(path_entry.strip()):
return False
return True | [
"def",
"valid_java_classpath",
"(",
"classpath",
")",
":",
"paths",
"=",
"classpath",
".",
"split",
"(",
"':'",
")",
"for",
"path_entry",
"in",
"paths",
":",
"if",
"not",
"valid_path",
"(",
"path_entry",
".",
"strip",
"(",
")",
")",
":",
"return",
"False... | 27.555556 | 0.023438 |
def main():
"""
$ ls --color=always | ansi2html > directories.html
$ sudo tail /var/log/messages | ccze -A | ansi2html > logs.html
$ task burndown | ansi2html > burndown.html
"""
scheme_names = sorted(six.iterkeys(SCHEME))
version_str = pkg_resources.get_distribution('ansi2html').version
... | [
"def",
"main",
"(",
")",
":",
"scheme_names",
"=",
"sorted",
"(",
"six",
".",
"iterkeys",
"(",
"SCHEME",
")",
")",
"version_str",
"=",
"pkg_resources",
".",
"get_distribution",
"(",
"'ansi2html'",
")",
".",
"version",
"parser",
"=",
"optparse",
".",
"Optio... | 36.122951 | 0.000883 |
def process_hashes(self, body, allow_create=False):
"""Process any hashes mentioned and push them to related topics.
:arg body: Body of the comment to check for hashes and push out.
:arg allow_create=False: Whether to allow creating new topics
from hash ta... | [
"def",
"process_hashes",
"(",
"self",
",",
"body",
",",
"allow_create",
"=",
"False",
")",
":",
"hash_re",
"=",
"re",
".",
"compile",
"(",
"self",
".",
"hashtag_re",
")",
"hashes",
"=",
"hash_re",
".",
"findall",
"(",
"body",
")",
"done",
"=",
"{",
"... | 43.482759 | 0.001552 |
def _check_positions(self):
'''Checks each bee to see if it abandons its current food source (has
not found a better one in self._limit iterations); if abandoning, it
becomes a scout and generates a new, random food source
'''
self.__verify_ready()
max_trials = 0
... | [
"def",
"_check_positions",
"(",
"self",
")",
":",
"self",
".",
"__verify_ready",
"(",
")",
"max_trials",
"=",
"0",
"scout",
"=",
"None",
"for",
"bee",
"in",
"self",
".",
"_employers",
":",
"if",
"(",
"bee",
".",
"failed_trials",
">=",
"max_trials",
")",
... | 38.428571 | 0.002418 |
def show_rules(cls, *names, attr=None):
"""Print algebraic rules used by :class:`create`
Print a summary of the algebraic rules with the given names, or all
rules if not names a given.
Args:
names (str): Names of rules to show
attr (None or str): Name of the cla... | [
"def",
"show_rules",
"(",
"cls",
",",
"*",
"names",
",",
"attr",
"=",
"None",
")",
":",
"from",
"qnet",
".",
"printing",
"import",
"srepr",
"try",
":",
"if",
"attr",
"is",
"None",
":",
"attr",
"=",
"cls",
".",
"_rules_attr",
"(",
")",
"rules",
"=",... | 34.029412 | 0.001681 |
def fmt_margin(text, margin = None, margin_left = None, margin_right = None, margin_char = ' '):
"""
Surround given text with given margin characters.
"""
if margin_left is None:
margin_left = margin
if margin_right is None:
margin_right = margin
i... | [
"def",
"fmt_margin",
"(",
"text",
",",
"margin",
"=",
"None",
",",
"margin_left",
"=",
"None",
",",
"margin_right",
"=",
"None",
",",
"margin_char",
"=",
"' '",
")",
":",
"if",
"margin_left",
"is",
"None",
":",
"margin_left",
"=",
"margin",
"if",
"margin... | 42.307692 | 0.019573 |
def value_assign(self, end_token=None):
"""
We are expecting a value (literal, list, dict, tuple).
If end_token then we are inside a list, dict or tuple so we are allow
newlines and also check for the end token.
"""
while True:
token = self.next()
... | [
"def",
"value_assign",
"(",
"self",
",",
"end_token",
"=",
"None",
")",
":",
"while",
"True",
":",
"token",
"=",
"self",
".",
"next",
"(",
")",
"t_value",
"=",
"token",
"[",
"\"value\"",
"]",
"if",
"end_token",
":",
"if",
"t_value",
"==",
"end_token",
... | 38.807692 | 0.001934 |
def convert_links(text, trim_url_limit=None, nofollow=False, autoescape=False):
"""
Finds URLs in text and attempts to handle correctly.
Heavily based on django.utils.html.urlize
With the additions of attempting to embed media links, particularly images.
Works on http://, https://, www. links, and ... | [
"def",
"convert_links",
"(",
"text",
",",
"trim_url_limit",
"=",
"None",
",",
"nofollow",
"=",
"False",
",",
"autoescape",
"=",
"False",
")",
":",
"safe_input",
"=",
"isinstance",
"(",
"text",
",",
"SafeData",
")",
"words",
"=",
"word_split_re",
".",
"spli... | 42.662791 | 0.002397 |
def get_composition_lookup_session_for_repository(self, repository_id, proxy):
"""Gets the OsidSession associated with the composition lookup
service for the given repository.
arg: repository_id (osid.id.Id): the Id of the repository
arg proxy (osid.proxy.Proxy): a proxy
... | [
"def",
"get_composition_lookup_session_for_repository",
"(",
"self",
",",
"repository_id",
",",
"proxy",
")",
":",
"if",
"repository_id",
"is",
"None",
":",
"raise",
"NullArgument",
"(",
")",
"if",
"not",
"self",
".",
"supports_composition_lookup",
"(",
")",
":",
... | 43.28125 | 0.002119 |
def run_direct(command, cl_args, action, extra_args=[], extra_lib_jars=[]):
'''
helper function to take action on topologies
:param command:
:param cl_args:
:param action: description of action taken
:return:
'''
topology_name = cl_args['topology-name']
new_args = [
"--cluster", cl_args[... | [
"def",
"run_direct",
"(",
"command",
",",
"cl_args",
",",
"action",
",",
"extra_args",
"=",
"[",
"]",
",",
"extra_lib_jars",
"=",
"[",
"]",
")",
":",
"topology_name",
"=",
"cl_args",
"[",
"'topology-name'",
"]",
"new_args",
"=",
"[",
"\"--cluster\"",
",",
... | 31.536585 | 0.011253 |
def sun_rise_set_transit_geometric(times, latitude, longitude, declination,
equation_of_time):
"""
Geometric calculation of solar sunrise, sunset, and transit.
.. warning:: The geometric calculation assumes a circular earth orbit with
the sun as a point source at ... | [
"def",
"sun_rise_set_transit_geometric",
"(",
"times",
",",
"latitude",
",",
"longitude",
",",
"declination",
",",
"equation_of_time",
")",
":",
"latitude_rad",
"=",
"np",
".",
"radians",
"(",
"latitude",
")",
"# radians",
"sunset_angle_rad",
"=",
"np",
".",
"ar... | 40.122807 | 0.000427 |
def __clean_and_tokenize(self, doc_list):
"""Method to clean and tokenize the document list.
:param doc_list: Document list to clean and tokenize.
:return: Cleaned and tokenized document list.
"""
# Some repositories fill entire documentation in description. We ignore
# ... | [
"def",
"__clean_and_tokenize",
"(",
"self",
",",
"doc_list",
")",
":",
"# Some repositories fill entire documentation in description. We ignore",
"# such repositories for cleaner tokens.",
"doc_list",
"=",
"filter",
"(",
"lambda",
"x",
":",
"x",
"is",
"not",
"None",
"and",
... | 32.386364 | 0.001362 |
def register_doi(self, submission_id, request_xml):
"""
This method registry a new DOI number in Crossref or update some DOI
metadata.
submission_id: Will be used as the submission file name. The file name
could be used in future requests to retrieve the submission status.
... | [
"def",
"register_doi",
"(",
"self",
",",
"submission_id",
",",
"request_xml",
")",
":",
"endpoint",
"=",
"self",
".",
"get_endpoint",
"(",
"'deposit'",
")",
"files",
"=",
"{",
"'mdFile'",
":",
"(",
"'%s.xml'",
"%",
"submission_id",
",",
"request_xml",
")",
... | 27.882353 | 0.002039 |
def get_group_offsets(self, group, topic=None):
"""Fetch group offsets for given topic and partition otherwise all topics
and partitions otherwise.
{
'topic':
{
'partition': offset-value,
...
...
}
}
... | [
"def",
"get_group_offsets",
"(",
"self",
",",
"group",
",",
"topic",
"=",
"None",
")",
":",
"group_offsets",
"=",
"{",
"}",
"try",
":",
"all_topics",
"=",
"self",
".",
"get_my_subscribed_topics",
"(",
"group",
")",
"except",
"NoNodeError",
":",
"# No offset ... | 34.815385 | 0.002149 |
def cmp_ast(node1, node2):
'''
Compare if two nodes are equal.
'''
if type(node1) != type(node2):
return False
if isinstance(node1, (list, tuple)):
if len(node1) != len(node2):
return False
for left, right in zip(node1, node2):
if not cmp_ast(left, ... | [
"def",
"cmp_ast",
"(",
"node1",
",",
"node2",
")",
":",
"if",
"type",
"(",
"node1",
")",
"!=",
"type",
"(",
"node2",
")",
":",
"return",
"False",
"if",
"isinstance",
"(",
"node1",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"if",
"len",
"(",
... | 23.592593 | 0.001508 |
def drop_columns_with_unique_values(
data: pd.DataFrame, max_unique_values: int = 0.25
):
"""
Remove columns when the proportion
of the total of unique values is more than the max_unique_values
threshold, just for columns with type as object or category
:param data:
:param max_unique_values... | [
"def",
"drop_columns_with_unique_values",
"(",
"data",
":",
"pd",
".",
"DataFrame",
",",
"max_unique_values",
":",
"int",
"=",
"0.25",
")",
":",
"size",
"=",
"data",
".",
"shape",
"[",
"0",
"]",
"df_uv",
"=",
"data",
".",
"apply",
"(",
"lambda",
"se",
... | 27.857143 | 0.001653 |
def _rts_smoother_update_step(k, p_m , p_P, p_m_pred, p_P_pred, p_m_prev_step,
p_P_prev_step, p_dynamic_callables):
"""
Rauch–Tung–Striebel(RTS) update step
Input:
-----------------------------
k: int
Iteration No. Starts at 0. Tot... | [
"def",
"_rts_smoother_update_step",
"(",
"k",
",",
"p_m",
",",
"p_P",
",",
"p_m_pred",
",",
"p_P_pred",
",",
"p_m_prev_step",
",",
"p_P_prev_step",
",",
"p_dynamic_callables",
")",
":",
"A",
"=",
"p_dynamic_callables",
".",
"Ak",
"(",
"k",
",",
"p_m",
",",
... | 33.431034 | 0.009519 |
def tessellation(mesh):
"""
Subdivide each face of a mesh into three faces with the new vertex
randomly placed inside the old face.
This produces a mesh with exactly the same surface area and volume
but with different tessellation.
Parameters
----------
mesh: Trimesh object
Return... | [
"def",
"tessellation",
"(",
"mesh",
")",
":",
"# create random barycentric coordinates for each face",
"# pad all coordinates by a small amount to bias new vertex towards center",
"barycentric",
"=",
"np",
".",
"random",
".",
"random",
"(",
"mesh",
".",
"faces",
".",
"shape",... | 39.15 | 0.001869 |
def check_rates(self, rates, base):
"""Local helper function for validating rates response"""
if "rates" not in rates:
raise RuntimeError("%s: 'rates' not found in results" % self.name)
if "base" not in rates or rates["base"] != base or base not in rates["rates"]:
self.l... | [
"def",
"check_rates",
"(",
"self",
",",
"rates",
",",
"base",
")",
":",
"if",
"\"rates\"",
"not",
"in",
"rates",
":",
"raise",
"RuntimeError",
"(",
"\"%s: 'rates' not found in results\"",
"%",
"self",
".",
"name",
")",
"if",
"\"base\"",
"not",
"in",
"rates",... | 50.625 | 0.009709 |
def _convert_attribute_to_tag(key, attr):
"""Convert the attributes to jaeger tags."""
if isinstance(attr, bool):
return jaeger.Tag(
key=key,
vBool=attr,
vType=jaeger.TagType.BOOL)
if isinstance(attr, str):
return jaeger.Tag(
key=key,
... | [
"def",
"_convert_attribute_to_tag",
"(",
"key",
",",
"attr",
")",
":",
"if",
"isinstance",
"(",
"attr",
",",
"bool",
")",
":",
"return",
"jaeger",
".",
"Tag",
"(",
"key",
"=",
"key",
",",
"vBool",
"=",
"attr",
",",
"vType",
"=",
"jaeger",
".",
"TagTy... | 29.96 | 0.001294 |
def _hydrate_options(self, query_options: QnAMakerOptions) -> QnAMakerOptions:
"""
Combines QnAMakerOptions passed into the QnAMaker constructor with the options passed as arguments into get_answers().
:return: QnAMakerOptions with options passed into constructor overwritten by new opti... | [
"def",
"_hydrate_options",
"(",
"self",
",",
"query_options",
":",
"QnAMakerOptions",
")",
"->",
"QnAMakerOptions",
":",
"hydrated_options",
"=",
"copy",
"(",
"self",
".",
"_options",
")",
"if",
"query_options",
":",
"if",
"(",
"query_options",
".",
"score_thres... | 41.16 | 0.010446 |
def add_adjustment(self, adjustment):
"""
Create a new Gift Card Adjustment
"""
resource = self.post("adjustments", adjustment.encode())
return GiftCardAdjustment(GiftCard.format.decode(resource.body)) | [
"def",
"add_adjustment",
"(",
"self",
",",
"adjustment",
")",
":",
"resource",
"=",
"self",
".",
"post",
"(",
"\"adjustments\"",
",",
"adjustment",
".",
"encode",
"(",
")",
")",
"return",
"GiftCardAdjustment",
"(",
"GiftCard",
".",
"format",
".",
"decode",
... | 39.333333 | 0.008299 |
def adjust(colors, light):
"""Adjust the generated colors and store them in a dict that
we will later save in json format."""
raw_colors = colors[:1] + colors[8:16] + colors[8:-1]
# Manually adjust colors.
if light:
for color in raw_colors:
color = util.saturate_color(color, ... | [
"def",
"adjust",
"(",
"colors",
",",
"light",
")",
":",
"raw_colors",
"=",
"colors",
"[",
":",
"1",
"]",
"+",
"colors",
"[",
"8",
":",
"16",
"]",
"+",
"colors",
"[",
"8",
":",
"-",
"1",
"]",
"# Manually adjust colors.",
"if",
"light",
":",
"for",
... | 35 | 0.001112 |
def _GetKeysDefaultEmpty(self, top_level, keys, depth=1):
"""Retrieves plist keys, defaulting to empty values.
Args:
top_level (plistlib._InternalDict): top level plist object.
keys (set[str]): names of keys that should be returned.
depth (int): depth within the plist, where 1 is top level.
... | [
"def",
"_GetKeysDefaultEmpty",
"(",
"self",
",",
"top_level",
",",
"keys",
",",
"depth",
"=",
"1",
")",
":",
"keys",
"=",
"set",
"(",
"keys",
")",
"match",
"=",
"{",
"}",
"if",
"depth",
"==",
"1",
":",
"for",
"key",
"in",
"keys",
":",
"value",
"=... | 30.185185 | 0.008323 |
def import_funcs(self, module):
"""Create a cells from a module."""
# Outside formulas only
newcells = self._impl.new_cells_from_module(module)
return get_interfaces(newcells) | [
"def",
"import_funcs",
"(",
"self",
",",
"module",
")",
":",
"# Outside formulas only",
"newcells",
"=",
"self",
".",
"_impl",
".",
"new_cells_from_module",
"(",
"module",
")",
"return",
"get_interfaces",
"(",
"newcells",
")"
] | 40.6 | 0.009662 |
def get_notificant(self, id, **kwargs): # noqa: E501
"""Get a specific notification target # 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.get_notificant(id, ... | [
"def",
"get_notificant",
"(",
"self",
",",
"id",
",",
"*",
"*",
"kwargs",
")",
":",
"# noqa: E501",
"kwargs",
"[",
"'_return_http_data_only'",
"]",
"=",
"True",
"if",
"kwargs",
".",
"get",
"(",
"'async_req'",
")",
":",
"return",
"self",
".",
"get_notifican... | 41 | 0.00227 |
def shuffle_artist(
self,
artist,
*,
num_songs=100,
only_library=False,
recently_played=None,
only_artist=False
):
"""Get a listing of artist shuffle/mix songs.
Parameters:
artist (dict): An artist dict.
num_songs (int, Optional): The maximum number of songs to return from the station.
Def... | [
"def",
"shuffle_artist",
"(",
"self",
",",
"artist",
",",
"*",
",",
"num_songs",
"=",
"100",
",",
"only_library",
"=",
"False",
",",
"recently_played",
"=",
"None",
",",
"only_artist",
"=",
"False",
")",
":",
"station_info",
"=",
"{",
"'num_entries'",
":",... | 25.534483 | 0.035761 |
def file_download(context, id, file_id, target):
"""file_download(context, id, path)
Download a job file
>>> dcictl job-download-file [OPTIONS]
:param string id: ID of the job to download file [required]
:param string file_id: ID of the job file to download [required]
:param string target: De... | [
"def",
"file_download",
"(",
"context",
",",
"id",
",",
"file_id",
",",
"target",
")",
":",
"dci_file",
".",
"download",
"(",
"context",
",",
"id",
"=",
"id",
",",
"file_id",
"=",
"file_id",
",",
"target",
"=",
"target",
")"
] | 34.333333 | 0.002364 |
def parse_tagged_params(raw_tagged_params):
"""strip tagged information elements wlan_mgt.tag
which has generic type-length-value structure
[type, length, value]
type(1 byte), length(1 byte), value(varies)
[wlan_mgt.tag.number, wlan_mgt.tag.length, payload]
structured fie... | [
"def",
"parse_tagged_params",
"(",
"raw_tagged_params",
")",
":",
"fcs_len",
"=",
"4",
"# wlan.fcs (4 bytes)",
"idx",
"=",
"0",
"tagged_params",
"=",
"[",
"]",
"while",
"idx",
"<",
"len",
"(",
"raw_tagged_params",
")",
"-",
"fcs_len",
":",
"tag_num",
",",
"t... | 43.3 | 0.001694 |
def cidr_notation(ip_address, netmask):
"""
Retrieve the cidr notation given an ip address and netmask.
For example:
cidr_notation('12.34.56.78', '255.255.255.248')
Would return: 12.34.56.72/29
@see http://terminalmage.net/2012/06/10/how-to-find-out-the-cidr-notation-for... | [
"def",
"cidr_notation",
"(",
"ip_address",
",",
"netmask",
")",
":",
"try",
":",
"inet_aton",
"(",
"ip_address",
")",
"except",
":",
"raise",
"Exception",
"(",
"\"Invalid ip address '%s'\"",
"%",
"ip_address",
")",
"try",
":",
"inet_aton",
"(",
"netmask",
")",... | 30.333333 | 0.013845 |
def PrepareHttpRequest(self, method_config, request, global_params=None,
upload=None, upload_config=None, download=None):
"""Prepares an HTTP request to be sent."""
request_type = _LoadClass(
method_config.request_type_name, self.__client.MESSAGES_MODULE)
u... | [
"def",
"PrepareHttpRequest",
"(",
"self",
",",
"method_config",
",",
"request",
",",
"global_params",
"=",
"None",
",",
"upload",
"=",
"None",
",",
"upload_config",
"=",
"None",
",",
"download",
"=",
"None",
")",
":",
"request_type",
"=",
"_LoadClass",
"(",
... | 48.766667 | 0.002011 |
def uniform_resampling(script, voxel=1.0, offset=0.0, merge_vert=True,
discretize=False, multisample=False, thicken=False):
""" Create a new mesh that is a resampled version of the current one.
The resampling is done by building a uniform volumetric representation
where each voxel co... | [
"def",
"uniform_resampling",
"(",
"script",
",",
"voxel",
"=",
"1.0",
",",
"offset",
"=",
"0.0",
",",
"merge_vert",
"=",
"True",
",",
"discretize",
"=",
"False",
",",
"multisample",
"=",
"False",
",",
"thicken",
"=",
"False",
")",
":",
"filter_xml",
"=",... | 43.72093 | 0.00026 |
def log_before_after(name: str, desc: str):
"""Log customized stirng before & after running func."""
def func_decorator(f):
"""Wrapper stub."""
@ft.wraps(f)
def wrapper(*args, **kwargs):
"""Wrapper stub."""
LOG.info("\n%s - %s", name, desc)
res = f(*... | [
"def",
"log_before_after",
"(",
"name",
":",
"str",
",",
"desc",
":",
"str",
")",
":",
"def",
"func_decorator",
"(",
"f",
")",
":",
"\"\"\"Wrapper stub.\"\"\"",
"@",
"ft",
".",
"wraps",
"(",
"f",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*"... | 27.2 | 0.001776 |
def generate_protocol(self):
"""
Recreate the command stimulus (protocol) for the current sweep.
It's not stored point by point (that's a waste of time and memory!)
Instead it's stored as a few (x,y) points which can be easily graphed.
TODO: THIS
for segment in abf.ABFre... | [
"def",
"generate_protocol",
"(",
"self",
")",
":",
"# TODO: elegantly read the protocol like this:",
"#abf.ABFreader.read_protocol()[0].analogsignals()[sigNum]",
"# TODO: right now this works only for the first channel",
"# correct for weird recording/protocol misalignment",
"#what is magic here... | 41.625 | 0.011733 |
def get_callable_handler_function(src, handler):
"""Tranlate a string of the form "module.function" into a callable
function.
:param str src:
The path to your Lambda project containing a valid handler file.
:param str handler:
A dot delimited string representing the `<module>.<function name... | [
"def",
"get_callable_handler_function",
"(",
"src",
",",
"handler",
")",
":",
"# \"cd\" into `src` directory.",
"os",
".",
"chdir",
"(",
"src",
")",
"module_name",
",",
"function_name",
"=",
"handler",
".",
"split",
"(",
"'.'",
")",
"filename",
"=",
"get_handler... | 32.578947 | 0.00157 |
def process_array(self, array, async=False):
"""
Main part of the protocol handling. Whan comes in as the parameter is
a array of expresions, for example:
[ "1", "'some string'", "variable",
"some_call(param1, some_other_call())" ]
Each element of the is evaluated... | [
"def",
"process_array",
"(",
"self",
",",
"array",
",",
"async",
"=",
"False",
")",
":",
"result",
"=",
"list",
"(",
")",
"kwargs",
"=",
"dict",
"(",
")",
"keyword",
"=",
"None",
"def",
"append_result",
"(",
"value",
")",
":",
"if",
"keyword",
":",
... | 35.330275 | 0.001768 |
def _get_ptext_to_endchars(value, endchars):
"""Scan printables/quoted-pairs until endchars and return unquoted ptext.
This function turns a run of qcontent, ccontent-without-comments, or
dtext-with-quoted-printables into a single string by unquoting any
quoted printables. It returns the string, the r... | [
"def",
"_get_ptext_to_endchars",
"(",
"value",
",",
"endchars",
")",
":",
"_3to2list",
"=",
"list",
"(",
"_wsp_splitter",
"(",
"value",
",",
"1",
")",
")",
"fragment",
",",
"remainder",
",",
"=",
"_3to2list",
"[",
":",
"1",
"]",
"+",
"[",
"_3to2list",
... | 34.1 | 0.000951 |
def do_mkdir(self, path):
"""create a new directory"""
path = path[0]
self.n.makeDirectory(self.current_path + path)
self.dirs = self.dir_complete() | [
"def",
"do_mkdir",
"(",
"self",
",",
"path",
")",
":",
"path",
"=",
"path",
"[",
"0",
"]",
"self",
".",
"n",
".",
"makeDirectory",
"(",
"self",
".",
"current_path",
"+",
"path",
")",
"self",
".",
"dirs",
"=",
"self",
".",
"dir_complete",
"(",
")"
] | 29.333333 | 0.01105 |
def datatype2schemacls(
_datatype, _registry=None, _factory=None, _force=True,
_besteffort=True, **kwargs
):
"""Get a schema class which has been associated to input data type by the
registry or the factory in this order.
:param type datatype: data type from where get associated schema.
... | [
"def",
"datatype2schemacls",
"(",
"_datatype",
",",
"_registry",
"=",
"None",
",",
"_factory",
"=",
"None",
",",
"_force",
"=",
"True",
",",
"_besteffort",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
":",
"result",
"=",
"None",
"gdbt",
"=",
"getbydatatype... | 38.540541 | 0.000684 |
def list_availability_zones(self, retrieve_all=True, **_params):
"""Fetches a list of all availability zones."""
return self.list('availability_zones', self.availability_zones_path,
retrieve_all, **_params) | [
"def",
"list_availability_zones",
"(",
"self",
",",
"retrieve_all",
"=",
"True",
",",
"*",
"*",
"_params",
")",
":",
"return",
"self",
".",
"list",
"(",
"'availability_zones'",
",",
"self",
".",
"availability_zones_path",
",",
"retrieve_all",
",",
"*",
"*",
... | 61 | 0.008097 |
def _configure_logger(cls, simple_name, log_dest, detail_level,
log_filename, connection, propagate):
# pylint: disable=line-too-long
"""
Configure the pywbem loggers and optionally activate WBEM connections
for logging and setting a log detail level.
P... | [
"def",
"_configure_logger",
"(",
"cls",
",",
"simple_name",
",",
"log_dest",
",",
"detail_level",
",",
"log_filename",
",",
"connection",
",",
"propagate",
")",
":",
"# pylint: disable=line-too-long",
"# noqa: E501",
"# pylint: enable=line-too-long",
"if",
"simple_name",
... | 43.764706 | 0.000876 |
def symbolic_barycentric(function):
"""
Symbolically integrate a function(x,y,z) across a triangle or mesh.
Parameters
----------
function: string or sympy expression
x, y, z will be replaced with a barycentric representation
and the the function is integrated across the... | [
"def",
"symbolic_barycentric",
"(",
"function",
")",
":",
"class",
"evaluator",
":",
"def",
"__init__",
"(",
"self",
",",
"expr",
",",
"expr_args",
")",
":",
"self",
".",
"lambdified",
"=",
"sp",
".",
"lambdify",
"(",
"args",
"=",
"expr_args",
",",
"expr... | 28.131579 | 0.000452 |
def adjust_boxes(line_wave, box_widths, left_edge, right_edge,
max_iter=1000, adjust_factor=0.35,
factor_decrement=3.0, fd_p=0.75):
"""Ajdust given boxes so that they don't overlap.
Parameters
----------
line_wave: list or array of floats
Line wave lengths. The... | [
"def",
"adjust_boxes",
"(",
"line_wave",
",",
"box_widths",
",",
"left_edge",
",",
"right_edge",
",",
"max_iter",
"=",
"1000",
",",
"adjust_factor",
"=",
"0.35",
",",
"factor_decrement",
"=",
"3.0",
",",
"fd_p",
"=",
"0.75",
")",
":",
"# Adjust positions.",
... | 35.552083 | 0.000285 |
def adj_par_names(self):
""" wrapper around pyemu.Pst.adj_par_names for list adjustable parameter
names
Returns
-------
adj_par_names : list
pyemu.Pst.adj_par_names
"""
if self.__pst is not None:
return self.pst.adj_par_names
... | [
"def",
"adj_par_names",
"(",
"self",
")",
":",
"if",
"self",
".",
"__pst",
"is",
"not",
"None",
":",
"return",
"self",
".",
"pst",
".",
"adj_par_names",
"else",
":",
"return",
"self",
".",
"jco",
".",
"par_names"
] | 25.285714 | 0.010899 |
def register_scm_provider(scm_name: str):
"""Return a decorator for registering a SCM provider named `scm_name`."""
def register_decorator(scm_class: SourceControl):
"""Decorator for registering SCM provider."""
if scm_name in ScmManager.providers:
raise KeyError('{} already registe... | [
"def",
"register_scm_provider",
"(",
"scm_name",
":",
"str",
")",
":",
"def",
"register_decorator",
"(",
"scm_class",
":",
"SourceControl",
")",
":",
"\"\"\"Decorator for registering SCM provider.\"\"\"",
"if",
"scm_name",
"in",
"ScmManager",
".",
"providers",
":",
"r... | 45.923077 | 0.001642 |
def upper_camel(string, prefix='', suffix=''):
"""
Generate a camel-case identifier with the first word capitalised.
Useful for class names.
Takes a string, prefix, and optional suffix.
`prefix` can be set to `''`, though be careful - without a prefix, the
function will throw `InvalidIdentifie... | [
"def",
"upper_camel",
"(",
"string",
",",
"prefix",
"=",
"''",
",",
"suffix",
"=",
"''",
")",
":",
"return",
"require_valid",
"(",
"append_underscore_if_keyword",
"(",
"''",
".",
"join",
"(",
"upper_case_first_char",
"(",
"word",
")",
"for",
"word",
"in",
... | 30.55 | 0.001587 |
def params(self):
"""
Returns a ParamDoc for each parameter of the function, picking up
the order from the actual parameter list.
>>> comments = parse_comments_for_file('examples/module_closure.js')
>>> fn2 = FunctionDoc(comments[2])
>>> fn2.params[0].name
'elem'... | [
"def",
"params",
"(",
"self",
")",
":",
"tag_texts",
"=",
"self",
".",
"get_as_list",
"(",
"'param'",
")",
"+",
"self",
".",
"get_as_list",
"(",
"'argument'",
")",
"if",
"self",
".",
"get",
"(",
"'guessed_params'",
")",
"is",
"None",
":",
"return",
"["... | 35.8 | 0.002176 |
def canonicalize_path(cwd, path):
"""
Canonicalizes a path relative to a given working directory. That
is, the path, if not absolute, is interpreted relative to the
working directory, then converted to absolute form.
:param cwd: The working directory.
:param path: The path to canonicalize.
... | [
"def",
"canonicalize_path",
"(",
"cwd",
",",
"path",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"isabs",
"(",
"path",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"cwd",
",",
"path",
")",
"return",
"os",
".",
"path",
".",
"ab... | 28.0625 | 0.002155 |
def execute_no_results(self, sock_info, generator):
"""Execute all operations, returning no results (w=0).
"""
if self.uses_collation:
raise ConfigurationError(
'Collation is unsupported for unacknowledged writes.')
if self.uses_array_filters:
rais... | [
"def",
"execute_no_results",
"(",
"self",
",",
"sock_info",
",",
"generator",
")",
":",
"if",
"self",
".",
"uses_collation",
":",
"raise",
"ConfigurationError",
"(",
"'Collation is unsupported for unacknowledged writes.'",
")",
"if",
"self",
".",
"uses_array_filters",
... | 44.681818 | 0.000995 |
def _http_request(url, request_timeout=None):
'''
PRIVATE METHOD
Uses salt.utils.json.load to fetch the JSON results from the solr API.
url : str
a complete URL that can be passed to urllib.open
request_timeout : int (None)
The number of seconds before the timeout should fail. Leave... | [
"def",
"_http_request",
"(",
"url",
",",
"request_timeout",
"=",
"None",
")",
":",
"_auth",
"(",
"url",
")",
"try",
":",
"request_timeout",
"=",
"__salt__",
"[",
"'config.option'",
"]",
"(",
"'solr.request_timeout'",
")",
"kwargs",
"=",
"{",
"}",
"if",
"re... | 36.5 | 0.002225 |
def gauge_laplacian(npts, spacing=1.0, beta=0.1):
"""Construct a Gauge Laplacian from Quantum Chromodynamics for regular 2D grids.
Note that this function is not written efficiently, but should be
fine for N x N grids where N is in the low hundreds.
Parameters
----------
npts : int
num... | [
"def",
"gauge_laplacian",
"(",
"npts",
",",
"spacing",
"=",
"1.0",
",",
"beta",
"=",
"0.1",
")",
":",
"# The gauge Laplacian has the same sparsity structure as a normal",
"# Laplacian, so we start out with a Poisson Operator",
"N",
"=",
"npts",
"A",
"=",
"poisson",
"(",
... | 29.156522 | 0.000577 |
def get_gpu_ids():
"""Get the IDs of the GPUs that are available to the worker.
If the CUDA_VISIBLE_DEVICES environment variable was set when the worker
started up, then the IDs returned by this method will be a subset of the
IDs in CUDA_VISIBLE_DEVICES. If not, the IDs will fall in the range
[0, N... | [
"def",
"get_gpu_ids",
"(",
")",
":",
"if",
"_mode",
"(",
")",
"==",
"LOCAL_MODE",
":",
"raise",
"Exception",
"(",
"\"ray.get_gpu_ids() currently does not work in PYTHON \"",
"\"MODE.\"",
")",
"all_resource_ids",
"=",
"global_worker",
".",
"raylet_client",
".",
"resour... | 38.75 | 0.000899 |
def publish_workflow_submission(self,
user_id,
workflow_id_or_name,
parameters):
"""Publish workflow submission parameters."""
msg = {
"user": user_id,
"workflow_id_or_name... | [
"def",
"publish_workflow_submission",
"(",
"self",
",",
"user_id",
",",
"workflow_id_or_name",
",",
"parameters",
")",
":",
"msg",
"=",
"{",
"\"user\"",
":",
"user_id",
",",
"\"workflow_id_or_name\"",
":",
"workflow_id_or_name",
",",
"\"parameters\"",
":",
"paramete... | 37 | 0.01199 |
def matrix_element(ji, fi, mi, jj, fj, mj,
II, reduced_matrix_element, q=None,
numeric=True, convention=1):
r"""Calculate a matrix element of the electric dipole (in the helicity
basis).
We calculate the matrix element for the cyclical transition of the D2 line
in ... | [
"def",
"matrix_element",
"(",
"ji",
",",
"fi",
",",
"mi",
",",
"jj",
",",
"fj",
",",
"mj",
",",
"II",
",",
"reduced_matrix_element",
",",
"q",
"=",
"None",
",",
"numeric",
"=",
"True",
",",
"convention",
"=",
"1",
")",
":",
"if",
"q",
"is",
"None... | 29.333333 | 0.000687 |
def lazy_reverse_binmap(f, xs):
"""
Same as lazy_binmap, except the parameters are flipped for the binary function
"""
return (f(y, x) for x, y in zip(xs, xs[1:])) | [
"def",
"lazy_reverse_binmap",
"(",
"f",
",",
"xs",
")",
":",
"return",
"(",
"f",
"(",
"y",
",",
"x",
")",
"for",
"x",
",",
"y",
"in",
"zip",
"(",
"xs",
",",
"xs",
"[",
"1",
":",
"]",
")",
")"
] | 35.8 | 0.010929 |
def execute_sql(server_context, schema_name, sql, container_path=None,
max_rows=None,
sort=None,
offset=None,
container_filter=None,
save_in_session=None,
parameters=None,
required_version=None,
... | [
"def",
"execute_sql",
"(",
"server_context",
",",
"schema_name",
",",
"sql",
",",
"container_path",
"=",
"None",
",",
"max_rows",
"=",
"None",
",",
"sort",
"=",
"None",
",",
"offset",
"=",
"None",
",",
"container_filter",
"=",
"None",
",",
"save_in_session",... | 36.912281 | 0.002315 |
def generate_pos_tagger(check_accuracy=False):
"""Accuracy is about 0.94 with 90% training data."""
global tagger
logging.debug("Reading TIGER corpus")
corp = nltk.corpus.ConllCorpusReader(DIR_PATH, TIGER_FILE_NAME,
['ignore', 'words', 'ignore', 'ignore', 'pos'],... | [
"def",
"generate_pos_tagger",
"(",
"check_accuracy",
"=",
"False",
")",
":",
"global",
"tagger",
"logging",
".",
"debug",
"(",
"\"Reading TIGER corpus\"",
")",
"corp",
"=",
"nltk",
".",
"corpus",
".",
"ConllCorpusReader",
"(",
"DIR_PATH",
",",
"TIGER_FILE_NAME",
... | 46 | 0.002457 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.