repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
GoogleCloudPlatform/datastore-ndb-python | ndb/key.py | Key.reference | def reference(self):
"""Return the Reference object for this Key.
This is a entity_pb.Reference instance -- a protocol buffer class
used by the lower-level API to the datastore.
NOTE: The caller should not mutate the return value.
"""
if self.__reference is None:
self.__reference = _Cons... | python | def reference(self):
"""Return the Reference object for this Key.
This is a entity_pb.Reference instance -- a protocol buffer class
used by the lower-level API to the datastore.
NOTE: The caller should not mutate the return value.
"""
if self.__reference is None:
self.__reference = _Cons... | [
"def",
"reference",
"(",
"self",
")",
":",
"if",
"self",
".",
"__reference",
"is",
"None",
":",
"self",
".",
"__reference",
"=",
"_ConstructReference",
"(",
"self",
".",
"__class__",
",",
"pairs",
"=",
"self",
".",
"__pairs",
",",
"app",
"=",
"self",
"... | Return the Reference object for this Key.
This is a entity_pb.Reference instance -- a protocol buffer class
used by the lower-level API to the datastore.
NOTE: The caller should not mutate the return value. | [
"Return",
"the",
"Reference",
"object",
"for",
"this",
"Key",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L534-L547 |
GoogleCloudPlatform/datastore-ndb-python | ndb/key.py | Key.urlsafe | def urlsafe(self):
"""Return a url-safe string encoding this Key's Reference.
This string is compatible with other APIs and languages and with
the strings used to represent Keys in GQL and in the App Engine
Admin Console.
"""
# This is 3-4x faster than urlsafe_b64decode()
urlsafe = base64.b... | python | def urlsafe(self):
"""Return a url-safe string encoding this Key's Reference.
This string is compatible with other APIs and languages and with
the strings used to represent Keys in GQL and in the App Engine
Admin Console.
"""
# This is 3-4x faster than urlsafe_b64decode()
urlsafe = base64.b... | [
"def",
"urlsafe",
"(",
"self",
")",
":",
"# This is 3-4x faster than urlsafe_b64decode()",
"urlsafe",
"=",
"base64",
".",
"b64encode",
"(",
"self",
".",
"reference",
"(",
")",
".",
"Encode",
"(",
")",
")",
"return",
"urlsafe",
".",
"rstrip",
"(",
"'='",
")",... | Return a url-safe string encoding this Key's Reference.
This string is compatible with other APIs and languages and with
the strings used to represent Keys in GQL and in the App Engine
Admin Console. | [
"Return",
"a",
"url",
"-",
"safe",
"string",
"encoding",
"this",
"Key",
"s",
"Reference",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L553-L562 |
GoogleCloudPlatform/datastore-ndb-python | ndb/key.py | Key.get_async | def get_async(self, **ctx_options):
"""Return a Future whose result is the entity for this Key.
If no such entity exists, a Future is still returned, and the
Future's eventual return result be None.
"""
from . import model, tasklets
ctx = tasklets.get_context()
cls = model.Model._kind_map.g... | python | def get_async(self, **ctx_options):
"""Return a Future whose result is the entity for this Key.
If no such entity exists, a Future is still returned, and the
Future's eventual return result be None.
"""
from . import model, tasklets
ctx = tasklets.get_context()
cls = model.Model._kind_map.g... | [
"def",
"get_async",
"(",
"self",
",",
"*",
"*",
"ctx_options",
")",
":",
"from",
".",
"import",
"model",
",",
"tasklets",
"ctx",
"=",
"tasklets",
".",
"get_context",
"(",
")",
"cls",
"=",
"model",
".",
"Model",
".",
"_kind_map",
".",
"get",
"(",
"sel... | Return a Future whose result is the entity for this Key.
If no such entity exists, a Future is still returned, and the
Future's eventual return result be None. | [
"Return",
"a",
"Future",
"whose",
"result",
"is",
"the",
"entity",
"for",
"this",
"Key",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L574-L591 |
GoogleCloudPlatform/datastore-ndb-python | ndb/key.py | Key.delete_async | def delete_async(self, **ctx_options):
"""Schedule deletion of the entity for this Key.
This returns a Future, whose result becomes available once the
deletion is complete. If no such entity exists, a Future is still
returned. In all cases the Future's result is None (i.e. there is
no way to tell... | python | def delete_async(self, **ctx_options):
"""Schedule deletion of the entity for this Key.
This returns a Future, whose result becomes available once the
deletion is complete. If no such entity exists, a Future is still
returned. In all cases the Future's result is None (i.e. there is
no way to tell... | [
"def",
"delete_async",
"(",
"self",
",",
"*",
"*",
"ctx_options",
")",
":",
"from",
".",
"import",
"tasklets",
",",
"model",
"ctx",
"=",
"tasklets",
".",
"get_context",
"(",
")",
"cls",
"=",
"model",
".",
"Model",
".",
"_kind_map",
".",
"get",
"(",
"... | Schedule deletion of the entity for this Key.
This returns a Future, whose result becomes available once the
deletion is complete. If no such entity exists, a Future is still
returned. In all cases the Future's result is None (i.e. there is
no way to tell whether the entity existed or not). | [
"Schedule",
"deletion",
"of",
"the",
"entity",
"for",
"this",
"Key",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/key.py#L600-L619 |
GoogleCloudPlatform/datastore-ndb-python | ndb/tasklets.py | add_flow_exception | def add_flow_exception(exc):
"""Add an exception that should not be logged.
The argument must be a subclass of Exception.
"""
global _flow_exceptions
if not isinstance(exc, type) or not issubclass(exc, Exception):
raise TypeError('Expected an Exception subclass, got %r' % (exc,))
as_set = set(_flow_exc... | python | def add_flow_exception(exc):
"""Add an exception that should not be logged.
The argument must be a subclass of Exception.
"""
global _flow_exceptions
if not isinstance(exc, type) or not issubclass(exc, Exception):
raise TypeError('Expected an Exception subclass, got %r' % (exc,))
as_set = set(_flow_exc... | [
"def",
"add_flow_exception",
"(",
"exc",
")",
":",
"global",
"_flow_exceptions",
"if",
"not",
"isinstance",
"(",
"exc",
",",
"type",
")",
"or",
"not",
"issubclass",
"(",
"exc",
",",
"Exception",
")",
":",
"raise",
"TypeError",
"(",
"'Expected an Exception subc... | Add an exception that should not be logged.
The argument must be a subclass of Exception. | [
"Add",
"an",
"exception",
"that",
"should",
"not",
"be",
"logged",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/tasklets.py#L201-L211 |
GoogleCloudPlatform/datastore-ndb-python | ndb/tasklets.py | _init_flow_exceptions | def _init_flow_exceptions():
"""Internal helper to initialize _flow_exceptions.
This automatically adds webob.exc.HTTPException, if it can be imported.
"""
global _flow_exceptions
_flow_exceptions = ()
add_flow_exception(datastore_errors.Rollback)
try:
from webob import exc
except ImportError:
... | python | def _init_flow_exceptions():
"""Internal helper to initialize _flow_exceptions.
This automatically adds webob.exc.HTTPException, if it can be imported.
"""
global _flow_exceptions
_flow_exceptions = ()
add_flow_exception(datastore_errors.Rollback)
try:
from webob import exc
except ImportError:
... | [
"def",
"_init_flow_exceptions",
"(",
")",
":",
"global",
"_flow_exceptions",
"_flow_exceptions",
"=",
"(",
")",
"add_flow_exception",
"(",
"datastore_errors",
".",
"Rollback",
")",
"try",
":",
"from",
"webob",
"import",
"exc",
"except",
"ImportError",
":",
"pass",... | Internal helper to initialize _flow_exceptions.
This automatically adds webob.exc.HTTPException, if it can be imported. | [
"Internal",
"helper",
"to",
"initialize",
"_flow_exceptions",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/tasklets.py#L214-L227 |
GoogleCloudPlatform/datastore-ndb-python | ndb/tasklets.py | sleep | def sleep(dt):
"""Public function to sleep some time.
Example:
yield tasklets.sleep(0.5) # Sleep for half a sec.
"""
fut = Future('sleep(%.3f)' % dt)
eventloop.queue_call(dt, fut.set_result, None)
return fut | python | def sleep(dt):
"""Public function to sleep some time.
Example:
yield tasklets.sleep(0.5) # Sleep for half a sec.
"""
fut = Future('sleep(%.3f)' % dt)
eventloop.queue_call(dt, fut.set_result, None)
return fut | [
"def",
"sleep",
"(",
"dt",
")",
":",
"fut",
"=",
"Future",
"(",
"'sleep(%.3f)'",
"%",
"dt",
")",
"eventloop",
".",
"queue_call",
"(",
"dt",
",",
"fut",
".",
"set_result",
",",
"None",
")",
"return",
"fut"
] | Public function to sleep some time.
Example:
yield tasklets.sleep(0.5) # Sleep for half a sec. | [
"Public",
"function",
"to",
"sleep",
"some",
"time",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/tasklets.py#L536-L544 |
GoogleCloudPlatform/datastore-ndb-python | ndb/tasklets.py | _transfer_result | def _transfer_result(fut1, fut2):
"""Helper to transfer result or errors from one Future to another."""
exc = fut1.get_exception()
if exc is not None:
tb = fut1.get_traceback()
fut2.set_exception(exc, tb)
else:
val = fut1.get_result()
fut2.set_result(val) | python | def _transfer_result(fut1, fut2):
"""Helper to transfer result or errors from one Future to another."""
exc = fut1.get_exception()
if exc is not None:
tb = fut1.get_traceback()
fut2.set_exception(exc, tb)
else:
val = fut1.get_result()
fut2.set_result(val) | [
"def",
"_transfer_result",
"(",
"fut1",
",",
"fut2",
")",
":",
"exc",
"=",
"fut1",
".",
"get_exception",
"(",
")",
"if",
"exc",
"is",
"not",
"None",
":",
"tb",
"=",
"fut1",
".",
"get_traceback",
"(",
")",
"fut2",
".",
"set_exception",
"(",
"exc",
","... | Helper to transfer result or errors from one Future to another. | [
"Helper",
"to",
"transfer",
"result",
"or",
"errors",
"from",
"one",
"Future",
"to",
"another",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/tasklets.py#L897-L905 |
GoogleCloudPlatform/datastore-ndb-python | ndb/tasklets.py | synctasklet | def synctasklet(func):
"""Decorator to run a function as a tasklet when called.
Use this to wrap a request handler function that will be called by
some web application framework (e.g. a Django view function or a
webapp.RequestHandler.get method).
"""
taskletfunc = tasklet(func) # wrap at declaration time.... | python | def synctasklet(func):
"""Decorator to run a function as a tasklet when called.
Use this to wrap a request handler function that will be called by
some web application framework (e.g. a Django view function or a
webapp.RequestHandler.get method).
"""
taskletfunc = tasklet(func) # wrap at declaration time.... | [
"def",
"synctasklet",
"(",
"func",
")",
":",
"taskletfunc",
"=",
"tasklet",
"(",
"func",
")",
"# wrap at declaration time.",
"@",
"utils",
".",
"wrapping",
"(",
"func",
")",
"def",
"synctasklet_wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwds",
")",
":",
... | Decorator to run a function as a tasklet when called.
Use this to wrap a request handler function that will be called by
some web application framework (e.g. a Django view function or a
webapp.RequestHandler.get method). | [
"Decorator",
"to",
"run",
"a",
"function",
"as",
"a",
"tasklet",
"when",
"called",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/tasklets.py#L1074-L1088 |
GoogleCloudPlatform/datastore-ndb-python | ndb/tasklets.py | toplevel | def toplevel(func):
"""A sync tasklet that sets a fresh default Context.
Use this for toplevel view functions such as
webapp.RequestHandler.get() or Django view functions.
"""
synctaskletfunc = synctasklet(func) # wrap at declaration time.
@utils.wrapping(func)
def add_context_wrapper(*args, **kwds):
... | python | def toplevel(func):
"""A sync tasklet that sets a fresh default Context.
Use this for toplevel view functions such as
webapp.RequestHandler.get() or Django view functions.
"""
synctaskletfunc = synctasklet(func) # wrap at declaration time.
@utils.wrapping(func)
def add_context_wrapper(*args, **kwds):
... | [
"def",
"toplevel",
"(",
"func",
")",
":",
"synctaskletfunc",
"=",
"synctasklet",
"(",
"func",
")",
"# wrap at declaration time.",
"@",
"utils",
".",
"wrapping",
"(",
"func",
")",
"def",
"add_context_wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwds",
")",
"... | A sync tasklet that sets a fresh default Context.
Use this for toplevel view functions such as
webapp.RequestHandler.get() or Django view functions. | [
"A",
"sync",
"tasklet",
"that",
"sets",
"a",
"fresh",
"default",
"Context",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/tasklets.py#L1091-L1113 |
GoogleCloudPlatform/datastore-ndb-python | ndb/tasklets.py | _make_cloud_datastore_context | def _make_cloud_datastore_context(app_id, external_app_ids=()):
"""Creates a new context to connect to a remote Cloud Datastore instance.
This should only be used outside of Google App Engine.
Args:
app_id: The application id to connect to. This differs from the project
id as it may have an additional... | python | def _make_cloud_datastore_context(app_id, external_app_ids=()):
"""Creates a new context to connect to a remote Cloud Datastore instance.
This should only be used outside of Google App Engine.
Args:
app_id: The application id to connect to. This differs from the project
id as it may have an additional... | [
"def",
"_make_cloud_datastore_context",
"(",
"app_id",
",",
"external_app_ids",
"=",
"(",
")",
")",
":",
"from",
".",
"import",
"model",
"# Late import to deal with circular imports.",
"# Late import since it might not exist.",
"if",
"not",
"datastore_pbs",
".",
"_CLOUD_DAT... | Creates a new context to connect to a remote Cloud Datastore instance.
This should only be used outside of Google App Engine.
Args:
app_id: The application id to connect to. This differs from the project
id as it may have an additional prefix, e.g. "s~" or "e~".
external_app_ids: A list of apps that... | [
"Creates",
"a",
"new",
"context",
"to",
"connect",
"to",
"a",
"remote",
"Cloud",
"Datastore",
"instance",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/tasklets.py#L1183-L1249 |
GoogleCloudPlatform/datastore-ndb-python | ndb/msgprop.py | _analyze_indexed_fields | def _analyze_indexed_fields(indexed_fields):
"""Internal helper to check a list of indexed fields.
Args:
indexed_fields: A list of names, possibly dotted names.
(A dotted name is a string containing names separated by dots,
e.g. 'foo.bar.baz'. An undotted name is a string containing no
dots, e.g. 'foo'... | python | def _analyze_indexed_fields(indexed_fields):
"""Internal helper to check a list of indexed fields.
Args:
indexed_fields: A list of names, possibly dotted names.
(A dotted name is a string containing names separated by dots,
e.g. 'foo.bar.baz'. An undotted name is a string containing no
dots, e.g. 'foo'... | [
"def",
"_analyze_indexed_fields",
"(",
"indexed_fields",
")",
":",
"result",
"=",
"{",
"}",
"for",
"field_name",
"in",
"indexed_fields",
":",
"if",
"not",
"isinstance",
"(",
"field_name",
",",
"basestring",
")",
":",
"raise",
"TypeError",
"(",
"'Field names must... | Internal helper to check a list of indexed fields.
Args:
indexed_fields: A list of names, possibly dotted names.
(A dotted name is a string containing names separated by dots,
e.g. 'foo.bar.baz'. An undotted name is a string containing no
dots, e.g. 'foo'.)
Returns:
A dict whose keys are undotted ... | [
"Internal",
"helper",
"to",
"check",
"a",
"list",
"of",
"indexed",
"fields",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/msgprop.py#L201-L245 |
GoogleCloudPlatform/datastore-ndb-python | ndb/msgprop.py | _make_model_class | def _make_model_class(message_type, indexed_fields, **props):
"""Construct a Model subclass corresponding to a Message subclass.
Args:
message_type: A Message subclass.
indexed_fields: A list of dotted and undotted field names.
**props: Additional properties with which to seed the class.
Returns:
... | python | def _make_model_class(message_type, indexed_fields, **props):
"""Construct a Model subclass corresponding to a Message subclass.
Args:
message_type: A Message subclass.
indexed_fields: A list of dotted and undotted field names.
**props: Additional properties with which to seed the class.
Returns:
... | [
"def",
"_make_model_class",
"(",
"message_type",
",",
"indexed_fields",
",",
"*",
"*",
"props",
")",
":",
"analyzed",
"=",
"_analyze_indexed_fields",
"(",
"indexed_fields",
")",
"for",
"field_name",
",",
"sub_fields",
"in",
"analyzed",
".",
"iteritems",
"(",
")"... | Construct a Model subclass corresponding to a Message subclass.
Args:
message_type: A Message subclass.
indexed_fields: A list of dotted and undotted field names.
**props: Additional properties with which to seed the class.
Returns:
A Model subclass whose properties correspond to those fields of
... | [
"Construct",
"a",
"Model",
"subclass",
"corresponding",
"to",
"a",
"Message",
"subclass",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/msgprop.py#L248-L299 |
GoogleCloudPlatform/datastore-ndb-python | ndb/msgprop.py | _message_to_entity | def _message_to_entity(msg, modelclass):
"""Recursive helper for _to_base_type() to convert a message to an entity.
Args:
msg: A Message instance.
modelclass: A Model subclass.
Returns:
An instance of modelclass.
"""
ent = modelclass()
for prop_name, prop in modelclass._properties.iteritems():... | python | def _message_to_entity(msg, modelclass):
"""Recursive helper for _to_base_type() to convert a message to an entity.
Args:
msg: A Message instance.
modelclass: A Model subclass.
Returns:
An instance of modelclass.
"""
ent = modelclass()
for prop_name, prop in modelclass._properties.iteritems():... | [
"def",
"_message_to_entity",
"(",
"msg",
",",
"modelclass",
")",
":",
"ent",
"=",
"modelclass",
"(",
")",
"for",
"prop_name",
",",
"prop",
"in",
"modelclass",
".",
"_properties",
".",
"iteritems",
"(",
")",
":",
"if",
"prop",
".",
"_code_name",
"==",
"'b... | Recursive helper for _to_base_type() to convert a message to an entity.
Args:
msg: A Message instance.
modelclass: A Model subclass.
Returns:
An instance of modelclass. | [
"Recursive",
"helper",
"for",
"_to_base_type",
"()",
"to",
"convert",
"a",
"message",
"to",
"an",
"entity",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/msgprop.py#L396-L417 |
GoogleCloudPlatform/datastore-ndb-python | ndb/msgprop.py | _projected_entity_to_message | def _projected_entity_to_message(ent, message_type):
"""Recursive helper for _from_base_type() to convert an entity to a message.
Args:
ent: A Model instance.
message_type: A Message subclass.
Returns:
An instance of message_type.
"""
msg = message_type()
analyzed = _analyze_indexed_fields(ent... | python | def _projected_entity_to_message(ent, message_type):
"""Recursive helper for _from_base_type() to convert an entity to a message.
Args:
ent: A Model instance.
message_type: A Message subclass.
Returns:
An instance of message_type.
"""
msg = message_type()
analyzed = _analyze_indexed_fields(ent... | [
"def",
"_projected_entity_to_message",
"(",
"ent",
",",
"message_type",
")",
":",
"msg",
"=",
"message_type",
"(",
")",
"analyzed",
"=",
"_analyze_indexed_fields",
"(",
"ent",
".",
"_projection",
")",
"for",
"name",
",",
"sublist",
"in",
"analyzed",
".",
"iter... | Recursive helper for _from_base_type() to convert an entity to a message.
Args:
ent: A Model instance.
message_type: A Message subclass.
Returns:
An instance of message_type. | [
"Recursive",
"helper",
"for",
"_from_base_type",
"()",
"to",
"convert",
"an",
"entity",
"to",
"a",
"message",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/msgprop.py#L420-L447 |
GoogleCloudPlatform/datastore-ndb-python | ndb/msgprop.py | EnumProperty._validate | def _validate(self, value):
"""Validate an Enum value.
Raises:
TypeError if the value is not an instance of self._enum_type.
"""
if not isinstance(value, self._enum_type):
raise TypeError('Expected a %s instance, got %r instead' %
(self._enum_type.__name__, value)) | python | def _validate(self, value):
"""Validate an Enum value.
Raises:
TypeError if the value is not an instance of self._enum_type.
"""
if not isinstance(value, self._enum_type):
raise TypeError('Expected a %s instance, got %r instead' %
(self._enum_type.__name__, value)) | [
"def",
"_validate",
"(",
"self",
",",
"value",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"self",
".",
"_enum_type",
")",
":",
"raise",
"TypeError",
"(",
"'Expected a %s instance, got %r instead'",
"%",
"(",
"self",
".",
"_enum_type",
".",
"__na... | Validate an Enum value.
Raises:
TypeError if the value is not an instance of self._enum_type. | [
"Validate",
"an",
"Enum",
"value",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/msgprop.py#L182-L190 |
GoogleCloudPlatform/datastore-ndb-python | ndb/msgprop.py | MessageProperty._validate | def _validate(self, msg):
"""Validate an Enum value.
Raises:
TypeError if the value is not an instance of self._message_type.
"""
if not isinstance(msg, self._message_type):
raise TypeError('Expected a %s instance for %s property',
self._message_type.__name__,
... | python | def _validate(self, msg):
"""Validate an Enum value.
Raises:
TypeError if the value is not an instance of self._message_type.
"""
if not isinstance(msg, self._message_type):
raise TypeError('Expected a %s instance for %s property',
self._message_type.__name__,
... | [
"def",
"_validate",
"(",
"self",
",",
"msg",
")",
":",
"if",
"not",
"isinstance",
"(",
"msg",
",",
"self",
".",
"_message_type",
")",
":",
"raise",
"TypeError",
"(",
"'Expected a %s instance for %s property'",
",",
"self",
".",
"_message_type",
".",
"__name__"... | Validate an Enum value.
Raises:
TypeError if the value is not an instance of self._message_type. | [
"Validate",
"an",
"Enum",
"value",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/msgprop.py#L353-L362 |
GoogleCloudPlatform/datastore-ndb-python | ndb/msgprop.py | MessageProperty._to_base_type | def _to_base_type(self, msg):
"""Convert a Message value to a Model instance (entity)."""
ent = _message_to_entity(msg, self._modelclass)
ent.blob_ = self._protocol_impl.encode_message(msg)
return ent | python | def _to_base_type(self, msg):
"""Convert a Message value to a Model instance (entity)."""
ent = _message_to_entity(msg, self._modelclass)
ent.blob_ = self._protocol_impl.encode_message(msg)
return ent | [
"def",
"_to_base_type",
"(",
"self",
",",
"msg",
")",
":",
"ent",
"=",
"_message_to_entity",
"(",
"msg",
",",
"self",
".",
"_modelclass",
")",
"ent",
".",
"blob_",
"=",
"self",
".",
"_protocol_impl",
".",
"encode_message",
"(",
"msg",
")",
"return",
"ent... | Convert a Message value to a Model instance (entity). | [
"Convert",
"a",
"Message",
"value",
"to",
"a",
"Model",
"instance",
"(",
"entity",
")",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/msgprop.py#L364-L368 |
GoogleCloudPlatform/datastore-ndb-python | ndb/msgprop.py | MessageProperty._from_base_type | def _from_base_type(self, ent):
"""Convert a Model instance (entity) to a Message value."""
if ent._projection:
# Projection query result. Reconstitute the message from the fields.
return _projected_entity_to_message(ent, self._message_type)
blob = ent.blob_
if blob is not None:
prot... | python | def _from_base_type(self, ent):
"""Convert a Model instance (entity) to a Message value."""
if ent._projection:
# Projection query result. Reconstitute the message from the fields.
return _projected_entity_to_message(ent, self._message_type)
blob = ent.blob_
if blob is not None:
prot... | [
"def",
"_from_base_type",
"(",
"self",
",",
"ent",
")",
":",
"if",
"ent",
".",
"_projection",
":",
"# Projection query result. Reconstitute the message from the fields.",
"return",
"_projected_entity_to_message",
"(",
"ent",
",",
"self",
".",
"_message_type",
")",
"blo... | Convert a Model instance (entity) to a Message value. | [
"Convert",
"a",
"Model",
"instance",
"(",
"entity",
")",
"to",
"a",
"Message",
"value",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/msgprop.py#L370-L393 |
GoogleCloudPlatform/datastore-ndb-python | ndb/polymodel.py | _ClassKeyProperty._get_value | def _get_value(self, entity):
"""Compute and store a default value if necessary."""
value = super(_ClassKeyProperty, self)._get_value(entity)
if not value:
value = entity._class_key()
self._store_value(entity, value)
return value | python | def _get_value(self, entity):
"""Compute and store a default value if necessary."""
value = super(_ClassKeyProperty, self)._get_value(entity)
if not value:
value = entity._class_key()
self._store_value(entity, value)
return value | [
"def",
"_get_value",
"(",
"self",
",",
"entity",
")",
":",
"value",
"=",
"super",
"(",
"_ClassKeyProperty",
",",
"self",
")",
".",
"_get_value",
"(",
"entity",
")",
"if",
"not",
"value",
":",
"value",
"=",
"entity",
".",
"_class_key",
"(",
")",
"self",... | Compute and store a default value if necessary. | [
"Compute",
"and",
"store",
"a",
"default",
"value",
"if",
"necessary",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/polymodel.py#L74-L80 |
GoogleCloudPlatform/datastore-ndb-python | ndb/polymodel.py | PolyModel._update_kind_map | def _update_kind_map(cls):
"""Override; called by Model._fix_up_properties().
Update the kind map as well as the class map, except for PolyModel
itself (its class key is empty). Note that the kind map will
contain entries for all classes in a PolyModel hierarchy; they all
have the same kind, but d... | python | def _update_kind_map(cls):
"""Override; called by Model._fix_up_properties().
Update the kind map as well as the class map, except for PolyModel
itself (its class key is empty). Note that the kind map will
contain entries for all classes in a PolyModel hierarchy; they all
have the same kind, but d... | [
"def",
"_update_kind_map",
"(",
"cls",
")",
":",
"cls",
".",
"_kind_map",
"[",
"cls",
".",
"_class_name",
"(",
")",
"]",
"=",
"cls",
"class_key",
"=",
"cls",
".",
"_class_key",
"(",
")",
"if",
"class_key",
":",
"cls",
".",
"_class_map",
"[",
"tuple",
... | Override; called by Model._fix_up_properties().
Update the kind map as well as the class map, except for PolyModel
itself (its class key is empty). Note that the kind map will
contain entries for all classes in a PolyModel hierarchy; they all
have the same kind, but different class names. PolyModel c... | [
"Override",
";",
"called",
"by",
"Model",
".",
"_fix_up_properties",
"()",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/polymodel.py#L168-L180 |
GoogleCloudPlatform/datastore-ndb-python | ndb/polymodel.py | PolyModel._from_pb | def _from_pb(cls, pb, set_key=True, ent=None, key=None):
"""Override.
Use the class map to give the entity the correct subclass.
"""
prop_name = cls.class_._name
class_name = []
for plist in [pb.property_list(), pb.raw_property_list()]:
for p in plist:
if p.name() == prop_name:
... | python | def _from_pb(cls, pb, set_key=True, ent=None, key=None):
"""Override.
Use the class map to give the entity the correct subclass.
"""
prop_name = cls.class_._name
class_name = []
for plist in [pb.property_list(), pb.raw_property_list()]:
for p in plist:
if p.name() == prop_name:
... | [
"def",
"_from_pb",
"(",
"cls",
",",
"pb",
",",
"set_key",
"=",
"True",
",",
"ent",
"=",
"None",
",",
"key",
"=",
"None",
")",
":",
"prop_name",
"=",
"cls",
".",
"class_",
".",
"_name",
"class_name",
"=",
"[",
"]",
"for",
"plist",
"in",
"[",
"pb",... | Override.
Use the class map to give the entity the correct subclass. | [
"Override",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/polymodel.py#L183-L195 |
GoogleCloudPlatform/datastore-ndb-python | ndb/polymodel.py | PolyModel._get_kind | def _get_kind(cls):
"""Override.
Make sure that the kind returned is the root class of the
polymorphic hierarchy.
"""
bases = cls._get_hierarchy()
if not bases:
# We have to jump through some hoops to call the superclass'
# _get_kind() method. First, this is called by the metaclass... | python | def _get_kind(cls):
"""Override.
Make sure that the kind returned is the root class of the
polymorphic hierarchy.
"""
bases = cls._get_hierarchy()
if not bases:
# We have to jump through some hoops to call the superclass'
# _get_kind() method. First, this is called by the metaclass... | [
"def",
"_get_kind",
"(",
"cls",
")",
":",
"bases",
"=",
"cls",
".",
"_get_hierarchy",
"(",
")",
"if",
"not",
"bases",
":",
"# We have to jump through some hoops to call the superclass'",
"# _get_kind() method. First, this is called by the metaclass",
"# before the PolyModel na... | Override.
Make sure that the kind returned is the root class of the
polymorphic hierarchy. | [
"Override",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/polymodel.py#L206-L222 |
GoogleCloudPlatform/datastore-ndb-python | ndb/polymodel.py | PolyModel._get_hierarchy | def _get_hierarchy(cls):
"""Internal helper to return the list of polymorphic base classes.
This returns a list of class objects, e.g. [Animal, Feline, Cat].
"""
bases = []
for base in cls.mro(): # pragma: no branch
if hasattr(base, '_get_hierarchy'):
bases.append(base)
del bases... | python | def _get_hierarchy(cls):
"""Internal helper to return the list of polymorphic base classes.
This returns a list of class objects, e.g. [Animal, Feline, Cat].
"""
bases = []
for base in cls.mro(): # pragma: no branch
if hasattr(base, '_get_hierarchy'):
bases.append(base)
del bases... | [
"def",
"_get_hierarchy",
"(",
"cls",
")",
":",
"bases",
"=",
"[",
"]",
"for",
"base",
"in",
"cls",
".",
"mro",
"(",
")",
":",
"# pragma: no branch",
"if",
"hasattr",
"(",
"base",
",",
"'_get_hierarchy'",
")",
":",
"bases",
".",
"append",
"(",
"base",
... | Internal helper to return the list of polymorphic base classes.
This returns a list of class objects, e.g. [Animal, Feline, Cat]. | [
"Internal",
"helper",
"to",
"return",
"the",
"list",
"of",
"polymorphic",
"base",
"classes",
"."
] | train | https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/cf4cab3f1f69cd04e1a9229871be466b53729f3f/ndb/polymodel.py#L242-L253 |
Cadair/jupyter_environment_kernels | environment_kernels/envs_common.py | find_env_paths_in_basedirs | def find_env_paths_in_basedirs(base_dirs):
"""Returns all potential envs in a basedir"""
# get potential env path in the base_dirs
env_path = []
for base_dir in base_dirs:
env_path.extend(glob.glob(os.path.join(
os.path.expanduser(base_dir), '*', '')))
# self.log.info("Found the ... | python | def find_env_paths_in_basedirs(base_dirs):
"""Returns all potential envs in a basedir"""
# get potential env path in the base_dirs
env_path = []
for base_dir in base_dirs:
env_path.extend(glob.glob(os.path.join(
os.path.expanduser(base_dir), '*', '')))
# self.log.info("Found the ... | [
"def",
"find_env_paths_in_basedirs",
"(",
"base_dirs",
")",
":",
"# get potential env path in the base_dirs",
"env_path",
"=",
"[",
"]",
"for",
"base_dir",
"in",
"base_dirs",
":",
"env_path",
".",
"extend",
"(",
"glob",
".",
"glob",
"(",
"os",
".",
"path",
".",
... | Returns all potential envs in a basedir | [
"Returns",
"all",
"potential",
"envs",
"in",
"a",
"basedir"
] | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_common.py#L12-L21 |
Cadair/jupyter_environment_kernels | environment_kernels/envs_common.py | convert_to_env_data | def convert_to_env_data(mgr, env_paths, validator_func, activate_func,
name_template, display_name_template, name_prefix):
"""Converts a list of paths to environments to env_data.
env_data is a structure {name -> (ressourcedir, kernel spec)}
"""
env_data = {}
for venv_dir in... | python | def convert_to_env_data(mgr, env_paths, validator_func, activate_func,
name_template, display_name_template, name_prefix):
"""Converts a list of paths to environments to env_data.
env_data is a structure {name -> (ressourcedir, kernel spec)}
"""
env_data = {}
for venv_dir in... | [
"def",
"convert_to_env_data",
"(",
"mgr",
",",
"env_paths",
",",
"validator_func",
",",
"activate_func",
",",
"name_template",
",",
"display_name_template",
",",
"name_prefix",
")",
":",
"env_data",
"=",
"{",
"}",
"for",
"venv_dir",
"in",
"env_paths",
":",
"venv... | Converts a list of paths to environments to env_data.
env_data is a structure {name -> (ressourcedir, kernel spec)} | [
"Converts",
"a",
"list",
"of",
"paths",
"to",
"environments",
"to",
"env_data",
"."
] | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_common.py#L24-L60 |
Cadair/jupyter_environment_kernels | environment_kernels/envs_common.py | validate_IPykernel | def validate_IPykernel(venv_dir):
"""Validates that this env contains an IPython kernel and returns info to start it
Returns: tuple
(ARGV, language, resource_dir)
"""
python_exe_name = find_exe(venv_dir, "python")
if python_exe_name is None:
python_exe_name = find_exe(venv_dir, "py... | python | def validate_IPykernel(venv_dir):
"""Validates that this env contains an IPython kernel and returns info to start it
Returns: tuple
(ARGV, language, resource_dir)
"""
python_exe_name = find_exe(venv_dir, "python")
if python_exe_name is None:
python_exe_name = find_exe(venv_dir, "py... | [
"def",
"validate_IPykernel",
"(",
"venv_dir",
")",
":",
"python_exe_name",
"=",
"find_exe",
"(",
"venv_dir",
",",
"\"python\"",
")",
"if",
"python_exe_name",
"is",
"None",
":",
"python_exe_name",
"=",
"find_exe",
"(",
"venv_dir",
",",
"\"python2\"",
")",
"if",
... | Validates that this env contains an IPython kernel and returns info to start it
Returns: tuple
(ARGV, language, resource_dir) | [
"Validates",
"that",
"this",
"env",
"contains",
"an",
"IPython",
"kernel",
"and",
"returns",
"info",
"to",
"start",
"it"
] | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_common.py#L63-L93 |
Cadair/jupyter_environment_kernels | environment_kernels/envs_common.py | validate_IRkernel | def validate_IRkernel(venv_dir):
"""Validates that this env contains an IRkernel kernel and returns info to start it
Returns: tuple
(ARGV, language, resource_dir)
"""
r_exe_name = find_exe(venv_dir, "R")
if r_exe_name is None:
return [], None, None
# check if this is really an... | python | def validate_IRkernel(venv_dir):
"""Validates that this env contains an IRkernel kernel and returns info to start it
Returns: tuple
(ARGV, language, resource_dir)
"""
r_exe_name = find_exe(venv_dir, "R")
if r_exe_name is None:
return [], None, None
# check if this is really an... | [
"def",
"validate_IRkernel",
"(",
"venv_dir",
")",
":",
"r_exe_name",
"=",
"find_exe",
"(",
"venv_dir",
",",
"\"R\"",
")",
"if",
"r_exe_name",
"is",
"None",
":",
"return",
"[",
"]",
",",
"None",
",",
"None",
"# check if this is really an IRkernel **kernel**",
"im... | Validates that this env contains an IRkernel kernel and returns info to start it
Returns: tuple
(ARGV, language, resource_dir) | [
"Validates",
"that",
"this",
"env",
"contains",
"an",
"IRkernel",
"kernel",
"and",
"returns",
"info",
"to",
"start",
"it"
] | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_common.py#L96-L121 |
Cadair/jupyter_environment_kernels | environment_kernels/envs_common.py | find_exe | def find_exe(env_dir, name):
"""Finds a exe with that name in the environment path"""
if platform.system() == "Windows":
name = name + ".exe"
# find the binary
exe_name = os.path.join(env_dir, name)
if not os.path.exists(exe_name):
exe_name = os.path.join(env_dir, "bin", name)
... | python | def find_exe(env_dir, name):
"""Finds a exe with that name in the environment path"""
if platform.system() == "Windows":
name = name + ".exe"
# find the binary
exe_name = os.path.join(env_dir, name)
if not os.path.exists(exe_name):
exe_name = os.path.join(env_dir, "bin", name)
... | [
"def",
"find_exe",
"(",
"env_dir",
",",
"name",
")",
":",
"if",
"platform",
".",
"system",
"(",
")",
"==",
"\"Windows\"",
":",
"name",
"=",
"name",
"+",
"\".exe\"",
"# find the binary",
"exe_name",
"=",
"os",
".",
"path",
".",
"join",
"(",
"env_dir",
"... | Finds a exe with that name in the environment path | [
"Finds",
"a",
"exe",
"with",
"that",
"name",
"in",
"the",
"environment",
"path"
] | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_common.py#L124-L138 |
Cadair/jupyter_environment_kernels | environment_kernels/envs_virtualenv.py | get_virtualenv_env_data | def get_virtualenv_env_data(mgr):
"""Finds kernel specs from virtualenv environments
env_data is a structure {name -> (resourcedir, kernel spec)}
"""
if not mgr.find_virtualenv_envs:
return {}
mgr.log.debug("Looking for virtualenv environments in %s...", mgr.virtualenv_env_dirs)
# fi... | python | def get_virtualenv_env_data(mgr):
"""Finds kernel specs from virtualenv environments
env_data is a structure {name -> (resourcedir, kernel spec)}
"""
if not mgr.find_virtualenv_envs:
return {}
mgr.log.debug("Looking for virtualenv environments in %s...", mgr.virtualenv_env_dirs)
# fi... | [
"def",
"get_virtualenv_env_data",
"(",
"mgr",
")",
":",
"if",
"not",
"mgr",
".",
"find_virtualenv_envs",
":",
"return",
"{",
"}",
"mgr",
".",
"log",
".",
"debug",
"(",
"\"Looking for virtualenv environments in %s...\"",
",",
"mgr",
".",
"virtualenv_env_dirs",
")",... | Finds kernel specs from virtualenv environments
env_data is a structure {name -> (resourcedir, kernel spec)} | [
"Finds",
"kernel",
"specs",
"from",
"virtualenv",
"environments"
] | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_virtualenv.py#L12-L35 |
Cadair/jupyter_environment_kernels | environment_kernels/activate_helper.py | source_bash | def source_bash(args, stdin=None):
"""Simply bash-specific wrapper around source-foreign
Returns a dict to be used as a new environment"""
args = list(args)
new_args = ['bash', '--sourcer=source']
new_args.extend(args)
return source_foreign(new_args, stdin=stdin) | python | def source_bash(args, stdin=None):
"""Simply bash-specific wrapper around source-foreign
Returns a dict to be used as a new environment"""
args = list(args)
new_args = ['bash', '--sourcer=source']
new_args.extend(args)
return source_foreign(new_args, stdin=stdin) | [
"def",
"source_bash",
"(",
"args",
",",
"stdin",
"=",
"None",
")",
":",
"args",
"=",
"list",
"(",
"args",
")",
"new_args",
"=",
"[",
"'bash'",
",",
"'--sourcer=source'",
"]",
"new_args",
".",
"extend",
"(",
"args",
")",
"return",
"source_foreign",
"(",
... | Simply bash-specific wrapper around source-foreign
Returns a dict to be used as a new environment | [
"Simply",
"bash",
"-",
"specific",
"wrapper",
"around",
"source",
"-",
"foreign"
] | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L66-L73 |
Cadair/jupyter_environment_kernels | environment_kernels/activate_helper.py | source_zsh | def source_zsh(args, stdin=None):
"""Simply zsh-specific wrapper around source-foreign
Returns a dict to be used as a new environment"""
args = list(args)
new_args = ['zsh', '--sourcer=source']
new_args.extend(args)
return source_foreign(new_args, stdin=stdin) | python | def source_zsh(args, stdin=None):
"""Simply zsh-specific wrapper around source-foreign
Returns a dict to be used as a new environment"""
args = list(args)
new_args = ['zsh', '--sourcer=source']
new_args.extend(args)
return source_foreign(new_args, stdin=stdin) | [
"def",
"source_zsh",
"(",
"args",
",",
"stdin",
"=",
"None",
")",
":",
"args",
"=",
"list",
"(",
"args",
")",
"new_args",
"=",
"[",
"'zsh'",
",",
"'--sourcer=source'",
"]",
"new_args",
".",
"extend",
"(",
"args",
")",
"return",
"source_foreign",
"(",
"... | Simply zsh-specific wrapper around source-foreign
Returns a dict to be used as a new environment | [
"Simply",
"zsh",
"-",
"specific",
"wrapper",
"around",
"source",
"-",
"foreign"
] | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L75-L82 |
Cadair/jupyter_environment_kernels | environment_kernels/activate_helper.py | source_cmd | def source_cmd(args, stdin=None):
"""Simple cmd.exe-specific wrapper around source-foreign.
returns a dict to be used as a new environment
"""
args = list(args)
fpath = locate_binary(args[0])
args[0] = fpath if fpath else args[0]
if not os.path.isfile(args[0]):
raise RuntimeError("C... | python | def source_cmd(args, stdin=None):
"""Simple cmd.exe-specific wrapper around source-foreign.
returns a dict to be used as a new environment
"""
args = list(args)
fpath = locate_binary(args[0])
args[0] = fpath if fpath else args[0]
if not os.path.isfile(args[0]):
raise RuntimeError("C... | [
"def",
"source_cmd",
"(",
"args",
",",
"stdin",
"=",
"None",
")",
":",
"args",
"=",
"list",
"(",
"args",
")",
"fpath",
"=",
"locate_binary",
"(",
"args",
"[",
"0",
"]",
")",
"args",
"[",
"0",
"]",
"=",
"fpath",
"if",
"fpath",
"else",
"args",
"[",... | Simple cmd.exe-specific wrapper around source-foreign.
returns a dict to be used as a new environment | [
"Simple",
"cmd",
".",
"exe",
"-",
"specific",
"wrapper",
"around",
"source",
"-",
"foreign",
"."
] | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L85-L105 |
Cadair/jupyter_environment_kernels | environment_kernels/activate_helper.py | argvquote | def argvquote(arg, force=False):
""" Returns an argument quoted in such a way that that CommandLineToArgvW
on Windows will return the argument string unchanged.
This is the same thing Popen does when supplied with an list of arguments.
Arguments in a command line should be separated by spaces; this
... | python | def argvquote(arg, force=False):
""" Returns an argument quoted in such a way that that CommandLineToArgvW
on Windows will return the argument string unchanged.
This is the same thing Popen does when supplied with an list of arguments.
Arguments in a command line should be separated by spaces; this
... | [
"def",
"argvquote",
"(",
"arg",
",",
"force",
"=",
"False",
")",
":",
"if",
"not",
"force",
"and",
"len",
"(",
"arg",
")",
"!=",
"0",
"and",
"not",
"any",
"(",
"[",
"c",
"in",
"arg",
"for",
"c",
"in",
"' \\t\\n\\v\"'",
"]",
")",
":",
"return",
... | Returns an argument quoted in such a way that that CommandLineToArgvW
on Windows will return the argument string unchanged.
This is the same thing Popen does when supplied with an list of arguments.
Arguments in a command line should be separated by spaces; this
function does not add these spaces. This ... | [
"Returns",
"an",
"argument",
"quoted",
"in",
"such",
"a",
"way",
"that",
"that",
"CommandLineToArgvW",
"on",
"Windows",
"will",
"return",
"the",
"argument",
"string",
"unchanged",
".",
"This",
"is",
"the",
"same",
"thing",
"Popen",
"does",
"when",
"supplied",
... | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L124-L155 |
Cadair/jupyter_environment_kernels | environment_kernels/activate_helper.py | escape_windows_cmd_string | def escape_windows_cmd_string(s):
"""Returns a string that is usable by the Windows cmd.exe.
The escaping is based on details here and emperical testing:
http://www.robvanderwoude.com/escapechars.php
"""
for c in '()%!^<>&|"':
s = s.replace(c, '^' + c)
s = s.replace('/?', '/.')
retur... | python | def escape_windows_cmd_string(s):
"""Returns a string that is usable by the Windows cmd.exe.
The escaping is based on details here and emperical testing:
http://www.robvanderwoude.com/escapechars.php
"""
for c in '()%!^<>&|"':
s = s.replace(c, '^' + c)
s = s.replace('/?', '/.')
retur... | [
"def",
"escape_windows_cmd_string",
"(",
"s",
")",
":",
"for",
"c",
"in",
"'()%!^<>&|\"'",
":",
"s",
"=",
"s",
".",
"replace",
"(",
"c",
",",
"'^'",
"+",
"c",
")",
"s",
"=",
"s",
".",
"replace",
"(",
"'/?'",
",",
"'/.'",
")",
"return",
"s"
] | Returns a string that is usable by the Windows cmd.exe.
The escaping is based on details here and emperical testing:
http://www.robvanderwoude.com/escapechars.php | [
"Returns",
"a",
"string",
"that",
"is",
"usable",
"by",
"the",
"Windows",
"cmd",
".",
"exe",
".",
"The",
"escaping",
"is",
"based",
"on",
"details",
"here",
"and",
"emperical",
"testing",
":",
"http",
":",
"//",
"www",
".",
"robvanderwoude",
".",
"com",
... | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L158-L166 |
Cadair/jupyter_environment_kernels | environment_kernels/activate_helper.py | source_foreign | def source_foreign(args, stdin=None):
"""Sources a file written in a foreign shell language."""
parser = _ensure_source_foreign_parser()
ns = parser.parse_args(args)
if ns.prevcmd is not None:
pass # don't change prevcmd if given explicitly
elif os.path.isfile(ns.files_or_code[0]):
... | python | def source_foreign(args, stdin=None):
"""Sources a file written in a foreign shell language."""
parser = _ensure_source_foreign_parser()
ns = parser.parse_args(args)
if ns.prevcmd is not None:
pass # don't change prevcmd if given explicitly
elif os.path.isfile(ns.files_or_code[0]):
... | [
"def",
"source_foreign",
"(",
"args",
",",
"stdin",
"=",
"None",
")",
":",
"parser",
"=",
"_ensure_source_foreign_parser",
"(",
")",
"ns",
"=",
"parser",
".",
"parse_args",
"(",
"args",
")",
"if",
"ns",
".",
"prevcmd",
"is",
"not",
"None",
":",
"pass",
... | Sources a file written in a foreign shell language. | [
"Sources",
"a",
"file",
"written",
"in",
"a",
"foreign",
"shell",
"language",
"."
] | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L169-L204 |
Cadair/jupyter_environment_kernels | environment_kernels/activate_helper.py | _is_executable_file | def _is_executable_file(path):
"""Checks that path is an executable regular file, or a symlink towards one.
This is roughly ``os.path isfile(path) and os.access(path, os.X_OK)``.
This function was forked from pexpect originally:
Copyright (c) 2013-2014, Pexpect development team
Copyright (c) 2012,... | python | def _is_executable_file(path):
"""Checks that path is an executable regular file, or a symlink towards one.
This is roughly ``os.path isfile(path) and os.access(path, os.X_OK)``.
This function was forked from pexpect originally:
Copyright (c) 2013-2014, Pexpect development team
Copyright (c) 2012,... | [
"def",
"_is_executable_file",
"(",
"path",
")",
":",
"# follow symlinks,",
"fpath",
"=",
"os",
".",
"path",
".",
"realpath",
"(",
"path",
")",
"if",
"not",
"os",
".",
"path",
".",
"isfile",
"(",
"fpath",
")",
":",
"# non-files (directories, fifo, etc.)",
"re... | Checks that path is an executable regular file, or a symlink towards one.
This is roughly ``os.path isfile(path) and os.access(path, os.X_OK)``.
This function was forked from pexpect originally:
Copyright (c) 2013-2014, Pexpect development team
Copyright (c) 2012, Noah Spurrier <noah@noah.org>
PE... | [
"Checks",
"that",
"path",
"is",
"an",
"executable",
"regular",
"file",
"or",
"a",
"symlink",
"towards",
"one",
".",
"This",
"is",
"roughly",
"os",
".",
"path",
"isfile",
"(",
"path",
")",
"and",
"os",
".",
"access",
"(",
"path",
"os",
".",
"X_OK",
")... | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L244-L271 |
Cadair/jupyter_environment_kernels | environment_kernels/activate_helper.py | foreign_shell_data | def foreign_shell_data(shell, interactive=True, login=False, envcmd=None,
aliascmd=None, extra_args=(), currenv=None,
safe=False, prevcmd='', postcmd='', funcscmd=None,
sourcer=None, use_tmpfile=False, tmpfile_ext=None,
runcmd=N... | python | def foreign_shell_data(shell, interactive=True, login=False, envcmd=None,
aliascmd=None, extra_args=(), currenv=None,
safe=False, prevcmd='', postcmd='', funcscmd=None,
sourcer=None, use_tmpfile=False, tmpfile_ext=None,
runcmd=N... | [
"def",
"foreign_shell_data",
"(",
"shell",
",",
"interactive",
"=",
"True",
",",
"login",
"=",
"False",
",",
"envcmd",
"=",
"None",
",",
"aliascmd",
"=",
"None",
",",
"extra_args",
"=",
"(",
")",
",",
"currenv",
"=",
"None",
",",
"safe",
"=",
"False",
... | Extracts data from a foreign (non-xonsh) shells. Currently this gets
the environment, aliases, and functions but may be extended in the future.
Parameters
----------
shell : str
The name of the shell, such as 'bash' or '/bin/sh'.
interactive : bool, optional
Whether the shell should... | [
"Extracts",
"data",
"from",
"a",
"foreign",
"(",
"non",
"-",
"xonsh",
")",
"shells",
".",
"Currently",
"this",
"gets",
"the",
"environment",
"aliases",
"and",
"functions",
"but",
"may",
"be",
"extended",
"in",
"the",
"future",
"."
] | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L328-L443 |
Cadair/jupyter_environment_kernels | environment_kernels/activate_helper.py | to_bool | def to_bool(x):
""""Converts to a boolean in a semantically meaningful way."""
if isinstance(x, bool):
return x
elif isinstance(x, str):
return False if x.lower() in _FALSES else True
else:
return bool(x) | python | def to_bool(x):
""""Converts to a boolean in a semantically meaningful way."""
if isinstance(x, bool):
return x
elif isinstance(x, str):
return False if x.lower() in _FALSES else True
else:
return bool(x) | [
"def",
"to_bool",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"bool",
")",
":",
"return",
"x",
"elif",
"isinstance",
"(",
"x",
",",
"str",
")",
":",
"return",
"False",
"if",
"x",
".",
"lower",
"(",
")",
"in",
"_FALSES",
"else",
"True",... | Converts to a boolean in a semantically meaningful way. | [
"Converts",
"to",
"a",
"boolean",
"in",
"a",
"semantically",
"meaningful",
"way",
"."
] | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L445-L452 |
Cadair/jupyter_environment_kernels | environment_kernels/activate_helper.py | parse_env | def parse_env(s):
"""Parses the environment portion of string into a dict."""
m = ENV_RE.search(s)
if m is None:
return {}
g1 = m.group(1)
env = dict(ENV_SPLIT_RE.findall(g1))
return env | python | def parse_env(s):
"""Parses the environment portion of string into a dict."""
m = ENV_RE.search(s)
if m is None:
return {}
g1 = m.group(1)
env = dict(ENV_SPLIT_RE.findall(g1))
return env | [
"def",
"parse_env",
"(",
"s",
")",
":",
"m",
"=",
"ENV_RE",
".",
"search",
"(",
"s",
")",
"if",
"m",
"is",
"None",
":",
"return",
"{",
"}",
"g1",
"=",
"m",
".",
"group",
"(",
"1",
")",
"env",
"=",
"dict",
"(",
"ENV_SPLIT_RE",
".",
"findall",
... | Parses the environment portion of string into a dict. | [
"Parses",
"the",
"environment",
"portion",
"of",
"string",
"into",
"a",
"dict",
"."
] | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/activate_helper.py#L511-L518 |
Cadair/jupyter_environment_kernels | environment_kernels/envs_conda.py | get_conda_env_data | def get_conda_env_data(mgr):
"""Finds kernel specs from conda environments
env_data is a structure {name -> (resourcedir, kernel spec)}
"""
if not mgr.find_conda_envs:
return {}
mgr.log.debug("Looking for conda environments in %s...", mgr.conda_env_dirs)
# find all potential env paths... | python | def get_conda_env_data(mgr):
"""Finds kernel specs from conda environments
env_data is a structure {name -> (resourcedir, kernel spec)}
"""
if not mgr.find_conda_envs:
return {}
mgr.log.debug("Looking for conda environments in %s...", mgr.conda_env_dirs)
# find all potential env paths... | [
"def",
"get_conda_env_data",
"(",
"mgr",
")",
":",
"if",
"not",
"mgr",
".",
"find_conda_envs",
":",
"return",
"{",
"}",
"mgr",
".",
"log",
".",
"debug",
"(",
"\"Looking for conda environments in %s...\"",
",",
"mgr",
".",
"conda_env_dirs",
")",
"# find all poten... | Finds kernel specs from conda environments
env_data is a structure {name -> (resourcedir, kernel spec)} | [
"Finds",
"kernel",
"specs",
"from",
"conda",
"environments"
] | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_conda.py#L10-L42 |
Cadair/jupyter_environment_kernels | environment_kernels/envs_conda.py | _find_conda_env_paths_from_conda | def _find_conda_env_paths_from_conda(mgr):
"""Returns a list of path as given by `conda env list --json`.
Returns empty list, if conda couldn't be called.
"""
# this is expensive, so make it configureable...
if not mgr.use_conda_directly:
return []
mgr.log.debug("Looking for conda envir... | python | def _find_conda_env_paths_from_conda(mgr):
"""Returns a list of path as given by `conda env list --json`.
Returns empty list, if conda couldn't be called.
"""
# this is expensive, so make it configureable...
if not mgr.use_conda_directly:
return []
mgr.log.debug("Looking for conda envir... | [
"def",
"_find_conda_env_paths_from_conda",
"(",
"mgr",
")",
":",
"# this is expensive, so make it configureable...",
"if",
"not",
"mgr",
".",
"use_conda_directly",
":",
"return",
"[",
"]",
"mgr",
".",
"log",
".",
"debug",
"(",
"\"Looking for conda environments by calling ... | Returns a list of path as given by `conda env list --json`.
Returns empty list, if conda couldn't be called. | [
"Returns",
"a",
"list",
"of",
"path",
"as",
"given",
"by",
"conda",
"env",
"list",
"--",
"json",
"."
] | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/envs_conda.py#L62-L91 |
Cadair/jupyter_environment_kernels | environment_kernels/core.py | EnvironmentKernelSpecManager.validate_env | def validate_env(self, envname):
"""
Check the name of the environment against the black list and the
whitelist. If a whitelist is specified only it is checked.
"""
if self.whitelist_envs and envname in self.whitelist_envs:
return True
elif self.whitelist_envs... | python | def validate_env(self, envname):
"""
Check the name of the environment against the black list and the
whitelist. If a whitelist is specified only it is checked.
"""
if self.whitelist_envs and envname in self.whitelist_envs:
return True
elif self.whitelist_envs... | [
"def",
"validate_env",
"(",
"self",
",",
"envname",
")",
":",
"if",
"self",
".",
"whitelist_envs",
"and",
"envname",
"in",
"self",
".",
"whitelist_envs",
":",
"return",
"True",
"elif",
"self",
".",
"whitelist_envs",
":",
"return",
"False",
"if",
"self",
".... | Check the name of the environment against the black list and the
whitelist. If a whitelist is specified only it is checked. | [
"Check",
"the",
"name",
"of",
"the",
"environment",
"against",
"the",
"black",
"list",
"and",
"the",
"whitelist",
".",
"If",
"a",
"whitelist",
"is",
"specified",
"only",
"it",
"is",
"checked",
"."
] | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/core.py#L128-L144 |
Cadair/jupyter_environment_kernels | environment_kernels/core.py | EnvironmentKernelSpecManager._get_env_data | def _get_env_data(self, reload=False):
"""Get the data about the available environments.
env_data is a structure {name -> (resourcedir, kernel spec)}
"""
# This is called much too often and finding-process is really expensive :-(
if not reload and getattr(self, "_env_data_cache... | python | def _get_env_data(self, reload=False):
"""Get the data about the available environments.
env_data is a structure {name -> (resourcedir, kernel spec)}
"""
# This is called much too often and finding-process is really expensive :-(
if not reload and getattr(self, "_env_data_cache... | [
"def",
"_get_env_data",
"(",
"self",
",",
"reload",
"=",
"False",
")",
":",
"# This is called much too often and finding-process is really expensive :-(",
"if",
"not",
"reload",
"and",
"getattr",
"(",
"self",
",",
"\"_env_data_cache\"",
",",
"{",
"}",
")",
":",
"ret... | Get the data about the available environments.
env_data is a structure {name -> (resourcedir, kernel spec)} | [
"Get",
"the",
"data",
"about",
"the",
"available",
"environments",
"."
] | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/core.py#L154-L174 |
Cadair/jupyter_environment_kernels | environment_kernels/core.py | EnvironmentKernelSpecManager.find_kernel_specs_for_envs | def find_kernel_specs_for_envs(self):
"""Returns a dict mapping kernel names to resource directories."""
data = self._get_env_data()
return {name: data[name][0] for name in data} | python | def find_kernel_specs_for_envs(self):
"""Returns a dict mapping kernel names to resource directories."""
data = self._get_env_data()
return {name: data[name][0] for name in data} | [
"def",
"find_kernel_specs_for_envs",
"(",
"self",
")",
":",
"data",
"=",
"self",
".",
"_get_env_data",
"(",
")",
"return",
"{",
"name",
":",
"data",
"[",
"name",
"]",
"[",
"0",
"]",
"for",
"name",
"in",
"data",
"}"
] | Returns a dict mapping kernel names to resource directories. | [
"Returns",
"a",
"dict",
"mapping",
"kernel",
"names",
"to",
"resource",
"directories",
"."
] | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/core.py#L176-L179 |
Cadair/jupyter_environment_kernels | environment_kernels/core.py | EnvironmentKernelSpecManager.get_all_kernel_specs_for_envs | def get_all_kernel_specs_for_envs(self):
"""Returns the dict of name -> kernel_spec for all environments"""
data = self._get_env_data()
return {name: data[name][1] for name in data} | python | def get_all_kernel_specs_for_envs(self):
"""Returns the dict of name -> kernel_spec for all environments"""
data = self._get_env_data()
return {name: data[name][1] for name in data} | [
"def",
"get_all_kernel_specs_for_envs",
"(",
"self",
")",
":",
"data",
"=",
"self",
".",
"_get_env_data",
"(",
")",
"return",
"{",
"name",
":",
"data",
"[",
"name",
"]",
"[",
"1",
"]",
"for",
"name",
"in",
"data",
"}"
] | Returns the dict of name -> kernel_spec for all environments | [
"Returns",
"the",
"dict",
"of",
"name",
"-",
">",
"kernel_spec",
"for",
"all",
"environments"
] | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/core.py#L181-L185 |
Cadair/jupyter_environment_kernels | environment_kernels/core.py | EnvironmentKernelSpecManager.find_kernel_specs | def find_kernel_specs(self):
"""Returns a dict mapping kernel names to resource directories."""
# let real installed kernels overwrite envs with the same name:
# this is the same order as the get_kernel_spec way, which also prefers
# kernels from the jupyter dir over env kernels.
... | python | def find_kernel_specs(self):
"""Returns a dict mapping kernel names to resource directories."""
# let real installed kernels overwrite envs with the same name:
# this is the same order as the get_kernel_spec way, which also prefers
# kernels from the jupyter dir over env kernels.
... | [
"def",
"find_kernel_specs",
"(",
"self",
")",
":",
"# let real installed kernels overwrite envs with the same name:",
"# this is the same order as the get_kernel_spec way, which also prefers",
"# kernels from the jupyter dir over env kernels.",
"specs",
"=",
"self",
".",
"find_kernel_specs... | Returns a dict mapping kernel names to resource directories. | [
"Returns",
"a",
"dict",
"mapping",
"kernel",
"names",
"to",
"resource",
"directories",
"."
] | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/core.py#L187-L195 |
Cadair/jupyter_environment_kernels | environment_kernels/core.py | EnvironmentKernelSpecManager.get_all_specs | def get_all_specs(self):
"""Returns a dict mapping kernel names and resource directories.
"""
# This is new in 4.1 -> https://github.com/jupyter/jupyter_client/pull/93
specs = self.get_all_kernel_specs_for_envs()
specs.update(super(EnvironmentKernelSpecManager, self).get_all_spec... | python | def get_all_specs(self):
"""Returns a dict mapping kernel names and resource directories.
"""
# This is new in 4.1 -> https://github.com/jupyter/jupyter_client/pull/93
specs = self.get_all_kernel_specs_for_envs()
specs.update(super(EnvironmentKernelSpecManager, self).get_all_spec... | [
"def",
"get_all_specs",
"(",
"self",
")",
":",
"# This is new in 4.1 -> https://github.com/jupyter/jupyter_client/pull/93",
"specs",
"=",
"self",
".",
"get_all_kernel_specs_for_envs",
"(",
")",
"specs",
".",
"update",
"(",
"super",
"(",
"EnvironmentKernelSpecManager",
",",
... | Returns a dict mapping kernel names and resource directories. | [
"Returns",
"a",
"dict",
"mapping",
"kernel",
"names",
"and",
"resource",
"directories",
"."
] | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/core.py#L197-L203 |
Cadair/jupyter_environment_kernels | environment_kernels/core.py | EnvironmentKernelSpecManager.get_kernel_spec | def get_kernel_spec(self, kernel_name):
"""Returns a :class:`KernelSpec` instance for the given kernel_name.
Raises :exc:`NoSuchKernel` if the given kernel name is not found.
"""
try:
return super(EnvironmentKernelSpecManager,
self).get_kernel_spec(k... | python | def get_kernel_spec(self, kernel_name):
"""Returns a :class:`KernelSpec` instance for the given kernel_name.
Raises :exc:`NoSuchKernel` if the given kernel name is not found.
"""
try:
return super(EnvironmentKernelSpecManager,
self).get_kernel_spec(k... | [
"def",
"get_kernel_spec",
"(",
"self",
",",
"kernel_name",
")",
":",
"try",
":",
"return",
"super",
"(",
"EnvironmentKernelSpecManager",
",",
"self",
")",
".",
"get_kernel_spec",
"(",
"kernel_name",
")",
"except",
"(",
"NoSuchKernel",
",",
"FileNotFoundError",
"... | Returns a :class:`KernelSpec` instance for the given kernel_name.
Raises :exc:`NoSuchKernel` if the given kernel name is not found. | [
"Returns",
"a",
":",
"class",
":",
"KernelSpec",
"instance",
"for",
"the",
"given",
"kernel_name",
"."
] | train | https://github.com/Cadair/jupyter_environment_kernels/blob/3da304550b511bda7d5d39280379b5ca39bb31bc/environment_kernels/core.py#L205-L219 |
opendatakosovo/cyrillic-transliteration | cyrtranslit/__init__.py | to_latin | def to_latin(string_to_transliterate, lang_code='sr'):
''' Transliterate serbian cyrillic string of characters to latin string of characters.
:param string_to_transliterate: The cyrillic string to transliterate into latin characters.
:param lang_code: Indicates the cyrillic language code we are translating ... | python | def to_latin(string_to_transliterate, lang_code='sr'):
''' Transliterate serbian cyrillic string of characters to latin string of characters.
:param string_to_transliterate: The cyrillic string to transliterate into latin characters.
:param lang_code: Indicates the cyrillic language code we are translating ... | [
"def",
"to_latin",
"(",
"string_to_transliterate",
",",
"lang_code",
"=",
"'sr'",
")",
":",
"# First check if we support the cyrillic alphabet we want to transliterate to latin.",
"if",
"lang_code",
".",
"lower",
"(",
")",
"not",
"in",
"TRANSLIT_DICT",
":",
"# If we don't s... | Transliterate serbian cyrillic string of characters to latin string of characters.
:param string_to_transliterate: The cyrillic string to transliterate into latin characters.
:param lang_code: Indicates the cyrillic language code we are translating from. Defaults to Serbian (sr).
:return: A string of latin ... | [
"Transliterate",
"serbian",
"cyrillic",
"string",
"of",
"characters",
"to",
"latin",
"string",
"of",
"characters",
".",
":",
"param",
"string_to_transliterate",
":",
"The",
"cyrillic",
"string",
"to",
"transliterate",
"into",
"latin",
"characters",
".",
":",
"para... | train | https://github.com/opendatakosovo/cyrillic-transliteration/blob/84dad6208759d1dc540161e28414026d0e2908f6/cyrtranslit/__init__.py#L17-L59 |
opendatakosovo/cyrillic-transliteration | cyrtranslit/__init__.py | to_cyrillic | def to_cyrillic(string_to_transliterate, lang_code='sr'):
''' Transliterate serbian latin string of characters to cyrillic string of characters.
:param string_to_transliterate: The latin string to transliterate into cyrillic characters.
:param lang_code: Indicates the cyrillic language code we are translati... | python | def to_cyrillic(string_to_transliterate, lang_code='sr'):
''' Transliterate serbian latin string of characters to cyrillic string of characters.
:param string_to_transliterate: The latin string to transliterate into cyrillic characters.
:param lang_code: Indicates the cyrillic language code we are translati... | [
"def",
"to_cyrillic",
"(",
"string_to_transliterate",
",",
"lang_code",
"=",
"'sr'",
")",
":",
"# First check if we support the cyrillic alphabet we want to transliterate to latin.",
"if",
"lang_code",
".",
"lower",
"(",
")",
"not",
"in",
"TRANSLIT_DICT",
":",
"# If we don'... | Transliterate serbian latin string of characters to cyrillic string of characters.
:param string_to_transliterate: The latin string to transliterate into cyrillic characters.
:param lang_code: Indicates the cyrillic language code we are translating to. Defaults to Serbian (sr).
:return: A string of cyrillic... | [
"Transliterate",
"serbian",
"latin",
"string",
"of",
"characters",
"to",
"cyrillic",
"string",
"of",
"characters",
".",
":",
"param",
"string_to_transliterate",
":",
"The",
"latin",
"string",
"to",
"transliterate",
"into",
"cyrillic",
"characters",
".",
":",
"para... | train | https://github.com/opendatakosovo/cyrillic-transliteration/blob/84dad6208759d1dc540161e28414026d0e2908f6/cyrtranslit/__init__.py#L62-L137 |
jpadilla/django-rest-framework-xml | rest_framework_xml/parsers.py | XMLParser.parse | def parse(self, stream, media_type=None, parser_context=None):
"""
Parses the incoming bytestream as XML and returns the resulting data.
"""
assert etree, 'XMLParser requires defusedxml to be installed'
parser_context = parser_context or {}
encoding = parser_context.get(... | python | def parse(self, stream, media_type=None, parser_context=None):
"""
Parses the incoming bytestream as XML and returns the resulting data.
"""
assert etree, 'XMLParser requires defusedxml to be installed'
parser_context = parser_context or {}
encoding = parser_context.get(... | [
"def",
"parse",
"(",
"self",
",",
"stream",
",",
"media_type",
"=",
"None",
",",
"parser_context",
"=",
"None",
")",
":",
"assert",
"etree",
",",
"'XMLParser requires defusedxml to be installed'",
"parser_context",
"=",
"parser_context",
"or",
"{",
"}",
"encoding"... | Parses the incoming bytestream as XML and returns the resulting data. | [
"Parses",
"the",
"incoming",
"bytestream",
"as",
"XML",
"and",
"returns",
"the",
"resulting",
"data",
"."
] | train | https://github.com/jpadilla/django-rest-framework-xml/blob/71c2f88b40c80ffd5029022147a57cc7341ef013/rest_framework_xml/parsers.py#L23-L38 |
jpadilla/django-rest-framework-xml | rest_framework_xml/parsers.py | XMLParser._xml_convert | def _xml_convert(self, element):
"""
convert the xml `element` into the corresponding python object
"""
children = list(element)
if len(children) == 0:
return self._type_convert(element.text)
else:
# if the fist child tag is list-item means all c... | python | def _xml_convert(self, element):
"""
convert the xml `element` into the corresponding python object
"""
children = list(element)
if len(children) == 0:
return self._type_convert(element.text)
else:
# if the fist child tag is list-item means all c... | [
"def",
"_xml_convert",
"(",
"self",
",",
"element",
")",
":",
"children",
"=",
"list",
"(",
"element",
")",
"if",
"len",
"(",
"children",
")",
"==",
"0",
":",
"return",
"self",
".",
"_type_convert",
"(",
"element",
".",
"text",
")",
"else",
":",
"# i... | convert the xml `element` into the corresponding python object | [
"convert",
"the",
"xml",
"element",
"into",
"the",
"corresponding",
"python",
"object"
] | train | https://github.com/jpadilla/django-rest-framework-xml/blob/71c2f88b40c80ffd5029022147a57cc7341ef013/rest_framework_xml/parsers.py#L40-L60 |
jpadilla/django-rest-framework-xml | rest_framework_xml/parsers.py | XMLParser._type_convert | def _type_convert(self, value):
"""
Converts the value returned by the XMl parse into the equivalent
Python type
"""
if value is None:
return value
try:
return datetime.datetime.strptime(value, '%Y-%m-%d %H:%M:%S')
except ValueError:
... | python | def _type_convert(self, value):
"""
Converts the value returned by the XMl parse into the equivalent
Python type
"""
if value is None:
return value
try:
return datetime.datetime.strptime(value, '%Y-%m-%d %H:%M:%S')
except ValueError:
... | [
"def",
"_type_convert",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"is",
"None",
":",
"return",
"value",
"try",
":",
"return",
"datetime",
".",
"datetime",
".",
"strptime",
"(",
"value",
",",
"'%Y-%m-%d %H:%M:%S'",
")",
"except",
"ValueError",
":"... | Converts the value returned by the XMl parse into the equivalent
Python type | [
"Converts",
"the",
"value",
"returned",
"by",
"the",
"XMl",
"parse",
"into",
"the",
"equivalent",
"Python",
"type"
] | train | https://github.com/jpadilla/django-rest-framework-xml/blob/71c2f88b40c80ffd5029022147a57cc7341ef013/rest_framework_xml/parsers.py#L62-L85 |
jpadilla/django-rest-framework-xml | rest_framework_xml/renderers.py | XMLRenderer.render | def render(self, data, accepted_media_type=None, renderer_context=None):
"""
Renders `data` into serialized XML.
"""
if data is None:
return ''
stream = StringIO()
xml = SimplerXMLGenerator(stream, self.charset)
xml.startDocument()
xml.startE... | python | def render(self, data, accepted_media_type=None, renderer_context=None):
"""
Renders `data` into serialized XML.
"""
if data is None:
return ''
stream = StringIO()
xml = SimplerXMLGenerator(stream, self.charset)
xml.startDocument()
xml.startE... | [
"def",
"render",
"(",
"self",
",",
"data",
",",
"accepted_media_type",
"=",
"None",
",",
"renderer_context",
"=",
"None",
")",
":",
"if",
"data",
"is",
"None",
":",
"return",
"''",
"stream",
"=",
"StringIO",
"(",
")",
"xml",
"=",
"SimplerXMLGenerator",
"... | Renders `data` into serialized XML. | [
"Renders",
"data",
"into",
"serialized",
"XML",
"."
] | train | https://github.com/jpadilla/django-rest-framework-xml/blob/71c2f88b40c80ffd5029022147a57cc7341ef013/rest_framework_xml/renderers.py#L24-L41 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver.open | def open(self):
"""Open a connection to the device."""
device_type = 'cisco_ios'
if self.transport == 'telnet':
device_type = 'cisco_ios_telnet'
self.device = ConnectHandler(device_type=device_type,
host=self.hostname,
... | python | def open(self):
"""Open a connection to the device."""
device_type = 'cisco_ios'
if self.transport == 'telnet':
device_type = 'cisco_ios_telnet'
self.device = ConnectHandler(device_type=device_type,
host=self.hostname,
... | [
"def",
"open",
"(",
"self",
")",
":",
"device_type",
"=",
"'cisco_ios'",
"if",
"self",
".",
"transport",
"==",
"'telnet'",
":",
"device_type",
"=",
"'cisco_ios_telnet'",
"self",
".",
"device",
"=",
"ConnectHandler",
"(",
"device_type",
"=",
"device_type",
",",... | Open a connection to the device. | [
"Open",
"a",
"connection",
"to",
"the",
"device",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L131-L142 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver._create_tmp_file | def _create_tmp_file(config):
"""Write temp file and for use with inline config and SCP."""
tmp_dir = tempfile.gettempdir()
rand_fname = py23_compat.text_type(uuid.uuid4())
filename = os.path.join(tmp_dir, rand_fname)
with open(filename, 'wt') as fobj:
fobj.write(conf... | python | def _create_tmp_file(config):
"""Write temp file and for use with inline config and SCP."""
tmp_dir = tempfile.gettempdir()
rand_fname = py23_compat.text_type(uuid.uuid4())
filename = os.path.join(tmp_dir, rand_fname)
with open(filename, 'wt') as fobj:
fobj.write(conf... | [
"def",
"_create_tmp_file",
"(",
"config",
")",
":",
"tmp_dir",
"=",
"tempfile",
".",
"gettempdir",
"(",
")",
"rand_fname",
"=",
"py23_compat",
".",
"text_type",
"(",
"uuid",
".",
"uuid4",
"(",
")",
")",
"filename",
"=",
"os",
".",
"path",
".",
"join",
... | Write temp file and for use with inline config and SCP. | [
"Write",
"temp",
"file",
"and",
"for",
"use",
"with",
"inline",
"config",
"and",
"SCP",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L201-L208 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver._load_candidate_wrapper | def _load_candidate_wrapper(self, source_file=None, source_config=None, dest_file=None,
file_system=None):
"""
Transfer file to remote device for either merge or replace operations
Returns (return_status, msg)
"""
return_status = False
msg... | python | def _load_candidate_wrapper(self, source_file=None, source_config=None, dest_file=None,
file_system=None):
"""
Transfer file to remote device for either merge or replace operations
Returns (return_status, msg)
"""
return_status = False
msg... | [
"def",
"_load_candidate_wrapper",
"(",
"self",
",",
"source_file",
"=",
"None",
",",
"source_config",
"=",
"None",
",",
"dest_file",
"=",
"None",
",",
"file_system",
"=",
"None",
")",
":",
"return_status",
"=",
"False",
"msg",
"=",
"''",
"if",
"source_file",... | Transfer file to remote device for either merge or replace operations
Returns (return_status, msg) | [
"Transfer",
"file",
"to",
"remote",
"device",
"for",
"either",
"merge",
"or",
"replace",
"operations"
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L210-L245 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver.load_replace_candidate | def load_replace_candidate(self, filename=None, config=None):
"""
SCP file to device filesystem, defaults to candidate_config.
Return None or raise exception
"""
self.config_replace = True
return_status, msg = self._load_candidate_wrapper(source_file=filename,
... | python | def load_replace_candidate(self, filename=None, config=None):
"""
SCP file to device filesystem, defaults to candidate_config.
Return None or raise exception
"""
self.config_replace = True
return_status, msg = self._load_candidate_wrapper(source_file=filename,
... | [
"def",
"load_replace_candidate",
"(",
"self",
",",
"filename",
"=",
"None",
",",
"config",
"=",
"None",
")",
":",
"self",
".",
"config_replace",
"=",
"True",
"return_status",
",",
"msg",
"=",
"self",
".",
"_load_candidate_wrapper",
"(",
"source_file",
"=",
"... | SCP file to device filesystem, defaults to candidate_config.
Return None or raise exception | [
"SCP",
"file",
"to",
"device",
"filesystem",
"defaults",
"to",
"candidate_config",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L247-L259 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver.load_merge_candidate | def load_merge_candidate(self, filename=None, config=None):
"""
SCP file to remote device.
Merge configuration in: copy <file> running-config
"""
self.config_replace = False
return_status, msg = self._load_candidate_wrapper(source_file=filename,
... | python | def load_merge_candidate(self, filename=None, config=None):
"""
SCP file to remote device.
Merge configuration in: copy <file> running-config
"""
self.config_replace = False
return_status, msg = self._load_candidate_wrapper(source_file=filename,
... | [
"def",
"load_merge_candidate",
"(",
"self",
",",
"filename",
"=",
"None",
",",
"config",
"=",
"None",
")",
":",
"self",
".",
"config_replace",
"=",
"False",
"return_status",
",",
"msg",
"=",
"self",
".",
"_load_candidate_wrapper",
"(",
"source_file",
"=",
"f... | SCP file to remote device.
Merge configuration in: copy <file> running-config | [
"SCP",
"file",
"to",
"remote",
"device",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L261-L273 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver._commit_hostname_handler | def _commit_hostname_handler(self, cmd):
"""Special handler for hostname change on commit operation."""
current_prompt = self.device.find_prompt().strip()
terminating_char = current_prompt[-1]
pattern = r"[>#{}]\s*$".format(terminating_char)
# Look exclusively for trailing patter... | python | def _commit_hostname_handler(self, cmd):
"""Special handler for hostname change on commit operation."""
current_prompt = self.device.find_prompt().strip()
terminating_char = current_prompt[-1]
pattern = r"[>#{}]\s*$".format(terminating_char)
# Look exclusively for trailing patter... | [
"def",
"_commit_hostname_handler",
"(",
"self",
",",
"cmd",
")",
":",
"current_prompt",
"=",
"self",
".",
"device",
".",
"find_prompt",
"(",
")",
".",
"strip",
"(",
")",
"terminating_char",
"=",
"current_prompt",
"[",
"-",
"1",
"]",
"pattern",
"=",
"r\"[>#... | Special handler for hostname change on commit operation. | [
"Special",
"handler",
"for",
"hostname",
"change",
"on",
"commit",
"operation",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L378-L387 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver.commit_config | def commit_config(self):
"""
If replacement operation, perform 'configure replace' for the entire config.
If merge operation, perform copy <file> running-config.
"""
# Always generate a rollback config on commit
self._gen_rollback_cfg()
if self.config_replace:
... | python | def commit_config(self):
"""
If replacement operation, perform 'configure replace' for the entire config.
If merge operation, perform copy <file> running-config.
"""
# Always generate a rollback config on commit
self._gen_rollback_cfg()
if self.config_replace:
... | [
"def",
"commit_config",
"(",
"self",
")",
":",
"# Always generate a rollback config on commit",
"self",
".",
"_gen_rollback_cfg",
"(",
")",
"if",
"self",
".",
"config_replace",
":",
"# Replace operation",
"filename",
"=",
"self",
".",
"candidate_cfg",
"cfg_file",
"=",... | If replacement operation, perform 'configure replace' for the entire config.
If merge operation, perform copy <file> running-config. | [
"If",
"replacement",
"operation",
"perform",
"configure",
"replace",
"for",
"the",
"entire",
"config",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L389-L434 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver.discard_config | def discard_config(self):
"""Set candidate_cfg to current running-config. Erase the merge_cfg file."""
discard_candidate = 'copy running-config {}'.format(self._gen_full_path(self.candidate_cfg))
discard_merge = 'copy null: {}'.format(self._gen_full_path(self.merge_cfg))
self._disable_co... | python | def discard_config(self):
"""Set candidate_cfg to current running-config. Erase the merge_cfg file."""
discard_candidate = 'copy running-config {}'.format(self._gen_full_path(self.candidate_cfg))
discard_merge = 'copy null: {}'.format(self._gen_full_path(self.merge_cfg))
self._disable_co... | [
"def",
"discard_config",
"(",
"self",
")",
":",
"discard_candidate",
"=",
"'copy running-config {}'",
".",
"format",
"(",
"self",
".",
"_gen_full_path",
"(",
"self",
".",
"candidate_cfg",
")",
")",
"discard_merge",
"=",
"'copy null: {}'",
".",
"format",
"(",
"se... | Set candidate_cfg to current running-config. Erase the merge_cfg file. | [
"Set",
"candidate_cfg",
"to",
"current",
"running",
"-",
"config",
".",
"Erase",
"the",
"merge_cfg",
"file",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L436-L443 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver._xfer_file | def _xfer_file(self, source_file=None, source_config=None, dest_file=None, file_system=None,
TransferClass=FileTransfer):
"""Transfer file to remote device.
By default, this will use Secure Copy if self.inline_transfer is set, then will use
Netmiko InlineTransfer method to tr... | python | def _xfer_file(self, source_file=None, source_config=None, dest_file=None, file_system=None,
TransferClass=FileTransfer):
"""Transfer file to remote device.
By default, this will use Secure Copy if self.inline_transfer is set, then will use
Netmiko InlineTransfer method to tr... | [
"def",
"_xfer_file",
"(",
"self",
",",
"source_file",
"=",
"None",
",",
"source_config",
"=",
"None",
",",
"dest_file",
"=",
"None",
",",
"file_system",
"=",
"None",
",",
"TransferClass",
"=",
"FileTransfer",
")",
":",
"if",
"not",
"source_file",
"and",
"n... | Transfer file to remote device.
By default, this will use Secure Copy if self.inline_transfer is set, then will use
Netmiko InlineTransfer method to transfer inline using either SSH or telnet (plus TCL
onbox).
Return (status, msg)
status = boolean
msg = details on what ... | [
"Transfer",
"file",
"to",
"remote",
"device",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L485-L534 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver._gen_full_path | def _gen_full_path(self, filename, file_system=None):
"""Generate full file path on remote device."""
if file_system is None:
return '{}/{}'.format(self.dest_file_system, filename)
else:
if ":" not in file_system:
raise ValueError("Invalid file_system spec... | python | def _gen_full_path(self, filename, file_system=None):
"""Generate full file path on remote device."""
if file_system is None:
return '{}/{}'.format(self.dest_file_system, filename)
else:
if ":" not in file_system:
raise ValueError("Invalid file_system spec... | [
"def",
"_gen_full_path",
"(",
"self",
",",
"filename",
",",
"file_system",
"=",
"None",
")",
":",
"if",
"file_system",
"is",
"None",
":",
"return",
"'{}/{}'",
".",
"format",
"(",
"self",
".",
"dest_file_system",
",",
"filename",
")",
"else",
":",
"if",
"... | Generate full file path on remote device. | [
"Generate",
"full",
"file",
"path",
"on",
"remote",
"device",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L546-L553 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver._gen_rollback_cfg | def _gen_rollback_cfg(self):
"""Save a configuration that can be used for rollback."""
cfg_file = self._gen_full_path(self.rollback_cfg)
cmd = 'copy running-config {}'.format(cfg_file)
self._disable_confirm()
self.device.send_command_expect(cmd)
self._enable_confirm() | python | def _gen_rollback_cfg(self):
"""Save a configuration that can be used for rollback."""
cfg_file = self._gen_full_path(self.rollback_cfg)
cmd = 'copy running-config {}'.format(cfg_file)
self._disable_confirm()
self.device.send_command_expect(cmd)
self._enable_confirm() | [
"def",
"_gen_rollback_cfg",
"(",
"self",
")",
":",
"cfg_file",
"=",
"self",
".",
"_gen_full_path",
"(",
"self",
".",
"rollback_cfg",
")",
"cmd",
"=",
"'copy running-config {}'",
".",
"format",
"(",
"cfg_file",
")",
"self",
".",
"_disable_confirm",
"(",
")",
... | Save a configuration that can be used for rollback. | [
"Save",
"a",
"configuration",
"that",
"can",
"be",
"used",
"for",
"rollback",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L555-L561 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver._check_file_exists | def _check_file_exists(self, cfg_file):
"""
Check that the file exists on remote device using full path.
cfg_file is full path i.e. flash:/file_name
For example
# dir flash:/candidate_config.txt
Directory of flash:/candidate_config.txt
33 -rw- 5592 Dec... | python | def _check_file_exists(self, cfg_file):
"""
Check that the file exists on remote device using full path.
cfg_file is full path i.e. flash:/file_name
For example
# dir flash:/candidate_config.txt
Directory of flash:/candidate_config.txt
33 -rw- 5592 Dec... | [
"def",
"_check_file_exists",
"(",
"self",
",",
"cfg_file",
")",
":",
"cmd",
"=",
"'dir {}'",
".",
"format",
"(",
"cfg_file",
")",
"success_pattern",
"=",
"'Directory of {}'",
".",
"format",
"(",
"cfg_file",
")",
"output",
"=",
"self",
".",
"device",
".",
"... | Check that the file exists on remote device using full path.
cfg_file is full path i.e. flash:/file_name
For example
# dir flash:/candidate_config.txt
Directory of flash:/candidate_config.txt
33 -rw- 5592 Dec 18 2015 10:50:22 -08:00 candidate_config.txt
retu... | [
"Check",
"that",
"the",
"file",
"exists",
"on",
"remote",
"device",
"using",
"full",
"path",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L563-L584 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver._expand_interface_name | def _expand_interface_name(self, interface_brief):
"""
Obtain the full interface name from the abbreviated name.
Cache mappings in self.interface_map.
"""
if self.interface_map.get(interface_brief):
return self.interface_map.get(interface_brief)
command = 'sh... | python | def _expand_interface_name(self, interface_brief):
"""
Obtain the full interface name from the abbreviated name.
Cache mappings in self.interface_map.
"""
if self.interface_map.get(interface_brief):
return self.interface_map.get(interface_brief)
command = 'sh... | [
"def",
"_expand_interface_name",
"(",
"self",
",",
"interface_brief",
")",
":",
"if",
"self",
".",
"interface_map",
".",
"get",
"(",
"interface_brief",
")",
":",
"return",
"self",
".",
"interface_map",
".",
"get",
"(",
"interface_brief",
")",
"command",
"=",
... | Obtain the full interface name from the abbreviated name.
Cache mappings in self.interface_map. | [
"Obtain",
"the",
"full",
"interface",
"name",
"from",
"the",
"abbreviated",
"name",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L586-L602 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver.get_lldp_neighbors | def get_lldp_neighbors(self):
"""IOS implementation of get_lldp_neighbors."""
lldp = {}
command = 'show lldp neighbors'
output = self._send_command(command)
# Check if router supports the command
if '% Invalid input' in output:
return {}
# Process th... | python | def get_lldp_neighbors(self):
"""IOS implementation of get_lldp_neighbors."""
lldp = {}
command = 'show lldp neighbors'
output = self._send_command(command)
# Check if router supports the command
if '% Invalid input' in output:
return {}
# Process th... | [
"def",
"get_lldp_neighbors",
"(",
"self",
")",
":",
"lldp",
"=",
"{",
"}",
"command",
"=",
"'show lldp neighbors'",
"output",
"=",
"self",
".",
"_send_command",
"(",
"command",
")",
"# Check if router supports the command",
"if",
"'% Invalid input'",
"in",
"output",... | IOS implementation of get_lldp_neighbors. | [
"IOS",
"implementation",
"of",
"get_lldp_neighbors",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L690-L738 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver.get_lldp_neighbors_detail | def get_lldp_neighbors_detail(self, interface=''):
"""
IOS implementation of get_lldp_neighbors_detail.
Calls get_lldp_neighbors.
"""
lldp = {}
lldp_neighbors = self.get_lldp_neighbors()
# Filter to specific interface
if interface:
lldp_data ... | python | def get_lldp_neighbors_detail(self, interface=''):
"""
IOS implementation of get_lldp_neighbors_detail.
Calls get_lldp_neighbors.
"""
lldp = {}
lldp_neighbors = self.get_lldp_neighbors()
# Filter to specific interface
if interface:
lldp_data ... | [
"def",
"get_lldp_neighbors_detail",
"(",
"self",
",",
"interface",
"=",
"''",
")",
":",
"lldp",
"=",
"{",
"}",
"lldp_neighbors",
"=",
"self",
".",
"get_lldp_neighbors",
"(",
")",
"# Filter to specific interface",
"if",
"interface",
":",
"lldp_data",
"=",
"lldp_n... | IOS implementation of get_lldp_neighbors_detail.
Calls get_lldp_neighbors. | [
"IOS",
"implementation",
"of",
"get_lldp_neighbors_detail",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L773-L828 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver.get_facts | def get_facts(self):
"""Return a set of facts from the devices."""
# default values.
vendor = u'Cisco'
uptime = -1
serial_number, fqdn, os_version, hostname, domain_name = ('Unknown',) * 5
# obtain output from device
show_ver = self._send_command('show version')
... | python | def get_facts(self):
"""Return a set of facts from the devices."""
# default values.
vendor = u'Cisco'
uptime = -1
serial_number, fqdn, os_version, hostname, domain_name = ('Unknown',) * 5
# obtain output from device
show_ver = self._send_command('show version')
... | [
"def",
"get_facts",
"(",
"self",
")",
":",
"# default values.",
"vendor",
"=",
"u'Cisco'",
"uptime",
"=",
"-",
"1",
"serial_number",
",",
"fqdn",
",",
"os_version",
",",
"hostname",
",",
"domain_name",
"=",
"(",
"'Unknown'",
",",
")",
"*",
"5",
"# obtain o... | Return a set of facts from the devices. | [
"Return",
"a",
"set",
"of",
"facts",
"from",
"the",
"devices",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L858-L926 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver.get_interfaces | def get_interfaces(self):
"""
Get interface details.
last_flapped is not implemented
Example Output:
{ u'Vlan1': { 'description': u'N/A',
'is_enabled': True,
'is_up': True,
'last_flapped': -1.0,
... | python | def get_interfaces(self):
"""
Get interface details.
last_flapped is not implemented
Example Output:
{ u'Vlan1': { 'description': u'N/A',
'is_enabled': True,
'is_up': True,
'last_flapped': -1.0,
... | [
"def",
"get_interfaces",
"(",
"self",
")",
":",
"# default values.",
"last_flapped",
"=",
"-",
"1.0",
"command",
"=",
"'show interfaces'",
"output",
"=",
"self",
".",
"_send_command",
"(",
"command",
")",
"interface",
"=",
"description",
"=",
"mac_address",
"=",... | Get interface details.
last_flapped is not implemented
Example Output:
{ u'Vlan1': { 'description': u'N/A',
'is_enabled': True,
'is_up': True,
'last_flapped': -1.0,
'mac_address': u'a493.4cc1.67a7',
... | [
"Get",
"interface",
"details",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L928-L1023 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver.get_interfaces_ip | def get_interfaces_ip(self):
"""
Get interface ip details.
Returns a dict of dicts
Example Output:
{ u'FastEthernet8': { 'ipv4': { u'10.66.43.169': { 'prefix_length': 22}}},
u'Loopback555': { 'ipv4': { u'192.168.1.1': { 'prefix_length': 24}},
... | python | def get_interfaces_ip(self):
"""
Get interface ip details.
Returns a dict of dicts
Example Output:
{ u'FastEthernet8': { 'ipv4': { u'10.66.43.169': { 'prefix_length': 22}}},
u'Loopback555': { 'ipv4': { u'192.168.1.1': { 'prefix_length': 24}},
... | [
"def",
"get_interfaces_ip",
"(",
"self",
")",
":",
"interfaces",
"=",
"{",
"}",
"command",
"=",
"'show ip interface'",
"show_ip_interface",
"=",
"self",
".",
"_send_command",
"(",
"command",
")",
"command",
"=",
"'show ipv6 interface'",
"show_ipv6_interface",
"=",
... | Get interface ip details.
Returns a dict of dicts
Example Output:
{ u'FastEthernet8': { 'ipv4': { u'10.66.43.169': { 'prefix_length': 22}}},
u'Loopback555': { 'ipv4': { u'192.168.1.1': { 'prefix_length': 24}},
'ipv6': { u'1::1': { ... | [
"Get",
"interface",
"ip",
"details",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L1025-L1091 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver.bgp_time_conversion | def bgp_time_conversion(bgp_uptime):
"""
Convert string time to seconds.
Examples
00:14:23
00:13:40
00:00:21
00:00:13
00:00:49
1d11h
1d17h
1w0d
8w5d
1y28w
never
"""
bgp_uptime = bgp_uptime.st... | python | def bgp_time_conversion(bgp_uptime):
"""
Convert string time to seconds.
Examples
00:14:23
00:13:40
00:00:21
00:00:13
00:00:49
1d11h
1d17h
1w0d
8w5d
1y28w
never
"""
bgp_uptime = bgp_uptime.st... | [
"def",
"bgp_time_conversion",
"(",
"bgp_uptime",
")",
":",
"bgp_uptime",
"=",
"bgp_uptime",
".",
"strip",
"(",
")",
"uptime_letters",
"=",
"set",
"(",
"[",
"'w'",
",",
"'h'",
",",
"'d'",
"]",
")",
"if",
"'never'",
"in",
"bgp_uptime",
":",
"return",
"-",
... | Convert string time to seconds.
Examples
00:14:23
00:13:40
00:00:21
00:00:13
00:00:49
1d11h
1d17h
1w0d
8w5d
1y28w
never | [
"Convert",
"string",
"time",
"to",
"seconds",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L1094-L1141 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver.get_bgp_neighbors | def get_bgp_neighbors(self):
"""BGP neighbor information.
Currently no VRF support. Supports both IPv4 and IPv6.
"""
supported_afi = ['ipv4', 'ipv6']
bgp_neighbor_data = dict()
bgp_neighbor_data['global'] = {}
# get summary output from device
cmd_bgp_al... | python | def get_bgp_neighbors(self):
"""BGP neighbor information.
Currently no VRF support. Supports both IPv4 and IPv6.
"""
supported_afi = ['ipv4', 'ipv6']
bgp_neighbor_data = dict()
bgp_neighbor_data['global'] = {}
# get summary output from device
cmd_bgp_al... | [
"def",
"get_bgp_neighbors",
"(",
"self",
")",
":",
"supported_afi",
"=",
"[",
"'ipv4'",
",",
"'ipv6'",
"]",
"bgp_neighbor_data",
"=",
"dict",
"(",
")",
"bgp_neighbor_data",
"[",
"'global'",
"]",
"=",
"{",
"}",
"# get summary output from device",
"cmd_bgp_all_sum",... | BGP neighbor information.
Currently no VRF support. Supports both IPv4 and IPv6. | [
"BGP",
"neighbor",
"information",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L1143-L1419 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver.get_environment | def get_environment(self):
"""
Get environment facts.
power and fan are currently not implemented
cpu is using 1-minute average
cpu hard-coded to cpu0 (i.e. only a single CPU)
"""
environment = {}
cpu_cmd = 'show proc cpu'
mem_cmd = 'show memory s... | python | def get_environment(self):
"""
Get environment facts.
power and fan are currently not implemented
cpu is using 1-minute average
cpu hard-coded to cpu0 (i.e. only a single CPU)
"""
environment = {}
cpu_cmd = 'show proc cpu'
mem_cmd = 'show memory s... | [
"def",
"get_environment",
"(",
"self",
")",
":",
"environment",
"=",
"{",
"}",
"cpu_cmd",
"=",
"'show proc cpu'",
"mem_cmd",
"=",
"'show memory statistics'",
"temp_cmd",
"=",
"'show env temperature status'",
"output",
"=",
"self",
".",
"_send_command",
"(",
"cpu_cmd... | Get environment facts.
power and fan are currently not implemented
cpu is using 1-minute average
cpu hard-coded to cpu0 (i.e. only a single CPU) | [
"Get",
"environment",
"facts",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L1520-L1581 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver.get_arp_table | def get_arp_table(self):
"""
Get arp table information.
Return a list of dictionaries having the following set of keys:
* interface (string)
* mac (string)
* ip (string)
* age (float)
For example::
[
{
... | python | def get_arp_table(self):
"""
Get arp table information.
Return a list of dictionaries having the following set of keys:
* interface (string)
* mac (string)
* ip (string)
* age (float)
For example::
[
{
... | [
"def",
"get_arp_table",
"(",
"self",
")",
":",
"arp_table",
"=",
"[",
"]",
"command",
"=",
"'show arp | exclude Incomplete'",
"output",
"=",
"self",
".",
"_send_command",
"(",
"command",
")",
"# Skip the first line which is a header",
"output",
"=",
"output",
".",
... | Get arp table information.
Return a list of dictionaries having the following set of keys:
* interface (string)
* mac (string)
* ip (string)
* age (float)
For example::
[
{
'interface' : 'MgmtEth0/RSP0/CPU0... | [
"Get",
"arp",
"table",
"information",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L1583-L1650 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver.cli | def cli(self, commands):
"""
Execute a list of commands and return the output in a dictionary format using the command
as the key.
Example input:
['show clock', 'show calendar']
Output example:
{ 'show calendar': u'22:02:01 UTC Thu Feb 18 2016',
's... | python | def cli(self, commands):
"""
Execute a list of commands and return the output in a dictionary format using the command
as the key.
Example input:
['show clock', 'show calendar']
Output example:
{ 'show calendar': u'22:02:01 UTC Thu Feb 18 2016',
's... | [
"def",
"cli",
"(",
"self",
",",
"commands",
")",
":",
"cli_output",
"=",
"dict",
"(",
")",
"if",
"type",
"(",
"commands",
")",
"is",
"not",
"list",
":",
"raise",
"TypeError",
"(",
"'Please enter a valid list of commands!'",
")",
"for",
"command",
"in",
"co... | Execute a list of commands and return the output in a dictionary format using the command
as the key.
Example input:
['show clock', 'show calendar']
Output example:
{ 'show calendar': u'22:02:01 UTC Thu Feb 18 2016',
'show clock': u'*22:01:51.165 UTC Thu Feb 18 20... | [
"Execute",
"a",
"list",
"of",
"commands",
"and",
"return",
"the",
"output",
"in",
"a",
"dictionary",
"format",
"using",
"the",
"command",
"as",
"the",
"key",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L1652-L1676 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver.get_mac_address_table | def get_mac_address_table(self):
"""
Returns a lists of dictionaries. Each dictionary represents an entry in the MAC Address
Table, having the following keys
* mac (string)
* interface (string)
* vlan (int)
* active (boolean)
* static (... | python | def get_mac_address_table(self):
"""
Returns a lists of dictionaries. Each dictionary represents an entry in the MAC Address
Table, having the following keys
* mac (string)
* interface (string)
* vlan (int)
* active (boolean)
* static (... | [
"def",
"get_mac_address_table",
"(",
"self",
")",
":",
"RE_MACTABLE_DEFAULT",
"=",
"r\"^\"",
"+",
"MAC_REGEX",
"RE_MACTABLE_6500_1",
"=",
"r\"^\\*\\s+{}\\s+{}\\s+\"",
".",
"format",
"(",
"VLAN_REGEX",
",",
"MAC_REGEX",
")",
"# 7 fields",
"RE_MACTABLE_6500_2",
"=",
"r\... | Returns a lists of dictionaries. Each dictionary represents an entry in the MAC Address
Table, having the following keys
* mac (string)
* interface (string)
* vlan (int)
* active (boolean)
* static (boolean)
* moves (int)
* last... | [
"Returns",
"a",
"lists",
"of",
"dictionaries",
".",
"Each",
"dictionary",
"represents",
"an",
"entry",
"in",
"the",
"MAC",
"Address",
"Table",
"having",
"the",
"following",
"keys",
"*",
"mac",
"(",
"string",
")",
"*",
"interface",
"(",
"string",
")",
"*",
... | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L1742-L1903 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver.traceroute | def traceroute(self, destination, source=C.TRACEROUTE_SOURCE,
ttl=C.TRACEROUTE_TTL, timeout=C.TRACEROUTE_TIMEOUT, vrf=C.TRACEROUTE_VRF):
"""
Executes traceroute on the device and returns a dictionary with the result.
:param destination: Host or IP Address of the destination
... | python | def traceroute(self, destination, source=C.TRACEROUTE_SOURCE,
ttl=C.TRACEROUTE_TTL, timeout=C.TRACEROUTE_TIMEOUT, vrf=C.TRACEROUTE_VRF):
"""
Executes traceroute on the device and returns a dictionary with the result.
:param destination: Host or IP Address of the destination
... | [
"def",
"traceroute",
"(",
"self",
",",
"destination",
",",
"source",
"=",
"C",
".",
"TRACEROUTE_SOURCE",
",",
"ttl",
"=",
"C",
".",
"TRACEROUTE_TTL",
",",
"timeout",
"=",
"C",
".",
"TRACEROUTE_TIMEOUT",
",",
"vrf",
"=",
"C",
".",
"TRACEROUTE_VRF",
")",
"... | Executes traceroute on the device and returns a dictionary with the result.
:param destination: Host or IP Address of the destination
:param source (optional): Use a specific IP Address to execute the traceroute
:param ttl (optional): Maimum number of hops -> int (0-255)
:param timeout ... | [
"Executes",
"traceroute",
"on",
"the",
"device",
"and",
"returns",
"a",
"dictionary",
"with",
"the",
"result",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L2033-L2147 |
napalm-automation/napalm-ios | napalm_ios/ios.py | IOSDriver.get_config | def get_config(self, retrieve='all'):
"""Implementation of get_config for IOS.
Returns the startup or/and running configuration as dictionary.
The keys of the dictionary represent the type of configuration
(startup or running). The candidate is always empty string,
since IOS doe... | python | def get_config(self, retrieve='all'):
"""Implementation of get_config for IOS.
Returns the startup or/and running configuration as dictionary.
The keys of the dictionary represent the type of configuration
(startup or running). The candidate is always empty string,
since IOS doe... | [
"def",
"get_config",
"(",
"self",
",",
"retrieve",
"=",
"'all'",
")",
":",
"configs",
"=",
"{",
"'startup'",
":",
"''",
",",
"'running'",
":",
"''",
",",
"'candidate'",
":",
"''",
",",
"}",
"if",
"retrieve",
"in",
"(",
"'startup'",
",",
"'all'",
")",... | Implementation of get_config for IOS.
Returns the startup or/and running configuration as dictionary.
The keys of the dictionary represent the type of configuration
(startup or running). The candidate is always empty string,
since IOS does not support candidate configuration. | [
"Implementation",
"of",
"get_config",
"for",
"IOS",
"."
] | train | https://github.com/napalm-automation/napalm-ios/blob/7bbbc6a4d9f70a5b8cf32b7c7072a7ab437ddb81/napalm_ios/ios.py#L2149-L2174 |
adafruit/Adafruit_Python_ADXL345 | Adafruit_ADXL345/ADXL345.py | ADXL345.set_range | def set_range(self, value):
"""Set the range of the accelerometer to the provided value. Range value
should be one of these constants:
- ADXL345_RANGE_2_G = +/-2G
- ADXL345_RANGE_4_G = +/-4G
- ADXL345_RANGE_8_G = +/-8G
- ADXL345_RANGE_16_G = +/-16G
... | python | def set_range(self, value):
"""Set the range of the accelerometer to the provided value. Range value
should be one of these constants:
- ADXL345_RANGE_2_G = +/-2G
- ADXL345_RANGE_4_G = +/-4G
- ADXL345_RANGE_8_G = +/-8G
- ADXL345_RANGE_16_G = +/-16G
... | [
"def",
"set_range",
"(",
"self",
",",
"value",
")",
":",
"# Read the data format register to preserve bits. Update the data",
"# rate, make sure that the FULL-RES bit is enabled for range scaling",
"format_reg",
"=",
"self",
".",
"_device",
".",
"readU8",
"(",
"ADXL345_REG_DATA_... | Set the range of the accelerometer to the provided value. Range value
should be one of these constants:
- ADXL345_RANGE_2_G = +/-2G
- ADXL345_RANGE_4_G = +/-4G
- ADXL345_RANGE_8_G = +/-8G
- ADXL345_RANGE_16_G = +/-16G | [
"Set",
"the",
"range",
"of",
"the",
"accelerometer",
"to",
"the",
"provided",
"value",
".",
"Range",
"value",
"should",
"be",
"one",
"of",
"these",
"constants",
":",
"-",
"ADXL345_RANGE_2_G",
"=",
"+",
"/",
"-",
"2G",
"-",
"ADXL345_RANGE_4_G",
"=",
"+",
... | train | https://github.com/adafruit/Adafruit_Python_ADXL345/blob/d897bcaa16b5fe365463ae0c2791d0c155becd05/Adafruit_ADXL345/ADXL345.py#L70-L84 |
adafruit/Adafruit_Python_ADXL345 | Adafruit_ADXL345/ADXL345.py | ADXL345.read | def read(self):
"""Read the current value of the accelerometer and return it as a tuple
of signed 16-bit X, Y, Z axis values.
"""
raw = self._device.readList(ADXL345_REG_DATAX0, 6)
return struct.unpack('<hhh', raw) | python | def read(self):
"""Read the current value of the accelerometer and return it as a tuple
of signed 16-bit X, Y, Z axis values.
"""
raw = self._device.readList(ADXL345_REG_DATAX0, 6)
return struct.unpack('<hhh', raw) | [
"def",
"read",
"(",
"self",
")",
":",
"raw",
"=",
"self",
".",
"_device",
".",
"readList",
"(",
"ADXL345_REG_DATAX0",
",",
"6",
")",
"return",
"struct",
".",
"unpack",
"(",
"'<hhh'",
",",
"raw",
")"
] | Read the current value of the accelerometer and return it as a tuple
of signed 16-bit X, Y, Z axis values. | [
"Read",
"the",
"current",
"value",
"of",
"the",
"accelerometer",
"and",
"return",
"it",
"as",
"a",
"tuple",
"of",
"signed",
"16",
"-",
"bit",
"X",
"Y",
"Z",
"axis",
"values",
"."
] | train | https://github.com/adafruit/Adafruit_Python_ADXL345/blob/d897bcaa16b5fe365463ae0c2791d0c155becd05/Adafruit_ADXL345/ADXL345.py#L122-L127 |
piface/pifacedigitalio | pifacedigitalio/core.py | deinit | def deinit(bus=DEFAULT_SPI_BUS,
chip_select=DEFAULT_SPI_CHIP_SELECT):
"""Stops interrupts on all boards. Only required when using
:func:`digital_read` and :func:`digital_write`.
:param bus: SPI bus /dev/spidev<bus>.<chipselect> (default: {bus})
:type bus: int
:param chip_select: SPI chip... | python | def deinit(bus=DEFAULT_SPI_BUS,
chip_select=DEFAULT_SPI_CHIP_SELECT):
"""Stops interrupts on all boards. Only required when using
:func:`digital_read` and :func:`digital_write`.
:param bus: SPI bus /dev/spidev<bus>.<chipselect> (default: {bus})
:type bus: int
:param chip_select: SPI chip... | [
"def",
"deinit",
"(",
"bus",
"=",
"DEFAULT_SPI_BUS",
",",
"chip_select",
"=",
"DEFAULT_SPI_CHIP_SELECT",
")",
":",
"global",
"_pifacedigitals",
"for",
"pfd",
"in",
"_pifacedigitals",
":",
"try",
":",
"pfd",
".",
"deinit_board",
"(",
")",
"except",
"AttributeErro... | Stops interrupts on all boards. Only required when using
:func:`digital_read` and :func:`digital_write`.
:param bus: SPI bus /dev/spidev<bus>.<chipselect> (default: {bus})
:type bus: int
:param chip_select: SPI chip select /dev/spidev<bus>.<chipselect>
(default: {chip})
:type chip_select: i... | [
"Stops",
"interrupts",
"on",
"all",
"boards",
".",
"Only",
"required",
"when",
"using",
":",
"func",
":",
"digital_read",
"and",
":",
"func",
":",
"digital_write",
"."
] | train | https://github.com/piface/pifacedigitalio/blob/d231a82bdb55d5f57f44ba7aec00bfd6c0b9a9d4/pifacedigitalio/core.py#L176-L192 |
piface/pifacedigitalio | pifacedigitalio/core.py | digital_write | def digital_write(pin_num, value, hardware_addr=0):
"""Writes the value to the input pin specified.
.. note:: This function is for familiarality with users of other types of
IO board. Consider accessing the ``output_pins`` attribute of a
PiFaceDigital object:
>>> pfd = PiFaceDigital(hardw... | python | def digital_write(pin_num, value, hardware_addr=0):
"""Writes the value to the input pin specified.
.. note:: This function is for familiarality with users of other types of
IO board. Consider accessing the ``output_pins`` attribute of a
PiFaceDigital object:
>>> pfd = PiFaceDigital(hardw... | [
"def",
"digital_write",
"(",
"pin_num",
",",
"value",
",",
"hardware_addr",
"=",
"0",
")",
":",
"_get_pifacedigital",
"(",
"hardware_addr",
")",
".",
"output_pins",
"[",
"pin_num",
"]",
".",
"value",
"=",
"value"
] | Writes the value to the input pin specified.
.. note:: This function is for familiarality with users of other types of
IO board. Consider accessing the ``output_pins`` attribute of a
PiFaceDigital object:
>>> pfd = PiFaceDigital(hardware_addr)
>>> pfd.output_pins[pin_num].value = 1
... | [
"Writes",
"the",
"value",
"to",
"the",
"input",
"pin",
"specified",
"."
] | train | https://github.com/piface/pifacedigitalio/blob/d231a82bdb55d5f57f44ba7aec00bfd6c0b9a9d4/pifacedigitalio/core.py#L216-L233 |
piface/pifacedigitalio | pifacedigitalio/core.py | digital_write_pullup | def digital_write_pullup(pin_num, value, hardware_addr=0):
"""Writes the value to the input pullup specified.
.. note:: This function is for familiarality with users of other types of
IO board. Consider accessing the ``gppub`` attribute of a
PiFaceDigital object:
>>> pfd = PiFaceDigital(h... | python | def digital_write_pullup(pin_num, value, hardware_addr=0):
"""Writes the value to the input pullup specified.
.. note:: This function is for familiarality with users of other types of
IO board. Consider accessing the ``gppub`` attribute of a
PiFaceDigital object:
>>> pfd = PiFaceDigital(h... | [
"def",
"digital_write_pullup",
"(",
"pin_num",
",",
"value",
",",
"hardware_addr",
"=",
"0",
")",
":",
"_get_pifacedigital",
"(",
"hardware_addr",
")",
".",
"gppub",
".",
"bits",
"[",
"pin_num",
"]",
".",
"value",
"=",
"value"
] | Writes the value to the input pullup specified.
.. note:: This function is for familiarality with users of other types of
IO board. Consider accessing the ``gppub`` attribute of a
PiFaceDigital object:
>>> pfd = PiFaceDigital(hardware_addr)
>>> hex(pfd.gppub.value)
0xff
>... | [
"Writes",
"the",
"value",
"to",
"the",
"input",
"pullup",
"specified",
"."
] | train | https://github.com/piface/pifacedigitalio/blob/d231a82bdb55d5f57f44ba7aec00bfd6c0b9a9d4/pifacedigitalio/core.py#L258-L277 |
piface/pifacedigitalio | examples/simplewebcontrol.py | get_my_ip | def get_my_ip():
"""Returns this computers IP address as a string."""
ip = subprocess.check_output(GET_IP_CMD, shell=True).decode('utf-8')[:-1]
return ip.strip() | python | def get_my_ip():
"""Returns this computers IP address as a string."""
ip = subprocess.check_output(GET_IP_CMD, shell=True).decode('utf-8')[:-1]
return ip.strip() | [
"def",
"get_my_ip",
"(",
")",
":",
"ip",
"=",
"subprocess",
".",
"check_output",
"(",
"GET_IP_CMD",
",",
"shell",
"=",
"True",
")",
".",
"decode",
"(",
"'utf-8'",
")",
"[",
":",
"-",
"1",
"]",
"return",
"ip",
".",
"strip",
"(",
")"
] | Returns this computers IP address as a string. | [
"Returns",
"this",
"computers",
"IP",
"address",
"as",
"a",
"string",
"."
] | train | https://github.com/piface/pifacedigitalio/blob/d231a82bdb55d5f57f44ba7aec00bfd6c0b9a9d4/examples/simplewebcontrol.py#L72-L75 |
piface/pifacedigitalio | examples/simplewebcontrol.py | PiFaceWebHandler.set_output_port | def set_output_port(self, new_value, old_value=0):
"""Sets the output port value to new_value, defaults to old_value."""
print("Setting output port to {}.".format(new_value))
port_value = old_value
try:
port_value = int(new_value) # dec
except ValueError:
... | python | def set_output_port(self, new_value, old_value=0):
"""Sets the output port value to new_value, defaults to old_value."""
print("Setting output port to {}.".format(new_value))
port_value = old_value
try:
port_value = int(new_value) # dec
except ValueError:
... | [
"def",
"set_output_port",
"(",
"self",
",",
"new_value",
",",
"old_value",
"=",
"0",
")",
":",
"print",
"(",
"\"Setting output port to {}.\"",
".",
"format",
"(",
"new_value",
")",
")",
"port_value",
"=",
"old_value",
"try",
":",
"port_value",
"=",
"int",
"(... | Sets the output port value to new_value, defaults to old_value. | [
"Sets",
"the",
"output",
"port",
"value",
"to",
"new_value",
"defaults",
"to",
"old_value",
"."
] | train | https://github.com/piface/pifacedigitalio/blob/d231a82bdb55d5f57f44ba7aec00bfd6c0b9a9d4/examples/simplewebcontrol.py#L59-L69 |
tbobm/etnawrapper | etnawrapper/etna.py | EtnaWrapper._request_api | def _request_api(self, **kwargs):
"""Wrap the calls the url, with the given arguments.
:param str url: Url to call with the given arguments
:param str method: [POST | GET] Method to use on the request
:param int status: Expected status code
"""
_url = kwargs.get('url')
... | python | def _request_api(self, **kwargs):
"""Wrap the calls the url, with the given arguments.
:param str url: Url to call with the given arguments
:param str method: [POST | GET] Method to use on the request
:param int status: Expected status code
"""
_url = kwargs.get('url')
... | [
"def",
"_request_api",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"_url",
"=",
"kwargs",
".",
"get",
"(",
"'url'",
")",
"_method",
"=",
"kwargs",
".",
"get",
"(",
"'method'",
",",
"'GET'",
")",
"_status",
"=",
"kwargs",
".",
"get",
"(",
"'stat... | Wrap the calls the url, with the given arguments.
:param str url: Url to call with the given arguments
:param str method: [POST | GET] Method to use on the request
:param int status: Expected status code | [
"Wrap",
"the",
"calls",
"the",
"url",
"with",
"the",
"given",
"arguments",
"."
] | train | https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L119-L147 |
tbobm/etnawrapper | etnawrapper/etna.py | EtnaWrapper.get_infos_with_id | def get_infos_with_id(self, uid):
"""Get info about a user based on his id.
:return: JSON
"""
_logid = uid
_user_info_url = USER_INFO_URL.format(logid=_logid)
return self._request_api(url=_user_info_url).json() | python | def get_infos_with_id(self, uid):
"""Get info about a user based on his id.
:return: JSON
"""
_logid = uid
_user_info_url = USER_INFO_URL.format(logid=_logid)
return self._request_api(url=_user_info_url).json() | [
"def",
"get_infos_with_id",
"(",
"self",
",",
"uid",
")",
":",
"_logid",
"=",
"uid",
"_user_info_url",
"=",
"USER_INFO_URL",
".",
"format",
"(",
"logid",
"=",
"_logid",
")",
"return",
"self",
".",
"_request_api",
"(",
"url",
"=",
"_user_info_url",
")",
"."... | Get info about a user based on his id.
:return: JSON | [
"Get",
"info",
"about",
"a",
"user",
"based",
"on",
"his",
"id",
"."
] | train | https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L157-L165 |
tbobm/etnawrapper | etnawrapper/etna.py | EtnaWrapper.get_current_activities | def get_current_activities(self, login=None, **kwargs):
"""Get the current activities of user.
Either use the `login` param, or the client's login if unset.
:return: JSON
"""
_login = kwargs.get(
'login',
login or self._login
)
_activity_... | python | def get_current_activities(self, login=None, **kwargs):
"""Get the current activities of user.
Either use the `login` param, or the client's login if unset.
:return: JSON
"""
_login = kwargs.get(
'login',
login or self._login
)
_activity_... | [
"def",
"get_current_activities",
"(",
"self",
",",
"login",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"_login",
"=",
"kwargs",
".",
"get",
"(",
"'login'",
",",
"login",
"or",
"self",
".",
"_login",
")",
"_activity_url",
"=",
"ACTIVITY_URL",
".",
... | Get the current activities of user.
Either use the `login` param, or the client's login if unset.
:return: JSON | [
"Get",
"the",
"current",
"activities",
"of",
"user",
"."
] | train | https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L175-L187 |
tbobm/etnawrapper | etnawrapper/etna.py | EtnaWrapper.get_notifications | def get_notifications(self, login=None, **kwargs):
"""Get the current notifications of a user.
:return: JSON
"""
_login = kwargs.get(
'login',
login or self._login
)
_notif_url = NOTIF_URL.format(login=_login)
return self._request_api(url... | python | def get_notifications(self, login=None, **kwargs):
"""Get the current notifications of a user.
:return: JSON
"""
_login = kwargs.get(
'login',
login or self._login
)
_notif_url = NOTIF_URL.format(login=_login)
return self._request_api(url... | [
"def",
"get_notifications",
"(",
"self",
",",
"login",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"_login",
"=",
"kwargs",
".",
"get",
"(",
"'login'",
",",
"login",
"or",
"self",
".",
"_login",
")",
"_notif_url",
"=",
"NOTIF_URL",
".",
"format",
... | Get the current notifications of a user.
:return: JSON | [
"Get",
"the",
"current",
"notifications",
"of",
"a",
"user",
"."
] | train | https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L189-L200 |
tbobm/etnawrapper | etnawrapper/etna.py | EtnaWrapper.get_grades | def get_grades(self, login=None, promotion=None, **kwargs):
"""Get a user's grades on a single promotion based on his login.
Either use the `login` param, or the client's login if unset.
:return: JSON
"""
_login = kwargs.get(
'login',
login or self._logi... | python | def get_grades(self, login=None, promotion=None, **kwargs):
"""Get a user's grades on a single promotion based on his login.
Either use the `login` param, or the client's login if unset.
:return: JSON
"""
_login = kwargs.get(
'login',
login or self._logi... | [
"def",
"get_grades",
"(",
"self",
",",
"login",
"=",
"None",
",",
"promotion",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"_login",
"=",
"kwargs",
".",
"get",
"(",
"'login'",
",",
"login",
"or",
"self",
".",
"_login",
")",
"_promotion_id",
"=",
... | Get a user's grades on a single promotion based on his login.
Either use the `login` param, or the client's login if unset.
:return: JSON | [
"Get",
"a",
"user",
"s",
"grades",
"on",
"a",
"single",
"promotion",
"based",
"on",
"his",
"login",
"."
] | train | https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L202-L215 |
tbobm/etnawrapper | etnawrapper/etna.py | EtnaWrapper.get_picture | def get_picture(self, login=None, **kwargs):
"""Get a user's picture.
:param str login: Login of the user to check
:return: JSON
"""
_login = kwargs.get(
'login',
login or self._login
)
_activities_url = PICTURE_URL.format(login=_login)
... | python | def get_picture(self, login=None, **kwargs):
"""Get a user's picture.
:param str login: Login of the user to check
:return: JSON
"""
_login = kwargs.get(
'login',
login or self._login
)
_activities_url = PICTURE_URL.format(login=_login)
... | [
"def",
"get_picture",
"(",
"self",
",",
"login",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"_login",
"=",
"kwargs",
".",
"get",
"(",
"'login'",
",",
"login",
"or",
"self",
".",
"_login",
")",
"_activities_url",
"=",
"PICTURE_URL",
".",
"format",
... | Get a user's picture.
:param str login: Login of the user to check
:return: JSON | [
"Get",
"a",
"user",
"s",
"picture",
"."
] | train | https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L217-L229 |
tbobm/etnawrapper | etnawrapper/etna.py | EtnaWrapper.get_projects | def get_projects(self, **kwargs):
"""Get a user's project.
:param str login: User's login (Default: self._login)
:return: JSON
"""
_login = kwargs.get('login', self._login)
search_url = SEARCH_URL.format(login=_login)
return self._request_api(url=search_url).jso... | python | def get_projects(self, **kwargs):
"""Get a user's project.
:param str login: User's login (Default: self._login)
:return: JSON
"""
_login = kwargs.get('login', self._login)
search_url = SEARCH_URL.format(login=_login)
return self._request_api(url=search_url).jso... | [
"def",
"get_projects",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"_login",
"=",
"kwargs",
".",
"get",
"(",
"'login'",
",",
"self",
".",
"_login",
")",
"search_url",
"=",
"SEARCH_URL",
".",
"format",
"(",
"login",
"=",
"_login",
")",
"return",
"... | Get a user's project.
:param str login: User's login (Default: self._login)
:return: JSON | [
"Get",
"a",
"user",
"s",
"project",
"."
] | train | https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L231-L240 |
tbobm/etnawrapper | etnawrapper/etna.py | EtnaWrapper.get_activities_for_project | def get_activities_for_project(self, module=None, **kwargs):
"""Get the related activities of a project.
:param str module: Stages of a given module
:return: JSON
"""
_module_id = kwargs.get('module', module)
_activities_url = ACTIVITIES_URL.format(module_id=_module_id)... | python | def get_activities_for_project(self, module=None, **kwargs):
"""Get the related activities of a project.
:param str module: Stages of a given module
:return: JSON
"""
_module_id = kwargs.get('module', module)
_activities_url = ACTIVITIES_URL.format(module_id=_module_id)... | [
"def",
"get_activities_for_project",
"(",
"self",
",",
"module",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"_module_id",
"=",
"kwargs",
".",
"get",
"(",
"'module'",
",",
"module",
")",
"_activities_url",
"=",
"ACTIVITIES_URL",
".",
"format",
"(",
"mo... | Get the related activities of a project.
:param str module: Stages of a given module
:return: JSON | [
"Get",
"the",
"related",
"activities",
"of",
"a",
"project",
"."
] | train | https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L242-L251 |
tbobm/etnawrapper | etnawrapper/etna.py | EtnaWrapper.get_group_for_activity | def get_group_for_activity(self, module=None, project=None, **kwargs):
"""Get groups for activity.
:param str module: Base module
:param str module: Project which contains the group requested
:return: JSON
"""
_module_id = kwargs.get('module', module)
_project_i... | python | def get_group_for_activity(self, module=None, project=None, **kwargs):
"""Get groups for activity.
:param str module: Base module
:param str module: Project which contains the group requested
:return: JSON
"""
_module_id = kwargs.get('module', module)
_project_i... | [
"def",
"get_group_for_activity",
"(",
"self",
",",
"module",
"=",
"None",
",",
"project",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"_module_id",
"=",
"kwargs",
".",
"get",
"(",
"'module'",
",",
"module",
")",
"_project_id",
"=",
"kwargs",
".",
"... | Get groups for activity.
:param str module: Base module
:param str module: Project which contains the group requested
:return: JSON | [
"Get",
"groups",
"for",
"activity",
"."
] | train | https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L253-L264 |
tbobm/etnawrapper | etnawrapper/etna.py | EtnaWrapper.get_students | def get_students(self, **kwargs):
"""Get users by promotion id.
:param int promotion: Promotion ID
:return: JSON
"""
_promotion_id = kwargs.get('promotion')
_url = PROMOTION_URL.format(promo_id=_promotion_id)
return self._request_api(url=_url).json() | python | def get_students(self, **kwargs):
"""Get users by promotion id.
:param int promotion: Promotion ID
:return: JSON
"""
_promotion_id = kwargs.get('promotion')
_url = PROMOTION_URL.format(promo_id=_promotion_id)
return self._request_api(url=_url).json() | [
"def",
"get_students",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"_promotion_id",
"=",
"kwargs",
".",
"get",
"(",
"'promotion'",
")",
"_url",
"=",
"PROMOTION_URL",
".",
"format",
"(",
"promo_id",
"=",
"_promotion_id",
")",
"return",
"self",
".",
"_... | Get users by promotion id.
:param int promotion: Promotion ID
:return: JSON | [
"Get",
"users",
"by",
"promotion",
"id",
"."
] | train | https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L266-L275 |
tbobm/etnawrapper | etnawrapper/etna.py | EtnaWrapper.get_log_events | def get_log_events(self, login=None, **kwargs):
"""Get a user's log events.
:param str login: User's login (Default: self._login)
:return: JSON
"""
_login = kwargs.get(
'login',
login
)
log_events_url = GSA_EVENTS_URL.format(login=_login)... | python | def get_log_events(self, login=None, **kwargs):
"""Get a user's log events.
:param str login: User's login (Default: self._login)
:return: JSON
"""
_login = kwargs.get(
'login',
login
)
log_events_url = GSA_EVENTS_URL.format(login=_login)... | [
"def",
"get_log_events",
"(",
"self",
",",
"login",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"_login",
"=",
"kwargs",
".",
"get",
"(",
"'login'",
",",
"login",
")",
"log_events_url",
"=",
"GSA_EVENTS_URL",
".",
"format",
"(",
"login",
"=",
"_log... | Get a user's log events.
:param str login: User's login (Default: self._login)
:return: JSON | [
"Get",
"a",
"user",
"s",
"log",
"events",
"."
] | train | https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L277-L289 |
tbobm/etnawrapper | etnawrapper/etna.py | EtnaWrapper.get_events | def get_events(self, login=None, start_date=None, end_date=None, **kwargs):
"""Get a user's events.
:param str login: User's login (Default: self._login)
:param str start_date: Start date
:param str end_date: To date
:return: JSON
"""
_login = kwargs.get(
... | python | def get_events(self, login=None, start_date=None, end_date=None, **kwargs):
"""Get a user's events.
:param str login: User's login (Default: self._login)
:param str start_date: Start date
:param str end_date: To date
:return: JSON
"""
_login = kwargs.get(
... | [
"def",
"get_events",
"(",
"self",
",",
"login",
"=",
"None",
",",
"start_date",
"=",
"None",
",",
"end_date",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"_login",
"=",
"kwargs",
".",
"get",
"(",
"'login'",
",",
"login",
")",
"log_events_url",
"=... | Get a user's events.
:param str login: User's login (Default: self._login)
:param str start_date: Start date
:param str end_date: To date
:return: JSON | [
"Get",
"a",
"user",
"s",
"events",
"."
] | train | https://github.com/tbobm/etnawrapper/blob/0f1759646a30f658cf75fd521fd6e9cef5cd09c4/etnawrapper/etna.py#L291-L309 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.