repo stringlengths 7 55 | path stringlengths 4 223 | url stringlengths 87 315 | code stringlengths 75 104k | code_tokens list | docstring stringlengths 1 46.9k | docstring_tokens list | language stringclasses 1
value | partition stringclasses 3
values | avg_line_len float64 7.91 980 |
|---|---|---|---|---|---|---|---|---|---|
fboender/ansible-cmdb | lib/mako/runtime.py | https://github.com/fboender/ansible-cmdb/blob/ebd960ac10684e8c9ec2b12751bba2c4c9504ab7/lib/mako/runtime.py#L732-L759 | def _inherit_from(context, uri, calling_uri):
"""called by the _inherit method in template modules to set
up the inheritance chain at the start of a template's
execution."""
if uri is None:
return None
template = _lookup_template(context, uri, calling_uri)
self_ns = context['self']
... | [
"def",
"_inherit_from",
"(",
"context",
",",
"uri",
",",
"calling_uri",
")",
":",
"if",
"uri",
"is",
"None",
":",
"return",
"None",
"template",
"=",
"_lookup_template",
"(",
"context",
",",
"uri",
",",
"calling_uri",
")",
"self_ns",
"=",
"context",
"[",
... | called by the _inherit method in template modules to set
up the inheritance chain at the start of a template's
execution. | [
"called",
"by",
"the",
"_inherit",
"method",
"in",
"template",
"modules",
"to",
"set",
"up",
"the",
"inheritance",
"chain",
"at",
"the",
"start",
"of",
"a",
"template",
"s",
"execution",
"."
] | python | train | 37.142857 |
amelchio/pysonos | pysonos/core.py | https://github.com/amelchio/pysonos/blob/23527c445a00e198fbb94d44b92f7f99d139e325/pysonos/core.py#L705-L716 | def mute(self):
"""bool: The speaker's mute state.
True if muted, False otherwise.
"""
response = self.renderingControl.GetMute([
('InstanceID', 0),
('Channel', 'Master')
])
mute_state = response['CurrentMute']
return bool(int(mute_state)... | [
"def",
"mute",
"(",
"self",
")",
":",
"response",
"=",
"self",
".",
"renderingControl",
".",
"GetMute",
"(",
"[",
"(",
"'InstanceID'",
",",
"0",
")",
",",
"(",
"'Channel'",
",",
"'Master'",
")",
"]",
")",
"mute_state",
"=",
"response",
"[",
"'CurrentMu... | bool: The speaker's mute state.
True if muted, False otherwise. | [
"bool",
":",
"The",
"speaker",
"s",
"mute",
"state",
"."
] | python | train | 25.833333 |
bpython/curtsies | examples/tttplaybitboard.py | https://github.com/bpython/curtsies/blob/223e42b97fbf6c86b479ed4f0963a067333c5a63/examples/tttplaybitboard.py#L161-L165 | def apply_move(grid, move):
"Try to move: return a new grid, or None if illegal."
p, q = grid
bit = 1 << move
return (q, p | bit) if 0 == (bit & (p | q)) else None | [
"def",
"apply_move",
"(",
"grid",
",",
"move",
")",
":",
"p",
",",
"q",
"=",
"grid",
"bit",
"=",
"1",
"<<",
"move",
"return",
"(",
"q",
",",
"p",
"|",
"bit",
")",
"if",
"0",
"==",
"(",
"bit",
"&",
"(",
"p",
"|",
"q",
")",
")",
"else",
"No... | Try to move: return a new grid, or None if illegal. | [
"Try",
"to",
"move",
":",
"return",
"a",
"new",
"grid",
"or",
"None",
"if",
"illegal",
"."
] | python | train | 35 |
OpenKMIP/PyKMIP | kmip/core/messages/payloads/activate.py | https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/activate.py#L95-L103 | def validate(self):
"""
Error check the attributes of the ActivateRequestPayload object.
"""
if self.unique_identifier is not None:
if not isinstance(self.unique_identifier,
attributes.UniqueIdentifier):
msg = "invalid unique iden... | [
"def",
"validate",
"(",
"self",
")",
":",
"if",
"self",
".",
"unique_identifier",
"is",
"not",
"None",
":",
"if",
"not",
"isinstance",
"(",
"self",
".",
"unique_identifier",
",",
"attributes",
".",
"UniqueIdentifier",
")",
":",
"msg",
"=",
"\"invalid unique ... | Error check the attributes of the ActivateRequestPayload object. | [
"Error",
"check",
"the",
"attributes",
"of",
"the",
"ActivateRequestPayload",
"object",
"."
] | python | test | 39.555556 |
angr/angr | angr/analyses/congruency_check.py | https://github.com/angr/angr/blob/4e2f97d56af5419ee73bdb30482c8dd8ff5f3e40/angr/analyses/congruency_check.py#L281-L342 | def compare_states(self, sl, sr):
"""
Compares two states for similarity.
"""
joint_solver = claripy.Solver()
# make sure the canonicalized constraints are the same
n_map, n_counter, n_canon_constraint = claripy.And(*sr.solver.constraints).canonicalize() #pylint:disable=... | [
"def",
"compare_states",
"(",
"self",
",",
"sl",
",",
"sr",
")",
":",
"joint_solver",
"=",
"claripy",
".",
"Solver",
"(",
")",
"# make sure the canonicalized constraints are the same",
"n_map",
",",
"n_counter",
",",
"n_canon_constraint",
"=",
"claripy",
".",
"And... | Compares two states for similarity. | [
"Compares",
"two",
"states",
"for",
"similarity",
"."
] | python | train | 49.822581 |
refindlyllc/rets | rets/session.py | https://github.com/refindlyllc/rets/blob/c615dfc272cff0825fd3b50863c46afc3e33916f/rets/session.py#L197-L238 | def _make_metadata_request(self, meta_id, metadata_type=None):
"""
Get the Metadata. The Session initializes with 'COMPACT-DECODED' as the format type. If that returns a DTD error
then we change to the 'STANDARD-XML' format and try again.
:param meta_id: The name of the resource, class, ... | [
"def",
"_make_metadata_request",
"(",
"self",
",",
"meta_id",
",",
"metadata_type",
"=",
"None",
")",
":",
"# If this metadata _request has already happened, returned the saved result.",
"key",
"=",
"'{0!s}:{1!s}'",
".",
"format",
"(",
"metadata_type",
",",
"meta_id",
")"... | Get the Metadata. The Session initializes with 'COMPACT-DECODED' as the format type. If that returns a DTD error
then we change to the 'STANDARD-XML' format and try again.
:param meta_id: The name of the resource, class, or lookup to get metadata for
:param metadata_type: The RETS metadata type
... | [
"Get",
"the",
"Metadata",
".",
"The",
"Session",
"initializes",
"with",
"COMPACT",
"-",
"DECODED",
"as",
"the",
"format",
"type",
".",
"If",
"that",
"returns",
"a",
"DTD",
"error",
"then",
"we",
"change",
"to",
"the",
"STANDARD",
"-",
"XML",
"format",
"a... | python | train | 44.97619 |
census-instrumentation/opencensus-python | opencensus/trace/tracers/context_tracer.py | https://github.com/census-instrumentation/opencensus-python/blob/992b223f7e34c5dcb65922b7d5c827e7a1351e7d/opencensus/trace/tracers/context_tracer.py#L149-L176 | def get_span_datas(self, span):
"""Extracts a list of SpanData tuples from a span
:rtype: list of opencensus.trace.span_data.SpanData
:return list of SpanData tuples
"""
span_datas = [
span_data_module.SpanData(
name=ss.name,
context=s... | [
"def",
"get_span_datas",
"(",
"self",
",",
"span",
")",
":",
"span_datas",
"=",
"[",
"span_data_module",
".",
"SpanData",
"(",
"name",
"=",
"ss",
".",
"name",
",",
"context",
"=",
"self",
".",
"span_context",
",",
"span_id",
"=",
"ss",
".",
"span_id",
... | Extracts a list of SpanData tuples from a span
:rtype: list of opencensus.trace.span_data.SpanData
:return list of SpanData tuples | [
"Extracts",
"a",
"list",
"of",
"SpanData",
"tuples",
"from",
"a",
"span"
] | python | train | 34.464286 |
google/prettytensor | prettytensor/tutorial/data_utils.py | https://github.com/google/prettytensor/blob/75daa0b11252590f548da5647addc0ea610c4c45/prettytensor/tutorial/data_utils.py#L92-L106 | def mnist(training):
"""Downloads MNIST and loads it into numpy arrays."""
if training:
data_filename = 'train-images-idx3-ubyte.gz'
labels_filename = 'train-labels-idx1-ubyte.gz'
count = 60000
else:
data_filename = 't10k-images-idx3-ubyte.gz'
labels_filename = 't10k-labels-idx1-ubyte.gz'
... | [
"def",
"mnist",
"(",
"training",
")",
":",
"if",
"training",
":",
"data_filename",
"=",
"'train-images-idx3-ubyte.gz'",
"labels_filename",
"=",
"'train-labels-idx1-ubyte.gz'",
"count",
"=",
"60000",
"else",
":",
"data_filename",
"=",
"'t10k-images-idx3-ubyte.gz'",
"labe... | Downloads MNIST and loads it into numpy arrays. | [
"Downloads",
"MNIST",
"and",
"loads",
"it",
"into",
"numpy",
"arrays",
"."
] | python | train | 36.666667 |
modin-project/modin | modin/backends/pandas/query_compiler.py | https://github.com/modin-project/modin/blob/5b77d242596560c646b8405340c9ce64acb183cb/modin/backends/pandas/query_compiler.py#L1251-L1263 | def median(self, **kwargs):
"""Returns median of each column or row.
Returns:
A new QueryCompiler object containing the median of each column or row.
"""
if self._is_transposed:
kwargs["axis"] = kwargs.get("axis", 0) ^ 1
return self.transpose().median... | [
"def",
"median",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"_is_transposed",
":",
"kwargs",
"[",
"\"axis\"",
"]",
"=",
"kwargs",
".",
"get",
"(",
"\"axis\"",
",",
"0",
")",
"^",
"1",
"return",
"self",
".",
"transpose",
"(",... | Returns median of each column or row.
Returns:
A new QueryCompiler object containing the median of each column or row. | [
"Returns",
"median",
"of",
"each",
"column",
"or",
"row",
"."
] | python | train | 41.769231 |
yyuu/botornado | boto/__init__.py | https://github.com/yyuu/botornado/blob/fffb056f5ff2324d1d5c1304014cfb1d899f602e/boto/__init__.py#L521-L536 | def check_extensions(module_name, module_path):
"""
This function checks for extensions to boto modules. It should be called in the
__init__.py file of all boto modules. See:
http://code.google.com/p/boto/wiki/ExtendModules
for details.
"""
option_name = '%s_extend' % module_name
vers... | [
"def",
"check_extensions",
"(",
"module_name",
",",
"module_path",
")",
":",
"option_name",
"=",
"'%s_extend'",
"%",
"module_name",
"version",
"=",
"config",
".",
"get",
"(",
"'Boto'",
",",
"option_name",
",",
"None",
")",
"if",
"version",
":",
"dirname",
"=... | This function checks for extensions to boto modules. It should be called in the
__init__.py file of all boto modules. See:
http://code.google.com/p/boto/wiki/ExtendModules
for details. | [
"This",
"function",
"checks",
"for",
"extensions",
"to",
"boto",
"modules",
".",
"It",
"should",
"be",
"called",
"in",
"the",
"__init__",
".",
"py",
"file",
"of",
"all",
"boto",
"modules",
".",
"See",
":",
"http",
":",
"//",
"code",
".",
"google",
".",... | python | train | 36.875 |
Microsoft/azure-devops-python-api | azure-devops/azure/devops/v5_1/task_agent/task_agent_client.py | https://github.com/Microsoft/azure-devops-python-api/blob/4777ffda2f5052fabbaddb2abe9cb434e0cf1aa8/azure-devops/azure/devops/v5_1/task_agent/task_agent_client.py#L829-L843 | def delete_variable_group(self, project, group_id):
"""DeleteVariableGroup.
[Preview API] Delete a variable group
:param str project: Project ID or project name
:param int group_id: Id of the variable group.
"""
route_values = {}
if project is not None:
... | [
"def",
"delete_variable_group",
"(",
"self",
",",
"project",
",",
"group_id",
")",
":",
"route_values",
"=",
"{",
"}",
"if",
"project",
"is",
"not",
"None",
":",
"route_values",
"[",
"'project'",
"]",
"=",
"self",
".",
"_serialize",
".",
"url",
"(",
"'pr... | DeleteVariableGroup.
[Preview API] Delete a variable group
:param str project: Project ID or project name
:param int group_id: Id of the variable group. | [
"DeleteVariableGroup",
".",
"[",
"Preview",
"API",
"]",
"Delete",
"a",
"variable",
"group",
":",
"param",
"str",
"project",
":",
"Project",
"ID",
"or",
"project",
"name",
":",
"param",
"int",
"group_id",
":",
"Id",
"of",
"the",
"variable",
"group",
"."
] | python | train | 46.8 |
saltstack/salt | salt/transport/ipc.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/transport/ipc.py#L616-L629 | def close(self):
'''
Routines to handle any cleanup before the instance shuts down.
Sockets and filehandles should be closed explicitly, to prevent
leaks.
'''
if self._closing:
return
self._closing = True
for stream in self.streams:
... | [
"def",
"close",
"(",
"self",
")",
":",
"if",
"self",
".",
"_closing",
":",
"return",
"self",
".",
"_closing",
"=",
"True",
"for",
"stream",
"in",
"self",
".",
"streams",
":",
"stream",
".",
"close",
"(",
")",
"self",
".",
"streams",
".",
"clear",
"... | Routines to handle any cleanup before the instance shuts down.
Sockets and filehandles should be closed explicitly, to prevent
leaks. | [
"Routines",
"to",
"handle",
"any",
"cleanup",
"before",
"the",
"instance",
"shuts",
"down",
".",
"Sockets",
"and",
"filehandles",
"should",
"be",
"closed",
"explicitly",
"to",
"prevent",
"leaks",
"."
] | python | train | 30.071429 |
BerkeleyAutomation/autolab_core | autolab_core/rigid_transformations.py | https://github.com/BerkeleyAutomation/autolab_core/blob/8f3813f6401972868cc5e3981ba1b4382d4418d5/autolab_core/rigid_transformations.py#L560-L590 | def delete_from_ros(self, service_name='rigid_transforms/rigid_transform_publisher', namespace=None):
"""Removes RigidTransform referencing from_frame and to_frame from ROS publisher.
Note that this may not be this exact transform, but may that references the same frames (order doesn't matter)
... | [
"def",
"delete_from_ros",
"(",
"self",
",",
"service_name",
"=",
"'rigid_transforms/rigid_transform_publisher'",
",",
"namespace",
"=",
"None",
")",
":",
"if",
"namespace",
"==",
"None",
":",
"service_name",
"=",
"rospy",
".",
"get_namespace",
"(",
")",
"+",
"se... | Removes RigidTransform referencing from_frame and to_frame from ROS publisher.
Note that this may not be this exact transform, but may that references the same frames (order doesn't matter)
Also, note that it may take quite a while for the transform to disappear from rigid_transform_publisher's... | [
"Removes",
"RigidTransform",
"referencing",
"from_frame",
"and",
"to_frame",
"from",
"ROS",
"publisher",
".",
"Note",
"that",
"this",
"may",
"not",
"be",
"this",
"exact",
"transform",
"but",
"may",
"that",
"references",
"the",
"same",
"frames",
"(",
"order",
"... | python | train | 51.612903 |
nok/sklearn-porter | sklearn_porter/estimator/classifier/GaussianNB/__init__.py | https://github.com/nok/sklearn-porter/blob/04673f768310bde31f9747a68a5e070592441ef2/sklearn_porter/estimator/classifier/GaussianNB/__init__.py#L61-L135 | def export(self, class_name, method_name, export_data=False,
export_dir='.', export_filename='data.json',
export_append_checksum=False, **kwargs):
"""
Port a trained estimator to the syntax of a chosen programming language.
Parameters
----------
:pa... | [
"def",
"export",
"(",
"self",
",",
"class_name",
",",
"method_name",
",",
"export_data",
"=",
"False",
",",
"export_dir",
"=",
"'.'",
",",
"export_filename",
"=",
"'data.json'",
",",
"export_append_checksum",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
... | Port a trained estimator to the syntax of a chosen programming language.
Parameters
----------
:param class_name : string
The name of the class in the returned result.
:param method_name : string
The name of the method in the returned result.
:param expor... | [
"Port",
"a",
"trained",
"estimator",
"to",
"the",
"syntax",
"of",
"a",
"chosen",
"programming",
"language",
"."
] | python | train | 38.04 |
Demonware/jose | jose.py | https://github.com/Demonware/jose/blob/5835ec9c9fcab17eddea3c3169881ec12df552d4/jose.py#L315-L380 | def legacy_decrypt(jwe, jwk, adata='', validate_claims=True,
expiry_seconds=None):
""" Decrypts a deserialized :class:`~jose.JWE`
:param jwe: An instance of :class:`~jose.JWE`
:param jwk: A `dict` representing the JWK required to decrypt the content
of the :class:`~jose.J... | [
"def",
"legacy_decrypt",
"(",
"jwe",
",",
"jwk",
",",
"adata",
"=",
"''",
",",
"validate_claims",
"=",
"True",
",",
"expiry_seconds",
"=",
"None",
")",
":",
"protected_header",
",",
"encrypted_key",
",",
"iv",
",",
"ciphertext",
",",
"authentication_tag",
"=... | Decrypts a deserialized :class:`~jose.JWE`
:param jwe: An instance of :class:`~jose.JWE`
:param jwk: A `dict` representing the JWK required to decrypt the content
of the :class:`~jose.JWE`.
:param adata: Arbitrary string data used during encryption for additional
authentic... | [
"Decrypts",
"a",
"deserialized",
":",
"class",
":",
"~jose",
".",
"JWE"
] | python | train | 38.757576 |
saltstack/salt | salt/modules/rabbitmq.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/rabbitmq.py#L789-L805 | def list_queues(runas=None, *args):
'''
Returns queue details of the / virtual host
CLI Example:
.. code-block:: bash
salt '*' rabbitmq.list_queues messages consumers
'''
if runas is None and not salt.utils.platform.is_windows():
runas = salt.utils.user.get_user()
cmd = [R... | [
"def",
"list_queues",
"(",
"runas",
"=",
"None",
",",
"*",
"args",
")",
":",
"if",
"runas",
"is",
"None",
"and",
"not",
"salt",
".",
"utils",
".",
"platform",
".",
"is_windows",
"(",
")",
":",
"runas",
"=",
"salt",
".",
"utils",
".",
"user",
".",
... | Returns queue details of the / virtual host
CLI Example:
.. code-block:: bash
salt '*' rabbitmq.list_queues messages consumers | [
"Returns",
"queue",
"details",
"of",
"the",
"/",
"virtual",
"host"
] | python | train | 30.764706 |
opennode/waldur-core | waldur_core/structure/metadata.py | https://github.com/opennode/waldur-core/blob/d6c17a9592bb6c49c33567542eef8d099605a46a/waldur_core/structure/metadata.py#L186-L230 | def get_field_info(self, field, field_name):
"""
Given an instance of a serializer field, return a dictionary
of metadata about it.
"""
field_info = OrderedDict()
field_info['type'] = self.label_lookup[field]
field_info['required'] = getattr(field, 'required', Fal... | [
"def",
"get_field_info",
"(",
"self",
",",
"field",
",",
"field_name",
")",
":",
"field_info",
"=",
"OrderedDict",
"(",
")",
"field_info",
"[",
"'type'",
"]",
"=",
"self",
".",
"label_lookup",
"[",
"field",
"]",
"field_info",
"[",
"'required'",
"]",
"=",
... | Given an instance of a serializer field, return a dictionary
of metadata about it. | [
"Given",
"an",
"instance",
"of",
"a",
"serializer",
"field",
"return",
"a",
"dictionary",
"of",
"metadata",
"about",
"it",
"."
] | python | train | 39.444444 |
IRC-SPHERE/HyperStream | hyperstream/stream/stream.py | https://github.com/IRC-SPHERE/HyperStream/blob/98478f4d31ed938f4aa7c958ed0d4c3ffcb2e780/hyperstream/stream/stream.py#L246-L256 | def calculated_intervals(self, intervals):
"""
Updates the calculated intervals in the database. Performs an upsert
:param intervals: The calculated intervals
:return: None
"""
logging.debug("set calculated intervals")
self.mongo_model.set_calculated_intervals(in... | [
"def",
"calculated_intervals",
"(",
"self",
",",
"intervals",
")",
":",
"logging",
".",
"debug",
"(",
"\"set calculated intervals\"",
")",
"self",
".",
"mongo_model",
".",
"set_calculated_intervals",
"(",
"intervals",
")",
"self",
".",
"save",
"(",
")",
"self",
... | Updates the calculated intervals in the database. Performs an upsert
:param intervals: The calculated intervals
:return: None | [
"Updates",
"the",
"calculated",
"intervals",
"in",
"the",
"database",
".",
"Performs",
"an",
"upsert"
] | python | train | 36.363636 |
bukun/TorCMS | torcms/model/post_model.py | https://github.com/bukun/TorCMS/blob/6567c7fe2604a1d646d4570c017840958630ed2b/torcms/model/post_model.py#L272-L304 | def query_recent(num=8, **kwargs):
'''
query recent posts.
'''
order_by_create = kwargs.get('order_by_create', False)
kind = kwargs.get('kind', None)
if order_by_create:
if kind:
recent_recs = TabPost.select().where(
(TabPos... | [
"def",
"query_recent",
"(",
"num",
"=",
"8",
",",
"*",
"*",
"kwargs",
")",
":",
"order_by_create",
"=",
"kwargs",
".",
"get",
"(",
"'order_by_create'",
",",
"False",
")",
"kind",
"=",
"kwargs",
".",
"get",
"(",
"'kind'",
",",
"None",
")",
"if",
"orde... | query recent posts. | [
"query",
"recent",
"posts",
"."
] | python | train | 34.727273 |
fabioz/PyDev.Debugger | _pydevd_bundle/pydevd_comm.py | https://github.com/fabioz/PyDev.Debugger/blob/ed9c4307662a5593b8a7f1f3389ecd0e79b8c503/_pydevd_bundle/pydevd_comm.py#L1047-L1060 | def internal_get_description(dbg, seq, thread_id, frame_id, expression):
''' Fetch the variable description stub from the debug console
'''
try:
frame = dbg.find_frame(thread_id, frame_id)
description = pydevd_console.get_description(frame, thread_id, frame_id, expression)
descriptio... | [
"def",
"internal_get_description",
"(",
"dbg",
",",
"seq",
",",
"thread_id",
",",
"frame_id",
",",
"expression",
")",
":",
"try",
":",
"frame",
"=",
"dbg",
".",
"find_frame",
"(",
"thread_id",
",",
"frame_id",
")",
"description",
"=",
"pydevd_console",
".",
... | Fetch the variable description stub from the debug console | [
"Fetch",
"the",
"variable",
"description",
"stub",
"from",
"the",
"debug",
"console"
] | python | train | 54.428571 |
spyder-ide/spyder | spyder/widgets/tabs.py | https://github.com/spyder-ide/spyder/blob/f76836ce1b924bcc4efd3f74f2960d26a4e528e0/spyder/widgets/tabs.py#L123-L132 | def edit_finished(self):
"""On clean exit, update tab name."""
# Hides editor
self.hide()
if isinstance(self.tab_index, int) and self.tab_index >= 0:
# We are editing a valid tab, update name
tab_text = to_text_string(self.text())
self.main.se... | [
"def",
"edit_finished",
"(",
"self",
")",
":",
"# Hides editor\r",
"self",
".",
"hide",
"(",
")",
"if",
"isinstance",
"(",
"self",
".",
"tab_index",
",",
"int",
")",
"and",
"self",
".",
"tab_index",
">=",
"0",
":",
"# We are editing a valid tab, update name\r"... | On clean exit, update tab name. | [
"On",
"clean",
"exit",
"update",
"tab",
"name",
"."
] | python | train | 39.9 |
pandas-dev/pandas | doc/source/conf.py | https://github.com/pandas-dev/pandas/blob/9feb3ad92cc0397a04b665803a49299ee7aa1037/doc/source/conf.py#L688-L724 | def process_class_docstrings(app, what, name, obj, options, lines):
"""
For those classes for which we use ::
:template: autosummary/class_without_autosummary.rst
the documented attributes/methods have to be listed in the class
docstring. However, if one of those lists is empty, we use 'None',
... | [
"def",
"process_class_docstrings",
"(",
"app",
",",
"what",
",",
"name",
",",
"obj",
",",
"options",
",",
"lines",
")",
":",
"if",
"what",
"==",
"\"class\"",
":",
"joined",
"=",
"'\\n'",
".",
"join",
"(",
"lines",
")",
"templates",
"=",
"[",
"\"\"\".. ... | For those classes for which we use ::
:template: autosummary/class_without_autosummary.rst
the documented attributes/methods have to be listed in the class
docstring. However, if one of those lists is empty, we use 'None',
which then generates warnings in sphinx / ugly html output.
This "autodoc-p... | [
"For",
"those",
"classes",
"for",
"which",
"we",
"use",
"::"
] | python | train | 23.621622 |
pytroll/trollimage | trollimage/xrimage.py | https://github.com/pytroll/trollimage/blob/d35a7665ad475ff230e457085523e21f2cd3f454/trollimage/xrimage.py#L447-L463 | def _add_alpha(self, data, alpha=None):
"""Create an alpha channel and concatenate it to the provided data.
If ``data`` is an integer type then the alpha band will be scaled
to use the smallest (min) value as fully transparent and the largest
(max) value as fully opaque. For float types... | [
"def",
"_add_alpha",
"(",
"self",
",",
"data",
",",
"alpha",
"=",
"None",
")",
":",
"null_mask",
"=",
"alpha",
"if",
"alpha",
"is",
"not",
"None",
"else",
"self",
".",
"_create_alpha",
"(",
"data",
")",
"# if we are using integer data, then alpha needs to be min... | Create an alpha channel and concatenate it to the provided data.
If ``data`` is an integer type then the alpha band will be scaled
to use the smallest (min) value as fully transparent and the largest
(max) value as fully opaque. For float types the alpha band spans
0 to 1. | [
"Create",
"an",
"alpha",
"channel",
"and",
"concatenate",
"it",
"to",
"the",
"provided",
"data",
"."
] | python | train | 49.647059 |
wakatime/wakatime | wakatime/stats.py | https://github.com/wakatime/wakatime/blob/74519ace04e8472f3a3993269963732b9946a01d/wakatime/stats.py#L136-L162 | def guess_lexer_using_modeline(text):
"""Guess lexer for given text using Vim modeline.
Returns a tuple of (lexer, accuracy).
"""
lexer, accuracy = None, None
file_type = None
try:
file_type = get_filetype_from_buffer(text)
except: # pragma: nocover
log.traceback(logging.... | [
"def",
"guess_lexer_using_modeline",
"(",
"text",
")",
":",
"lexer",
",",
"accuracy",
"=",
"None",
",",
"None",
"file_type",
"=",
"None",
"try",
":",
"file_type",
"=",
"get_filetype_from_buffer",
"(",
"text",
")",
"except",
":",
"# pragma: nocover",
"log",
"."... | Guess lexer for given text using Vim modeline.
Returns a tuple of (lexer, accuracy). | [
"Guess",
"lexer",
"for",
"given",
"text",
"using",
"Vim",
"modeline",
"."
] | python | train | 24.296296 |
has2k1/plotnine | plotnine/geoms/geom_path.py | https://github.com/has2k1/plotnine/blob/566e579af705367e584fb27a74e6c5199624ca89/plotnine/geoms/geom_path.py#L276-L338 | def get_paths(self, x1, y1, x2, y2, panel_params, coord, ax):
"""
Compute paths that create the arrow heads
Parameters
----------
x1, y1, x2, y2 : array_like
List of points that define the tails of the arrows.
The arrow heads will be at x1, y1. If you nee... | [
"def",
"get_paths",
"(",
"self",
",",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
",",
"panel_params",
",",
"coord",
",",
"ax",
")",
":",
"Path",
"=",
"mpath",
".",
"Path",
"# Create reusable lists of vertices and codes",
"# arrowhead path has 3 vertices (Nones),",
"... | Compute paths that create the arrow heads
Parameters
----------
x1, y1, x2, y2 : array_like
List of points that define the tails of the arrows.
The arrow heads will be at x1, y1. If you need them
at x2, y2 reverse the input.
Returns
-------
... | [
"Compute",
"paths",
"that",
"create",
"the",
"arrow",
"heads"
] | python | train | 30.396825 |
tsroten/pynlpir | pynlpir/cli.py | https://github.com/tsroten/pynlpir/blob/8d5e994796a2b5d513f7db8d76d7d24a85d531b1/pynlpir/cli.py#L34-L68 | def update_license_file(data_dir):
"""Update NLPIR license file if it is out-of-date or missing.
:param str data_dir: The NLPIR data directory that houses the license.
:returns bool: Whether or not an update occurred.
"""
license_file = os.path.join(data_dir, LICENSE_FILENAME)
temp_dir = tempf... | [
"def",
"update_license_file",
"(",
"data_dir",
")",
":",
"license_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"data_dir",
",",
"LICENSE_FILENAME",
")",
"temp_dir",
"=",
"tempfile",
".",
"mkdtemp",
"(",
")",
"gh_license_filename",
"=",
"os",
".",
"path",... | Update NLPIR license file if it is out-of-date or missing.
:param str data_dir: The NLPIR data directory that houses the license.
:returns bool: Whether or not an update occurred. | [
"Update",
"NLPIR",
"license",
"file",
"if",
"it",
"is",
"out",
"-",
"of",
"-",
"date",
"or",
"missing",
"."
] | python | train | 33.085714 |
hMatoba/Piexif | piexif/_common.py | https://github.com/hMatoba/Piexif/blob/afd0d232cf05cf530423f4b2a82ab291f150601a/piexif/_common.py#L6-L27 | def split_into_segments(data):
"""Slices JPEG meta data into a list from JPEG binary data.
"""
if data[0:2] != b"\xff\xd8":
raise InvalidImageDataError("Given data isn't JPEG.")
head = 2
segments = [b"\xff\xd8"]
while 1:
if data[head: head + 2] == b"\xff\xda":
segmen... | [
"def",
"split_into_segments",
"(",
"data",
")",
":",
"if",
"data",
"[",
"0",
":",
"2",
"]",
"!=",
"b\"\\xff\\xd8\"",
":",
"raise",
"InvalidImageDataError",
"(",
"\"Given data isn't JPEG.\"",
")",
"head",
"=",
"2",
"segments",
"=",
"[",
"b\"\\xff\\xd8\"",
"]",
... | Slices JPEG meta data into a list from JPEG binary data. | [
"Slices",
"JPEG",
"meta",
"data",
"into",
"a",
"list",
"from",
"JPEG",
"binary",
"data",
"."
] | python | train | 30.772727 |
openstax/cnx-publishing | cnxpublishing/views/user_actions.py | https://github.com/openstax/cnx-publishing/blob/f55b4a2c45d8618737288f1b74b4139d5ac74154/cnxpublishing/views/user_actions.py#L235-L257 | def get_acl(request):
"""Returns the ACL for the given content identified by ``uuid``."""
uuid_ = request.matchdict['uuid']
with db_connect() as db_conn:
with db_conn.cursor() as cursor:
cursor.execute("""\
SELECT TRUE FROM document_controls WHERE uuid = %s""", (uuid_,))
try... | [
"def",
"get_acl",
"(",
"request",
")",
":",
"uuid_",
"=",
"request",
".",
"matchdict",
"[",
"'uuid'",
"]",
"with",
"db_connect",
"(",
")",
"as",
"db_conn",
":",
"with",
"db_conn",
".",
"cursor",
"(",
")",
"as",
"cursor",
":",
"cursor",
".",
"execute",
... | Returns the ACL for the given content identified by ``uuid``. | [
"Returns",
"the",
"ACL",
"for",
"the",
"given",
"content",
"identified",
"by",
"uuid",
"."
] | python | valid | 32.565217 |
Parallels/artifactory | artifactory.py | https://github.com/Parallels/artifactory/blob/09ddcc4ae15095eec2347d39774c3f8aca6c4654/artifactory.py#L420-L426 | def rest_put(self, url, params=None, headers=None, auth=None, verify=True, cert=None):
"""
Perform a PUT request to url with optional authentication
"""
res = requests.put(url, params=params, headers=headers, auth=auth, verify=verify,
cert=cert)
return ... | [
"def",
"rest_put",
"(",
"self",
",",
"url",
",",
"params",
"=",
"None",
",",
"headers",
"=",
"None",
",",
"auth",
"=",
"None",
",",
"verify",
"=",
"True",
",",
"cert",
"=",
"None",
")",
":",
"res",
"=",
"requests",
".",
"put",
"(",
"url",
",",
... | Perform a PUT request to url with optional authentication | [
"Perform",
"a",
"PUT",
"request",
"to",
"url",
"with",
"optional",
"authentication"
] | python | train | 48.428571 |
csparpa/pyowm | pyowm/weatherapi25/owm25.py | https://github.com/csparpa/pyowm/blob/cdd59eb72f32f7238624ceef9b2e2329a5ebd472/pyowm/weatherapi25/owm25.py#L338-L378 | def weather_at_places(self, pattern, searchtype, limit=None):
"""
Queries the OWM Weather API for the currently observed weather in all the
locations whose name is matching the specified text search parameters.
A twofold search can be issued: *'accurate'* (exact matching) and
*'l... | [
"def",
"weather_at_places",
"(",
"self",
",",
"pattern",
",",
"searchtype",
",",
"limit",
"=",
"None",
")",
":",
"assert",
"isinstance",
"(",
"pattern",
",",
"str",
")",
",",
"\"'pattern' must be a str\"",
"assert",
"isinstance",
"(",
"searchtype",
",",
"str",... | Queries the OWM Weather API for the currently observed weather in all the
locations whose name is matching the specified text search parameters.
A twofold search can be issued: *'accurate'* (exact matching) and
*'like'* (matches names that are similar to the supplied pattern).
:param pa... | [
"Queries",
"the",
"OWM",
"Weather",
"API",
"for",
"the",
"currently",
"observed",
"weather",
"in",
"all",
"the",
"locations",
"whose",
"name",
"is",
"matching",
"the",
"specified",
"text",
"search",
"parameters",
".",
"A",
"twofold",
"search",
"can",
"be",
"... | python | train | 56.780488 |
frmdstryr/enamlx | enamlx/core/block.py | https://github.com/frmdstryr/enamlx/blob/9582e29c88dc0c0340f912b49168b7307a47ed4f/enamlx/core/block.py#L35-L48 | def _observe_block(self, change):
""" A change handler for the 'objects' list of the Include.
If the object is initialized objects which are removed will be
unparented and objects which are added will be reparented. Old
objects will be destroyed if the 'destroy_old' flag is True.
... | [
"def",
"_observe_block",
"(",
"self",
",",
"change",
")",
":",
"if",
"self",
".",
"is_initialized",
":",
"if",
"change",
"[",
"'type'",
"]",
"==",
"'update'",
":",
"old_block",
"=",
"change",
"[",
"'oldvalue'",
"]",
"old_block",
".",
"parent",
".",
"remo... | A change handler for the 'objects' list of the Include.
If the object is initialized objects which are removed will be
unparented and objects which are added will be reparented. Old
objects will be destroyed if the 'destroy_old' flag is True. | [
"A",
"change",
"handler",
"for",
"the",
"objects",
"list",
"of",
"the",
"Include",
"."
] | python | train | 44.857143 |
twilio/twilio-python | twilio/rest/api/v2010/account/conference/__init__.py | https://github.com/twilio/twilio-python/blob/c867895f55dcc29f522e6e8b8868d0d18483132f/twilio/rest/api/v2010/account/conference/__init__.py#L307-L332 | def update(self, status=values.unset, announce_url=values.unset,
announce_method=values.unset):
"""
Update the ConferenceInstance
:param ConferenceInstance.UpdateStatus status: The new status of the resource
:param unicode announce_url: The URL we should call to announce ... | [
"def",
"update",
"(",
"self",
",",
"status",
"=",
"values",
".",
"unset",
",",
"announce_url",
"=",
"values",
".",
"unset",
",",
"announce_method",
"=",
"values",
".",
"unset",
")",
":",
"data",
"=",
"values",
".",
"of",
"(",
"{",
"'Status'",
":",
"s... | Update the ConferenceInstance
:param ConferenceInstance.UpdateStatus status: The new status of the resource
:param unicode announce_url: The URL we should call to announce something into the conference
:param unicode announce_method: he HTTP method used to call announce_url
:returns: U... | [
"Update",
"the",
"ConferenceInstance"
] | python | train | 36.730769 |
UDST/orca | orca/orca.py | https://github.com/UDST/orca/blob/07b34aeef13cc87c966b2e30cbe7e76cc9d3622c/orca/orca.py#L1263-L1304 | def _memoize_function(f, name, cache_scope=_CS_FOREVER):
"""
Wraps a function for memoization and ties it's cache into the
Orca cacheing system.
Parameters
----------
f : function
name : str
Name of injectable.
cache_scope : {'step', 'iteration', 'forever'}, optional
Sco... | [
"def",
"_memoize_function",
"(",
"f",
",",
"name",
",",
"cache_scope",
"=",
"_CS_FOREVER",
")",
":",
"cache",
"=",
"{",
"}",
"@",
"wraps",
"(",
"f",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"cache_key"... | Wraps a function for memoization and ties it's cache into the
Orca cacheing system.
Parameters
----------
f : function
name : str
Name of injectable.
cache_scope : {'step', 'iteration', 'forever'}, optional
Scope for which to cache data. Default is to cache forever
(or u... | [
"Wraps",
"a",
"function",
"for",
"memoization",
"and",
"ties",
"it",
"s",
"cache",
"into",
"the",
"Orca",
"cacheing",
"system",
"."
] | python | train | 29.52381 |
sirfoga/pyhal | hal/wrappers/errors.py | https://github.com/sirfoga/pyhal/blob/4394d8a1f7e45bea28a255ec390f4962ee64d33a/hal/wrappers/errors.py#L8-L32 | def true_false_returns(func):
"""Executes function, if error returns False, else True
:param func: function to call
:return: True iff ok, else False
"""
@functools.wraps(func)
def _execute(*args, **kwargs):
"""Executes function, if error returns False, else True
:param args: a... | [
"def",
"true_false_returns",
"(",
"func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"_execute",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"\"\"\"Executes function, if error returns False, else True\n\n :param args: args of fu... | Executes function, if error returns False, else True
:param func: function to call
:return: True iff ok, else False | [
"Executes",
"function",
"if",
"error",
"returns",
"False",
"else",
"True"
] | python | train | 24.28 |
chaoss/grimoirelab-manuscripts | manuscripts2/elasticsearch.py | https://github.com/chaoss/grimoirelab-manuscripts/blob/94a3ad4f11bfbcd6c5190e01cb5d3e47a5187cd9/manuscripts2/elasticsearch.py#L247-L259 | def add_custom_aggregation(self, agg, name=None):
"""
Takes in an es_dsl Aggregation object and adds it to the aggregation dict.
Can be used to add custom aggregations such as moving averages
:param agg: aggregation to be added to the es_dsl search object
:param name: name of th... | [
"def",
"add_custom_aggregation",
"(",
"self",
",",
"agg",
",",
"name",
"=",
"None",
")",
":",
"agg_name",
"=",
"name",
"if",
"name",
"else",
"'custom_agg'",
"self",
".",
"aggregations",
"[",
"agg_name",
"]",
"=",
"agg",
"return",
"self"
] | Takes in an es_dsl Aggregation object and adds it to the aggregation dict.
Can be used to add custom aggregations such as moving averages
:param agg: aggregation to be added to the es_dsl search object
:param name: name of the aggregation object (optional)
:returns: self, which allows t... | [
"Takes",
"in",
"an",
"es_dsl",
"Aggregation",
"object",
"and",
"adds",
"it",
"to",
"the",
"aggregation",
"dict",
".",
"Can",
"be",
"used",
"to",
"add",
"custom",
"aggregations",
"such",
"as",
"moving",
"averages"
] | python | train | 42.384615 |
array-split/array_split | array_split/split.py | https://github.com/array-split/array_split/blob/e07abe3001209394dde809f7e6f505f9f49a1c26/array_split/split.py#L795-L807 | def convert_halo_to_array_form(self, halo):
"""
Converts the :samp:`{halo}` argument to a :samp:`({self}.array_shape.size, 2)`
shaped array.
:type halo: :samp:`None`, :obj:`int`, :samp:`self.array_shape.size` length sequence
of :samp:`int` or :samp:`(self.array_shape.size, 2... | [
"def",
"convert_halo_to_array_form",
"(",
"self",
",",
"halo",
")",
":",
"return",
"convert_halo_to_array_form",
"(",
"halo",
"=",
"halo",
",",
"ndim",
"=",
"len",
"(",
"self",
".",
"array_shape",
")",
")"
] | Converts the :samp:`{halo}` argument to a :samp:`({self}.array_shape.size, 2)`
shaped array.
:type halo: :samp:`None`, :obj:`int`, :samp:`self.array_shape.size` length sequence
of :samp:`int` or :samp:`(self.array_shape.size, 2)` shaped array
of :samp:`int`
:param halo: ... | [
"Converts",
"the",
":",
"samp",
":",
"{",
"halo",
"}",
"argument",
"to",
"a",
":",
"samp",
":",
"(",
"{",
"self",
"}",
".",
"array_shape",
".",
"size",
"2",
")",
"shaped",
"array",
"."
] | python | train | 52.153846 |
poldracklab/niworkflows | niworkflows/utils/bids.py | https://github.com/poldracklab/niworkflows/blob/254f4b4fcc5e6ecb29d2f4602a30786b913ecce5/niworkflows/utils/bids.py#L44-L118 | def collect_participants(bids_dir, participant_label=None, strict=False,
bids_validate=True):
"""
List the participants under the BIDS root and checks that participants
designated with the participant_label argument exist in that folder.
Returns the list of participants to be fi... | [
"def",
"collect_participants",
"(",
"bids_dir",
",",
"participant_label",
"=",
"None",
",",
"strict",
"=",
"False",
",",
"bids_validate",
"=",
"True",
")",
":",
"if",
"isinstance",
"(",
"bids_dir",
",",
"BIDSLayout",
")",
":",
"layout",
"=",
"bids_dir",
"els... | List the participants under the BIDS root and checks that participants
designated with the participant_label argument exist in that folder.
Returns the list of participants to be finally processed.
Requesting all subjects in a BIDS directory root:
>>> collect_participants(str(datadir / 'ds114'), bids_va... | [
"List",
"the",
"participants",
"under",
"the",
"BIDS",
"root",
"and",
"checks",
"that",
"participants",
"designated",
"with",
"the",
"participant_label",
"argument",
"exist",
"in",
"that",
"folder",
".",
"Returns",
"the",
"list",
"of",
"participants",
"to",
"be"... | python | train | 41.053333 |
andreikop/qutepart | qutepart/brackethlighter.py | https://github.com/andreikop/qutepart/blob/109d76b239751318bcef06f39b2fbbf18687a40b/qutepart/brackethlighter.py#L75-L96 | def _findMatchingBracket(self, bracket, qpart, block, columnIndex):
"""Find matching bracket for the bracket.
Return (block, columnIndex) or (None, None)
Raise _TimeoutException, if time is over
"""
if bracket in self._START_BRACKETS:
charsGenerator = self._iterateDoc... | [
"def",
"_findMatchingBracket",
"(",
"self",
",",
"bracket",
",",
"qpart",
",",
"block",
",",
"columnIndex",
")",
":",
"if",
"bracket",
"in",
"self",
".",
"_START_BRACKETS",
":",
"charsGenerator",
"=",
"self",
".",
"_iterateDocumentCharsForward",
"(",
"block",
... | Find matching bracket for the bracket.
Return (block, columnIndex) or (None, None)
Raise _TimeoutException, if time is over | [
"Find",
"matching",
"bracket",
"for",
"the",
"bracket",
".",
"Return",
"(",
"block",
"columnIndex",
")",
"or",
"(",
"None",
"None",
")",
"Raise",
"_TimeoutException",
"if",
"time",
"is",
"over"
] | python | train | 39.818182 |
PyGithub/PyGithub | github/PullRequest.py | https://github.com/PyGithub/PyGithub/blob/f716df86bbe7dc276c6596699fa9712b61ef974c/github/PullRequest.py#L754-L778 | def merge(self, commit_message=github.GithubObject.NotSet, commit_title=github.GithubObject.NotSet, merge_method=github.GithubObject.NotSet, sha=github.GithubObject.NotSet):
"""
:calls: `PUT /repos/:owner/:repo/pulls/:number/merge <http://developer.github.com/v3/pulls>`_
:param commit_message: s... | [
"def",
"merge",
"(",
"self",
",",
"commit_message",
"=",
"github",
".",
"GithubObject",
".",
"NotSet",
",",
"commit_title",
"=",
"github",
".",
"GithubObject",
".",
"NotSet",
",",
"merge_method",
"=",
"github",
".",
"GithubObject",
".",
"NotSet",
",",
"sha",... | :calls: `PUT /repos/:owner/:repo/pulls/:number/merge <http://developer.github.com/v3/pulls>`_
:param commit_message: string
:rtype: :class:`github.PullRequestMergeStatus.PullRequestMergeStatus` | [
":",
"calls",
":",
"PUT",
"/",
"repos",
"/",
":",
"owner",
"/",
":",
"repo",
"/",
"pulls",
"/",
":",
"number",
"/",
"merge",
"<http",
":",
"//",
"developer",
".",
"github",
".",
"com",
"/",
"v3",
"/",
"pulls",
">",
"_",
":",
"param",
"commit_mess... | python | train | 63.64 |
iotile/coretools | iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Tool/tex.py | https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Tool/tex.py#L495-L560 | def is_LaTeX(flist,env,abspath):
"""Scan a file list to decide if it's TeX- or LaTeX-flavored."""
# We need to scan files that are included in case the
# \documentclass command is in them.
# get path list from both env['TEXINPUTS'] and env['ENV']['TEXINPUTS']
savedpath = modify_env_var(env, 'TEXIN... | [
"def",
"is_LaTeX",
"(",
"flist",
",",
"env",
",",
"abspath",
")",
":",
"# We need to scan files that are included in case the",
"# \\documentclass command is in them.",
"# get path list from both env['TEXINPUTS'] and env['ENV']['TEXINPUTS']",
"savedpath",
"=",
"modify_env_var",
"(",
... | Scan a file list to decide if it's TeX- or LaTeX-flavored. | [
"Scan",
"a",
"file",
"list",
"to",
"decide",
"if",
"it",
"s",
"TeX",
"-",
"or",
"LaTeX",
"-",
"flavored",
"."
] | python | train | 32.69697 |
KimiNewt/pyshark | src/pyshark/capture/inmem_capture.py | https://github.com/KimiNewt/pyshark/blob/089ea6208c4321f03bc548f491e00a053285918f/src/pyshark/capture/inmem_capture.py#L96-L118 | def parse_packets(self, binary_packets):
"""
Parses binary packets and return a list of parsed packets.
DOES NOT CLOSE tshark. It must be closed manually by calling close() when you're done
working with it.
"""
if not binary_packets:
raise ValueError("Must su... | [
"def",
"parse_packets",
"(",
"self",
",",
"binary_packets",
")",
":",
"if",
"not",
"binary_packets",
":",
"raise",
"ValueError",
"(",
"\"Must supply at least one packet\"",
")",
"parsed_packets",
"=",
"[",
"]",
"if",
"not",
"self",
".",
"_current_tshark",
":",
"... | Parses binary packets and return a list of parsed packets.
DOES NOT CLOSE tshark. It must be closed manually by calling close() when you're done
working with it. | [
"Parses",
"binary",
"packets",
"and",
"return",
"a",
"list",
"of",
"parsed",
"packets",
"."
] | python | train | 36.391304 |
angr/angr | angr/state_plugins/heap/heap_base.py | https://github.com/angr/angr/blob/4e2f97d56af5419ee73bdb30482c8dd8ff5f3e40/angr/state_plugins/heap/heap_base.py#L68-L76 | def _malloc(self, sim_size):
"""
Handler for any libc `malloc` SimProcedure call. If the heap has faithful support for `malloc`, it ought to be
implemented in a `malloc` function (as opposed to the `_malloc` function).
:param sim_size: the amount of memory (in bytes) to be allocated
... | [
"def",
"_malloc",
"(",
"self",
",",
"sim_size",
")",
":",
"raise",
"NotImplementedError",
"(",
"\"%s not implemented for %s\"",
"%",
"(",
"self",
".",
"_malloc",
".",
"__func__",
".",
"__name__",
",",
"self",
".",
"__class__",
".",
"__name__",
")",
")"
] | Handler for any libc `malloc` SimProcedure call. If the heap has faithful support for `malloc`, it ought to be
implemented in a `malloc` function (as opposed to the `_malloc` function).
:param sim_size: the amount of memory (in bytes) to be allocated | [
"Handler",
"for",
"any",
"libc",
"malloc",
"SimProcedure",
"call",
".",
"If",
"the",
"heap",
"has",
"faithful",
"support",
"for",
"malloc",
"it",
"ought",
"to",
"be",
"implemented",
"in",
"a",
"malloc",
"function",
"(",
"as",
"opposed",
"to",
"the",
"_mall... | python | train | 56.444444 |
tensorflow/tensorboard | tensorboard/plugins/hparams/backend_context.py | https://github.com/tensorflow/tensorboard/blob/8e5f497b48e40f2a774f85416b8a35ac0693c35e/tensorboard/plugins/hparams/backend_context.py#L280-L295 | def _protobuf_value_type(value):
"""Returns the type of the google.protobuf.Value message as an api.DataType.
Returns None if the type of 'value' is not one of the types supported in
api_pb2.DataType.
Args:
value: google.protobuf.Value message.
"""
if value.HasField("number_value"):
return api_pb2... | [
"def",
"_protobuf_value_type",
"(",
"value",
")",
":",
"if",
"value",
".",
"HasField",
"(",
"\"number_value\"",
")",
":",
"return",
"api_pb2",
".",
"DATA_TYPE_FLOAT64",
"if",
"value",
".",
"HasField",
"(",
"\"string_value\"",
")",
":",
"return",
"api_pb2",
"."... | Returns the type of the google.protobuf.Value message as an api.DataType.
Returns None if the type of 'value' is not one of the types supported in
api_pb2.DataType.
Args:
value: google.protobuf.Value message. | [
"Returns",
"the",
"type",
"of",
"the",
"google",
".",
"protobuf",
".",
"Value",
"message",
"as",
"an",
"api",
".",
"DataType",
"."
] | python | train | 29.9375 |
vaexio/vaex | packages/vaex-astro/vaex/astro/transformations.py | https://github.com/vaexio/vaex/blob/a45b672f8287afca2ada8e36b74b604b9b28dd85/packages/vaex-astro/vaex/astro/transformations.py#L5-L9 | def patch(f):
'''Adds method f to the Dataset class'''
name = f.__name__
Dataset.__hidden__[name] = f
return f | [
"def",
"patch",
"(",
"f",
")",
":",
"name",
"=",
"f",
".",
"__name__",
"Dataset",
".",
"__hidden__",
"[",
"name",
"]",
"=",
"f",
"return",
"f"
] | Adds method f to the Dataset class | [
"Adds",
"method",
"f",
"to",
"the",
"Dataset",
"class"
] | python | test | 24.4 |
awslabs/sockeye | sockeye/inference.py | https://github.com/awslabs/sockeye/blob/5d64a1ee1ef3cbba17c6d1d94bc061020c43f6ab/sockeye/inference.py#L388-L508 | def load_models(context: mx.context.Context,
max_input_len: Optional[int],
beam_size: int,
batch_size: int,
model_folders: List[str],
checkpoints: Optional[List[int]] = None,
softmax_temperature: Optional[float] = None,
... | [
"def",
"load_models",
"(",
"context",
":",
"mx",
".",
"context",
".",
"Context",
",",
"max_input_len",
":",
"Optional",
"[",
"int",
"]",
",",
"beam_size",
":",
"int",
",",
"batch_size",
":",
"int",
",",
"model_folders",
":",
"List",
"[",
"str",
"]",
",... | Loads a list of models for inference.
:param context: MXNet context to bind modules to.
:param max_input_len: Maximum input length.
:param beam_size: Beam size.
:param batch_size: Batch size.
:param model_folders: List of model folders to load models from.
:param checkpoints: List of checkpoint... | [
"Loads",
"a",
"list",
"of",
"models",
"for",
"inference",
"."
] | python | train | 59.22314 |
AshleySetter/optoanalysis | optoanalysis/optoanalysis/optoanalysis.py | https://github.com/AshleySetter/optoanalysis/blob/9d390acc834d70024d47b574aea14189a5a5714e/optoanalysis/optoanalysis/optoanalysis.py#L770-L827 | def calc_gamma_from_energy_autocorrelation_fit(self, GammaGuess=None, silent=False, MakeFig=True, show_fig=True):
"""
Calculates the total damping, i.e. Gamma, by calculating the energy each
point in time. This energy array is then used for the autocorrleation.
The autocorrelation is f... | [
"def",
"calc_gamma_from_energy_autocorrelation_fit",
"(",
"self",
",",
"GammaGuess",
"=",
"None",
",",
"silent",
"=",
"False",
",",
"MakeFig",
"=",
"True",
",",
"show_fig",
"=",
"True",
")",
":",
"autocorrelation",
"=",
"calc_autocorrelation",
"(",
"self",
".",
... | Calculates the total damping, i.e. Gamma, by calculating the energy each
point in time. This energy array is then used for the autocorrleation.
The autocorrelation is fitted with an exponential relaxation function and
the function returns the parameters with errors.
Parameters
... | [
"Calculates",
"the",
"total",
"damping",
"i",
".",
"e",
".",
"Gamma",
"by",
"calculating",
"the",
"energy",
"each",
"point",
"in",
"time",
".",
"This",
"energy",
"array",
"is",
"then",
"used",
"for",
"the",
"autocorrleation",
".",
"The",
"autocorrelation",
... | python | train | 40.448276 |
saltstack/salt | salt/modules/git.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/git.py#L48-L60 | def _check_worktree_support(failhard=True):
'''
Ensure that we don't try to operate on worktrees in git < 2.5.0.
'''
git_version = version(versioninfo=False)
if _LooseVersion(git_version) < _LooseVersion('2.5.0'):
if failhard:
raise CommandExecutionError(
'Worktre... | [
"def",
"_check_worktree_support",
"(",
"failhard",
"=",
"True",
")",
":",
"git_version",
"=",
"version",
"(",
"versioninfo",
"=",
"False",
")",
"if",
"_LooseVersion",
"(",
"git_version",
")",
"<",
"_LooseVersion",
"(",
"'2.5.0'",
")",
":",
"if",
"failhard",
... | Ensure that we don't try to operate on worktrees in git < 2.5.0. | [
"Ensure",
"that",
"we",
"don",
"t",
"try",
"to",
"operate",
"on",
"worktrees",
"in",
"git",
"<",
"2",
".",
"5",
".",
"0",
"."
] | python | train | 35.923077 |
ray-project/ray | python/ray/tune/suggest/sigopt.py | https://github.com/ray-project/ray/blob/4eade036a0505e244c976f36aaa2d64386b5129b/python/ray/tune/suggest/sigopt.py#L95-L119 | def on_trial_complete(self,
trial_id,
result=None,
error=False,
early_terminated=False):
"""Passes the result to SigOpt unless early terminated or errored.
If a trial fails, it will be reported as a ... | [
"def",
"on_trial_complete",
"(",
"self",
",",
"trial_id",
",",
"result",
"=",
"None",
",",
"error",
"=",
"False",
",",
"early_terminated",
"=",
"False",
")",
":",
"if",
"result",
":",
"self",
".",
"conn",
".",
"experiments",
"(",
"self",
".",
"experiment... | Passes the result to SigOpt unless early terminated or errored.
If a trial fails, it will be reported as a failed Observation, telling
the optimizer that the Suggestion led to a metric failure, which
updates the feasible region and improves parameter recommendation.
Creates SigOpt Obse... | [
"Passes",
"the",
"result",
"to",
"SigOpt",
"unless",
"early",
"terminated",
"or",
"errored",
"."
] | python | train | 46.84 |
secdev/scapy | scapy/layers/sixlowpan.py | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/sixlowpan.py#L751-L778 | def sixlowpan_fragment(packet, datagram_tag=1):
"""Split a packet into different links to transmit as 6lowpan packets.
Usage example:
>>> ipv6 = ..... (very big packet)
>>> pkts = sixlowpan_fragment(ipv6, datagram_tag=0x17)
>>> send = [Dot15d4()/Dot15d4Data()/x for x in pkts]
... | [
"def",
"sixlowpan_fragment",
"(",
"packet",
",",
"datagram_tag",
"=",
"1",
")",
":",
"if",
"not",
"packet",
".",
"haslayer",
"(",
"IPv6",
")",
":",
"raise",
"Exception",
"(",
"\"SixLoWPAN only fragments IPv6 packets !\"",
")",
"str_packet",
"=",
"raw",
"(",
"p... | Split a packet into different links to transmit as 6lowpan packets.
Usage example:
>>> ipv6 = ..... (very big packet)
>>> pkts = sixlowpan_fragment(ipv6, datagram_tag=0x17)
>>> send = [Dot15d4()/Dot15d4Data()/x for x in pkts]
>>> wireshark(send) | [
"Split",
"a",
"packet",
"into",
"different",
"links",
"to",
"transmit",
"as",
"6lowpan",
"packets",
".",
"Usage",
"example",
":",
">>>",
"ipv6",
"=",
".....",
"(",
"very",
"big",
"packet",
")",
">>>",
"pkts",
"=",
"sixlowpan_fragment",
"(",
"ipv6",
"datagr... | python | train | 37.107143 |
chimera0/accel-brain-code | Automatic-Summarization/pysummarization/similarity_filter.py | https://github.com/chimera0/accel-brain-code/blob/03661f6f544bed656269fcd4b3c23c9061629daa/Automatic-Summarization/pysummarization/similarity_filter.py#L39-L43 | def set_similarity_limit(self, value):
''' setter '''
if isinstance(value, float) is False:
raise TypeError("__similarity_limit must be float.")
self.__similarity_limit = value | [
"def",
"set_similarity_limit",
"(",
"self",
",",
"value",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"float",
")",
"is",
"False",
":",
"raise",
"TypeError",
"(",
"\"__similarity_limit must be float.\"",
")",
"self",
".",
"__similarity_limit",
"=",
"value"
... | setter | [
"setter"
] | python | train | 41.6 |
eng-tools/sfsimodels | sfsimodels/models/soils.py | https://github.com/eng-tools/sfsimodels/blob/65a690ca440d61307f5a9b8478e4704f203a5925/sfsimodels/models/soils.py#L121-L127 | def reset_all(self):
"""
Resets all parameters to None
"""
for item in self.inputs:
setattr(self, "_%s" % item, None)
self.stack = [] | [
"def",
"reset_all",
"(",
"self",
")",
":",
"for",
"item",
"in",
"self",
".",
"inputs",
":",
"setattr",
"(",
"self",
",",
"\"_%s\"",
"%",
"item",
",",
"None",
")",
"self",
".",
"stack",
"=",
"[",
"]"
] | Resets all parameters to None | [
"Resets",
"all",
"parameters",
"to",
"None"
] | python | train | 25.571429 |
dereneaton/ipyrad | ipyrad/assemble/util.py | https://github.com/dereneaton/ipyrad/blob/5eeb8a178160f45faf71bf47cec4abe998a575d1/ipyrad/assemble/util.py#L521-L719 | def merge_pairs(data, two_files, merged_out, revcomp, merge):
"""
Merge PE reads. Takes in a list of unmerged files [r1, r2] and the
filehandle to write merged data to, and it returns the number of reads
that were merged (overlapping). If merge==0 then only concat pairs (nnnn),
no merging in vsearch... | [
"def",
"merge_pairs",
"(",
"data",
",",
"two_files",
",",
"merged_out",
",",
"revcomp",
",",
"merge",
")",
":",
"LOGGER",
".",
"debug",
"(",
"\"Entering merge_pairs()\"",
")",
"## Return the number of merged pairs",
"nmerged",
"=",
"-",
"1",
"## Check input files fr... | Merge PE reads. Takes in a list of unmerged files [r1, r2] and the
filehandle to write merged data to, and it returns the number of reads
that were merged (overlapping). If merge==0 then only concat pairs (nnnn),
no merging in vsearch.
Parameters
-----------
two_files (tuple):
A list or... | [
"Merge",
"PE",
"reads",
".",
"Takes",
"in",
"a",
"list",
"of",
"unmerged",
"files",
"[",
"r1",
"r2",
"]",
"and",
"the",
"filehandle",
"to",
"write",
"merged",
"data",
"to",
"and",
"it",
"returns",
"the",
"number",
"of",
"reads",
"that",
"were",
"merged... | python | valid | 36.849246 |
MartinThoma/mpu | mpu/ml.py | https://github.com/MartinThoma/mpu/blob/61bc36d0192ca90c0bcf9b8a5d7d0d8520e20ff6/mpu/ml.py#L47-L70 | def one_hot2indices(one_hots):
"""
Convert an iterable of one-hot encoded targets to a list of indices.
Parameters
----------
one_hot : list
Returns
-------
indices : list
Examples
--------
>>> one_hot2indices([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
[0, 1, 2]
>>> one_h... | [
"def",
"one_hot2indices",
"(",
"one_hots",
")",
":",
"indices",
"=",
"[",
"]",
"for",
"one_hot",
"in",
"one_hots",
":",
"indices",
".",
"append",
"(",
"argmax",
"(",
"one_hot",
")",
")",
"return",
"indices"
] | Convert an iterable of one-hot encoded targets to a list of indices.
Parameters
----------
one_hot : list
Returns
-------
indices : list
Examples
--------
>>> one_hot2indices([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
[0, 1, 2]
>>> one_hot2indices([[1, 0], [1, 0], [0, 1]])
[0... | [
"Convert",
"an",
"iterable",
"of",
"one",
"-",
"hot",
"encoded",
"targets",
"to",
"a",
"list",
"of",
"indices",
"."
] | python | train | 19.166667 |
hubo1016/vlcp | vlcp/utils/http.py | https://github.com/hubo1016/vlcp/blob/239055229ec93a99cc7e15208075724ccf543bd1/vlcp/utils/http.py#L353-L364 | async def close(self):
"""
Close this request, send all data. You can still run other operations in the handler.
"""
if not self._sendHeaders:
self._startResponse()
if self.inputstream is not None:
self.inputstream.close(self.connection.scheduler)
... | [
"async",
"def",
"close",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_sendHeaders",
":",
"self",
".",
"_startResponse",
"(",
")",
"if",
"self",
".",
"inputstream",
"is",
"not",
"None",
":",
"self",
".",
"inputstream",
".",
"close",
"(",
"self",
... | Close this request, send all data. You can still run other operations in the handler. | [
"Close",
"this",
"request",
"send",
"all",
"data",
".",
"You",
"can",
"still",
"run",
"other",
"operations",
"in",
"the",
"handler",
"."
] | python | train | 38.75 |
saltstack/salt | salt/modules/napalm_yang_mod.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/napalm_yang_mod.py#L420-L567 | def load_config(data, *models, **kwargs):
'''
Generate and load the config on the device using the OpenConfig or IETF
models and device profiles.
data
Dictionary structured with respect to the models referenced.
models
A list of models to be used when generating the config.
pr... | [
"def",
"load_config",
"(",
"data",
",",
"*",
"models",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"isinstance",
"(",
"models",
",",
"tuple",
")",
"and",
"isinstance",
"(",
"models",
"[",
"0",
"]",
",",
"list",
")",
":",
"models",
"=",
"models",
"[",
... | Generate and load the config on the device using the OpenConfig or IETF
models and device profiles.
data
Dictionary structured with respect to the models referenced.
models
A list of models to be used when generating the config.
profiles: ``None``
Use certain profiles to gener... | [
"Generate",
"and",
"load",
"the",
"config",
"on",
"the",
"device",
"using",
"the",
"OpenConfig",
"or",
"IETF",
"models",
"and",
"device",
"profiles",
"."
] | python | train | 35.006757 |
raiden-network/raiden | raiden/transfer/mediated_transfer/target.py | https://github.com/raiden-network/raiden/blob/407ba15c72074e9de88771d6b9661ff4dc36bef5/raiden/transfer/mediated_transfer/target.py#L215-L238 | def handle_onchain_secretreveal(
target_state: TargetTransferState,
state_change: ContractReceiveSecretReveal,
channel_state: NettingChannelState,
) -> TransitionResult[TargetTransferState]:
""" Validates and handles a ContractReceiveSecretReveal state change. """
valid_secret = is_valid... | [
"def",
"handle_onchain_secretreveal",
"(",
"target_state",
":",
"TargetTransferState",
",",
"state_change",
":",
"ContractReceiveSecretReveal",
",",
"channel_state",
":",
"NettingChannelState",
",",
")",
"->",
"TransitionResult",
"[",
"TargetTransferState",
"]",
":",
"val... | Validates and handles a ContractReceiveSecretReveal state change. | [
"Validates",
"and",
"handles",
"a",
"ContractReceiveSecretReveal",
"state",
"change",
"."
] | python | train | 37.083333 |
michaelaye/pyciss | pyciss/downloader.py | https://github.com/michaelaye/pyciss/blob/019256424466060babead7edab86736c881b0831/pyciss/downloader.py#L54-L83 | def download_and_calibrate(img_id=None, overwrite=False, recalibrate=False, **kwargs):
"""Download and calibrate one or more image ids, in parallel.
Parameters
----------
img_id : str or io.PathManager, optional
If more than one item is in img_id, a parallel process is started
overwrite: bo... | [
"def",
"download_and_calibrate",
"(",
"img_id",
"=",
"None",
",",
"overwrite",
"=",
"False",
",",
"recalibrate",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"isinstance",
"(",
"img_id",
",",
"io",
".",
"PathManager",
")",
":",
"pm",
"=",
"im... | Download and calibrate one or more image ids, in parallel.
Parameters
----------
img_id : str or io.PathManager, optional
If more than one item is in img_id, a parallel process is started
overwrite: bool, optional
If the pm.cubepath exists, this switch controls if it is being overwritte... | [
"Download",
"and",
"calibrate",
"one",
"or",
"more",
"image",
"ids",
"in",
"parallel",
"."
] | python | train | 39.5 |
saxix/sample-data-utils | sample_data_utils/people.py | https://github.com/saxix/sample-data-utils/blob/769f1b46e60def2675a14bd5872047af6d1ea398/sample_data_utils/people.py#L118-L135 | def last_name(languages=None):
"""
return a random last name
>>> from mock import patch
>>> with patch('%s._get_lastnames' % __name__, lambda *args: ['aaa']):
... last_name()
'Aaa'
>>> with patch('%s.get_lastnames' % __name__, lambda lang: ['%s_lastname'% lang]):
... last_na... | [
"def",
"last_name",
"(",
"languages",
"=",
"None",
")",
":",
"choices",
"=",
"[",
"]",
"languages",
"=",
"languages",
"or",
"[",
"'en'",
"]",
"for",
"lang",
"in",
"languages",
":",
"samples",
"=",
"_get_lastnames",
"(",
"lang",
")",
"choices",
".",
"ex... | return a random last name
>>> from mock import patch
>>> with patch('%s._get_lastnames' % __name__, lambda *args: ['aaa']):
... last_name()
'Aaa'
>>> with patch('%s.get_lastnames' % __name__, lambda lang: ['%s_lastname'% lang]):
... last_name(['it'])
'It_Lastname' | [
"return",
"a",
"random",
"last",
"name"
] | python | test | 29.555556 |
iterative/dvc | dvc/progress.py | https://github.com/iterative/dvc/blob/8bb21261e34c9632453e09090de7ebe50e38d341/dvc/progress.py#L49-L62 | def refresh(self, line=None):
"""Refreshes progress bar."""
# Just go away if it is locked. Will update next time
if not self._lock.acquire(False):
return
if line is None:
line = self._line
if sys.stdout.isatty() and line is not None:
self._w... | [
"def",
"refresh",
"(",
"self",
",",
"line",
"=",
"None",
")",
":",
"# Just go away if it is locked. Will update next time",
"if",
"not",
"self",
".",
"_lock",
".",
"acquire",
"(",
"False",
")",
":",
"return",
"if",
"line",
"is",
"None",
":",
"line",
"=",
"... | Refreshes progress bar. | [
"Refreshes",
"progress",
"bar",
"."
] | python | train | 27.071429 |
mwickert/scikit-dsp-comm | sk_dsp_comm/synchronization.py | https://github.com/mwickert/scikit-dsp-comm/blob/5c1353412a4d81a8d7da169057564ecf940f8b5b/sk_dsp_comm/synchronization.py#L255-L269 | def time_step(z,Ns,t_step,Nstep):
"""
Create a one sample per symbol signal containing a phase rotation
step Nsymb into the waveform.
:param z: complex baseband signal after matched filter
:param Ns: number of sample per symbol
:param t_step: in samples relative to Ns
:param Nstep: symbol s... | [
"def",
"time_step",
"(",
"z",
",",
"Ns",
",",
"t_step",
",",
"Nstep",
")",
":",
"z_step",
"=",
"np",
".",
"hstack",
"(",
"(",
"z",
"[",
":",
"Ns",
"*",
"Nstep",
"]",
",",
"z",
"[",
"(",
"Ns",
"*",
"Nstep",
"+",
"t_step",
")",
":",
"]",
",",... | Create a one sample per symbol signal containing a phase rotation
step Nsymb into the waveform.
:param z: complex baseband signal after matched filter
:param Ns: number of sample per symbol
:param t_step: in samples relative to Ns
:param Nstep: symbol sample location where the step turns on
:re... | [
"Create",
"a",
"one",
"sample",
"per",
"symbol",
"signal",
"containing",
"a",
"phase",
"rotation",
"step",
"Nsymb",
"into",
"the",
"waveform",
"."
] | python | valid | 36.666667 |
johntruckenbrodt/spatialist | spatialist/vector.py | https://github.com/johntruckenbrodt/spatialist/blob/007f49296a156de8d7168ad235b5a5b8e8d3633d/spatialist/vector.py#L163-L182 | def addlayer(self, name, srs, geomType):
"""
add a layer to the vector layer
Parameters
----------
name: str
the layer name
srs: int, str or :osgeo:class:`osr.SpatialReference`
the spatial reference system. See :func:`spatialist.auxil.crsConvert` ... | [
"def",
"addlayer",
"(",
"self",
",",
"name",
",",
"srs",
",",
"geomType",
")",
":",
"self",
".",
"vector",
".",
"CreateLayer",
"(",
"name",
",",
"srs",
",",
"geomType",
")",
"self",
".",
"init_layer",
"(",
")"
] | add a layer to the vector layer
Parameters
----------
name: str
the layer name
srs: int, str or :osgeo:class:`osr.SpatialReference`
the spatial reference system. See :func:`spatialist.auxil.crsConvert` for options.
geomType: int
an OGR well-kn... | [
"add",
"a",
"layer",
"to",
"the",
"vector",
"layer"
] | python | train | 29.35 |
limodou/uliweb | uliweb/contrib/generic/__init__.py | https://github.com/limodou/uliweb/blob/34472f25e4bc0b954a35346672f94e84ef18b076/uliweb/contrib/generic/__init__.py#L88-L112 | def _list_view(self, model, **kwargs):
"""
:param model:
:param fields_convert_map: it's different from ListView
:param kwargs:
:return:
"""
from uliweb import request
#add download fields process
fields = kwargs.pop('fields', None)
meta =... | [
"def",
"_list_view",
"(",
"self",
",",
"model",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
"uliweb",
"import",
"request",
"#add download fields process",
"fields",
"=",
"kwargs",
".",
"pop",
"(",
"'fields'",
",",
"None",
")",
"meta",
"=",
"kwargs",
".",
... | :param model:
:param fields_convert_map: it's different from ListView
:param kwargs:
:return: | [
":",
"param",
"model",
":",
":",
"param",
"fields_convert_map",
":",
"it",
"s",
"different",
"from",
"ListView",
":",
"param",
"kwargs",
":",
":",
"return",
":"
] | python | train | 32.68 |
manodeep/Corrfunc | mocks/python_bindings/call_correlation_functions_mocks.py | https://github.com/manodeep/Corrfunc/blob/753aa50b93eebfefc76a0b0cd61522536bd45d2a/mocks/python_bindings/call_correlation_functions_mocks.py#L28-L41 | def read_text_file(filename, encoding="utf-8"):
"""
Reads a file under python3 with encoding (default UTF-8).
Also works under python2, without encoding.
Uses the EAFP (https://docs.python.org/2/glossary.html#term-eafp)
principle.
"""
try:
with open(filename, 'r', encoding) as f:
... | [
"def",
"read_text_file",
"(",
"filename",
",",
"encoding",
"=",
"\"utf-8\"",
")",
":",
"try",
":",
"with",
"open",
"(",
"filename",
",",
"'r'",
",",
"encoding",
")",
"as",
"f",
":",
"r",
"=",
"f",
".",
"read",
"(",
")",
"except",
"TypeError",
":",
... | Reads a file under python3 with encoding (default UTF-8).
Also works under python2, without encoding.
Uses the EAFP (https://docs.python.org/2/glossary.html#term-eafp)
principle. | [
"Reads",
"a",
"file",
"under",
"python3",
"with",
"encoding",
"(",
"default",
"UTF",
"-",
"8",
")",
".",
"Also",
"works",
"under",
"python2",
"without",
"encoding",
".",
"Uses",
"the",
"EAFP",
"(",
"https",
":",
"//",
"docs",
".",
"python",
".",
"org",... | python | train | 30.5 |
materialsproject/pymatgen | pymatgen/io/cif.py | https://github.com/materialsproject/pymatgen/blob/4ca558cf72f8d5f8a1f21dfdfc0181a971c186da/pymatgen/io/cif.py#L822-L839 | def parse_oxi_states(self, data):
"""
Parse oxidation states from data dictionary
"""
try:
oxi_states = {
data["_atom_type_symbol"][i]:
str2float(data["_atom_type_oxidation_number"][i])
for i in range(len(data["_atom_type_sy... | [
"def",
"parse_oxi_states",
"(",
"self",
",",
"data",
")",
":",
"try",
":",
"oxi_states",
"=",
"{",
"data",
"[",
"\"_atom_type_symbol\"",
"]",
"[",
"i",
"]",
":",
"str2float",
"(",
"data",
"[",
"\"_atom_type_oxidation_number\"",
"]",
"[",
"i",
"]",
")",
"... | Parse oxidation states from data dictionary | [
"Parse",
"oxidation",
"states",
"from",
"data",
"dictionary"
] | python | train | 41.722222 |
mozilla-releng/mozilla-version | mozilla_version/parser.py | https://github.com/mozilla-releng/mozilla-version/blob/e5400f31f7001bd48fb6e17626905147dd4c17d7/mozilla_version/parser.py#L26-L33 | def positive_int(val):
"""Parse `val` into a positive integer."""
if isinstance(val, float):
raise ValueError('"{}" must not be a float'.format(val))
val = int(val)
if val >= 0:
return val
raise ValueError('"{}" must be positive'.format(val)) | [
"def",
"positive_int",
"(",
"val",
")",
":",
"if",
"isinstance",
"(",
"val",
",",
"float",
")",
":",
"raise",
"ValueError",
"(",
"'\"{}\" must not be a float'",
".",
"format",
"(",
"val",
")",
")",
"val",
"=",
"int",
"(",
"val",
")",
"if",
"val",
">=",... | Parse `val` into a positive integer. | [
"Parse",
"val",
"into",
"a",
"positive",
"integer",
"."
] | python | train | 33.875 |
reanahub/reana-commons | reana_commons/utils.py | https://github.com/reanahub/reana-commons/blob/abf31d9f495e0d93171c43fc4a414cd292091b11/reana_commons/utils.py#L88-L95 | def calculate_file_access_time(workflow_workspace):
"""Calculate access times of files in workspace."""
access_times = {}
for subdir, dirs, files in os.walk(workflow_workspace):
for file in files:
file_path = os.path.join(subdir, file)
access_times[file_path] = os.stat(file_p... | [
"def",
"calculate_file_access_time",
"(",
"workflow_workspace",
")",
":",
"access_times",
"=",
"{",
"}",
"for",
"subdir",
",",
"dirs",
",",
"files",
"in",
"os",
".",
"walk",
"(",
"workflow_workspace",
")",
":",
"for",
"file",
"in",
"files",
":",
"file_path",... | Calculate access times of files in workspace. | [
"Calculate",
"access",
"times",
"of",
"files",
"in",
"workspace",
"."
] | python | train | 43.75 |
ibis-project/ibis | ibis/config.py | https://github.com/ibis-project/ibis/blob/1e39a5fd9ef088b45c155e8a5f541767ee8ef2e7/ibis/config.py#L599-L631 | def pp_options_list(keys, width=80, _print=False):
""" Builds a concise listing of available options, grouped by prefix """
from textwrap import wrap
from itertools import groupby
def pp(name, ks):
pfx = '- ' + name + '.[' if name else ''
ls = wrap(
', '.join(ks),
... | [
"def",
"pp_options_list",
"(",
"keys",
",",
"width",
"=",
"80",
",",
"_print",
"=",
"False",
")",
":",
"from",
"textwrap",
"import",
"wrap",
"from",
"itertools",
"import",
"groupby",
"def",
"pp",
"(",
"name",
",",
"ks",
")",
":",
"pfx",
"=",
"'- '",
... | Builds a concise listing of available options, grouped by prefix | [
"Builds",
"a",
"concise",
"listing",
"of",
"available",
"options",
"grouped",
"by",
"prefix"
] | python | train | 26.878788 |
jwass/geog | geog/geog.py | https://github.com/jwass/geog/blob/52ceb9b543454b31c63694ee459aad9cd52f011a/geog/geog.py#L129-L184 | def propagate(p0, angle, d, deg=True, bearing=False, r=r_earth_mean):
"""
Given an initial point and angle, move distance d along the surface
Parameters
----------
p0 : point-like (or array of point-like) [lon, lat] objects
angle : float (or array of float)
bearing. Note that by default... | [
"def",
"propagate",
"(",
"p0",
",",
"angle",
",",
"d",
",",
"deg",
"=",
"True",
",",
"bearing",
"=",
"False",
",",
"r",
"=",
"r_earth_mean",
")",
":",
"single",
",",
"(",
"p0",
",",
"angle",
",",
"d",
")",
"=",
"_to_arrays",
"(",
"(",
"p0",
","... | Given an initial point and angle, move distance d along the surface
Parameters
----------
p0 : point-like (or array of point-like) [lon, lat] objects
angle : float (or array of float)
bearing. Note that by default, 0 degrees is due East increasing
clockwise so that 90 degrees is due No... | [
"Given",
"an",
"initial",
"point",
"and",
"angle",
"move",
"distance",
"d",
"along",
"the",
"surface"
] | python | train | 29.892857 |
pybel/pybel | src/pybel/struct/graph.py | https://github.com/pybel/pybel/blob/c8a7a1bdae4c475fa2a8c77f3a9a5f6d79556ca0/src/pybel/struct/graph.py#L251-L253 | def defined_namespace_keywords(self) -> Set[str]: # noqa: D401
"""The set of all keywords defined as namespaces in this graph."""
return set(self.namespace_pattern) | set(self.namespace_url) | [
"def",
"defined_namespace_keywords",
"(",
"self",
")",
"->",
"Set",
"[",
"str",
"]",
":",
"# noqa: D401",
"return",
"set",
"(",
"self",
".",
"namespace_pattern",
")",
"|",
"set",
"(",
"self",
".",
"namespace_url",
")"
] | The set of all keywords defined as namespaces in this graph. | [
"The",
"set",
"of",
"all",
"keywords",
"defined",
"as",
"namespaces",
"in",
"this",
"graph",
"."
] | python | train | 68.333333 |
nerox8664/pytorch2keras | pytorch2keras/operation_layers.py | https://github.com/nerox8664/pytorch2keras/blob/750eaf747323580e6732d0c5ba9f2f39cb096764/pytorch2keras/operation_layers.py#L10-L32 | def convert_sum(
params, w_name, scope_name, inputs, layers, weights, names
):
"""
Convert sum.
Args:
params: dictionary with layer parameters
w_name: name prefix in state_dict
scope_name: pytorch scope name
inputs: pytorch node inputs
layers: dictionary with ker... | [
"def",
"convert_sum",
"(",
"params",
",",
"w_name",
",",
"scope_name",
",",
"inputs",
",",
"layers",
",",
"weights",
",",
"names",
")",
":",
"print",
"(",
"'Converting Sum ...'",
")",
"def",
"target_layer",
"(",
"x",
")",
":",
"import",
"keras",
".",
"ba... | Convert sum.
Args:
params: dictionary with layer parameters
w_name: name prefix in state_dict
scope_name: pytorch scope name
inputs: pytorch node inputs
layers: dictionary with keras tensors
weights: pytorch state_dict
names: use short names for keras layers | [
"Convert",
"sum",
"."
] | python | valid | 27.26087 |
tensorflow/cleverhans | examples/nips17_adversarial_competition/dev_toolkit/sample_attacks/fgsm/attack_fgsm.py | https://github.com/tensorflow/cleverhans/blob/97488e215760547b81afc53f5e5de8ba7da5bd98/examples/nips17_adversarial_competition/dev_toolkit/sample_attacks/fgsm/attack_fgsm.py#L47-L77 | def load_images(input_dir, batch_shape):
"""Read png images from input directory in batches.
Args:
input_dir: input directory
batch_shape: shape of minibatch array, i.e. [batch_size, height, width, 3]
Yields:
filenames: list file names without path of each image
Lenght of this list could be le... | [
"def",
"load_images",
"(",
"input_dir",
",",
"batch_shape",
")",
":",
"images",
"=",
"np",
".",
"zeros",
"(",
"batch_shape",
")",
"filenames",
"=",
"[",
"]",
"idx",
"=",
"0",
"batch_size",
"=",
"batch_shape",
"[",
"0",
"]",
"for",
"filepath",
"in",
"tf... | Read png images from input directory in batches.
Args:
input_dir: input directory
batch_shape: shape of minibatch array, i.e. [batch_size, height, width, 3]
Yields:
filenames: list file names without path of each image
Lenght of this list could be less than batch_size, in this case only
fi... | [
"Read",
"png",
"images",
"from",
"input",
"directory",
"in",
"batches",
"."
] | python | train | 34.903226 |
wtsi-hgi/python-hgijson | hgijson/json_converters/builders.py | https://github.com/wtsi-hgi/python-hgijson/blob/6e8ccb562eabcaa816a136268a16504c2e0d4664/hgijson/json_converters/builders.py#L25-L48 | def _get_all_property_mappings(encoder: MappingJSONEncoder, property_mappings: Iterable[JsonPropertyMapping],
superclasses: Tuple[PropertyMapper]) -> List[JsonPropertyMapping]:
"""
Gets all of the property mappings from the given property mapper, considering the property mappings ... | [
"def",
"_get_all_property_mappings",
"(",
"encoder",
":",
"MappingJSONEncoder",
",",
"property_mappings",
":",
"Iterable",
"[",
"JsonPropertyMapping",
"]",
",",
"superclasses",
":",
"Tuple",
"[",
"PropertyMapper",
"]",
")",
"->",
"List",
"[",
"JsonPropertyMapping",
... | Gets all of the property mappings from the given property mapper, considering the property mappings for self and the
property mappings defined by the superclass.
:param encoder: `self` when binded as class method
:param property_mappings: mappings defined for the given encoder, excluding mappings defined by... | [
"Gets",
"all",
"of",
"the",
"property",
"mappings",
"from",
"the",
"given",
"property",
"mapper",
"considering",
"the",
"property",
"mappings",
"for",
"self",
"and",
"the",
"property",
"mappings",
"defined",
"by",
"the",
"superclass",
".",
":",
"param",
"encod... | python | train | 63.375 |
mitsei/dlkit | dlkit/json_/repository/objects.py | https://github.com/mitsei/dlkit/blob/445f968a175d61c8d92c0f617a3c17dc1dc7c584/dlkit/json_/repository/objects.py#L1177-L1195 | def set_published_date(self, published_date):
"""Sets the published date.
arg: published_date (osid.calendaring.DateTime): the new
published date
raise: InvalidArgument - ``published_date`` is invalid
raise: NoAccess - ``Metadata.isReadOnly()`` is ``true``
r... | [
"def",
"set_published_date",
"(",
"self",
",",
"published_date",
")",
":",
"# Implemented from template for osid.assessment.AssessmentOfferedForm.set_start_time_template",
"if",
"self",
".",
"get_published_date_metadata",
"(",
")",
".",
"is_read_only",
"(",
")",
":",
"raise",... | Sets the published date.
arg: published_date (osid.calendaring.DateTime): the new
published date
raise: InvalidArgument - ``published_date`` is invalid
raise: NoAccess - ``Metadata.isReadOnly()`` is ``true``
raise: NullArgument - ``published_date`` is ``null``
... | [
"Sets",
"the",
"published",
"date",
"."
] | python | train | 45.210526 |
log2timeline/plaso | plaso/lib/lexer.py | https://github.com/log2timeline/plaso/blob/9c564698d2da3ffbe23607a3c54c0582ea18a6cc/plaso/lib/lexer.py#L72-L120 | def NextToken(self):
"""Fetch the next token by trying to match any of the regexes in order."""
current_state = self.state
for token in self.tokens:
# Does the rule apply to us?
if not token.state_regex.match(current_state):
continue
# Try to match the rule
m = token.regex.m... | [
"def",
"NextToken",
"(",
"self",
")",
":",
"current_state",
"=",
"self",
".",
"state",
"for",
"token",
"in",
"self",
".",
"tokens",
":",
"# Does the rule apply to us?",
"if",
"not",
"token",
".",
"state_regex",
".",
"match",
"(",
"current_state",
")",
":",
... | Fetch the next token by trying to match any of the regexes in order. | [
"Fetch",
"the",
"next",
"token",
"by",
"trying",
"to",
"match",
"any",
"of",
"the",
"regexes",
"in",
"order",
"."
] | python | train | 31.938776 |
yvesalexandre/bandicoot | bandicoot/individual.py | https://github.com/yvesalexandre/bandicoot/blob/73a658f6f17331541cf0b1547028db9b70e8d58a/bandicoot/individual.py#L250-L286 | def response_delay_text(records):
"""
The response delay of the user within a conversation (in seconds)
The following sequence of messages defines conversations (``I`` for an
incoming text, ``O`` for an outgoing text, ``-`` for a one minute
delay): ::
I-O--I----O, we have a 60 seconds resp... | [
"def",
"response_delay_text",
"(",
"records",
")",
":",
"interactions",
"=",
"defaultdict",
"(",
"list",
")",
"for",
"r",
"in",
"records",
":",
"interactions",
"[",
"r",
".",
"correspondent_id",
"]",
".",
"append",
"(",
"r",
")",
"def",
"_response_delay",
... | The response delay of the user within a conversation (in seconds)
The following sequence of messages defines conversations (``I`` for an
incoming text, ``O`` for an outgoing text, ``-`` for a one minute
delay): ::
I-O--I----O, we have a 60 seconds response delay and a 240 seconds response delay
... | [
"The",
"response",
"delay",
"of",
"the",
"user",
"within",
"a",
"conversation",
"(",
"in",
"seconds",
")"
] | python | train | 36.459459 |
twisted/txaws | txaws/server/schema.py | https://github.com/twisted/txaws/blob/5c3317376cd47e536625027e38c3b37840175ce0/txaws/server/schema.py#L646-L678 | def _convert_flat_to_nest(self, params):
"""
Convert a structure in the form of::
{'foo.1.bar': 'value',
'foo.2.baz': 'value'}
to::
{'foo': {'1': {'bar': 'value'},
'2': {'baz': 'value'}}}
This is intended for use both during p... | [
"def",
"_convert_flat_to_nest",
"(",
"self",
",",
"params",
")",
":",
"result",
"=",
"{",
"}",
"for",
"k",
",",
"v",
"in",
"params",
".",
"iteritems",
"(",
")",
":",
"last",
"=",
"result",
"segments",
"=",
"k",
".",
"split",
"(",
"'.'",
")",
"for",... | Convert a structure in the form of::
{'foo.1.bar': 'value',
'foo.2.baz': 'value'}
to::
{'foo': {'1': {'bar': 'value'},
'2': {'baz': 'value'}}}
This is intended for use both during parsing of HTTP arguments like
'foo.1.bar=value' and w... | [
"Convert",
"a",
"structure",
"in",
"the",
"form",
"of",
"::"
] | python | train | 33.363636 |
alphatwirl/alphatwirl | alphatwirl/concurrently/CommunicationChannel.py | https://github.com/alphatwirl/alphatwirl/blob/5138eeba6cd8a334ba52d6c2c022b33c61e3ba38/alphatwirl/concurrently/CommunicationChannel.py#L152-L187 | def put_multiple(self, task_args_kwargs_list):
"""put a list of tasks and their arguments
This method can be used to put multiple tasks at once. Calling
this method once with multiple tasks can be much faster than
calling `put()` multiple times.
Parameters
----------
... | [
"def",
"put_multiple",
"(",
"self",
",",
"task_args_kwargs_list",
")",
":",
"if",
"not",
"self",
".",
"isopen",
":",
"logger",
"=",
"logging",
".",
"getLogger",
"(",
"__name__",
")",
"logger",
".",
"warning",
"(",
"'the drop box is not open'",
")",
"return",
... | put a list of tasks and their arguments
This method can be used to put multiple tasks at once. Calling
this method once with multiple tasks can be much faster than
calling `put()` multiple times.
Parameters
----------
task_args_kwargs_list : list
A list of ... | [
"put",
"a",
"list",
"of",
"tasks",
"and",
"their",
"arguments"
] | python | valid | 31.805556 |
saltstack/salt | salt/modules/win_pkg.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/win_pkg.py#L766-L832 | def _refresh_db_conditional(saltenv, **kwargs):
'''
Internal use only in this module, has a different set of defaults and
returns True or False. And supports checking the age of the existing
generated metadata db, as well as ensure metadata db exists to begin with
Args:
saltenv (str): Salt ... | [
"def",
"_refresh_db_conditional",
"(",
"saltenv",
",",
"*",
"*",
"kwargs",
")",
":",
"force",
"=",
"salt",
".",
"utils",
".",
"data",
".",
"is_true",
"(",
"kwargs",
".",
"pop",
"(",
"'force'",
",",
"False",
")",
")",
"failhard",
"=",
"salt",
".",
"ut... | Internal use only in this module, has a different set of defaults and
returns True or False. And supports checking the age of the existing
generated metadata db, as well as ensure metadata db exists to begin with
Args:
saltenv (str): Salt environment
Kwargs:
force (bool):
... | [
"Internal",
"use",
"only",
"in",
"this",
"module",
"has",
"a",
"different",
"set",
"of",
"defaults",
"and",
"returns",
"True",
"or",
"False",
".",
"And",
"supports",
"checking",
"the",
"age",
"of",
"the",
"existing",
"generated",
"metadata",
"db",
"as",
"w... | python | train | 33.328358 |
enkore/i3pystatus | i3pystatus/cpu_usage.py | https://github.com/enkore/i3pystatus/blob/14cfde967cecf79b40e223e35a04600f4c875af7/i3pystatus/cpu_usage.py#L116-L134 | def get_usage(self):
"""
parses /proc/stat and calcualtes total and busy time
(more specific USER_HZ see man 5 proc for further informations )
"""
usage = {}
for cpu, timings in self.get_cpu_timings().items():
cpu_total = sum(timings)
del timings[... | [
"def",
"get_usage",
"(",
"self",
")",
":",
"usage",
"=",
"{",
"}",
"for",
"cpu",
",",
"timings",
"in",
"self",
".",
"get_cpu_timings",
"(",
")",
".",
"items",
"(",
")",
":",
"cpu_total",
"=",
"sum",
"(",
"timings",
")",
"del",
"timings",
"[",
"3",
... | parses /proc/stat and calcualtes total and busy time
(more specific USER_HZ see man 5 proc for further informations ) | [
"parses",
"/",
"proc",
"/",
"stat",
"and",
"calcualtes",
"total",
"and",
"busy",
"time",
"(",
"more",
"specific",
"USER_HZ",
"see",
"man",
"5",
"proc",
"for",
"further",
"informations",
")"
] | python | train | 29.684211 |
quantmind/pulsar | pulsar/apps/data/redis/client.py | https://github.com/quantmind/pulsar/blob/fee44e871954aa6ca36d00bb5a3739abfdb89b26/pulsar/apps/data/redis/client.py#L434-L498 | def sort(self, key, start=None, num=None, by=None, get=None,
desc=False, alpha=False, store=None, groups=False):
'''Sort and return the list, set or sorted set at ``key``.
``start`` and ``num`` allow for paging through the sorted data
``by`` allows using an external key to weight ... | [
"def",
"sort",
"(",
"self",
",",
"key",
",",
"start",
"=",
"None",
",",
"num",
"=",
"None",
",",
"by",
"=",
"None",
",",
"get",
"=",
"None",
",",
"desc",
"=",
"False",
",",
"alpha",
"=",
"False",
",",
"store",
"=",
"None",
",",
"groups",
"=",
... | Sort and return the list, set or sorted set at ``key``.
``start`` and ``num`` allow for paging through the sorted data
``by`` allows using an external key to weight and sort the items.
Use an "*" to indicate where in the key the item value is located
``get`` allows for returning i... | [
"Sort",
"and",
"return",
"the",
"list",
"set",
"or",
"sorted",
"set",
"at",
"key",
"."
] | python | train | 39.246154 |
blockstack-packages/keychain-manager-py | keychain/utils.py | https://github.com/blockstack-packages/keychain-manager-py/blob/c15c4ed8f3ed155f71ccac7c13ee08f081d38c06/keychain/utils.py#L28-L38 | def bip32_serialize(rawtuple):
"""
Derived from code from pybitcointools (https://github.com/vbuterin/pybitcointools)
by Vitalik Buterin
"""
vbytes, depth, fingerprint, i, chaincode, key = rawtuple
i = encode(i, 256, 4)
chaincode = encode(hash_to_int(chaincode), 256, 32)
keydata = b'\x00... | [
"def",
"bip32_serialize",
"(",
"rawtuple",
")",
":",
"vbytes",
",",
"depth",
",",
"fingerprint",
",",
"i",
",",
"chaincode",
",",
"key",
"=",
"rawtuple",
"i",
"=",
"encode",
"(",
"i",
",",
"256",
",",
"4",
")",
"chaincode",
"=",
"encode",
"(",
"hash_... | Derived from code from pybitcointools (https://github.com/vbuterin/pybitcointools)
by Vitalik Buterin | [
"Derived",
"from",
"code",
"from",
"pybitcointools",
"(",
"https",
":",
"//",
"github",
".",
"com",
"/",
"vbuterin",
"/",
"pybitcointools",
")",
"by",
"Vitalik",
"Buterin"
] | python | test | 46.818182 |
gwww/elkm1 | elkm1_lib/lights.py | https://github.com/gwww/elkm1/blob/078d0de30840c3fab46f1f8534d98df557931e91/elkm1_lib/lights.py#L14-L21 | def level(self, level, time=0):
"""(Helper) Set light to specified level"""
if level <= 0:
self._elk.send(pf_encode(self._index))
elif level >= 98:
self._elk.send(pn_encode(self._index))
else:
self._elk.send(pc_encode(self._index, 9, level, time)) | [
"def",
"level",
"(",
"self",
",",
"level",
",",
"time",
"=",
"0",
")",
":",
"if",
"level",
"<=",
"0",
":",
"self",
".",
"_elk",
".",
"send",
"(",
"pf_encode",
"(",
"self",
".",
"_index",
")",
")",
"elif",
"level",
">=",
"98",
":",
"self",
".",
... | (Helper) Set light to specified level | [
"(",
"Helper",
")",
"Set",
"light",
"to",
"specified",
"level"
] | python | train | 38.5 |
saltstack/salt | salt/modules/solr.py | https://github.com/saltstack/salt/blob/e8541fd6e744ab0df786c0f76102e41631f45d46/salt/modules/solr.py#L1198-L1252 | def full_import(handler, host=None, core_name=None, options=None, extra=None):
'''
MASTER ONLY
Submits an import command to the specified handler using specified options.
This command can only be run if the minion is configured with
solr.type=master
handler : str
The name of the data im... | [
"def",
"full_import",
"(",
"handler",
",",
"host",
"=",
"None",
",",
"core_name",
"=",
"None",
",",
"options",
"=",
"None",
",",
"extra",
"=",
"None",
")",
":",
"options",
"=",
"{",
"}",
"if",
"options",
"is",
"None",
"else",
"options",
"extra",
"=",... | MASTER ONLY
Submits an import command to the specified handler using specified options.
This command can only be run if the minion is configured with
solr.type=master
handler : str
The name of the data import handler.
host : str (None)
The solr host to query. __opts__['host'] is def... | [
"MASTER",
"ONLY",
"Submits",
"an",
"import",
"command",
"to",
"the",
"specified",
"handler",
"using",
"specified",
"options",
".",
"This",
"command",
"can",
"only",
"be",
"run",
"if",
"the",
"minion",
"is",
"configured",
"with",
"solr",
".",
"type",
"=",
"... | python | train | 37.745455 |
devricks/soft_drf | soft_drf/auth/utilities.py | https://github.com/devricks/soft_drf/blob/1869b13f9341bfcebd931059e93de2bc38570da3/soft_drf/auth/utilities.py#L107-L119 | def create_token(user):
"""
Create token.
"""
payload = jwt_payload_handler(user)
if api_settings.JWT_ALLOW_REFRESH:
payload['orig_iat'] = timegm(
datetime.utcnow().utctimetuple()
)
# Return values
token = jwt_encode_handler(payload)
return token | [
"def",
"create_token",
"(",
"user",
")",
":",
"payload",
"=",
"jwt_payload_handler",
"(",
"user",
")",
"if",
"api_settings",
".",
"JWT_ALLOW_REFRESH",
":",
"payload",
"[",
"'orig_iat'",
"]",
"=",
"timegm",
"(",
"datetime",
".",
"utcnow",
"(",
")",
".",
"ut... | Create token. | [
"Create",
"token",
"."
] | python | train | 22.692308 |
pseudonym117/Riot-Watcher | src/riotwatcher/Handlers/RateLimit/RateLimitHandler.py | https://github.com/pseudonym117/Riot-Watcher/blob/21ab12453a0d824d67e30f5514d02a5c5a411dea/src/riotwatcher/Handlers/RateLimit/RateLimitHandler.py#L54-L67 | def after_request(self, region, endpoint_name, method_name, url, response):
"""
Called after a response is received and before it is returned to the user.
:param string region: the region of this request
:param string endpoint_name: the name of the endpoint that was requested
:p... | [
"def",
"after_request",
"(",
"self",
",",
"region",
",",
"endpoint_name",
",",
"method_name",
",",
"url",
",",
"response",
")",
":",
"for",
"limiter",
"in",
"self",
".",
"_limiters",
":",
"limiter",
".",
"update_limiter",
"(",
"region",
",",
"endpoint_name",... | Called after a response is received and before it is returned to the user.
:param string region: the region of this request
:param string endpoint_name: the name of the endpoint that was requested
:param string method_name: the name of the method that was requested
:param url: The url t... | [
"Called",
"after",
"a",
"response",
"is",
"received",
"and",
"before",
"it",
"is",
"returned",
"to",
"the",
"user",
"."
] | python | train | 47.857143 |
jgorset/facebook | facebook/entity.py | https://github.com/jgorset/facebook/blob/90f035ae1828e4eeb7af428964fedf0ee99ec2ad/facebook/entity.py#L29-L34 | def cache(self):
"""Query or return the Graph API representation of this resource."""
if not self._cache:
self._cache = self.graph.get('%s' % self.id)
return self._cache | [
"def",
"cache",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_cache",
":",
"self",
".",
"_cache",
"=",
"self",
".",
"graph",
".",
"get",
"(",
"'%s'",
"%",
"self",
".",
"id",
")",
"return",
"self",
".",
"_cache"
] | Query or return the Graph API representation of this resource. | [
"Query",
"or",
"return",
"the",
"Graph",
"API",
"representation",
"of",
"this",
"resource",
"."
] | python | train | 33.5 |
djaodjin/djaodjin-deployutils | deployutils/apps/flask/templates.py | https://github.com/djaodjin/djaodjin-deployutils/blob/a0fe3cf3030dbbf09025c69ce75a69b326565dd8/deployutils/apps/flask/templates.py#L31-L48 | def site_prefixed(path):
"""
*Mockup*: adds the path prefix when required.
"""
if path is None:
path = ''
if settings.DEBUG and hasattr(settings, 'APP_NAME'):
path_prefix = '/%s' % settings.APP_NAME
else:
path_prefix = ''
if path:
# We have an actual path inst... | [
"def",
"site_prefixed",
"(",
"path",
")",
":",
"if",
"path",
"is",
"None",
":",
"path",
"=",
"''",
"if",
"settings",
".",
"DEBUG",
"and",
"hasattr",
"(",
"settings",
",",
"'APP_NAME'",
")",
":",
"path_prefix",
"=",
"'/%s'",
"%",
"settings",
".",
"APP_N... | *Mockup*: adds the path prefix when required. | [
"*",
"Mockup",
"*",
":",
"adds",
"the",
"path",
"prefix",
"when",
"required",
"."
] | python | train | 33.222222 |
pmacosta/pexdoc | pexdoc/pinspect.py | https://github.com/pmacosta/pexdoc/blob/201ac243e5781347feb75896a4231429fe6da4b1/pexdoc/pinspect.py#L531-L576 | def load(self, callables_fname):
r"""
Load traced modules information from a `JSON <http://www.json.org/>`_ file.
The loaded module information is merged with any existing module information
:param callables_fname: File name
:type callables_fname: :ref:`FileNameExists`
... | [
"def",
"load",
"(",
"self",
",",
"callables_fname",
")",
":",
"# Validate file name",
"_validate_fname",
"(",
"callables_fname",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"callables_fname",
")",
":",
"raise",
"OSError",
"(",
"\"File {0} could not ... | r"""
Load traced modules information from a `JSON <http://www.json.org/>`_ file.
The loaded module information is merged with any existing module information
:param callables_fname: File name
:type callables_fname: :ref:`FileNameExists`
:raises:
* OSError (File *[fna... | [
"r",
"Load",
"traced",
"modules",
"information",
"from",
"a",
"JSON",
"<http",
":",
"//",
"www",
".",
"json",
".",
"org",
"/",
">",
"_",
"file",
"."
] | python | train | 45.434783 |
flowersteam/explauto | explauto/sensorimotor_model/inverse/inverse.py | https://github.com/flowersteam/explauto/blob/cf0f81ecb9f6412f7276a95bd27359000e1e26b6/explauto/sensorimotor_model/inverse/inverse.py#L81-L93 | def _guess_x_kmeans(self, y_desired, **kwargs):
"""Provide an initial guesses for a probable x from y"""
k = kwargs.get('k', self.k)
_, indexes = self.fmodel.dataset.nn_y(y_desired, k=k)
X = np.array([self.fmodel.get_x(i) for i in indexes])
if np.sum(X) == 0.:
centroi... | [
"def",
"_guess_x_kmeans",
"(",
"self",
",",
"y_desired",
",",
"*",
"*",
"kwargs",
")",
":",
"k",
"=",
"kwargs",
".",
"get",
"(",
"'k'",
",",
"self",
".",
"k",
")",
"_",
",",
"indexes",
"=",
"self",
".",
"fmodel",
".",
"dataset",
".",
"nn_y",
"(",... | Provide an initial guesses for a probable x from y | [
"Provide",
"an",
"initial",
"guesses",
"for",
"a",
"probable",
"x",
"from",
"y"
] | python | train | 42.615385 |
secdev/scapy | scapy/packet.py | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/packet.py#L1588-L1600 | def split_bottom_up(lower, upper, __fval=None, **fval):
"""This call un-links an association that was made using bind_bottom_up.
Have a look at help(bind_bottom_up)
"""
if __fval is not None:
fval.update(__fval)
def do_filter(params, cls):
params_is_invalid = any(
k not ... | [
"def",
"split_bottom_up",
"(",
"lower",
",",
"upper",
",",
"__fval",
"=",
"None",
",",
"*",
"*",
"fval",
")",
":",
"if",
"__fval",
"is",
"not",
"None",
":",
"fval",
".",
"update",
"(",
"__fval",
")",
"def",
"do_filter",
"(",
"params",
",",
"cls",
"... | This call un-links an association that was made using bind_bottom_up.
Have a look at help(bind_bottom_up) | [
"This",
"call",
"un",
"-",
"links",
"an",
"association",
"that",
"was",
"made",
"using",
"bind_bottom_up",
".",
"Have",
"a",
"look",
"at",
"help",
"(",
"bind_bottom_up",
")"
] | python | train | 38.615385 |
openstack/networking-cisco | networking_cisco/plugins/cisco/cfg_agent/device_drivers/iosxe/iosxe_routing_driver.py | https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/device_drivers/iosxe/iosxe_routing_driver.py#L384-L403 | def _check_acl(self, acl_no, network, netmask):
"""Check a ACL config exists in the running config.
:param acl_no: access control list (ACL) number
:param network: network which this ACL permits
:param netmask: netmask of the network
:return:
"""
exp_cfg_lines = ... | [
"def",
"_check_acl",
"(",
"self",
",",
"acl_no",
",",
"network",
",",
"netmask",
")",
":",
"exp_cfg_lines",
"=",
"[",
"'ip access-list standard '",
"+",
"str",
"(",
"acl_no",
")",
",",
"' permit '",
"+",
"str",
"(",
"network",
")",
"+",
"' '",
"+",
"str"... | Check a ACL config exists in the running config.
:param acl_no: access control list (ACL) number
:param network: network which this ACL permits
:param netmask: netmask of the network
:return: | [
"Check",
"a",
"ACL",
"config",
"exists",
"in",
"the",
"running",
"config",
"."
] | python | train | 40.95 |
rosenbrockc/fortpy | fortpy/utility.py | https://github.com/rosenbrockc/fortpy/blob/1ed0757c52d549e41d9d44bdea68cb89529293a5/fortpy/utility.py#L17-L39 | def symlink(source, target, isfile=True):
"""Creates a symlink at target *file* pointing to source.
:arg isfile: when True, if symlinking is disabled in the global config, the file
is copied instead with fortpy.utility.copyfile; otherwise fortpy.utility.copy
is used and the target is considered a d... | [
"def",
"symlink",
"(",
"source",
",",
"target",
",",
"isfile",
"=",
"True",
")",
":",
"from",
"fortpy",
".",
"code",
"import",
"config",
"from",
"os",
"import",
"path",
"if",
"config",
".",
"symlink",
":",
"from",
"os",
"import",
"symlink",
",",
"remov... | Creates a symlink at target *file* pointing to source.
:arg isfile: when True, if symlinking is disabled in the global config, the file
is copied instead with fortpy.utility.copyfile; otherwise fortpy.utility.copy
is used and the target is considered a directory. | [
"Creates",
"a",
"symlink",
"at",
"target",
"*",
"file",
"*",
"pointing",
"to",
"source",
"."
] | python | train | 37 |
marcomusy/vtkplotter | vtkplotter/actors.py | https://github.com/marcomusy/vtkplotter/blob/692c3396782722ec525bc1346a26999868c650c6/vtkplotter/actors.py#L870-L884 | def color(self, c=False):
"""
Set/get actor's color.
If None is passed as input, will use colors from active scalars.
Same as `c()`.
"""
if c is False:
return np.array(self.GetProperty().GetColor())
elif c is None:
self.GetMapper().ScalarVi... | [
"def",
"color",
"(",
"self",
",",
"c",
"=",
"False",
")",
":",
"if",
"c",
"is",
"False",
":",
"return",
"np",
".",
"array",
"(",
"self",
".",
"GetProperty",
"(",
")",
".",
"GetColor",
"(",
")",
")",
"elif",
"c",
"is",
"None",
":",
"self",
".",
... | Set/get actor's color.
If None is passed as input, will use colors from active scalars.
Same as `c()`. | [
"Set",
"/",
"get",
"actor",
"s",
"color",
".",
"If",
"None",
"is",
"passed",
"as",
"input",
"will",
"use",
"colors",
"from",
"active",
"scalars",
".",
"Same",
"as",
"c",
"()",
"."
] | python | train | 32.733333 |
Galarzaa90/tibia.py | tibiapy/utils.py | https://github.com/Galarzaa90/tibia.py/blob/02ba1a8f1e18177ef5c7dcd44affc8d761d59e12/tibiapy/utils.py#L242-L262 | def parse_tibiacom_content(content, *, html_class="BoxContent", tag="div", builder="lxml"):
"""Parses HTML content from Tibia.com into a BeautifulSoup object.
Parameters
----------
content: :class:`str`
The raw HTML content from Tibia.com
html_class: :class:`str`
The HTML class of t... | [
"def",
"parse_tibiacom_content",
"(",
"content",
",",
"*",
",",
"html_class",
"=",
"\"BoxContent\"",
",",
"tag",
"=",
"\"div\"",
",",
"builder",
"=",
"\"lxml\"",
")",
":",
"return",
"bs4",
".",
"BeautifulSoup",
"(",
"content",
".",
"replace",
"(",
"'ISO-8859... | Parses HTML content from Tibia.com into a BeautifulSoup object.
Parameters
----------
content: :class:`str`
The raw HTML content from Tibia.com
html_class: :class:`str`
The HTML class of the parsed element. The default value is ``BoxContent``.
tag: :class:`str`
The HTML tag ... | [
"Parses",
"HTML",
"content",
"from",
"Tibia",
".",
"com",
"into",
"a",
"BeautifulSoup",
"object",
"."
] | python | train | 37.285714 |
Crunch-io/crunch-cube | src/cr/cube/dimension.py | https://github.com/Crunch-io/crunch-cube/blob/a837840755690eb14b2ec8e8d93b4104e01c854f/src/cr/cube/dimension.py#L322-L357 | def labels(
self, include_missing=False, include_transforms=False, include_cat_ids=False
):
"""Return list of str labels for the elements of this dimension.
Returns a list of (label, element_id) pairs if *include_cat_ids* is
True. The `element_id` value in the second position of the... | [
"def",
"labels",
"(",
"self",
",",
"include_missing",
"=",
"False",
",",
"include_transforms",
"=",
"False",
",",
"include_cat_ids",
"=",
"False",
")",
":",
"# TODO: Having an alternate return type triggered by a flag-parameter",
"# (`include_cat_ids` in this case) is poor prac... | Return list of str labels for the elements of this dimension.
Returns a list of (label, element_id) pairs if *include_cat_ids* is
True. The `element_id` value in the second position of the pair is
None for subtotal items (which don't have an element-id). | [
"Return",
"list",
"of",
"str",
"labels",
"for",
"the",
"elements",
"of",
"this",
"dimension",
"."
] | python | train | 42.194444 |
HazyResearch/pdftotree | pdftotree/utils/pdf/layout_utils.py | https://github.com/HazyResearch/pdftotree/blob/5890d668b475d5d3058d1d886aafbfd83268c440/pdftotree/utils/pdf/layout_utils.py#L17-L25 | def traverse_layout(root, callback):
"""
Tree walker and invokes the callback as it
traverse pdf object tree
"""
callback(root)
if isinstance(root, collections.Iterable):
for child in root:
traverse_layout(child, callback) | [
"def",
"traverse_layout",
"(",
"root",
",",
"callback",
")",
":",
"callback",
"(",
"root",
")",
"if",
"isinstance",
"(",
"root",
",",
"collections",
".",
"Iterable",
")",
":",
"for",
"child",
"in",
"root",
":",
"traverse_layout",
"(",
"child",
",",
"call... | Tree walker and invokes the callback as it
traverse pdf object tree | [
"Tree",
"walker",
"and",
"invokes",
"the",
"callback",
"as",
"it",
"traverse",
"pdf",
"object",
"tree"
] | python | train | 28.666667 |
fhcrc/seqmagick | seqmagick/transform.py | https://github.com/fhcrc/seqmagick/blob/1642bb87ba5c171fbd307f9da0f8a0ee1d69d5ed/seqmagick/transform.py#L134-L143 | def include_from_file(records, handle):
"""
Filter the records, keeping only sequences whose ID is contained in the
handle.
"""
ids = set(i.strip() for i in handle)
for record in records:
if record.id.strip() in ids:
yield record | [
"def",
"include_from_file",
"(",
"records",
",",
"handle",
")",
":",
"ids",
"=",
"set",
"(",
"i",
".",
"strip",
"(",
")",
"for",
"i",
"in",
"handle",
")",
"for",
"record",
"in",
"records",
":",
"if",
"record",
".",
"id",
".",
"strip",
"(",
")",
"... | Filter the records, keeping only sequences whose ID is contained in the
handle. | [
"Filter",
"the",
"records",
"keeping",
"only",
"sequences",
"whose",
"ID",
"is",
"contained",
"in",
"the",
"handle",
"."
] | python | train | 26.5 |
moluwole/Bast | bast/controller.py | https://github.com/moluwole/Bast/blob/eecf55ae72e6f24af7c101549be0422cd2c1c95a/bast/controller.py#L37-L51 | def write_error(self, status_code, **kwargs):
"""
Handle Exceptions from the server. Formats the HTML into readable form
"""
reason = self._reason
if self.settings.get("serve_traceback") and "exc_info" in kwargs:
error = []
for line in traceback.format_ex... | [
"def",
"write_error",
"(",
"self",
",",
"status_code",
",",
"*",
"*",
"kwargs",
")",
":",
"reason",
"=",
"self",
".",
"_reason",
"if",
"self",
".",
"settings",
".",
"get",
"(",
"\"serve_traceback\"",
")",
"and",
"\"exc_info\"",
"in",
"kwargs",
":",
"erro... | Handle Exceptions from the server. Formats the HTML into readable form | [
"Handle",
"Exceptions",
"from",
"the",
"server",
".",
"Formats",
"the",
"HTML",
"into",
"readable",
"form"
] | python | train | 37.466667 |
dingusdk/PythonIhcSdk | ihcsdk/ihccontroller.py | https://github.com/dingusdk/PythonIhcSdk/blob/7e2067e009fe7600b49f30bff1cf91dc72fc891e/ihcsdk/ihccontroller.py#L75-L85 | def get_project(self) -> str:
""" Get the ihc project and make sure controller is ready before"""
with IHCController._mutex:
if self._project is None:
if self.client.get_state() != IHCSTATE_READY:
ready = self.client.wait_for_state_change(IHCSTATE_READY,
... | [
"def",
"get_project",
"(",
"self",
")",
"->",
"str",
":",
"with",
"IHCController",
".",
"_mutex",
":",
"if",
"self",
".",
"_project",
"is",
"None",
":",
"if",
"self",
".",
"client",
".",
"get_state",
"(",
")",
"!=",
"IHCSTATE_READY",
":",
"ready",
"=",... | Get the ihc project and make sure controller is ready before | [
"Get",
"the",
"ihc",
"project",
"and",
"make",
"sure",
"controller",
"is",
"ready",
"before"
] | python | train | 49.545455 |
facelessuser/soupsieve | soupsieve/css_match.py | https://github.com/facelessuser/soupsieve/blob/24859cc3e756ebf46b75547d49c6b4a7bf35ee82/soupsieve/css_match.py#L236-L242 | def get_parent(self, el, no_iframe=False):
"""Get parent."""
parent = el.parent
if no_iframe and parent is not None and self.is_iframe(parent):
parent = None
return parent | [
"def",
"get_parent",
"(",
"self",
",",
"el",
",",
"no_iframe",
"=",
"False",
")",
":",
"parent",
"=",
"el",
".",
"parent",
"if",
"no_iframe",
"and",
"parent",
"is",
"not",
"None",
"and",
"self",
".",
"is_iframe",
"(",
"parent",
")",
":",
"parent",
"=... | Get parent. | [
"Get",
"parent",
"."
] | python | train | 30 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.