repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
vburenin/xjpath | xjpath/xjpath.py | split | def split(inp_str, sep_char, maxsplit=-1, escape_char='\\'):
"""Separates a string on a character, taking into account escapes.
:param str inp_str: string to split.
:param str sep_char: separator character.
:param int maxsplit: maximum number of times to split from left.
:param str escape_char: esc... | python | def split(inp_str, sep_char, maxsplit=-1, escape_char='\\'):
"""Separates a string on a character, taking into account escapes.
:param str inp_str: string to split.
:param str sep_char: separator character.
:param int maxsplit: maximum number of times to split from left.
:param str escape_char: esc... | [
"def",
"split",
"(",
"inp_str",
",",
"sep_char",
",",
"maxsplit",
"=",
"-",
"1",
",",
"escape_char",
"=",
"'\\\\'",
")",
":",
"word_chars",
"=",
"[",
"]",
"word_chars_append",
"=",
"word_chars",
".",
"append",
"inp_str_iter",
"=",
"iter",
"(",
"inp_str",
... | Separates a string on a character, taking into account escapes.
:param str inp_str: string to split.
:param str sep_char: separator character.
:param int maxsplit: maximum number of times to split from left.
:param str escape_char: escape character.
:rtype: __generator[str]
:return: sub-strings... | [
"Separates",
"a",
"string",
"on",
"a",
"character",
"taking",
"into",
"account",
"escapes",
"."
] | train | https://github.com/vburenin/xjpath/blob/98a19fd6e6d0bcdc5ecbd3651ffa8915f06d7d44/xjpath/xjpath.py#L118-L155 |
vburenin/xjpath | xjpath/xjpath.py | _full_sub_array | def _full_sub_array(data_obj, xj_path, create_dict_path):
"""Retrieves all array or dictionary elements for '*' JSON path marker.
:param dict|list data_obj: The current data object.
:param str xj_path: A json path.
:param bool create_dict_path create a dict path.
:return: tuple with two values: fir... | python | def _full_sub_array(data_obj, xj_path, create_dict_path):
"""Retrieves all array or dictionary elements for '*' JSON path marker.
:param dict|list data_obj: The current data object.
:param str xj_path: A json path.
:param bool create_dict_path create a dict path.
:return: tuple with two values: fir... | [
"def",
"_full_sub_array",
"(",
"data_obj",
",",
"xj_path",
",",
"create_dict_path",
")",
":",
"if",
"isinstance",
"(",
"data_obj",
",",
"list",
")",
":",
"if",
"xj_path",
":",
"res",
"=",
"[",
"]",
"for",
"d",
"in",
"data_obj",
":",
"val",
",",
"exists... | Retrieves all array or dictionary elements for '*' JSON path marker.
:param dict|list data_obj: The current data object.
:param str xj_path: A json path.
:param bool create_dict_path create a dict path.
:return: tuple with two values: first is a result and second
a boolean flag telling if ... | [
"Retrieves",
"all",
"array",
"or",
"dictionary",
"elements",
"for",
"*",
"JSON",
"path",
"marker",
"."
] | train | https://github.com/vburenin/xjpath/blob/98a19fd6e6d0bcdc5ecbd3651ffa8915f06d7d44/xjpath/xjpath.py#L158-L189 |
vburenin/xjpath | xjpath/xjpath.py | _get_array_index | def _get_array_index(array_path):
"""Translates @first @last @1 @-1 expressions into an actual array index.
:param str array_path: Array path in XJ notation.
:rtype: int
:return: Array index.
"""
if not array_path.startswith('@'):
raise XJPathError('Array index must start from @ symbol... | python | def _get_array_index(array_path):
"""Translates @first @last @1 @-1 expressions into an actual array index.
:param str array_path: Array path in XJ notation.
:rtype: int
:return: Array index.
"""
if not array_path.startswith('@'):
raise XJPathError('Array index must start from @ symbol... | [
"def",
"_get_array_index",
"(",
"array_path",
")",
":",
"if",
"not",
"array_path",
".",
"startswith",
"(",
"'@'",
")",
":",
"raise",
"XJPathError",
"(",
"'Array index must start from @ symbol.'",
")",
"array_path",
"=",
"array_path",
"[",
"1",
":",
"]",
"if",
... | Translates @first @last @1 @-1 expressions into an actual array index.
:param str array_path: Array path in XJ notation.
:rtype: int
:return: Array index. | [
"Translates",
"@first",
"@last",
"@1",
"@",
"-",
"1",
"expressions",
"into",
"an",
"actual",
"array",
"index",
"."
] | train | https://github.com/vburenin/xjpath/blob/98a19fd6e6d0bcdc5ecbd3651ffa8915f06d7d44/xjpath/xjpath.py#L192-L211 |
vburenin/xjpath | xjpath/xjpath.py | _single_array_element | def _single_array_element(data_obj, xj_path, array_path, create_dict_path):
"""Retrieves a single array for a '@' JSON path marker.
:param list data_obj: The current data object.
:param str xj_path: A json path.
:param str array_path: A lookup key.
:param bool create_dict_path create a dict path.
... | python | def _single_array_element(data_obj, xj_path, array_path, create_dict_path):
"""Retrieves a single array for a '@' JSON path marker.
:param list data_obj: The current data object.
:param str xj_path: A json path.
:param str array_path: A lookup key.
:param bool create_dict_path create a dict path.
... | [
"def",
"_single_array_element",
"(",
"data_obj",
",",
"xj_path",
",",
"array_path",
",",
"create_dict_path",
")",
":",
"val_type",
",",
"array_path",
"=",
"_clean_key_type",
"(",
"array_path",
")",
"array_idx",
"=",
"_get_array_index",
"(",
"array_path",
")",
"if"... | Retrieves a single array for a '@' JSON path marker.
:param list data_obj: The current data object.
:param str xj_path: A json path.
:param str array_path: A lookup key.
:param bool create_dict_path create a dict path. | [
"Retrieves",
"a",
"single",
"array",
"for",
"a",
"@",
"JSON",
"path",
"marker",
"."
] | train | https://github.com/vburenin/xjpath/blob/98a19fd6e6d0bcdc5ecbd3651ffa8915f06d7d44/xjpath/xjpath.py#L214-L244 |
vburenin/xjpath | xjpath/xjpath.py | _split_path | def _split_path(xj_path):
"""Extract the last piece of XJPath.
:param str xj_path: A XJPath expression.
:rtype: tuple[str|None, str]
:return: A tuple where first element is a root XJPath and the second is
a last piece of key.
"""
res = xj_path.rsplit('.', 1)
root_key = res[0]
... | python | def _split_path(xj_path):
"""Extract the last piece of XJPath.
:param str xj_path: A XJPath expression.
:rtype: tuple[str|None, str]
:return: A tuple where first element is a root XJPath and the second is
a last piece of key.
"""
res = xj_path.rsplit('.', 1)
root_key = res[0]
... | [
"def",
"_split_path",
"(",
"xj_path",
")",
":",
"res",
"=",
"xj_path",
".",
"rsplit",
"(",
"'.'",
",",
"1",
")",
"root_key",
"=",
"res",
"[",
"0",
"]",
"if",
"len",
"(",
"res",
")",
">",
"1",
":",
"return",
"root_key",
",",
"res",
"[",
"1",
"]"... | Extract the last piece of XJPath.
:param str xj_path: A XJPath expression.
:rtype: tuple[str|None, str]
:return: A tuple where first element is a root XJPath and the second is
a last piece of key. | [
"Extract",
"the",
"last",
"piece",
"of",
"XJPath",
"."
] | train | https://github.com/vburenin/xjpath/blob/98a19fd6e6d0bcdc5ecbd3651ffa8915f06d7d44/xjpath/xjpath.py#L247-L264 |
vburenin/xjpath | xjpath/xjpath.py | validate_path | def validate_path(xj_path):
"""Validates XJ path.
:param str xj_path: XJ Path
:raise: XJPathError if validation fails.
"""
if not isinstance(xj_path, str):
raise XJPathError('XJPath must be a string')
for path in split(xj_path, '.'):
if path == '*':
continue
... | python | def validate_path(xj_path):
"""Validates XJ path.
:param str xj_path: XJ Path
:raise: XJPathError if validation fails.
"""
if not isinstance(xj_path, str):
raise XJPathError('XJPath must be a string')
for path in split(xj_path, '.'):
if path == '*':
continue
... | [
"def",
"validate_path",
"(",
"xj_path",
")",
":",
"if",
"not",
"isinstance",
"(",
"xj_path",
",",
"str",
")",
":",
"raise",
"XJPathError",
"(",
"'XJPath must be a string'",
")",
"for",
"path",
"in",
"split",
"(",
"xj_path",
",",
"'.'",
")",
":",
"if",
"p... | Validates XJ path.
:param str xj_path: XJ Path
:raise: XJPathError if validation fails. | [
"Validates",
"XJ",
"path",
"."
] | train | https://github.com/vburenin/xjpath/blob/98a19fd6e6d0bcdc5ecbd3651ffa8915f06d7d44/xjpath/xjpath.py#L267-L287 |
vburenin/xjpath | xjpath/xjpath.py | _clean_key_type | def _clean_key_type(key_name, escape_char=ESCAPE_SEQ):
"""Removes type specifier returning detected type and
a key name without type specifier.
:param str key_name: A key name containing type postfix.
:rtype: tuple[type|None, str]
:returns: Type definition and cleaned key name.
"""
for i i... | python | def _clean_key_type(key_name, escape_char=ESCAPE_SEQ):
"""Removes type specifier returning detected type and
a key name without type specifier.
:param str key_name: A key name containing type postfix.
:rtype: tuple[type|None, str]
:returns: Type definition and cleaned key name.
"""
for i i... | [
"def",
"_clean_key_type",
"(",
"key_name",
",",
"escape_char",
"=",
"ESCAPE_SEQ",
")",
":",
"for",
"i",
"in",
"(",
"2",
",",
"1",
")",
":",
"if",
"len",
"(",
"key_name",
")",
"<",
"i",
":",
"return",
"None",
",",
"key_name",
"type_v",
"=",
"key_name"... | Removes type specifier returning detected type and
a key name without type specifier.
:param str key_name: A key name containing type postfix.
:rtype: tuple[type|None, str]
:returns: Type definition and cleaned key name. | [
"Removes",
"type",
"specifier",
"returning",
"detected",
"type",
"and",
"a",
"key",
"name",
"without",
"type",
"specifier",
"."
] | train | https://github.com/vburenin/xjpath/blob/98a19fd6e6d0bcdc5ecbd3651ffa8915f06d7d44/xjpath/xjpath.py#L317-L349 |
vburenin/xjpath | xjpath/xjpath.py | path_lookup | def path_lookup(data_obj, xj_path, create_dict_path=False):
"""Looks up a xj path in the data_obj.
:param dict|list data_obj: An object to look into.
:param str xj_path: A path to extract data from.
:param bool create_dict_path: Create an element if type is specified.
:return: A tuple where 0 value... | python | def path_lookup(data_obj, xj_path, create_dict_path=False):
"""Looks up a xj path in the data_obj.
:param dict|list data_obj: An object to look into.
:param str xj_path: A path to extract data from.
:param bool create_dict_path: Create an element if type is specified.
:return: A tuple where 0 value... | [
"def",
"path_lookup",
"(",
"data_obj",
",",
"xj_path",
",",
"create_dict_path",
"=",
"False",
")",
":",
"if",
"not",
"xj_path",
"or",
"xj_path",
"==",
"'.'",
":",
"return",
"data_obj",
",",
"True",
"res",
"=",
"list",
"(",
"split",
"(",
"xj_path",
",",
... | Looks up a xj path in the data_obj.
:param dict|list data_obj: An object to look into.
:param str xj_path: A path to extract data from.
:param bool create_dict_path: Create an element if type is specified.
:return: A tuple where 0 value is an extracted value and a second
field that tells i... | [
"Looks",
"up",
"a",
"xj",
"path",
"in",
"the",
"data_obj",
"."
] | train | https://github.com/vburenin/xjpath/blob/98a19fd6e6d0bcdc5ecbd3651ffa8915f06d7d44/xjpath/xjpath.py#L352-L400 |
vburenin/xjpath | xjpath/xjpath.py | strict_path_lookup | def strict_path_lookup(data_obj, xj_path, force_type=None):
"""Looks up a xj path in the data_obj.
:param dict|list data_obj: An object to look into.
:param str xj_path: A path to extract data from.
:param type force_type: A type that excepted to be.
:return: Returns result or throws an exception i... | python | def strict_path_lookup(data_obj, xj_path, force_type=None):
"""Looks up a xj path in the data_obj.
:param dict|list data_obj: An object to look into.
:param str xj_path: A path to extract data from.
:param type force_type: A type that excepted to be.
:return: Returns result or throws an exception i... | [
"def",
"strict_path_lookup",
"(",
"data_obj",
",",
"xj_path",
",",
"force_type",
"=",
"None",
")",
":",
"value",
",",
"exists",
"=",
"path_lookup",
"(",
"data_obj",
",",
"xj_path",
")",
"if",
"exists",
":",
"if",
"force_type",
"is",
"not",
"None",
":",
"... | Looks up a xj path in the data_obj.
:param dict|list data_obj: An object to look into.
:param str xj_path: A path to extract data from.
:param type force_type: A type that excepted to be.
:return: Returns result or throws an exception if value is not found. | [
"Looks",
"up",
"a",
"xj",
"path",
"in",
"the",
"data_obj",
"."
] | train | https://github.com/vburenin/xjpath/blob/98a19fd6e6d0bcdc5ecbd3651ffa8915f06d7d44/xjpath/xjpath.py#L403-L420 |
TissueMAPS/TmClient | src/python/tmclient/log.py | map_logging_verbosity | def map_logging_verbosity(verbosity):
'''
Parameters
----------
verbosity: int
logging verbosity level (0-4)
Returns
-------
A logging level as exported by `logging` module.
By default returns logging.NOTSET
Raises
------
TypeError
when `verbosity` doesn't h... | python | def map_logging_verbosity(verbosity):
'''
Parameters
----------
verbosity: int
logging verbosity level (0-4)
Returns
-------
A logging level as exported by `logging` module.
By default returns logging.NOTSET
Raises
------
TypeError
when `verbosity` doesn't h... | [
"def",
"map_logging_verbosity",
"(",
"verbosity",
")",
":",
"if",
"not",
"isinstance",
"(",
"verbosity",
",",
"int",
")",
":",
"raise",
"TypeError",
"(",
"'Argument \"verbosity\" must have type int.'",
")",
"if",
"not",
"verbosity",
">=",
"0",
":",
"raise",
"Val... | Parameters
----------
verbosity: int
logging verbosity level (0-4)
Returns
-------
A logging level as exported by `logging` module.
By default returns logging.NOTSET
Raises
------
TypeError
when `verbosity` doesn't have type int
ValueError
when `verbosit... | [
"Parameters",
"----------",
"verbosity",
":",
"int",
"logging",
"verbosity",
"level",
"(",
"0",
"-",
"4",
")"
] | train | https://github.com/TissueMAPS/TmClient/blob/6fb40622af19142cb5169a64b8c2965993a25ab1/src/python/tmclient/log.py#L34-L60 |
TissueMAPS/TmClient | src/python/tmclient/log.py | configure_logging | def configure_logging():
'''Configures the root logger for command line applications.
Two stream handlers will be added to the logger:
* "out" that will direct INFO & DEBUG messages to the standard output
stream
* "err" that will direct WARN, WARNING, ERROR, & CRITICAL messages to
... | python | def configure_logging():
'''Configures the root logger for command line applications.
Two stream handlers will be added to the logger:
* "out" that will direct INFO & DEBUG messages to the standard output
stream
* "err" that will direct WARN, WARNING, ERROR, & CRITICAL messages to
... | [
"def",
"configure_logging",
"(",
")",
":",
"fmt",
"=",
"'[%(process)6d/%(threadName)-12s] %(asctime)s | %(levelname)-8s | %(name)-40s | %(message)s'",
"datefmt",
"=",
"'%Y-%m-%d %H:%M:%S'",
"formatter",
"=",
"logging",
".",
"Formatter",
"(",
"fmt",
"=",
"fmt",
",",
"datefmt... | Configures the root logger for command line applications.
Two stream handlers will be added to the logger:
* "out" that will direct INFO & DEBUG messages to the standard output
stream
* "err" that will direct WARN, WARNING, ERROR, & CRITICAL messages to
the standard error stream
... | [
"Configures",
"the",
"root",
"logger",
"for",
"command",
"line",
"applications",
"."
] | train | https://github.com/TissueMAPS/TmClient/blob/6fb40622af19142cb5169a64b8c2965993a25ab1/src/python/tmclient/log.py#L63-L106 |
goshuirc/irc | girc/utils.py | sort_prefixes | def sort_prefixes(orig, prefixes='@+'):
"""Returns a sorted list of prefixes.
Args:
orig (str): Unsorted list of prefixes.
prefixes (str): List of prefixes, from highest-priv to lowest.
"""
new = ''
for prefix in prefixes:
if prefix in orig:
new += prefix
ret... | python | def sort_prefixes(orig, prefixes='@+'):
"""Returns a sorted list of prefixes.
Args:
orig (str): Unsorted list of prefixes.
prefixes (str): List of prefixes, from highest-priv to lowest.
"""
new = ''
for prefix in prefixes:
if prefix in orig:
new += prefix
ret... | [
"def",
"sort_prefixes",
"(",
"orig",
",",
"prefixes",
"=",
"'@+'",
")",
":",
"new",
"=",
"''",
"for",
"prefix",
"in",
"prefixes",
":",
"if",
"prefix",
"in",
"orig",
":",
"new",
"+=",
"prefix",
"return",
"new"
] | Returns a sorted list of prefixes.
Args:
orig (str): Unsorted list of prefixes.
prefixes (str): List of prefixes, from highest-priv to lowest. | [
"Returns",
"a",
"sorted",
"list",
"of",
"prefixes",
"."
] | train | https://github.com/goshuirc/irc/blob/d6a5e3e04d337566c009b087f108cd76f9e122cc/girc/utils.py#L8-L19 |
goshuirc/irc | girc/utils.py | parse_modes | def parse_modes(params, mode_types=None, prefixes=''):
"""Return a modelist.
Args:
params (list of str): Parameters from MODE event.
mode_types (list): CHANMODES-like mode types.
prefixes (str): PREFIX-like mode types.
"""
# we don't accept bare strings because we don't want to ... | python | def parse_modes(params, mode_types=None, prefixes=''):
"""Return a modelist.
Args:
params (list of str): Parameters from MODE event.
mode_types (list): CHANMODES-like mode types.
prefixes (str): PREFIX-like mode types.
"""
# we don't accept bare strings because we don't want to ... | [
"def",
"parse_modes",
"(",
"params",
",",
"mode_types",
"=",
"None",
",",
"prefixes",
"=",
"''",
")",
":",
"# we don't accept bare strings because we don't want to try to do",
"# intelligent parameter splitting",
"params",
"=",
"list",
"(",
"params",
")",
"if",
"param... | Return a modelist.
Args:
params (list of str): Parameters from MODE event.
mode_types (list): CHANMODES-like mode types.
prefixes (str): PREFIX-like mode types. | [
"Return",
"a",
"modelist",
"."
] | train | https://github.com/goshuirc/irc/blob/d6a5e3e04d337566c009b087f108cd76f9e122cc/girc/utils.py#L22-L58 |
idlesign/envbox | envbox/utils.py | read_envfile | def read_envfile(fpath):
"""Reads environment variables from .env key-value file.
Rules:
* Lines starting with # (hash) considered comments. Inline comments not supported;
* Multiline values not supported.
* Invalid lines are ignored;
* Matching opening-closing quotes are stripp... | python | def read_envfile(fpath):
"""Reads environment variables from .env key-value file.
Rules:
* Lines starting with # (hash) considered comments. Inline comments not supported;
* Multiline values not supported.
* Invalid lines are ignored;
* Matching opening-closing quotes are stripp... | [
"def",
"read_envfile",
"(",
"fpath",
")",
":",
"environ",
"=",
"os",
".",
"environ",
"env_vars",
"=",
"OrderedDict",
"(",
")",
"try",
":",
"with",
"io",
".",
"open",
"(",
"fpath",
")",
"as",
"f",
":",
"lines",
"=",
"f",
".",
"readlines",
"(",
")",
... | Reads environment variables from .env key-value file.
Rules:
* Lines starting with # (hash) considered comments. Inline comments not supported;
* Multiline values not supported.
* Invalid lines are ignored;
* Matching opening-closing quotes are stripped;
* ${VAL} will be rep... | [
"Reads",
"environment",
"variables",
"from",
".",
"env",
"key",
"-",
"value",
"file",
"."
] | train | https://github.com/idlesign/envbox/blob/4d10cc007e1bc6acf924413c4c16c3b5960d460a/envbox/utils.py#L56-L119 |
gmr/httpbl | httpbl.py | HttpBL.query | def query(self, ip_address):
"""Query the Project Honeypot Http:BL API for the given IP address
:param ip_address: IP address to query
:type ip_address: str
:rtype: dict
"""
try:
return self._decode_response(
socket.gethostbyname(self._build_... | python | def query(self, ip_address):
"""Query the Project Honeypot Http:BL API for the given IP address
:param ip_address: IP address to query
:type ip_address: str
:rtype: dict
"""
try:
return self._decode_response(
socket.gethostbyname(self._build_... | [
"def",
"query",
"(",
"self",
",",
"ip_address",
")",
":",
"try",
":",
"return",
"self",
".",
"_decode_response",
"(",
"socket",
".",
"gethostbyname",
"(",
"self",
".",
"_build_query",
"(",
"ip_address",
")",
")",
")",
"except",
"socket",
".",
"gaierror",
... | Query the Project Honeypot Http:BL API for the given IP address
:param ip_address: IP address to query
:type ip_address: str
:rtype: dict | [
"Query",
"the",
"Project",
"Honeypot",
"Http",
":",
"BL",
"API",
"for",
"the",
"given",
"IP",
"address"
] | train | https://github.com/gmr/httpbl/blob/1728720e104748def509b142231c7e48f1f80e8c/httpbl.py#L63-L80 |
gmr/httpbl | httpbl.py | HttpBL._build_query | def _build_query(self, ip_address):
"""Returns the Http:BL query string to use
:param ip_address: IP address to query
:type ip_address: str
:returns: str
"""
return '{}.{}.{}'.format(
self.key, self._reverse_ip(ip_address), DNSBL_SUFFIX) | python | def _build_query(self, ip_address):
"""Returns the Http:BL query string to use
:param ip_address: IP address to query
:type ip_address: str
:returns: str
"""
return '{}.{}.{}'.format(
self.key, self._reverse_ip(ip_address), DNSBL_SUFFIX) | [
"def",
"_build_query",
"(",
"self",
",",
"ip_address",
")",
":",
"return",
"'{}.{}.{}'",
".",
"format",
"(",
"self",
".",
"key",
",",
"self",
".",
"_reverse_ip",
"(",
"ip_address",
")",
",",
"DNSBL_SUFFIX",
")"
] | Returns the Http:BL query string to use
:param ip_address: IP address to query
:type ip_address: str
:returns: str | [
"Returns",
"the",
"Http",
":",
"BL",
"query",
"string",
"to",
"use"
] | train | https://github.com/gmr/httpbl/blob/1728720e104748def509b142231c7e48f1f80e8c/httpbl.py#L82-L91 |
gmr/httpbl | httpbl.py | HttpBL._decode_response | def _decode_response(self, ip_address):
"""Decodes a HttpBL response IP and return data structure of response
data.
:param ip_address: IP address to query
:type ip_address: str
:rtype: dict
:raises: ValueError
"""
# Reverse the IP, reassign the octets to... | python | def _decode_response(self, ip_address):
"""Decodes a HttpBL response IP and return data structure of response
data.
:param ip_address: IP address to query
:type ip_address: str
:rtype: dict
:raises: ValueError
"""
# Reverse the IP, reassign the octets to... | [
"def",
"_decode_response",
"(",
"self",
",",
"ip_address",
")",
":",
"# Reverse the IP, reassign the octets to integers",
"vt",
",",
"ts",
",",
"days",
",",
"rc",
"=",
"[",
"int",
"(",
"o",
")",
"for",
"o",
"in",
"ip_address",
".",
"split",
"(",
"'.'",
")"... | Decodes a HttpBL response IP and return data structure of response
data.
:param ip_address: IP address to query
:type ip_address: str
:rtype: dict
:raises: ValueError | [
"Decodes",
"a",
"HttpBL",
"response",
"IP",
"and",
"return",
"data",
"structure",
"of",
"response",
"data",
"."
] | train | https://github.com/gmr/httpbl/blob/1728720e104748def509b142231c7e48f1f80e8c/httpbl.py#L103-L133 |
mozilla/mozpay-py | mozpay/verify.py | verify_jwt | def verify_jwt(signed_request, expected_aud, secret, validators=[],
required_keys=('request.pricePoint',
'request.name',
'request.description',
'response.transactionID'),
algorithms=None):
"""
... | python | def verify_jwt(signed_request, expected_aud, secret, validators=[],
required_keys=('request.pricePoint',
'request.name',
'request.description',
'response.transactionID'),
algorithms=None):
"""
... | [
"def",
"verify_jwt",
"(",
"signed_request",
",",
"expected_aud",
",",
"secret",
",",
"validators",
"=",
"[",
"]",
",",
"required_keys",
"=",
"(",
"'request.pricePoint'",
",",
"'request.name'",
",",
"'request.description'",
",",
"'response.transactionID'",
")",
",",
... | Verifies a postback/chargeback JWT.
Returns the trusted JSON data from the original request.
When there's an error, an exception derived from
:class:`mozpay.exc.InvalidJWT`
will be raised.
This is an all-in-one function that does all verification you'd
need. There are some low-level functions ... | [
"Verifies",
"a",
"postback",
"/",
"chargeback",
"JWT",
"."
] | train | https://github.com/mozilla/mozpay-py/blob/e9e674ff35e053d6bb6a1619a1435b7ba3c14af7/mozpay/verify.py#L15-L74 |
mozilla/mozpay-py | mozpay/verify.py | verify_claims | def verify_claims(app_req, issuer=None):
"""
Verify JWT claims.
All times must be UTC unix timestamps.
These claims will be verified:
- iat: issued at time. If JWT was issued more than an hour ago it is
rejected.
- exp: expiration time.
All exceptions are derived from
:class:`m... | python | def verify_claims(app_req, issuer=None):
"""
Verify JWT claims.
All times must be UTC unix timestamps.
These claims will be verified:
- iat: issued at time. If JWT was issued more than an hour ago it is
rejected.
- exp: expiration time.
All exceptions are derived from
:class:`m... | [
"def",
"verify_claims",
"(",
"app_req",
",",
"issuer",
"=",
"None",
")",
":",
"if",
"not",
"issuer",
":",
"issuer",
"=",
"_get_issuer",
"(",
"app_req",
"=",
"app_req",
")",
"try",
":",
"float",
"(",
"str",
"(",
"app_req",
".",
"get",
"(",
"'exp'",
")... | Verify JWT claims.
All times must be UTC unix timestamps.
These claims will be verified:
- iat: issued at time. If JWT was issued more than an hour ago it is
rejected.
- exp: expiration time.
All exceptions are derived from
:class:`mozpay.exc.InvalidJWT`.
For expirations a
:cla... | [
"Verify",
"JWT",
"claims",
"."
] | train | https://github.com/mozilla/mozpay-py/blob/e9e674ff35e053d6bb6a1619a1435b7ba3c14af7/mozpay/verify.py#L77-L104 |
mozilla/mozpay-py | mozpay/verify.py | verify_keys | def verify_keys(app_req, required_keys, issuer=None):
"""
Verify all JWT object keys listed in required_keys.
Each required key is specified as a dot-separated path.
The key values are returned as a list ordered by how
you specified them.
Take this JWT for example::
{
"iss... | python | def verify_keys(app_req, required_keys, issuer=None):
"""
Verify all JWT object keys listed in required_keys.
Each required key is specified as a dot-separated path.
The key values are returned as a list ordered by how
you specified them.
Take this JWT for example::
{
"iss... | [
"def",
"verify_keys",
"(",
"app_req",
",",
"required_keys",
",",
"issuer",
"=",
"None",
")",
":",
"if",
"not",
"issuer",
":",
"issuer",
"=",
"_get_issuer",
"(",
"app_req",
"=",
"app_req",
")",
"key_vals",
"=",
"[",
"]",
"for",
"key_path",
"in",
"required... | Verify all JWT object keys listed in required_keys.
Each required key is specified as a dot-separated path.
The key values are returned as a list ordered by how
you specified them.
Take this JWT for example::
{
"iss": "...",
"aud": "...",
"request": {
... | [
"Verify",
"all",
"JWT",
"object",
"keys",
"listed",
"in",
"required_keys",
"."
] | train | https://github.com/mozilla/mozpay-py/blob/e9e674ff35e053d6bb6a1619a1435b7ba3c14af7/mozpay/verify.py#L107-L152 |
mozilla/mozpay-py | mozpay/verify.py | verify_sig | def verify_sig(signed_request, secret, issuer=None, algorithms=None,
expected_aud=None):
"""
Verify the JWT signature.
Given a raw JWT, this verifies it was signed with
*secret*, decodes it, and returns the JSON dict.
"""
if not issuer:
issuer = _get_issuer(signed_request... | python | def verify_sig(signed_request, secret, issuer=None, algorithms=None,
expected_aud=None):
"""
Verify the JWT signature.
Given a raw JWT, this verifies it was signed with
*secret*, decodes it, and returns the JSON dict.
"""
if not issuer:
issuer = _get_issuer(signed_request... | [
"def",
"verify_sig",
"(",
"signed_request",
",",
"secret",
",",
"issuer",
"=",
"None",
",",
"algorithms",
"=",
"None",
",",
"expected_aud",
"=",
"None",
")",
":",
"if",
"not",
"issuer",
":",
"issuer",
"=",
"_get_issuer",
"(",
"signed_request",
"=",
"signed... | Verify the JWT signature.
Given a raw JWT, this verifies it was signed with
*secret*, decodes it, and returns the JSON dict. | [
"Verify",
"the",
"JWT",
"signature",
"."
] | train | https://github.com/mozilla/mozpay-py/blob/e9e674ff35e053d6bb6a1619a1435b7ba3c14af7/mozpay/verify.py#L155-L178 |
mozilla/mozpay-py | mozpay/verify.py | _re_raise_as | def _re_raise_as(NewExc, *args, **kw):
"""Raise a new exception using the preserved traceback of the last one."""
etype, val, tb = sys.exc_info()
raise NewExc(*args, **kw), None, tb | python | def _re_raise_as(NewExc, *args, **kw):
"""Raise a new exception using the preserved traceback of the last one."""
etype, val, tb = sys.exc_info()
raise NewExc(*args, **kw), None, tb | [
"def",
"_re_raise_as",
"(",
"NewExc",
",",
"*",
"args",
",",
"*",
"*",
"kw",
")",
":",
"etype",
",",
"val",
",",
"tb",
"=",
"sys",
".",
"exc_info",
"(",
")",
"raise",
"NewExc",
"(",
"*",
"args",
",",
"*",
"*",
"kw",
")",
",",
"None",
",",
"tb... | Raise a new exception using the preserved traceback of the last one. | [
"Raise",
"a",
"new",
"exception",
"using",
"the",
"preserved",
"traceback",
"of",
"the",
"last",
"one",
"."
] | train | https://github.com/mozilla/mozpay-py/blob/e9e674ff35e053d6bb6a1619a1435b7ba3c14af7/mozpay/verify.py#L217-L220 |
peopledoc/populous | populous/cli.py | generators | def generators():
"""
List all the available generators.
"""
from populous import generators
base = generators.Generator
for name in dir(generators):
generator = getattr(generators, name)
if isinstance(generator, type) and issubclass(generator, base):
name = genera... | python | def generators():
"""
List all the available generators.
"""
from populous import generators
base = generators.Generator
for name in dir(generators):
generator = getattr(generators, name)
if isinstance(generator, type) and issubclass(generator, base):
name = genera... | [
"def",
"generators",
"(",
")",
":",
"from",
"populous",
"import",
"generators",
"base",
"=",
"generators",
".",
"Generator",
"for",
"name",
"in",
"dir",
"(",
"generators",
")",
":",
"generator",
"=",
"getattr",
"(",
"generators",
",",
"name",
")",
"if",
... | List all the available generators. | [
"List",
"all",
"the",
"available",
"generators",
"."
] | train | https://github.com/peopledoc/populous/blob/50ea445ee973c82a36e0853ae7e2817961143b05/populous/cli.py#L79-L97 |
getfleety/coralillo | coralillo/utils.py | snake_case | def snake_case(string):
''' Takes a string that represents for example a class name and returns
the snake case version of it. It is used for model-to-key conversion '''
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', string)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() | python | def snake_case(string):
''' Takes a string that represents for example a class name and returns
the snake case version of it. It is used for model-to-key conversion '''
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', string)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() | [
"def",
"snake_case",
"(",
"string",
")",
":",
"s1",
"=",
"re",
".",
"sub",
"(",
"'(.)([A-Z][a-z]+)'",
",",
"r'\\1_\\2'",
",",
"string",
")",
"return",
"re",
".",
"sub",
"(",
"'([a-z0-9])([A-Z])'",
",",
"r'\\1_\\2'",
",",
"s1",
")",
".",
"lower",
"(",
"... | Takes a string that represents for example a class name and returns
the snake case version of it. It is used for model-to-key conversion | [
"Takes",
"a",
"string",
"that",
"represents",
"for",
"example",
"a",
"class",
"name",
"and",
"returns",
"the",
"snake",
"case",
"version",
"of",
"it",
".",
"It",
"is",
"used",
"for",
"model",
"-",
"to",
"-",
"key",
"conversion"
] | train | https://github.com/getfleety/coralillo/blob/9cac101738a0fa7c1106f129604c00ef703370e1/coralillo/utils.py#L14-L19 |
enricobacis/limit | limit/limit.py | limit | def limit(limit, every=1):
"""This decorator factory creates a decorator that can be applied to
functions in order to limit the rate the function can be invoked.
The rate is `limit` over `every`, where limit is the number of
invocation allowed every `every` seconds.
limit(4, 60) creates ... | python | def limit(limit, every=1):
"""This decorator factory creates a decorator that can be applied to
functions in order to limit the rate the function can be invoked.
The rate is `limit` over `every`, where limit is the number of
invocation allowed every `every` seconds.
limit(4, 60) creates ... | [
"def",
"limit",
"(",
"limit",
",",
"every",
"=",
"1",
")",
":",
"def",
"limitdecorator",
"(",
"fn",
")",
":",
"\"\"\"This is the actual decorator that performs the rate-limiting.\"\"\"",
"semaphore",
"=",
"_threading",
".",
"Semaphore",
"(",
"limit",
")",
"@",
"_f... | This decorator factory creates a decorator that can be applied to
functions in order to limit the rate the function can be invoked.
The rate is `limit` over `every`, where limit is the number of
invocation allowed every `every` seconds.
limit(4, 60) creates a decorator that limit the functio... | [
"This",
"decorator",
"factory",
"creates",
"a",
"decorator",
"that",
"can",
"be",
"applied",
"to",
"functions",
"in",
"order",
"to",
"limit",
"the",
"rate",
"the",
"function",
"can",
"be",
"invoked",
".",
"The",
"rate",
"is",
"limit",
"over",
"every",
"whe... | train | https://github.com/enricobacis/limit/blob/9bf4f7842990687f605413b7c606dbfd280749ef/limit/limit.py#L5-L31 |
getfleety/coralillo | coralillo/fields.py | Field.value_or_default | def value_or_default(self, value):
''' Returns the given value or the specified default value for this
field '''
if value is None:
if callable(self.default):
return self.default()
else:
return self.default
return value | python | def value_or_default(self, value):
''' Returns the given value or the specified default value for this
field '''
if value is None:
if callable(self.default):
return self.default()
else:
return self.default
return value | [
"def",
"value_or_default",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"is",
"None",
":",
"if",
"callable",
"(",
"self",
".",
"default",
")",
":",
"return",
"self",
".",
"default",
"(",
")",
"else",
":",
"return",
"self",
".",
"default",
"ret... | Returns the given value or the specified default value for this
field | [
"Returns",
"the",
"given",
"value",
"or",
"the",
"specified",
"default",
"value",
"for",
"this",
"field"
] | train | https://github.com/getfleety/coralillo/blob/9cac101738a0fa7c1106f129604c00ef703370e1/coralillo/fields.py#L46-L55 |
getfleety/coralillo | coralillo/fields.py | Field.validate_required | def validate_required(self, value):
''' Validates the given value agains this field's 'required' property
'''
if self.required and (value is None or value==''):
raise MissingFieldError(self.name) | python | def validate_required(self, value):
''' Validates the given value agains this field's 'required' property
'''
if self.required and (value is None or value==''):
raise MissingFieldError(self.name) | [
"def",
"validate_required",
"(",
"self",
",",
"value",
")",
":",
"if",
"self",
".",
"required",
"and",
"(",
"value",
"is",
"None",
"or",
"value",
"==",
"''",
")",
":",
"raise",
"MissingFieldError",
"(",
"self",
".",
"name",
")"
] | Validates the given value agains this field's 'required' property | [
"Validates",
"the",
"given",
"value",
"agains",
"this",
"field",
"s",
"required",
"property"
] | train | https://github.com/getfleety/coralillo/blob/9cac101738a0fa7c1106f129604c00ef703370e1/coralillo/fields.py#L57-L61 |
getfleety/coralillo | coralillo/fields.py | Field.recover | def recover(self, data, redis=None):
''' Retrieve this field's value from the database '''
value = data.get(self.name)
if value is None or value == 'None':
return None
return str(value) | python | def recover(self, data, redis=None):
''' Retrieve this field's value from the database '''
value = data.get(self.name)
if value is None or value == 'None':
return None
return str(value) | [
"def",
"recover",
"(",
"self",
",",
"data",
",",
"redis",
"=",
"None",
")",
":",
"value",
"=",
"data",
".",
"get",
"(",
"self",
".",
"name",
")",
"if",
"value",
"is",
"None",
"or",
"value",
"==",
"'None'",
":",
"return",
"None",
"return",
"str",
... | Retrieve this field's value from the database | [
"Retrieve",
"this",
"field",
"s",
"value",
"from",
"the",
"database"
] | train | https://github.com/getfleety/coralillo/blob/9cac101738a0fa7c1106f129604c00ef703370e1/coralillo/fields.py#L68-L75 |
getfleety/coralillo | coralillo/fields.py | Field.save | def save(self, value, redis, *, commit=True):
''' Sets this fields value in the databse '''
value = self.prepare(value)
if value is not None:
redis.hset(self.obj.key(), self.name, value)
else:
redis.hdel(self.obj.key(), self.name)
if self.index:
... | python | def save(self, value, redis, *, commit=True):
''' Sets this fields value in the databse '''
value = self.prepare(value)
if value is not None:
redis.hset(self.obj.key(), self.name, value)
else:
redis.hdel(self.obj.key(), self.name)
if self.index:
... | [
"def",
"save",
"(",
"self",
",",
"value",
",",
"redis",
",",
"*",
",",
"commit",
"=",
"True",
")",
":",
"value",
"=",
"self",
".",
"prepare",
"(",
"value",
")",
"if",
"value",
"is",
"not",
"None",
":",
"redis",
".",
"hset",
"(",
"self",
".",
"o... | Sets this fields value in the databse | [
"Sets",
"this",
"fields",
"value",
"in",
"the",
"databse"
] | train | https://github.com/getfleety/coralillo/blob/9cac101738a0fa7c1106f129604c00ef703370e1/coralillo/fields.py#L87-L103 |
getfleety/coralillo | coralillo/fields.py | Field.delete | def delete(self, redis):
''' Deletes this field's value from the databse. Should be implemented
in special cases '''
if self.index:
redis.hdel(self.key(), getattr(self.obj, self.name)) | python | def delete(self, redis):
''' Deletes this field's value from the databse. Should be implemented
in special cases '''
if self.index:
redis.hdel(self.key(), getattr(self.obj, self.name)) | [
"def",
"delete",
"(",
"self",
",",
"redis",
")",
":",
"if",
"self",
".",
"index",
":",
"redis",
".",
"hdel",
"(",
"self",
".",
"key",
"(",
")",
",",
"getattr",
"(",
"self",
".",
"obj",
",",
"self",
".",
"name",
")",
")"
] | Deletes this field's value from the databse. Should be implemented
in special cases | [
"Deletes",
"this",
"field",
"s",
"value",
"from",
"the",
"databse",
".",
"Should",
"be",
"implemented",
"in",
"special",
"cases"
] | train | https://github.com/getfleety/coralillo/blob/9cac101738a0fa7c1106f129604c00ef703370e1/coralillo/fields.py#L105-L109 |
getfleety/coralillo | coralillo/fields.py | Field.validate | def validate(self, value, redis):
'''
Validates data obtained from a request and returns it in the apropiate
format
'''
# cleanup
if type(value) == str:
value = value.strip()
value = self.value_or_default(value)
# validation
self.vali... | python | def validate(self, value, redis):
'''
Validates data obtained from a request and returns it in the apropiate
format
'''
# cleanup
if type(value) == str:
value = value.strip()
value = self.value_or_default(value)
# validation
self.vali... | [
"def",
"validate",
"(",
"self",
",",
"value",
",",
"redis",
")",
":",
"# cleanup",
"if",
"type",
"(",
"value",
")",
"==",
"str",
":",
"value",
"=",
"value",
".",
"strip",
"(",
")",
"value",
"=",
"self",
".",
"value_or_default",
"(",
"value",
")",
"... | Validates data obtained from a request and returns it in the apropiate
format | [
"Validates",
"data",
"obtained",
"from",
"a",
"request",
"and",
"returns",
"it",
"in",
"the",
"apropiate",
"format"
] | train | https://github.com/getfleety/coralillo/blob/9cac101738a0fa7c1106f129604c00ef703370e1/coralillo/fields.py#L111-L145 |
getfleety/coralillo | coralillo/fields.py | TreeIndex.delete | def delete(self, redis):
''' Deletes this field's value from the databse. Should be implemented
in special cases '''
value = getattr(self.obj, self.name)
redis.srem(self.key() + ':' + value, self.obj.id) | python | def delete(self, redis):
''' Deletes this field's value from the databse. Should be implemented
in special cases '''
value = getattr(self.obj, self.name)
redis.srem(self.key() + ':' + value, self.obj.id) | [
"def",
"delete",
"(",
"self",
",",
"redis",
")",
":",
"value",
"=",
"getattr",
"(",
"self",
".",
"obj",
",",
"self",
".",
"name",
")",
"redis",
".",
"srem",
"(",
"self",
".",
"key",
"(",
")",
"+",
"':'",
"+",
"value",
",",
"self",
".",
"obj",
... | Deletes this field's value from the databse. Should be implemented
in special cases | [
"Deletes",
"this",
"field",
"s",
"value",
"from",
"the",
"databse",
".",
"Should",
"be",
"implemented",
"in",
"special",
"cases"
] | train | https://github.com/getfleety/coralillo/blob/9cac101738a0fa7c1106f129604c00ef703370e1/coralillo/fields.py#L173-L177 |
getfleety/coralillo | coralillo/fields.py | Hash.init | def init(self, value):
''' hash passwords given in the constructor '''
value = self.value_or_default(value)
if value is None: return None
if is_hashed(value):
return value
return make_password(value) | python | def init(self, value):
''' hash passwords given in the constructor '''
value = self.value_or_default(value)
if value is None: return None
if is_hashed(value):
return value
return make_password(value) | [
"def",
"init",
"(",
"self",
",",
"value",
")",
":",
"value",
"=",
"self",
".",
"value_or_default",
"(",
"value",
")",
"if",
"value",
"is",
"None",
":",
"return",
"None",
"if",
"is_hashed",
"(",
"value",
")",
":",
"return",
"value",
"return",
"make_pass... | hash passwords given in the constructor | [
"hash",
"passwords",
"given",
"in",
"the",
"constructor"
] | train | https://github.com/getfleety/coralillo/blob/9cac101738a0fa7c1106f129604c00ef703370e1/coralillo/fields.py#L186-L195 |
getfleety/coralillo | coralillo/fields.py | Hash.validate | def validate(self, value, redis):
''' hash passwords given via http '''
value = super().validate(value, redis)
if is_hashed(value):
return value
return make_password(value) | python | def validate(self, value, redis):
''' hash passwords given via http '''
value = super().validate(value, redis)
if is_hashed(value):
return value
return make_password(value) | [
"def",
"validate",
"(",
"self",
",",
"value",
",",
"redis",
")",
":",
"value",
"=",
"super",
"(",
")",
".",
"validate",
"(",
"value",
",",
"redis",
")",
"if",
"is_hashed",
"(",
"value",
")",
":",
"return",
"value",
"return",
"make_password",
"(",
"va... | hash passwords given via http | [
"hash",
"passwords",
"given",
"via",
"http"
] | train | https://github.com/getfleety/coralillo/blob/9cac101738a0fa7c1106f129604c00ef703370e1/coralillo/fields.py#L207-L214 |
getfleety/coralillo | coralillo/fields.py | Datetime.validate | def validate(self, value, redis):
'''
Validates data obtained from a request in ISO 8061 and returns it in Datetime data type
'''
value = self.value_or_default(value)
self.validate_required(value)
if value is None:
return None
if type(value) == str... | python | def validate(self, value, redis):
'''
Validates data obtained from a request in ISO 8061 and returns it in Datetime data type
'''
value = self.value_or_default(value)
self.validate_required(value)
if value is None:
return None
if type(value) == str... | [
"def",
"validate",
"(",
"self",
",",
"value",
",",
"redis",
")",
":",
"value",
"=",
"self",
".",
"value_or_default",
"(",
"value",
")",
"self",
".",
"validate_required",
"(",
"value",
")",
"if",
"value",
"is",
"None",
":",
"return",
"None",
"if",
"type... | Validates data obtained from a request in ISO 8061 and returns it in Datetime data type | [
"Validates",
"data",
"obtained",
"from",
"a",
"request",
"in",
"ISO",
"8061",
"and",
"returns",
"it",
"in",
"Datetime",
"data",
"type"
] | train | https://github.com/getfleety/coralillo/blob/9cac101738a0fa7c1106f129604c00ef703370e1/coralillo/fields.py#L297-L315 |
getfleety/coralillo | coralillo/fields.py | MultipleRelation.fill | def fill(self, **kwargs):
''' Loads the relationships into this model. They are not loaded by
default '''
setattr(self.obj, self.name, self.get(**kwargs)) | python | def fill(self, **kwargs):
''' Loads the relationships into this model. They are not loaded by
default '''
setattr(self.obj, self.name, self.get(**kwargs)) | [
"def",
"fill",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"setattr",
"(",
"self",
".",
"obj",
",",
"self",
".",
"name",
",",
"self",
".",
"get",
"(",
"*",
"*",
"kwargs",
")",
")"
] | Loads the relationships into this model. They are not loaded by
default | [
"Loads",
"the",
"relationships",
"into",
"this",
"model",
".",
"They",
"are",
"not",
"loaded",
"by",
"default"
] | train | https://github.com/getfleety/coralillo/blob/9cac101738a0fa7c1106f129604c00ef703370e1/coralillo/fields.py#L591-L594 |
getfleety/coralillo | coralillo/fields.py | MultipleRelation.get | def get(self, **kwargs):
''' Returns this relation '''
redis = type(self.obj).get_redis()
related = list(map(
lambda id : self.model().get(debyte_string(id)),
self.get_related_ids(redis, **kwargs)
))
return related | python | def get(self, **kwargs):
''' Returns this relation '''
redis = type(self.obj).get_redis()
related = list(map(
lambda id : self.model().get(debyte_string(id)),
self.get_related_ids(redis, **kwargs)
))
return related | [
"def",
"get",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"redis",
"=",
"type",
"(",
"self",
".",
"obj",
")",
".",
"get_redis",
"(",
")",
"related",
"=",
"list",
"(",
"map",
"(",
"lambda",
"id",
":",
"self",
".",
"model",
"(",
")",
".",
"... | Returns this relation | [
"Returns",
"this",
"relation"
] | train | https://github.com/getfleety/coralillo/blob/9cac101738a0fa7c1106f129604c00ef703370e1/coralillo/fields.py#L596-L604 |
inveniosoftware-contrib/invenio-classifier | invenio_classifier/acronymer.py | get_acronyms | def get_acronyms(fulltext):
"""Find acronyms and expansions from the fulltext.
If needed, acronyms can already contain a dictionary of previously found
acronyms that will be merged with the current results.
"""
acronyms = {}
for m in ACRONYM_BRACKETS_REGEX.finditer(fulltext):
acronym ... | python | def get_acronyms(fulltext):
"""Find acronyms and expansions from the fulltext.
If needed, acronyms can already contain a dictionary of previously found
acronyms that will be merged with the current results.
"""
acronyms = {}
for m in ACRONYM_BRACKETS_REGEX.finditer(fulltext):
acronym ... | [
"def",
"get_acronyms",
"(",
"fulltext",
")",
":",
"acronyms",
"=",
"{",
"}",
"for",
"m",
"in",
"ACRONYM_BRACKETS_REGEX",
".",
"finditer",
"(",
"fulltext",
")",
":",
"acronym",
"=",
"DOTS_REGEX",
".",
"sub",
"(",
"\"\"",
",",
"m",
".",
"group",
"(",
"1"... | Find acronyms and expansions from the fulltext.
If needed, acronyms can already contain a dictionary of previously found
acronyms that will be merged with the current results. | [
"Find",
"acronyms",
"and",
"expansions",
"from",
"the",
"fulltext",
"."
] | train | https://github.com/inveniosoftware-contrib/invenio-classifier/blob/3c758cf34dca6bf0548e7da5de34e5f72e3b255e/invenio_classifier/acronymer.py#L33-L216 |
inveniosoftware-contrib/invenio-classifier | invenio_classifier/acronymer.py | _add_expansion_to_acronym_dict | def _add_expansion_to_acronym_dict(acronym, expansion, level, dictionary):
"""Add an acronym to the dictionary.
Takes care of avoiding duplicates and keeping the expansion marked with
the best score.
"""
if len(acronym) >= len(expansion) or acronym in expansion:
return
for punctuation ... | python | def _add_expansion_to_acronym_dict(acronym, expansion, level, dictionary):
"""Add an acronym to the dictionary.
Takes care of avoiding duplicates and keeping the expansion marked with
the best score.
"""
if len(acronym) >= len(expansion) or acronym in expansion:
return
for punctuation ... | [
"def",
"_add_expansion_to_acronym_dict",
"(",
"acronym",
",",
"expansion",
",",
"level",
",",
"dictionary",
")",
":",
"if",
"len",
"(",
"acronym",
")",
">=",
"len",
"(",
"expansion",
")",
"or",
"acronym",
"in",
"expansion",
":",
"return",
"for",
"punctuation... | Add an acronym to the dictionary.
Takes care of avoiding duplicates and keeping the expansion marked with
the best score. | [
"Add",
"an",
"acronym",
"to",
"the",
"dictionary",
"."
] | train | https://github.com/inveniosoftware-contrib/invenio-classifier/blob/3c758cf34dca6bf0548e7da5de34e5f72e3b255e/invenio_classifier/acronymer.py#L224-L256 |
inveniosoftware-contrib/invenio-classifier | invenio_classifier/acronymer.py | _equivalent_expansions | def _equivalent_expansions(expansion1, expansion2):
"""Compare two expansions."""
words1 = _words(expansion1)
words2 = _words(expansion2)
simplified_versions = []
if words1 == words2:
return True
for words in (words1, words2):
store = []
for word in words:
... | python | def _equivalent_expansions(expansion1, expansion2):
"""Compare two expansions."""
words1 = _words(expansion1)
words2 = _words(expansion2)
simplified_versions = []
if words1 == words2:
return True
for words in (words1, words2):
store = []
for word in words:
... | [
"def",
"_equivalent_expansions",
"(",
"expansion1",
",",
"expansion2",
")",
":",
"words1",
"=",
"_words",
"(",
"expansion1",
")",
"words2",
"=",
"_words",
"(",
"expansion2",
")",
"simplified_versions",
"=",
"[",
"]",
"if",
"words1",
"==",
"words2",
":",
"ret... | Compare two expansions. | [
"Compare",
"two",
"expansions",
"."
] | train | https://github.com/inveniosoftware-contrib/invenio-classifier/blob/3c758cf34dca6bf0548e7da5de34e5f72e3b255e/invenio_classifier/acronymer.py#L259-L275 |
askedrelic/libgreader | libgreader/auth.py | ClientAuthMethod.get | def get(self, url, parameters=None):
"""
Convenience method for requesting to google with proper cookies/params.
"""
getString = self.getParameters(parameters)
headers = {'Authorization':'GoogleLogin auth=%s' % self.auth_token}
req = requests.get(url + "?" + getString, he... | python | def get(self, url, parameters=None):
"""
Convenience method for requesting to google with proper cookies/params.
"""
getString = self.getParameters(parameters)
headers = {'Authorization':'GoogleLogin auth=%s' % self.auth_token}
req = requests.get(url + "?" + getString, he... | [
"def",
"get",
"(",
"self",
",",
"url",
",",
"parameters",
"=",
"None",
")",
":",
"getString",
"=",
"self",
".",
"getParameters",
"(",
"parameters",
")",
"headers",
"=",
"{",
"'Authorization'",
":",
"'GoogleLogin auth=%s'",
"%",
"self",
".",
"auth_token",
"... | Convenience method for requesting to google with proper cookies/params. | [
"Convenience",
"method",
"for",
"requesting",
"to",
"google",
"with",
"proper",
"cookies",
"/",
"params",
"."
] | train | https://github.com/askedrelic/libgreader/blob/7b668ee291c2464ea172ef44393100c369efa970/libgreader/auth.py#L74-L81 |
askedrelic/libgreader | libgreader/auth.py | ClientAuthMethod.post | def post(self, url, postParameters=None, urlParameters=None):
"""
Convenience method for requesting to google with proper cookies/params.
"""
if urlParameters:
url = url + "?" + self.getParameters(urlParameters)
headers = {'Authorization':'GoogleLogin auth=%s' % self.... | python | def post(self, url, postParameters=None, urlParameters=None):
"""
Convenience method for requesting to google with proper cookies/params.
"""
if urlParameters:
url = url + "?" + self.getParameters(urlParameters)
headers = {'Authorization':'GoogleLogin auth=%s' % self.... | [
"def",
"post",
"(",
"self",
",",
"url",
",",
"postParameters",
"=",
"None",
",",
"urlParameters",
"=",
"None",
")",
":",
"if",
"urlParameters",
":",
"url",
"=",
"url",
"+",
"\"?\"",
"+",
"self",
".",
"getParameters",
"(",
"urlParameters",
")",
"headers",... | Convenience method for requesting to google with proper cookies/params. | [
"Convenience",
"method",
"for",
"requesting",
"to",
"google",
"with",
"proper",
"cookies",
"/",
"params",
"."
] | train | https://github.com/askedrelic/libgreader/blob/7b668ee291c2464ea172ef44393100c369efa970/libgreader/auth.py#L83-L94 |
askedrelic/libgreader | libgreader/auth.py | ClientAuthMethod._getAuth | def _getAuth(self):
"""
Main step in authorizing with Reader.
Sends request to Google ClientAuthMethod URL which returns an Auth token.
Returns Auth token or raises IOError on error.
"""
parameters = {
'service' : 'reader',
'Email' : sel... | python | def _getAuth(self):
"""
Main step in authorizing with Reader.
Sends request to Google ClientAuthMethod URL which returns an Auth token.
Returns Auth token or raises IOError on error.
"""
parameters = {
'service' : 'reader',
'Email' : sel... | [
"def",
"_getAuth",
"(",
"self",
")",
":",
"parameters",
"=",
"{",
"'service'",
":",
"'reader'",
",",
"'Email'",
":",
"self",
".",
"username",
",",
"'Passwd'",
":",
"self",
".",
"password",
",",
"'accountType'",
":",
"'GOOGLE'",
"}",
"req",
"=",
"requests... | Main step in authorizing with Reader.
Sends request to Google ClientAuthMethod URL which returns an Auth token.
Returns Auth token or raises IOError on error. | [
"Main",
"step",
"in",
"authorizing",
"with",
"Reader",
".",
"Sends",
"request",
"to",
"Google",
"ClientAuthMethod",
"URL",
"which",
"returns",
"an",
"Auth",
"token",
"."
] | train | https://github.com/askedrelic/libgreader/blob/7b668ee291c2464ea172ef44393100c369efa970/libgreader/auth.py#L96-L115 |
askedrelic/libgreader | libgreader/auth.py | ClientAuthMethod._getToken | def _getToken(self):
"""
Second step in authorizing with Reader.
Sends authorized request to Reader token URL and returns a token value.
Returns token or raises IOError on error.
"""
headers = {'Authorization':'GoogleLogin auth=%s' % self.auth_token}
req = reques... | python | def _getToken(self):
"""
Second step in authorizing with Reader.
Sends authorized request to Reader token URL and returns a token value.
Returns token or raises IOError on error.
"""
headers = {'Authorization':'GoogleLogin auth=%s' % self.auth_token}
req = reques... | [
"def",
"_getToken",
"(",
"self",
")",
":",
"headers",
"=",
"{",
"'Authorization'",
":",
"'GoogleLogin auth=%s'",
"%",
"self",
".",
"auth_token",
"}",
"req",
"=",
"requests",
".",
"get",
"(",
"ReaderUrl",
".",
"API_URL",
"+",
"'token'",
",",
"headers",
"=",... | Second step in authorizing with Reader.
Sends authorized request to Reader token URL and returns a token value.
Returns token or raises IOError on error. | [
"Second",
"step",
"in",
"authorizing",
"with",
"Reader",
".",
"Sends",
"authorized",
"request",
"to",
"Reader",
"token",
"URL",
"and",
"returns",
"a",
"token",
"value",
"."
] | train | https://github.com/askedrelic/libgreader/blob/7b668ee291c2464ea172ef44393100c369efa970/libgreader/auth.py#L117-L128 |
askedrelic/libgreader | libgreader/auth.py | OAuthMethod.post | def post(self, url, postParameters=None, urlParameters=None):
"""
Convenience method for requesting to google with proper cookies/params.
"""
if self.authorized_client:
if urlParameters:
getString = self.getParameters(urlParameters)
req = urlli... | python | def post(self, url, postParameters=None, urlParameters=None):
"""
Convenience method for requesting to google with proper cookies/params.
"""
if self.authorized_client:
if urlParameters:
getString = self.getParameters(urlParameters)
req = urlli... | [
"def",
"post",
"(",
"self",
",",
"url",
",",
"postParameters",
"=",
"None",
",",
"urlParameters",
"=",
"None",
")",
":",
"if",
"self",
".",
"authorized_client",
":",
"if",
"urlParameters",
":",
"getString",
"=",
"self",
".",
"getParameters",
"(",
"urlParam... | Convenience method for requesting to google with proper cookies/params. | [
"Convenience",
"method",
"for",
"requesting",
"to",
"google",
"with",
"proper",
"cookies",
"/",
"params",
"."
] | train | https://github.com/askedrelic/libgreader/blob/7b668ee291c2464ea172ef44393100c369efa970/libgreader/auth.py#L218-L232 |
askedrelic/libgreader | libgreader/auth.py | OAuth2Method.get | def get(self, url, parameters=None):
"""
Convenience method for requesting to google with proper cookies/params.
"""
if not self.access_token:
raise IOError("No authorized client available.")
if parameters is None:
parameters = {}
parameters.update... | python | def get(self, url, parameters=None):
"""
Convenience method for requesting to google with proper cookies/params.
"""
if not self.access_token:
raise IOError("No authorized client available.")
if parameters is None:
parameters = {}
parameters.update... | [
"def",
"get",
"(",
"self",
",",
"url",
",",
"parameters",
"=",
"None",
")",
":",
"if",
"not",
"self",
".",
"access_token",
":",
"raise",
"IOError",
"(",
"\"No authorized client available.\"",
")",
"if",
"parameters",
"is",
"None",
":",
"parameters",
"=",
"... | Convenience method for requesting to google with proper cookies/params. | [
"Convenience",
"method",
"for",
"requesting",
"to",
"google",
"with",
"proper",
"cookies",
"/",
"params",
"."
] | train | https://github.com/askedrelic/libgreader/blob/7b668ee291c2464ea172ef44393100c369efa970/libgreader/auth.py#L303-L316 |
askedrelic/libgreader | libgreader/auth.py | OAuth2Method.post | def post(self, url, postParameters=None, urlParameters=None):
"""
Convenience method for requesting to google with proper cookies/params.
"""
if not self.access_token:
raise IOError("No authorized client available.")
if not self.action_token:
raise IOError... | python | def post(self, url, postParameters=None, urlParameters=None):
"""
Convenience method for requesting to google with proper cookies/params.
"""
if not self.access_token:
raise IOError("No authorized client available.")
if not self.action_token:
raise IOError... | [
"def",
"post",
"(",
"self",
",",
"url",
",",
"postParameters",
"=",
"None",
",",
"urlParameters",
"=",
"None",
")",
":",
"if",
"not",
"self",
".",
"access_token",
":",
"raise",
"IOError",
"(",
"\"No authorized client available.\"",
")",
"if",
"not",
"self",
... | Convenience method for requesting to google with proper cookies/params. | [
"Convenience",
"method",
"for",
"requesting",
"to",
"google",
"with",
"proper",
"cookies",
"/",
"params",
"."
] | train | https://github.com/askedrelic/libgreader/blob/7b668ee291c2464ea172ef44393100c369efa970/libgreader/auth.py#L318-L336 |
askedrelic/libgreader | libgreader/auth.py | GAPDecoratorAuthMethod._setupHttp | def _setupHttp(self):
"""
Setup an HTTP session authorized by OAuth2.
"""
if self._http == None:
http = httplib2.Http()
self._http = self._credentials.authorize(http) | python | def _setupHttp(self):
"""
Setup an HTTP session authorized by OAuth2.
"""
if self._http == None:
http = httplib2.Http()
self._http = self._credentials.authorize(http) | [
"def",
"_setupHttp",
"(",
"self",
")",
":",
"if",
"self",
".",
"_http",
"==",
"None",
":",
"http",
"=",
"httplib2",
".",
"Http",
"(",
")",
"self",
".",
"_http",
"=",
"self",
".",
"_credentials",
".",
"authorize",
"(",
"http",
")"
] | Setup an HTTP session authorized by OAuth2. | [
"Setup",
"an",
"HTTP",
"session",
"authorized",
"by",
"OAuth2",
"."
] | train | https://github.com/askedrelic/libgreader/blob/7b668ee291c2464ea172ef44393100c369efa970/libgreader/auth.py#L356-L362 |
askedrelic/libgreader | libgreader/auth.py | GAPDecoratorAuthMethod.get | def get(self, url, parameters=None):
"""
Implement libgreader's interface for authenticated GET request
"""
if self._http == None:
self._setupHttp()
uri = url + "?" + self.getParameters(parameters)
response, content = self._http.request(uri, "GET")
ret... | python | def get(self, url, parameters=None):
"""
Implement libgreader's interface for authenticated GET request
"""
if self._http == None:
self._setupHttp()
uri = url + "?" + self.getParameters(parameters)
response, content = self._http.request(uri, "GET")
ret... | [
"def",
"get",
"(",
"self",
",",
"url",
",",
"parameters",
"=",
"None",
")",
":",
"if",
"self",
".",
"_http",
"==",
"None",
":",
"self",
".",
"_setupHttp",
"(",
")",
"uri",
"=",
"url",
"+",
"\"?\"",
"+",
"self",
".",
"getParameters",
"(",
"parameter... | Implement libgreader's interface for authenticated GET request | [
"Implement",
"libgreader",
"s",
"interface",
"for",
"authenticated",
"GET",
"request"
] | train | https://github.com/askedrelic/libgreader/blob/7b668ee291c2464ea172ef44393100c369efa970/libgreader/auth.py#L364-L372 |
askedrelic/libgreader | libgreader/auth.py | GAPDecoratorAuthMethod.post | def post(self, url, postParameters=None, urlParameters=None):
"""
Implement libgreader's interface for authenticated POST request
"""
if self._action_token == None:
self._action_token = self.get(ReaderUrl.ACTION_TOKEN_URL)
if self._http == None:
self._set... | python | def post(self, url, postParameters=None, urlParameters=None):
"""
Implement libgreader's interface for authenticated POST request
"""
if self._action_token == None:
self._action_token = self.get(ReaderUrl.ACTION_TOKEN_URL)
if self._http == None:
self._set... | [
"def",
"post",
"(",
"self",
",",
"url",
",",
"postParameters",
"=",
"None",
",",
"urlParameters",
"=",
"None",
")",
":",
"if",
"self",
".",
"_action_token",
"==",
"None",
":",
"self",
".",
"_action_token",
"=",
"self",
".",
"get",
"(",
"ReaderUrl",
"."... | Implement libgreader's interface for authenticated POST request | [
"Implement",
"libgreader",
"s",
"interface",
"for",
"authenticated",
"POST",
"request"
] | train | https://github.com/askedrelic/libgreader/blob/7b668ee291c2464ea172ef44393100c369efa970/libgreader/auth.py#L374-L387 |
PMBio/limix-backup | src/interfaces/doxy2swig.py | Doxy2SWIG.parse_Element | def parse_Element(self, node):
"""Parse an `ELEMENT_NODE`. This calls specific
`do_<tagName>` handers for different elements. If no handler
is available the `generic_parse` method is called. All
tagNames specified in `self.ignores` are simply ignored.
"""
name = node.... | python | def parse_Element(self, node):
"""Parse an `ELEMENT_NODE`. This calls specific
`do_<tagName>` handers for different elements. If no handler
is available the `generic_parse` method is called. All
tagNames specified in `self.ignores` are simply ignored.
"""
name = node.... | [
"def",
"parse_Element",
"(",
"self",
",",
"node",
")",
":",
"name",
"=",
"node",
".",
"tagName",
"ignores",
"=",
"self",
".",
"ignores",
"if",
"name",
"in",
"ignores",
":",
"return",
"attr",
"=",
"\"do_%s\"",
"%",
"name",
"if",
"hasattr",
"(",
"self",
... | Parse an `ELEMENT_NODE`. This calls specific
`do_<tagName>` handers for different elements. If no handler
is available the `generic_parse` method is called. All
tagNames specified in `self.ignores` are simply ignored. | [
"Parse",
"an",
"ELEMENT_NODE",
".",
"This",
"calls",
"specific",
"do_<tagName",
">",
"handers",
"for",
"different",
"elements",
".",
"If",
"no",
"handler",
"is",
"available",
"the",
"generic_parse",
"method",
"is",
"called",
".",
"All",
"tagNames",
"specified",
... | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/src/interfaces/doxy2swig.py#L110-L126 |
PMBio/limix-backup | src/interfaces/doxy2swig.py | Doxy2SWIG.generic_parse | def generic_parse(self, node, pad=0):
"""A Generic parser for arbitrary tags in a node.
Parameters:
- node: A node in the DOM.
- pad: `int` (default: 0)
If 0 the node data is not padded with newlines. If 1 it
appends a newline after parsing the childNodes. I... | python | def generic_parse(self, node, pad=0):
"""A Generic parser for arbitrary tags in a node.
Parameters:
- node: A node in the DOM.
- pad: `int` (default: 0)
If 0 the node data is not padded with newlines. If 1 it
appends a newline after parsing the childNodes. I... | [
"def",
"generic_parse",
"(",
"self",
",",
"node",
",",
"pad",
"=",
"0",
")",
":",
"npiece",
"=",
"0",
"if",
"pad",
":",
"npiece",
"=",
"len",
"(",
"self",
".",
"pieces",
")",
"if",
"pad",
"==",
"2",
":",
"self",
".",
"add_text",
"(",
"'\\n'",
"... | A Generic parser for arbitrary tags in a node.
Parameters:
- node: A node in the DOM.
- pad: `int` (default: 0)
If 0 the node data is not padded with newlines. If 1 it
appends a newline after parsing the childNodes. If 2 it
pads before and after the nodes... | [
"A",
"Generic",
"parser",
"for",
"arbitrary",
"tags",
"in",
"a",
"node",
"."
] | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/src/interfaces/doxy2swig.py#L147-L170 |
PMBio/limix-backup | src/interfaces/doxy2swig.py | Doxy2SWIG.clean_pieces | def clean_pieces(self, pieces):
"""Cleans the list of strings given as `pieces`. It replaces
multiple newlines by a maximum of 2 and returns a new list.
It also wraps the paragraphs nicely.
"""
ret = []
count = 0
for i in pieces:
if i == '\n':
... | python | def clean_pieces(self, pieces):
"""Cleans the list of strings given as `pieces`. It replaces
multiple newlines by a maximum of 2 and returns a new list.
It also wraps the paragraphs nicely.
"""
ret = []
count = 0
for i in pieces:
if i == '\n':
... | [
"def",
"clean_pieces",
"(",
"self",
",",
"pieces",
")",
":",
"ret",
"=",
"[",
"]",
"count",
"=",
"0",
"for",
"i",
"in",
"pieces",
":",
"if",
"i",
"==",
"'\\n'",
":",
"count",
"=",
"count",
"+",
"1",
"else",
":",
"if",
"i",
"==",
"'\";'",
":",
... | Cleans the list of strings given as `pieces`. It replaces
multiple newlines by a maximum of 2 and returns a new list.
It also wraps the paragraphs nicely. | [
"Cleans",
"the",
"list",
"of",
"strings",
"given",
"as",
"pieces",
".",
"It",
"replaces",
"multiple",
"newlines",
"by",
"a",
"maximum",
"of",
"2",
"and",
"returns",
"a",
"new",
"list",
".",
"It",
"also",
"wraps",
"the",
"paragraphs",
"nicely",
"."
] | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/src/interfaces/doxy2swig.py#L325-L358 |
akfullfo/taskforce | taskforce/status.py | http._format_json | def _format_json(self, ans, q):
"""
Generate a json response string.
"""
params = {}
try: params['indent'] = int(q.get('indent')[0])
except: pass
return json.dumps(ans, **params)+'\n' | python | def _format_json(self, ans, q):
"""
Generate a json response string.
"""
params = {}
try: params['indent'] = int(q.get('indent')[0])
except: pass
return json.dumps(ans, **params)+'\n' | [
"def",
"_format_json",
"(",
"self",
",",
"ans",
",",
"q",
")",
":",
"params",
"=",
"{",
"}",
"try",
":",
"params",
"[",
"'indent'",
"]",
"=",
"int",
"(",
"q",
".",
"get",
"(",
"'indent'",
")",
"[",
"0",
"]",
")",
"except",
":",
"pass",
"return"... | Generate a json response string. | [
"Generate",
"a",
"json",
"response",
"string",
"."
] | train | https://github.com/akfullfo/taskforce/blob/bc6dd744bd33546447d085dbd18a350532220193/taskforce/status.py#L75-L83 |
akfullfo/taskforce | taskforce/status.py | http._format | def _format(self, ans, q):
"""
Returns the response tuple according to the selected format.
A format is available if the method "_format_xxx" is callable.
The default format is json.
"""
if 'fmt' in q:
fmt = q['fmt'][0]
else:
fmt = 'json'
... | python | def _format(self, ans, q):
"""
Returns the response tuple according to the selected format.
A format is available if the method "_format_xxx" is callable.
The default format is json.
"""
if 'fmt' in q:
fmt = q['fmt'][0]
else:
fmt = 'json'
... | [
"def",
"_format",
"(",
"self",
",",
"ans",
",",
"q",
")",
":",
"if",
"'fmt'",
"in",
"q",
":",
"fmt",
"=",
"q",
"[",
"'fmt'",
"]",
"[",
"0",
"]",
"else",
":",
"fmt",
"=",
"'json'",
"fmt",
"=",
"fmt",
".",
"lower",
"(",
")",
"if",
"fmt",
"in"... | Returns the response tuple according to the selected format.
A format is available if the method "_format_xxx" is callable.
The default format is json. | [
"Returns",
"the",
"response",
"tuple",
"according",
"to",
"the",
"selected",
"format",
".",
"A",
"format",
"is",
"available",
"if",
"the",
"method",
"_format_xxx",
"is",
"callable",
".",
"The",
"default",
"format",
"is",
"json",
"."
] | train | https://github.com/akfullfo/taskforce/blob/bc6dd744bd33546447d085dbd18a350532220193/taskforce/status.py#L85-L104 |
akfullfo/taskforce | taskforce/status.py | http.version | def version(self, path, postmap=None, **params):
"""
Return the taskforce version.
Supports standard options.
"""
q = httpd.merge_query(path, postmap)
ans = {
'taskforce': taskforce_version,
'python': '.'.join(str(x) for x in sys.version_info[:3]),
... | python | def version(self, path, postmap=None, **params):
"""
Return the taskforce version.
Supports standard options.
"""
q = httpd.merge_query(path, postmap)
ans = {
'taskforce': taskforce_version,
'python': '.'.join(str(x) for x in sys.version_info[:3]),
... | [
"def",
"version",
"(",
"self",
",",
"path",
",",
"postmap",
"=",
"None",
",",
"*",
"*",
"params",
")",
":",
"q",
"=",
"httpd",
".",
"merge_query",
"(",
"path",
",",
"postmap",
")",
"ans",
"=",
"{",
"'taskforce'",
":",
"taskforce_version",
",",
"'pyth... | Return the taskforce version.
Supports standard options. | [
"Return",
"the",
"taskforce",
"version",
"."
] | train | https://github.com/akfullfo/taskforce/blob/bc6dd744bd33546447d085dbd18a350532220193/taskforce/status.py#L106-L130 |
akfullfo/taskforce | taskforce/status.py | http.config | def config(self, path, postmap=None, **params):
"""
Return the running configuration which almost always matches the
configuration in the config file. During a reconfiguration, it may
be transitioning to the new state, in which case it will be different
to the pending config. N... | python | def config(self, path, postmap=None, **params):
"""
Return the running configuration which almost always matches the
configuration in the config file. During a reconfiguration, it may
be transitioning to the new state, in which case it will be different
to the pending config. N... | [
"def",
"config",
"(",
"self",
",",
"path",
",",
"postmap",
"=",
"None",
",",
"*",
"*",
"params",
")",
":",
"q",
"=",
"httpd",
".",
"merge_query",
"(",
"path",
",",
"postmap",
")",
"ans",
"=",
"self",
".",
"_legion",
".",
"_config_running",
"if",
"n... | Return the running configuration which almost always matches the
configuration in the config file. During a reconfiguration, it may
be transitioning to the new state, in which case it will be different
to the pending config. Neither the running or pending configurations
necessarily mat... | [
"Return",
"the",
"running",
"configuration",
"which",
"almost",
"always",
"matches",
"the",
"configuration",
"in",
"the",
"config",
"file",
".",
"During",
"a",
"reconfiguration",
"it",
"may",
"be",
"transitioning",
"to",
"the",
"new",
"state",
"in",
"which",
"... | train | https://github.com/akfullfo/taskforce/blob/bc6dd744bd33546447d085dbd18a350532220193/taskforce/status.py#L132-L150 |
akfullfo/taskforce | taskforce/status.py | http.tasks | def tasks(self, path, postmap=None, **params):
"""
Return the task status. This delves into the operating structures
and picks out information about tasks that is useful for status
monitoring.
For each task, the response includes:
control - The active task control ... | python | def tasks(self, path, postmap=None, **params):
"""
Return the task status. This delves into the operating structures
and picks out information about tasks that is useful for status
monitoring.
For each task, the response includes:
control - The active task control ... | [
"def",
"tasks",
"(",
"self",
",",
"path",
",",
"postmap",
"=",
"None",
",",
"*",
"*",
"params",
")",
":",
"q",
"=",
"httpd",
".",
"merge_query",
"(",
"path",
",",
"postmap",
")",
"ans",
"=",
"{",
"}",
"for",
"name",
",",
"tinfo",
"in",
"self",
... | Return the task status. This delves into the operating structures
and picks out information about tasks that is useful for status
monitoring.
For each task, the response includes:
control - The active task control value, whoich may have been
changed via the manag... | [
"Return",
"the",
"task",
"status",
".",
"This",
"delves",
"into",
"the",
"operating",
"structures",
"and",
"picks",
"out",
"information",
"about",
"tasks",
"that",
"is",
"useful",
"for",
"status",
"monitoring",
"."
] | train | https://github.com/akfullfo/taskforce/blob/bc6dd744bd33546447d085dbd18a350532220193/taskforce/status.py#L152-L216 |
KelSolaar/Foundations | foundations/nodes.py | AbstractNode.list_attributes | def list_attributes(self):
"""
Returns the Node attributes names.
Usage::
>>> node_a = AbstractNode("MyNodeA", attributeA=Attribute(), attributeB=Attribute())
>>> node_a.list_attributes()
['attributeB', 'attributeA']
:return: Attributes names.
... | python | def list_attributes(self):
"""
Returns the Node attributes names.
Usage::
>>> node_a = AbstractNode("MyNodeA", attributeA=Attribute(), attributeB=Attribute())
>>> node_a.list_attributes()
['attributeB', 'attributeA']
:return: Attributes names.
... | [
"def",
"list_attributes",
"(",
"self",
")",
":",
"return",
"[",
"attribute",
"for",
"attribute",
",",
"value",
"in",
"self",
".",
"iteritems",
"(",
")",
"if",
"issubclass",
"(",
"value",
".",
"__class__",
",",
"Attribute",
")",
"]"
] | Returns the Node attributes names.
Usage::
>>> node_a = AbstractNode("MyNodeA", attributeA=Attribute(), attributeB=Attribute())
>>> node_a.list_attributes()
['attributeB', 'attributeA']
:return: Attributes names.
:rtype: list | [
"Returns",
"the",
"Node",
"attributes",
"names",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/nodes.py#L436-L450 |
KelSolaar/Foundations | foundations/nodes.py | AbstractNode.get_attributes | def get_attributes(self):
"""
Returns the Node attributes.
Usage::
>>> node_a = AbstractNode("MyNodeA", attributeA=Attribute(value="A"), attributeB=Attribute(value="B"))
>>> node_a.get_attributes()
[<Attribute object at 0x7fa471d3b5e0>, <Attribute object at ... | python | def get_attributes(self):
"""
Returns the Node attributes.
Usage::
>>> node_a = AbstractNode("MyNodeA", attributeA=Attribute(value="A"), attributeB=Attribute(value="B"))
>>> node_a.get_attributes()
[<Attribute object at 0x7fa471d3b5e0>, <Attribute object at ... | [
"def",
"get_attributes",
"(",
"self",
")",
":",
"return",
"[",
"attribute",
"for",
"attribute",
"in",
"self",
".",
"itervalues",
"(",
")",
"if",
"issubclass",
"(",
"attribute",
".",
"__class__",
",",
"Attribute",
")",
"]"
] | Returns the Node attributes.
Usage::
>>> node_a = AbstractNode("MyNodeA", attributeA=Attribute(value="A"), attributeB=Attribute(value="B"))
>>> node_a.get_attributes()
[<Attribute object at 0x7fa471d3b5e0>, <Attribute object at 0x101e6c4a0>]
:return: Attributes.
... | [
"Returns",
"the",
"Node",
"attributes",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/nodes.py#L452-L466 |
KelSolaar/Foundations | foundations/nodes.py | AbstractNode.attribute_exists | def attribute_exists(self, name):
"""
Returns if given attribute exists in the node.
Usage::
>>> node_a = AbstractNode("MyNodeA", attributeA=Attribute(), attributeB=Attribute())
>>> node_a.attribute_exists("attributeA")
True
>>> node_a.attribute_... | python | def attribute_exists(self, name):
"""
Returns if given attribute exists in the node.
Usage::
>>> node_a = AbstractNode("MyNodeA", attributeA=Attribute(), attributeB=Attribute())
>>> node_a.attribute_exists("attributeA")
True
>>> node_a.attribute_... | [
"def",
"attribute_exists",
"(",
"self",
",",
"name",
")",
":",
"if",
"name",
"in",
"self",
":",
"if",
"issubclass",
"(",
"self",
"[",
"name",
"]",
".",
"__class__",
",",
"Attribute",
")",
":",
"return",
"True",
"return",
"False"
] | Returns if given attribute exists in the node.
Usage::
>>> node_a = AbstractNode("MyNodeA", attributeA=Attribute(), attributeB=Attribute())
>>> node_a.attribute_exists("attributeA")
True
>>> node_a.attribute_exists("attributeC")
False
:param... | [
"Returns",
"if",
"given",
"attribute",
"exists",
"in",
"the",
"node",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/nodes.py#L468-L489 |
KelSolaar/Foundations | foundations/nodes.py | AbstractNode.add_attribute | def add_attribute(self, name, value):
"""
Adds given attribute to the node.
Usage::
>>> node_a = AbstractNode()
>>> node_a.add_attribute("attributeA", Attribute())
True
>>> node_a.list_attributes()
[u'attributeA']
:param name... | python | def add_attribute(self, name, value):
"""
Adds given attribute to the node.
Usage::
>>> node_a = AbstractNode()
>>> node_a.add_attribute("attributeA", Attribute())
True
>>> node_a.list_attributes()
[u'attributeA']
:param name... | [
"def",
"add_attribute",
"(",
"self",
",",
"name",
",",
"value",
")",
":",
"if",
"not",
"issubclass",
"(",
"value",
".",
"__class__",
",",
"Attribute",
")",
":",
"raise",
"foundations",
".",
"exceptions",
".",
"NodeAttributeTypeError",
"(",
"\"Node attribute va... | Adds given attribute to the node.
Usage::
>>> node_a = AbstractNode()
>>> node_a.add_attribute("attributeA", Attribute())
True
>>> node_a.list_attributes()
[u'attributeA']
:param name: Attribute name.
:type name: unicode
:par... | [
"Adds",
"given",
"attribute",
"to",
"the",
"node",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/nodes.py#L492-L520 |
KelSolaar/Foundations | foundations/nodes.py | AbstractNode.remove_attribute | def remove_attribute(self, name):
"""
Removes given attribute from the node.
Usage::
>>> node_a = AbstractNode("MyNodeA", attributeA=Attribute(), attributeB=Attribute())
>>> node_a.remove_attribute("attributeA")
True
>>> node_a.list_attributes()
... | python | def remove_attribute(self, name):
"""
Removes given attribute from the node.
Usage::
>>> node_a = AbstractNode("MyNodeA", attributeA=Attribute(), attributeB=Attribute())
>>> node_a.remove_attribute("attributeA")
True
>>> node_a.list_attributes()
... | [
"def",
"remove_attribute",
"(",
"self",
",",
"name",
")",
":",
"if",
"not",
"self",
".",
"attribute_exists",
"(",
"name",
")",
":",
"raise",
"foundations",
".",
"exceptions",
".",
"NodeAttributeExistsError",
"(",
"\"Node attribute '{0}' doesn't exists!\"",
".",
"f... | Removes given attribute from the node.
Usage::
>>> node_a = AbstractNode("MyNodeA", attributeA=Attribute(), attributeB=Attribute())
>>> node_a.remove_attribute("attributeA")
True
>>> node_a.list_attributes()
['attributeB']
:param name: Attri... | [
"Removes",
"given",
"attribute",
"from",
"the",
"node",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/nodes.py#L523-L545 |
KelSolaar/Foundations | foundations/nodes.py | AbstractCompositeNode.parent | def parent(self, value):
"""
Setter for **self.__parent** attribute.
:param value: Attribute value.
:type value: AbstractNode or AbstractCompositeNode
"""
if value is not None:
assert issubclass(value.__class__, AbstractNode), "'{0}' attribute: '{1}' is not ... | python | def parent(self, value):
"""
Setter for **self.__parent** attribute.
:param value: Attribute value.
:type value: AbstractNode or AbstractCompositeNode
"""
if value is not None:
assert issubclass(value.__class__, AbstractNode), "'{0}' attribute: '{1}' is not ... | [
"def",
"parent",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"is",
"not",
"None",
":",
"assert",
"issubclass",
"(",
"value",
".",
"__class__",
",",
"AbstractNode",
")",
",",
"\"'{0}' attribute: '{1}' is not a '{2}' subclass!\"",
".",
"format",
"(",
"\"... | Setter for **self.__parent** attribute.
:param value: Attribute value.
:type value: AbstractNode or AbstractCompositeNode | [
"Setter",
"for",
"**",
"self",
".",
"__parent",
"**",
"attribute",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/nodes.py#L601-L612 |
KelSolaar/Foundations | foundations/nodes.py | AbstractCompositeNode.children | def children(self, value):
"""
Setter for **self.__children** attribute.
:param value: Attribute value.
:type value: list
"""
if value is not None:
assert type(value) is list, "'{0}' attribute: '{1}' type is not 'list'!".format("children", value)
... | python | def children(self, value):
"""
Setter for **self.__children** attribute.
:param value: Attribute value.
:type value: list
"""
if value is not None:
assert type(value) is list, "'{0}' attribute: '{1}' type is not 'list'!".format("children", value)
... | [
"def",
"children",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"is",
"not",
"None",
":",
"assert",
"type",
"(",
"value",
")",
"is",
"list",
",",
"\"'{0}' attribute: '{1}' type is not 'list'!\"",
".",
"format",
"(",
"\"children\"",
",",
"value",
")",
... | Setter for **self.__children** attribute.
:param value: Attribute value.
:type value: list | [
"Setter",
"for",
"**",
"self",
".",
"__children",
"**",
"attribute",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/nodes.py#L637-L651 |
KelSolaar/Foundations | foundations/nodes.py | AbstractCompositeNode.child | def child(self, index):
"""
Returns the child associated with given index.
Usage::
>>> node_b = AbstractCompositeNode("MyNodeB")
>>> node_c = AbstractCompositeNode("MyNodeC")
>>> node_a = AbstractCompositeNode("MyNodeA", children=[node_b, node_c])
... | python | def child(self, index):
"""
Returns the child associated with given index.
Usage::
>>> node_b = AbstractCompositeNode("MyNodeB")
>>> node_c = AbstractCompositeNode("MyNodeC")
>>> node_a = AbstractCompositeNode("MyNodeA", children=[node_b, node_c])
... | [
"def",
"child",
"(",
"self",
",",
"index",
")",
":",
"if",
"not",
"self",
".",
"__children",
":",
"return",
"if",
"index",
">=",
"0",
"and",
"index",
"<",
"len",
"(",
"self",
".",
"__children",
")",
":",
"return",
"self",
".",
"__children",
"[",
"i... | Returns the child associated with given index.
Usage::
>>> node_b = AbstractCompositeNode("MyNodeB")
>>> node_c = AbstractCompositeNode("MyNodeC")
>>> node_a = AbstractCompositeNode("MyNodeA", children=[node_b, node_c])
>>> node_a.child(0)
<AbstractC... | [
"Returns",
"the",
"child",
"associated",
"with",
"given",
"index",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/nodes.py#L681-L705 |
KelSolaar/Foundations | foundations/nodes.py | AbstractCompositeNode.index_of | def index_of(self, child):
"""
Returns the given child index.
Usage::
>>> node_a = AbstractCompositeNode("MyNodeA")
>>> node_b = AbstractCompositeNode("MyNodeB", node_a)
>>> node_c = AbstractCompositeNode("MyNodeC", node_a)
>>> node_a.index_of(no... | python | def index_of(self, child):
"""
Returns the given child index.
Usage::
>>> node_a = AbstractCompositeNode("MyNodeA")
>>> node_b = AbstractCompositeNode("MyNodeB", node_a)
>>> node_c = AbstractCompositeNode("MyNodeC", node_a)
>>> node_a.index_of(no... | [
"def",
"index_of",
"(",
"self",
",",
"child",
")",
":",
"for",
"i",
",",
"item",
"in",
"enumerate",
"(",
"self",
".",
"__children",
")",
":",
"if",
"child",
"is",
"item",
":",
"return",
"i"
] | Returns the given child index.
Usage::
>>> node_a = AbstractCompositeNode("MyNodeA")
>>> node_b = AbstractCompositeNode("MyNodeB", node_a)
>>> node_c = AbstractCompositeNode("MyNodeC", node_a)
>>> node_a.index_of(node_b)
0
>>> node_a.inde... | [
"Returns",
"the",
"given",
"child",
"index",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/nodes.py#L707-L729 |
KelSolaar/Foundations | foundations/nodes.py | AbstractCompositeNode.add_child | def add_child(self, child):
"""
Adds given child to the node.
Usage::
>>> node_a = AbstractCompositeNode("MyNodeA")
>>> node_b = AbstractCompositeNode("MyNodeB")
>>> node_a.add_child(node_b)
True
>>> node_a.children
[<Abst... | python | def add_child(self, child):
"""
Adds given child to the node.
Usage::
>>> node_a = AbstractCompositeNode("MyNodeA")
>>> node_b = AbstractCompositeNode("MyNodeB")
>>> node_a.add_child(node_b)
True
>>> node_a.children
[<Abst... | [
"def",
"add_child",
"(",
"self",
",",
"child",
")",
":",
"self",
".",
"__children",
".",
"append",
"(",
"child",
")",
"child",
".",
"parent",
"=",
"self",
"return",
"True"
] | Adds given child to the node.
Usage::
>>> node_a = AbstractCompositeNode("MyNodeA")
>>> node_b = AbstractCompositeNode("MyNodeB")
>>> node_a.add_child(node_b)
True
>>> node_a.children
[<AbstractCompositeNode object at 0x10107afe0>]
... | [
"Adds",
"given",
"child",
"to",
"the",
"node",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/nodes.py#L752-L773 |
KelSolaar/Foundations | foundations/nodes.py | AbstractCompositeNode.remove_child | def remove_child(self, index):
"""
Removes child at given index from the Node children.
Usage::
>>> node_a = AbstractCompositeNode("MyNodeA")
>>> node_b = AbstractCompositeNode("MyNodeB", node_a)
>>> node_c = AbstractCompositeNode("MyNodeC", node_a)
... | python | def remove_child(self, index):
"""
Removes child at given index from the Node children.
Usage::
>>> node_a = AbstractCompositeNode("MyNodeA")
>>> node_b = AbstractCompositeNode("MyNodeB", node_a)
>>> node_c = AbstractCompositeNode("MyNodeC", node_a)
... | [
"def",
"remove_child",
"(",
"self",
",",
"index",
")",
":",
"if",
"index",
"<",
"0",
"or",
"index",
">",
"len",
"(",
"self",
".",
"__children",
")",
":",
"return",
"child",
"=",
"self",
".",
"__children",
".",
"pop",
"(",
"index",
")",
"child",
"."... | Removes child at given index from the Node children.
Usage::
>>> node_a = AbstractCompositeNode("MyNodeA")
>>> node_b = AbstractCompositeNode("MyNodeB", node_a)
>>> node_c = AbstractCompositeNode("MyNodeC", node_a)
>>> node_a.remove_child(1)
True
... | [
"Removes",
"child",
"at",
"given",
"index",
"from",
"the",
"Node",
"children",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/nodes.py#L775-L800 |
KelSolaar/Foundations | foundations/nodes.py | AbstractCompositeNode.insert_child | def insert_child(self, child, index):
"""
Inserts given child at given index.
Usage::
>>> node_a = AbstractCompositeNode("MyNodeA")
>>> node_b = AbstractCompositeNode("MyNodeB", node_a)
>>> node_c = AbstractCompositeNode("MyNodeC", node_a)
>>> no... | python | def insert_child(self, child, index):
"""
Inserts given child at given index.
Usage::
>>> node_a = AbstractCompositeNode("MyNodeA")
>>> node_b = AbstractCompositeNode("MyNodeB", node_a)
>>> node_c = AbstractCompositeNode("MyNodeC", node_a)
>>> no... | [
"def",
"insert_child",
"(",
"self",
",",
"child",
",",
"index",
")",
":",
"if",
"index",
"<",
"0",
"or",
"index",
">",
"len",
"(",
"self",
".",
"__children",
")",
":",
"return",
"False",
"self",
".",
"__children",
".",
"insert",
"(",
"index",
",",
... | Inserts given child at given index.
Usage::
>>> node_a = AbstractCompositeNode("MyNodeA")
>>> node_b = AbstractCompositeNode("MyNodeB", node_a)
>>> node_c = AbstractCompositeNode("MyNodeC", node_a)
>>> node_d = AbstractCompositeNode("MyNodeD")
>>> no... | [
"Inserts",
"given",
"child",
"at",
"given",
"index",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/nodes.py#L802-L830 |
KelSolaar/Foundations | foundations/nodes.py | AbstractCompositeNode.sort_children | def sort_children(self, attribute=None, reverse_order=False):
"""
Sorts the children using either the given attribute or the Node name.
:param attribute: Attribute name used for sorting.
:type attribute: unicode
:param reverse_order: Sort in reverse order.
:type reverse_... | python | def sort_children(self, attribute=None, reverse_order=False):
"""
Sorts the children using either the given attribute or the Node name.
:param attribute: Attribute name used for sorting.
:type attribute: unicode
:param reverse_order: Sort in reverse order.
:type reverse_... | [
"def",
"sort_children",
"(",
"self",
",",
"attribute",
"=",
"None",
",",
"reverse_order",
"=",
"False",
")",
":",
"sorted_children",
"=",
"[",
"]",
"if",
"attribute",
":",
"sortable_children",
"=",
"[",
"]",
"unsortable_children",
"=",
"[",
"]",
"for",
"ch... | Sorts the children using either the given attribute or the Node name.
:param attribute: Attribute name used for sorting.
:type attribute: unicode
:param reverse_order: Sort in reverse order.
:type reverse_order: bool
:return: Method success.
:rtype: bool | [
"Sorts",
"the",
"children",
"using",
"either",
"the",
"given",
"attribute",
"or",
"the",
"Node",
"name",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/nodes.py#L866-L898 |
KelSolaar/Foundations | foundations/nodes.py | AbstractCompositeNode.find_children | def find_children(self, pattern=r".*", flags=0, candidates=None):
"""
Finds the children matching the given patten.
Usage::
>>> node_a = AbstractCompositeNode("MyNodeA")
>>> node_b = AbstractCompositeNode("MyNodeB", node_a)
>>> node_c = AbstractCompositeNode... | python | def find_children(self, pattern=r".*", flags=0, candidates=None):
"""
Finds the children matching the given patten.
Usage::
>>> node_a = AbstractCompositeNode("MyNodeA")
>>> node_b = AbstractCompositeNode("MyNodeB", node_a)
>>> node_c = AbstractCompositeNode... | [
"def",
"find_children",
"(",
"self",
",",
"pattern",
"=",
"r\".*\"",
",",
"flags",
"=",
"0",
",",
"candidates",
"=",
"None",
")",
":",
"if",
"candidates",
"is",
"None",
":",
"candidates",
"=",
"[",
"]",
"for",
"child",
"in",
"self",
".",
"__children",
... | Finds the children matching the given patten.
Usage::
>>> node_a = AbstractCompositeNode("MyNodeA")
>>> node_b = AbstractCompositeNode("MyNodeB", node_a)
>>> node_c = AbstractCompositeNode("MyNodeC", node_a)
>>> node_a.find_children("c", re.IGNORECASE)
... | [
"Finds",
"the",
"children",
"matching",
"the",
"given",
"patten",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/nodes.py#L900-L929 |
KelSolaar/Foundations | foundations/nodes.py | AbstractCompositeNode.find_family | def find_family(self, pattern=r".*", flags=0, node=None):
"""
Returns the Nodes from given family.
:param pattern: Matching pattern.
:type pattern: unicode
:param flags: Matching regex flags.
:type flags: int
:param node: Node to start walking from.
:type... | python | def find_family(self, pattern=r".*", flags=0, node=None):
"""
Returns the Nodes from given family.
:param pattern: Matching pattern.
:type pattern: unicode
:param flags: Matching regex flags.
:type flags: int
:param node: Node to start walking from.
:type... | [
"def",
"find_family",
"(",
"self",
",",
"pattern",
"=",
"r\".*\"",
",",
"flags",
"=",
"0",
",",
"node",
"=",
"None",
")",
":",
"return",
"[",
"node",
"for",
"node",
"in",
"foundations",
".",
"walkers",
".",
"nodes_walker",
"(",
"node",
"or",
"self",
... | Returns the Nodes from given family.
:param pattern: Matching pattern.
:type pattern: unicode
:param flags: Matching regex flags.
:type flags: int
:param node: Node to start walking from.
:type node: AbstractNode or AbstractCompositeNode or Object
:return: Family... | [
"Returns",
"the",
"Nodes",
"from",
"given",
"family",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/nodes.py#L931-L946 |
KelSolaar/Foundations | foundations/nodes.py | AbstractCompositeNode.list_node | def list_node(self, tab_level=-1):
"""
Lists the current Node and its children.
Usage::
>>> node_a = AbstractCompositeNode("MyNodeA")
>>> node_b = AbstractCompositeNode("MyNodeB", node_a)
>>> node_c = AbstractCompositeNode("MyNodeC", node_a)
>>> ... | python | def list_node(self, tab_level=-1):
"""
Lists the current Node and its children.
Usage::
>>> node_a = AbstractCompositeNode("MyNodeA")
>>> node_b = AbstractCompositeNode("MyNodeB", node_a)
>>> node_c = AbstractCompositeNode("MyNodeC", node_a)
>>> ... | [
"def",
"list_node",
"(",
"self",
",",
"tab_level",
"=",
"-",
"1",
")",
":",
"output",
"=",
"\"\"",
"tab_level",
"+=",
"1",
"for",
"i",
"in",
"range",
"(",
"tab_level",
")",
":",
"output",
"+=",
"\"\\t\"",
"output",
"+=",
"\"|----'{0}'\\n\"",
".",
"form... | Lists the current Node and its children.
Usage::
>>> node_a = AbstractCompositeNode("MyNodeA")
>>> node_b = AbstractCompositeNode("MyNodeB", node_a)
>>> node_c = AbstractCompositeNode("MyNodeC", node_a)
>>> print node_a.list_node()
|----'MyNodeA'
... | [
"Lists",
"the",
"current",
"Node",
"and",
"its",
"children",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/nodes.py#L948-L976 |
bretth/woven | woven/linux.py | add_repositories | def add_repositories():
"""
Adds additional sources as defined in LINUX_PACKAGE_REPOSITORIES.
"""
if not env.overwrite and env.LINUX_PACKAGE_REPOSITORIES == server_state('linux_package_repositories'): return
if env.verbosity:
print env.host, "UNCOMMENTING SOURCES in /etc/apt/sources.list an... | python | def add_repositories():
"""
Adds additional sources as defined in LINUX_PACKAGE_REPOSITORIES.
"""
if not env.overwrite and env.LINUX_PACKAGE_REPOSITORIES == server_state('linux_package_repositories'): return
if env.verbosity:
print env.host, "UNCOMMENTING SOURCES in /etc/apt/sources.list an... | [
"def",
"add_repositories",
"(",
")",
":",
"if",
"not",
"env",
".",
"overwrite",
"and",
"env",
".",
"LINUX_PACKAGE_REPOSITORIES",
"==",
"server_state",
"(",
"'linux_package_repositories'",
")",
":",
"return",
"if",
"env",
".",
"verbosity",
":",
"print",
"env",
... | Adds additional sources as defined in LINUX_PACKAGE_REPOSITORIES. | [
"Adds",
"additional",
"sources",
"as",
"defined",
"in",
"LINUX_PACKAGE_REPOSITORIES",
"."
] | train | https://github.com/bretth/woven/blob/ec1da7b401a335f43129e7115fe7a4d145649f1e/woven/linux.py#L34-L51 |
bretth/woven | woven/linux.py | add_user | def add_user(username='',password='',group='', site_user=False):
"""
Adds the username
"""
if group: group = '-g %s'% group
if not site_user:
run('echo %s:%s > /tmp/users.txt'% (username,password))
if not site_user:
sudo('useradd -m -s /bin/bash %s %s'% (group,username))
... | python | def add_user(username='',password='',group='', site_user=False):
"""
Adds the username
"""
if group: group = '-g %s'% group
if not site_user:
run('echo %s:%s > /tmp/users.txt'% (username,password))
if not site_user:
sudo('useradd -m -s /bin/bash %s %s'% (group,username))
... | [
"def",
"add_user",
"(",
"username",
"=",
"''",
",",
"password",
"=",
"''",
",",
"group",
"=",
"''",
",",
"site_user",
"=",
"False",
")",
":",
"if",
"group",
":",
"group",
"=",
"'-g %s'",
"%",
"group",
"if",
"not",
"site_user",
":",
"run",
"(",
"'ec... | Adds the username | [
"Adds",
"the",
"username"
] | train | https://github.com/bretth/woven/blob/ec1da7b401a335f43129e7115fe7a4d145649f1e/woven/linux.py#L53-L66 |
bretth/woven | woven/linux.py | change_ssh_port | def change_ssh_port():
"""
For security woven changes the default ssh port.
"""
host = normalize(env.host_string)[1]
after = env.port
before = str(env.DEFAULT_SSH_PORT)
host_string=join_host_strings(env.user,host,before)
with settings(host_string=host_string, user=env.user):
... | python | def change_ssh_port():
"""
For security woven changes the default ssh port.
"""
host = normalize(env.host_string)[1]
after = env.port
before = str(env.DEFAULT_SSH_PORT)
host_string=join_host_strings(env.user,host,before)
with settings(host_string=host_string, user=env.user):
... | [
"def",
"change_ssh_port",
"(",
")",
":",
"host",
"=",
"normalize",
"(",
"env",
".",
"host_string",
")",
"[",
"1",
"]",
"after",
"=",
"env",
".",
"port",
"before",
"=",
"str",
"(",
"env",
".",
"DEFAULT_SSH_PORT",
")",
"host_string",
"=",
"join_host_string... | For security woven changes the default ssh port. | [
"For",
"security",
"woven",
"changes",
"the",
"default",
"ssh",
"port",
"."
] | train | https://github.com/bretth/woven/blob/ec1da7b401a335f43129e7115fe7a4d145649f1e/woven/linux.py#L68-L88 |
bretth/woven | woven/linux.py | disable_root | def disable_root():
"""
Disables root and creates a new sudo user as specified by HOST_USER in your
settings or your host_string
The normal pattern for hosting is to get a root account which is then disabled.
returns True on success
"""
def enter_password():
password1 ... | python | def disable_root():
"""
Disables root and creates a new sudo user as specified by HOST_USER in your
settings or your host_string
The normal pattern for hosting is to get a root account which is then disabled.
returns True on success
"""
def enter_password():
password1 ... | [
"def",
"disable_root",
"(",
")",
":",
"def",
"enter_password",
"(",
")",
":",
"password1",
"=",
"getpass",
".",
"getpass",
"(",
"prompt",
"=",
"'Enter the password for %s:'",
"%",
"sudo_user",
")",
"password2",
"=",
"getpass",
".",
"getpass",
"(",
"prompt",
... | Disables root and creates a new sudo user as specified by HOST_USER in your
settings or your host_string
The normal pattern for hosting is to get a root account which is then disabled.
returns True on success | [
"Disables",
"root",
"and",
"creates",
"a",
"new",
"sudo",
"user",
"as",
"specified",
"by",
"HOST_USER",
"in",
"your",
"settings",
"or",
"your",
"host_string",
"The",
"normal",
"pattern",
"for",
"hosting",
"is",
"to",
"get",
"a",
"root",
"account",
"which",
... | train | https://github.com/bretth/woven/blob/ec1da7b401a335f43129e7115fe7a4d145649f1e/woven/linux.py#L90-L177 |
bretth/woven | woven/linux.py | install_packages | def install_packages():
"""
Install a set of baseline packages and configure where necessary
"""
if env.verbosity:
print env.host, "INSTALLING & CONFIGURING NODE PACKAGES:"
#Get a list of installed packages
p = run("dpkg -l | awk '/ii/ {print $2}'").split('\n')
#Remove apparmor... | python | def install_packages():
"""
Install a set of baseline packages and configure where necessary
"""
if env.verbosity:
print env.host, "INSTALLING & CONFIGURING NODE PACKAGES:"
#Get a list of installed packages
p = run("dpkg -l | awk '/ii/ {print $2}'").split('\n')
#Remove apparmor... | [
"def",
"install_packages",
"(",
")",
":",
"if",
"env",
".",
"verbosity",
":",
"print",
"env",
".",
"host",
",",
"\"INSTALLING & CONFIGURING NODE PACKAGES:\"",
"#Get a list of installed packages",
"p",
"=",
"run",
"(",
"\"dpkg -l | awk '/ii/ {print $2}'\"",
")",
".",
"... | Install a set of baseline packages and configure where necessary | [
"Install",
"a",
"set",
"of",
"baseline",
"packages",
"and",
"configure",
"where",
"necessary"
] | train | https://github.com/bretth/woven/blob/ec1da7b401a335f43129e7115fe7a4d145649f1e/woven/linux.py#L186-L242 |
bretth/woven | woven/linux.py | lsb_release | def lsb_release():
"""
Get the linux distribution information and return in an attribute dict
The following attributes should be available:
base, distributor_id, description, release, codename
For example Ubuntu Lucid would return
base = debian
distributor_id = Ubuntu
descripti... | python | def lsb_release():
"""
Get the linux distribution information and return in an attribute dict
The following attributes should be available:
base, distributor_id, description, release, codename
For example Ubuntu Lucid would return
base = debian
distributor_id = Ubuntu
descripti... | [
"def",
"lsb_release",
"(",
")",
":",
"output",
"=",
"run",
"(",
"'lsb_release -a'",
")",
".",
"split",
"(",
"'\\n'",
")",
"release",
"=",
"_AttributeDict",
"(",
"{",
"}",
")",
"for",
"line",
"in",
"output",
":",
"try",
":",
"key",
",",
"value",
"=",
... | Get the linux distribution information and return in an attribute dict
The following attributes should be available:
base, distributor_id, description, release, codename
For example Ubuntu Lucid would return
base = debian
distributor_id = Ubuntu
description = Ubuntu 10.04.x LTS
rel... | [
"Get",
"the",
"linux",
"distribution",
"information",
"and",
"return",
"in",
"an",
"attribute",
"dict",
"The",
"following",
"attributes",
"should",
"be",
"available",
":",
"base",
"distributor_id",
"description",
"release",
"codename",
"For",
"example",
"Ubuntu",
... | train | https://github.com/bretth/woven/blob/ec1da7b401a335f43129e7115fe7a4d145649f1e/woven/linux.py#L244-L272 |
bretth/woven | woven/linux.py | port_is_open | def port_is_open():
"""
Determine if the default port and user is open for business.
"""
with settings(hide('aborts'), warn_only=True ):
try:
if env.verbosity:
print "Testing node for previous installation on port %s:"% env.port
distribution = lsb_release(... | python | def port_is_open():
"""
Determine if the default port and user is open for business.
"""
with settings(hide('aborts'), warn_only=True ):
try:
if env.verbosity:
print "Testing node for previous installation on port %s:"% env.port
distribution = lsb_release(... | [
"def",
"port_is_open",
"(",
")",
":",
"with",
"settings",
"(",
"hide",
"(",
"'aborts'",
")",
",",
"warn_only",
"=",
"True",
")",
":",
"try",
":",
"if",
"env",
".",
"verbosity",
":",
"print",
"\"Testing node for previous installation on port %s:\"",
"%",
"env",... | Determine if the default port and user is open for business. | [
"Determine",
"if",
"the",
"default",
"port",
"and",
"user",
"is",
"open",
"for",
"business",
"."
] | train | https://github.com/bretth/woven/blob/ec1da7b401a335f43129e7115fe7a4d145649f1e/woven/linux.py#L274-L291 |
bretth/woven | woven/linux.py | restrict_ssh | def restrict_ssh(rollback=False):
"""
Set some sensible restrictions in Ubuntu /etc/ssh/sshd_config and restart sshd
UseDNS no #prevents dns spoofing sshd defaults to yes
X11Forwarding no # defaults to no
AuthorizedKeysFile %h/.ssh/authorized_keys
uncomments PasswordAuthentication no and resta... | python | def restrict_ssh(rollback=False):
"""
Set some sensible restrictions in Ubuntu /etc/ssh/sshd_config and restart sshd
UseDNS no #prevents dns spoofing sshd defaults to yes
X11Forwarding no # defaults to no
AuthorizedKeysFile %h/.ssh/authorized_keys
uncomments PasswordAuthentication no and resta... | [
"def",
"restrict_ssh",
"(",
"rollback",
"=",
"False",
")",
":",
"if",
"not",
"rollback",
":",
"if",
"server_state",
"(",
"'ssh_restricted'",
")",
":",
"return",
"False",
"sshd_config",
"=",
"'/etc/ssh/sshd_config'",
"if",
"env",
".",
"verbosity",
":",
"print",... | Set some sensible restrictions in Ubuntu /etc/ssh/sshd_config and restart sshd
UseDNS no #prevents dns spoofing sshd defaults to yes
X11Forwarding no # defaults to no
AuthorizedKeysFile %h/.ssh/authorized_keys
uncomments PasswordAuthentication no and restarts sshd | [
"Set",
"some",
"sensible",
"restrictions",
"in",
"Ubuntu",
"/",
"etc",
"/",
"ssh",
"/",
"sshd_config",
"and",
"restart",
"sshd",
"UseDNS",
"no",
"#prevents",
"dns",
"spoofing",
"sshd",
"defaults",
"to",
"yes",
"X11Forwarding",
"no",
"#",
"defaults",
"to",
"n... | train | https://github.com/bretth/woven/blob/ec1da7b401a335f43129e7115fe7a4d145649f1e/woven/linux.py#L293-L341 |
bretth/woven | woven/linux.py | set_timezone | def set_timezone(rollback=False):
"""
Set the time zone on the server using Django settings.TIME_ZONE
"""
if not rollback:
if contains(filename='/etc/timezone', text=env.TIME_ZONE, use_sudo=True):
return False
if env.verbosity:
print env.host, "CHANGING TIMEZONE /... | python | def set_timezone(rollback=False):
"""
Set the time zone on the server using Django settings.TIME_ZONE
"""
if not rollback:
if contains(filename='/etc/timezone', text=env.TIME_ZONE, use_sudo=True):
return False
if env.verbosity:
print env.host, "CHANGING TIMEZONE /... | [
"def",
"set_timezone",
"(",
"rollback",
"=",
"False",
")",
":",
"if",
"not",
"rollback",
":",
"if",
"contains",
"(",
"filename",
"=",
"'/etc/timezone'",
",",
"text",
"=",
"env",
".",
"TIME_ZONE",
",",
"use_sudo",
"=",
"True",
")",
":",
"return",
"False",... | Set the time zone on the server using Django settings.TIME_ZONE | [
"Set",
"the",
"time",
"zone",
"on",
"the",
"server",
"using",
"Django",
"settings",
".",
"TIME_ZONE"
] | train | https://github.com/bretth/woven/blob/ec1da7b401a335f43129e7115fe7a4d145649f1e/woven/linux.py#L343-L359 |
bretth/woven | woven/linux.py | setup_ufw | def setup_ufw():
"""
Setup basic ufw rules just for ssh login
"""
if not env.ENABLE_UFW: return
ufw_state = server_state('ufw_installed')
if ufw_state and not env.overwrite or ufw_state == str(env.HOST_SSH_PORT): return
#check for actual package
ufw = run("dpkg -l | grep 'ufw' | awk ... | python | def setup_ufw():
"""
Setup basic ufw rules just for ssh login
"""
if not env.ENABLE_UFW: return
ufw_state = server_state('ufw_installed')
if ufw_state and not env.overwrite or ufw_state == str(env.HOST_SSH_PORT): return
#check for actual package
ufw = run("dpkg -l | grep 'ufw' | awk ... | [
"def",
"setup_ufw",
"(",
")",
":",
"if",
"not",
"env",
".",
"ENABLE_UFW",
":",
"return",
"ufw_state",
"=",
"server_state",
"(",
"'ufw_installed'",
")",
"if",
"ufw_state",
"and",
"not",
"env",
".",
"overwrite",
"or",
"ufw_state",
"==",
"str",
"(",
"env",
... | Setup basic ufw rules just for ssh login | [
"Setup",
"basic",
"ufw",
"rules",
"just",
"for",
"ssh",
"login"
] | train | https://github.com/bretth/woven/blob/ec1da7b401a335f43129e7115fe7a4d145649f1e/woven/linux.py#L361-L400 |
bretth/woven | woven/linux.py | setup_ufw_rules | def setup_ufw_rules():
"""
Setup ufw app rules from application templates and settings UFW_RULES
"""
#current rules
current_rules = server_state('ufw_rules')
if current_rules: current_rules = set(current_rules)
else: current_rules = set([])
role = env.role_lookup[env.host_string]
... | python | def setup_ufw_rules():
"""
Setup ufw app rules from application templates and settings UFW_RULES
"""
#current rules
current_rules = server_state('ufw_rules')
if current_rules: current_rules = set(current_rules)
else: current_rules = set([])
role = env.role_lookup[env.host_string]
... | [
"def",
"setup_ufw_rules",
"(",
")",
":",
"#current rules",
"current_rules",
"=",
"server_state",
"(",
"'ufw_rules'",
")",
"if",
"current_rules",
":",
"current_rules",
"=",
"set",
"(",
"current_rules",
")",
"else",
":",
"current_rules",
"=",
"set",
"(",
"[",
"]... | Setup ufw app rules from application templates and settings UFW_RULES | [
"Setup",
"ufw",
"app",
"rules",
"from",
"application",
"templates",
"and",
"settings",
"UFW_RULES"
] | train | https://github.com/bretth/woven/blob/ec1da7b401a335f43129e7115fe7a4d145649f1e/woven/linux.py#L402-L435 |
bretth/woven | woven/linux.py | uninstall_packages | def uninstall_packages():
"""
Uninstall unwanted packages
"""
p = server_state('packages_installed')
if p: installed = set(p)
else: return
env.uninstalled_packages[env.host] = []
#first uninstall any that have been taken off the list
packages = set(get_packages())
uninstall = ins... | python | def uninstall_packages():
"""
Uninstall unwanted packages
"""
p = server_state('packages_installed')
if p: installed = set(p)
else: return
env.uninstalled_packages[env.host] = []
#first uninstall any that have been taken off the list
packages = set(get_packages())
uninstall = ins... | [
"def",
"uninstall_packages",
"(",
")",
":",
"p",
"=",
"server_state",
"(",
"'packages_installed'",
")",
"if",
"p",
":",
"installed",
"=",
"set",
"(",
"p",
")",
"else",
":",
"return",
"env",
".",
"uninstalled_packages",
"[",
"env",
".",
"host",
"]",
"=",
... | Uninstall unwanted packages | [
"Uninstall",
"unwanted",
"packages"
] | train | https://github.com/bretth/woven/blob/ec1da7b401a335f43129e7115fe7a4d145649f1e/woven/linux.py#L448-L467 |
bretth/woven | woven/linux.py | upgrade_packages | def upgrade_packages():
"""
apt-get update and apt-get upgrade
"""
if env.verbosity:
print env.host, "apt-get UPDATING and UPGRADING SERVER PACKAGES"
print " * running apt-get update "
sudo('apt-get -qqy update')
if env.verbosity:
print " * running apt-get upgrade"
... | python | def upgrade_packages():
"""
apt-get update and apt-get upgrade
"""
if env.verbosity:
print env.host, "apt-get UPDATING and UPGRADING SERVER PACKAGES"
print " * running apt-get update "
sudo('apt-get -qqy update')
if env.verbosity:
print " * running apt-get upgrade"
... | [
"def",
"upgrade_packages",
"(",
")",
":",
"if",
"env",
".",
"verbosity",
":",
"print",
"env",
".",
"host",
",",
"\"apt-get UPDATING and UPGRADING SERVER PACKAGES\"",
"print",
"\" * running apt-get update \"",
"sudo",
"(",
"'apt-get -qqy update'",
")",
"if",
"env",
"."... | apt-get update and apt-get upgrade | [
"apt",
"-",
"get",
"update",
"and",
"apt",
"-",
"get",
"upgrade"
] | train | https://github.com/bretth/woven/blob/ec1da7b401a335f43129e7115fe7a4d145649f1e/woven/linux.py#L469-L482 |
bretth/woven | woven/linux.py | upload_etc | def upload_etc():
"""
Upload and render all templates in the woven/etc directory to the respective directories on the nodes
Only configuration for installed packages will be uploaded where that package creates it's own subdirectory
in /etc/ ie /etc/apache2.
For configuration that falls in ... | python | def upload_etc():
"""
Upload and render all templates in the woven/etc directory to the respective directories on the nodes
Only configuration for installed packages will be uploaded where that package creates it's own subdirectory
in /etc/ ie /etc/apache2.
For configuration that falls in ... | [
"def",
"upload_etc",
"(",
")",
":",
"role",
"=",
"env",
".",
"role_lookup",
"[",
"env",
".",
"host_string",
"]",
"packages",
"=",
"env",
".",
"packages",
"[",
"role",
"]",
"#determine the templatedir",
"if",
"env",
".",
"verbosity",
":",
"print",
"\"UPLOAD... | Upload and render all templates in the woven/etc directory to the respective directories on the nodes
Only configuration for installed packages will be uploaded where that package creates it's own subdirectory
in /etc/ ie /etc/apache2.
For configuration that falls in some other non package directo... | [
"Upload",
"and",
"render",
"all",
"templates",
"in",
"the",
"woven",
"/",
"etc",
"directory",
"to",
"the",
"respective",
"directories",
"on",
"the",
"nodes",
"Only",
"configuration",
"for",
"installed",
"packages",
"will",
"be",
"uploaded",
"where",
"that",
"p... | train | https://github.com/bretth/woven/blob/ec1da7b401a335f43129e7115fe7a4d145649f1e/woven/linux.py#L484-L539 |
bretth/woven | woven/linux.py | upload_ssh_key | def upload_ssh_key(rollback=False):
"""
Upload your ssh key for passwordless logins
"""
auth_keys = '/home/%s/.ssh/authorized_keys'% env.user
if not rollback:
local_user = getpass.getuser()
host = socket.gethostname()
u = '@'.join([local_user,host])
u = 'ssh-key-uploa... | python | def upload_ssh_key(rollback=False):
"""
Upload your ssh key for passwordless logins
"""
auth_keys = '/home/%s/.ssh/authorized_keys'% env.user
if not rollback:
local_user = getpass.getuser()
host = socket.gethostname()
u = '@'.join([local_user,host])
u = 'ssh-key-uploa... | [
"def",
"upload_ssh_key",
"(",
"rollback",
"=",
"False",
")",
":",
"auth_keys",
"=",
"'/home/%s/.ssh/authorized_keys'",
"%",
"env",
".",
"user",
"if",
"not",
"rollback",
":",
"local_user",
"=",
"getpass",
".",
"getuser",
"(",
")",
"host",
"=",
"socket",
".",
... | Upload your ssh key for passwordless logins | [
"Upload",
"your",
"ssh",
"key",
"for",
"passwordless",
"logins"
] | train | https://github.com/bretth/woven/blob/ec1da7b401a335f43129e7115fe7a4d145649f1e/woven/linux.py#L541-L584 |
heuer/cablemap | examples/converttotext.py | cable_to_text | def cable_to_text(cable, include_header):
"""\
Returns the header/content of the cable as text.
"""
if include_header:
return u'\n\n'.join(cable.header, cable.content)
return cable.content | python | def cable_to_text(cable, include_header):
"""\
Returns the header/content of the cable as text.
"""
if include_header:
return u'\n\n'.join(cable.header, cable.content)
return cable.content | [
"def",
"cable_to_text",
"(",
"cable",
",",
"include_header",
")",
":",
"if",
"include_header",
":",
"return",
"u'\\n\\n'",
".",
"join",
"(",
"cable",
".",
"header",
",",
"cable",
".",
"content",
")",
"return",
"cable",
".",
"content"
] | \
Returns the header/content of the cable as text. | [
"\\",
"Returns",
"the",
"header",
"/",
"content",
"of",
"the",
"cable",
"as",
"text",
"."
] | train | https://github.com/heuer/cablemap/blob/42066c8fc2972d237a2c35578e14525aaf705f38/examples/converttotext.py#L12-L18 |
heuer/cablemap | examples/converttotext.py | generate_text_files | def generate_text_files(in_dir, out_dir, include_header=False):
"""\
Walks through the `in_dir` and generates text versions of
the cables in the `out_dir`.
"""
for cable in cables_from_source(in_dir):
out = codecs.open(out_dir + '/' + cable.reference_id + '.txt', 'wb', encoding='utf-8')
... | python | def generate_text_files(in_dir, out_dir, include_header=False):
"""\
Walks through the `in_dir` and generates text versions of
the cables in the `out_dir`.
"""
for cable in cables_from_source(in_dir):
out = codecs.open(out_dir + '/' + cable.reference_id + '.txt', 'wb', encoding='utf-8')
... | [
"def",
"generate_text_files",
"(",
"in_dir",
",",
"out_dir",
",",
"include_header",
"=",
"False",
")",
":",
"for",
"cable",
"in",
"cables_from_source",
"(",
"in_dir",
")",
":",
"out",
"=",
"codecs",
".",
"open",
"(",
"out_dir",
"+",
"'/'",
"+",
"cable",
... | \
Walks through the `in_dir` and generates text versions of
the cables in the `out_dir`. | [
"\\",
"Walks",
"through",
"the",
"in_dir",
"and",
"generates",
"text",
"versions",
"of",
"the",
"cables",
"in",
"the",
"out_dir",
"."
] | train | https://github.com/heuer/cablemap/blob/42066c8fc2972d237a2c35578e14525aaf705f38/examples/converttotext.py#L20-L28 |
KelSolaar/Foundations | foundations/exceptions.py | extract_stack | def extract_stack(frame, context=10, exceptionsFrameSymbol=EXCEPTIONS_FRAME_SYMBOL):
"""
Extracts the stack from given frame while excluded any symbolized frame.
:param frame: Frame.
:type frame: Frame
:param context: Context to extract.
:type context: int
:param exceptionsFrameSymbol: Stac... | python | def extract_stack(frame, context=10, exceptionsFrameSymbol=EXCEPTIONS_FRAME_SYMBOL):
"""
Extracts the stack from given frame while excluded any symbolized frame.
:param frame: Frame.
:type frame: Frame
:param context: Context to extract.
:type context: int
:param exceptionsFrameSymbol: Stac... | [
"def",
"extract_stack",
"(",
"frame",
",",
"context",
"=",
"10",
",",
"exceptionsFrameSymbol",
"=",
"EXCEPTIONS_FRAME_SYMBOL",
")",
":",
"decode",
"=",
"lambda",
"x",
":",
"unicode",
"(",
"x",
",",
"Constants",
".",
"default_codec",
",",
"Constants",
".",
"c... | Extracts the stack from given frame while excluded any symbolized frame.
:param frame: Frame.
:type frame: Frame
:param context: Context to extract.
:type context: int
:param exceptionsFrameSymbol: Stack trace frame tag.
:type exceptionsFrameSymbol: unicode
:return: Stack.
:rtype: list | [
"Extracts",
"the",
"stack",
"from",
"given",
"frame",
"while",
"excluded",
"any",
"symbolized",
"frame",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/exceptions.py#L108-L137 |
KelSolaar/Foundations | foundations/exceptions.py | extract_arguments | def extract_arguments(frame):
"""
Extracts the arguments from given frame.
:param frame: Frame.
:type frame: object
:return: Arguments.
:rtype: tuple
"""
arguments = ([], None, None)
try:
source = textwrap.dedent("".join(inspect.getsourcelines(frame)[0]).replace("\\\n", "")... | python | def extract_arguments(frame):
"""
Extracts the arguments from given frame.
:param frame: Frame.
:type frame: object
:return: Arguments.
:rtype: tuple
"""
arguments = ([], None, None)
try:
source = textwrap.dedent("".join(inspect.getsourcelines(frame)[0]).replace("\\\n", "")... | [
"def",
"extract_arguments",
"(",
"frame",
")",
":",
"arguments",
"=",
"(",
"[",
"]",
",",
"None",
",",
"None",
")",
"try",
":",
"source",
"=",
"textwrap",
".",
"dedent",
"(",
"\"\"",
".",
"join",
"(",
"inspect",
".",
"getsourcelines",
"(",
"frame",
"... | Extracts the arguments from given frame.
:param frame: Frame.
:type frame: object
:return: Arguments.
:rtype: tuple | [
"Extracts",
"the",
"arguments",
"from",
"given",
"frame",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/exceptions.py#L140-L168 |
KelSolaar/Foundations | foundations/exceptions.py | extract_locals | def extract_locals(trcback):
"""
Extracts the frames locals of given traceback.
:param trcback: Traceback.
:type trcback: Traceback
:return: Frames locals.
:rtype: list
"""
output = []
stack = extract_stack(get_inner_most_frame(trcback))
for frame, file_name, line_number, name,... | python | def extract_locals(trcback):
"""
Extracts the frames locals of given traceback.
:param trcback: Traceback.
:type trcback: Traceback
:return: Frames locals.
:rtype: list
"""
output = []
stack = extract_stack(get_inner_most_frame(trcback))
for frame, file_name, line_number, name,... | [
"def",
"extract_locals",
"(",
"trcback",
")",
":",
"output",
"=",
"[",
"]",
"stack",
"=",
"extract_stack",
"(",
"get_inner_most_frame",
"(",
"trcback",
")",
")",
"for",
"frame",
",",
"file_name",
",",
"line_number",
",",
"name",
",",
"context",
",",
"index... | Extracts the frames locals of given traceback.
:param trcback: Traceback.
:type trcback: Traceback
:return: Frames locals.
:rtype: list | [
"Extracts",
"the",
"frames",
"locals",
"of",
"given",
"traceback",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/exceptions.py#L171-L196 |
KelSolaar/Foundations | foundations/exceptions.py | extract_exception | def extract_exception(*args):
"""
Extracts the exception from given arguments or from :func:`sys.exc_info`.
:param \*args: Arguments.
:type \*args: \*
:return: Extracted exception.
:rtype: tuple
"""
cls, instance, trcback = sys.exc_info()
exceptions = filter(lambda x: issubclass(t... | python | def extract_exception(*args):
"""
Extracts the exception from given arguments or from :func:`sys.exc_info`.
:param \*args: Arguments.
:type \*args: \*
:return: Extracted exception.
:rtype: tuple
"""
cls, instance, trcback = sys.exc_info()
exceptions = filter(lambda x: issubclass(t... | [
"def",
"extract_exception",
"(",
"*",
"args",
")",
":",
"cls",
",",
"instance",
",",
"trcback",
"=",
"sys",
".",
"exc_info",
"(",
")",
"exceptions",
"=",
"filter",
"(",
"lambda",
"x",
":",
"issubclass",
"(",
"type",
"(",
"x",
")",
",",
"BaseException",... | Extracts the exception from given arguments or from :func:`sys.exc_info`.
:param \*args: Arguments.
:type \*args: \*
:return: Extracted exception.
:rtype: tuple | [
"Extracts",
"the",
"exception",
"from",
"given",
"arguments",
"or",
"from",
":",
"func",
":",
"sys",
".",
"exc_info",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/exceptions.py#L199-L217 |
KelSolaar/Foundations | foundations/exceptions.py | format_exception | def format_exception(cls, instance, trcback, context=1):
"""
| Formats given exception.
| The code produce a similar output to :func:`traceback.format_exception` except that it allows frames to be excluded
from the stack if the given stack trace frame tag is found in the frame locals and set **True*... | python | def format_exception(cls, instance, trcback, context=1):
"""
| Formats given exception.
| The code produce a similar output to :func:`traceback.format_exception` except that it allows frames to be excluded
from the stack if the given stack trace frame tag is found in the frame locals and set **True*... | [
"def",
"format_exception",
"(",
"cls",
",",
"instance",
",",
"trcback",
",",
"context",
"=",
"1",
")",
":",
"stack",
"=",
"extract_stack",
"(",
"get_inner_most_frame",
"(",
"trcback",
")",
",",
"context",
"=",
"context",
")",
"output",
"=",
"[",
"]",
"ou... | | Formats given exception.
| The code produce a similar output to :func:`traceback.format_exception` except that it allows frames to be excluded
from the stack if the given stack trace frame tag is found in the frame locals and set **True**.
:param cls: Exception class.
:type cls: object
:param... | [
"|",
"Formats",
"given",
"exception",
".",
"|",
"The",
"code",
"produce",
"a",
"similar",
"output",
"to",
":",
"func",
":",
"traceback",
".",
"format_exception",
"except",
"that",
"it",
"allows",
"frames",
"to",
"be",
"excluded",
"from",
"the",
"stack",
"i... | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/exceptions.py#L220-L247 |
KelSolaar/Foundations | foundations/exceptions.py | format_report | def format_report(cls, instance, trcback, context=1):
"""
Formats a report using given exception.
:param cls: Exception class.
:type cls: object
:param instance: Exception instance.
:type instance: object
:param trcback: Traceback.
:type trcback: Traceback
:param context: Context be... | python | def format_report(cls, instance, trcback, context=1):
"""
Formats a report using given exception.
:param cls: Exception class.
:type cls: object
:param instance: Exception instance.
:type instance: object
:param trcback: Traceback.
:type trcback: Traceback
:param context: Context be... | [
"def",
"format_report",
"(",
"cls",
",",
"instance",
",",
"trcback",
",",
"context",
"=",
"1",
")",
":",
"header",
"=",
"[",
"]",
"header",
".",
"append",
"(",
"\"Exception in '{0}'.\"",
".",
"format",
"(",
"get_inner_most_frame",
"(",
"trcback",
")",
".",... | Formats a report using given exception.
:param cls: Exception class.
:type cls: object
:param instance: Exception instance.
:type instance: object
:param trcback: Traceback.
:type trcback: Traceback
:param context: Context being included.
:type context: int
:return: Formated report.... | [
"Formats",
"a",
"report",
"using",
"given",
"exception",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/exceptions.py#L250-L292 |
KelSolaar/Foundations | foundations/exceptions.py | base_exception_handler | def base_exception_handler(*args):
"""
Provides the base exception handler.
:param \*args: Arguments.
:type \*args: \*
:return: Definition success.
:rtype: bool
"""
header, frames, trcback = format_report(*extract_exception(*args))
LOGGER.error("!> {0}".format(Constants.logging_se... | python | def base_exception_handler(*args):
"""
Provides the base exception handler.
:param \*args: Arguments.
:type \*args: \*
:return: Definition success.
:rtype: bool
"""
header, frames, trcback = format_report(*extract_exception(*args))
LOGGER.error("!> {0}".format(Constants.logging_se... | [
"def",
"base_exception_handler",
"(",
"*",
"args",
")",
":",
"header",
",",
"frames",
",",
"trcback",
"=",
"format_report",
"(",
"*",
"extract_exception",
"(",
"*",
"args",
")",
")",
"LOGGER",
".",
"error",
"(",
"\"!> {0}\"",
".",
"format",
"(",
"Constants... | Provides the base exception handler.
:param \*args: Arguments.
:type \*args: \*
:return: Definition success.
:rtype: bool | [
"Provides",
"the",
"base",
"exception",
"handler",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/exceptions.py#L295-L316 |
KelSolaar/Foundations | foundations/exceptions.py | handle_exceptions | def handle_exceptions(*args):
"""
| Handles exceptions.
| It's possible to specify an user defined exception handler,
if not, :func:`base_exception_handler` handler will be used.
| The decorator uses given exceptions objects
or the default Python `Exception <http://docs.python.org/librar... | python | def handle_exceptions(*args):
"""
| Handles exceptions.
| It's possible to specify an user defined exception handler,
if not, :func:`base_exception_handler` handler will be used.
| The decorator uses given exceptions objects
or the default Python `Exception <http://docs.python.org/librar... | [
"def",
"handle_exceptions",
"(",
"*",
"args",
")",
":",
"exceptions",
"=",
"tuple",
"(",
"filter",
"(",
"lambda",
"x",
":",
"issubclass",
"(",
"x",
",",
"Exception",
")",
",",
"filter",
"(",
"lambda",
"x",
":",
"isinstance",
"(",
"x",
",",
"(",
"type... | | Handles exceptions.
| It's possible to specify an user defined exception handler,
if not, :func:`base_exception_handler` handler will be used.
| The decorator uses given exceptions objects
or the default Python `Exception <http://docs.python.org/library/exceptions.html#exceptions.Exception>`_ ... | [
"|",
"Handles",
"exceptions",
".",
"|",
"It",
"s",
"possible",
"to",
"specify",
"an",
"user",
"defined",
"exception",
"handler",
"if",
"not",
":",
"func",
":",
"base_exception_handler",
"handler",
"will",
"be",
"used",
".",
"|",
"The",
"decorator",
"uses",
... | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/exceptions.py#L345-L405 |
KelSolaar/Foundations | foundations/exceptions.py | AttributeStructureParsingError.line | def line(self, value):
"""
Setter for **self.__line** attribute.
:param value: Attribute value.
:type value: int
"""
if value is not None:
assert type(value) is int, "'{0}' attribute: '{1}' type is not 'int'!".format("line", value)
assert value >... | python | def line(self, value):
"""
Setter for **self.__line** attribute.
:param value: Attribute value.
:type value: int
"""
if value is not None:
assert type(value) is int, "'{0}' attribute: '{1}' type is not 'int'!".format("line", value)
assert value >... | [
"def",
"line",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"is",
"not",
"None",
":",
"assert",
"type",
"(",
"value",
")",
"is",
"int",
",",
"\"'{0}' attribute: '{1}' type is not 'int'!\"",
".",
"format",
"(",
"\"line\"",
",",
"value",
")",
"assert"... | Setter for **self.__line** attribute.
:param value: Attribute value.
:type value: int | [
"Setter",
"for",
"**",
"self",
".",
"__line",
"**",
"attribute",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/exceptions.py#L535-L546 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.