repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 3
values | summary stringlengths 4 350 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
rhjdjong/SlipLib | sliplib/slip.py | decode | def decode(packet):
"""decode(packet) -> message from SLIP-encoded packet
Retrieves the message from the SLIP-encoded packet.
:param bytes packet: The SLIP-encoded message.
Note that this must be exactly one complete packet.
The :func:`decode` function does not provide any buf... | python | def decode(packet):
"""decode(packet) -> message from SLIP-encoded packet
Retrieves the message from the SLIP-encoded packet.
:param bytes packet: The SLIP-encoded message.
Note that this must be exactly one complete packet.
The :func:`decode` function does not provide any buf... | [
"def",
"decode",
"(",
"packet",
")",
":",
"packet",
"=",
"bytes",
"(",
"packet",
")",
".",
"strip",
"(",
"END",
")",
"if",
"not",
"is_valid",
"(",
"packet",
")",
":",
"raise",
"ProtocolError",
"(",
"packet",
")",
"return",
"packet",
".",
"strip",
"("... | decode(packet) -> message from SLIP-encoded packet
Retrieves the message from the SLIP-encoded packet.
:param bytes packet: The SLIP-encoded message.
Note that this must be exactly one complete packet.
The :func:`decode` function does not provide any buffering
for incom... | [
"decode",
"(",
"packet",
")",
"-",
">",
"message",
"from",
"SLIP",
"-",
"encoded",
"packet",
"Retrieves",
"the",
"message",
"from",
"the",
"SLIP",
"-",
"encoded",
"packet",
".",
":",
"param",
"bytes",
"packet",
":",
"The",
"SLIP",
"-",
"encoded",
"messag... | 8300dba3e512bca282380f234be34d75f4a73ce1 | https://github.com/rhjdjong/SlipLib/blob/8300dba3e512bca282380f234be34d75f4a73ce1/sliplib/slip.py#L43-L60 | train | Decode a given packet into a new message with the highest priority. |
rhjdjong/SlipLib | sliplib/slip.py | is_valid | def is_valid(packet):
"""is_valid(packet) -> indicates if the packet's contents conform to the SLIP specification.
A packet is valid if:
* It contains no :const:`END` bytes other than leading and/or trailing :const:`END` bytes, and
* Each :const:`ESC` byte is followed by either an :const:`ES... | python | def is_valid(packet):
"""is_valid(packet) -> indicates if the packet's contents conform to the SLIP specification.
A packet is valid if:
* It contains no :const:`END` bytes other than leading and/or trailing :const:`END` bytes, and
* Each :const:`ESC` byte is followed by either an :const:`ES... | [
"def",
"is_valid",
"(",
"packet",
")",
":",
"packet",
"=",
"packet",
".",
"strip",
"(",
"END",
")",
"return",
"not",
"(",
"END",
"in",
"packet",
"or",
"packet",
".",
"endswith",
"(",
"ESC",
")",
"or",
"re",
".",
"search",
"(",
"ESC",
"+",
"b'[^'",
... | is_valid(packet) -> indicates if the packet's contents conform to the SLIP specification.
A packet is valid if:
* It contains no :const:`END` bytes other than leading and/or trailing :const:`END` bytes, and
* Each :const:`ESC` byte is followed by either an :const:`ESC_END` or an :const:`ESC_ESC` ... | [
"is_valid",
"(",
"packet",
")",
"-",
">",
"indicates",
"if",
"the",
"packet",
"s",
"contents",
"conform",
"to",
"the",
"SLIP",
"specification",
".",
"A",
"packet",
"is",
"valid",
"if",
":",
"*",
"It",
"contains",
"no",
":",
"const",
":",
"END",
"bytes"... | 8300dba3e512bca282380f234be34d75f4a73ce1 | https://github.com/rhjdjong/SlipLib/blob/8300dba3e512bca282380f234be34d75f4a73ce1/sliplib/slip.py#L63-L78 | train | Checks if the packet is valid according to the SLIP specification. |
rhjdjong/SlipLib | sliplib/slip.py | Driver.receive | def receive(self, data):
"""receive(data) -> List of decoded messages.
Processes :obj:`data`, which must be a bytes-like object,
and returns a (possibly empty) list with :class:`bytes` objects,
each containing a decoded message.
Any non-terminated SLIP packets in :obj:`dat... | python | def receive(self, data):
"""receive(data) -> List of decoded messages.
Processes :obj:`data`, which must be a bytes-like object,
and returns a (possibly empty) list with :class:`bytes` objects,
each containing a decoded message.
Any non-terminated SLIP packets in :obj:`dat... | [
"def",
"receive",
"(",
"self",
",",
"data",
")",
":",
"# Empty data indicates that the data reception is complete.\r",
"# To force a buffer flush, an END byte is added, so that the\r",
"# current contents of _recv_buffer will form a complete message.\r",
"if",
"not",
"data",
":",
"data... | receive(data) -> List of decoded messages.
Processes :obj:`data`, which must be a bytes-like object,
and returns a (possibly empty) list with :class:`bytes` objects,
each containing a decoded message.
Any non-terminated SLIP packets in :obj:`data`
are buffered, and process... | [
"receive",
"(",
"data",
")",
"-",
">",
"List",
"of",
"decoded",
"messages",
".",
"Processes",
":",
"obj",
":",
"data",
"which",
"must",
"be",
"a",
"bytes",
"-",
"like",
"object",
"and",
"returns",
"a",
"(",
"possibly",
"empty",
")",
"list",
"with",
"... | 8300dba3e512bca282380f234be34d75f4a73ce1 | https://github.com/rhjdjong/SlipLib/blob/8300dba3e512bca282380f234be34d75f4a73ce1/sliplib/slip.py#L105-L149 | train | Processes and processes the given bytes - like object and returns a list of decoded messages. |
rhjdjong/SlipLib | sliplib/slip.py | Driver.flush | def flush(self):
"""flush() -> List of decoded messages.
Decodes the packets in the internal buffer.
This enables the continuation of the processing
of received packets after a :exc:`ProtocolError`
has been handled.
:return: A (possibly empty) list of decoded me... | python | def flush(self):
"""flush() -> List of decoded messages.
Decodes the packets in the internal buffer.
This enables the continuation of the processing
of received packets after a :exc:`ProtocolError`
has been handled.
:return: A (possibly empty) list of decoded me... | [
"def",
"flush",
"(",
"self",
")",
":",
"messages",
"=",
"[",
"]",
"while",
"self",
".",
"_packets",
":",
"p",
"=",
"self",
".",
"_packets",
".",
"popleft",
"(",
")",
"try",
":",
"msg",
"=",
"decode",
"(",
"p",
")",
"except",
"ProtocolError",
":",
... | flush() -> List of decoded messages.
Decodes the packets in the internal buffer.
This enables the continuation of the processing
of received packets after a :exc:`ProtocolError`
has been handled.
:return: A (possibly empty) list of decoded messages from the buffered pack... | [
"flush",
"()",
"-",
">",
"List",
"of",
"decoded",
"messages",
".",
"Decodes",
"the",
"packets",
"in",
"the",
"internal",
"buffer",
".",
"This",
"enables",
"the",
"continuation",
"of",
"the",
"processing",
"of",
"received",
"packets",
"after",
"a",
":",
"ex... | 8300dba3e512bca282380f234be34d75f4a73ce1 | https://github.com/rhjdjong/SlipLib/blob/8300dba3e512bca282380f234be34d75f4a73ce1/sliplib/slip.py#L151-L173 | train | Flushes the internal buffer and returns a list of decoded messages. |
Grk0/python-libconf | libconf.py | decode_escapes | def decode_escapes(s):
'''Unescape libconfig string literals'''
def decode_match(match):
return codecs.decode(match.group(0), 'unicode-escape')
return ESCAPE_SEQUENCE_RE.sub(decode_match, s) | python | def decode_escapes(s):
'''Unescape libconfig string literals'''
def decode_match(match):
return codecs.decode(match.group(0), 'unicode-escape')
return ESCAPE_SEQUENCE_RE.sub(decode_match, s) | [
"def",
"decode_escapes",
"(",
"s",
")",
":",
"def",
"decode_match",
"(",
"match",
")",
":",
"return",
"codecs",
".",
"decode",
"(",
"match",
".",
"group",
"(",
"0",
")",
",",
"'unicode-escape'",
")",
"return",
"ESCAPE_SEQUENCE_RE",
".",
"sub",
"(",
"deco... | Unescape libconfig string literals | [
"Unescape",
"libconfig",
"string",
"literals"
] | 9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4 | https://github.com/Grk0/python-libconf/blob/9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4/libconf.py#L50-L55 | train | Unescape libconfig string literals |
Grk0/python-libconf | libconf.py | load | def load(f, filename=None, includedir=''):
'''Load the contents of ``f`` (a file-like object) to a Python object
The returned object is a subclass of ``dict`` that exposes string keys as
attributes as well.
Example:
>>> with open('test/example.cfg') as f:
... config = libconf.load... | python | def load(f, filename=None, includedir=''):
'''Load the contents of ``f`` (a file-like object) to a Python object
The returned object is a subclass of ``dict`` that exposes string keys as
attributes as well.
Example:
>>> with open('test/example.cfg') as f:
... config = libconf.load... | [
"def",
"load",
"(",
"f",
",",
"filename",
"=",
"None",
",",
"includedir",
"=",
"''",
")",
":",
"if",
"isinstance",
"(",
"f",
".",
"read",
"(",
"0",
")",
",",
"bytes",
")",
":",
"raise",
"TypeError",
"(",
"\"libconf.load() input file must by unicode\"",
"... | Load the contents of ``f`` (a file-like object) to a Python object
The returned object is a subclass of ``dict`` that exposes string keys as
attributes as well.
Example:
>>> with open('test/example.cfg') as f:
... config = libconf.load(f)
>>> config['window']['title']
... | [
"Load",
"the",
"contents",
"of",
"f",
"(",
"a",
"file",
"-",
"like",
"object",
")",
"to",
"a",
"Python",
"object"
] | 9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4 | https://github.com/Grk0/python-libconf/blob/9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4/libconf.py#L476-L498 | train | Load the contents of f to a Python object
|
Grk0/python-libconf | libconf.py | loads | def loads(string, filename=None, includedir=''):
'''Load the contents of ``string`` to a Python object
The returned object is a subclass of ``dict`` that exposes string keys as
attributes as well.
Example:
>>> config = libconf.loads('window: { title: "libconfig example"; };')
>>> conf... | python | def loads(string, filename=None, includedir=''):
'''Load the contents of ``string`` to a Python object
The returned object is a subclass of ``dict`` that exposes string keys as
attributes as well.
Example:
>>> config = libconf.loads('window: { title: "libconfig example"; };')
>>> conf... | [
"def",
"loads",
"(",
"string",
",",
"filename",
"=",
"None",
",",
"includedir",
"=",
"''",
")",
":",
"try",
":",
"f",
"=",
"io",
".",
"StringIO",
"(",
"string",
")",
"except",
"TypeError",
":",
"raise",
"TypeError",
"(",
"\"libconf.loads() input string mus... | Load the contents of ``string`` to a Python object
The returned object is a subclass of ``dict`` that exposes string keys as
attributes as well.
Example:
>>> config = libconf.loads('window: { title: "libconfig example"; };')
>>> config['window']['title']
'libconfig example'
... | [
"Load",
"the",
"contents",
"of",
"string",
"to",
"a",
"Python",
"object"
] | 9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4 | https://github.com/Grk0/python-libconf/blob/9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4/libconf.py#L501-L521 | train | Load the contents of string to a Python object
|
Grk0/python-libconf | libconf.py | dump_string | def dump_string(s):
'''Stringize ``s``, adding double quotes and escaping as necessary
Backslash escape backslashes, double quotes, ``\f``, ``\n``, ``\r``, and
``\t``. Escape all remaining unprintable characters in ``\xFF``-style.
The returned string will be surrounded by double quotes.
'''
s ... | python | def dump_string(s):
'''Stringize ``s``, adding double quotes and escaping as necessary
Backslash escape backslashes, double quotes, ``\f``, ``\n``, ``\r``, and
``\t``. Escape all remaining unprintable characters in ``\xFF``-style.
The returned string will be surrounded by double quotes.
'''
s ... | [
"def",
"dump_string",
"(",
"s",
")",
":",
"s",
"=",
"(",
"s",
".",
"replace",
"(",
"'\\\\'",
",",
"'\\\\\\\\'",
")",
".",
"replace",
"(",
"'\"'",
",",
"'\\\\\"'",
")",
".",
"replace",
"(",
"'\\f'",
",",
"r'\\f'",
")",
".",
"replace",
"(",
"'\\n'",
... | Stringize ``s``, adding double quotes and escaping as necessary
Backslash escape backslashes, double quotes, ``\f``, ``\n``, ``\r``, and
``\t``. Escape all remaining unprintable characters in ``\xFF``-style.
The returned string will be surrounded by double quotes. | [
"Stringize",
"s",
"adding",
"double",
"quotes",
"and",
"escaping",
"as",
"necessary"
] | 9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4 | https://github.com/Grk0/python-libconf/blob/9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4/libconf.py#L555-L572 | train | Stringize s adding double quotes and escaping as necessary
Backslash escape backslashes double quotes double quotes and escaping as necessary
|
Grk0/python-libconf | libconf.py | get_dump_type | def get_dump_type(value):
'''Get the libconfig datatype of a value
Return values: ``'d'`` (dict), ``'l'`` (list), ``'a'`` (array),
``'i'`` (integer), ``'i64'`` (long integer), ``'b'`` (bool),
``'f'`` (float), or ``'s'`` (string).
Produces the proper type for LibconfList, LibconfArray, LibconfInt64... | python | def get_dump_type(value):
'''Get the libconfig datatype of a value
Return values: ``'d'`` (dict), ``'l'`` (list), ``'a'`` (array),
``'i'`` (integer), ``'i64'`` (long integer), ``'b'`` (bool),
``'f'`` (float), or ``'s'`` (string).
Produces the proper type for LibconfList, LibconfArray, LibconfInt64... | [
"def",
"get_dump_type",
"(",
"value",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"dict",
")",
":",
"return",
"'d'",
"if",
"isinstance",
"(",
"value",
",",
"tuple",
")",
":",
"return",
"'l'",
"if",
"isinstance",
"(",
"value",
",",
"list",
")",
"... | Get the libconfig datatype of a value
Return values: ``'d'`` (dict), ``'l'`` (list), ``'a'`` (array),
``'i'`` (integer), ``'i64'`` (long integer), ``'b'`` (bool),
``'f'`` (float), or ``'s'`` (string).
Produces the proper type for LibconfList, LibconfArray, LibconfInt64
instances. | [
"Get",
"the",
"libconfig",
"datatype",
"of",
"a",
"value"
] | 9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4 | https://github.com/Grk0/python-libconf/blob/9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4/libconf.py#L575-L606 | train | Get the libconfig datatype of a value. |
Grk0/python-libconf | libconf.py | get_array_value_dtype | def get_array_value_dtype(lst):
'''Return array value type, raise ConfigSerializeError for invalid arrays
Libconfig arrays must only contain scalar values and all elements must be
of the same libconfig data type. Raises ConfigSerializeError if these
invariants are not met.
Returns the value type o... | python | def get_array_value_dtype(lst):
'''Return array value type, raise ConfigSerializeError for invalid arrays
Libconfig arrays must only contain scalar values and all elements must be
of the same libconfig data type. Raises ConfigSerializeError if these
invariants are not met.
Returns the value type o... | [
"def",
"get_array_value_dtype",
"(",
"lst",
")",
":",
"array_value_type",
"=",
"None",
"for",
"value",
"in",
"lst",
":",
"dtype",
"=",
"get_dump_type",
"(",
"value",
")",
"if",
"dtype",
"not",
"in",
"{",
"'b'",
",",
"'i'",
",",
"'i64'",
",",
"'f'",
","... | Return array value type, raise ConfigSerializeError for invalid arrays
Libconfig arrays must only contain scalar values and all elements must be
of the same libconfig data type. Raises ConfigSerializeError if these
invariants are not met.
Returns the value type of the array. If an array contains both ... | [
"Return",
"array",
"value",
"type",
"raise",
"ConfigSerializeError",
"for",
"invalid",
"arrays"
] | 9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4 | https://github.com/Grk0/python-libconf/blob/9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4/libconf.py#L609-L646 | train | Return array value type raise ConfigSerializeError for invalid arrays
Libconfig arrays must only contain scalar values and all elements must be of same type. |
Grk0/python-libconf | libconf.py | dump_value | def dump_value(key, value, f, indent=0):
'''Save a value of any libconfig type
This function serializes takes ``key`` and ``value`` and serializes them
into ``f``. If ``key`` is ``None``, a list-style output is produced.
Otherwise, output has ``key = value`` format.
'''
spaces = ' ' * indent
... | python | def dump_value(key, value, f, indent=0):
'''Save a value of any libconfig type
This function serializes takes ``key`` and ``value`` and serializes them
into ``f``. If ``key`` is ``None``, a list-style output is produced.
Otherwise, output has ``key = value`` format.
'''
spaces = ' ' * indent
... | [
"def",
"dump_value",
"(",
"key",
",",
"value",
",",
"f",
",",
"indent",
"=",
"0",
")",
":",
"spaces",
"=",
"' '",
"*",
"indent",
"if",
"key",
"is",
"None",
":",
"key_prefix",
"=",
"''",
"key_prefix_nl",
"=",
"''",
"else",
":",
"key_prefix",
"=",
"k... | Save a value of any libconfig type
This function serializes takes ``key`` and ``value`` and serializes them
into ``f``. If ``key`` is ``None``, a list-style output is produced.
Otherwise, output has ``key = value`` format. | [
"Save",
"a",
"value",
"of",
"any",
"libconfig",
"type"
] | 9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4 | https://github.com/Grk0/python-libconf/blob/9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4/libconf.py#L649-L692 | train | Save a value of any libconfig type
|
Grk0/python-libconf | libconf.py | dump_collection | def dump_collection(cfg, f, indent=0):
'''Save a collection of attributes'''
for i, value in enumerate(cfg):
dump_value(None, value, f, indent)
if i < len(cfg) - 1:
f.write(u',\n') | python | def dump_collection(cfg, f, indent=0):
'''Save a collection of attributes'''
for i, value in enumerate(cfg):
dump_value(None, value, f, indent)
if i < len(cfg) - 1:
f.write(u',\n') | [
"def",
"dump_collection",
"(",
"cfg",
",",
"f",
",",
"indent",
"=",
"0",
")",
":",
"for",
"i",
",",
"value",
"in",
"enumerate",
"(",
"cfg",
")",
":",
"dump_value",
"(",
"None",
",",
"value",
",",
"f",
",",
"indent",
")",
"if",
"i",
"<",
"len",
... | Save a collection of attributes | [
"Save",
"a",
"collection",
"of",
"attributes"
] | 9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4 | https://github.com/Grk0/python-libconf/blob/9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4/libconf.py#L695-L701 | train | Save a collection of attributes |
Grk0/python-libconf | libconf.py | dump_dict | def dump_dict(cfg, f, indent=0):
'''Save a dictionary of attributes'''
for key in cfg:
if not isstr(key):
raise ConfigSerializeError("Dict keys must be strings: %r" %
(key,))
dump_value(key, cfg[key], f, indent)
f.write(u';\n') | python | def dump_dict(cfg, f, indent=0):
'''Save a dictionary of attributes'''
for key in cfg:
if not isstr(key):
raise ConfigSerializeError("Dict keys must be strings: %r" %
(key,))
dump_value(key, cfg[key], f, indent)
f.write(u';\n') | [
"def",
"dump_dict",
"(",
"cfg",
",",
"f",
",",
"indent",
"=",
"0",
")",
":",
"for",
"key",
"in",
"cfg",
":",
"if",
"not",
"isstr",
"(",
"key",
")",
":",
"raise",
"ConfigSerializeError",
"(",
"\"Dict keys must be strings: %r\"",
"%",
"(",
"key",
",",
")... | Save a dictionary of attributes | [
"Save",
"a",
"dictionary",
"of",
"attributes"
] | 9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4 | https://github.com/Grk0/python-libconf/blob/9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4/libconf.py#L704-L712 | train | Save a dictionary of attributes |
Grk0/python-libconf | libconf.py | dumps | def dumps(cfg):
'''Serialize ``cfg`` into a libconfig-formatted ``str``
``cfg`` must be a ``dict`` with ``str`` keys and libconf-supported values
(numbers, strings, booleans, possibly nested dicts, lists, and tuples).
Returns the formatted string.
'''
str_file = io.StringIO()
dump(cfg, st... | python | def dumps(cfg):
'''Serialize ``cfg`` into a libconfig-formatted ``str``
``cfg`` must be a ``dict`` with ``str`` keys and libconf-supported values
(numbers, strings, booleans, possibly nested dicts, lists, and tuples).
Returns the formatted string.
'''
str_file = io.StringIO()
dump(cfg, st... | [
"def",
"dumps",
"(",
"cfg",
")",
":",
"str_file",
"=",
"io",
".",
"StringIO",
"(",
")",
"dump",
"(",
"cfg",
",",
"str_file",
")",
"return",
"str_file",
".",
"getvalue",
"(",
")"
] | Serialize ``cfg`` into a libconfig-formatted ``str``
``cfg`` must be a ``dict`` with ``str`` keys and libconf-supported values
(numbers, strings, booleans, possibly nested dicts, lists, and tuples).
Returns the formatted string. | [
"Serialize",
"cfg",
"into",
"a",
"libconfig",
"-",
"formatted",
"str"
] | 9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4 | https://github.com/Grk0/python-libconf/blob/9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4/libconf.py#L715-L726 | train | Serialize cfg into a libconfig - formatted string. |
Grk0/python-libconf | libconf.py | dump | def dump(cfg, f):
'''Serialize ``cfg`` as a libconfig-formatted stream into ``f``
``cfg`` must be a ``dict`` with ``str`` keys and libconf-supported values
(numbers, strings, booleans, possibly nested dicts, lists, and tuples).
``f`` must be a ``file``-like object with a ``write()`` method.
'''
... | python | def dump(cfg, f):
'''Serialize ``cfg`` as a libconfig-formatted stream into ``f``
``cfg`` must be a ``dict`` with ``str`` keys and libconf-supported values
(numbers, strings, booleans, possibly nested dicts, lists, and tuples).
``f`` must be a ``file``-like object with a ``write()`` method.
'''
... | [
"def",
"dump",
"(",
"cfg",
",",
"f",
")",
":",
"if",
"not",
"isinstance",
"(",
"cfg",
",",
"dict",
")",
":",
"raise",
"ConfigSerializeError",
"(",
"'dump() requires a dict as input, not %r of type %r'",
"%",
"(",
"cfg",
",",
"type",
"(",
"cfg",
")",
")",
"... | Serialize ``cfg`` as a libconfig-formatted stream into ``f``
``cfg`` must be a ``dict`` with ``str`` keys and libconf-supported values
(numbers, strings, booleans, possibly nested dicts, lists, and tuples).
``f`` must be a ``file``-like object with a ``write()`` method. | [
"Serialize",
"cfg",
"as",
"a",
"libconfig",
"-",
"formatted",
"stream",
"into",
"f"
] | 9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4 | https://github.com/Grk0/python-libconf/blob/9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4/libconf.py#L729-L743 | train | Serialize cfg as a libconfig - formatted stream into f. |
Grk0/python-libconf | libconf.py | main | def main():
'''Open the libconfig file specified by sys.argv[1] and pretty-print it'''
global output
if len(sys.argv[1:]) == 1:
with io.open(sys.argv[1], 'r', encoding='utf-8') as f:
output = load(f)
else:
output = load(sys.stdin)
dump(output, sys.stdout) | python | def main():
'''Open the libconfig file specified by sys.argv[1] and pretty-print it'''
global output
if len(sys.argv[1:]) == 1:
with io.open(sys.argv[1], 'r', encoding='utf-8') as f:
output = load(f)
else:
output = load(sys.stdin)
dump(output, sys.stdout) | [
"def",
"main",
"(",
")",
":",
"global",
"output",
"if",
"len",
"(",
"sys",
".",
"argv",
"[",
"1",
":",
"]",
")",
"==",
"1",
":",
"with",
"io",
".",
"open",
"(",
"sys",
".",
"argv",
"[",
"1",
"]",
",",
"'r'",
",",
"encoding",
"=",
"'utf-8'",
... | Open the libconfig file specified by sys.argv[1] and pretty-print it | [
"Open",
"the",
"libconfig",
"file",
"specified",
"by",
"sys",
".",
"argv",
"[",
"1",
"]",
"and",
"pretty",
"-",
"print",
"it"
] | 9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4 | https://github.com/Grk0/python-libconf/blob/9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4/libconf.py#L749-L758 | train | Open the libconfig file specified by sys. argv [ 1 ] and pretty - print it |
Grk0/python-libconf | libconf.py | Tokenizer.tokenize | def tokenize(self, string):
'''Yield tokens from the input string or throw ConfigParseError'''
pos = 0
while pos < len(string):
m = SKIP_RE.match(string, pos=pos)
if m:
skip_lines = m.group(0).split('\n')
if len(skip_lines) > 1:
... | python | def tokenize(self, string):
'''Yield tokens from the input string or throw ConfigParseError'''
pos = 0
while pos < len(string):
m = SKIP_RE.match(string, pos=pos)
if m:
skip_lines = m.group(0).split('\n')
if len(skip_lines) > 1:
... | [
"def",
"tokenize",
"(",
"self",
",",
"string",
")",
":",
"pos",
"=",
"0",
"while",
"pos",
"<",
"len",
"(",
"string",
")",
":",
"m",
"=",
"SKIP_RE",
".",
"match",
"(",
"string",
",",
"pos",
"=",
"pos",
")",
"if",
"m",
":",
"skip_lines",
"=",
"m"... | Yield tokens from the input string or throw ConfigParseError | [
"Yield",
"tokens",
"from",
"the",
"input",
"string",
"or",
"throw",
"ConfigParseError"
] | 9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4 | https://github.com/Grk0/python-libconf/blob/9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4/libconf.py#L178-L206 | train | Yield tokens from the input string or throw ConfigParseError |
Grk0/python-libconf | libconf.py | TokenStream.from_file | def from_file(cls, f, filename=None, includedir='', seenfiles=None):
'''Create a token stream by reading an input file
Read tokens from `f`. If an include directive ('@include "file.cfg"')
is found, read its contents as well.
The `filename` argument is used for error messages and to de... | python | def from_file(cls, f, filename=None, includedir='', seenfiles=None):
'''Create a token stream by reading an input file
Read tokens from `f`. If an include directive ('@include "file.cfg"')
is found, read its contents as well.
The `filename` argument is used for error messages and to de... | [
"def",
"from_file",
"(",
"cls",
",",
"f",
",",
"filename",
"=",
"None",
",",
"includedir",
"=",
"''",
",",
"seenfiles",
"=",
"None",
")",
":",
"if",
"filename",
"is",
"None",
":",
"filename",
"=",
"getattr",
"(",
"f",
",",
"'name'",
",",
"'<unknown>'... | Create a token stream by reading an input file
Read tokens from `f`. If an include directive ('@include "file.cfg"')
is found, read its contents as well.
The `filename` argument is used for error messages and to detect
circular imports. ``includedir`` sets the lookup directory for incl... | [
"Create",
"a",
"token",
"stream",
"by",
"reading",
"an",
"input",
"file"
] | 9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4 | https://github.com/Grk0/python-libconf/blob/9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4/libconf.py#L224-L273 | train | Create a token stream by reading an input file f Read tokens from f. If an include directive is found read its contents as well. |
Grk0/python-libconf | libconf.py | TokenStream.peek | def peek(self):
'''Return (but do not consume) the next token
At the end of input, ``None`` is returned.
'''
if self.position >= len(self.tokens):
return None
return self.tokens[self.position] | python | def peek(self):
'''Return (but do not consume) the next token
At the end of input, ``None`` is returned.
'''
if self.position >= len(self.tokens):
return None
return self.tokens[self.position] | [
"def",
"peek",
"(",
"self",
")",
":",
"if",
"self",
".",
"position",
">=",
"len",
"(",
"self",
".",
"tokens",
")",
":",
"return",
"None",
"return",
"self",
".",
"tokens",
"[",
"self",
".",
"position",
"]"
] | Return (but do not consume) the next token
At the end of input, ``None`` is returned. | [
"Return",
"(",
"but",
"do",
"not",
"consume",
")",
"the",
"next",
"token"
] | 9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4 | https://github.com/Grk0/python-libconf/blob/9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4/libconf.py#L275-L284 | train | Return the next token in the input. |
Grk0/python-libconf | libconf.py | TokenStream.accept | def accept(self, *args):
'''Consume and return the next token if it has the correct type
Multiple token types (as strings, e.g. 'integer64') can be given
as arguments. If the next token is one of them, consume and return it.
If the token type doesn't match, return None.
'''
... | python | def accept(self, *args):
'''Consume and return the next token if it has the correct type
Multiple token types (as strings, e.g. 'integer64') can be given
as arguments. If the next token is one of them, consume and return it.
If the token type doesn't match, return None.
'''
... | [
"def",
"accept",
"(",
"self",
",",
"*",
"args",
")",
":",
"token",
"=",
"self",
".",
"peek",
"(",
")",
"if",
"token",
"is",
"None",
":",
"return",
"None",
"for",
"arg",
"in",
"args",
":",
"if",
"token",
".",
"type",
"==",
"arg",
":",
"self",
".... | Consume and return the next token if it has the correct type
Multiple token types (as strings, e.g. 'integer64') can be given
as arguments. If the next token is one of them, consume and return it.
If the token type doesn't match, return None. | [
"Consume",
"and",
"return",
"the",
"next",
"token",
"if",
"it",
"has",
"the",
"correct",
"type"
] | 9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4 | https://github.com/Grk0/python-libconf/blob/9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4/libconf.py#L286-L304 | train | Consume and return the next token if it has the correct type
as arguments. |
Grk0/python-libconf | libconf.py | TokenStream.expect | def expect(self, *args):
'''Consume and return the next token if it has the correct type
Multiple token types (as strings, e.g. 'integer64') can be given
as arguments. If the next token is one of them, consume and return it.
If the token type doesn't match, raise a ConfigParseError.
... | python | def expect(self, *args):
'''Consume and return the next token if it has the correct type
Multiple token types (as strings, e.g. 'integer64') can be given
as arguments. If the next token is one of them, consume and return it.
If the token type doesn't match, raise a ConfigParseError.
... | [
"def",
"expect",
"(",
"self",
",",
"*",
"args",
")",
":",
"t",
"=",
"self",
".",
"accept",
"(",
"*",
"args",
")",
"if",
"t",
"is",
"not",
"None",
":",
"return",
"t",
"self",
".",
"error",
"(",
"\"expected: %r\"",
"%",
"(",
"args",
",",
")",
")"... | Consume and return the next token if it has the correct type
Multiple token types (as strings, e.g. 'integer64') can be given
as arguments. If the next token is one of them, consume and return it.
If the token type doesn't match, raise a ConfigParseError. | [
"Consume",
"and",
"return",
"the",
"next",
"token",
"if",
"it",
"has",
"the",
"correct",
"type"
] | 9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4 | https://github.com/Grk0/python-libconf/blob/9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4/libconf.py#L306-L319 | train | Consume and return the next token if it has the correct type and return it. |
Grk0/python-libconf | libconf.py | TokenStream.error | def error(self, msg):
'''Raise a ConfigParseError at the current input position'''
if self.finished():
raise ConfigParseError("Unexpected end of input; %s" % (msg,))
else:
t = self.peek()
raise ConfigParseError("Unexpected token %s; %s" % (t, msg)) | python | def error(self, msg):
'''Raise a ConfigParseError at the current input position'''
if self.finished():
raise ConfigParseError("Unexpected end of input; %s" % (msg,))
else:
t = self.peek()
raise ConfigParseError("Unexpected token %s; %s" % (t, msg)) | [
"def",
"error",
"(",
"self",
",",
"msg",
")",
":",
"if",
"self",
".",
"finished",
"(",
")",
":",
"raise",
"ConfigParseError",
"(",
"\"Unexpected end of input; %s\"",
"%",
"(",
"msg",
",",
")",
")",
"else",
":",
"t",
"=",
"self",
".",
"peek",
"(",
")"... | Raise a ConfigParseError at the current input position | [
"Raise",
"a",
"ConfigParseError",
"at",
"the",
"current",
"input",
"position"
] | 9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4 | https://github.com/Grk0/python-libconf/blob/9c4cf5f56d56ebbc1fe0e1596807218b7d5d5da4/libconf.py#L321-L327 | train | Raise a ConfigParseError at the current input position. |
FulcrumTechnologies/pyconfluence | pyconfluence/api.py | load_variables | def load_variables():
"""Load variables from environment variables."""
if (not os.environ.get("PYCONFLUENCE_TOKEN") or
not os.environ.get("PYCONFLUENCE_USER") or
not os.environ.get("PYCONFLUENCE_ORG")):
print ("One or more pyconfluence environment variables are not set. "
... | python | def load_variables():
"""Load variables from environment variables."""
if (not os.environ.get("PYCONFLUENCE_TOKEN") or
not os.environ.get("PYCONFLUENCE_USER") or
not os.environ.get("PYCONFLUENCE_ORG")):
print ("One or more pyconfluence environment variables are not set. "
... | [
"def",
"load_variables",
"(",
")",
":",
"if",
"(",
"not",
"os",
".",
"environ",
".",
"get",
"(",
"\"PYCONFLUENCE_TOKEN\"",
")",
"or",
"not",
"os",
".",
"environ",
".",
"get",
"(",
"\"PYCONFLUENCE_USER\"",
")",
"or",
"not",
"os",
".",
"environ",
".",
"g... | Load variables from environment variables. | [
"Load",
"variables",
"from",
"environment",
"variables",
"."
] | a999726dbc1cbdd3d9062234698eeae799ce84ce | https://github.com/FulcrumTechnologies/pyconfluence/blob/a999726dbc1cbdd3d9062234698eeae799ce84ce/pyconfluence/api.py#L21-L36 | train | Load variables from environment variables. |
FulcrumTechnologies/pyconfluence | pyconfluence/api.py | rest | def rest(url, req="GET", data=None):
"""Main function to be called from this module.
send a request using method 'req' and to the url. the _rest() function
will add the base_url to this, so 'url' should be something like '/ips'.
"""
load_variables()
return _rest(base_url + url, req, data) | python | def rest(url, req="GET", data=None):
"""Main function to be called from this module.
send a request using method 'req' and to the url. the _rest() function
will add the base_url to this, so 'url' should be something like '/ips'.
"""
load_variables()
return _rest(base_url + url, req, data) | [
"def",
"rest",
"(",
"url",
",",
"req",
"=",
"\"GET\"",
",",
"data",
"=",
"None",
")",
":",
"load_variables",
"(",
")",
"return",
"_rest",
"(",
"base_url",
"+",
"url",
",",
"req",
",",
"data",
")"
] | Main function to be called from this module.
send a request using method 'req' and to the url. the _rest() function
will add the base_url to this, so 'url' should be something like '/ips'. | [
"Main",
"function",
"to",
"be",
"called",
"from",
"this",
"module",
"."
] | a999726dbc1cbdd3d9062234698eeae799ce84ce | https://github.com/FulcrumTechnologies/pyconfluence/blob/a999726dbc1cbdd3d9062234698eeae799ce84ce/pyconfluence/api.py#L39-L47 | train | This function is called from this module. It will send a request to the url and data to the url. |
FulcrumTechnologies/pyconfluence | pyconfluence/api.py | _rest | def _rest(url, req, data=None):
"""Send a rest rest request to the server."""
if url.upper().startswith("HTTPS"):
print("Secure connection required: Please use HTTPS or https")
return ""
req = req.upper()
if req != "GET" and req != "PUT" and req != "POST" and req != "DELETE":
re... | python | def _rest(url, req, data=None):
"""Send a rest rest request to the server."""
if url.upper().startswith("HTTPS"):
print("Secure connection required: Please use HTTPS or https")
return ""
req = req.upper()
if req != "GET" and req != "PUT" and req != "POST" and req != "DELETE":
re... | [
"def",
"_rest",
"(",
"url",
",",
"req",
",",
"data",
"=",
"None",
")",
":",
"if",
"url",
".",
"upper",
"(",
")",
".",
"startswith",
"(",
"\"HTTPS\"",
")",
":",
"print",
"(",
"\"Secure connection required: Please use HTTPS or https\"",
")",
"return",
"\"\"",
... | Send a rest rest request to the server. | [
"Send",
"a",
"rest",
"rest",
"request",
"to",
"the",
"server",
"."
] | a999726dbc1cbdd3d9062234698eeae799ce84ce | https://github.com/FulcrumTechnologies/pyconfluence/blob/a999726dbc1cbdd3d9062234698eeae799ce84ce/pyconfluence/api.py#L50-L64 | train | Send a rest request to the server. |
FulcrumTechnologies/pyconfluence | pyconfluence/api.py | _api_action | def _api_action(url, req, data=None):
"""Take action based on what kind of request is needed."""
requisite_headers = {'Accept': 'application/json',
'Content-Type': 'application/json'}
auth = (user, token)
if req == "GET":
response = requests.get(url, headers=requisite_h... | python | def _api_action(url, req, data=None):
"""Take action based on what kind of request is needed."""
requisite_headers = {'Accept': 'application/json',
'Content-Type': 'application/json'}
auth = (user, token)
if req == "GET":
response = requests.get(url, headers=requisite_h... | [
"def",
"_api_action",
"(",
"url",
",",
"req",
",",
"data",
"=",
"None",
")",
":",
"requisite_headers",
"=",
"{",
"'Accept'",
":",
"'application/json'",
",",
"'Content-Type'",
":",
"'application/json'",
"}",
"auth",
"=",
"(",
"user",
",",
"token",
")",
"if"... | Take action based on what kind of request is needed. | [
"Take",
"action",
"based",
"on",
"what",
"kind",
"of",
"request",
"is",
"needed",
"."
] | a999726dbc1cbdd3d9062234698eeae799ce84ce | https://github.com/FulcrumTechnologies/pyconfluence/blob/a999726dbc1cbdd3d9062234698eeae799ce84ce/pyconfluence/api.py#L67-L84 | train | Take action based on what kind of request is needed. |
AmanoTeam/amanobot | amanobot/aio/__init__.py | Bot.sendAnimation | async def sendAnimation(self, chat_id, animation,
duration=None,
width=None,
height=None,
thumb=None,
caption=None,
parse_mode=None,
... | python | async def sendAnimation(self, chat_id, animation,
duration=None,
width=None,
height=None,
thumb=None,
caption=None,
parse_mode=None,
... | [
"async",
"def",
"sendAnimation",
"(",
"self",
",",
"chat_id",
",",
"animation",
",",
"duration",
"=",
"None",
",",
"width",
"=",
"None",
",",
"height",
"=",
"None",
",",
"thumb",
"=",
"None",
",",
"caption",
"=",
"None",
",",
"parse_mode",
"=",
"None",... | See: https://core.telegram.org/bots/api#sendanimation
:param animation: Same as ``photo`` in :meth:`amanobot.aio.Bot.sendPhoto` | [
"See",
":",
"https",
":",
"//",
"core",
".",
"telegram",
".",
"org",
"/",
"bots",
"/",
"api#sendanimation"
] | fe546e2e294eec88e637da0b2567c7e7e8662437 | https://github.com/AmanoTeam/amanobot/blob/fe546e2e294eec88e637da0b2567c7e7e8662437/amanobot/aio/__init__.py#L180-L196 | train | Send an animation to a chat. |
AmanoTeam/amanobot | amanobot/aio/__init__.py | Bot.sendVenue | async def sendVenue(self, chat_id, latitude, longitude, title, address,
foursquare_id=None,
foursquare_type=None,
disable_notification=None,
reply_to_message_id=None,
reply_markup=None):
""" S... | python | async def sendVenue(self, chat_id, latitude, longitude, title, address,
foursquare_id=None,
foursquare_type=None,
disable_notification=None,
reply_to_message_id=None,
reply_markup=None):
""" S... | [
"async",
"def",
"sendVenue",
"(",
"self",
",",
"chat_id",
",",
"latitude",
",",
"longitude",
",",
"title",
",",
"address",
",",
"foursquare_id",
"=",
"None",
",",
"foursquare_type",
"=",
"None",
",",
"disable_notification",
"=",
"None",
",",
"reply_to_message_... | See: https://core.telegram.org/bots/api#sendvenue | [
"See",
":",
"https",
":",
"//",
"core",
".",
"telegram",
".",
"org",
"/",
"bots",
"/",
"api#sendvenue"
] | fe546e2e294eec88e637da0b2567c7e7e8662437 | https://github.com/AmanoTeam/amanobot/blob/fe546e2e294eec88e637da0b2567c7e7e8662437/amanobot/aio/__init__.py#L291-L299 | train | Send a venue. |
AmanoTeam/amanobot | amanobot/aio/__init__.py | Bot.sendContact | async def sendContact(self, chat_id, phone_number, first_name,
last_name=None,
vcard=None,
disable_notification=None,
reply_to_message_id=None,
reply_markup=None):
""" See: https://c... | python | async def sendContact(self, chat_id, phone_number, first_name,
last_name=None,
vcard=None,
disable_notification=None,
reply_to_message_id=None,
reply_markup=None):
""" See: https://c... | [
"async",
"def",
"sendContact",
"(",
"self",
",",
"chat_id",
",",
"phone_number",
",",
"first_name",
",",
"last_name",
"=",
"None",
",",
"vcard",
"=",
"None",
",",
"disable_notification",
"=",
"None",
",",
"reply_to_message_id",
"=",
"None",
",",
"reply_markup"... | See: https://core.telegram.org/bots/api#sendcontact | [
"See",
":",
"https",
":",
"//",
"core",
".",
"telegram",
".",
"org",
"/",
"bots",
"/",
"api#sendcontact"
] | fe546e2e294eec88e637da0b2567c7e7e8662437 | https://github.com/AmanoTeam/amanobot/blob/fe546e2e294eec88e637da0b2567c7e7e8662437/amanobot/aio/__init__.py#L301-L309 | train | Send a contact to a chat. |
AmanoTeam/amanobot | amanobot/aio/__init__.py | Bot.sendPoll | async def sendPoll(self, chat_id, question, options,
disable_notification=None,
reply_to_message_id=None,
reply_markup=None):
""" See: https://core.telegram.org/bots/api#sendpoll """
p = _strip(locals())
return await self._api_... | python | async def sendPoll(self, chat_id, question, options,
disable_notification=None,
reply_to_message_id=None,
reply_markup=None):
""" See: https://core.telegram.org/bots/api#sendpoll """
p = _strip(locals())
return await self._api_... | [
"async",
"def",
"sendPoll",
"(",
"self",
",",
"chat_id",
",",
"question",
",",
"options",
",",
"disable_notification",
"=",
"None",
",",
"reply_to_message_id",
"=",
"None",
",",
"reply_markup",
"=",
"None",
")",
":",
"p",
"=",
"_strip",
"(",
"locals",
"(",... | See: https://core.telegram.org/bots/api#sendpoll | [
"See",
":",
"https",
":",
"//",
"core",
".",
"telegram",
".",
"org",
"/",
"bots",
"/",
"api#sendpoll"
] | fe546e2e294eec88e637da0b2567c7e7e8662437 | https://github.com/AmanoTeam/amanobot/blob/fe546e2e294eec88e637da0b2567c7e7e8662437/amanobot/aio/__init__.py#L311-L317 | train | Send a poll. |
AmanoTeam/amanobot | amanobot/aio/__init__.py | Bot.editMessageMedia | async def editMessageMedia(self, msg_identifier, media,
reply_markup=None):
"""
See: https://core.telegram.org/bots/api#editmessagemedia
:param msg_identifier: Same as ``msg_identifier`` in :meth:`amanobot.aio.Bot.editMessageText`
"""
p = _strip(lo... | python | async def editMessageMedia(self, msg_identifier, media,
reply_markup=None):
"""
See: https://core.telegram.org/bots/api#editmessagemedia
:param msg_identifier: Same as ``msg_identifier`` in :meth:`amanobot.aio.Bot.editMessageText`
"""
p = _strip(lo... | [
"async",
"def",
"editMessageMedia",
"(",
"self",
",",
"msg_identifier",
",",
"media",
",",
"reply_markup",
"=",
"None",
")",
":",
"p",
"=",
"_strip",
"(",
"locals",
"(",
")",
",",
"more",
"=",
"[",
"'msg_identifier'",
"]",
")",
"p",
".",
"update",
"(",... | See: https://core.telegram.org/bots/api#editmessagemedia
:param msg_identifier: Same as ``msg_identifier`` in :meth:`amanobot.aio.Bot.editMessageText` | [
"See",
":",
"https",
":",
"//",
"core",
".",
"telegram",
".",
"org",
"/",
"bots",
"/",
"api#editmessagemedia"
] | fe546e2e294eec88e637da0b2567c7e7e8662437 | https://github.com/AmanoTeam/amanobot/blob/fe546e2e294eec88e637da0b2567c7e7e8662437/amanobot/aio/__init__.py#L521-L530 | train | Edit a message s media. |
kstaniek/condoor | condoor/patterns.py | PatternManager._prepare_patterns | def _prepare_patterns(self, pattern_dict):
"""Return two dictionaries: compiled and text prompts."""
dict_compiled = {}
dict_text = {}
dict_dscr = {}
for platform, patterns in pattern_dict.items():
dict_text[platform] = {}
dict_compiled[platform] = {}
... | python | def _prepare_patterns(self, pattern_dict):
"""Return two dictionaries: compiled and text prompts."""
dict_compiled = {}
dict_text = {}
dict_dscr = {}
for platform, patterns in pattern_dict.items():
dict_text[platform] = {}
dict_compiled[platform] = {}
... | [
"def",
"_prepare_patterns",
"(",
"self",
",",
"pattern_dict",
")",
":",
"dict_compiled",
"=",
"{",
"}",
"dict_text",
"=",
"{",
"}",
"dict_dscr",
"=",
"{",
"}",
"for",
"platform",
",",
"patterns",
"in",
"pattern_dict",
".",
"items",
"(",
")",
":",
"dict_t... | Return two dictionaries: compiled and text prompts. | [
"Return",
"two",
"dictionaries",
":",
"compiled",
"and",
"text",
"prompts",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/patterns.py#L16-L54 | train | Return two dictionaries containing compiled text prompts and DSCR patterns. |
kstaniek/condoor | condoor/patterns.py | PatternManager._platform_patterns | def _platform_patterns(self, platform='generic', compiled=False):
"""Return all the patterns for specific platform."""
patterns = self._dict_compiled.get(platform, None) if compiled else self._dict_text.get(platform, None)
if patterns is None:
raise KeyError("Unknown platform: {}".fo... | python | def _platform_patterns(self, platform='generic', compiled=False):
"""Return all the patterns for specific platform."""
patterns = self._dict_compiled.get(platform, None) if compiled else self._dict_text.get(platform, None)
if patterns is None:
raise KeyError("Unknown platform: {}".fo... | [
"def",
"_platform_patterns",
"(",
"self",
",",
"platform",
"=",
"'generic'",
",",
"compiled",
"=",
"False",
")",
":",
"patterns",
"=",
"self",
".",
"_dict_compiled",
".",
"get",
"(",
"platform",
",",
"None",
")",
"if",
"compiled",
"else",
"self",
".",
"_... | Return all the patterns for specific platform. | [
"Return",
"all",
"the",
"patterns",
"for",
"specific",
"platform",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/patterns.py#L56-L61 | train | Return all the patterns for specific platform. |
kstaniek/condoor | condoor/patterns.py | PatternManager.pattern | def pattern(self, platform, key, compiled=True):
"""Return the pattern defined by the key string specific to the platform.
:param platform:
:param key:
:param compiled:
:return: Pattern string or RE object.
"""
patterns = self._platform_patterns(platform, compile... | python | def pattern(self, platform, key, compiled=True):
"""Return the pattern defined by the key string specific to the platform.
:param platform:
:param key:
:param compiled:
:return: Pattern string or RE object.
"""
patterns = self._platform_patterns(platform, compile... | [
"def",
"pattern",
"(",
"self",
",",
"platform",
",",
"key",
",",
"compiled",
"=",
"True",
")",
":",
"patterns",
"=",
"self",
".",
"_platform_patterns",
"(",
"platform",
",",
"compiled",
"=",
"compiled",
")",
"pattern",
"=",
"patterns",
".",
"get",
"(",
... | Return the pattern defined by the key string specific to the platform.
:param platform:
:param key:
:param compiled:
:return: Pattern string or RE object. | [
"Return",
"the",
"pattern",
"defined",
"by",
"the",
"key",
"string",
"specific",
"to",
"the",
"platform",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/patterns.py#L76-L90 | train | Return the pattern string for the key string specific to the platform. |
kstaniek/condoor | condoor/patterns.py | PatternManager.description | def description(self, platform, key):
"""Return the patter description."""
patterns = self._dict_dscr.get(platform, None)
description = patterns.get(key, None)
return description | python | def description(self, platform, key):
"""Return the patter description."""
patterns = self._dict_dscr.get(platform, None)
description = patterns.get(key, None)
return description | [
"def",
"description",
"(",
"self",
",",
"platform",
",",
"key",
")",
":",
"patterns",
"=",
"self",
".",
"_dict_dscr",
".",
"get",
"(",
"platform",
",",
"None",
")",
"description",
"=",
"patterns",
".",
"get",
"(",
"key",
",",
"None",
")",
"return",
"... | Return the patter description. | [
"Return",
"the",
"patter",
"description",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/patterns.py#L92-L96 | train | Return the patter description for the given key. |
kstaniek/condoor | condoor/patterns.py | PatternManager.platform | def platform(self, with_prompt, platforms=None):
"""Return the platform name based on the prompt matching."""
if platforms is None:
platforms = self._dict['generic']['prompt_detection']
for platform in platforms:
pattern = self.pattern(platform, 'prompt')
res... | python | def platform(self, with_prompt, platforms=None):
"""Return the platform name based on the prompt matching."""
if platforms is None:
platforms = self._dict['generic']['prompt_detection']
for platform in platforms:
pattern = self.pattern(platform, 'prompt')
res... | [
"def",
"platform",
"(",
"self",
",",
"with_prompt",
",",
"platforms",
"=",
"None",
")",
":",
"if",
"platforms",
"is",
"None",
":",
"platforms",
"=",
"self",
".",
"_dict",
"[",
"'generic'",
"]",
"[",
"'prompt_detection'",
"]",
"for",
"platform",
"in",
"pl... | Return the platform name based on the prompt matching. | [
"Return",
"the",
"platform",
"name",
"based",
"on",
"the",
"prompt",
"matching",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/patterns.py#L98-L108 | train | Return the platform name based on the prompt matching. |
kstaniek/condoor | condoor/drivers/Calvados.py | Driver.after_connect | def after_connect(self):
"""Execute after connect."""
# TODO: check if this works.
show_users = self.device.send("show users", timeout=120)
result = re.search(pattern_manager.pattern(self.platform, 'connected_locally'), show_users)
if result:
self.log('Locally connect... | python | def after_connect(self):
"""Execute after connect."""
# TODO: check if this works.
show_users = self.device.send("show users", timeout=120)
result = re.search(pattern_manager.pattern(self.platform, 'connected_locally'), show_users)
if result:
self.log('Locally connect... | [
"def",
"after_connect",
"(",
"self",
")",
":",
"# TODO: check if this works.",
"show_users",
"=",
"self",
".",
"device",
".",
"send",
"(",
"\"show users\"",
",",
"timeout",
"=",
"120",
")",
"result",
"=",
"re",
".",
"search",
"(",
"pattern_manager",
".",
"pa... | Execute after connect. | [
"Execute",
"after",
"connect",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/drivers/Calvados.py#L47-L56 | train | Execute after connect. |
kstaniek/condoor | condoor/drivers/jumphost.py | Driver.get_version_text | def get_version_text(self):
"""Return the version information from Unix host."""
try:
version_text = self.device.send('uname -sr', timeout=10)
except CommandError:
self.log("Non Unix jumphost type detected")
return None
raise ConnectionError("Non U... | python | def get_version_text(self):
"""Return the version information from Unix host."""
try:
version_text = self.device.send('uname -sr', timeout=10)
except CommandError:
self.log("Non Unix jumphost type detected")
return None
raise ConnectionError("Non U... | [
"def",
"get_version_text",
"(",
"self",
")",
":",
"try",
":",
"version_text",
"=",
"self",
".",
"device",
".",
"send",
"(",
"'uname -sr'",
",",
"timeout",
"=",
"10",
")",
"except",
"CommandError",
":",
"self",
".",
"log",
"(",
"\"Non Unix jumphost type detec... | Return the version information from Unix host. | [
"Return",
"the",
"version",
"information",
"from",
"Unix",
"host",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/drivers/jumphost.py#L21-L29 | train | Return the version information from Unix host. |
kstaniek/condoor | condoor/drivers/jumphost.py | Driver.get_hostname_text | def get_hostname_text(self):
"""Return hostname information from the Unix host."""
# FIXME: fix it, too complex logic
try:
hostname_text = self.device.send('hostname', timeout=10)
if hostname_text:
self.device.hostname = hostname_text.splitlines()[0]
... | python | def get_hostname_text(self):
"""Return hostname information from the Unix host."""
# FIXME: fix it, too complex logic
try:
hostname_text = self.device.send('hostname', timeout=10)
if hostname_text:
self.device.hostname = hostname_text.splitlines()[0]
... | [
"def",
"get_hostname_text",
"(",
"self",
")",
":",
"# FIXME: fix it, too complex logic",
"try",
":",
"hostname_text",
"=",
"self",
".",
"device",
".",
"send",
"(",
"'hostname'",
",",
"timeout",
"=",
"10",
")",
"if",
"hostname_text",
":",
"self",
".",
"device",... | Return hostname information from the Unix host. | [
"Return",
"hostname",
"information",
"from",
"the",
"Unix",
"host",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/drivers/jumphost.py#L35-L45 | train | Return hostname information from the Unix host. |
kstaniek/condoor | condoor/drivers/jumphost.py | Driver.make_dynamic_prompt | def make_dynamic_prompt(self, prompt):
"""Extend prompt with flexible mode handling regexp."""
patterns = ["[\r\n]" + pattern_manager.pattern(
self.platform, pattern_name, compiled=False) for pattern_name in self.target_prompt_components]
patterns_re = "|".join(patterns).format(host... | python | def make_dynamic_prompt(self, prompt):
"""Extend prompt with flexible mode handling regexp."""
patterns = ["[\r\n]" + pattern_manager.pattern(
self.platform, pattern_name, compiled=False) for pattern_name in self.target_prompt_components]
patterns_re = "|".join(patterns).format(host... | [
"def",
"make_dynamic_prompt",
"(",
"self",
",",
"prompt",
")",
":",
"patterns",
"=",
"[",
"\"[\\r\\n]\"",
"+",
"pattern_manager",
".",
"pattern",
"(",
"self",
".",
"platform",
",",
"pattern_name",
",",
"compiled",
"=",
"False",
")",
"for",
"pattern_name",
"i... | Extend prompt with flexible mode handling regexp. | [
"Extend",
"prompt",
"with",
"flexible",
"mode",
"handling",
"regexp",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/drivers/jumphost.py#L47-L60 | train | Extend prompt with flexible mode handling regexp. |
theherk/figgypy | figgypy/config.py | Config._find_file | def _find_file(f):
"""Find a config file if possible."""
if os.path.isabs(f):
return f
else:
for d in Config._dirs:
_f = os.path.join(d, f)
if os.path.isfile(_f):
return _f
raise FiggypyError(
... | python | def _find_file(f):
"""Find a config file if possible."""
if os.path.isabs(f):
return f
else:
for d in Config._dirs:
_f = os.path.join(d, f)
if os.path.isfile(_f):
return _f
raise FiggypyError(
... | [
"def",
"_find_file",
"(",
"f",
")",
":",
"if",
"os",
".",
"path",
".",
"isabs",
"(",
"f",
")",
":",
"return",
"f",
"else",
":",
"for",
"d",
"in",
"Config",
".",
"_dirs",
":",
"_f",
"=",
"os",
".",
"path",
".",
"join",
"(",
"d",
",",
"f",
")... | Find a config file if possible. | [
"Find",
"a",
"config",
"file",
"if",
"possible",
"."
] | 324d1b281a8df20a26b92f42bf7fda0cca892116 | https://github.com/theherk/figgypy/blob/324d1b281a8df20a26b92f42bf7fda0cca892116/figgypy/config.py#L82-L94 | train | Find a config file if possible. |
theherk/figgypy | figgypy/config.py | Config._load_file | def _load_file(self, f):
"""Get values from config file"""
try:
with open(f, 'r') as _fo:
_seria_in = seria.load(_fo)
_y = _seria_in.dump('yaml')
except IOError:
raise FiggypyError("could not open configuration file")
self.values.up... | python | def _load_file(self, f):
"""Get values from config file"""
try:
with open(f, 'r') as _fo:
_seria_in = seria.load(_fo)
_y = _seria_in.dump('yaml')
except IOError:
raise FiggypyError("could not open configuration file")
self.values.up... | [
"def",
"_load_file",
"(",
"self",
",",
"f",
")",
":",
"try",
":",
"with",
"open",
"(",
"f",
",",
"'r'",
")",
"as",
"_fo",
":",
"_seria_in",
"=",
"seria",
".",
"load",
"(",
"_fo",
")",
"_y",
"=",
"_seria_in",
".",
"dump",
"(",
"'yaml'",
")",
"ex... | Get values from config file | [
"Get",
"values",
"from",
"config",
"file"
] | 324d1b281a8df20a26b92f42bf7fda0cca892116 | https://github.com/theherk/figgypy/blob/324d1b281a8df20a26b92f42bf7fda0cca892116/figgypy/config.py#L96-L104 | train | Load values from config file |
theherk/figgypy | figgypy/config.py | Config.setup | def setup(self, config_file=None, aws_config=None, gpg_config=None,
decrypt_gpg=True, decrypt_kms=True):
"""Make setup easier by providing a constructor method.
Move to config_file
File can be located with a filename only, relative path, or absolute path.
If only name or r... | python | def setup(self, config_file=None, aws_config=None, gpg_config=None,
decrypt_gpg=True, decrypt_kms=True):
"""Make setup easier by providing a constructor method.
Move to config_file
File can be located with a filename only, relative path, or absolute path.
If only name or r... | [
"def",
"setup",
"(",
"self",
",",
"config_file",
"=",
"None",
",",
"aws_config",
"=",
"None",
",",
"gpg_config",
"=",
"None",
",",
"decrypt_gpg",
"=",
"True",
",",
"decrypt_kms",
"=",
"True",
")",
":",
"if",
"aws_config",
"is",
"not",
"None",
":",
"sel... | Make setup easier by providing a constructor method.
Move to config_file
File can be located with a filename only, relative path, or absolute path.
If only name or relative path is provided, look in this order:
1. current directory
2. `~/.config/<file_name>`
3. `/etc/<f... | [
"Make",
"setup",
"easier",
"by",
"providing",
"a",
"constructor",
"method",
"."
] | 324d1b281a8df20a26b92f42bf7fda0cca892116 | https://github.com/theherk/figgypy/blob/324d1b281a8df20a26b92f42bf7fda0cca892116/figgypy/config.py#L199-L227 | train | This method is used to set up the instance variables for the current instance of the class. |
kstaniek/condoor | condoor/protocols/console.py | Console.authenticate | def authenticate(self, driver):
"""Authenticate using the Console Server protocol specific FSM."""
# 0 1 2 3
events = [driver.username_re, driver.password_re, self.device.prompt_re, driver.rommon_re,
... | python | def authenticate(self, driver):
"""Authenticate using the Console Server protocol specific FSM."""
# 0 1 2 3
events = [driver.username_re, driver.password_re, self.device.prompt_re, driver.rommon_re,
... | [
"def",
"authenticate",
"(",
"self",
",",
"driver",
")",
":",
"# 0 1 2 3",
"events",
"=",
"[",
"driver",
".",
"username_re",
",",
"driver",
".",
"password_re",
",",
"self",
".",
"device",
"."... | Authenticate using the Console Server protocol specific FSM. | [
"Authenticate",
"using",
"the",
"Console",
"Server",
"protocol",
"specific",
"FSM",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/protocols/console.py#L70-L95 | train | Authenticate using the Console Server protocol specific FSM. |
kstaniek/condoor | condoor/protocols/console.py | Console.disconnect | def disconnect(self, device):
"""Disconnect using protocol specific method."""
self.device.ctrl.sendcontrol('d')
self.device.ctrl.send("c.")
self.log("CONSOLE SERVER disconnect")
try:
self.device.ctrl.send(chr(4))
except OSError:
self.log("Protocol... | python | def disconnect(self, device):
"""Disconnect using protocol specific method."""
self.device.ctrl.sendcontrol('d')
self.device.ctrl.send("c.")
self.log("CONSOLE SERVER disconnect")
try:
self.device.ctrl.send(chr(4))
except OSError:
self.log("Protocol... | [
"def",
"disconnect",
"(",
"self",
",",
"device",
")",
":",
"self",
".",
"device",
".",
"ctrl",
".",
"sendcontrol",
"(",
"'d'",
")",
"self",
".",
"device",
".",
"ctrl",
".",
"send",
"(",
"\"c.\"",
")",
"self",
".",
"log",
"(",
"\"CONSOLE SERVER disconne... | Disconnect using protocol specific method. | [
"Disconnect",
"using",
"protocol",
"specific",
"method",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/protocols/console.py#L97-L105 | train | Disconnect from the specified device. |
kstaniek/condoor | condoor/utils.py | delegate | def delegate(attribute_name, method_names):
"""Pass the call to the attribute called attribute_name for every method listed in method_names."""
# hack for python 2.7 as nonlocal is not available
info = {
'attribute': attribute_name,
'methods': method_names
}
def decorator(cls):
... | python | def delegate(attribute_name, method_names):
"""Pass the call to the attribute called attribute_name for every method listed in method_names."""
# hack for python 2.7 as nonlocal is not available
info = {
'attribute': attribute_name,
'methods': method_names
}
def decorator(cls):
... | [
"def",
"delegate",
"(",
"attribute_name",
",",
"method_names",
")",
":",
"# hack for python 2.7 as nonlocal is not available",
"info",
"=",
"{",
"'attribute'",
":",
"attribute_name",
",",
"'methods'",
":",
"method_names",
"}",
"def",
"decorator",
"(",
"cls",
")",
":... | Pass the call to the attribute called attribute_name for every method listed in method_names. | [
"Pass",
"the",
"call",
"to",
"the",
"attribute",
"called",
"attribute_name",
"for",
"every",
"method",
"listed",
"in",
"method_names",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/utils.py#L12-L29 | train | Decorator that delegates the class to the attribute called attribute_name for every method listed in method_names. |
kstaniek/condoor | condoor/utils.py | is_reachable | def is_reachable(host, port=23):
"""Check reachability for specified hostname/port.
It tries to open TCP socket.
It supports IPv6.
:param host: hostname or ip address string
:rtype: str
:param port: tcp port number
:rtype: number
:return: True if host is reachable else false
"""
... | python | def is_reachable(host, port=23):
"""Check reachability for specified hostname/port.
It tries to open TCP socket.
It supports IPv6.
:param host: hostname or ip address string
:rtype: str
:param port: tcp port number
:rtype: number
:return: True if host is reachable else false
"""
... | [
"def",
"is_reachable",
"(",
"host",
",",
"port",
"=",
"23",
")",
":",
"try",
":",
"addresses",
"=",
"socket",
".",
"getaddrinfo",
"(",
"host",
",",
"port",
",",
"socket",
".",
"AF_UNSPEC",
",",
"socket",
".",
"SOCK_STREAM",
")",
"except",
"socket",
"."... | Check reachability for specified hostname/port.
It tries to open TCP socket.
It supports IPv6.
:param host: hostname or ip address string
:rtype: str
:param port: tcp port number
:rtype: number
:return: True if host is reachable else false | [
"Check",
"reachability",
"for",
"specified",
"hostname",
"/",
"port",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/utils.py#L49-L82 | train | Check if host is reachable. |
kstaniek/condoor | condoor/utils.py | pattern_to_str | def pattern_to_str(pattern):
"""Convert regex pattern to string.
If pattern is string it returns itself,
if pattern is SRE_Pattern then return pattern attribute
:param pattern: pattern object or string
:return: str: pattern sttring
"""
if isinstance(pattern, str):
return repr(patter... | python | def pattern_to_str(pattern):
"""Convert regex pattern to string.
If pattern is string it returns itself,
if pattern is SRE_Pattern then return pattern attribute
:param pattern: pattern object or string
:return: str: pattern sttring
"""
if isinstance(pattern, str):
return repr(patter... | [
"def",
"pattern_to_str",
"(",
"pattern",
")",
":",
"if",
"isinstance",
"(",
"pattern",
",",
"str",
")",
":",
"return",
"repr",
"(",
"pattern",
")",
"else",
":",
"return",
"repr",
"(",
"pattern",
".",
"pattern",
")",
"if",
"pattern",
"else",
"None"
] | Convert regex pattern to string.
If pattern is string it returns itself,
if pattern is SRE_Pattern then return pattern attribute
:param pattern: pattern object or string
:return: str: pattern sttring | [
"Convert",
"regex",
"pattern",
"to",
"string",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/utils.py#L85-L96 | train | Convert regex pattern to string. |
kstaniek/condoor | condoor/utils.py | levenshtein_distance | def levenshtein_distance(str_a, str_b):
"""Calculate the Levenshtein distance between string a and b.
:param str_a: String - input string a
:param str_b: String - input string b
:return: Number - Levenshtein Distance between string a and b
"""
len_a, len_b = len(str_a), len(str_b)
if len_a ... | python | def levenshtein_distance(str_a, str_b):
"""Calculate the Levenshtein distance between string a and b.
:param str_a: String - input string a
:param str_b: String - input string b
:return: Number - Levenshtein Distance between string a and b
"""
len_a, len_b = len(str_a), len(str_b)
if len_a ... | [
"def",
"levenshtein_distance",
"(",
"str_a",
",",
"str_b",
")",
":",
"len_a",
",",
"len_b",
"=",
"len",
"(",
"str_a",
")",
",",
"len",
"(",
"str_b",
")",
"if",
"len_a",
">",
"len_b",
":",
"str_a",
",",
"str_b",
"=",
"str_b",
",",
"str_a",
"len_a",
... | Calculate the Levenshtein distance between string a and b.
:param str_a: String - input string a
:param str_b: String - input string b
:return: Number - Levenshtein Distance between string a and b | [
"Calculate",
"the",
"Levenshtein",
"distance",
"between",
"string",
"a",
"and",
"b",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/utils.py#L99-L119 | train | Calculate the Levenshtein distance between strings a and b. |
kstaniek/condoor | condoor/utils.py | parse_inventory | def parse_inventory(inventory_output=None):
"""Parse the inventory text and return udi dict."""
udi = {
"name": "",
"description": "",
"pid": "",
"vid": "",
"sn": ""
}
if inventory_output is None:
return udi
# find the record with chassis text in name... | python | def parse_inventory(inventory_output=None):
"""Parse the inventory text and return udi dict."""
udi = {
"name": "",
"description": "",
"pid": "",
"vid": "",
"sn": ""
}
if inventory_output is None:
return udi
# find the record with chassis text in name... | [
"def",
"parse_inventory",
"(",
"inventory_output",
"=",
"None",
")",
":",
"udi",
"=",
"{",
"\"name\"",
":",
"\"\"",
",",
"\"description\"",
":",
"\"\"",
",",
"\"pid\"",
":",
"\"\"",
",",
"\"vid\"",
":",
"\"\"",
",",
"\"sn\"",
":",
"\"\"",
"}",
"if",
"i... | Parse the inventory text and return udi dict. | [
"Parse",
"the",
"inventory",
"text",
"and",
"return",
"udi",
"dict",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/utils.py#L122-L165 | train | Parse the inventory text and return udi dict. |
kstaniek/condoor | condoor/utils.py | normalize_urls | def normalize_urls(urls):
"""Overload urls and make list of lists of urls."""
_urls = []
if isinstance(urls, list):
if urls:
if isinstance(urls[0], list):
# multiple connections (list of the lists)
_urls = urls
elif isinstance(urls[0], str):
... | python | def normalize_urls(urls):
"""Overload urls and make list of lists of urls."""
_urls = []
if isinstance(urls, list):
if urls:
if isinstance(urls[0], list):
# multiple connections (list of the lists)
_urls = urls
elif isinstance(urls[0], str):
... | [
"def",
"normalize_urls",
"(",
"urls",
")",
":",
"_urls",
"=",
"[",
"]",
"if",
"isinstance",
"(",
"urls",
",",
"list",
")",
":",
"if",
"urls",
":",
"if",
"isinstance",
"(",
"urls",
"[",
"0",
"]",
",",
"list",
")",
":",
"# multiple connections (list of t... | Overload urls and make list of lists of urls. | [
"Overload",
"urls",
"and",
"make",
"list",
"of",
"lists",
"of",
"urls",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/utils.py#L233-L248 | train | Overload urls and make list of lists of urls. |
kstaniek/condoor | condoor/utils.py | yaml_file_to_dict | def yaml_file_to_dict(script_name, path=None):
"""Read yaml file and return the dict.
It assumes the module file exists with the defaults.
If the CONDOOR_{SCRIPT_NAME} env is set then the user file from the env is loaded and merged with the default
There can be user file located in ~/.condoor director... | python | def yaml_file_to_dict(script_name, path=None):
"""Read yaml file and return the dict.
It assumes the module file exists with the defaults.
If the CONDOOR_{SCRIPT_NAME} env is set then the user file from the env is loaded and merged with the default
There can be user file located in ~/.condoor director... | [
"def",
"yaml_file_to_dict",
"(",
"script_name",
",",
"path",
"=",
"None",
")",
":",
"def",
"load_yaml",
"(",
"file_path",
")",
":",
"\"\"\"Load YAML file from full file path and return dict.\"\"\"",
"with",
"open",
"(",
"file_path",
",",
"'r'",
")",
"as",
"yamlfile"... | Read yaml file and return the dict.
It assumes the module file exists with the defaults.
If the CONDOOR_{SCRIPT_NAME} env is set then the user file from the env is loaded and merged with the default
There can be user file located in ~/.condoor directory with the {script_name}.yaml filename. If exists
... | [
"Read",
"yaml",
"file",
"and",
"return",
"the",
"dict",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/utils.py#L280-L323 | train | Read a YAML file and return a dict. |
kstaniek/condoor | condoor/utils.py | FilteredFile.write | def write(self, text):
"""Override the standard write method to filter the content."""
index = text.find('\n')
if index == -1:
self._buffer = self._buffer + text
else:
self._buffer = self._buffer + text[:index + 1]
if self._pattern:
# p... | python | def write(self, text):
"""Override the standard write method to filter the content."""
index = text.find('\n')
if index == -1:
self._buffer = self._buffer + text
else:
self._buffer = self._buffer + text[:index + 1]
if self._pattern:
# p... | [
"def",
"write",
"(",
"self",
",",
"text",
")",
":",
"index",
"=",
"text",
".",
"find",
"(",
"'\\n'",
")",
"if",
"index",
"==",
"-",
"1",
":",
"self",
".",
"_buffer",
"=",
"self",
".",
"_buffer",
"+",
"text",
"else",
":",
"self",
".",
"_buffer",
... | Override the standard write method to filter the content. | [
"Override",
"the",
"standard",
"write",
"method",
"to",
"filter",
"the",
"content",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/utils.py#L193-L209 | train | Override the standard write method to filter the content. |
ajdavis/GreenletProfiler | _vendorized_yappi/yappi.py | convert2pstats | def convert2pstats(stats):
"""
Converts the internal stat type of yappi(which is returned by a call to YFuncStats.get())
as pstats object.
"""
if not isinstance(stats, YFuncStats):
raise YappiError("Source stats must be derived from YFuncStats.")
import pstats
class _PStatHolder... | python | def convert2pstats(stats):
"""
Converts the internal stat type of yappi(which is returned by a call to YFuncStats.get())
as pstats object.
"""
if not isinstance(stats, YFuncStats):
raise YappiError("Source stats must be derived from YFuncStats.")
import pstats
class _PStatHolder... | [
"def",
"convert2pstats",
"(",
"stats",
")",
":",
"if",
"not",
"isinstance",
"(",
"stats",
",",
"YFuncStats",
")",
":",
"raise",
"YappiError",
"(",
"\"Source stats must be derived from YFuncStats.\"",
")",
"import",
"pstats",
"class",
"_PStatHolder",
":",
"def",
"_... | Converts the internal stat type of yappi(which is returned by a call to YFuncStats.get())
as pstats object. | [
"Converts",
"the",
"internal",
"stat",
"type",
"of",
"yappi",
"(",
"which",
"is",
"returned",
"by",
"a",
"call",
"to",
"YFuncStats",
".",
"get",
"()",
")",
"as",
"pstats",
"object",
"."
] | 700349864a4f368a8a73a2a60f048c2e818d7cea | https://github.com/ajdavis/GreenletProfiler/blob/700349864a4f368a8a73a2a60f048c2e818d7cea/_vendorized_yappi/yappi.py#L108-L142 | train | Convert stats from YFuncStats to pstats object. |
ajdavis/GreenletProfiler | _vendorized_yappi/yappi.py | start | def start(builtins=False, profile_threads=True):
"""
Start profiler.
"""
if profile_threads:
threading.setprofile(_callback)
_yappi.start(builtins, profile_threads) | python | def start(builtins=False, profile_threads=True):
"""
Start profiler.
"""
if profile_threads:
threading.setprofile(_callback)
_yappi.start(builtins, profile_threads) | [
"def",
"start",
"(",
"builtins",
"=",
"False",
",",
"profile_threads",
"=",
"True",
")",
":",
"if",
"profile_threads",
":",
"threading",
".",
"setprofile",
"(",
"_callback",
")",
"_yappi",
".",
"start",
"(",
"builtins",
",",
"profile_threads",
")"
] | Start profiler. | [
"Start",
"profiler",
"."
] | 700349864a4f368a8a73a2a60f048c2e818d7cea | https://github.com/ajdavis/GreenletProfiler/blob/700349864a4f368a8a73a2a60f048c2e818d7cea/_vendorized_yappi/yappi.py#L700-L706 | train | Start profiler. |
ajdavis/GreenletProfiler | _vendorized_yappi/yappi.py | set_clock_type | def set_clock_type(type):
"""
Sets the internal clock type for timing. Profiler shall not have any previous stats.
Otherwise an exception is thrown.
"""
type = type.upper()
if type not in CLOCK_TYPES:
raise YappiError("Invalid clock type:%s" % (type))
_yappi.set_clock_type(C... | python | def set_clock_type(type):
"""
Sets the internal clock type for timing. Profiler shall not have any previous stats.
Otherwise an exception is thrown.
"""
type = type.upper()
if type not in CLOCK_TYPES:
raise YappiError("Invalid clock type:%s" % (type))
_yappi.set_clock_type(C... | [
"def",
"set_clock_type",
"(",
"type",
")",
":",
"type",
"=",
"type",
".",
"upper",
"(",
")",
"if",
"type",
"not",
"in",
"CLOCK_TYPES",
":",
"raise",
"YappiError",
"(",
"\"Invalid clock type:%s\"",
"%",
"(",
"type",
")",
")",
"_yappi",
".",
"set_clock_type"... | Sets the internal clock type for timing. Profiler shall not have any previous stats.
Otherwise an exception is thrown. | [
"Sets",
"the",
"internal",
"clock",
"type",
"for",
"timing",
".",
"Profiler",
"shall",
"not",
"have",
"any",
"previous",
"stats",
".",
"Otherwise",
"an",
"exception",
"is",
"thrown",
"."
] | 700349864a4f368a8a73a2a60f048c2e818d7cea | https://github.com/ajdavis/GreenletProfiler/blob/700349864a4f368a8a73a2a60f048c2e818d7cea/_vendorized_yappi/yappi.py#L755-L764 | train | Sets the internal clock type for timing. |
ajdavis/GreenletProfiler | _vendorized_yappi/yappi.py | YStats._debug_check_sanity | def _debug_check_sanity(self):
"""
Check for basic sanity errors in stats. e.g: Check for duplicate stats.
"""
for x in self:
if self._stats.count(x) > 1:
return False
return True | python | def _debug_check_sanity(self):
"""
Check for basic sanity errors in stats. e.g: Check for duplicate stats.
"""
for x in self:
if self._stats.count(x) > 1:
return False
return True | [
"def",
"_debug_check_sanity",
"(",
"self",
")",
":",
"for",
"x",
"in",
"self",
":",
"if",
"self",
".",
"_stats",
".",
"count",
"(",
"x",
")",
">",
"1",
":",
"return",
"False",
"return",
"True"
] | Check for basic sanity errors in stats. e.g: Check for duplicate stats. | [
"Check",
"for",
"basic",
"sanity",
"errors",
"in",
"stats",
".",
"e",
".",
"g",
":",
"Check",
"for",
"duplicate",
"stats",
"."
] | 700349864a4f368a8a73a2a60f048c2e818d7cea | https://github.com/ajdavis/GreenletProfiler/blob/700349864a4f368a8a73a2a60f048c2e818d7cea/_vendorized_yappi/yappi.py#L310-L317 | train | Check for basic sanity errors in stats. e. g. for duplicate stats. |
ajdavis/GreenletProfiler | _vendorized_yappi/yappi.py | YChildFuncStats.print_all | def print_all(self, out=sys.stdout):
"""
Prints all of the child function profiler results to a given file. (stdout by default)
"""
if self.empty():
return
FUNC_NAME_LEN = 38
CALLCOUNT_LEN = 9
out.write(CRLF)
out.write("name ... | python | def print_all(self, out=sys.stdout):
"""
Prints all of the child function profiler results to a given file. (stdout by default)
"""
if self.empty():
return
FUNC_NAME_LEN = 38
CALLCOUNT_LEN = 9
out.write(CRLF)
out.write("name ... | [
"def",
"print_all",
"(",
"self",
",",
"out",
"=",
"sys",
".",
"stdout",
")",
":",
"if",
"self",
".",
"empty",
"(",
")",
":",
"return",
"FUNC_NAME_LEN",
"=",
"38",
"CALLCOUNT_LEN",
"=",
"9",
"out",
".",
"write",
"(",
"CRLF",
")",
"out",
".",
"write"... | Prints all of the child function profiler results to a given file. (stdout by default) | [
"Prints",
"all",
"of",
"the",
"child",
"function",
"profiler",
"results",
"to",
"a",
"given",
"file",
".",
"(",
"stdout",
"by",
"default",
")"
] | 700349864a4f368a8a73a2a60f048c2e818d7cea | https://github.com/ajdavis/GreenletProfiler/blob/700349864a4f368a8a73a2a60f048c2e818d7cea/_vendorized_yappi/yappi.py#L342-L369 | train | Prints all of the child function profiler results to a given file. |
ajdavis/GreenletProfiler | _vendorized_yappi/yappi.py | YFuncStats._save_as_CALLGRIND | def _save_as_CALLGRIND(self, path):
"""
Writes all the function stats in a callgrind-style format to the given
file. (stdout by default)
"""
header = """version: 1\ncreator: %s\npid: %d\ncmd: %s\npart: 1\n\nevents: Ticks""" % \
('yappi', os.getpid(), ' '... | python | def _save_as_CALLGRIND(self, path):
"""
Writes all the function stats in a callgrind-style format to the given
file. (stdout by default)
"""
header = """version: 1\ncreator: %s\npid: %d\ncmd: %s\npart: 1\n\nevents: Ticks""" % \
('yappi', os.getpid(), ' '... | [
"def",
"_save_as_CALLGRIND",
"(",
"self",
",",
"path",
")",
":",
"header",
"=",
"\"\"\"version: 1\\ncreator: %s\\npid: %d\\ncmd: %s\\npart: 1\\n\\nevents: Ticks\"\"\"",
"%",
"(",
"'yappi'",
",",
"os",
".",
"getpid",
"(",
")",
",",
"' '",
".",
"join",
"(",
"sys",
... | Writes all the function stats in a callgrind-style format to the given
file. (stdout by default) | [
"Writes",
"all",
"the",
"function",
"stats",
"in",
"a",
"callgrind",
"-",
"style",
"format",
"to",
"the",
"given",
"file",
".",
"(",
"stdout",
"by",
"default",
")"
] | 700349864a4f368a8a73a2a60f048c2e818d7cea | https://github.com/ajdavis/GreenletProfiler/blob/700349864a4f368a8a73a2a60f048c2e818d7cea/_vendorized_yappi/yappi.py#L500-L540 | train | Saves all the function stats in a callgrind - style format to the given path. |
ajdavis/GreenletProfiler | _vendorized_yappi/yappi.py | YThreadStats.print_all | def print_all(self, out=sys.stdout):
"""
Prints all of the thread profiler results to a given file. (stdout by default)
"""
THREAD_FUNC_NAME_LEN = 25
THREAD_NAME_LEN = 13
THREAD_ID_LEN = 15
THREAD_SCHED_CNT_LEN = 10
out.write(CRLF)
out.write("name... | python | def print_all(self, out=sys.stdout):
"""
Prints all of the thread profiler results to a given file. (stdout by default)
"""
THREAD_FUNC_NAME_LEN = 25
THREAD_NAME_LEN = 13
THREAD_ID_LEN = 15
THREAD_SCHED_CNT_LEN = 10
out.write(CRLF)
out.write("name... | [
"def",
"print_all",
"(",
"self",
",",
"out",
"=",
"sys",
".",
"stdout",
")",
":",
"THREAD_FUNC_NAME_LEN",
"=",
"25",
"THREAD_NAME_LEN",
"=",
"13",
"THREAD_ID_LEN",
"=",
"15",
"THREAD_SCHED_CNT_LEN",
"=",
"10",
"out",
".",
"write",
"(",
"CRLF",
")",
"out",
... | Prints all of the thread profiler results to a given file. (stdout by default) | [
"Prints",
"all",
"of",
"the",
"thread",
"profiler",
"results",
"to",
"a",
"given",
"file",
".",
"(",
"stdout",
"by",
"default",
")"
] | 700349864a4f368a8a73a2a60f048c2e818d7cea | https://github.com/ajdavis/GreenletProfiler/blob/700349864a4f368a8a73a2a60f048c2e818d7cea/_vendorized_yappi/yappi.py#L669-L689 | train | Prints all of the thread profiler results to a given file. |
hwmrocker/smtplibaio | smtplibaio/streams.py | SMTPStreamReader.read_reply | async def read_reply(self):
"""
Reads a reply from the server.
Raises:
ConnectionResetError: If the connection with the server is lost
(we can't read any response anymore). Or if the server
replies without a proper return code.
Returns:
... | python | async def read_reply(self):
"""
Reads a reply from the server.
Raises:
ConnectionResetError: If the connection with the server is lost
(we can't read any response anymore). Or if the server
replies without a proper return code.
Returns:
... | [
"async",
"def",
"read_reply",
"(",
"self",
")",
":",
"code",
"=",
"500",
"messages",
"=",
"[",
"]",
"go_on",
"=",
"True",
"while",
"go_on",
":",
"try",
":",
"line",
"=",
"await",
"self",
".",
"readline",
"(",
")",
"except",
"ValueError",
"as",
"e",
... | Reads a reply from the server.
Raises:
ConnectionResetError: If the connection with the server is lost
(we can't read any response anymore). Or if the server
replies without a proper return code.
Returns:
(int, str): A (code, full_message) 2-tupl... | [
"Reads",
"a",
"reply",
"from",
"the",
"server",
"."
] | 84ce8e45b7e706476739d0efcb416c18ecabbbb6 | https://github.com/hwmrocker/smtplibaio/blob/84ce8e45b7e706476739d0efcb416c18ecabbbb6/smtplibaio/streams.py#L31-L79 | train | Reads a reply from the server. |
hwmrocker/smtplibaio | smtplibaio/streams.py | SMTPStreamWriter.send_command | async def send_command(self, command):
"""
Sends the given command to the server.
Args:
command (str): Command to send to the server.
Raises:
ConnectionResetError: If the connection with the server is lost.
(Shouldn't it raise BrokenPipeError too ?)
... | python | async def send_command(self, command):
"""
Sends the given command to the server.
Args:
command (str): Command to send to the server.
Raises:
ConnectionResetError: If the connection with the server is lost.
(Shouldn't it raise BrokenPipeError too ?)
... | [
"async",
"def",
"send_command",
"(",
"self",
",",
"command",
")",
":",
"command",
"=",
"\"{}\\r\\n\"",
".",
"format",
"(",
"command",
")",
".",
"encode",
"(",
"\"ascii\"",
",",
"errors",
"=",
"\"backslashreplace\"",
")",
"self",
".",
"write",
"(",
"command... | Sends the given command to the server.
Args:
command (str): Command to send to the server.
Raises:
ConnectionResetError: If the connection with the server is lost.
(Shouldn't it raise BrokenPipeError too ?) | [
"Sends",
"the",
"given",
"command",
"to",
"the",
"server",
"."
] | 84ce8e45b7e706476739d0efcb416c18ecabbbb6 | https://github.com/hwmrocker/smtplibaio/blob/84ce8e45b7e706476739d0efcb416c18ecabbbb6/smtplibaio/streams.py#L89-L105 | train | Sends a command to the server. |
kstaniek/condoor | condoor/hopinfo.py | make_hop_info_from_url | def make_hop_info_from_url(url, verify_reachability=None):
"""Build HopInfo object from url.
It allows only telnet and ssh as a valid protocols.
Args:
url (str): The url string describing the node. i.e.
telnet://username@1.1.1.1. The protocol, username and address
portion o... | python | def make_hop_info_from_url(url, verify_reachability=None):
"""Build HopInfo object from url.
It allows only telnet and ssh as a valid protocols.
Args:
url (str): The url string describing the node. i.e.
telnet://username@1.1.1.1. The protocol, username and address
portion o... | [
"def",
"make_hop_info_from_url",
"(",
"url",
",",
"verify_reachability",
"=",
"None",
")",
":",
"parsed",
"=",
"urlparse",
"(",
"url",
")",
"username",
"=",
"None",
"if",
"parsed",
".",
"username",
"is",
"None",
"else",
"unquote",
"(",
"parsed",
".",
"user... | Build HopInfo object from url.
It allows only telnet and ssh as a valid protocols.
Args:
url (str): The url string describing the node. i.e.
telnet://username@1.1.1.1. The protocol, username and address
portion of url is mandatory. Port and password is optional.
If ... | [
"Build",
"HopInfo",
"object",
"from",
"url",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/hopinfo.py#L16-L63 | train | Build HopInfo object from url. |
kstaniek/condoor | condoor/hopinfo.py | HopInfo.is_reachable | def is_reachable(self):
"""Return if host is reachable."""
if self.verify_reachability and \
hasattr(self.verify_reachability, '__call__'):
return self.verify_reachability(host=self.hostname, port=self.port)
# assume is reachable if can't verify
return True | python | def is_reachable(self):
"""Return if host is reachable."""
if self.verify_reachability and \
hasattr(self.verify_reachability, '__call__'):
return self.verify_reachability(host=self.hostname, port=self.port)
# assume is reachable if can't verify
return True | [
"def",
"is_reachable",
"(",
"self",
")",
":",
"if",
"self",
".",
"verify_reachability",
"and",
"hasattr",
"(",
"self",
".",
"verify_reachability",
",",
"'__call__'",
")",
":",
"return",
"self",
".",
"verify_reachability",
"(",
"host",
"=",
"self",
".",
"host... | Return if host is reachable. | [
"Return",
"if",
"host",
"is",
"reachable",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/hopinfo.py#L118-L124 | train | Return if host is reachable. |
bfarr/kombine | examples/kepler/synthetic.py | DataGenerator.generate | def generate(self):
"""Returns (ts, rvs), where ts is a list of arrays of
observation times (one array for each observatory), and rvs is
a corresponding list of total radial velocity measurements."""
ts=self.generate_tobs()
noise=self.generate_noise(ts)
rvs=[]
... | python | def generate(self):
"""Returns (ts, rvs), where ts is a list of arrays of
observation times (one array for each observatory), and rvs is
a corresponding list of total radial velocity measurements."""
ts=self.generate_tobs()
noise=self.generate_noise(ts)
rvs=[]
... | [
"def",
"generate",
"(",
"self",
")",
":",
"ts",
"=",
"self",
".",
"generate_tobs",
"(",
")",
"noise",
"=",
"self",
".",
"generate_noise",
"(",
"ts",
")",
"rvs",
"=",
"[",
"]",
"for",
"t",
",",
"n",
"in",
"zip",
"(",
"ts",
",",
"noise",
")",
":"... | Returns (ts, rvs), where ts is a list of arrays of
observation times (one array for each observatory), and rvs is
a corresponding list of total radial velocity measurements. | [
"Returns",
"(",
"ts",
"rvs",
")",
"where",
"ts",
"is",
"a",
"list",
"of",
"arrays",
"of",
"observation",
"times",
"(",
"one",
"array",
"for",
"each",
"observatory",
")",
"and",
"rvs",
"is",
"a",
"corresponding",
"list",
"of",
"total",
"radial",
"velocity... | 50c946dee5da33e7baab71d9bd6c265ff02ffb13 | https://github.com/bfarr/kombine/blob/50c946dee5da33e7baab71d9bd6c265ff02ffb13/examples/kepler/synthetic.py#L114-L126 | train | Returns ( ts rvs ) where ts is a list of arrays of arrays of
observation times one array for each observatory and rvs is a corresponding list of total radial velocity measurements. |
kstaniek/condoor | condoor/drivers/IOS.py | Driver.enable | def enable(self, enable_password):
"""Change to the privilege mode."""
if self.device.prompt[-1] == '#':
self.log("Device is already in privileged mode")
return
events = [self.password_re, self.device.prompt_re, pexpect.TIMEOUT, pexpect.EOF]
transitions = [
... | python | def enable(self, enable_password):
"""Change to the privilege mode."""
if self.device.prompt[-1] == '#':
self.log("Device is already in privileged mode")
return
events = [self.password_re, self.device.prompt_re, pexpect.TIMEOUT, pexpect.EOF]
transitions = [
... | [
"def",
"enable",
"(",
"self",
",",
"enable_password",
")",
":",
"if",
"self",
".",
"device",
".",
"prompt",
"[",
"-",
"1",
"]",
"==",
"'#'",
":",
"self",
".",
"log",
"(",
"\"Device is already in privileged mode\"",
")",
"return",
"events",
"=",
"[",
"sel... | Change to the privilege mode. | [
"Change",
"to",
"the",
"privilege",
"mode",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/drivers/IOS.py#L48-L68 | train | Change to the privilege mode. |
kstaniek/condoor | condoor/drivers/IOS.py | Driver.reload | def reload(self, reload_timeout=300, save_config=True):
"""Reload the device.
CSM_DUT#reload
System configuration has been modified. Save? [yes/no]: yes
Building configuration...
[OK]
Proceed with reload? [confirm]
"""
response = "yes" if save_config els... | python | def reload(self, reload_timeout=300, save_config=True):
"""Reload the device.
CSM_DUT#reload
System configuration has been modified. Save? [yes/no]: yes
Building configuration...
[OK]
Proceed with reload? [confirm]
"""
response = "yes" if save_config els... | [
"def",
"reload",
"(",
"self",
",",
"reload_timeout",
"=",
"300",
",",
"save_config",
"=",
"True",
")",
":",
"response",
"=",
"\"yes\"",
"if",
"save_config",
"else",
"\"no\"",
"events",
"=",
"[",
"SAVE_CONFIG",
",",
"PROCEED",
",",
"pexpect",
".",
"TIMEOUT"... | Reload the device.
CSM_DUT#reload
System configuration has been modified. Save? [yes/no]: yes
Building configuration...
[OK]
Proceed with reload? [confirm] | [
"Reload",
"the",
"device",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/drivers/IOS.py#L70-L93 | train | Reload the device. |
kstaniek/condoor | condoor/drivers/IOS.py | Driver.config | def config(self, config_text, plane):
"""Apply config."""
nol = config_text.count('\n')
config_lines = iter(config_text.splitlines())
events = [self.prompt_re, self.syntax_error_re]
transitions = [
(self.prompt_re, [0], 0, partial(a_send_line, config_lines), 10),
... | python | def config(self, config_text, plane):
"""Apply config."""
nol = config_text.count('\n')
config_lines = iter(config_text.splitlines())
events = [self.prompt_re, self.syntax_error_re]
transitions = [
(self.prompt_re, [0], 0, partial(a_send_line, config_lines), 10),
... | [
"def",
"config",
"(",
"self",
",",
"config_text",
",",
"plane",
")",
":",
"nol",
"=",
"config_text",
".",
"count",
"(",
"'\\n'",
")",
"config_lines",
"=",
"iter",
"(",
"config_text",
".",
"splitlines",
"(",
")",
")",
"events",
"=",
"[",
"self",
".",
... | Apply config. | [
"Apply",
"config",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/drivers/IOS.py#L95-L121 | train | Apply config. |
OnroerendErfgoed/language-tags | language_tags/tags.py | tags.types | def types(subtag):
"""
Get the types of a subtag string (excludes redundant and grandfathered).
:param str subtag: subtag.
:return: list of types. The return list can be empty.
"""
if subtag in index:
types = index[subtag]
return [type for type i... | python | def types(subtag):
"""
Get the types of a subtag string (excludes redundant and grandfathered).
:param str subtag: subtag.
:return: list of types. The return list can be empty.
"""
if subtag in index:
types = index[subtag]
return [type for type i... | [
"def",
"types",
"(",
"subtag",
")",
":",
"if",
"subtag",
"in",
"index",
":",
"types",
"=",
"index",
"[",
"subtag",
"]",
"return",
"[",
"type",
"for",
"type",
"in",
"types",
".",
"keys",
"(",
")",
"if",
"type",
"!=",
"'redundant'",
"or",
"type",
"!=... | Get the types of a subtag string (excludes redundant and grandfathered).
:param str subtag: subtag.
:return: list of types. The return list can be empty. | [
"Get",
"the",
"types",
"of",
"a",
"subtag",
"string",
"(",
"excludes",
"redundant",
"and",
"grandfathered",
")",
"."
] | acb91e5458d22617f344e2eefaba9a9865373fdd | https://github.com/OnroerendErfgoed/language-tags/blob/acb91e5458d22617f344e2eefaba9a9865373fdd/language_tags/tags.py#L36-L48 | train | Get the types of a subtag string. |
OnroerendErfgoed/language-tags | language_tags/tags.py | tags.subtags | def subtags(subtags):
"""
Get a list of existing :class:`language_tags.Subtag.Subtag` objects given the input subtag(s).
:param subtags: string subtag or list of string subtags.
:return: a list of existing :class:`language_tags.Subtag.Subtag` objects. The return list can be empty.
... | python | def subtags(subtags):
"""
Get a list of existing :class:`language_tags.Subtag.Subtag` objects given the input subtag(s).
:param subtags: string subtag or list of string subtags.
:return: a list of existing :class:`language_tags.Subtag.Subtag` objects. The return list can be empty.
... | [
"def",
"subtags",
"(",
"subtags",
")",
":",
"result",
"=",
"[",
"]",
"if",
"not",
"isinstance",
"(",
"subtags",
",",
"list",
")",
":",
"subtags",
"=",
"[",
"subtags",
"]",
"for",
"subtag",
"in",
"subtags",
":",
"for",
"type",
"in",
"tags",
".",
"ty... | Get a list of existing :class:`language_tags.Subtag.Subtag` objects given the input subtag(s).
:param subtags: string subtag or list of string subtags.
:return: a list of existing :class:`language_tags.Subtag.Subtag` objects. The return list can be empty. | [
"Get",
"a",
"list",
"of",
"existing",
":",
"class",
":",
"language_tags",
".",
"Subtag",
".",
"Subtag",
"objects",
"given",
"the",
"input",
"subtag",
"(",
"s",
")",
"."
] | acb91e5458d22617f344e2eefaba9a9865373fdd | https://github.com/OnroerendErfgoed/language-tags/blob/acb91e5458d22617f344e2eefaba9a9865373fdd/language_tags/tags.py#L51-L67 | train | Get a list of existing : class:`language_tags. Subtag. Subtag objects given the input subtag ( s. |
OnroerendErfgoed/language-tags | language_tags/tags.py | tags.filter | def filter(subtags):
"""
Get a list of non-existing string subtag(s) given the input string subtag(s).
:param subtags: string subtag or a list of string subtags.
:return: list of non-existing string subtags. The return list can be empty.
"""
if not isinstance(subtags, li... | python | def filter(subtags):
"""
Get a list of non-existing string subtag(s) given the input string subtag(s).
:param subtags: string subtag or a list of string subtags.
:return: list of non-existing string subtags. The return list can be empty.
"""
if not isinstance(subtags, li... | [
"def",
"filter",
"(",
"subtags",
")",
":",
"if",
"not",
"isinstance",
"(",
"subtags",
",",
"list",
")",
":",
"subtags",
"=",
"[",
"subtags",
"]",
"return",
"[",
"subtag",
"for",
"subtag",
"in",
"subtags",
"if",
"len",
"(",
"tags",
".",
"types",
"(",
... | Get a list of non-existing string subtag(s) given the input string subtag(s).
:param subtags: string subtag or a list of string subtags.
:return: list of non-existing string subtags. The return list can be empty. | [
"Get",
"a",
"list",
"of",
"non",
"-",
"existing",
"string",
"subtag",
"(",
"s",
")",
"given",
"the",
"input",
"string",
"subtag",
"(",
"s",
")",
"."
] | acb91e5458d22617f344e2eefaba9a9865373fdd | https://github.com/OnroerendErfgoed/language-tags/blob/acb91e5458d22617f344e2eefaba9a9865373fdd/language_tags/tags.py#L70-L79 | train | Returns a list of non - existing string subtag s given the input string subtag ( s ). |
OnroerendErfgoed/language-tags | language_tags/tags.py | tags.search | def search(description, all=False):
"""
Gets a list of :class:`language_tags.Subtag.Subtag` objects where the description matches.
:param description: a string or compiled regular expression. For example: ``search(re.compile('\d{4}'))`` if the
description of the returned subtag must... | python | def search(description, all=False):
"""
Gets a list of :class:`language_tags.Subtag.Subtag` objects where the description matches.
:param description: a string or compiled regular expression. For example: ``search(re.compile('\d{4}'))`` if the
description of the returned subtag must... | [
"def",
"search",
"(",
"description",
",",
"all",
"=",
"False",
")",
":",
"# If the input query is all lowercase, make a case-insensitive match.",
"if",
"isinstance",
"(",
"description",
",",
"str",
")",
":",
"list_to_string",
"=",
"lambda",
"l",
":",
"', '",
".",
... | Gets a list of :class:`language_tags.Subtag.Subtag` objects where the description matches.
:param description: a string or compiled regular expression. For example: ``search(re.compile('\d{4}'))`` if the
description of the returned subtag must contain four contiguous numerical digits.
:type... | [
"Gets",
"a",
"list",
"of",
":",
"class",
":",
"language_tags",
".",
"Subtag",
".",
"Subtag",
"objects",
"where",
"the",
"description",
"matches",
"."
] | acb91e5458d22617f344e2eefaba9a9865373fdd | https://github.com/OnroerendErfgoed/language-tags/blob/acb91e5458d22617f344e2eefaba9a9865373fdd/language_tags/tags.py#L82-L114 | train | Searches the registry for the given description. |
OnroerendErfgoed/language-tags | language_tags/tags.py | tags.description | def description(tag):
"""
Gets a list of descriptions given the tag.
:param str tag: (hyphen-separated) tag.
:return: list of string descriptions. The return list can be empty.
"""
tag_object = Tag(tag)
results = []
results.extend(tag_object.descriptions)... | python | def description(tag):
"""
Gets a list of descriptions given the tag.
:param str tag: (hyphen-separated) tag.
:return: list of string descriptions. The return list can be empty.
"""
tag_object = Tag(tag)
results = []
results.extend(tag_object.descriptions)... | [
"def",
"description",
"(",
"tag",
")",
":",
"tag_object",
"=",
"Tag",
"(",
"tag",
")",
"results",
"=",
"[",
"]",
"results",
".",
"extend",
"(",
"tag_object",
".",
"descriptions",
")",
"subtags",
"=",
"tag_object",
".",
"subtags",
"for",
"subtag",
"in",
... | Gets a list of descriptions given the tag.
:param str tag: (hyphen-separated) tag.
:return: list of string descriptions. The return list can be empty. | [
"Gets",
"a",
"list",
"of",
"descriptions",
"given",
"the",
"tag",
"."
] | acb91e5458d22617f344e2eefaba9a9865373fdd | https://github.com/OnroerendErfgoed/language-tags/blob/acb91e5458d22617f344e2eefaba9a9865373fdd/language_tags/tags.py#L117-L131 | train | Gets a list of descriptions given the tag. |
OnroerendErfgoed/language-tags | language_tags/tags.py | tags.languages | def languages(macrolanguage):
"""
Get a list of :class:`language_tags.Subtag.Subtag` objects given the string macrolanguage.
:param string macrolanguage: subtag macrolanguage.
:return: a list of the macrolanguage :class:`language_tags.Subtag.Subtag` objects.
:raise Exception: if... | python | def languages(macrolanguage):
"""
Get a list of :class:`language_tags.Subtag.Subtag` objects given the string macrolanguage.
:param string macrolanguage: subtag macrolanguage.
:return: a list of the macrolanguage :class:`language_tags.Subtag.Subtag` objects.
:raise Exception: if... | [
"def",
"languages",
"(",
"macrolanguage",
")",
":",
"results",
"=",
"[",
"]",
"macrolanguage",
"=",
"macrolanguage",
".",
"lower",
"(",
")",
"macrolanguage_data",
"=",
"data",
".",
"get",
"(",
"'macrolanguage'",
")",
"if",
"macrolanguage",
"not",
"in",
"macr... | Get a list of :class:`language_tags.Subtag.Subtag` objects given the string macrolanguage.
:param string macrolanguage: subtag macrolanguage.
:return: a list of the macrolanguage :class:`language_tags.Subtag.Subtag` objects.
:raise Exception: if the macrolanguage does not exists. | [
"Get",
"a",
"list",
"of",
":",
"class",
":",
"language_tags",
".",
"Subtag",
".",
"Subtag",
"objects",
"given",
"the",
"string",
"macrolanguage",
"."
] | acb91e5458d22617f344e2eefaba9a9865373fdd | https://github.com/OnroerendErfgoed/language-tags/blob/acb91e5458d22617f344e2eefaba9a9865373fdd/language_tags/tags.py#L134-L154 | train | Get a list of the subtag objects given the string macrolanguage. |
OnroerendErfgoed/language-tags | language_tags/tags.py | tags.type | def type(subtag, type):
"""
Get a :class:`language_tags.Subtag.Subtag` by subtag and type. Can be None if not exists.
:param str subtag: subtag.
:param str type: type of the subtag.
:return: :class:`language_tags.Subtag.Subtag` if exists, otherwise None.
"""
subt... | python | def type(subtag, type):
"""
Get a :class:`language_tags.Subtag.Subtag` by subtag and type. Can be None if not exists.
:param str subtag: subtag.
:param str type: type of the subtag.
:return: :class:`language_tags.Subtag.Subtag` if exists, otherwise None.
"""
subt... | [
"def",
"type",
"(",
"subtag",
",",
"type",
")",
":",
"subtag",
"=",
"subtag",
".",
"lower",
"(",
")",
"if",
"subtag",
"in",
"index",
":",
"types",
"=",
"index",
"[",
"subtag",
"]",
"if",
"type",
"in",
"types",
":",
"return",
"Subtag",
"(",
"subtag"... | Get a :class:`language_tags.Subtag.Subtag` by subtag and type. Can be None if not exists.
:param str subtag: subtag.
:param str type: type of the subtag.
:return: :class:`language_tags.Subtag.Subtag` if exists, otherwise None. | [
"Get",
"a",
":",
"class",
":",
"language_tags",
".",
"Subtag",
".",
"Subtag",
"by",
"subtag",
"and",
"type",
".",
"Can",
"be",
"None",
"if",
"not",
"exists",
"."
] | acb91e5458d22617f344e2eefaba9a9865373fdd | https://github.com/OnroerendErfgoed/language-tags/blob/acb91e5458d22617f344e2eefaba9a9865373fdd/language_tags/tags.py#L157-L170 | train | Get a : class : language_tags. Subtag. Subtag by subtag and type. Can be None. |
bfarr/kombine | examples/twoD.py | Posterior.prior_draw | def prior_draw(self, N=1):
"""
Draw ``N`` samples from the prior.
"""
p = np.random.ranf(size=(N, self.ndim))
p = (self._upper_right - self._lower_left) * p + self._lower_left
return p | python | def prior_draw(self, N=1):
"""
Draw ``N`` samples from the prior.
"""
p = np.random.ranf(size=(N, self.ndim))
p = (self._upper_right - self._lower_left) * p + self._lower_left
return p | [
"def",
"prior_draw",
"(",
"self",
",",
"N",
"=",
"1",
")",
":",
"p",
"=",
"np",
".",
"random",
".",
"ranf",
"(",
"size",
"=",
"(",
"N",
",",
"self",
".",
"ndim",
")",
")",
"p",
"=",
"(",
"self",
".",
"_upper_right",
"-",
"self",
".",
"_lower_... | Draw ``N`` samples from the prior. | [
"Draw",
"N",
"samples",
"from",
"the",
"prior",
"."
] | 50c946dee5da33e7baab71d9bd6c265ff02ffb13 | https://github.com/bfarr/kombine/blob/50c946dee5da33e7baab71d9bd6c265ff02ffb13/examples/twoD.py#L49-L55 | train | Draw N samples from the prior. |
bfarr/kombine | examples/twoD.py | Posterior.lnprior | def lnprior(self, X):
"""
Use a uniform, bounded prior.
"""
if np.any(X < self._lower_left) or np.any(X > self._upper_right):
return -np.inf
else:
return 0.0 | python | def lnprior(self, X):
"""
Use a uniform, bounded prior.
"""
if np.any(X < self._lower_left) or np.any(X > self._upper_right):
return -np.inf
else:
return 0.0 | [
"def",
"lnprior",
"(",
"self",
",",
"X",
")",
":",
"if",
"np",
".",
"any",
"(",
"X",
"<",
"self",
".",
"_lower_left",
")",
"or",
"np",
".",
"any",
"(",
"X",
">",
"self",
".",
"_upper_right",
")",
":",
"return",
"-",
"np",
".",
"inf",
"else",
... | Use a uniform, bounded prior. | [
"Use",
"a",
"uniform",
"bounded",
"prior",
"."
] | 50c946dee5da33e7baab71d9bd6c265ff02ffb13 | https://github.com/bfarr/kombine/blob/50c946dee5da33e7baab71d9bd6c265ff02ffb13/examples/twoD.py#L57-L64 | train | Use a uniform bounded prior. |
bfarr/kombine | examples/twoD.py | Posterior.lnlike | def lnlike(self, X):
"""
Use a softened version of the interpolant as a likelihood.
"""
return -3.5*np.log(self._interpolant(X[0], X[1], grid=False)) | python | def lnlike(self, X):
"""
Use a softened version of the interpolant as a likelihood.
"""
return -3.5*np.log(self._interpolant(X[0], X[1], grid=False)) | [
"def",
"lnlike",
"(",
"self",
",",
"X",
")",
":",
"return",
"-",
"3.5",
"*",
"np",
".",
"log",
"(",
"self",
".",
"_interpolant",
"(",
"X",
"[",
"0",
"]",
",",
"X",
"[",
"1",
"]",
",",
"grid",
"=",
"False",
")",
")"
] | Use a softened version of the interpolant as a likelihood. | [
"Use",
"a",
"softened",
"version",
"of",
"the",
"interpolant",
"as",
"a",
"likelihood",
"."
] | 50c946dee5da33e7baab71d9bd6c265ff02ffb13 | https://github.com/bfarr/kombine/blob/50c946dee5da33e7baab71d9bd6c265ff02ffb13/examples/twoD.py#L66-L70 | train | Calculate the log likelihood of the log likelihood of the given data. |
kstaniek/condoor | condoor/__main__.py | echo_info | def echo_info(conn):
"""Print detected information."""
click.echo("General information:")
click.echo(" Hostname: {}".format(conn.hostname))
click.echo(" HW Family: {}".format(conn.family))
click.echo(" HW Platform: {}".format(conn.platform))
click.echo(" SW Type: {}".format(conn.os_type))
cl... | python | def echo_info(conn):
"""Print detected information."""
click.echo("General information:")
click.echo(" Hostname: {}".format(conn.hostname))
click.echo(" HW Family: {}".format(conn.family))
click.echo(" HW Platform: {}".format(conn.platform))
click.echo(" SW Type: {}".format(conn.os_type))
cl... | [
"def",
"echo_info",
"(",
"conn",
")",
":",
"click",
".",
"echo",
"(",
"\"General information:\"",
")",
"click",
".",
"echo",
"(",
"\" Hostname: {}\"",
".",
"format",
"(",
"conn",
".",
"hostname",
")",
")",
"click",
".",
"echo",
"(",
"\" HW Family: {}\"",
"... | Print detected information. | [
"Print",
"detected",
"information",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/__main__.py#L16-L32 | train | Print detected information. |
kstaniek/condoor | condoor/__main__.py | run | def run(url, cmd, log_path, log_level, log_session, force_discovery, print_info):
"""Run the main function."""
log_level = log_levels[log_level]
conn = condoor.Connection("host", list(url), log_session=log_session, log_level=log_level, log_dir=log_path)
try:
conn.connect(force_discovery=force_di... | python | def run(url, cmd, log_path, log_level, log_session, force_discovery, print_info):
"""Run the main function."""
log_level = log_levels[log_level]
conn = condoor.Connection("host", list(url), log_session=log_session, log_level=log_level, log_dir=log_path)
try:
conn.connect(force_discovery=force_di... | [
"def",
"run",
"(",
"url",
",",
"cmd",
",",
"log_path",
",",
"log_level",
",",
"log_session",
",",
"force_discovery",
",",
"print_info",
")",
":",
"log_level",
"=",
"log_levels",
"[",
"log_level",
"]",
"conn",
"=",
"condoor",
".",
"Connection",
"(",
"\"host... | Run the main function. | [
"Run",
"the",
"main",
"function",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/__main__.py#L77-L96 | train | Run the main function. |
kstaniek/condoor | condoor/__main__.py | URL.convert | def convert(self, value, param, ctx):
"""Convert to URL scheme."""
if not isinstance(value, tuple):
parsed = urlparse.urlparse(value)
if parsed.scheme not in ('telnet', 'ssh'):
self.fail('invalid URL scheme (%s). Only telnet and ssh URLs are '
... | python | def convert(self, value, param, ctx):
"""Convert to URL scheme."""
if not isinstance(value, tuple):
parsed = urlparse.urlparse(value)
if parsed.scheme not in ('telnet', 'ssh'):
self.fail('invalid URL scheme (%s). Only telnet and ssh URLs are '
... | [
"def",
"convert",
"(",
"self",
",",
"value",
",",
"param",
",",
"ctx",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"tuple",
")",
":",
"parsed",
"=",
"urlparse",
".",
"urlparse",
"(",
"value",
")",
"if",
"parsed",
".",
"scheme",
"not",
"... | Convert to URL scheme. | [
"Convert",
"to",
"URL",
"scheme",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/__main__.py#L40-L47 | train | Convert to URL scheme. |
kstaniek/condoor | condoor/actions.py | a_send_line | def a_send_line(text, ctx):
"""Send text line to the controller followed by `os.linesep`."""
if hasattr(text, '__iter__'):
try:
ctx.ctrl.sendline(text.next())
except StopIteration:
ctx.finished = True
else:
ctx.ctrl.sendline(text)
return True | python | def a_send_line(text, ctx):
"""Send text line to the controller followed by `os.linesep`."""
if hasattr(text, '__iter__'):
try:
ctx.ctrl.sendline(text.next())
except StopIteration:
ctx.finished = True
else:
ctx.ctrl.sendline(text)
return True | [
"def",
"a_send_line",
"(",
"text",
",",
"ctx",
")",
":",
"if",
"hasattr",
"(",
"text",
",",
"'__iter__'",
")",
":",
"try",
":",
"ctx",
".",
"ctrl",
".",
"sendline",
"(",
"text",
".",
"next",
"(",
")",
")",
"except",
"StopIteration",
":",
"ctx",
"."... | Send text line to the controller followed by `os.linesep`. | [
"Send",
"text",
"line",
"to",
"the",
"controller",
"followed",
"by",
"os",
".",
"linesep",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/actions.py#L9-L18 | train | Send text line to the controller followed by os. linesep. |
kstaniek/condoor | condoor/actions.py | a_send_username | def a_send_username(username, ctx):
"""Sent the username text."""
if username:
ctx.ctrl.sendline(username)
return True
else:
ctx.ctrl.disconnect()
raise ConnectionAuthenticationError("Username not provided", ctx.ctrl.hostname) | python | def a_send_username(username, ctx):
"""Sent the username text."""
if username:
ctx.ctrl.sendline(username)
return True
else:
ctx.ctrl.disconnect()
raise ConnectionAuthenticationError("Username not provided", ctx.ctrl.hostname) | [
"def",
"a_send_username",
"(",
"username",
",",
"ctx",
")",
":",
"if",
"username",
":",
"ctx",
".",
"ctrl",
".",
"sendline",
"(",
"username",
")",
"return",
"True",
"else",
":",
"ctx",
".",
"ctrl",
".",
"disconnect",
"(",
")",
"raise",
"ConnectionAuthent... | Sent the username text. | [
"Sent",
"the",
"username",
"text",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/actions.py#L29-L36 | train | Send the username text. |
kstaniek/condoor | condoor/actions.py | a_send_password | def a_send_password(password, ctx):
"""Send the password text.
Before sending the password local echo is disabled.
If password not provided it disconnects from the device and raises ConnectionAuthenticationError exception.
"""
if password:
ctx.ctrl.send_command(password, password=True)
... | python | def a_send_password(password, ctx):
"""Send the password text.
Before sending the password local echo is disabled.
If password not provided it disconnects from the device and raises ConnectionAuthenticationError exception.
"""
if password:
ctx.ctrl.send_command(password, password=True)
... | [
"def",
"a_send_password",
"(",
"password",
",",
"ctx",
")",
":",
"if",
"password",
":",
"ctx",
".",
"ctrl",
".",
"send_command",
"(",
"password",
",",
"password",
"=",
"True",
")",
"return",
"True",
"else",
":",
"ctx",
".",
"ctrl",
".",
"disconnect",
"... | Send the password text.
Before sending the password local echo is disabled.
If password not provided it disconnects from the device and raises ConnectionAuthenticationError exception. | [
"Send",
"the",
"password",
"text",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/actions.py#L40-L51 | train | Send the password text to the local echo is disabled. |
kstaniek/condoor | condoor/actions.py | a_unable_to_connect | def a_unable_to_connect(ctx):
"""Provide detailed information about the session (before, after) when unable to connect.
The state machine finishes without exception
"""
message = "{}{}".format(ctx.ctrl.before, ctx.ctrl.after)
ctx.msg = message.strip().splitlines()[-1]
ctx.device.last_error_msg ... | python | def a_unable_to_connect(ctx):
"""Provide detailed information about the session (before, after) when unable to connect.
The state machine finishes without exception
"""
message = "{}{}".format(ctx.ctrl.before, ctx.ctrl.after)
ctx.msg = message.strip().splitlines()[-1]
ctx.device.last_error_msg ... | [
"def",
"a_unable_to_connect",
"(",
"ctx",
")",
":",
"message",
"=",
"\"{}{}\"",
".",
"format",
"(",
"ctx",
".",
"ctrl",
".",
"before",
",",
"ctx",
".",
"ctrl",
".",
"after",
")",
"ctx",
".",
"msg",
"=",
"message",
".",
"strip",
"(",
")",
".",
"spli... | Provide detailed information about the session (before, after) when unable to connect.
The state machine finishes without exception | [
"Provide",
"detailed",
"information",
"about",
"the",
"session",
"(",
"before",
"after",
")",
"when",
"unable",
"to",
"connect",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/actions.py#L69-L78 | train | Provide detailed information about the session before and after when unable to connect. |
kstaniek/condoor | condoor/actions.py | a_standby_console | def a_standby_console(ctx):
"""Raise ConnectionError exception when connected to standby console."""
ctx.device.is_console = True
ctx.ctrl.disconnect()
raise ConnectionError("Standby console", ctx.ctrl.hostname) | python | def a_standby_console(ctx):
"""Raise ConnectionError exception when connected to standby console."""
ctx.device.is_console = True
ctx.ctrl.disconnect()
raise ConnectionError("Standby console", ctx.ctrl.hostname) | [
"def",
"a_standby_console",
"(",
"ctx",
")",
":",
"ctx",
".",
"device",
".",
"is_console",
"=",
"True",
"ctx",
".",
"ctrl",
".",
"disconnect",
"(",
")",
"raise",
"ConnectionError",
"(",
"\"Standby console\"",
",",
"ctx",
".",
"ctrl",
".",
"hostname",
")"
] | Raise ConnectionError exception when connected to standby console. | [
"Raise",
"ConnectionError",
"exception",
"when",
"connected",
"to",
"standby",
"console",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/actions.py#L82-L86 | train | Raise ConnectionError exception when connected to standby console. |
kstaniek/condoor | condoor/actions.py | a_not_committed | def a_not_committed(ctx):
"""Provide the message that current software is not committed and reload is not possible."""
ctx.ctrl.sendline('n')
ctx.msg = "Some active software packages are not yet committed. Reload may cause software rollback."
ctx.device.chain.connection.emit_message(ctx.msg, log_level=l... | python | def a_not_committed(ctx):
"""Provide the message that current software is not committed and reload is not possible."""
ctx.ctrl.sendline('n')
ctx.msg = "Some active software packages are not yet committed. Reload may cause software rollback."
ctx.device.chain.connection.emit_message(ctx.msg, log_level=l... | [
"def",
"a_not_committed",
"(",
"ctx",
")",
":",
"ctx",
".",
"ctrl",
".",
"sendline",
"(",
"'n'",
")",
"ctx",
".",
"msg",
"=",
"\"Some active software packages are not yet committed. Reload may cause software rollback.\"",
"ctx",
".",
"device",
".",
"chain",
".",
"co... | Provide the message that current software is not committed and reload is not possible. | [
"Provide",
"the",
"message",
"that",
"current",
"software",
"is",
"not",
"committed",
"and",
"reload",
"is",
"not",
"possible",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/actions.py#L107-L113 | train | Provide the message that current software is not yet committed. Reload is not possible. |
kstaniek/condoor | condoor/actions.py | a_stays_connected | def a_stays_connected(ctx):
"""Stay connected."""
ctx.ctrl.connected = True
ctx.device.connected = False
return True | python | def a_stays_connected(ctx):
"""Stay connected."""
ctx.ctrl.connected = True
ctx.device.connected = False
return True | [
"def",
"a_stays_connected",
"(",
"ctx",
")",
":",
"ctx",
".",
"ctrl",
".",
"connected",
"=",
"True",
"ctx",
".",
"device",
".",
"connected",
"=",
"False",
"return",
"True"
] | Stay connected. | [
"Stay",
"connected",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/actions.py#L126-L130 | train | Stays connected. |
kstaniek/condoor | condoor/actions.py | a_unexpected_prompt | def a_unexpected_prompt(ctx):
"""Provide message when received humphost prompt."""
prompt = ctx.ctrl.match.group(0)
ctx.msg = "Received the jump host prompt: '{}'".format(prompt)
ctx.device.connected = False
ctx.finished = True
raise ConnectionError("Unable to connect to the device.", ctx.ctrl.h... | python | def a_unexpected_prompt(ctx):
"""Provide message when received humphost prompt."""
prompt = ctx.ctrl.match.group(0)
ctx.msg = "Received the jump host prompt: '{}'".format(prompt)
ctx.device.connected = False
ctx.finished = True
raise ConnectionError("Unable to connect to the device.", ctx.ctrl.h... | [
"def",
"a_unexpected_prompt",
"(",
"ctx",
")",
":",
"prompt",
"=",
"ctx",
".",
"ctrl",
".",
"match",
".",
"group",
"(",
"0",
")",
"ctx",
".",
"msg",
"=",
"\"Received the jump host prompt: '{}'\"",
".",
"format",
"(",
"prompt",
")",
"ctx",
".",
"device",
... | Provide message when received humphost prompt. | [
"Provide",
"message",
"when",
"received",
"humphost",
"prompt",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/actions.py#L134-L140 | train | Provide message when received humphost prompt. |
kstaniek/condoor | condoor/actions.py | a_connection_timeout | def a_connection_timeout(ctx):
"""Check the prompt and update the drivers."""
prompt = ctx.ctrl.after
ctx.msg = "Received the jump host prompt: '{}'".format(prompt)
ctx.device.connected = False
ctx.finished = True
raise ConnectionTimeoutError("Unable to connect to the device.", ctx.ctrl.hostname... | python | def a_connection_timeout(ctx):
"""Check the prompt and update the drivers."""
prompt = ctx.ctrl.after
ctx.msg = "Received the jump host prompt: '{}'".format(prompt)
ctx.device.connected = False
ctx.finished = True
raise ConnectionTimeoutError("Unable to connect to the device.", ctx.ctrl.hostname... | [
"def",
"a_connection_timeout",
"(",
"ctx",
")",
":",
"prompt",
"=",
"ctx",
".",
"ctrl",
".",
"after",
"ctx",
".",
"msg",
"=",
"\"Received the jump host prompt: '{}'\"",
".",
"format",
"(",
"prompt",
")",
"ctx",
".",
"device",
".",
"connected",
"=",
"False",
... | Check the prompt and update the drivers. | [
"Check",
"the",
"prompt",
"and",
"update",
"the",
"drivers",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/actions.py#L144-L150 | train | Check the prompt and update the drivers. |
kstaniek/condoor | condoor/actions.py | a_expected_prompt | def a_expected_prompt(ctx):
"""Update driver, config mode and hostname when received an expected prompt."""
prompt = ctx.ctrl.match.group(0)
ctx.device.update_driver(prompt)
ctx.device.update_config_mode()
ctx.device.update_hostname()
ctx.finished = True
return True | python | def a_expected_prompt(ctx):
"""Update driver, config mode and hostname when received an expected prompt."""
prompt = ctx.ctrl.match.group(0)
ctx.device.update_driver(prompt)
ctx.device.update_config_mode()
ctx.device.update_hostname()
ctx.finished = True
return True | [
"def",
"a_expected_prompt",
"(",
"ctx",
")",
":",
"prompt",
"=",
"ctx",
".",
"ctrl",
".",
"match",
".",
"group",
"(",
"0",
")",
"ctx",
".",
"device",
".",
"update_driver",
"(",
"prompt",
")",
"ctx",
".",
"device",
".",
"update_config_mode",
"(",
")",
... | Update driver, config mode and hostname when received an expected prompt. | [
"Update",
"driver",
"config",
"mode",
"and",
"hostname",
"when",
"received",
"an",
"expected",
"prompt",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/actions.py#L154-L161 | train | Update driver config mode and hostname when received an expected prompt. |
kstaniek/condoor | condoor/actions.py | a_return_and_reconnect | def a_return_and_reconnect(ctx):
"""Send new line and reconnect."""
ctx.ctrl.send("\r")
ctx.device.connect(ctx.ctrl)
return True | python | def a_return_and_reconnect(ctx):
"""Send new line and reconnect."""
ctx.ctrl.send("\r")
ctx.device.connect(ctx.ctrl)
return True | [
"def",
"a_return_and_reconnect",
"(",
"ctx",
")",
":",
"ctx",
".",
"ctrl",
".",
"send",
"(",
"\"\\r\"",
")",
"ctx",
".",
"device",
".",
"connect",
"(",
"ctx",
".",
"ctrl",
")",
"return",
"True"
] | Send new line and reconnect. | [
"Send",
"new",
"line",
"and",
"reconnect",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/actions.py#L186-L190 | train | Send new line and reconnect. |
kstaniek/condoor | condoor/actions.py | a_store_cmd_result | def a_store_cmd_result(ctx):
"""Store the command result for complex state machines.
It is useful when exact command output is embedded in another commands, i.e. admin show inventory in eXR.
"""
result = ctx.ctrl.before
# check if multi line
index = result.find('\n')
if index > 0:
#... | python | def a_store_cmd_result(ctx):
"""Store the command result for complex state machines.
It is useful when exact command output is embedded in another commands, i.e. admin show inventory in eXR.
"""
result = ctx.ctrl.before
# check if multi line
index = result.find('\n')
if index > 0:
#... | [
"def",
"a_store_cmd_result",
"(",
"ctx",
")",
":",
"result",
"=",
"ctx",
".",
"ctrl",
".",
"before",
"# check if multi line",
"index",
"=",
"result",
".",
"find",
"(",
"'\\n'",
")",
"if",
"index",
">",
"0",
":",
"# remove first line",
"result",
"=",
"resul... | Store the command result for complex state machines.
It is useful when exact command output is embedded in another commands, i.e. admin show inventory in eXR. | [
"Store",
"the",
"command",
"result",
"for",
"complex",
"state",
"machines",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/actions.py#L194-L206 | train | Store the command result for complex state machines. |
kstaniek/condoor | condoor/actions.py | a_message_callback | def a_message_callback(ctx):
"""Message the captured pattern."""
message = ctx.ctrl.after.strip().splitlines()[-1]
ctx.device.chain.connection.emit_message(message, log_level=logging.INFO)
return True | python | def a_message_callback(ctx):
"""Message the captured pattern."""
message = ctx.ctrl.after.strip().splitlines()[-1]
ctx.device.chain.connection.emit_message(message, log_level=logging.INFO)
return True | [
"def",
"a_message_callback",
"(",
"ctx",
")",
":",
"message",
"=",
"ctx",
".",
"ctrl",
".",
"after",
".",
"strip",
"(",
")",
".",
"splitlines",
"(",
")",
"[",
"-",
"1",
"]",
"ctx",
".",
"device",
".",
"chain",
".",
"connection",
".",
"emit_message",
... | Message the captured pattern. | [
"Message",
"the",
"captured",
"pattern",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/actions.py#L210-L214 | train | Message the captured pattern. |
kstaniek/condoor | condoor/actions.py | a_capture_show_configuration_failed | def a_capture_show_configuration_failed(ctx):
"""Capture the show configuration failed result."""
result = ctx.device.send("show configuration failed")
ctx.device.last_command_result = result
index = result.find("SEMANTIC ERRORS")
ctx.device.chain.connection.emit_message(result, log_level=logging.ER... | python | def a_capture_show_configuration_failed(ctx):
"""Capture the show configuration failed result."""
result = ctx.device.send("show configuration failed")
ctx.device.last_command_result = result
index = result.find("SEMANTIC ERRORS")
ctx.device.chain.connection.emit_message(result, log_level=logging.ER... | [
"def",
"a_capture_show_configuration_failed",
"(",
"ctx",
")",
":",
"result",
"=",
"ctx",
".",
"device",
".",
"send",
"(",
"\"show configuration failed\"",
")",
"ctx",
".",
"device",
".",
"last_command_result",
"=",
"result",
"index",
"=",
"result",
".",
"find",... | Capture the show configuration failed result. | [
"Capture",
"the",
"show",
"configuration",
"failed",
"result",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/actions.py#L218-L227 | train | Capture the show configuration failed result. |
kstaniek/condoor | condoor/actions.py | a_configuration_inconsistency | def a_configuration_inconsistency(ctx):
"""Raise the configuration inconsistency error."""
ctx.msg = "This SDR's running configuration is inconsistent with persistent configuration. " \
"No configuration commits for this SDR will be allowed until a 'clear configuration inconsistency' " \
... | python | def a_configuration_inconsistency(ctx):
"""Raise the configuration inconsistency error."""
ctx.msg = "This SDR's running configuration is inconsistent with persistent configuration. " \
"No configuration commits for this SDR will be allowed until a 'clear configuration inconsistency' " \
... | [
"def",
"a_configuration_inconsistency",
"(",
"ctx",
")",
":",
"ctx",
".",
"msg",
"=",
"\"This SDR's running configuration is inconsistent with persistent configuration. \"",
"\"No configuration commits for this SDR will be allowed until a 'clear configuration inconsistency' \"",
"\"command i... | Raise the configuration inconsistency error. | [
"Raise",
"the",
"configuration",
"inconsistency",
"error",
"."
] | 77c054b29d4e286c1d7aca2c74dff86b805e1fae | https://github.com/kstaniek/condoor/blob/77c054b29d4e286c1d7aca2c74dff86b805e1fae/condoor/actions.py#L231-L239 | train | Raise the configuration inconsistency error. |
FulcrumTechnologies/pyconfluence | pyconfluence/actions.py | get_page_content | def get_page_content(id):
"""Return XHTML content of a page.
Parameters:
- id: id of a Confluence page.
"""
data = _json.loads(_api.rest("/" + str(id) + "?expand=body.storage"))
return data["body"]["storage"]["value"] | python | def get_page_content(id):
"""Return XHTML content of a page.
Parameters:
- id: id of a Confluence page.
"""
data = _json.loads(_api.rest("/" + str(id) + "?expand=body.storage"))
return data["body"]["storage"]["value"] | [
"def",
"get_page_content",
"(",
"id",
")",
":",
"data",
"=",
"_json",
".",
"loads",
"(",
"_api",
".",
"rest",
"(",
"\"/\"",
"+",
"str",
"(",
"id",
")",
"+",
"\"?expand=body.storage\"",
")",
")",
"return",
"data",
"[",
"\"body\"",
"]",
"[",
"\"storage\"... | Return XHTML content of a page.
Parameters:
- id: id of a Confluence page. | [
"Return",
"XHTML",
"content",
"of",
"a",
"page",
".",
"Parameters",
":",
"-",
"id",
":",
"id",
"of",
"a",
"Confluence",
"page",
"."
] | a999726dbc1cbdd3d9062234698eeae799ce84ce | https://github.com/FulcrumTechnologies/pyconfluence/blob/a999726dbc1cbdd3d9062234698eeae799ce84ce/pyconfluence/actions.py#L133-L139 | train | Get XHTML content of a Confluence page. |
FulcrumTechnologies/pyconfluence | pyconfluence/actions.py | get_page_name | def get_page_name(id):
"""Return name of a page based on passed page id.
Parameters:
- id: id of a Confluence page.
"""
data = _json.loads(_api.rest("/" + str(id) + "?expand=body.storage"))
return data["title"] | python | def get_page_name(id):
"""Return name of a page based on passed page id.
Parameters:
- id: id of a Confluence page.
"""
data = _json.loads(_api.rest("/" + str(id) + "?expand=body.storage"))
return data["title"] | [
"def",
"get_page_name",
"(",
"id",
")",
":",
"data",
"=",
"_json",
".",
"loads",
"(",
"_api",
".",
"rest",
"(",
"\"/\"",
"+",
"str",
"(",
"id",
")",
"+",
"\"?expand=body.storage\"",
")",
")",
"return",
"data",
"[",
"\"title\"",
"]"
] | Return name of a page based on passed page id.
Parameters:
- id: id of a Confluence page. | [
"Return",
"name",
"of",
"a",
"page",
"based",
"on",
"passed",
"page",
"id",
".",
"Parameters",
":",
"-",
"id",
":",
"id",
"of",
"a",
"Confluence",
"page",
"."
] | a999726dbc1cbdd3d9062234698eeae799ce84ce | https://github.com/FulcrumTechnologies/pyconfluence/blob/a999726dbc1cbdd3d9062234698eeae799ce84ce/pyconfluence/actions.py#L142-L148 | train | Get the name of a page based on passed page id. |
FulcrumTechnologies/pyconfluence | pyconfluence/actions.py | get_page_id | def get_page_id(name, space):
"""Return id of a page based on passed page name and space.
Parameters:
- name: name of a Confluence page.
- space: space the Confluence page is in.
"""
data = _json.loads(_api.rest("?title=" + name.replace(" ", "%20") + "&"
"spaceKey=" + spac... | python | def get_page_id(name, space):
"""Return id of a page based on passed page name and space.
Parameters:
- name: name of a Confluence page.
- space: space the Confluence page is in.
"""
data = _json.loads(_api.rest("?title=" + name.replace(" ", "%20") + "&"
"spaceKey=" + spac... | [
"def",
"get_page_id",
"(",
"name",
",",
"space",
")",
":",
"data",
"=",
"_json",
".",
"loads",
"(",
"_api",
".",
"rest",
"(",
"\"?title=\"",
"+",
"name",
".",
"replace",
"(",
"\" \"",
",",
"\"%20\"",
")",
"+",
"\"&\"",
"\"spaceKey=\"",
"+",
"space",
... | Return id of a page based on passed page name and space.
Parameters:
- name: name of a Confluence page.
- space: space the Confluence page is in. | [
"Return",
"id",
"of",
"a",
"page",
"based",
"on",
"passed",
"page",
"name",
"and",
"space",
".",
"Parameters",
":",
"-",
"name",
":",
"name",
"of",
"a",
"Confluence",
"page",
".",
"-",
"space",
":",
"space",
"the",
"Confluence",
"page",
"is",
"in",
"... | a999726dbc1cbdd3d9062234698eeae799ce84ce | https://github.com/FulcrumTechnologies/pyconfluence/blob/a999726dbc1cbdd3d9062234698eeae799ce84ce/pyconfluence/actions.py#L151-L162 | train | Get the id of a Confluence page based on passed page name and space. |
FulcrumTechnologies/pyconfluence | pyconfluence/actions.py | create_page | def create_page(name, parent_id, space, content):
"""Create a page in Confluence.
Parameters:
- name: name of the Confluence page to create.
- parent_id: ID of the intended parent of the page.
- space: key of the space where the page will be created.
- content: XHTML content to be written to the... | python | def create_page(name, parent_id, space, content):
"""Create a page in Confluence.
Parameters:
- name: name of the Confluence page to create.
- parent_id: ID of the intended parent of the page.
- space: key of the space where the page will be created.
- content: XHTML content to be written to the... | [
"def",
"create_page",
"(",
"name",
",",
"parent_id",
",",
"space",
",",
"content",
")",
":",
"data",
"=",
"{",
"}",
"data",
"[",
"\"type\"",
"]",
"=",
"\"page\"",
"data",
"[",
"\"title\"",
"]",
"=",
"name",
"data",
"[",
"\"ancestors\"",
"]",
"=",
"["... | Create a page in Confluence.
Parameters:
- name: name of the Confluence page to create.
- parent_id: ID of the intended parent of the page.
- space: key of the space where the page will be created.
- content: XHTML content to be written to the page.
Notes: the page id can be obtained by getting ... | [
"Create",
"a",
"page",
"in",
"Confluence",
".",
"Parameters",
":",
"-",
"name",
":",
"name",
"of",
"the",
"Confluence",
"page",
"to",
"create",
".",
"-",
"parent_id",
":",
"ID",
"of",
"the",
"intended",
"parent",
"of",
"the",
"page",
".",
"-",
"space",... | a999726dbc1cbdd3d9062234698eeae799ce84ce | https://github.com/FulcrumTechnologies/pyconfluence/blob/a999726dbc1cbdd3d9062234698eeae799ce84ce/pyconfluence/actions.py#L229-L244 | train | Create a Confluence page in the Confluence. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.