repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
openvax/varlens | varlens/read_evidence/pileup.py | Pileup.filter | def filter(self, filters):
'''
Apply filters to the pileup elements, and return a new Pileup with the
filtered elements removed.
Parameters
----------
filters : list of PileupElement -> bool callables
A PileupUp element is retained if all filters return True ... | python | def filter(self, filters):
'''
Apply filters to the pileup elements, and return a new Pileup with the
filtered elements removed.
Parameters
----------
filters : list of PileupElement -> bool callables
A PileupUp element is retained if all filters return True ... | [
"def",
"filter",
"(",
"self",
",",
"filters",
")",
":",
"new_elements",
"=",
"[",
"e",
"for",
"e",
"in",
"self",
".",
"elements",
"if",
"all",
"(",
"function",
"(",
"e",
")",
"for",
"function",
"in",
"filters",
")",
"]",
"return",
"Pileup",
"(",
"s... | Apply filters to the pileup elements, and return a new Pileup with the
filtered elements removed.
Parameters
----------
filters : list of PileupElement -> bool callables
A PileupUp element is retained if all filters return True when
called on it. | [
"Apply",
"filters",
"to",
"the",
"pileup",
"elements",
"and",
"return",
"a",
"new",
"Pileup",
"with",
"the",
"filtered",
"elements",
"removed",
"."
] | 715d3ede5893757b2fcba4117515621bca7b1e5d | https://github.com/openvax/varlens/blob/715d3ede5893757b2fcba4117515621bca7b1e5d/varlens/read_evidence/pileup.py#L72-L86 | train |
BernardFW/bernard | src/bernard/analytics/base.py | new_task | def new_task(func):
"""
Runs the decorated function in a new task
"""
@wraps(func)
async def wrapper(self, *args, **kwargs):
loop = get_event_loop()
loop.create_task(func(self, *args, **kwargs))
return wrapper | python | def new_task(func):
"""
Runs the decorated function in a new task
"""
@wraps(func)
async def wrapper(self, *args, **kwargs):
loop = get_event_loop()
loop.create_task(func(self, *args, **kwargs))
return wrapper | [
"def",
"new_task",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"async",
"def",
"wrapper",
"(",
"self",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"loop",
"=",
"get_event_loop",
"(",
")",
"loop",
".",
"create_task",
"(",
"func",
"("... | Runs the decorated function in a new task | [
"Runs",
"the",
"decorated",
"function",
"in",
"a",
"new",
"task"
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/analytics/base.py#L65-L74 | train |
BernardFW/bernard | src/bernard/analytics/base.py | providers | async def providers():
"""
Iterates over all instances of analytics provider found in configuration
"""
for provider in settings.ANALYTICS_PROVIDERS:
cls: BaseAnalytics = import_class(provider['class'])
yield await cls.instance(*provider['args']) | python | async def providers():
"""
Iterates over all instances of analytics provider found in configuration
"""
for provider in settings.ANALYTICS_PROVIDERS:
cls: BaseAnalytics = import_class(provider['class'])
yield await cls.instance(*provider['args']) | [
"async",
"def",
"providers",
"(",
")",
":",
"for",
"provider",
"in",
"settings",
".",
"ANALYTICS_PROVIDERS",
":",
"cls",
":",
"BaseAnalytics",
"=",
"import_class",
"(",
"provider",
"[",
"'class'",
"]",
")",
"yield",
"await",
"cls",
".",
"instance",
"(",
"*... | Iterates over all instances of analytics provider found in configuration | [
"Iterates",
"over",
"all",
"instances",
"of",
"analytics",
"provider",
"found",
"in",
"configuration"
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/analytics/base.py#L77-L84 | train |
BernardFW/bernard | src/bernard/analytics/base.py | BaseAnalytics.page_view | async def page_view(self,
url: str,
title: str,
user_id: str,
user_lang: str='') -> None:
"""
Track the view of a page
"""
raise NotImplementedError | python | async def page_view(self,
url: str,
title: str,
user_id: str,
user_lang: str='') -> None:
"""
Track the view of a page
"""
raise NotImplementedError | [
"async",
"def",
"page_view",
"(",
"self",
",",
"url",
":",
"str",
",",
"title",
":",
"str",
",",
"user_id",
":",
"str",
",",
"user_lang",
":",
"str",
"=",
"''",
")",
"->",
"None",
":",
"raise",
"NotImplementedError"
] | Track the view of a page | [
"Track",
"the",
"view",
"of",
"a",
"page"
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/analytics/base.py#L37-L46 | train |
BernardFW/bernard | src/bernard/analytics/base.py | BaseAnalytics.hash_user_id | def hash_user_id(self, user_id: str) -> str:
"""
As per the law, anonymize user identifier before sending it.
"""
h = sha256()
h.update(user_id.encode())
return h.hexdigest() | python | def hash_user_id(self, user_id: str) -> str:
"""
As per the law, anonymize user identifier before sending it.
"""
h = sha256()
h.update(user_id.encode())
return h.hexdigest() | [
"def",
"hash_user_id",
"(",
"self",
",",
"user_id",
":",
"str",
")",
"->",
"str",
":",
"h",
"=",
"sha256",
"(",
")",
"h",
".",
"update",
"(",
"user_id",
".",
"encode",
"(",
")",
")",
"return",
"h",
".",
"hexdigest",
"(",
")"
] | As per the law, anonymize user identifier before sending it. | [
"As",
"per",
"the",
"law",
"anonymize",
"user",
"identifier",
"before",
"sending",
"it",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/analytics/base.py#L48-L55 | train |
inveniosoftware-contrib/invenio-workflows | invenio_workflows/models.py | Workflow.delete | def delete(cls, uuid):
"""Delete a workflow."""
to_delete = Workflow.query.get(uuid)
db.session.delete(to_delete) | python | def delete(cls, uuid):
"""Delete a workflow."""
to_delete = Workflow.query.get(uuid)
db.session.delete(to_delete) | [
"def",
"delete",
"(",
"cls",
",",
"uuid",
")",
":",
"to_delete",
"=",
"Workflow",
".",
"query",
".",
"get",
"(",
"uuid",
")",
"db",
".",
"session",
".",
"delete",
"(",
"to_delete",
")"
] | Delete a workflow. | [
"Delete",
"a",
"workflow",
"."
] | 9c09fd29509a3db975ac2aba337e6760d8cfd3c2 | https://github.com/inveniosoftware-contrib/invenio-workflows/blob/9c09fd29509a3db975ac2aba337e6760d8cfd3c2/invenio_workflows/models.py#L96-L99 | train |
inveniosoftware-contrib/invenio-workflows | invenio_workflows/worker_engine.py | run_worker | def run_worker(wname, data, engine_uuid_hex=None, **kwargs):
"""Run a workflow by name with list of data objects.
The list of data can also contain WorkflowObjects.
``**kwargs`` can be used to pass custom arguments to the engine/object.
:param wname: name of workflow to run.
:type wname: str
... | python | def run_worker(wname, data, engine_uuid_hex=None, **kwargs):
"""Run a workflow by name with list of data objects.
The list of data can also contain WorkflowObjects.
``**kwargs`` can be used to pass custom arguments to the engine/object.
:param wname: name of workflow to run.
:type wname: str
... | [
"def",
"run_worker",
"(",
"wname",
",",
"data",
",",
"engine_uuid_hex",
"=",
"None",
",",
"**",
"kwargs",
")",
":",
"if",
"'stop_on_halt'",
"not",
"in",
"kwargs",
":",
"kwargs",
"[",
"'stop_on_halt'",
"]",
"=",
"False",
"if",
"engine_uuid_hex",
":",
"engin... | Run a workflow by name with list of data objects.
The list of data can also contain WorkflowObjects.
``**kwargs`` can be used to pass custom arguments to the engine/object.
:param wname: name of workflow to run.
:type wname: str
:param data: objects to run through the workflow.
:type data: l... | [
"Run",
"a",
"workflow",
"by",
"name",
"with",
"list",
"of",
"data",
"objects",
"."
] | 9c09fd29509a3db975ac2aba337e6760d8cfd3c2 | https://github.com/inveniosoftware-contrib/invenio-workflows/blob/9c09fd29509a3db975ac2aba337e6760d8cfd3c2/invenio_workflows/worker_engine.py#L30-L62 | train |
inveniosoftware-contrib/invenio-workflows | invenio_workflows/worker_engine.py | restart_worker | def restart_worker(uuid, **kwargs):
"""Restart workflow from beginning with given engine UUID and any data.
``**kwargs`` can be used to pass custom arguments to the engine/object such
as ``data``. If ``data`` is not specified then it will load all
initial data for the data objects.
Data can be spe... | python | def restart_worker(uuid, **kwargs):
"""Restart workflow from beginning with given engine UUID and any data.
``**kwargs`` can be used to pass custom arguments to the engine/object such
as ``data``. If ``data`` is not specified then it will load all
initial data for the data objects.
Data can be spe... | [
"def",
"restart_worker",
"(",
"uuid",
",",
"**",
"kwargs",
")",
":",
"if",
"'stop_on_halt'",
"not",
"in",
"kwargs",
":",
"kwargs",
"[",
"'stop_on_halt'",
"]",
"=",
"False",
"engine",
"=",
"WorkflowEngine",
".",
"from_uuid",
"(",
"uuid",
"=",
"uuid",
",",
... | Restart workflow from beginning with given engine UUID and any data.
``**kwargs`` can be used to pass custom arguments to the engine/object such
as ``data``. If ``data`` is not specified then it will load all
initial data for the data objects.
Data can be specified as list of objects or single id of
... | [
"Restart",
"workflow",
"from",
"beginning",
"with",
"given",
"engine",
"UUID",
"and",
"any",
"data",
"."
] | 9c09fd29509a3db975ac2aba337e6760d8cfd3c2 | https://github.com/inveniosoftware-contrib/invenio-workflows/blob/9c09fd29509a3db975ac2aba337e6760d8cfd3c2/invenio_workflows/worker_engine.py#L65-L95 | train |
inveniosoftware-contrib/invenio-workflows | invenio_workflows/worker_engine.py | get_workflow_object_instances | def get_workflow_object_instances(data, engine):
"""Analyze data and create corresponding WorkflowObjects.
Wrap each item in the given list of data objects into WorkflowObject
instances - creating appropriate status of objects in the database and
returning a list of these objects.
This process is ... | python | def get_workflow_object_instances(data, engine):
"""Analyze data and create corresponding WorkflowObjects.
Wrap each item in the given list of data objects into WorkflowObject
instances - creating appropriate status of objects in the database and
returning a list of these objects.
This process is ... | [
"def",
"get_workflow_object_instances",
"(",
"data",
",",
"engine",
")",
":",
"workflow_objects",
"=",
"[",
"]",
"data_type",
"=",
"engine",
".",
"get_default_data_type",
"(",
")",
"for",
"data_object",
"in",
"data",
":",
"if",
"isinstance",
"(",
"data_object",
... | Analyze data and create corresponding WorkflowObjects.
Wrap each item in the given list of data objects into WorkflowObject
instances - creating appropriate status of objects in the database and
returning a list of these objects.
This process is necessary to save an initial status of the data before
... | [
"Analyze",
"data",
"and",
"create",
"corresponding",
"WorkflowObjects",
"."
] | 9c09fd29509a3db975ac2aba337e6760d8cfd3c2 | https://github.com/inveniosoftware-contrib/invenio-workflows/blob/9c09fd29509a3db975ac2aba337e6760d8cfd3c2/invenio_workflows/worker_engine.py#L136-L184 | train |
inveniosoftware-contrib/invenio-workflows | invenio_workflows/worker_engine.py | create_data_object_from_data | def create_data_object_from_data(data_object, engine, data_type):
"""Create a new WorkflowObject from given data and return it.
Returns a data object wrapped around data_object given.
:param data_object: object containing the data
:type data_object: object
:param engine: Instance of Workflow that... | python | def create_data_object_from_data(data_object, engine, data_type):
"""Create a new WorkflowObject from given data and return it.
Returns a data object wrapped around data_object given.
:param data_object: object containing the data
:type data_object: object
:param engine: Instance of Workflow that... | [
"def",
"create_data_object_from_data",
"(",
"data_object",
",",
"engine",
",",
"data_type",
")",
":",
"return",
"workflow_object_class",
".",
"create",
"(",
"data",
"=",
"data_object",
",",
"id_workflow",
"=",
"engine",
".",
"uuid",
",",
"status",
"=",
"workflow... | Create a new WorkflowObject from given data and return it.
Returns a data object wrapped around data_object given.
:param data_object: object containing the data
:type data_object: object
:param engine: Instance of Workflow that is currently running.
:type engine: py:class:`.engine.WorkflowEngine... | [
"Create",
"a",
"new",
"WorkflowObject",
"from",
"given",
"data",
"and",
"return",
"it",
"."
] | 9c09fd29509a3db975ac2aba337e6760d8cfd3c2 | https://github.com/inveniosoftware-contrib/invenio-workflows/blob/9c09fd29509a3db975ac2aba337e6760d8cfd3c2/invenio_workflows/worker_engine.py#L187-L210 | train |
cloudmesh-cmd3/cmd3 | cmd3/plugins/rst.py | rst._print_rst | def _print_rst(self, what):
"""
prints the rst page of the command what
:param what: the command
:type what: string
"""
print
print "Command - %s::" % what
exec ("h = self.do_%s.__doc__" % what)
# noinspection PyUnboundLocalVariable
h =... | python | def _print_rst(self, what):
"""
prints the rst page of the command what
:param what: the command
:type what: string
"""
print
print "Command - %s::" % what
exec ("h = self.do_%s.__doc__" % what)
# noinspection PyUnboundLocalVariable
h =... | [
"def",
"_print_rst",
"(",
"self",
",",
"what",
")",
":",
"print",
"print",
"\"Command - %s::\"",
"%",
"what",
"exec",
"(",
"\"h = self.do_%s.__doc__\"",
"%",
"what",
")",
"h",
"=",
"textwrap",
".",
"dedent",
"(",
"h",
")",
".",
"replace",
"(",
"\"::\\n\\n\... | prints the rst page of the command what
:param what: the command
:type what: string | [
"prints",
"the",
"rst",
"page",
"of",
"the",
"command",
"what"
] | 92e33c96032fd3921f159198a0e57917c4dc34ed | https://github.com/cloudmesh-cmd3/cmd3/blob/92e33c96032fd3921f159198a0e57917c4dc34ed/cmd3/plugins/rst.py#L11-L27 | train |
garenchan/policy | policy/enforcer.py | Rules.load_json | def load_json(cls, data, default_rule=None, raise_error=False):
"""Allow loading of JSON rule data."""
rules = {k: _parser.parse_rule(v, raise_error)
for k, v in json.loads(data).items()}
return cls(rules, default_rule) | python | def load_json(cls, data, default_rule=None, raise_error=False):
"""Allow loading of JSON rule data."""
rules = {k: _parser.parse_rule(v, raise_error)
for k, v in json.loads(data).items()}
return cls(rules, default_rule) | [
"def",
"load_json",
"(",
"cls",
",",
"data",
",",
"default_rule",
"=",
"None",
",",
"raise_error",
"=",
"False",
")",
":",
"rules",
"=",
"{",
"k",
":",
"_parser",
".",
"parse_rule",
"(",
"v",
",",
"raise_error",
")",
"for",
"k",
",",
"v",
"in",
"js... | Allow loading of JSON rule data. | [
"Allow",
"loading",
"of",
"JSON",
"rule",
"data",
"."
] | 7709ae5f371146f8c90380d0877a5e59d731f644 | https://github.com/garenchan/policy/blob/7709ae5f371146f8c90380d0877a5e59d731f644/policy/enforcer.py#L30-L36 | train |
garenchan/policy | policy/enforcer.py | Rules.from_dict | def from_dict(cls, rules_dict: dict, default_rule=None, raise_error=False):
"""Allow loading of rule data from a dictionary."""
# Parse the rules stored in the dictionary
rules = {k: _parser.parse_rule(v, raise_error)
for k, v in rules_dict.items()}
return cls(rules, d... | python | def from_dict(cls, rules_dict: dict, default_rule=None, raise_error=False):
"""Allow loading of rule data from a dictionary."""
# Parse the rules stored in the dictionary
rules = {k: _parser.parse_rule(v, raise_error)
for k, v in rules_dict.items()}
return cls(rules, d... | [
"def",
"from_dict",
"(",
"cls",
",",
"rules_dict",
":",
"dict",
",",
"default_rule",
"=",
"None",
",",
"raise_error",
"=",
"False",
")",
":",
"rules",
"=",
"{",
"k",
":",
"_parser",
".",
"parse_rule",
"(",
"v",
",",
"raise_error",
")",
"for",
"k",
",... | Allow loading of rule data from a dictionary. | [
"Allow",
"loading",
"of",
"rule",
"data",
"from",
"a",
"dictionary",
"."
] | 7709ae5f371146f8c90380d0877a5e59d731f644 | https://github.com/garenchan/policy/blob/7709ae5f371146f8c90380d0877a5e59d731f644/policy/enforcer.py#L39-L46 | train |
garenchan/policy | policy/enforcer.py | Enforcer._set_rules | def _set_rules(self, rules: dict, overwrite=True):
"""Created a new Rules object based on the provided dict of rules."""
if not isinstance(rules, dict):
raise TypeError('rules must be an instance of dict or Rules,'
'got %r instead' % type(rules))
if over... | python | def _set_rules(self, rules: dict, overwrite=True):
"""Created a new Rules object based on the provided dict of rules."""
if not isinstance(rules, dict):
raise TypeError('rules must be an instance of dict or Rules,'
'got %r instead' % type(rules))
if over... | [
"def",
"_set_rules",
"(",
"self",
",",
"rules",
":",
"dict",
",",
"overwrite",
"=",
"True",
")",
":",
"if",
"not",
"isinstance",
"(",
"rules",
",",
"dict",
")",
":",
"raise",
"TypeError",
"(",
"'rules must be an instance of dict or Rules,'",
"'got %r instead'",
... | Created a new Rules object based on the provided dict of rules. | [
"Created",
"a",
"new",
"Rules",
"object",
"based",
"on",
"the",
"provided",
"dict",
"of",
"rules",
"."
] | 7709ae5f371146f8c90380d0877a5e59d731f644 | https://github.com/garenchan/policy/blob/7709ae5f371146f8c90380d0877a5e59d731f644/policy/enforcer.py#L103-L113 | train |
garenchan/policy | policy/enforcer.py | Enforcer.load_rules | def load_rules(self, force_reload=False, overwrite=True):
"""Load rules from policy file or cache."""
# double-checked locking
if self.load_once and self._policy_loaded:
return
with self._load_lock:
if self.load_once and self._policy_loaded:
retur... | python | def load_rules(self, force_reload=False, overwrite=True):
"""Load rules from policy file or cache."""
# double-checked locking
if self.load_once and self._policy_loaded:
return
with self._load_lock:
if self.load_once and self._policy_loaded:
retur... | [
"def",
"load_rules",
"(",
"self",
",",
"force_reload",
"=",
"False",
",",
"overwrite",
"=",
"True",
")",
":",
"if",
"self",
".",
"load_once",
"and",
"self",
".",
"_policy_loaded",
":",
"return",
"with",
"self",
".",
"_load_lock",
":",
"if",
"self",
".",
... | Load rules from policy file or cache. | [
"Load",
"rules",
"from",
"policy",
"file",
"or",
"cache",
"."
] | 7709ae5f371146f8c90380d0877a5e59d731f644 | https://github.com/garenchan/policy/blob/7709ae5f371146f8c90380d0877a5e59d731f644/policy/enforcer.py#L115-L131 | train |
garenchan/policy | policy/enforcer.py | Enforcer.enforce | def enforce(self, rule, target, creds, exc=None, *args, **kwargs):
"""Checks authorization of a rule against the target and credentials."""
self.load_rules()
if isinstance(rule, checks.BaseCheck):
result = rule(target, creds, self, rule)
elif not self.rules:
# N... | python | def enforce(self, rule, target, creds, exc=None, *args, **kwargs):
"""Checks authorization of a rule against the target and credentials."""
self.load_rules()
if isinstance(rule, checks.BaseCheck):
result = rule(target, creds, self, rule)
elif not self.rules:
# N... | [
"def",
"enforce",
"(",
"self",
",",
"rule",
",",
"target",
",",
"creds",
",",
"exc",
"=",
"None",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"self",
".",
"load_rules",
"(",
")",
"if",
"isinstance",
"(",
"rule",
",",
"checks",
".",
"BaseCheck"... | Checks authorization of a rule against the target and credentials. | [
"Checks",
"authorization",
"of",
"a",
"rule",
"against",
"the",
"target",
"and",
"credentials",
"."
] | 7709ae5f371146f8c90380d0877a5e59d731f644 | https://github.com/garenchan/policy/blob/7709ae5f371146f8c90380d0877a5e59d731f644/policy/enforcer.py#L133-L158 | train |
seung-lab/EMAnnotationSchemas | emannotationschemas/utils.py | get_flattened_bsp_keys_from_schema | def get_flattened_bsp_keys_from_schema(schema):
""" Returns the flattened keys of BoundSpatialPoints in a schema
:param schema: schema
:return: list
"""
keys = []
for key in schema.declared_fields.keys():
field = schema.declared_fields[key]
if isinstance(field, mm.fields.Neste... | python | def get_flattened_bsp_keys_from_schema(schema):
""" Returns the flattened keys of BoundSpatialPoints in a schema
:param schema: schema
:return: list
"""
keys = []
for key in schema.declared_fields.keys():
field = schema.declared_fields[key]
if isinstance(field, mm.fields.Neste... | [
"def",
"get_flattened_bsp_keys_from_schema",
"(",
"schema",
")",
":",
"keys",
"=",
"[",
"]",
"for",
"key",
"in",
"schema",
".",
"declared_fields",
".",
"keys",
"(",
")",
":",
"field",
"=",
"schema",
".",
"declared_fields",
"[",
"key",
"]",
"if",
"isinstanc... | Returns the flattened keys of BoundSpatialPoints in a schema
:param schema: schema
:return: list | [
"Returns",
"the",
"flattened",
"keys",
"of",
"BoundSpatialPoints",
"in",
"a",
"schema"
] | ca81eff0f449bd7eb0392e0982db8f3636446a9e | https://github.com/seung-lab/EMAnnotationSchemas/blob/ca81eff0f449bd7eb0392e0982db8f3636446a9e/emannotationschemas/utils.py#L14-L29 | train |
BernardFW/bernard | src/bernard/engine/triggers.py | SharedTrigger.lock | def lock(self) -> asyncio.Lock:
"""
Return and generate if required the lock for this request.
"""
if self.lock_key not in self.request.custom_content:
self.request.custom_content[self.lock_key] = asyncio.Lock()
return self.request.custom_content[self.lock_key] | python | def lock(self) -> asyncio.Lock:
"""
Return and generate if required the lock for this request.
"""
if self.lock_key not in self.request.custom_content:
self.request.custom_content[self.lock_key] = asyncio.Lock()
return self.request.custom_content[self.lock_key] | [
"def",
"lock",
"(",
"self",
")",
"->",
"asyncio",
".",
"Lock",
":",
"if",
"self",
".",
"lock_key",
"not",
"in",
"self",
".",
"request",
".",
"custom_content",
":",
"self",
".",
"request",
".",
"custom_content",
"[",
"self",
".",
"lock_key",
"]",
"=",
... | Return and generate if required the lock for this request. | [
"Return",
"and",
"generate",
"if",
"required",
"the",
"lock",
"for",
"this",
"request",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/engine/triggers.py#L94-L102 | train |
BernardFW/bernard | src/bernard/engine/triggers.py | SharedTrigger.get_value | async def get_value(self):
"""
Get the value from the API. Make sure to use a lock in order not to
fetch the value twice at the same time.
"""
cc = self.request.custom_content
async with self.lock:
if self.content_key not in cc:
cc[self.conte... | python | async def get_value(self):
"""
Get the value from the API. Make sure to use a lock in order not to
fetch the value twice at the same time.
"""
cc = self.request.custom_content
async with self.lock:
if self.content_key not in cc:
cc[self.conte... | [
"async",
"def",
"get_value",
"(",
"self",
")",
":",
"cc",
"=",
"self",
".",
"request",
".",
"custom_content",
"async",
"with",
"self",
".",
"lock",
":",
"if",
"self",
".",
"content_key",
"not",
"in",
"cc",
":",
"cc",
"[",
"self",
".",
"content_key",
... | Get the value from the API. Make sure to use a lock in order not to
fetch the value twice at the same time. | [
"Get",
"the",
"value",
"from",
"the",
"API",
".",
"Make",
"sure",
"to",
"use",
"a",
"lock",
"in",
"order",
"not",
"to",
"fetch",
"the",
"value",
"twice",
"at",
"the",
"same",
"time",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/engine/triggers.py#L119-L131 | train |
BernardFW/bernard | src/bernard/engine/triggers.py | Text.rank | async def rank(self) -> Optional[float]:
"""
If there is a text layer inside the request, try to find a matching
text in the specified intent.
"""
if not self.request.has_layer(l.RawText):
return
tl = self.request.get_layer(l.RawText)
matcher = Match... | python | async def rank(self) -> Optional[float]:
"""
If there is a text layer inside the request, try to find a matching
text in the specified intent.
"""
if not self.request.has_layer(l.RawText):
return
tl = self.request.get_layer(l.RawText)
matcher = Match... | [
"async",
"def",
"rank",
"(",
"self",
")",
"->",
"Optional",
"[",
"float",
"]",
":",
"if",
"not",
"self",
".",
"request",
".",
"has_layer",
"(",
"l",
".",
"RawText",
")",
":",
"return",
"tl",
"=",
"self",
".",
"request",
".",
"get_layer",
"(",
"l",
... | If there is a text layer inside the request, try to find a matching
text in the specified intent. | [
"If",
"there",
"is",
"a",
"text",
"layer",
"inside",
"the",
"request",
"try",
"to",
"find",
"a",
"matching",
"text",
"in",
"the",
"specified",
"intent",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/engine/triggers.py#L163-L178 | train |
BernardFW/bernard | src/bernard/engine/triggers.py | Choice._rank_qr | def _rank_qr(self, choices):
"""
Look for the QuickReply layer's slug into available choices.
"""
from bernard.platforms.facebook import layers as fbl
try:
qr = self.request.get_layer(fbl.QuickReply)
self.chosen = choices[qr.slug]
self.slug = ... | python | def _rank_qr(self, choices):
"""
Look for the QuickReply layer's slug into available choices.
"""
from bernard.platforms.facebook import layers as fbl
try:
qr = self.request.get_layer(fbl.QuickReply)
self.chosen = choices[qr.slug]
self.slug = ... | [
"def",
"_rank_qr",
"(",
"self",
",",
"choices",
")",
":",
"from",
"bernard",
".",
"platforms",
".",
"facebook",
"import",
"layers",
"as",
"fbl",
"try",
":",
"qr",
"=",
"self",
".",
"request",
".",
"get_layer",
"(",
"fbl",
".",
"QuickReply",
")",
"self"... | Look for the QuickReply layer's slug into available choices. | [
"Look",
"for",
"the",
"QuickReply",
"layer",
"s",
"slug",
"into",
"available",
"choices",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/engine/triggers.py#L200-L214 | train |
BernardFW/bernard | src/bernard/engine/triggers.py | Choice._rank_text | async def _rank_text(self, choices):
"""
Try to match the TextLayer with choice's intents.
"""
tl = self.request.get_layer(l.RawText)
best = 0.0
for slug, params in choices.items():
strings = []
if params['intent']:
intent = geta... | python | async def _rank_text(self, choices):
"""
Try to match the TextLayer with choice's intents.
"""
tl = self.request.get_layer(l.RawText)
best = 0.0
for slug, params in choices.items():
strings = []
if params['intent']:
intent = geta... | [
"async",
"def",
"_rank_text",
"(",
"self",
",",
"choices",
")",
":",
"tl",
"=",
"self",
".",
"request",
".",
"get_layer",
"(",
"l",
".",
"RawText",
")",
"best",
"=",
"0.0",
"for",
"slug",
",",
"params",
"in",
"choices",
".",
"items",
"(",
")",
":",... | Try to match the TextLayer with choice's intents. | [
"Try",
"to",
"match",
"the",
"TextLayer",
"with",
"choice",
"s",
"intents",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/engine/triggers.py#L216-L243 | train |
ioos/cc-plugin-ncei | cc_plugin_ncei/ncei_timeseries.py | NCEITimeSeriesOrthogonal2_0.check_recommended_attributes | def check_recommended_attributes(self, dataset):
'''
Feature type specific check of global recommended attributes.
:param netCDF4.Dataset dataset: An open netCDF dataset
'''
results = []
recommended_ctx = TestCtx(BaseCheck.MEDIUM, 'Recommended global attributes')
... | python | def check_recommended_attributes(self, dataset):
'''
Feature type specific check of global recommended attributes.
:param netCDF4.Dataset dataset: An open netCDF dataset
'''
results = []
recommended_ctx = TestCtx(BaseCheck.MEDIUM, 'Recommended global attributes')
... | [
"def",
"check_recommended_attributes",
"(",
"self",
",",
"dataset",
")",
":",
"results",
"=",
"[",
"]",
"recommended_ctx",
"=",
"TestCtx",
"(",
"BaseCheck",
".",
"MEDIUM",
",",
"'Recommended global attributes'",
")",
"for",
"attr",
"in",
"[",
"'time_coverage_durat... | Feature type specific check of global recommended attributes.
:param netCDF4.Dataset dataset: An open netCDF dataset | [
"Feature",
"type",
"specific",
"check",
"of",
"global",
"recommended",
"attributes",
"."
] | 963fefd7fa43afd32657ac4c36aad4ddb4c25acf | https://github.com/ioos/cc-plugin-ncei/blob/963fefd7fa43afd32657ac4c36aad4ddb4c25acf/cc_plugin_ncei/ncei_timeseries.py#L154-L171 | train |
ioos/cc-plugin-ncei | cc_plugin_ncei/ncei_timeseries.py | NCEITimeSeriesIncompleteBase.check_dimensions | def check_dimensions(self, dataset):
'''
Checks that the feature types of this dataset are consitent with a time series incomplete dataset
:param netCDF4.Dataset dataset: An open netCDF dataset
'''
required_ctx = TestCtx(BaseCheck.HIGH, 'All geophysical variables are time-series... | python | def check_dimensions(self, dataset):
'''
Checks that the feature types of this dataset are consitent with a time series incomplete dataset
:param netCDF4.Dataset dataset: An open netCDF dataset
'''
required_ctx = TestCtx(BaseCheck.HIGH, 'All geophysical variables are time-series... | [
"def",
"check_dimensions",
"(",
"self",
",",
"dataset",
")",
":",
"required_ctx",
"=",
"TestCtx",
"(",
"BaseCheck",
".",
"HIGH",
",",
"'All geophysical variables are time-series incomplete feature types'",
")",
"message",
"=",
"'{} must be a valid timeseries feature type. It ... | Checks that the feature types of this dataset are consitent with a time series incomplete dataset
:param netCDF4.Dataset dataset: An open netCDF dataset | [
"Checks",
"that",
"the",
"feature",
"types",
"of",
"this",
"dataset",
"are",
"consitent",
"with",
"a",
"time",
"series",
"incomplete",
"dataset"
] | 963fefd7fa43afd32657ac4c36aad4ddb4c25acf | https://github.com/ioos/cc-plugin-ncei/blob/963fefd7fa43afd32657ac4c36aad4ddb4c25acf/cc_plugin_ncei/ncei_timeseries.py#L181-L196 | train |
garenchan/policy | policy/_cache.py | read_file | def read_file(filename: str, force_reload=False):
"""Read a file if it has been modified.
:param filename: File name which want to be read from.
:param force_reload: Whether to reload the file.
:returns: A tuple with a boolean specifying if the data is fresh or not.
"""
if force_reload:
... | python | def read_file(filename: str, force_reload=False):
"""Read a file if it has been modified.
:param filename: File name which want to be read from.
:param force_reload: Whether to reload the file.
:returns: A tuple with a boolean specifying if the data is fresh or not.
"""
if force_reload:
... | [
"def",
"read_file",
"(",
"filename",
":",
"str",
",",
"force_reload",
"=",
"False",
")",
":",
"if",
"force_reload",
":",
"_delete_cached_file",
"(",
"filename",
")",
"reloaded",
"=",
"False",
"mtime",
"=",
"os",
".",
"path",
".",
"getmtime",
"(",
"filename... | Read a file if it has been modified.
:param filename: File name which want to be read from.
:param force_reload: Whether to reload the file.
:returns: A tuple with a boolean specifying if the data is fresh or not. | [
"Read",
"a",
"file",
"if",
"it",
"has",
"been",
"modified",
"."
] | 7709ae5f371146f8c90380d0877a5e59d731f644 | https://github.com/garenchan/policy/blob/7709ae5f371146f8c90380d0877a5e59d731f644/policy/_cache.py#L19-L41 | train |
COALAIP/pycoalaip | coalaip/model_validators.py | use_model_attr | def use_model_attr(attr):
"""Use the validator set on a separate attribute on the class."""
def use_model_validator(instance, attribute, value):
getattr(instance, attr)(instance, attribute, value)
return use_model_validator | python | def use_model_attr(attr):
"""Use the validator set on a separate attribute on the class."""
def use_model_validator(instance, attribute, value):
getattr(instance, attr)(instance, attribute, value)
return use_model_validator | [
"def",
"use_model_attr",
"(",
"attr",
")",
":",
"def",
"use_model_validator",
"(",
"instance",
",",
"attribute",
",",
"value",
")",
":",
"getattr",
"(",
"instance",
",",
"attr",
")",
"(",
"instance",
",",
"attribute",
",",
"value",
")",
"return",
"use_mode... | Use the validator set on a separate attribute on the class. | [
"Use",
"the",
"validator",
"set",
"on",
"a",
"separate",
"attribute",
"on",
"the",
"class",
"."
] | cecc8f6ff4733f0525fafcee63647753e832f0be | https://github.com/COALAIP/pycoalaip/blob/cecc8f6ff4733f0525fafcee63647753e832f0be/coalaip/model_validators.py#L13-L18 | train |
COALAIP/pycoalaip | coalaip/model_validators.py | is_creation_model | def is_creation_model(instance, attribute, value):
"""Must include at least a ``name`` key."""
creation_name = value.get('name')
if not isinstance(creation_name, str):
instance_name = instance.__class__.__name__
err_str = ("'name' must be given as a string in the '{attr}' "
... | python | def is_creation_model(instance, attribute, value):
"""Must include at least a ``name`` key."""
creation_name = value.get('name')
if not isinstance(creation_name, str):
instance_name = instance.__class__.__name__
err_str = ("'name' must be given as a string in the '{attr}' "
... | [
"def",
"is_creation_model",
"(",
"instance",
",",
"attribute",
",",
"value",
")",
":",
"creation_name",
"=",
"value",
".",
"get",
"(",
"'name'",
")",
"if",
"not",
"isinstance",
"(",
"creation_name",
",",
"str",
")",
":",
"instance_name",
"=",
"instance",
"... | Must include at least a ``name`` key. | [
"Must",
"include",
"at",
"least",
"a",
"name",
"key",
"."
] | cecc8f6ff4733f0525fafcee63647753e832f0be | https://github.com/COALAIP/pycoalaip/blob/cecc8f6ff4733f0525fafcee63647753e832f0be/coalaip/model_validators.py#L45-L56 | train |
COALAIP/pycoalaip | coalaip/model_validators.py | is_manifestation_model | def is_manifestation_model(instance, attribute, value):
"""Must include a ``manifestationOfWork`` key."""
instance_name = instance.__class__.__name__
is_creation_model(instance, attribute, value)
manifestation_of = value.get('manifestationOfWork')
if not isinstance(manifestation_of, str):
... | python | def is_manifestation_model(instance, attribute, value):
"""Must include a ``manifestationOfWork`` key."""
instance_name = instance.__class__.__name__
is_creation_model(instance, attribute, value)
manifestation_of = value.get('manifestationOfWork')
if not isinstance(manifestation_of, str):
... | [
"def",
"is_manifestation_model",
"(",
"instance",
",",
"attribute",
",",
"value",
")",
":",
"instance_name",
"=",
"instance",
".",
"__class__",
".",
"__name__",
"is_creation_model",
"(",
"instance",
",",
"attribute",
",",
"value",
")",
"manifestation_of",
"=",
"... | Must include a ``manifestationOfWork`` key. | [
"Must",
"include",
"a",
"manifestationOfWork",
"key",
"."
] | cecc8f6ff4733f0525fafcee63647753e832f0be | https://github.com/COALAIP/pycoalaip/blob/cecc8f6ff4733f0525fafcee63647753e832f0be/coalaip/model_validators.py#L68-L81 | train |
klmitch/turnstile | turnstile/tools.py | add_preprocessor | def add_preprocessor(preproc):
"""
Define a preprocessor to run after the arguments are parsed and
before the function is executed, when running in console script
mode.
:param preproc: The callable, which will be passed the Namespace
object generated by argparse.
"""
de... | python | def add_preprocessor(preproc):
"""
Define a preprocessor to run after the arguments are parsed and
before the function is executed, when running in console script
mode.
:param preproc: The callable, which will be passed the Namespace
object generated by argparse.
"""
de... | [
"def",
"add_preprocessor",
"(",
"preproc",
")",
":",
"def",
"decorator",
"(",
"func",
")",
":",
"func",
"=",
"ScriptAdaptor",
".",
"_wrap",
"(",
"func",
")",
"func",
".",
"_add_preprocessor",
"(",
"preproc",
")",
"return",
"func",
"return",
"decorator"
] | Define a preprocessor to run after the arguments are parsed and
before the function is executed, when running in console script
mode.
:param preproc: The callable, which will be passed the Namespace
object generated by argparse. | [
"Define",
"a",
"preprocessor",
"to",
"run",
"after",
"the",
"arguments",
"are",
"parsed",
"and",
"before",
"the",
"function",
"is",
"executed",
"when",
"running",
"in",
"console",
"script",
"mode",
"."
] | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/tools.py#L255-L269 | train |
klmitch/turnstile | turnstile/tools.py | add_postprocessor | def add_postprocessor(postproc):
"""
Define a postprocessor to run after the function is executed, when
running in console script mode.
:param postproc: The callable, which will be passed the Namespace
object generated by argparse and the return
result of the f... | python | def add_postprocessor(postproc):
"""
Define a postprocessor to run after the function is executed, when
running in console script mode.
:param postproc: The callable, which will be passed the Namespace
object generated by argparse and the return
result of the f... | [
"def",
"add_postprocessor",
"(",
"postproc",
")",
":",
"def",
"decorator",
"(",
"func",
")",
":",
"func",
"=",
"ScriptAdaptor",
".",
"_wrap",
"(",
"func",
")",
"func",
".",
"_add_postprocessor",
"(",
"postproc",
")",
"return",
"func",
"return",
"decorator"
] | Define a postprocessor to run after the function is executed, when
running in console script mode.
:param postproc: The callable, which will be passed the Namespace
object generated by argparse and the return
result of the function. The return result of the
... | [
"Define",
"a",
"postprocessor",
"to",
"run",
"after",
"the",
"function",
"is",
"executed",
"when",
"running",
"in",
"console",
"script",
"mode",
"."
] | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/tools.py#L272-L289 | train |
klmitch/turnstile | turnstile/tools.py | _setup_logging | def _setup_logging(args):
"""
Set up logging for the script, based on the configuration
specified by the 'logging' attribute of the command line
arguments.
:param args: A Namespace object containing a 'logging' attribute
specifying the name of a logging configuration file
... | python | def _setup_logging(args):
"""
Set up logging for the script, based on the configuration
specified by the 'logging' attribute of the command line
arguments.
:param args: A Namespace object containing a 'logging' attribute
specifying the name of a logging configuration file
... | [
"def",
"_setup_logging",
"(",
"args",
")",
":",
"log_conf",
"=",
"getattr",
"(",
"args",
",",
"'logging'",
",",
"None",
")",
"if",
"log_conf",
":",
"logging",
".",
"config",
".",
"fileConfig",
"(",
"log_conf",
")",
"else",
":",
"logging",
".",
"basicConf... | Set up logging for the script, based on the configuration
specified by the 'logging' attribute of the command line
arguments.
:param args: A Namespace object containing a 'logging' attribute
specifying the name of a logging configuration file
to use. If not present or not... | [
"Set",
"up",
"logging",
"for",
"the",
"script",
"based",
"on",
"the",
"configuration",
"specified",
"by",
"the",
"logging",
"attribute",
"of",
"the",
"command",
"line",
"arguments",
"."
] | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/tools.py#L292-L308 | train |
klmitch/turnstile | turnstile/tools.py | setup_limits | def setup_limits(conf_file, limits_file, do_reload=True,
dry_run=False, debug=False):
"""
Set up or update limits in the Redis database.
:param conf_file: Name of the configuration file, for connecting
to the Redis database.
:param limits_file: Name of the XML fil... | python | def setup_limits(conf_file, limits_file, do_reload=True,
dry_run=False, debug=False):
"""
Set up or update limits in the Redis database.
:param conf_file: Name of the configuration file, for connecting
to the Redis database.
:param limits_file: Name of the XML fil... | [
"def",
"setup_limits",
"(",
"conf_file",
",",
"limits_file",
",",
"do_reload",
"=",
"True",
",",
"dry_run",
"=",
"False",
",",
"debug",
"=",
"False",
")",
":",
"if",
"dry_run",
":",
"debug",
"=",
"True",
"conf",
"=",
"config",
".",
"Config",
"(",
"conf... | Set up or update limits in the Redis database.
:param conf_file: Name of the configuration file, for connecting
to the Redis database.
:param limits_file: Name of the XML file describing the limits to
configure.
:param do_reload: Controls reloading behavior. I... | [
"Set",
"up",
"or",
"update",
"limits",
"in",
"the",
"Redis",
"database",
"."
] | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/tools.py#L473-L555 | train |
klmitch/turnstile | turnstile/tools.py | make_limit_node | def make_limit_node(root, limit):
"""
Given a Limit object, generate an XML node.
:param root: The root node of the XML tree being built.
:param limit: The Limit object to serialize to XML.
"""
# Build the base limit node
limit_node = etree.SubElement(root, 'limit',
... | python | def make_limit_node(root, limit):
"""
Given a Limit object, generate an XML node.
:param root: The root node of the XML tree being built.
:param limit: The Limit object to serialize to XML.
"""
# Build the base limit node
limit_node = etree.SubElement(root, 'limit',
... | [
"def",
"make_limit_node",
"(",
"root",
",",
"limit",
")",
":",
"limit_node",
"=",
"etree",
".",
"SubElement",
"(",
"root",
",",
"'limit'",
",",
"{",
"'class'",
":",
"limit",
".",
"_limit_full_name",
"}",
")",
"for",
"attr",
"in",
"sorted",
"(",
"limit",
... | Given a Limit object, generate an XML node.
:param root: The root node of the XML tree being built.
:param limit: The Limit object to serialize to XML. | [
"Given",
"a",
"Limit",
"object",
"generate",
"an",
"XML",
"node",
"."
] | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/tools.py#L562-L602 | train |
klmitch/turnstile | turnstile/tools.py | dump_limits | def dump_limits(conf_file, limits_file, debug=False):
"""
Dump the current limits from the Redis database.
:param conf_file: Name of the configuration file, for connecting
to the Redis database.
:param limits_file: Name of the XML file that the limits will be
... | python | def dump_limits(conf_file, limits_file, debug=False):
"""
Dump the current limits from the Redis database.
:param conf_file: Name of the configuration file, for connecting
to the Redis database.
:param limits_file: Name of the XML file that the limits will be
... | [
"def",
"dump_limits",
"(",
"conf_file",
",",
"limits_file",
",",
"debug",
"=",
"False",
")",
":",
"conf",
"=",
"config",
".",
"Config",
"(",
"conf_file",
"=",
"conf_file",
")",
"db",
"=",
"conf",
".",
"get_database",
"(",
")",
"limits_key",
"=",
"conf",
... | Dump the current limits from the Redis database.
:param conf_file: Name of the configuration file, for connecting
to the Redis database.
:param limits_file: Name of the XML file that the limits will be
dumped to. Use '-' to dump to stdout.
:param debug: If Tru... | [
"Dump",
"the",
"current",
"limits",
"from",
"the",
"Redis",
"database",
"."
] | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/tools.py#L617-L652 | train |
klmitch/turnstile | turnstile/tools.py | remote_daemon | def remote_daemon(conf_file):
"""
Run the external control daemon.
:param conf_file: Name of the configuration file.
"""
eventlet.monkey_patch()
conf = config.Config(conf_file=conf_file)
daemon = remote.RemoteControlDaemon(None, conf)
daemon.serve() | python | def remote_daemon(conf_file):
"""
Run the external control daemon.
:param conf_file: Name of the configuration file.
"""
eventlet.monkey_patch()
conf = config.Config(conf_file=conf_file)
daemon = remote.RemoteControlDaemon(None, conf)
daemon.serve() | [
"def",
"remote_daemon",
"(",
"conf_file",
")",
":",
"eventlet",
".",
"monkey_patch",
"(",
")",
"conf",
"=",
"config",
".",
"Config",
"(",
"conf_file",
"=",
"conf_file",
")",
"daemon",
"=",
"remote",
".",
"RemoteControlDaemon",
"(",
"None",
",",
"conf",
")"... | Run the external control daemon.
:param conf_file: Name of the configuration file. | [
"Run",
"the",
"external",
"control",
"daemon",
"."
] | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/tools.py#L673-L683 | train |
klmitch/turnstile | turnstile/tools.py | turnstile_command | def turnstile_command(conf_file, command, arguments=[], channel=None,
debug=False):
"""
Issue a command to all running control daemons.
:param conf_file: Name of the configuration file.
:param command: The command to execute. Note that 'ping' is
handled specia... | python | def turnstile_command(conf_file, command, arguments=[], channel=None,
debug=False):
"""
Issue a command to all running control daemons.
:param conf_file: Name of the configuration file.
:param command: The command to execute. Note that 'ping' is
handled specia... | [
"def",
"turnstile_command",
"(",
"conf_file",
",",
"command",
",",
"arguments",
"=",
"[",
"]",
",",
"channel",
"=",
"None",
",",
"debug",
"=",
"False",
")",
":",
"conf",
"=",
"config",
".",
"Config",
"(",
"conf_file",
"=",
"conf_file",
")",
"db",
"=",
... | Issue a command to all running control daemons.
:param conf_file: Name of the configuration file.
:param command: The command to execute. Note that 'ping' is
handled specially; in particular, the "channel"
parameter is implied. (A random value will be
... | [
"Issue",
"a",
"command",
"to",
"all",
"running",
"control",
"daemons",
"."
] | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/tools.py#L712-L803 | train |
klmitch/turnstile | turnstile/tools.py | compactor_daemon | def compactor_daemon(conf_file):
"""
Run the compactor daemon.
:param conf_file: Name of the configuration file.
"""
eventlet.monkey_patch()
conf = config.Config(conf_file=conf_file)
compactor.compactor(conf) | python | def compactor_daemon(conf_file):
"""
Run the compactor daemon.
:param conf_file: Name of the configuration file.
"""
eventlet.monkey_patch()
conf = config.Config(conf_file=conf_file)
compactor.compactor(conf) | [
"def",
"compactor_daemon",
"(",
"conf_file",
")",
":",
"eventlet",
".",
"monkey_patch",
"(",
")",
"conf",
"=",
"config",
".",
"Config",
"(",
"conf_file",
"=",
"conf_file",
")",
"compactor",
".",
"compactor",
"(",
"conf",
")"
] | Run the compactor daemon.
:param conf_file: Name of the configuration file. | [
"Run",
"the",
"compactor",
"daemon",
"."
] | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/tools.py#L820-L829 | train |
klmitch/turnstile | turnstile/tools.py | ScriptAdaptor._wrap | def _wrap(cls, func):
"""
Ensures that the function is wrapped in a ScriptAdaptor
object. If it is not, a new ScriptAdaptor will be returned.
If it is, the ScriptAdaptor is returned.
:param func: The function to be wrapped.
"""
if isinstance(func, cls):
... | python | def _wrap(cls, func):
"""
Ensures that the function is wrapped in a ScriptAdaptor
object. If it is not, a new ScriptAdaptor will be returned.
If it is, the ScriptAdaptor is returned.
:param func: The function to be wrapped.
"""
if isinstance(func, cls):
... | [
"def",
"_wrap",
"(",
"cls",
",",
"func",
")",
":",
"if",
"isinstance",
"(",
"func",
",",
"cls",
")",
":",
"return",
"func",
"return",
"functools",
".",
"update_wrapper",
"(",
"cls",
"(",
"func",
")",
",",
"func",
")"
] | Ensures that the function is wrapped in a ScriptAdaptor
object. If it is not, a new ScriptAdaptor will be returned.
If it is, the ScriptAdaptor is returned.
:param func: The function to be wrapped. | [
"Ensures",
"that",
"the",
"function",
"is",
"wrapped",
"in",
"a",
"ScriptAdaptor",
"object",
".",
"If",
"it",
"is",
"not",
"a",
"new",
"ScriptAdaptor",
"will",
"be",
"returned",
".",
"If",
"it",
"is",
"the",
"ScriptAdaptor",
"is",
"returned",
"."
] | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/tools.py#L50-L61 | train |
klmitch/turnstile | turnstile/tools.py | ScriptAdaptor.setup_args | def setup_args(self, parser):
"""
Set up an argparse.ArgumentParser object by adding all the
arguments taken by the function.
"""
# Add all the arguments to the argument parser
for args, kwargs in self._arguments:
parser.add_argument(*args, **kwargs) | python | def setup_args(self, parser):
"""
Set up an argparse.ArgumentParser object by adding all the
arguments taken by the function.
"""
# Add all the arguments to the argument parser
for args, kwargs in self._arguments:
parser.add_argument(*args, **kwargs) | [
"def",
"setup_args",
"(",
"self",
",",
"parser",
")",
":",
"for",
"args",
",",
"kwargs",
"in",
"self",
".",
"_arguments",
":",
"parser",
".",
"add_argument",
"(",
"*",
"args",
",",
"**",
"kwargs",
")"
] | Set up an argparse.ArgumentParser object by adding all the
arguments taken by the function. | [
"Set",
"up",
"an",
"argparse",
".",
"ArgumentParser",
"object",
"by",
"adding",
"all",
"the",
"arguments",
"taken",
"by",
"the",
"function",
"."
] | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/tools.py#L131-L139 | train |
klmitch/turnstile | turnstile/tools.py | ScriptAdaptor.get_kwargs | def get_kwargs(self, args):
"""
Given a Namespace object drawn from argparse, determines the
keyword arguments to pass to the underlying function. Note
that, if the underlying function accepts all keyword
arguments, the dictionary returned will contain the entire
content... | python | def get_kwargs(self, args):
"""
Given a Namespace object drawn from argparse, determines the
keyword arguments to pass to the underlying function. Note
that, if the underlying function accepts all keyword
arguments, the dictionary returned will contain the entire
content... | [
"def",
"get_kwargs",
"(",
"self",
",",
"args",
")",
":",
"kwargs",
"=",
"{",
"}",
"argspec",
"=",
"inspect",
".",
"getargspec",
"(",
"self",
".",
"_func",
")",
"required",
"=",
"set",
"(",
"argspec",
".",
"args",
"[",
":",
"-",
"len",
"(",
"argspec... | Given a Namespace object drawn from argparse, determines the
keyword arguments to pass to the underlying function. Note
that, if the underlying function accepts all keyword
arguments, the dictionary returned will contain the entire
contents of the Namespace object. Also note that an
... | [
"Given",
"a",
"Namespace",
"object",
"drawn",
"from",
"argparse",
"determines",
"the",
"keyword",
"arguments",
"to",
"pass",
"to",
"the",
"underlying",
"function",
".",
"Note",
"that",
"if",
"the",
"underlying",
"function",
"accepts",
"all",
"keyword",
"argument... | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/tools.py#L141-L177 | train |
klmitch/turnstile | turnstile/tools.py | ScriptAdaptor.console | def console(self):
"""
Call the function as a console script. Command line arguments
are parsed, preprocessors are called, then the function is
called. If a 'debug' attribute is set by the command line
arguments, and it is True, any exception raised by the
underlying fu... | python | def console(self):
"""
Call the function as a console script. Command line arguments
are parsed, preprocessors are called, then the function is
called. If a 'debug' attribute is set by the command line
arguments, and it is True, any exception raised by the
underlying fu... | [
"def",
"console",
"(",
"self",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"self",
".",
"description",
")",
"self",
".",
"setup_args",
"(",
"parser",
")",
"args",
"=",
"parser",
".",
"parse_args",
"(",
")",
"for",... | Call the function as a console script. Command line arguments
are parsed, preprocessors are called, then the function is
called. If a 'debug' attribute is set by the command line
arguments, and it is True, any exception raised by the
underlying function will be reraised; otherwise, the... | [
"Call",
"the",
"function",
"as",
"a",
"console",
"script",
".",
"Command",
"line",
"arguments",
"are",
"parsed",
"preprocessors",
"are",
"called",
"then",
"the",
"function",
"is",
"called",
".",
"If",
"a",
"debug",
"attribute",
"is",
"set",
"by",
"the",
"c... | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/tools.py#L206-L238 | train |
BernardFW/bernard | src/bernard/utils.py | import_class | def import_class(name: Text) -> Type:
"""
Import a class based on its full name.
:param name: name of the class
"""
parts = name.split('.')
module_name = parts[:-1]
class_name = parts[-1]
module_ = importlib.import_module('.'.join(module_name))
return getattr(module_, class_name) | python | def import_class(name: Text) -> Type:
"""
Import a class based on its full name.
:param name: name of the class
"""
parts = name.split('.')
module_name = parts[:-1]
class_name = parts[-1]
module_ = importlib.import_module('.'.join(module_name))
return getattr(module_, class_name) | [
"def",
"import_class",
"(",
"name",
":",
"Text",
")",
"->",
"Type",
":",
"parts",
"=",
"name",
".",
"split",
"(",
"'.'",
")",
"module_name",
"=",
"parts",
"[",
":",
"-",
"1",
"]",
"class_name",
"=",
"parts",
"[",
"-",
"1",
"]",
"module_",
"=",
"i... | Import a class based on its full name.
:param name: name of the class | [
"Import",
"a",
"class",
"based",
"on",
"its",
"full",
"name",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/utils.py#L34-L45 | train |
BernardFW/bernard | src/bernard/utils.py | make_ro | def make_ro(obj: Any, forgive_type=False):
"""
Make a json-serializable type recursively read-only
:param obj: Any json-serializable type
:param forgive_type: If you can forgive a type to be unknown (instead of
raising an exception)
"""
if isinstance(obj, (str, bytes, ... | python | def make_ro(obj: Any, forgive_type=False):
"""
Make a json-serializable type recursively read-only
:param obj: Any json-serializable type
:param forgive_type: If you can forgive a type to be unknown (instead of
raising an exception)
"""
if isinstance(obj, (str, bytes, ... | [
"def",
"make_ro",
"(",
"obj",
":",
"Any",
",",
"forgive_type",
"=",
"False",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"(",
"str",
",",
"bytes",
",",
"int",
",",
"float",
",",
"bool",
",",
"RoDict",
",",
"RoList",
")",
")",
"or",
"obj",
"is"... | Make a json-serializable type recursively read-only
:param obj: Any json-serializable type
:param forgive_type: If you can forgive a type to be unknown (instead of
raising an exception) | [
"Make",
"a",
"json",
"-",
"serializable",
"type",
"recursively",
"read",
"-",
"only"
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/utils.py#L127-L147 | train |
BernardFW/bernard | src/bernard/utils.py | make_rw | def make_rw(obj: Any):
"""
Copy a RO object into a RW structure made with standard Python classes.
WARNING there is no protection against recursion.
"""
if isinstance(obj, RoDict):
return {k: make_rw(v) for k, v in obj.items()}
elif isinstance(obj, RoList):
return [make_rw(x) f... | python | def make_rw(obj: Any):
"""
Copy a RO object into a RW structure made with standard Python classes.
WARNING there is no protection against recursion.
"""
if isinstance(obj, RoDict):
return {k: make_rw(v) for k, v in obj.items()}
elif isinstance(obj, RoList):
return [make_rw(x) f... | [
"def",
"make_rw",
"(",
"obj",
":",
"Any",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"RoDict",
")",
":",
"return",
"{",
"k",
":",
"make_rw",
"(",
"v",
")",
"for",
"k",
",",
"v",
"in",
"obj",
".",
"items",
"(",
")",
"}",
"elif",
"isinstance"... | Copy a RO object into a RW structure made with standard Python classes.
WARNING there is no protection against recursion. | [
"Copy",
"a",
"RO",
"object",
"into",
"a",
"RW",
"structure",
"made",
"with",
"standard",
"Python",
"classes",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/utils.py#L150-L162 | train |
BernardFW/bernard | src/bernard/utils.py | patch_qs | def patch_qs(url: Text, data: Dict[Text, Text]) -> Text:
"""
Given an URL, change the query string to include the values specified in
the dictionary.
If the keys of the dictionary can be found in the query string of the URL,
then they will be removed.
It is guaranteed that all other values of ... | python | def patch_qs(url: Text, data: Dict[Text, Text]) -> Text:
"""
Given an URL, change the query string to include the values specified in
the dictionary.
If the keys of the dictionary can be found in the query string of the URL,
then they will be removed.
It is guaranteed that all other values of ... | [
"def",
"patch_qs",
"(",
"url",
":",
"Text",
",",
"data",
":",
"Dict",
"[",
"Text",
",",
"Text",
"]",
")",
"->",
"Text",
":",
"qs_id",
"=",
"4",
"p",
"=",
"list",
"(",
"urlparse",
"(",
"url",
")",
")",
"qs",
"=",
"parse_qsl",
"(",
"p",
"[",
"q... | Given an URL, change the query string to include the values specified in
the dictionary.
If the keys of the dictionary can be found in the query string of the URL,
then they will be removed.
It is guaranteed that all other values of the query string will keep their
order. | [
"Given",
"an",
"URL",
"change",
"the",
"query",
"string",
"to",
"include",
"the",
"values",
"specified",
"in",
"the",
"dictionary",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/utils.py#L203-L225 | train |
BernardFW/bernard | src/bernard/utils.py | dict_is_subset | def dict_is_subset(subset: Any, full_set: Any) -> bool:
"""
Checks that all keys present in `subset` are present and have the same
value in `full_set`. If a key is in `full_set` but not in `subset` then
True will be returned anyways.
"""
if not isinstance(subset, full_set.__class__):
re... | python | def dict_is_subset(subset: Any, full_set: Any) -> bool:
"""
Checks that all keys present in `subset` are present and have the same
value in `full_set`. If a key is in `full_set` but not in `subset` then
True will be returned anyways.
"""
if not isinstance(subset, full_set.__class__):
re... | [
"def",
"dict_is_subset",
"(",
"subset",
":",
"Any",
",",
"full_set",
":",
"Any",
")",
"->",
"bool",
":",
"if",
"not",
"isinstance",
"(",
"subset",
",",
"full_set",
".",
"__class__",
")",
":",
"return",
"False",
"elif",
"isinstance",
"(",
"subset",
",",
... | Checks that all keys present in `subset` are present and have the same
value in `full_set`. If a key is in `full_set` but not in `subset` then
True will be returned anyways. | [
"Checks",
"that",
"all",
"keys",
"present",
"in",
"subset",
"are",
"present",
"and",
"have",
"the",
"same",
"value",
"in",
"full_set",
".",
"If",
"a",
"key",
"is",
"in",
"full_set",
"but",
"not",
"in",
"subset",
"then",
"True",
"will",
"be",
"returned",
... | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/utils.py#L234-L259 | train |
BernardFW/bernard | src/bernard/utils.py | ClassExp._compile | def _compile(self, expression):
"""
Transform a class exp into an actual regex
"""
x = self.RE_PYTHON_VAR.sub('(?:\\1,)', expression)
x = self.RE_SPACES.sub('', x)
return re.compile(x) | python | def _compile(self, expression):
"""
Transform a class exp into an actual regex
"""
x = self.RE_PYTHON_VAR.sub('(?:\\1,)', expression)
x = self.RE_SPACES.sub('', x)
return re.compile(x) | [
"def",
"_compile",
"(",
"self",
",",
"expression",
")",
":",
"x",
"=",
"self",
".",
"RE_PYTHON_VAR",
".",
"sub",
"(",
"'(?:\\\\1,)'",
",",
"expression",
")",
"x",
"=",
"self",
".",
"RE_SPACES",
".",
"sub",
"(",
"''",
",",
"x",
")",
"return",
"re",
... | Transform a class exp into an actual regex | [
"Transform",
"a",
"class",
"exp",
"into",
"an",
"actual",
"regex"
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/utils.py#L177-L184 | train |
BernardFW/bernard | src/bernard/utils.py | ClassExp._make_string | def _make_string(self, objects: List[Any]) -> Text:
"""
Transforms a list of objects into a matchable string
"""
return ''.join(x.__class__.__name__ + ',' for x in objects) | python | def _make_string(self, objects: List[Any]) -> Text:
"""
Transforms a list of objects into a matchable string
"""
return ''.join(x.__class__.__name__ + ',' for x in objects) | [
"def",
"_make_string",
"(",
"self",
",",
"objects",
":",
"List",
"[",
"Any",
"]",
")",
"->",
"Text",
":",
"return",
"''",
".",
"join",
"(",
"x",
".",
"__class__",
".",
"__name__",
"+",
"','",
"for",
"x",
"in",
"objects",
")"
] | Transforms a list of objects into a matchable string | [
"Transforms",
"a",
"list",
"of",
"objects",
"into",
"a",
"matchable",
"string"
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/utils.py#L186-L191 | train |
BernardFW/bernard | src/bernard/utils.py | ClassExp.match | def match(self, objects: List[Any]) -> bool:
"""
Return True if the list of objects matches the expression.
"""
s = self._make_string(objects)
m = self._compiled_expression.match(s)
return m is not None | python | def match(self, objects: List[Any]) -> bool:
"""
Return True if the list of objects matches the expression.
"""
s = self._make_string(objects)
m = self._compiled_expression.match(s)
return m is not None | [
"def",
"match",
"(",
"self",
",",
"objects",
":",
"List",
"[",
"Any",
"]",
")",
"->",
"bool",
":",
"s",
"=",
"self",
".",
"_make_string",
"(",
"objects",
")",
"m",
"=",
"self",
".",
"_compiled_expression",
".",
"match",
"(",
"s",
")",
"return",
"m"... | Return True if the list of objects matches the expression. | [
"Return",
"True",
"if",
"the",
"list",
"of",
"objects",
"matches",
"the",
"expression",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/utils.py#L193-L200 | train |
jstitch/MambuPy | MambuPy/mambuconfig.py | get_conf | def get_conf(conf, sect, opt):
""" Gets a config 'opt' from 'conf' file, under section 'sect'.
If no 'opt' exists under 'sect', it looks for option on the default_configs
dictionary
If there exists an environmental variable named MAMBUPY_{upper_case_opt},
it overrides whatever the conf files or de... | python | def get_conf(conf, sect, opt):
""" Gets a config 'opt' from 'conf' file, under section 'sect'.
If no 'opt' exists under 'sect', it looks for option on the default_configs
dictionary
If there exists an environmental variable named MAMBUPY_{upper_case_opt},
it overrides whatever the conf files or de... | [
"def",
"get_conf",
"(",
"conf",
",",
"sect",
",",
"opt",
")",
":",
"argu",
"=",
"getattr",
"(",
"args",
",",
"\"mambupy_\"",
"+",
"opt",
".",
"lower",
"(",
")",
")",
"if",
"not",
"argu",
":",
"envir",
"=",
"os",
".",
"environ",
".",
"get",
"(",
... | Gets a config 'opt' from 'conf' file, under section 'sect'.
If no 'opt' exists under 'sect', it looks for option on the default_configs
dictionary
If there exists an environmental variable named MAMBUPY_{upper_case_opt},
it overrides whatever the conf files or default_configs dict says.
But if yo... | [
"Gets",
"a",
"config",
"opt",
"from",
"conf",
"file",
"under",
"section",
"sect",
"."
] | 2af98cc12e7ed5ec183b3e97644e880e70b79ee8 | https://github.com/jstitch/MambuPy/blob/2af98cc12e7ed5ec183b3e97644e880e70b79ee8/MambuPy/mambuconfig.py#L119-L152 | train |
obilaniu/Nauka | src/nauka/fhs.py | iso8601timestamp | def iso8601timestamp(T=None, nanos=True, utc=False):
"""Get ISO8601-formatted timestamp string."""
T = time.time() if T is None else T
Ti = math.floor(T)
Tn = round((T-Ti)*1e9)
if Tn >= 1e9:
Ti += 1
Tn = 0
s = time.gmtime(Ti) if utc else time.localtime(Ti)
f = time.strftime("%Y%m%dT%H%M%S", s)
... | python | def iso8601timestamp(T=None, nanos=True, utc=False):
"""Get ISO8601-formatted timestamp string."""
T = time.time() if T is None else T
Ti = math.floor(T)
Tn = round((T-Ti)*1e9)
if Tn >= 1e9:
Ti += 1
Tn = 0
s = time.gmtime(Ti) if utc else time.localtime(Ti)
f = time.strftime("%Y%m%dT%H%M%S", s)
... | [
"def",
"iso8601timestamp",
"(",
"T",
"=",
"None",
",",
"nanos",
"=",
"True",
",",
"utc",
"=",
"False",
")",
":",
"T",
"=",
"time",
".",
"time",
"(",
")",
"if",
"T",
"is",
"None",
"else",
"T",
"Ti",
"=",
"math",
".",
"floor",
"(",
"T",
")",
"T... | Get ISO8601-formatted timestamp string. | [
"Get",
"ISO8601",
"-",
"formatted",
"timestamp",
"string",
"."
] | 1492a4f9d204a868c1a8a1d327bd108490b856b4 | https://github.com/obilaniu/Nauka/blob/1492a4f9d204a868c1a8a1d327bd108490b856b4/src/nauka/fhs.py#L5-L18 | train |
obilaniu/Nauka | src/nauka/fhs.py | createWorkDir | def createWorkDir(baseDir,
projName,
expUUID,
expNames = [],
nanos = True,
utc = False):
"""Create working directory for experiment if not existing already."""
#
# First, ensure the project's top-level hierarchy, espe... | python | def createWorkDir(baseDir,
projName,
expUUID,
expNames = [],
nanos = True,
utc = False):
"""Create working directory for experiment if not existing already."""
#
# First, ensure the project's top-level hierarchy, espe... | [
"def",
"createWorkDir",
"(",
"baseDir",
",",
"projName",
",",
"expUUID",
",",
"expNames",
"=",
"[",
"]",
",",
"nanos",
"=",
"True",
",",
"utc",
"=",
"False",
")",
":",
"projDir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"baseDir",
",",
"projName",
... | Create working directory for experiment if not existing already. | [
"Create",
"working",
"directory",
"for",
"experiment",
"if",
"not",
"existing",
"already",
"."
] | 1492a4f9d204a868c1a8a1d327bd108490b856b4 | https://github.com/obilaniu/Nauka/blob/1492a4f9d204a868c1a8a1d327bd108490b856b4/src/nauka/fhs.py#L21-L89 | train |
polyaxon/hestia | hestia/humanize.py | humanize_timesince | def humanize_timesince(start_time): # pylint:disable=too-many-return-statements
"""Creates a string representation of time since the given `start_time`."""
if not start_time:
return start_time
delta = local_now() - start_time
# assumption: negative delta values originate from clock
# ... | python | def humanize_timesince(start_time): # pylint:disable=too-many-return-statements
"""Creates a string representation of time since the given `start_time`."""
if not start_time:
return start_time
delta = local_now() - start_time
# assumption: negative delta values originate from clock
# ... | [
"def",
"humanize_timesince",
"(",
"start_time",
")",
":",
"if",
"not",
"start_time",
":",
"return",
"start_time",
"delta",
"=",
"local_now",
"(",
")",
"-",
"start_time",
"if",
"delta",
".",
"total_seconds",
"(",
")",
"<",
"0",
":",
"return",
"'a few seconds ... | Creates a string representation of time since the given `start_time`. | [
"Creates",
"a",
"string",
"representation",
"of",
"time",
"since",
"the",
"given",
"start_time",
"."
] | 382ed139cff8bf35c987cfc30a31b72c0d6b808e | https://github.com/polyaxon/hestia/blob/382ed139cff8bf35c987cfc30a31b72c0d6b808e/hestia/humanize.py#L7-L43 | train |
polyaxon/hestia | hestia/humanize.py | humanize_timedelta | def humanize_timedelta(seconds):
"""Creates a string representation of timedelta."""
hours, remainder = divmod(seconds, 3600)
days, hours = divmod(hours, 24)
minutes, seconds = divmod(remainder, 60)
if days:
result = '{}d'.format(days)
if hours:
result += ' {}h'.format(h... | python | def humanize_timedelta(seconds):
"""Creates a string representation of timedelta."""
hours, remainder = divmod(seconds, 3600)
days, hours = divmod(hours, 24)
minutes, seconds = divmod(remainder, 60)
if days:
result = '{}d'.format(days)
if hours:
result += ' {}h'.format(h... | [
"def",
"humanize_timedelta",
"(",
"seconds",
")",
":",
"hours",
",",
"remainder",
"=",
"divmod",
"(",
"seconds",
",",
"3600",
")",
"days",
",",
"hours",
"=",
"divmod",
"(",
"hours",
",",
"24",
")",
"minutes",
",",
"seconds",
"=",
"divmod",
"(",
"remain... | Creates a string representation of timedelta. | [
"Creates",
"a",
"string",
"representation",
"of",
"timedelta",
"."
] | 382ed139cff8bf35c987cfc30a31b72c0d6b808e | https://github.com/polyaxon/hestia/blob/382ed139cff8bf35c987cfc30a31b72c0d6b808e/hestia/humanize.py#L46-L72 | train |
peopledoc/mock-services | mock_services/http_mock.py | HttpMock.start | def start(self):
"""Overrides default start behaviour by raising ConnectionError instead
of custom requests_mock.exceptions.NoMockAddress.
"""
if self._http_last_send is not None:
raise RuntimeError('HttpMock has already been started')
# 1) save request.Session.send ... | python | def start(self):
"""Overrides default start behaviour by raising ConnectionError instead
of custom requests_mock.exceptions.NoMockAddress.
"""
if self._http_last_send is not None:
raise RuntimeError('HttpMock has already been started')
# 1) save request.Session.send ... | [
"def",
"start",
"(",
"self",
")",
":",
"if",
"self",
".",
"_http_last_send",
"is",
"not",
"None",
":",
"raise",
"RuntimeError",
"(",
"'HttpMock has already been started'",
")",
"super",
"(",
"HttpMock",
",",
"self",
")",
".",
"start",
"(",
")",
"self",
"."... | Overrides default start behaviour by raising ConnectionError instead
of custom requests_mock.exceptions.NoMockAddress. | [
"Overrides",
"default",
"start",
"behaviour",
"by",
"raising",
"ConnectionError",
"instead",
"of",
"custom",
"requests_mock",
".",
"exceptions",
".",
"NoMockAddress",
"."
] | fd3838280df8869725b538768357435eedf299c1 | https://github.com/peopledoc/mock-services/blob/fd3838280df8869725b538768357435eedf299c1/mock_services/http_mock.py#L63-L76 | train |
axel-events/axel | axel/axel.py | Event.unhandle | def unhandle(self, handler):
""" Unregisters a handler """
h, _, _ = self._extract(handler)
key = hash(h)
with self._hlock:
if key not in self.handlers:
raise ValueError('Handler "%s" was not found' % str(h))
handlers = self.handlers.copy()
... | python | def unhandle(self, handler):
""" Unregisters a handler """
h, _, _ = self._extract(handler)
key = hash(h)
with self._hlock:
if key not in self.handlers:
raise ValueError('Handler "%s" was not found' % str(h))
handlers = self.handlers.copy()
... | [
"def",
"unhandle",
"(",
"self",
",",
"handler",
")",
":",
"h",
",",
"_",
",",
"_",
"=",
"self",
".",
"_extract",
"(",
"handler",
")",
"key",
"=",
"hash",
"(",
"h",
")",
"with",
"self",
".",
"_hlock",
":",
"if",
"key",
"not",
"in",
"self",
".",
... | Unregisters a handler | [
"Unregisters",
"a",
"handler"
] | 08a663347ef21614b96f92f60f4de57a502db73c | https://github.com/axel-events/axel/blob/08a663347ef21614b96f92f60f4de57a502db73c/axel/axel.py#L163-L173 | train |
axel-events/axel | axel/axel.py | Event.fire | def fire(self, *args, **kw):
""" Stores all registered handlers in a queue for processing """
result = []
with self._hlock:
handlers = self.handlers
if self.threads == 0: # same-thread execution - synchronized
for k in handlers:
# handl... | python | def fire(self, *args, **kw):
""" Stores all registered handlers in a queue for processing """
result = []
with self._hlock:
handlers = self.handlers
if self.threads == 0: # same-thread execution - synchronized
for k in handlers:
# handl... | [
"def",
"fire",
"(",
"self",
",",
"*",
"args",
",",
"**",
"kw",
")",
":",
"result",
"=",
"[",
"]",
"with",
"self",
".",
"_hlock",
":",
"handlers",
"=",
"self",
".",
"handlers",
"if",
"self",
".",
"threads",
"==",
"0",
":",
"for",
"k",
"in",
"han... | Stores all registered handlers in a queue for processing | [
"Stores",
"all",
"registered",
"handlers",
"in",
"a",
"queue",
"for",
"processing"
] | 08a663347ef21614b96f92f60f4de57a502db73c | https://github.com/axel-events/axel/blob/08a663347ef21614b96f92f60f4de57a502db73c/axel/axel.py#L175-L247 | train |
axel-events/axel | axel/axel.py | Event.clear | def clear(self):
""" Discards all registered handlers and cached results """
with self._hlock:
self.handlers.clear()
with self._mlock:
self.memoize.clear() | python | def clear(self):
""" Discards all registered handlers and cached results """
with self._hlock:
self.handlers.clear()
with self._mlock:
self.memoize.clear() | [
"def",
"clear",
"(",
"self",
")",
":",
"with",
"self",
".",
"_hlock",
":",
"self",
".",
"handlers",
".",
"clear",
"(",
")",
"with",
"self",
".",
"_mlock",
":",
"self",
".",
"memoize",
".",
"clear",
"(",
")"
] | Discards all registered handlers and cached results | [
"Discards",
"all",
"registered",
"handlers",
"and",
"cached",
"results"
] | 08a663347ef21614b96f92f60f4de57a502db73c | https://github.com/axel-events/axel/blob/08a663347ef21614b96f92f60f4de57a502db73c/axel/axel.py#L254-L259 | train |
axel-events/axel | axel/axel.py | Event._timeout | def _timeout(self, timeout, handler, *args, **kw):
""" Controls the time allocated for the execution of a method """
t = spawn_thread(target=handler, args=args, kw=kw)
t.daemon = True
t.start()
t.join(timeout)
if not t.is_alive():
if t.exc_info:
... | python | def _timeout(self, timeout, handler, *args, **kw):
""" Controls the time allocated for the execution of a method """
t = spawn_thread(target=handler, args=args, kw=kw)
t.daemon = True
t.start()
t.join(timeout)
if not t.is_alive():
if t.exc_info:
... | [
"def",
"_timeout",
"(",
"self",
",",
"timeout",
",",
"handler",
",",
"*",
"args",
",",
"**",
"kw",
")",
":",
"t",
"=",
"spawn_thread",
"(",
"target",
"=",
"handler",
",",
"args",
"=",
"args",
",",
"kw",
"=",
"kw",
")",
"t",
".",
"daemon",
"=",
... | Controls the time allocated for the execution of a method | [
"Controls",
"the",
"time",
"allocated",
"for",
"the",
"execution",
"of",
"a",
"method"
] | 08a663347ef21614b96f92f60f4de57a502db73c | https://github.com/axel-events/axel/blob/08a663347ef21614b96f92f60f4de57a502db73c/axel/axel.py#L336-L352 | train |
axel-events/axel | axel/axel.py | Event._threads | def _threads(self, handlers):
""" Calculates maximum number of threads that will be started """
if self.threads < len(handlers):
return self.threads
return len(handlers) | python | def _threads(self, handlers):
""" Calculates maximum number of threads that will be started """
if self.threads < len(handlers):
return self.threads
return len(handlers) | [
"def",
"_threads",
"(",
"self",
",",
"handlers",
")",
":",
"if",
"self",
".",
"threads",
"<",
"len",
"(",
"handlers",
")",
":",
"return",
"self",
".",
"threads",
"return",
"len",
"(",
"handlers",
")"
] | Calculates maximum number of threads that will be started | [
"Calculates",
"maximum",
"number",
"of",
"threads",
"that",
"will",
"be",
"started"
] | 08a663347ef21614b96f92f60f4de57a502db73c | https://github.com/axel-events/axel/blob/08a663347ef21614b96f92f60f4de57a502db73c/axel/axel.py#L354-L358 | train |
azogue/i2csense | i2csense/htu21d.py | HTU21D.update | def update(self):
"""Read raw data and calculate temperature and humidity."""
if not self._ok:
self.log_error("Trying to restore OK mode w/ soft reset")
self._ok = self._soft_reset()
try:
self._bus.write_byte(self._i2c_add, CMD_READ_TEMP_NOHOLD)
sl... | python | def update(self):
"""Read raw data and calculate temperature and humidity."""
if not self._ok:
self.log_error("Trying to restore OK mode w/ soft reset")
self._ok = self._soft_reset()
try:
self._bus.write_byte(self._i2c_add, CMD_READ_TEMP_NOHOLD)
sl... | [
"def",
"update",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_ok",
":",
"self",
".",
"log_error",
"(",
"\"Trying to restore OK mode w/ soft reset\"",
")",
"self",
".",
"_ok",
"=",
"self",
".",
"_soft_reset",
"(",
")",
"try",
":",
"self",
".",
"_bus... | Read raw data and calculate temperature and humidity. | [
"Read",
"raw",
"data",
"and",
"calculate",
"temperature",
"and",
"humidity",
"."
] | ecc6806dcee9de827a5414a9e836d271fedca9b9 | https://github.com/azogue/i2csense/blob/ecc6806dcee9de827a5414a9e836d271fedca9b9/i2csense/htu21d.py#L87-L126 | train |
reanahub/reana-db | reana_db/models.py | Workflow.get_owner_access_token | def get_owner_access_token(self):
"""Return workflow owner access token."""
from .database import Session
db_session = Session.object_session(self)
owner = db_session.query(User).filter_by(
id_=self.owner_id).first()
return owner.access_token | python | def get_owner_access_token(self):
"""Return workflow owner access token."""
from .database import Session
db_session = Session.object_session(self)
owner = db_session.query(User).filter_by(
id_=self.owner_id).first()
return owner.access_token | [
"def",
"get_owner_access_token",
"(",
"self",
")",
":",
"from",
".",
"database",
"import",
"Session",
"db_session",
"=",
"Session",
".",
"object_session",
"(",
"self",
")",
"owner",
"=",
"db_session",
".",
"query",
"(",
"User",
")",
".",
"filter_by",
"(",
... | Return workflow owner access token. | [
"Return",
"workflow",
"owner",
"access",
"token",
"."
] | 4efcb46d23af035689964d8c25a804c5a8f1dfc3 | https://github.com/reanahub/reana-db/blob/4efcb46d23af035689964d8c25a804c5a8f1dfc3/reana_db/models.py#L167-L173 | train |
reanahub/reana-db | reana_db/models.py | Workflow.update_workflow_status | def update_workflow_status(db_session, workflow_uuid, status,
new_logs='', message=None):
"""Update database workflow status.
:param workflow_uuid: UUID which represents the workflow.
:param status: String that represents the workflow status.
:param new_lo... | python | def update_workflow_status(db_session, workflow_uuid, status,
new_logs='', message=None):
"""Update database workflow status.
:param workflow_uuid: UUID which represents the workflow.
:param status: String that represents the workflow status.
:param new_lo... | [
"def",
"update_workflow_status",
"(",
"db_session",
",",
"workflow_uuid",
",",
"status",
",",
"new_logs",
"=",
"''",
",",
"message",
"=",
"None",
")",
":",
"try",
":",
"workflow",
"=",
"db_session",
".",
"query",
"(",
"Workflow",
")",
".",
"filter_by",
"("... | Update database workflow status.
:param workflow_uuid: UUID which represents the workflow.
:param status: String that represents the workflow status.
:param new_logs: New logs from workflow execution.
:param message: Unused. | [
"Update",
"database",
"workflow",
"status",
"."
] | 4efcb46d23af035689964d8c25a804c5a8f1dfc3 | https://github.com/reanahub/reana-db/blob/4efcb46d23af035689964d8c25a804c5a8f1dfc3/reana_db/models.py#L176-L198 | train |
bacher09/xrcon | xrcon/utils.py | parse_server_addr | def parse_server_addr(str_addr, default_port=26000):
"""Parse address and returns host and port
Args:
str_addr --- string that contains server ip or hostname and optionaly
port
Returns: tuple (host, port)
Examples:
>>> parse_server_addr('127.0.0.1:26006')
('127.0.0.1', 26006)... | python | def parse_server_addr(str_addr, default_port=26000):
"""Parse address and returns host and port
Args:
str_addr --- string that contains server ip or hostname and optionaly
port
Returns: tuple (host, port)
Examples:
>>> parse_server_addr('127.0.0.1:26006')
('127.0.0.1', 26006)... | [
"def",
"parse_server_addr",
"(",
"str_addr",
",",
"default_port",
"=",
"26000",
")",
":",
"m",
"=",
"ADDR_STR_RE",
".",
"match",
"(",
"str_addr",
")",
"if",
"m",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"'Bad address string \"{0}\"'",
".",
"format",
"(... | Parse address and returns host and port
Args:
str_addr --- string that contains server ip or hostname and optionaly
port
Returns: tuple (host, port)
Examples:
>>> parse_server_addr('127.0.0.1:26006')
('127.0.0.1', 26006)
>>> parse_server_addr('[2001:db8:85a3:8d3:1319:8a2e:370... | [
"Parse",
"address",
"and",
"returns",
"host",
"and",
"port"
] | 6a883f780265cbca31af7a379dc7cb28fdd8b73f | https://github.com/bacher09/xrcon/blob/6a883f780265cbca31af7a379dc7cb28fdd8b73f/xrcon/utils.py#L103-L142 | train |
pyQode/pyqode.cobol | pyqode/cobol/modes/goto.py | GoToDefinitionMode.request_goto | def request_goto(self, tc=None):
"""
Request a go to assignment.
:param tc: Text cursor which contains the text that we must look for
its assignment. Can be None to go to the text that is under
the text cursor.
:type tc: QtGui.QTextCursor
""... | python | def request_goto(self, tc=None):
"""
Request a go to assignment.
:param tc: Text cursor which contains the text that we must look for
its assignment. Can be None to go to the text that is under
the text cursor.
:type tc: QtGui.QTextCursor
""... | [
"def",
"request_goto",
"(",
"self",
",",
"tc",
"=",
"None",
")",
":",
"if",
"not",
"tc",
":",
"tc",
"=",
"TextHelper",
"(",
"self",
".",
"editor",
")",
".",
"word_under_cursor",
"(",
"select_whole_word",
"=",
"True",
")",
"if",
"not",
"self",
".",
"_... | Request a go to assignment.
:param tc: Text cursor which contains the text that we must look for
its assignment. Can be None to go to the text that is under
the text cursor.
:type tc: QtGui.QTextCursor | [
"Request",
"a",
"go",
"to",
"assignment",
"."
] | eedae4e320a4b2d0c44abb2c3061091321648fb7 | https://github.com/pyQode/pyqode.cobol/blob/eedae4e320a4b2d0c44abb2c3061091321648fb7/pyqode/cobol/modes/goto.py#L122-L137 | train |
jasonrbriggs/proton | python/proton/template.py | get_template | def get_template(name):
"""
Return a copy of the template with the specified name. If not found, or an error occurs
during the load, return None.
"""
path = os.path.join(base_dir, name)
if path not in templates:
try:
templates[path] = Template(path)
except IOError:
... | python | def get_template(name):
"""
Return a copy of the template with the specified name. If not found, or an error occurs
during the load, return None.
"""
path = os.path.join(base_dir, name)
if path not in templates:
try:
templates[path] = Template(path)
except IOError:
... | [
"def",
"get_template",
"(",
"name",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"base_dir",
",",
"name",
")",
"if",
"path",
"not",
"in",
"templates",
":",
"try",
":",
"templates",
"[",
"path",
"]",
"=",
"Template",
"(",
"path",
")",... | Return a copy of the template with the specified name. If not found, or an error occurs
during the load, return None. | [
"Return",
"a",
"copy",
"of",
"the",
"template",
"with",
"the",
"specified",
"name",
".",
"If",
"not",
"found",
"or",
"an",
"error",
"occurs",
"during",
"the",
"load",
"return",
"None",
"."
] | e734734750797ef0caaa1680379e07b86d7a53e3 | https://github.com/jasonrbriggs/proton/blob/e734734750797ef0caaa1680379e07b86d7a53e3/python/proton/template.py#L366-L379 | train |
jasonrbriggs/proton | python/proton/template.py | Template.set_value | def set_value(self, eid, val, idx='*'):
"""
Set the content of an xml element marked with the matching eid attribute.
"""
if eid in self.__element_ids:
elems = self.__element_ids[eid]
if type(val) in SEQ_TYPES:
idx = 0
if idx == '*':
... | python | def set_value(self, eid, val, idx='*'):
"""
Set the content of an xml element marked with the matching eid attribute.
"""
if eid in self.__element_ids:
elems = self.__element_ids[eid]
if type(val) in SEQ_TYPES:
idx = 0
if idx == '*':
... | [
"def",
"set_value",
"(",
"self",
",",
"eid",
",",
"val",
",",
"idx",
"=",
"'*'",
")",
":",
"if",
"eid",
"in",
"self",
".",
"__element_ids",
":",
"elems",
"=",
"self",
".",
"__element_ids",
"[",
"eid",
"]",
"if",
"type",
"(",
"val",
")",
"in",
"SE... | Set the content of an xml element marked with the matching eid attribute. | [
"Set",
"the",
"content",
"of",
"an",
"xml",
"element",
"marked",
"with",
"the",
"matching",
"eid",
"attribute",
"."
] | e734734750797ef0caaa1680379e07b86d7a53e3 | https://github.com/jasonrbriggs/proton/blob/e734734750797ef0caaa1680379e07b86d7a53e3/python/proton/template.py#L220-L232 | train |
jasonrbriggs/proton | python/proton/template.py | Template.set_attribute | def set_attribute(self, aid, attrib, val, idx='*'):
"""
Set the value of an xml attribute marked with the matching aid attribute.
"""
if aid in self.__attrib_ids:
elems = self.__attrib_ids[aid]
if idx == '*':
for elem in elems:
... | python | def set_attribute(self, aid, attrib, val, idx='*'):
"""
Set the value of an xml attribute marked with the matching aid attribute.
"""
if aid in self.__attrib_ids:
elems = self.__attrib_ids[aid]
if idx == '*':
for elem in elems:
... | [
"def",
"set_attribute",
"(",
"self",
",",
"aid",
",",
"attrib",
",",
"val",
",",
"idx",
"=",
"'*'",
")",
":",
"if",
"aid",
"in",
"self",
".",
"__attrib_ids",
":",
"elems",
"=",
"self",
".",
"__attrib_ids",
"[",
"aid",
"]",
"if",
"idx",
"==",
"'*'",... | Set the value of an xml attribute marked with the matching aid attribute. | [
"Set",
"the",
"value",
"of",
"an",
"xml",
"attribute",
"marked",
"with",
"the",
"matching",
"aid",
"attribute",
"."
] | e734734750797ef0caaa1680379e07b86d7a53e3 | https://github.com/jasonrbriggs/proton/blob/e734734750797ef0caaa1680379e07b86d7a53e3/python/proton/template.py#L244-L255 | train |
jasonrbriggs/proton | python/proton/template.py | Template.hide | def hide(self, eid, index=0):
"""
Hide the element with the matching eid. If no match, look for an element with a matching rid.
"""
elems = None
if eid in self.__element_ids:
elems = self.__element_ids[eid]
elif eid in self.__repeat_ids:
elems = se... | python | def hide(self, eid, index=0):
"""
Hide the element with the matching eid. If no match, look for an element with a matching rid.
"""
elems = None
if eid in self.__element_ids:
elems = self.__element_ids[eid]
elif eid in self.__repeat_ids:
elems = se... | [
"def",
"hide",
"(",
"self",
",",
"eid",
",",
"index",
"=",
"0",
")",
":",
"elems",
"=",
"None",
"if",
"eid",
"in",
"self",
".",
"__element_ids",
":",
"elems",
"=",
"self",
".",
"__element_ids",
"[",
"eid",
"]",
"elif",
"eid",
"in",
"self",
".",
"... | Hide the element with the matching eid. If no match, look for an element with a matching rid. | [
"Hide",
"the",
"element",
"with",
"the",
"matching",
"eid",
".",
"If",
"no",
"match",
"look",
"for",
"an",
"element",
"with",
"a",
"matching",
"rid",
"."
] | e734734750797ef0caaa1680379e07b86d7a53e3 | https://github.com/jasonrbriggs/proton/blob/e734734750797ef0caaa1680379e07b86d7a53e3/python/proton/template.py#L279-L291 | train |
jasonrbriggs/proton | python/proton/template.py | Template.repeat | def repeat(self, rid, count, index=0):
"""
Repeat an xml element marked with the matching rid.
"""
elems = None
if rid in self.__repeat_ids:
elems = self.__repeat_ids[rid]
elif rid in self.__element_ids:
elems = self.__element_ids
if elems... | python | def repeat(self, rid, count, index=0):
"""
Repeat an xml element marked with the matching rid.
"""
elems = None
if rid in self.__repeat_ids:
elems = self.__repeat_ids[rid]
elif rid in self.__element_ids:
elems = self.__element_ids
if elems... | [
"def",
"repeat",
"(",
"self",
",",
"rid",
",",
"count",
",",
"index",
"=",
"0",
")",
":",
"elems",
"=",
"None",
"if",
"rid",
"in",
"self",
".",
"__repeat_ids",
":",
"elems",
"=",
"self",
".",
"__repeat_ids",
"[",
"rid",
"]",
"elif",
"rid",
"in",
... | Repeat an xml element marked with the matching rid. | [
"Repeat",
"an",
"xml",
"element",
"marked",
"with",
"the",
"matching",
"rid",
"."
] | e734734750797ef0caaa1680379e07b86d7a53e3 | https://github.com/jasonrbriggs/proton/blob/e734734750797ef0caaa1680379e07b86d7a53e3/python/proton/template.py#L293-L305 | train |
jasonrbriggs/proton | python/proton/template.py | Template.replace | def replace(self, eid, replacement, index=0):
"""
Replace an xml element marked with the matching eid. If the replacement value is an Element or TextElement,
it's swapped in untouched. If it's a Template, the children of the root element in the template are used.
Otherwise the replacemen... | python | def replace(self, eid, replacement, index=0):
"""
Replace an xml element marked with the matching eid. If the replacement value is an Element or TextElement,
it's swapped in untouched. If it's a Template, the children of the root element in the template are used.
Otherwise the replacemen... | [
"def",
"replace",
"(",
"self",
",",
"eid",
",",
"replacement",
",",
"index",
"=",
"0",
")",
":",
"if",
"eid",
"in",
"self",
".",
"__element_ids",
":",
"elems",
"=",
"self",
".",
"__element_ids",
"[",
"eid",
"]",
"elif",
"eid",
"in",
"self",
".",
"_... | Replace an xml element marked with the matching eid. If the replacement value is an Element or TextElement,
it's swapped in untouched. If it's a Template, the children of the root element in the template are used.
Otherwise the replacement value is wrapped with a TextElement. | [
"Replace",
"an",
"xml",
"element",
"marked",
"with",
"the",
"matching",
"eid",
".",
"If",
"the",
"replacement",
"value",
"is",
"an",
"Element",
"or",
"TextElement",
"it",
"s",
"swapped",
"in",
"untouched",
".",
"If",
"it",
"s",
"a",
"Template",
"the",
"c... | e734734750797ef0caaa1680379e07b86d7a53e3 | https://github.com/jasonrbriggs/proton/blob/e734734750797ef0caaa1680379e07b86d7a53e3/python/proton/template.py#L316-L347 | train |
jpscaletti/authcode | authcode/auth.py | Auth.set_hasher | def set_hasher(self, hash, rounds=None):
"""Updates the has algorithm and, optionally, the number of rounds
to use.
Raises:
`~WrongHashAlgorithm` if new algorithm isn't one of the three
recomended options.
"""
hash = hash.replace('-', '_')
if has... | python | def set_hasher(self, hash, rounds=None):
"""Updates the has algorithm and, optionally, the number of rounds
to use.
Raises:
`~WrongHashAlgorithm` if new algorithm isn't one of the three
recomended options.
"""
hash = hash.replace('-', '_')
if has... | [
"def",
"set_hasher",
"(",
"self",
",",
"hash",
",",
"rounds",
"=",
"None",
")",
":",
"hash",
"=",
"hash",
".",
"replace",
"(",
"'-'",
",",
"'_'",
")",
"if",
"hash",
"not",
"in",
"VALID_HASHERS",
":",
"raise",
"WrongHashAlgorithm",
"(",
"WRONG_HASH_MESSAG... | Updates the has algorithm and, optionally, the number of rounds
to use.
Raises:
`~WrongHashAlgorithm` if new algorithm isn't one of the three
recomended options. | [
"Updates",
"the",
"has",
"algorithm",
"and",
"optionally",
"the",
"number",
"of",
"rounds",
"to",
"use",
"."
] | 91529b6d0caec07d1452758d937e1e0745826139 | https://github.com/jpscaletti/authcode/blob/91529b6d0caec07d1452758d937e1e0745826139/authcode/auth.py#L140-L167 | train |
klmitch/turnstile | turnstile/config.py | Config.to_bool | def to_bool(value, do_raise=True):
"""Convert a string to a boolean value.
If the string consists of digits, the integer value of the string
is coerced to a boolean value. Otherwise, any of the strings "t",
"true", "on", "y", and "yes" are considered True and any of the
strings... | python | def to_bool(value, do_raise=True):
"""Convert a string to a boolean value.
If the string consists of digits, the integer value of the string
is coerced to a boolean value. Otherwise, any of the strings "t",
"true", "on", "y", and "yes" are considered True and any of the
strings... | [
"def",
"to_bool",
"(",
"value",
",",
"do_raise",
"=",
"True",
")",
":",
"value",
"=",
"value",
".",
"lower",
"(",
")",
"if",
"value",
".",
"isdigit",
"(",
")",
":",
"return",
"bool",
"(",
"int",
"(",
"value",
")",
")",
"if",
"value",
"in",
"_str_... | Convert a string to a boolean value.
If the string consists of digits, the integer value of the string
is coerced to a boolean value. Otherwise, any of the strings "t",
"true", "on", "y", and "yes" are considered True and any of the
strings "f", "false", "off", "n", and "no" are consid... | [
"Convert",
"a",
"string",
"to",
"a",
"boolean",
"value",
"."
] | 8fe9a359b45e505d3192ab193ecf9be177ab1a17 | https://github.com/klmitch/turnstile/blob/8fe9a359b45e505d3192ab193ecf9be177ab1a17/turnstile/config.py#L228-L254 | train |
BernardFW/bernard | src/bernard/layers/definitions.py | BaseLayer.become | async def become(self, layer_type: Type[L], request: 'Request') -> L:
"""
Transform this layer into another layer type
"""
raise ValueError('Cannot become "{}"'.format(layer_type.__name__)) | python | async def become(self, layer_type: Type[L], request: 'Request') -> L:
"""
Transform this layer into another layer type
"""
raise ValueError('Cannot become "{}"'.format(layer_type.__name__)) | [
"async",
"def",
"become",
"(",
"self",
",",
"layer_type",
":",
"Type",
"[",
"L",
"]",
",",
"request",
":",
"'Request'",
")",
"->",
"L",
":",
"raise",
"ValueError",
"(",
"'Cannot become \"{}\"'",
".",
"format",
"(",
"layer_type",
".",
"__name__",
")",
")"... | Transform this layer into another layer type | [
"Transform",
"this",
"layer",
"into",
"another",
"layer",
"type"
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/layers/definitions.py#L75-L80 | train |
BernardFW/bernard | src/bernard/layers/definitions.py | Text.become | async def become(self, layer_type: Type[L], request: 'Request'):
"""
Transforms the translatable string into an actual string and put it
inside a RawText.
"""
if layer_type != RawText:
super(Text, self).become(layer_type, request)
return RawText(await render(... | python | async def become(self, layer_type: Type[L], request: 'Request'):
"""
Transforms the translatable string into an actual string and put it
inside a RawText.
"""
if layer_type != RawText:
super(Text, self).become(layer_type, request)
return RawText(await render(... | [
"async",
"def",
"become",
"(",
"self",
",",
"layer_type",
":",
"Type",
"[",
"L",
"]",
",",
"request",
":",
"'Request'",
")",
":",
"if",
"layer_type",
"!=",
"RawText",
":",
"super",
"(",
"Text",
",",
"self",
")",
".",
"become",
"(",
"layer_type",
",",... | Transforms the translatable string into an actual string and put it
inside a RawText. | [
"Transforms",
"the",
"translatable",
"string",
"into",
"an",
"actual",
"string",
"and",
"put",
"it",
"inside",
"a",
"RawText",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/layers/definitions.py#L110-L118 | train |
BernardFW/bernard | src/bernard/engine/fsm.py | FSM._make_register | def _make_register(self) -> BaseRegisterStore:
"""
Make the register storage.
"""
s = settings.REGISTER_STORE
store_class = import_class(s['class'])
return store_class(**s['params']) | python | def _make_register(self) -> BaseRegisterStore:
"""
Make the register storage.
"""
s = settings.REGISTER_STORE
store_class = import_class(s['class'])
return store_class(**s['params']) | [
"def",
"_make_register",
"(",
"self",
")",
"->",
"BaseRegisterStore",
":",
"s",
"=",
"settings",
".",
"REGISTER_STORE",
"store_class",
"=",
"import_class",
"(",
"s",
"[",
"'class'",
"]",
")",
"return",
"store_class",
"(",
"**",
"s",
"[",
"'params'",
"]",
"... | Make the register storage. | [
"Make",
"the",
"register",
"storage",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/engine/fsm.py#L141-L148 | train |
BernardFW/bernard | src/bernard/engine/fsm.py | FSM._make_transitions | def _make_transitions(self) -> List[Transition]:
"""
Load the transitions file.
"""
module_name = settings.TRANSITIONS_MODULE
module_ = importlib.import_module(module_name)
return module_.transitions | python | def _make_transitions(self) -> List[Transition]:
"""
Load the transitions file.
"""
module_name = settings.TRANSITIONS_MODULE
module_ = importlib.import_module(module_name)
return module_.transitions | [
"def",
"_make_transitions",
"(",
"self",
")",
"->",
"List",
"[",
"Transition",
"]",
":",
"module_name",
"=",
"settings",
".",
"TRANSITIONS_MODULE",
"module_",
"=",
"importlib",
".",
"import_module",
"(",
"module_name",
")",
"return",
"module_",
".",
"transitions... | Load the transitions file. | [
"Load",
"the",
"transitions",
"file",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/engine/fsm.py#L150-L157 | train |
BernardFW/bernard | src/bernard/engine/fsm.py | FSM._make_allowed_states | def _make_allowed_states(self) -> Iterator[Text]:
"""
Sometimes we load states from the database. In order to avoid loading
an arbitrary class, we list here the state classes that are allowed.
"""
for trans in self.transitions:
yield trans.dest.name()
if... | python | def _make_allowed_states(self) -> Iterator[Text]:
"""
Sometimes we load states from the database. In order to avoid loading
an arbitrary class, we list here the state classes that are allowed.
"""
for trans in self.transitions:
yield trans.dest.name()
if... | [
"def",
"_make_allowed_states",
"(",
"self",
")",
"->",
"Iterator",
"[",
"Text",
"]",
":",
"for",
"trans",
"in",
"self",
".",
"transitions",
":",
"yield",
"trans",
".",
"dest",
".",
"name",
"(",
")",
"if",
"trans",
".",
"origin",
":",
"yield",
"trans",
... | Sometimes we load states from the database. In order to avoid loading
an arbitrary class, we list here the state classes that are allowed. | [
"Sometimes",
"we",
"load",
"states",
"from",
"the",
"database",
".",
"In",
"order",
"to",
"avoid",
"loading",
"an",
"arbitrary",
"class",
"we",
"list",
"here",
"the",
"state",
"classes",
"that",
"are",
"allowed",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/engine/fsm.py#L159-L169 | train |
BernardFW/bernard | src/bernard/engine/fsm.py | FSM._find_trigger | async def _find_trigger(self,
request: Request,
origin: Optional[Text]=None,
internal: bool=False) \
-> Tuple[
Optional[BaseTrigger],
Optional[Type[BaseState]],
Optional[bool],... | python | async def _find_trigger(self,
request: Request,
origin: Optional[Text]=None,
internal: bool=False) \
-> Tuple[
Optional[BaseTrigger],
Optional[Type[BaseState]],
Optional[bool],... | [
"async",
"def",
"_find_trigger",
"(",
"self",
",",
"request",
":",
"Request",
",",
"origin",
":",
"Optional",
"[",
"Text",
"]",
"=",
"None",
",",
"internal",
":",
"bool",
"=",
"False",
")",
"->",
"Tuple",
"[",
"Optional",
"[",
"BaseTrigger",
"]",
",",
... | Find the best trigger for this request, or go away. | [
"Find",
"the",
"best",
"trigger",
"for",
"this",
"request",
"or",
"go",
"away",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/engine/fsm.py#L171-L203 | train |
BernardFW/bernard | src/bernard/engine/fsm.py | FSM._confused_state | def _confused_state(self, request: Request) -> Type[BaseState]:
"""
If we're confused, find which state to call.
"""
origin = request.register.get(Register.STATE)
if origin in self._allowed_states:
try:
return import_class(origin)
except ... | python | def _confused_state(self, request: Request) -> Type[BaseState]:
"""
If we're confused, find which state to call.
"""
origin = request.register.get(Register.STATE)
if origin in self._allowed_states:
try:
return import_class(origin)
except ... | [
"def",
"_confused_state",
"(",
"self",
",",
"request",
":",
"Request",
")",
"->",
"Type",
"[",
"BaseState",
"]",
":",
"origin",
"=",
"request",
".",
"register",
".",
"get",
"(",
"Register",
".",
"STATE",
")",
"if",
"origin",
"in",
"self",
".",
"_allowe... | If we're confused, find which state to call. | [
"If",
"we",
"re",
"confused",
"find",
"which",
"state",
"to",
"call",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/engine/fsm.py#L206-L219 | train |
BernardFW/bernard | src/bernard/engine/fsm.py | FSM._build_state | async def _build_state(self,
request: Request,
message: BaseMessage,
responder: Responder) \
-> Tuple[
Optional[BaseState],
Optional[BaseTrigger],
Optional[bool],
]:
... | python | async def _build_state(self,
request: Request,
message: BaseMessage,
responder: Responder) \
-> Tuple[
Optional[BaseState],
Optional[BaseTrigger],
Optional[bool],
]:
... | [
"async",
"def",
"_build_state",
"(",
"self",
",",
"request",
":",
"Request",
",",
"message",
":",
"BaseMessage",
",",
"responder",
":",
"Responder",
")",
"->",
"Tuple",
"[",
"Optional",
"[",
"BaseState",
"]",
",",
"Optional",
"[",
"BaseTrigger",
"]",
",",
... | Build the state for this request. | [
"Build",
"the",
"state",
"for",
"this",
"request",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/engine/fsm.py#L221-L245 | train |
BernardFW/bernard | src/bernard/engine/fsm.py | FSM._run_state | async def _run_state(self, responder, state, trigger, request) \
-> BaseState:
"""
Execute the state, or if execution fails handle it.
"""
user_trigger = trigger
# noinspection PyBroadException
try:
if trigger:
await state.handle(... | python | async def _run_state(self, responder, state, trigger, request) \
-> BaseState:
"""
Execute the state, or if execution fails handle it.
"""
user_trigger = trigger
# noinspection PyBroadException
try:
if trigger:
await state.handle(... | [
"async",
"def",
"_run_state",
"(",
"self",
",",
"responder",
",",
"state",
",",
"trigger",
",",
"request",
")",
"->",
"BaseState",
":",
"user_trigger",
"=",
"trigger",
"try",
":",
"if",
"trigger",
":",
"await",
"state",
".",
"handle",
"(",
")",
"else",
... | Execute the state, or if execution fails handle it. | [
"Execute",
"the",
"state",
"or",
"if",
"execution",
"fails",
"handle",
"it",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/engine/fsm.py#L247-L281 | train |
BernardFW/bernard | src/bernard/engine/fsm.py | FSM._build_state_register | async def _build_state_register(self,
state: BaseState,
request: Request,
responder: Responder) -> Dict:
"""
Build the next register to store.
- The state is the name of the current s... | python | async def _build_state_register(self,
state: BaseState,
request: Request,
responder: Responder) -> Dict:
"""
Build the next register to store.
- The state is the name of the current s... | [
"async",
"def",
"_build_state_register",
"(",
"self",
",",
"state",
":",
"BaseState",
",",
"request",
":",
"Request",
",",
"responder",
":",
"Responder",
")",
"->",
"Dict",
":",
"return",
"{",
"Register",
".",
"STATE",
":",
"state",
".",
"name",
"(",
")"... | Build the next register to store.
- The state is the name of the current state
- The transition is made by all successive layers present in the
response. | [
"Build",
"the",
"next",
"register",
"to",
"store",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/engine/fsm.py#L283-L299 | train |
kata198/python-subprocess2 | subprocess2/simple.py | Simple.runGetResults | def runGetResults(cmd, stdout=True, stderr=True, encoding=sys.getdefaultencoding()):
'''
runGetResults - Simple method to run a command and return the results of the execution as a dict.
@param cmd <str/list> - String of command and arguments, or list of command and arguments
... | python | def runGetResults(cmd, stdout=True, stderr=True, encoding=sys.getdefaultencoding()):
'''
runGetResults - Simple method to run a command and return the results of the execution as a dict.
@param cmd <str/list> - String of command and arguments, or list of command and arguments
... | [
"def",
"runGetResults",
"(",
"cmd",
",",
"stdout",
"=",
"True",
",",
"stderr",
"=",
"True",
",",
"encoding",
"=",
"sys",
".",
"getdefaultencoding",
"(",
")",
")",
":",
"if",
"stderr",
"in",
"(",
"'stdout'",
",",
"subprocess",
".",
"STDOUT",
")",
":",
... | runGetResults - Simple method to run a command and return the results of the execution as a dict.
@param cmd <str/list> - String of command and arguments, or list of command and arguments
If cmd is a string, the command will be executed as if ran exactly as written in a shell. This mode su... | [
"runGetResults",
"-",
"Simple",
"method",
"to",
"run",
"a",
"command",
"and",
"return",
"the",
"results",
"of",
"the",
"execution",
"as",
"a",
"dict",
"."
] | 8544b0b651d8e14de9fdd597baa704182e248b01 | https://github.com/kata198/python-subprocess2/blob/8544b0b651d8e14de9fdd597baa704182e248b01/subprocess2/simple.py#L31-L144 | train |
BernardFW/bernard | src/bernard/storage/context/base.py | create_context_store | def create_context_store(name='default',
ttl=settings.CONTEXT_DEFAULT_TTL,
store=settings.CONTEXT_STORE) -> 'BaseContextStore':
"""
Create a context store. By default using the default configured context
store, but you can use a custom class if you want to u... | python | def create_context_store(name='default',
ttl=settings.CONTEXT_DEFAULT_TTL,
store=settings.CONTEXT_STORE) -> 'BaseContextStore':
"""
Create a context store. By default using the default configured context
store, but you can use a custom class if you want to u... | [
"def",
"create_context_store",
"(",
"name",
"=",
"'default'",
",",
"ttl",
"=",
"settings",
".",
"CONTEXT_DEFAULT_TTL",
",",
"store",
"=",
"settings",
".",
"CONTEXT_STORE",
")",
"->",
"'BaseContextStore'",
":",
"store_class",
"=",
"import_class",
"(",
"store",
"[... | Create a context store. By default using the default configured context
store, but you can use a custom class if you want to using the `store`
setting.
The time to live of each store (aka there is one per conversation) is
defined by the `ttl` value, which is also inferred by default from the
config... | [
"Create",
"a",
"context",
"store",
".",
"By",
"default",
"using",
"the",
"default",
"configured",
"context",
"store",
"but",
"you",
"can",
"use",
"a",
"custom",
"class",
"if",
"you",
"want",
"to",
"using",
"the",
"store",
"setting",
"."
] | 9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab | https://github.com/BernardFW/bernard/blob/9c55703e5ffe5717c9fa39793df59dbfa5b4c5ab/src/bernard/storage/context/base.py#L34-L68 | train |
AlejandroFrias/case-conversion | case_conversion/case_conversion.py | camelcase | def camelcase(text, acronyms=None):
"""Return text in camelCase style.
Args:
text: input string to convert case
detect_acronyms: should attempt to detect acronyms
acronyms: a list of acronyms to detect
>>> camelcase("hello world")
'helloWorld'
>>> camelcase("HELLO_HTML_WORL... | python | def camelcase(text, acronyms=None):
"""Return text in camelCase style.
Args:
text: input string to convert case
detect_acronyms: should attempt to detect acronyms
acronyms: a list of acronyms to detect
>>> camelcase("hello world")
'helloWorld'
>>> camelcase("HELLO_HTML_WORL... | [
"def",
"camelcase",
"(",
"text",
",",
"acronyms",
"=",
"None",
")",
":",
"words",
",",
"_case",
",",
"_sep",
"=",
"case_parse",
".",
"parse_case",
"(",
"text",
",",
"acronyms",
")",
"if",
"words",
":",
"words",
"[",
"0",
"]",
"=",
"words",
"[",
"0"... | Return text in camelCase style.
Args:
text: input string to convert case
detect_acronyms: should attempt to detect acronyms
acronyms: a list of acronyms to detect
>>> camelcase("hello world")
'helloWorld'
>>> camelcase("HELLO_HTML_WORLD", True, ["HTML"])
'helloHTMLWorld' | [
"Return",
"text",
"in",
"camelCase",
"style",
"."
] | 79ebce1403fbdac949b2da21b8f6fbe3234ddb31 | https://github.com/AlejandroFrias/case-conversion/blob/79ebce1403fbdac949b2da21b8f6fbe3234ddb31/case_conversion/case_conversion.py#L13-L29 | train |
AlejandroFrias/case-conversion | case_conversion/case_conversion.py | dotcase | def dotcase(text, acronyms=None):
"""Return text in dot.case style.
Args:
text: input string to convert case
detect_acronyms: should attempt to detect acronyms
acronyms: a list of acronyms to detect
>>> dotcase("hello world")
'hello.world'
>>> dotcase("helloHTMLWorld", True... | python | def dotcase(text, acronyms=None):
"""Return text in dot.case style.
Args:
text: input string to convert case
detect_acronyms: should attempt to detect acronyms
acronyms: a list of acronyms to detect
>>> dotcase("hello world")
'hello.world'
>>> dotcase("helloHTMLWorld", True... | [
"def",
"dotcase",
"(",
"text",
",",
"acronyms",
"=",
"None",
")",
":",
"words",
",",
"_case",
",",
"_sep",
"=",
"case_parse",
".",
"parse_case",
"(",
"text",
",",
"acronyms",
")",
"return",
"'.'",
".",
"join",
"(",
"[",
"w",
".",
"lower",
"(",
")",... | Return text in dot.case style.
Args:
text: input string to convert case
detect_acronyms: should attempt to detect acronyms
acronyms: a list of acronyms to detect
>>> dotcase("hello world")
'hello.world'
>>> dotcase("helloHTMLWorld", True, ["HTML"])
'hello.html.world' | [
"Return",
"text",
"in",
"dot",
".",
"case",
"style",
"."
] | 79ebce1403fbdac949b2da21b8f6fbe3234ddb31 | https://github.com/AlejandroFrias/case-conversion/blob/79ebce1403fbdac949b2da21b8f6fbe3234ddb31/case_conversion/case_conversion.py#L148-L162 | train |
AlejandroFrias/case-conversion | case_conversion/case_conversion.py | separate_words | def separate_words(text, acronyms=None):
"""Return text in "seperate words" style.
Args:
text: input string to convert case
detect_acronyms: should attempt to detect acronyms
acronyms: a list of acronyms to detect
>>> separate_words("HELLO_WORLD")
'HELLO WORLD'
>>> separate... | python | def separate_words(text, acronyms=None):
"""Return text in "seperate words" style.
Args:
text: input string to convert case
detect_acronyms: should attempt to detect acronyms
acronyms: a list of acronyms to detect
>>> separate_words("HELLO_WORLD")
'HELLO WORLD'
>>> separate... | [
"def",
"separate_words",
"(",
"text",
",",
"acronyms",
"=",
"None",
")",
":",
"words",
",",
"_case",
",",
"_sep",
"=",
"case_parse",
".",
"parse_case",
"(",
"text",
",",
"acronyms",
",",
"preserve_case",
"=",
"True",
")",
"return",
"' '",
".",
"join",
... | Return text in "seperate words" style.
Args:
text: input string to convert case
detect_acronyms: should attempt to detect acronyms
acronyms: a list of acronyms to detect
>>> separate_words("HELLO_WORLD")
'HELLO WORLD'
>>> separate_words("helloHTMLWorld", True, ["HTML"])
'he... | [
"Return",
"text",
"in",
"seperate",
"words",
"style",
"."
] | 79ebce1403fbdac949b2da21b8f6fbe3234ddb31 | https://github.com/AlejandroFrias/case-conversion/blob/79ebce1403fbdac949b2da21b8f6fbe3234ddb31/case_conversion/case_conversion.py#L165-L179 | train |
reanahub/reana-db | reana_db/database.py | init_db | def init_db():
"""Initialize the DB."""
import reana_db.models
if not database_exists(engine.url):
create_database(engine.url)
Base.metadata.create_all(bind=engine) | python | def init_db():
"""Initialize the DB."""
import reana_db.models
if not database_exists(engine.url):
create_database(engine.url)
Base.metadata.create_all(bind=engine) | [
"def",
"init_db",
"(",
")",
":",
"import",
"reana_db",
".",
"models",
"if",
"not",
"database_exists",
"(",
"engine",
".",
"url",
")",
":",
"create_database",
"(",
"engine",
".",
"url",
")",
"Base",
".",
"metadata",
".",
"create_all",
"(",
"bind",
"=",
... | Initialize the DB. | [
"Initialize",
"the",
"DB",
"."
] | 4efcb46d23af035689964d8c25a804c5a8f1dfc3 | https://github.com/reanahub/reana-db/blob/4efcb46d23af035689964d8c25a804c5a8f1dfc3/reana_db/database.py#L28-L33 | train |
greenelab/PathCORE-T | pathcore/network.py | _load_significant_pathways_file | def _load_significant_pathways_file(path_to_file):
"""Read in the significant pathways file as a
pandas.DataFrame.
"""
feature_pathway_df = pd.read_table(
path_to_file, header=0,
usecols=["feature", "side", "pathway"])
feature_pathway_df = feature_pathway_df.sort_values(
by=[... | python | def _load_significant_pathways_file(path_to_file):
"""Read in the significant pathways file as a
pandas.DataFrame.
"""
feature_pathway_df = pd.read_table(
path_to_file, header=0,
usecols=["feature", "side", "pathway"])
feature_pathway_df = feature_pathway_df.sort_values(
by=[... | [
"def",
"_load_significant_pathways_file",
"(",
"path_to_file",
")",
":",
"feature_pathway_df",
"=",
"pd",
".",
"read_table",
"(",
"path_to_file",
",",
"header",
"=",
"0",
",",
"usecols",
"=",
"[",
"\"feature\"",
",",
"\"side\"",
",",
"\"pathway\"",
"]",
")",
"... | Read in the significant pathways file as a
pandas.DataFrame. | [
"Read",
"in",
"the",
"significant",
"pathways",
"file",
"as",
"a",
"pandas",
".",
"DataFrame",
"."
] | 9d079d5ebffea2fe9fb9ab557588d51ad67d2c9c | https://github.com/greenelab/PathCORE-T/blob/9d079d5ebffea2fe9fb9ab557588d51ad67d2c9c/pathcore/network.py#L552-L561 | train |
greenelab/PathCORE-T | pathcore/network.py | _pathway_feature_permutation | def _pathway_feature_permutation(pathway_feature_tuples,
permutation_max_iters):
"""Permute the pathways across features for one side in the
network. Used in `permute_pathways_across_features`
Parameters
-----------
pathway_feature_tuples : list(tup(str, int))
... | python | def _pathway_feature_permutation(pathway_feature_tuples,
permutation_max_iters):
"""Permute the pathways across features for one side in the
network. Used in `permute_pathways_across_features`
Parameters
-----------
pathway_feature_tuples : list(tup(str, int))
... | [
"def",
"_pathway_feature_permutation",
"(",
"pathway_feature_tuples",
",",
"permutation_max_iters",
")",
":",
"pathways",
",",
"features",
"=",
"[",
"list",
"(",
"elements_at_position",
")",
"for",
"elements_at_position",
"in",
"zip",
"(",
"*",
"pathway_feature_tuples",... | Permute the pathways across features for one side in the
network. Used in `permute_pathways_across_features`
Parameters
-----------
pathway_feature_tuples : list(tup(str, int))
a tuple list [(pathway, feature)] where the pathway, feature pairing
indicates that a pathway was overrepresented ... | [
"Permute",
"the",
"pathways",
"across",
"features",
"for",
"one",
"side",
"in",
"the",
"network",
".",
"Used",
"in",
"permute_pathways_across_features"
] | 9d079d5ebffea2fe9fb9ab557588d51ad67d2c9c | https://github.com/greenelab/PathCORE-T/blob/9d079d5ebffea2fe9fb9ab557588d51ad67d2c9c/pathcore/network.py#L568-L652 | train |
greenelab/PathCORE-T | pathcore/network.py | CoNetwork.weight_by_edge_odds_ratios | def weight_by_edge_odds_ratios(self,
edges_expected_weight,
flag_as_significant):
"""Applied during the permutation test. Update the edges in the
network to be weighted by their odds ratios. The odds ratio measures
how unexpec... | python | def weight_by_edge_odds_ratios(self,
edges_expected_weight,
flag_as_significant):
"""Applied during the permutation test. Update the edges in the
network to be weighted by their odds ratios. The odds ratio measures
how unexpec... | [
"def",
"weight_by_edge_odds_ratios",
"(",
"self",
",",
"edges_expected_weight",
",",
"flag_as_significant",
")",
":",
"for",
"edge_id",
",",
"expected_weight",
"in",
"edges_expected_weight",
":",
"edge_obj",
"=",
"self",
".",
"edges",
"[",
"edge_id",
"]",
"edge_obj"... | Applied during the permutation test. Update the edges in the
network to be weighted by their odds ratios. The odds ratio measures
how unexpected the observed edge weight is based on the expected
weight.
Parameters
-----------
edges_expected_weight : list(tup(int, int), f... | [
"Applied",
"during",
"the",
"permutation",
"test",
".",
"Update",
"the",
"edges",
"in",
"the",
"network",
"to",
"be",
"weighted",
"by",
"their",
"odds",
"ratios",
".",
"The",
"odds",
"ratio",
"measures",
"how",
"unexpected",
"the",
"observed",
"edge",
"weigh... | 9d079d5ebffea2fe9fb9ab557588d51ad67d2c9c | https://github.com/greenelab/PathCORE-T/blob/9d079d5ebffea2fe9fb9ab557588d51ad67d2c9c/pathcore/network.py#L223-L247 | train |
greenelab/PathCORE-T | pathcore/network.py | CoNetwork.aggregate | def aggregate(self, merge):
"""Combine this network with another network. The aggregation step
takes the union of the edges in the two networks, where we take the
sum of weights for edges common to both networks.
Parameters
-----------
merge : CoNetwork
the CoN... | python | def aggregate(self, merge):
"""Combine this network with another network. The aggregation step
takes the union of the edges in the two networks, where we take the
sum of weights for edges common to both networks.
Parameters
-----------
merge : CoNetwork
the CoN... | [
"def",
"aggregate",
"(",
"self",
",",
"merge",
")",
":",
"self",
".",
"features",
"=",
"set",
"(",
")",
"self",
".",
"n_features",
"+=",
"merge",
".",
"n_features",
"vertex_id_conversion",
"=",
"self",
".",
"convert_pathway_mapping",
"(",
"merge",
".",
"pa... | Combine this network with another network. The aggregation step
takes the union of the edges in the two networks, where we take the
sum of weights for edges common to both networks.
Parameters
-----------
merge : CoNetwork
the CoNetwork object being merged into the cur... | [
"Combine",
"this",
"network",
"with",
"another",
"network",
".",
"The",
"aggregation",
"step",
"takes",
"the",
"union",
"of",
"the",
"edges",
"in",
"the",
"two",
"networks",
"where",
"we",
"take",
"the",
"sum",
"of",
"weights",
"for",
"edges",
"common",
"t... | 9d079d5ebffea2fe9fb9ab557588d51ad67d2c9c | https://github.com/greenelab/PathCORE-T/blob/9d079d5ebffea2fe9fb9ab557588d51ad67d2c9c/pathcore/network.py#L249-L276 | train |
greenelab/PathCORE-T | pathcore/network.py | CoNetwork.edge_tuple | def edge_tuple(self, vertex0_id, vertex1_id):
"""To avoid duplicate edges where the vertex ids are reversed,
we maintain that the vertex ids are ordered so that the corresponding
pathway names are alphabetical.
Parameters
-----------
vertex0_id : int
one vertex... | python | def edge_tuple(self, vertex0_id, vertex1_id):
"""To avoid duplicate edges where the vertex ids are reversed,
we maintain that the vertex ids are ordered so that the corresponding
pathway names are alphabetical.
Parameters
-----------
vertex0_id : int
one vertex... | [
"def",
"edge_tuple",
"(",
"self",
",",
"vertex0_id",
",",
"vertex1_id",
")",
":",
"pw0",
"=",
"self",
".",
"__getitem__",
"(",
"vertex0_id",
")",
"pw1",
"=",
"self",
".",
"__getitem__",
"(",
"vertex1_id",
")",
"if",
"not",
"pw0",
"or",
"not",
"pw1",
":... | To avoid duplicate edges where the vertex ids are reversed,
we maintain that the vertex ids are ordered so that the corresponding
pathway names are alphabetical.
Parameters
-----------
vertex0_id : int
one vertex in the edge
vertex1_id : int
the other... | [
"To",
"avoid",
"duplicate",
"edges",
"where",
"the",
"vertex",
"ids",
"are",
"reversed",
"we",
"maintain",
"that",
"the",
"vertex",
"ids",
"are",
"ordered",
"so",
"that",
"the",
"corresponding",
"pathway",
"names",
"are",
"alphabetical",
"."
] | 9d079d5ebffea2fe9fb9ab557588d51ad67d2c9c | https://github.com/greenelab/PathCORE-T/blob/9d079d5ebffea2fe9fb9ab557588d51ad67d2c9c/pathcore/network.py#L332-L360 | train |
greenelab/PathCORE-T | pathcore/network.py | CoNetwork.add_pathway | def add_pathway(self, pathway):
"""Updates `self.pathways` and `self.n_pathways.`
Parameters
-----------
pathway : str
the pathway to add to the network.
"""
if pathway not in self.pathways:
self.pathways[pathway] = self.n_pathways
self.... | python | def add_pathway(self, pathway):
"""Updates `self.pathways` and `self.n_pathways.`
Parameters
-----------
pathway : str
the pathway to add to the network.
"""
if pathway not in self.pathways:
self.pathways[pathway] = self.n_pathways
self.... | [
"def",
"add_pathway",
"(",
"self",
",",
"pathway",
")",
":",
"if",
"pathway",
"not",
"in",
"self",
".",
"pathways",
":",
"self",
".",
"pathways",
"[",
"pathway",
"]",
"=",
"self",
".",
"n_pathways",
"self",
".",
"n_pathways",
"+=",
"1",
"return",
"self... | Updates `self.pathways` and `self.n_pathways.`
Parameters
-----------
pathway : str
the pathway to add to the network. | [
"Updates",
"self",
".",
"pathways",
"and",
"self",
".",
"n_pathways",
"."
] | 9d079d5ebffea2fe9fb9ab557588d51ad67d2c9c | https://github.com/greenelab/PathCORE-T/blob/9d079d5ebffea2fe9fb9ab557588d51ad67d2c9c/pathcore/network.py#L362-L373 | train |
greenelab/PathCORE-T | pathcore/network.py | CoNetwork.get_edge_pathways | def get_edge_pathways(self, edge_id):
"""Get the pathways associated with an edge.
Parameters
-----------
edge_id : tup(int, int)
Returns
-----------
tup(str, str)|None, the edge as a pair of 2 pathways if the edge id
is in this network
"""
... | python | def get_edge_pathways(self, edge_id):
"""Get the pathways associated with an edge.
Parameters
-----------
edge_id : tup(int, int)
Returns
-----------
tup(str, str)|None, the edge as a pair of 2 pathways if the edge id
is in this network
"""
... | [
"def",
"get_edge_pathways",
"(",
"self",
",",
"edge_id",
")",
":",
"vertex0_id",
",",
"vertex1_id",
"=",
"edge_id",
"pw0",
"=",
"self",
".",
"get_pathway_from_vertex_id",
"(",
"vertex0_id",
")",
"pw1",
"=",
"self",
".",
"get_pathway_from_vertex_id",
"(",
"vertex... | Get the pathways associated with an edge.
Parameters
-----------
edge_id : tup(int, int)
Returns
-----------
tup(str, str)|None, the edge as a pair of 2 pathways if the edge id
is in this network | [
"Get",
"the",
"pathways",
"associated",
"with",
"an",
"edge",
"."
] | 9d079d5ebffea2fe9fb9ab557588d51ad67d2c9c | https://github.com/greenelab/PathCORE-T/blob/9d079d5ebffea2fe9fb9ab557588d51ad67d2c9c/pathcore/network.py#L388-L405 | train |
greenelab/PathCORE-T | pathcore/network.py | CoNetwork.get_vertex_obj_from_pathway | def get_vertex_obj_from_pathway(self, pathway):
"""Get the vertex object that corresponds to a pathway name
Parameters
-----------
pathway : str
Returns
-----------
Vertex|None, the Vertex obj if the pathway is in this network
"""
if pathway in s... | python | def get_vertex_obj_from_pathway(self, pathway):
"""Get the vertex object that corresponds to a pathway name
Parameters
-----------
pathway : str
Returns
-----------
Vertex|None, the Vertex obj if the pathway is in this network
"""
if pathway in s... | [
"def",
"get_vertex_obj_from_pathway",
"(",
"self",
",",
"pathway",
")",
":",
"if",
"pathway",
"in",
"self",
".",
"pathways",
":",
"vertex_id",
"=",
"self",
".",
"pathways",
"[",
"pathway",
"]",
"return",
"self",
".",
"vertices",
"[",
"vertex_id",
"]",
"els... | Get the vertex object that corresponds to a pathway name
Parameters
-----------
pathway : str
Returns
-----------
Vertex|None, the Vertex obj if the pathway is in this network | [
"Get",
"the",
"vertex",
"object",
"that",
"corresponds",
"to",
"a",
"pathway",
"name"
] | 9d079d5ebffea2fe9fb9ab557588d51ad67d2c9c | https://github.com/greenelab/PathCORE-T/blob/9d079d5ebffea2fe9fb9ab557588d51ad67d2c9c/pathcore/network.py#L422-L437 | train |
greenelab/PathCORE-T | pathcore/network.py | CoNetwork.get_adjacent_pathways | def get_adjacent_pathways(self, pathway):
"""Get the pathways adjacent to this pathway in the network
Parameters
-----------
pathway : str
Returns
-----------
list(str), a list of pathways adjacent to the input pathway
"""
vertex_id = self.pathwa... | python | def get_adjacent_pathways(self, pathway):
"""Get the pathways adjacent to this pathway in the network
Parameters
-----------
pathway : str
Returns
-----------
list(str), a list of pathways adjacent to the input pathway
"""
vertex_id = self.pathwa... | [
"def",
"get_adjacent_pathways",
"(",
"self",
",",
"pathway",
")",
":",
"vertex_id",
"=",
"self",
".",
"pathways",
"[",
"pathway",
"]",
"adjacent",
"=",
"self",
".",
"vertices",
"[",
"vertex_id",
"]",
".",
"get_adjacent_vertex_ids",
"(",
")",
"adjacent_pathways... | Get the pathways adjacent to this pathway in the network
Parameters
-----------
pathway : str
Returns
-----------
list(str), a list of pathways adjacent to the input pathway | [
"Get",
"the",
"pathways",
"adjacent",
"to",
"this",
"pathway",
"in",
"the",
"network"
] | 9d079d5ebffea2fe9fb9ab557588d51ad67d2c9c | https://github.com/greenelab/PathCORE-T/blob/9d079d5ebffea2fe9fb9ab557588d51ad67d2c9c/pathcore/network.py#L439-L456 | train |
greenelab/PathCORE-T | pathcore/network.py | CoNetwork.to_dataframe | def to_dataframe(self, drop_weights_below=0, whitelist=None):
""" Conversion of the network to a pandas.DataFrame.
Parameters
-----------
drop_weights_below : int (default=0)
specify an edge weight threshold - remove all edges with weight
below this value
whi... | python | def to_dataframe(self, drop_weights_below=0, whitelist=None):
""" Conversion of the network to a pandas.DataFrame.
Parameters
-----------
drop_weights_below : int (default=0)
specify an edge weight threshold - remove all edges with weight
below this value
whi... | [
"def",
"to_dataframe",
"(",
"self",
",",
"drop_weights_below",
"=",
"0",
",",
"whitelist",
"=",
"None",
")",
":",
"network_df_cols",
"=",
"[",
"\"pw0\"",
",",
"\"pw1\"",
",",
"\"weight\"",
"]",
"if",
"self",
".",
"features",
":",
"network_df_cols",
".",
"a... | Conversion of the network to a pandas.DataFrame.
Parameters
-----------
drop_weights_below : int (default=0)
specify an edge weight threshold - remove all edges with weight
below this value
whitelist : [set|list](tup(int, int))|None (default=None)
option to... | [
"Conversion",
"of",
"the",
"network",
"to",
"a",
"pandas",
".",
"DataFrame",
"."
] | 9d079d5ebffea2fe9fb9ab557588d51ad67d2c9c | https://github.com/greenelab/PathCORE-T/blob/9d079d5ebffea2fe9fb9ab557588d51ad67d2c9c/pathcore/network.py#L458-L501 | train |
greenelab/PathCORE-T | pathcore/network.py | CoNetwork._add_edge_to_vertex | def _add_edge_to_vertex(self, vertex_id, edge):
"""Adds the edge to the Vertex object's `edges` dictionary
"""
connected_to = edge.connected_to(vertex_id)
if vertex_id not in self.vertices:
vertex_obj = Vertex(vertex_id)
self.vertices[vertex_id] = vertex_obj
... | python | def _add_edge_to_vertex(self, vertex_id, edge):
"""Adds the edge to the Vertex object's `edges` dictionary
"""
connected_to = edge.connected_to(vertex_id)
if vertex_id not in self.vertices:
vertex_obj = Vertex(vertex_id)
self.vertices[vertex_id] = vertex_obj
... | [
"def",
"_add_edge_to_vertex",
"(",
"self",
",",
"vertex_id",
",",
"edge",
")",
":",
"connected_to",
"=",
"edge",
".",
"connected_to",
"(",
"vertex_id",
")",
"if",
"vertex_id",
"not",
"in",
"self",
".",
"vertices",
":",
"vertex_obj",
"=",
"Vertex",
"(",
"ve... | Adds the edge to the Vertex object's `edges` dictionary | [
"Adds",
"the",
"edge",
"to",
"the",
"Vertex",
"object",
"s",
"edges",
"dictionary"
] | 9d079d5ebffea2fe9fb9ab557588d51ad67d2c9c | https://github.com/greenelab/PathCORE-T/blob/9d079d5ebffea2fe9fb9ab557588d51ad67d2c9c/pathcore/network.py#L503-L510 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.