repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
mbj4668/pyang
pyang/yang_parser.py
YangTokenizer.skip
def skip(self): """Skip whitespace and count position""" buflen = len(self.buf) while True: self.buf = self.buf.lstrip() if self.buf == '': self.readline() buflen = len(self.buf) else: self.offset += (buflen - l...
python
def skip(self): """Skip whitespace and count position""" buflen = len(self.buf) while True: self.buf = self.buf.lstrip() if self.buf == '': self.readline() buflen = len(self.buf) else: self.offset += (buflen - l...
[ "def", "skip", "(", "self", ")", ":", "buflen", "=", "len", "(", "self", ".", "buf", ")", "while", "True", ":", "self", ".", "buf", "=", "self", ".", "buf", ".", "lstrip", "(", ")", "if", "self", ".", "buf", "==", "''", ":", "self", ".", "rea...
Skip whitespace and count position
[ "Skip", "whitespace", "and", "count", "position" ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/yang_parser.py#L51-L78
train
mbj4668/pyang
pyang/yang_parser.py
YangParser.parse
def parse(self, ctx, ref, text): """Parse the string `text` containing a YANG statement. Return a Statement on success or None on failure """ self.ctx = ctx self.pos = error.Position(ref) self.top = None try: self.tokenizer = YangTokenizer(text, self...
python
def parse(self, ctx, ref, text): """Parse the string `text` containing a YANG statement. Return a Statement on success or None on failure """ self.ctx = ctx self.pos = error.Position(ref) self.top = None try: self.tokenizer = YangTokenizer(text, self...
[ "def", "parse", "(", "self", ",", "ctx", ",", "ref", ",", "text", ")", ":", "self", ".", "ctx", "=", "ctx", "self", ".", "pos", "=", "error", ".", "Position", "(", "ref", ")", "self", ".", "top", "=", "None", "try", ":", "self", ".", "tokenizer...
Parse the string `text` containing a YANG statement. Return a Statement on success or None on failure
[ "Parse", "the", "string", "text", "containing", "a", "YANG", "statement", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/yang_parser.py#L261-L288
train
mbj4668/pyang
pyang/statements.py
add_validation_phase
def add_validation_phase(phase, before=None, after=None): """Add a validation phase to the framework. Can be used by plugins to do special validation of extensions.""" idx = 0 for x in _validation_phases: if x == before: _validation_phases.insert(idx, phase) return ...
python
def add_validation_phase(phase, before=None, after=None): """Add a validation phase to the framework. Can be used by plugins to do special validation of extensions.""" idx = 0 for x in _validation_phases: if x == before: _validation_phases.insert(idx, phase) return ...
[ "def", "add_validation_phase", "(", "phase", ",", "before", "=", "None", ",", "after", "=", "None", ")", ":", "idx", "=", "0", "for", "x", "in", "_validation_phases", ":", "if", "x", "==", "before", ":", "_validation_phases", ".", "insert", "(", "idx", ...
Add a validation phase to the framework. Can be used by plugins to do special validation of extensions.
[ "Add", "a", "validation", "phase", "to", "the", "framework", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/statements.py#L16-L30
train
mbj4668/pyang
pyang/statements.py
add_validation_fun
def add_validation_fun(phase, keywords, f): """Add a validation function to some phase in the framework. Function `f` is called for each valid occurance of each keyword in `keywords`. Can be used by plugins to do special validation of extensions.""" for keyword in keywords: if (phase, keywo...
python
def add_validation_fun(phase, keywords, f): """Add a validation function to some phase in the framework. Function `f` is called for each valid occurance of each keyword in `keywords`. Can be used by plugins to do special validation of extensions.""" for keyword in keywords: if (phase, keywo...
[ "def", "add_validation_fun", "(", "phase", ",", "keywords", ",", "f", ")", ":", "for", "keyword", "in", "keywords", ":", "if", "(", "phase", ",", "keyword", ")", "in", "_validation_map", ":", "oldf", "=", "_validation_map", "[", "(", "phase", ",", "keywo...
Add a validation function to some phase in the framework. Function `f` is called for each valid occurance of each keyword in `keywords`. Can be used by plugins to do special validation of extensions.
[ "Add", "a", "validation", "function", "to", "some", "phase", "in", "the", "framework", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/statements.py#L32-L46
train
mbj4668/pyang
pyang/statements.py
v_init_extension
def v_init_extension(ctx, stmt): """find the modulename of the prefix, and set `stmt.keyword`""" (prefix, identifier) = stmt.raw_keyword (modname, revision) = \ prefix_to_modulename_and_revision(stmt.i_module, prefix, stmt.pos, ctx.errors) stmt.keyword =...
python
def v_init_extension(ctx, stmt): """find the modulename of the prefix, and set `stmt.keyword`""" (prefix, identifier) = stmt.raw_keyword (modname, revision) = \ prefix_to_modulename_and_revision(stmt.i_module, prefix, stmt.pos, ctx.errors) stmt.keyword =...
[ "def", "v_init_extension", "(", "ctx", ",", "stmt", ")", ":", "(", "prefix", ",", "identifier", ")", "=", "stmt", ".", "raw_keyword", "(", "modname", ",", "revision", ")", "=", "prefix_to_modulename_and_revision", "(", "stmt", ".", "i_module", ",", "prefix",...
find the modulename of the prefix, and set `stmt.keyword`
[ "find", "the", "modulename", "of", "the", "prefix", "and", "set", "stmt", ".", "keyword" ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/statements.py#L491-L500
train
mbj4668/pyang
pyang/statements.py
v_grammar_unique_defs
def v_grammar_unique_defs(ctx, stmt): """Verify that all typedefs and groupings are unique Called for every statement. Stores all typedefs in stmt.i_typedef, groupings in stmt.i_grouping """ defs = [('typedef', 'TYPE_ALREADY_DEFINED', stmt.i_typedefs), ('grouping', 'GROUPING_ALREADY_DEFI...
python
def v_grammar_unique_defs(ctx, stmt): """Verify that all typedefs and groupings are unique Called for every statement. Stores all typedefs in stmt.i_typedef, groupings in stmt.i_grouping """ defs = [('typedef', 'TYPE_ALREADY_DEFINED', stmt.i_typedefs), ('grouping', 'GROUPING_ALREADY_DEFI...
[ "def", "v_grammar_unique_defs", "(", "ctx", ",", "stmt", ")", ":", "defs", "=", "[", "(", "'typedef'", ",", "'TYPE_ALREADY_DEFINED'", ",", "stmt", ".", "i_typedefs", ")", ",", "(", "'grouping'", ",", "'GROUPING_ALREADY_DEFINED'", ",", "stmt", ".", "i_groupings...
Verify that all typedefs and groupings are unique Called for every statement. Stores all typedefs in stmt.i_typedef, groupings in stmt.i_grouping
[ "Verify", "that", "all", "typedefs", "and", "groupings", "are", "unique", "Called", "for", "every", "statement", ".", "Stores", "all", "typedefs", "in", "stmt", ".", "i_typedef", "groupings", "in", "stmt", ".", "i_grouping" ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/statements.py#L537-L556
train
mbj4668/pyang
pyang/statements.py
v_type_extension
def v_type_extension(ctx, stmt): """verify that the extension matches the extension definition""" (modulename, identifier) = stmt.keyword revision = stmt.i_extension_revision module = modulename_to_module(stmt.i_module, modulename, revision) if module is None: return if identifier not in...
python
def v_type_extension(ctx, stmt): """verify that the extension matches the extension definition""" (modulename, identifier) = stmt.keyword revision = stmt.i_extension_revision module = modulename_to_module(stmt.i_module, modulename, revision) if module is None: return if identifier not in...
[ "def", "v_type_extension", "(", "ctx", ",", "stmt", ")", ":", "(", "modulename", ",", "identifier", ")", "=", "stmt", ".", "keyword", "revision", "=", "stmt", ".", "i_extension_revision", "module", "=", "modulename_to_module", "(", "stmt", ".", "i_module", "...
verify that the extension matches the extension definition
[ "verify", "that", "the", "extension", "matches", "the", "extension", "definition" ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/statements.py#L1172-L1200
train
mbj4668/pyang
pyang/statements.py
v_type_if_feature
def v_type_if_feature(ctx, stmt, no_error_report=False): """verify that the referenced feature exists.""" stmt.i_feature = None # Verify the argument type expr = syntax.parse_if_feature_expr(stmt.arg) if stmt.i_module.i_version == '1': # version 1 allows only a single value as if-feature ...
python
def v_type_if_feature(ctx, stmt, no_error_report=False): """verify that the referenced feature exists.""" stmt.i_feature = None # Verify the argument type expr = syntax.parse_if_feature_expr(stmt.arg) if stmt.i_module.i_version == '1': # version 1 allows only a single value as if-feature ...
[ "def", "v_type_if_feature", "(", "ctx", ",", "stmt", ",", "no_error_report", "=", "False", ")", ":", "stmt", ".", "i_feature", "=", "None", "expr", "=", "syntax", ".", "parse_if_feature_expr", "(", "stmt", ".", "arg", ")", "if", "stmt", ".", "i_module", ...
verify that the referenced feature exists.
[ "verify", "that", "the", "referenced", "feature", "exists", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/statements.py#L1224-L1294
train
mbj4668/pyang
pyang/statements.py
v_type_base
def v_type_base(ctx, stmt, no_error_report=False): """verify that the referenced identity exists.""" # Find the identity name = stmt.arg stmt.i_identity = None if name.find(":") == -1: prefix = None else: [prefix, name] = name.split(':', 1) if prefix is None or stmt.i_module....
python
def v_type_base(ctx, stmt, no_error_report=False): """verify that the referenced identity exists.""" # Find the identity name = stmt.arg stmt.i_identity = None if name.find(":") == -1: prefix = None else: [prefix, name] = name.split(':', 1) if prefix is None or stmt.i_module....
[ "def", "v_type_base", "(", "ctx", ",", "stmt", ",", "no_error_report", "=", "False", ")", ":", "name", "=", "stmt", ".", "arg", "stmt", ".", "i_identity", "=", "None", "if", "name", ".", "find", "(", "\":\"", ")", "==", "-", "1", ":", "prefix", "="...
verify that the referenced identity exists.
[ "verify", "that", "the", "referenced", "identity", "exists", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/statements.py#L1333-L1359
train
mbj4668/pyang
pyang/statements.py
v_unique_name_defintions
def v_unique_name_defintions(ctx, stmt): """Make sure that all top-level definitions in a module are unique""" defs = [('typedef', 'TYPE_ALREADY_DEFINED', stmt.i_typedefs), ('grouping', 'GROUPING_ALREADY_DEFINED', stmt.i_groupings)] def f(s): for (keyword, errcode, dict) in defs: ...
python
def v_unique_name_defintions(ctx, stmt): """Make sure that all top-level definitions in a module are unique""" defs = [('typedef', 'TYPE_ALREADY_DEFINED', stmt.i_typedefs), ('grouping', 'GROUPING_ALREADY_DEFINED', stmt.i_groupings)] def f(s): for (keyword, errcode, dict) in defs: ...
[ "def", "v_unique_name_defintions", "(", "ctx", ",", "stmt", ")", ":", "defs", "=", "[", "(", "'typedef'", ",", "'TYPE_ALREADY_DEFINED'", ",", "stmt", ".", "i_typedefs", ")", ",", "(", "'grouping'", ",", "'GROUPING_ALREADY_DEFINED'", ",", "stmt", ".", "i_groupi...
Make sure that all top-level definitions in a module are unique
[ "Make", "sure", "that", "all", "top", "-", "level", "definitions", "in", "a", "module", "are", "unique" ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/statements.py#L1802-L1818
train
mbj4668/pyang
pyang/statements.py
v_unique_name_children
def v_unique_name_children(ctx, stmt): """Make sure that each child of stmt has a unique name""" def sort_pos(p1, p2): if p1.line < p2.line: return (p1,p2) else: return (p2,p1) dict = {} chs = stmt.i_children def check(c): key = (c.i_module.i_module...
python
def v_unique_name_children(ctx, stmt): """Make sure that each child of stmt has a unique name""" def sort_pos(p1, p2): if p1.line < p2.line: return (p1,p2) else: return (p2,p1) dict = {} chs = stmt.i_children def check(c): key = (c.i_module.i_module...
[ "def", "v_unique_name_children", "(", "ctx", ",", "stmt", ")", ":", "def", "sort_pos", "(", "p1", ",", "p2", ")", ":", "if", "p1", ".", "line", "<", "p2", ".", "line", ":", "return", "(", "p1", ",", "p2", ")", "else", ":", "return", "(", "p2", ...
Make sure that each child of stmt has a unique name
[ "Make", "sure", "that", "each", "child", "of", "stmt", "has", "a", "unique", "name" ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/statements.py#L1821-L1850
train
mbj4668/pyang
pyang/statements.py
v_unique_name_leaf_list
def v_unique_name_leaf_list(ctx, stmt): """Make sure config true leaf-lists do nothave duplicate defaults""" if not stmt.i_config: return seen = [] for defval in stmt.i_default: if defval in seen: err_add(ctx.errors, stmt.pos, 'DUPLICATE_DEFAULT', (defval)) else: ...
python
def v_unique_name_leaf_list(ctx, stmt): """Make sure config true leaf-lists do nothave duplicate defaults""" if not stmt.i_config: return seen = [] for defval in stmt.i_default: if defval in seen: err_add(ctx.errors, stmt.pos, 'DUPLICATE_DEFAULT', (defval)) else: ...
[ "def", "v_unique_name_leaf_list", "(", "ctx", ",", "stmt", ")", ":", "if", "not", "stmt", ".", "i_config", ":", "return", "seen", "=", "[", "]", "for", "defval", "in", "stmt", ".", "i_default", ":", "if", "defval", "in", "seen", ":", "err_add", "(", ...
Make sure config true leaf-lists do nothave duplicate defaults
[ "Make", "sure", "config", "true", "leaf", "-", "lists", "do", "nothave", "duplicate", "defaults" ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/statements.py#L1852-L1862
train
mbj4668/pyang
pyang/statements.py
v_reference_choice
def v_reference_choice(ctx, stmt): """Make sure that the default case exists""" d = stmt.search_one('default') if d is not None: m = stmt.search_one('mandatory') if m is not None and m.arg == 'true': err_add(ctx.errors, stmt.pos, 'DEFAULT_AND_MANDATORY', ()) ptr = attrsea...
python
def v_reference_choice(ctx, stmt): """Make sure that the default case exists""" d = stmt.search_one('default') if d is not None: m = stmt.search_one('mandatory') if m is not None and m.arg == 'true': err_add(ctx.errors, stmt.pos, 'DEFAULT_AND_MANDATORY', ()) ptr = attrsea...
[ "def", "v_reference_choice", "(", "ctx", ",", "stmt", ")", ":", "d", "=", "stmt", ".", "search_one", "(", "'default'", ")", "if", "d", "is", "not", "None", ":", "m", "=", "stmt", ".", "search_one", "(", "'mandatory'", ")", "if", "m", "is", "not", "...
Make sure that the default case exists
[ "Make", "sure", "that", "the", "default", "case", "exists" ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/statements.py#L1993-L2021
train
mbj4668/pyang
pyang/statements.py
v_reference_leaf_leafref
def v_reference_leaf_leafref(ctx, stmt): """Verify that all leafrefs in a leaf or leaf-list have correct path""" if (hasattr(stmt, 'i_leafref') and stmt.i_leafref is not None and stmt.i_leafref_expanded is False): path_type_spec = stmt.i_leafref not_req_inst = not(path_type_spec...
python
def v_reference_leaf_leafref(ctx, stmt): """Verify that all leafrefs in a leaf or leaf-list have correct path""" if (hasattr(stmt, 'i_leafref') and stmt.i_leafref is not None and stmt.i_leafref_expanded is False): path_type_spec = stmt.i_leafref not_req_inst = not(path_type_spec...
[ "def", "v_reference_leaf_leafref", "(", "ctx", ",", "stmt", ")", ":", "if", "(", "hasattr", "(", "stmt", ",", "'i_leafref'", ")", "and", "stmt", ".", "i_leafref", "is", "not", "None", "and", "stmt", ".", "i_leafref_expanded", "is", "False", ")", ":", "pa...
Verify that all leafrefs in a leaf or leaf-list have correct path
[ "Verify", "that", "all", "leafrefs", "in", "a", "leaf", "or", "leaf", "-", "list", "have", "correct", "path" ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/statements.py#L2023-L2045
train
mbj4668/pyang
pyang/statements.py
has_type
def has_type(type, names): """Return type with name if `type` has name as one of its base types, and name is in the `names` list. otherwise, return None.""" if type.arg in names: return type for t in type.search('type'): # check all union's member types r = has_type(t, names) if...
python
def has_type(type, names): """Return type with name if `type` has name as one of its base types, and name is in the `names` list. otherwise, return None.""" if type.arg in names: return type for t in type.search('type'): # check all union's member types r = has_type(t, names) if...
[ "def", "has_type", "(", "type", ",", "names", ")", ":", "if", "type", ".", "arg", "in", "names", ":", "return", "type", "for", "t", "in", "type", ".", "search", "(", "'type'", ")", ":", "r", "=", "has_type", "(", "t", ",", "names", ")", "if", "...
Return type with name if `type` has name as one of its base types, and name is in the `names` list. otherwise, return None.
[ "Return", "type", "with", "name", "if", "type", "has", "name", "as", "one", "of", "its", "base", "types", "and", "name", "is", "in", "the", "names", "list", ".", "otherwise", "return", "None", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/statements.py#L2268-L2285
train
mbj4668/pyang
pyang/statements.py
search_typedef
def search_typedef(stmt, name): """Search for a typedef in scope First search the hierarchy, then the module and its submodules.""" mod = stmt.i_orig_module while stmt is not None: if name in stmt.i_typedefs: t = stmt.i_typedefs[name] if (mod is not None and ...
python
def search_typedef(stmt, name): """Search for a typedef in scope First search the hierarchy, then the module and its submodules.""" mod = stmt.i_orig_module while stmt is not None: if name in stmt.i_typedefs: t = stmt.i_typedefs[name] if (mod is not None and ...
[ "def", "search_typedef", "(", "stmt", ",", "name", ")", ":", "mod", "=", "stmt", ".", "i_orig_module", "while", "stmt", "is", "not", "None", ":", "if", "name", "in", "stmt", ".", "i_typedefs", ":", "t", "=", "stmt", ".", "i_typedefs", "[", "name", "]...
Search for a typedef in scope First search the hierarchy, then the module and its submodules.
[ "Search", "for", "a", "typedef", "in", "scope", "First", "search", "the", "hierarchy", "then", "the", "module", "and", "its", "submodules", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/statements.py#L2318-L2333
train
mbj4668/pyang
pyang/statements.py
search_grouping
def search_grouping(stmt, name): """Search for a grouping in scope First search the hierarchy, then the module and its submodules.""" mod = stmt.i_orig_module while stmt is not None: if name in stmt.i_groupings: g = stmt.i_groupings[name] if (mod is not None and ...
python
def search_grouping(stmt, name): """Search for a grouping in scope First search the hierarchy, then the module and its submodules.""" mod = stmt.i_orig_module while stmt is not None: if name in stmt.i_groupings: g = stmt.i_groupings[name] if (mod is not None and ...
[ "def", "search_grouping", "(", "stmt", ",", "name", ")", ":", "mod", "=", "stmt", ".", "i_orig_module", "while", "stmt", "is", "not", "None", ":", "if", "name", "in", "stmt", ".", "i_groupings", ":", "g", "=", "stmt", ".", "i_groupings", "[", "name", ...
Search for a grouping in scope First search the hierarchy, then the module and its submodules.
[ "Search", "for", "a", "grouping", "in", "scope", "First", "search", "the", "hierarchy", "then", "the", "module", "and", "its", "submodules", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/statements.py#L2335-L2350
train
mbj4668/pyang
pyang/statements.py
is_submodule_included
def is_submodule_included(src, tgt): """Check that the tgt's submodule is included by src, if they belong to the same module.""" if tgt is None or not hasattr(tgt, 'i_orig_module'): return True if (tgt.i_orig_module.keyword == 'submodule' and src.i_orig_module != tgt.i_orig_module and ...
python
def is_submodule_included(src, tgt): """Check that the tgt's submodule is included by src, if they belong to the same module.""" if tgt is None or not hasattr(tgt, 'i_orig_module'): return True if (tgt.i_orig_module.keyword == 'submodule' and src.i_orig_module != tgt.i_orig_module and ...
[ "def", "is_submodule_included", "(", "src", ",", "tgt", ")", ":", "if", "tgt", "is", "None", "or", "not", "hasattr", "(", "tgt", ",", "'i_orig_module'", ")", ":", "return", "True", "if", "(", "tgt", ".", "i_orig_module", ".", "keyword", "==", "'submodule...
Check that the tgt's submodule is included by src, if they belong to the same module.
[ "Check", "that", "the", "tgt", "s", "submodule", "is", "included", "by", "src", "if", "they", "belong", "to", "the", "same", "module", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/statements.py#L2466-L2477
train
mbj4668/pyang
pyang/statements.py
mk_path_str
def mk_path_str(stmt, with_prefixes=False, prefix_onchange=False, prefix_to_module=False, resolve_top_prefix_to_module=False): """Returns the XPath path of the node. with_prefixes indicates whether or not to prefix every node. prefix_onchange ...
python
def mk_path_str(stmt, with_prefixes=False, prefix_onchange=False, prefix_to_module=False, resolve_top_prefix_to_module=False): """Returns the XPath path of the node. with_prefixes indicates whether or not to prefix every node. prefix_onchange ...
[ "def", "mk_path_str", "(", "stmt", ",", "with_prefixes", "=", "False", ",", "prefix_onchange", "=", "False", ",", "prefix_to_module", "=", "False", ",", "resolve_top_prefix_to_module", "=", "False", ")", ":", "resolved_names", "=", "mk_path_list", "(", "stmt", "...
Returns the XPath path of the node. with_prefixes indicates whether or not to prefix every node. prefix_onchange modifies the behavior of with_prefixes and only adds prefixes when the prefix changes mid-XPath. prefix_to_module replaces prefixes with the module name of the prefix. resolve_top_pr...
[ "Returns", "the", "XPath", "path", "of", "the", "node", ".", "with_prefixes", "indicates", "whether", "or", "not", "to", "prefix", "every", "node", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/statements.py#L3107-L3139
train
mbj4668/pyang
pyang/statements.py
get_xpath
def get_xpath(stmt, qualified=False, prefix_to_module=False): """Gets the XPath of the statement. Unless qualified=True, does not include prefixes unless the prefix changes mid-XPath. qualified will add a prefix to each node. prefix_to_module will resolve prefixes to module names instead. F...
python
def get_xpath(stmt, qualified=False, prefix_to_module=False): """Gets the XPath of the statement. Unless qualified=True, does not include prefixes unless the prefix changes mid-XPath. qualified will add a prefix to each node. prefix_to_module will resolve prefixes to module names instead. F...
[ "def", "get_xpath", "(", "stmt", ",", "qualified", "=", "False", ",", "prefix_to_module", "=", "False", ")", ":", "return", "mk_path_str", "(", "stmt", ",", "with_prefixes", "=", "qualified", ",", "prefix_onchange", "=", "True", ",", "prefix_to_module", "=", ...
Gets the XPath of the statement. Unless qualified=True, does not include prefixes unless the prefix changes mid-XPath. qualified will add a prefix to each node. prefix_to_module will resolve prefixes to module names instead. For RFC 8040, set prefix_to_module=True: /prefix:root/node/prefi...
[ "Gets", "the", "XPath", "of", "the", "statement", ".", "Unless", "qualified", "=", "True", "does", "not", "include", "prefixes", "unless", "the", "prefix", "changes", "mid", "-", "XPath", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/statements.py#L3141-L3161
train
mbj4668/pyang
pyang/statements.py
get_qualified_type
def get_qualified_type(stmt): """Gets the qualified, top-level type of the node. This enters the typedef if defined instead of using the prefix to ensure absolute distinction. """ type_obj = stmt.search_one('type') fq_type_name = None if type_obj: if getattr(type_obj, 'i_typedef', No...
python
def get_qualified_type(stmt): """Gets the qualified, top-level type of the node. This enters the typedef if defined instead of using the prefix to ensure absolute distinction. """ type_obj = stmt.search_one('type') fq_type_name = None if type_obj: if getattr(type_obj, 'i_typedef', No...
[ "def", "get_qualified_type", "(", "stmt", ")", ":", "type_obj", "=", "stmt", ".", "search_one", "(", "'type'", ")", "fq_type_name", "=", "None", "if", "type_obj", ":", "if", "getattr", "(", "type_obj", ",", "'i_typedef'", ",", "None", ")", ":", "type_obj",...
Gets the qualified, top-level type of the node. This enters the typedef if defined instead of using the prefix to ensure absolute distinction.
[ "Gets", "the", "qualified", "top", "-", "level", "type", "of", "the", "node", ".", "This", "enters", "the", "typedef", "if", "defined", "instead", "of", "using", "the", "prefix", "to", "ensure", "absolute", "distinction", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/statements.py#L3171-L3190
train
mbj4668/pyang
pyang/statements.py
get_primitive_type
def get_primitive_type(stmt): """Recurses through the typedefs and returns the most primitive YANG type defined. """ type_obj = stmt.search_one('type') type_name = getattr(type_obj, 'arg', None) typedef_obj = getattr(type_obj, 'i_typedef', None) if typedef_obj: type_name = get_primit...
python
def get_primitive_type(stmt): """Recurses through the typedefs and returns the most primitive YANG type defined. """ type_obj = stmt.search_one('type') type_name = getattr(type_obj, 'arg', None) typedef_obj = getattr(type_obj, 'i_typedef', None) if typedef_obj: type_name = get_primit...
[ "def", "get_primitive_type", "(", "stmt", ")", ":", "type_obj", "=", "stmt", ".", "search_one", "(", "'type'", ")", "type_name", "=", "getattr", "(", "type_obj", ",", "'arg'", ",", "None", ")", "typedef_obj", "=", "getattr", "(", "type_obj", ",", "'i_typed...
Recurses through the typedefs and returns the most primitive YANG type defined.
[ "Recurses", "through", "the", "typedefs", "and", "returns", "the", "most", "primitive", "YANG", "type", "defined", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/statements.py#L3192-L3204
train
mbj4668/pyang
pyang/statements.py
Statement.search
def search(self, keyword, children=None, arg=None): """Return list of receiver's substmts with `keyword`. """ if children is None: children = self.substmts return [ ch for ch in children if (ch.keyword == keyword and (arg is None or ch.ar...
python
def search(self, keyword, children=None, arg=None): """Return list of receiver's substmts with `keyword`. """ if children is None: children = self.substmts return [ ch for ch in children if (ch.keyword == keyword and (arg is None or ch.ar...
[ "def", "search", "(", "self", ",", "keyword", ",", "children", "=", "None", ",", "arg", "=", "None", ")", ":", "if", "children", "is", "None", ":", "children", "=", "self", ".", "substmts", "return", "[", "ch", "for", "ch", "in", "children", "if", ...
Return list of receiver's substmts with `keyword`.
[ "Return", "list", "of", "receiver", "s", "substmts", "with", "keyword", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/statements.py#L2819-L2826
train
mbj4668/pyang
pyang/statements.py
Statement.search_one
def search_one(self, keyword, arg=None, children=None): """Return receiver's substmt with `keyword` and optionally `arg`. """ if children is None: children = self.substmts for ch in children: if ch.keyword == keyword and (arg is None or ch.arg == arg): ...
python
def search_one(self, keyword, arg=None, children=None): """Return receiver's substmt with `keyword` and optionally `arg`. """ if children is None: children = self.substmts for ch in children: if ch.keyword == keyword and (arg is None or ch.arg == arg): ...
[ "def", "search_one", "(", "self", ",", "keyword", ",", "arg", "=", "None", ",", "children", "=", "None", ")", ":", "if", "children", "is", "None", ":", "children", "=", "self", ".", "substmts", "for", "ch", "in", "children", ":", "if", "ch", ".", "...
Return receiver's substmt with `keyword` and optionally `arg`.
[ "Return", "receiver", "s", "substmt", "with", "keyword", "and", "optionally", "arg", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/statements.py#L2828-L2836
train
mbj4668/pyang
pyang/statements.py
Statement.main_module
def main_module(self): """Return the main module to which the receiver belongs.""" if self.i_module.keyword == "submodule": return self.i_module.i_ctx.get_module( self.i_module.i_including_modulename) return self.i_module
python
def main_module(self): """Return the main module to which the receiver belongs.""" if self.i_module.keyword == "submodule": return self.i_module.i_ctx.get_module( self.i_module.i_including_modulename) return self.i_module
[ "def", "main_module", "(", "self", ")", ":", "if", "self", ".", "i_module", ".", "keyword", "==", "\"submodule\"", ":", "return", "self", ".", "i_module", ".", "i_ctx", ".", "get_module", "(", "self", ".", "i_module", ".", "i_including_modulename", ")", "r...
Return the main module to which the receiver belongs.
[ "Return", "the", "main", "module", "to", "which", "the", "receiver", "belongs", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/statements.py#L2866-L2871
train
mbj4668/pyang
pyang/xpath.py
add_prefix
def add_prefix(prefix, s): "Add `prefix` to all unprefixed names in `s`" # tokenize the XPath expression toks = xpath_lexer.scan(s) # add default prefix to unprefixed names toks2 = [_add_prefix(prefix, tok) for tok in toks] # build a string of the patched expression ls = [x.value for x in to...
python
def add_prefix(prefix, s): "Add `prefix` to all unprefixed names in `s`" # tokenize the XPath expression toks = xpath_lexer.scan(s) # add default prefix to unprefixed names toks2 = [_add_prefix(prefix, tok) for tok in toks] # build a string of the patched expression ls = [x.value for x in to...
[ "def", "add_prefix", "(", "prefix", ",", "s", ")", ":", "\"Add `prefix` to all unprefixed names in `s`\"", "toks", "=", "xpath_lexer", ".", "scan", "(", "s", ")", "toks2", "=", "[", "_add_prefix", "(", "prefix", ",", "tok", ")", "for", "tok", "in", "toks", ...
Add `prefix` to all unprefixed names in `s`
[ "Add", "prefix", "to", "all", "unprefixed", "names", "in", "s" ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/xpath.py#L56-L64
train
mbj4668/pyang
pyang/syntax.py
chk_date_arg
def chk_date_arg(s): """Checks if the string `s` is a valid date string. Return True of False.""" if re_date.search(s) is None: return False comp = s.split('-') try: dt = datetime.date(int(comp[0]), int(comp[1]), int(comp[2])) return True except Exception as e: r...
python
def chk_date_arg(s): """Checks if the string `s` is a valid date string. Return True of False.""" if re_date.search(s) is None: return False comp = s.split('-') try: dt = datetime.date(int(comp[0]), int(comp[1]), int(comp[2])) return True except Exception as e: r...
[ "def", "chk_date_arg", "(", "s", ")", ":", "if", "re_date", ".", "search", "(", "s", ")", "is", "None", ":", "return", "False", "comp", "=", "s", ".", "split", "(", "'-'", ")", "try", ":", "dt", "=", "datetime", ".", "date", "(", "int", "(", "c...
Checks if the string `s` is a valid date string. Return True of False.
[ "Checks", "if", "the", "string", "s", "is", "a", "valid", "date", "string", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/syntax.py#L173-L184
train
mbj4668/pyang
pyang/syntax.py
chk_enum_arg
def chk_enum_arg(s): """Checks if the string `s` is a valid enum string. Return True or False.""" if len(s) == 0 or s[0].isspace() or s[-1].isspace(): return False else: return True
python
def chk_enum_arg(s): """Checks if the string `s` is a valid enum string. Return True or False.""" if len(s) == 0 or s[0].isspace() or s[-1].isspace(): return False else: return True
[ "def", "chk_enum_arg", "(", "s", ")", ":", "if", "len", "(", "s", ")", "==", "0", "or", "s", "[", "0", "]", ".", "isspace", "(", ")", "or", "s", "[", "-", "1", "]", ".", "isspace", "(", ")", ":", "return", "False", "else", ":", "return", "T...
Checks if the string `s` is a valid enum string. Return True or False.
[ "Checks", "if", "the", "string", "s", "is", "a", "valid", "enum", "string", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/syntax.py#L186-L194
train
mbj4668/pyang
pyang/syntax.py
chk_fraction_digits_arg
def chk_fraction_digits_arg(s): """Checks if the string `s` is a valid fraction-digits argument. Return True or False.""" try: v = int(s) if v >= 1 and v <= 18: return True else: return False except ValueError: return False
python
def chk_fraction_digits_arg(s): """Checks if the string `s` is a valid fraction-digits argument. Return True or False.""" try: v = int(s) if v >= 1 and v <= 18: return True else: return False except ValueError: return False
[ "def", "chk_fraction_digits_arg", "(", "s", ")", ":", "try", ":", "v", "=", "int", "(", "s", ")", "if", "v", ">=", "1", "and", "v", "<=", "18", ":", "return", "True", "else", ":", "return", "False", "except", "ValueError", ":", "return", "False" ]
Checks if the string `s` is a valid fraction-digits argument. Return True or False.
[ "Checks", "if", "the", "string", "s", "is", "a", "valid", "fraction", "-", "digits", "argument", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/syntax.py#L196-L207
train
mbj4668/pyang
pyang/translators/dsdl.py
Patch.combine
def combine(self, patch): """Add `patch.plist` to `self.plist`.""" exclusive = set(["config", "default", "mandatory", "presence", "min-elements", "max-elements"]) kws = set([s.keyword for s in self.plist]) & exclusive add = [n for n in patch.plist if n.keyword not in...
python
def combine(self, patch): """Add `patch.plist` to `self.plist`.""" exclusive = set(["config", "default", "mandatory", "presence", "min-elements", "max-elements"]) kws = set([s.keyword for s in self.plist]) & exclusive add = [n for n in patch.plist if n.keyword not in...
[ "def", "combine", "(", "self", ",", "patch", ")", ":", "exclusive", "=", "set", "(", "[", "\"config\"", ",", "\"default\"", ",", "\"mandatory\"", ",", "\"presence\"", ",", "\"min-elements\"", ",", "\"max-elements\"", "]", ")", "kws", "=", "set", "(", "[", ...
Add `patch.plist` to `self.plist`.
[ "Add", "patch", ".", "plist", "to", "self", ".", "plist", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L136-L142
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.serialize
def serialize(self): """Return the string representation of the receiver.""" res = '<?xml version="1.0" encoding="UTF-8"?>' for ns in self.namespaces: self.top_grammar.attr["xmlns:" + self.namespaces[ns]] = ns res += self.top_grammar.start_tag() for ch in self.top_gra...
python
def serialize(self): """Return the string representation of the receiver.""" res = '<?xml version="1.0" encoding="UTF-8"?>' for ns in self.namespaces: self.top_grammar.attr["xmlns:" + self.namespaces[ns]] = ns res += self.top_grammar.start_tag() for ch in self.top_gra...
[ "def", "serialize", "(", "self", ")", ":", "res", "=", "'<?xml version=\"1.0\" encoding=\"UTF-8\"?>'", "for", "ns", "in", "self", ".", "namespaces", ":", "self", ".", "top_grammar", ".", "attr", "[", "\"xmlns:\"", "+", "self", ".", "namespaces", "[", "ns", "...
Return the string representation of the receiver.
[ "Return", "the", "string", "representation", "of", "the", "receiver", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L340-L353
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.setup_top
def setup_top(self): """Create top-level elements of the hybrid schema.""" self.top_grammar = SchemaNode("grammar") self.top_grammar.attr = { "xmlns": "http://relaxng.org/ns/structure/1.0", "datatypeLibrary": "http://www.w3.org/2001/XMLSchema-datatypes"} self.tree...
python
def setup_top(self): """Create top-level elements of the hybrid schema.""" self.top_grammar = SchemaNode("grammar") self.top_grammar.attr = { "xmlns": "http://relaxng.org/ns/structure/1.0", "datatypeLibrary": "http://www.w3.org/2001/XMLSchema-datatypes"} self.tree...
[ "def", "setup_top", "(", "self", ")", ":", "self", ".", "top_grammar", "=", "SchemaNode", "(", "\"grammar\"", ")", "self", ".", "top_grammar", ".", "attr", "=", "{", "\"xmlns\"", ":", "\"http://relaxng.org/ns/structure/1.0\"", ",", "\"datatypeLibrary\"", ":", "\...
Create top-level elements of the hybrid schema.
[ "Create", "top", "-", "level", "elements", "of", "the", "hybrid", "schema", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L424-L430
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.create_roots
def create_roots(self, yam): """Create the top-level structure for module `yam`.""" self.local_grammar = SchemaNode("grammar") self.local_grammar.attr = { "ns": yam.search_one("namespace").arg, "nma:module": self.module.arg} src_text = "YANG module '%s'" % yam.arg...
python
def create_roots(self, yam): """Create the top-level structure for module `yam`.""" self.local_grammar = SchemaNode("grammar") self.local_grammar.attr = { "ns": yam.search_one("namespace").arg, "nma:module": self.module.arg} src_text = "YANG module '%s'" % yam.arg...
[ "def", "create_roots", "(", "self", ",", "yam", ")", ":", "self", ".", "local_grammar", "=", "SchemaNode", "(", "\"grammar\"", ")", "self", ".", "local_grammar", ".", "attr", "=", "{", "\"ns\"", ":", "yam", ".", "search_one", "(", "\"namespace\"", ")", "...
Create the top-level structure for module `yam`.
[ "Create", "the", "top", "-", "level", "structure", "for", "module", "yam", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L432-L448
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.yang_to_xpath
def yang_to_xpath(self, xpe): """Transform YANG's `xpath` to a form suitable for Schematron. 1. Prefixes are added to unprefixed local names. Inside global groupings, the prefix is represented as the variable '$pref' which is substituted via Schematron abstract patterns...
python
def yang_to_xpath(self, xpe): """Transform YANG's `xpath` to a form suitable for Schematron. 1. Prefixes are added to unprefixed local names. Inside global groupings, the prefix is represented as the variable '$pref' which is substituted via Schematron abstract patterns...
[ "def", "yang_to_xpath", "(", "self", ",", "xpe", ")", ":", "if", "self", ".", "gg_level", ":", "pref", "=", "\"$pref:\"", "else", ":", "pref", "=", "self", ".", "prefix_stack", "[", "-", "1", "]", "+", "\":\"", "toks", "=", "xpath_lexer", ".", "scan"...
Transform YANG's `xpath` to a form suitable for Schematron. 1. Prefixes are added to unprefixed local names. Inside global groupings, the prefix is represented as the variable '$pref' which is substituted via Schematron abstract patterns. 2. '$root' is prepended to ever...
[ "Transform", "YANG", "s", "xpath", "to", "a", "form", "suitable", "for", "Schematron", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L450-L475
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.register_identity
def register_identity(self, id_stmt): """Register `id_stmt` with its base identity, if any. """ bst = id_stmt.search_one("base") if bst: bder = self.identity_deps.setdefault(bst.i_identity, []) bder.append(id_stmt)
python
def register_identity(self, id_stmt): """Register `id_stmt` with its base identity, if any. """ bst = id_stmt.search_one("base") if bst: bder = self.identity_deps.setdefault(bst.i_identity, []) bder.append(id_stmt)
[ "def", "register_identity", "(", "self", ",", "id_stmt", ")", ":", "bst", "=", "id_stmt", ".", "search_one", "(", "\"base\"", ")", "if", "bst", ":", "bder", "=", "self", ".", "identity_deps", ".", "setdefault", "(", "bst", ".", "i_identity", ",", "[", ...
Register `id_stmt` with its base identity, if any.
[ "Register", "id_stmt", "with", "its", "base", "identity", "if", "any", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L498-L504
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.add_derived_identity
def add_derived_identity(self, id_stmt): """Add pattern def for `id_stmt` and all derived identities. The corresponding "ref" pattern is returned. """ p = self.add_namespace(id_stmt.main_module()) if id_stmt not in self.identities: # add named pattern def self.iden...
python
def add_derived_identity(self, id_stmt): """Add pattern def for `id_stmt` and all derived identities. The corresponding "ref" pattern is returned. """ p = self.add_namespace(id_stmt.main_module()) if id_stmt not in self.identities: # add named pattern def self.iden...
[ "def", "add_derived_identity", "(", "self", ",", "id_stmt", ")", ":", "p", "=", "self", ".", "add_namespace", "(", "id_stmt", ".", "main_module", "(", ")", ")", "if", "id_stmt", "not", "in", "self", ".", "identities", ":", "self", ".", "identities", "[",...
Add pattern def for `id_stmt` and all derived identities. The corresponding "ref" pattern is returned.
[ "Add", "pattern", "def", "for", "id_stmt", "and", "all", "derived", "identities", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L506-L524
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.preload_defs
def preload_defs(self): """Preload all top-level definitions.""" for d in (self.module.search("grouping") + self.module.search("typedef")): uname, dic = self.unique_def_name(d) self.install_def(uname, d, dic)
python
def preload_defs(self): """Preload all top-level definitions.""" for d in (self.module.search("grouping") + self.module.search("typedef")): uname, dic = self.unique_def_name(d) self.install_def(uname, d, dic)
[ "def", "preload_defs", "(", "self", ")", ":", "for", "d", "in", "(", "self", ".", "module", ".", "search", "(", "\"grouping\"", ")", "+", "self", ".", "module", ".", "search", "(", "\"typedef\"", ")", ")", ":", "uname", ",", "dic", "=", "self", "."...
Preload all top-level definitions.
[ "Preload", "all", "top", "-", "level", "definitions", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L526-L531
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.add_prefix
def add_prefix(self, name, stmt): """Return `name` prepended with correct prefix. If the name is already prefixed, the prefix may be translated to the value obtained from `self.module_prefixes`. Unmodified `name` is returned if we are inside a global grouping. """ if se...
python
def add_prefix(self, name, stmt): """Return `name` prepended with correct prefix. If the name is already prefixed, the prefix may be translated to the value obtained from `self.module_prefixes`. Unmodified `name` is returned if we are inside a global grouping. """ if se...
[ "def", "add_prefix", "(", "self", ",", "name", ",", "stmt", ")", ":", "if", "self", ".", "gg_level", ":", "return", "name", "pref", ",", "colon", ",", "local", "=", "name", ".", "partition", "(", "\":\"", ")", "if", "colon", ":", "return", "(", "se...
Return `name` prepended with correct prefix. If the name is already prefixed, the prefix may be translated to the value obtained from `self.module_prefixes`. Unmodified `name` is returned if we are inside a global grouping.
[ "Return", "name", "prepended", "with", "correct", "prefix", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L533-L546
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.dc_element
def dc_element(self, parent, name, text): """Add DC element `name` containing `text` to `parent`.""" if self.dc_uri in self.namespaces: dcel = SchemaNode(self.namespaces[self.dc_uri] + ":" + name, text=text) parent.children.insert(0,dcel)
python
def dc_element(self, parent, name, text): """Add DC element `name` containing `text` to `parent`.""" if self.dc_uri in self.namespaces: dcel = SchemaNode(self.namespaces[self.dc_uri] + ":" + name, text=text) parent.children.insert(0,dcel)
[ "def", "dc_element", "(", "self", ",", "parent", ",", "name", ",", "text", ")", ":", "if", "self", ".", "dc_uri", "in", "self", ".", "namespaces", ":", "dcel", "=", "SchemaNode", "(", "self", ".", "namespaces", "[", "self", ".", "dc_uri", "]", "+", ...
Add DC element `name` containing `text` to `parent`.
[ "Add", "DC", "element", "name", "containing", "text", "to", "parent", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L557-L562
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.get_default
def get_default(self, stmt, refd): """Return default value for `stmt` node. `refd` is a dictionary of applicable refinements that is constructed in the `process_patches` method. """ if refd["default"]: return refd["default"] defst = stmt.search_one("defau...
python
def get_default(self, stmt, refd): """Return default value for `stmt` node. `refd` is a dictionary of applicable refinements that is constructed in the `process_patches` method. """ if refd["default"]: return refd["default"] defst = stmt.search_one("defau...
[ "def", "get_default", "(", "self", ",", "stmt", ",", "refd", ")", ":", "if", "refd", "[", "\"default\"", "]", ":", "return", "refd", "[", "\"default\"", "]", "defst", "=", "stmt", ".", "search_one", "(", "\"default\"", ")", "if", "defst", ":", "return"...
Return default value for `stmt` node. `refd` is a dictionary of applicable refinements that is constructed in the `process_patches` method.
[ "Return", "default", "value", "for", "stmt", "node", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L564-L575
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.add_patch
def add_patch(self, pset, augref): """Add patch corresponding to `augref` to `pset`. `augref` must be either 'augment' or 'refine' statement. """ try: path = [ self.add_prefix(c, augref) for c in augref.arg.split("/") if c ] except KeyError: ...
python
def add_patch(self, pset, augref): """Add patch corresponding to `augref` to `pset`. `augref` must be either 'augment' or 'refine' statement. """ try: path = [ self.add_prefix(c, augref) for c in augref.arg.split("/") if c ] except KeyError: ...
[ "def", "add_patch", "(", "self", ",", "pset", ",", "augref", ")", ":", "try", ":", "path", "=", "[", "self", ".", "add_prefix", "(", "c", ",", "augref", ")", "for", "c", "in", "augref", ".", "arg", ".", "split", "(", "\"/\"", ")", "if", "c", "]...
Add patch corresponding to `augref` to `pset`. `augref` must be either 'augment' or 'refine' statement.
[ "Add", "patch", "corresponding", "to", "augref", "to", "pset", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L598-L618
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.apply_augments
def apply_augments(self, auglist, p_elem, pset): """Handle substatements of augments from `auglist`. The augments are applied in the context of `p_elem`. `pset` is a patch set containing patches that may be applicable to descendants. """ for a in auglist: pa...
python
def apply_augments(self, auglist, p_elem, pset): """Handle substatements of augments from `auglist`. The augments are applied in the context of `p_elem`. `pset` is a patch set containing patches that may be applicable to descendants. """ for a in auglist: pa...
[ "def", "apply_augments", "(", "self", ",", "auglist", ",", "p_elem", ",", "pset", ")", ":", "for", "a", "in", "auglist", ":", "par", "=", "a", ".", "parent", "if", "a", ".", "search_one", "(", "\"when\"", ")", "is", "None", ":", "wel", "=", "p_elem...
Handle substatements of augments from `auglist`. The augments are applied in the context of `p_elem`. `pset` is a patch set containing patches that may be applicable to descendants.
[ "Handle", "substatements", "of", "augments", "from", "auglist", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L620-L650
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.current_revision
def current_revision(self, r_stmts): """Pick the most recent revision date. `r_stmts` is a list of 'revision' statements. """ cur = max([[int(p) for p in r.arg.split("-")] for r in r_stmts]) return "%4d-%02d-%02d" % tuple(cur)
python
def current_revision(self, r_stmts): """Pick the most recent revision date. `r_stmts` is a list of 'revision' statements. """ cur = max([[int(p) for p in r.arg.split("-")] for r in r_stmts]) return "%4d-%02d-%02d" % tuple(cur)
[ "def", "current_revision", "(", "self", ",", "r_stmts", ")", ":", "cur", "=", "max", "(", "[", "[", "int", "(", "p", ")", "for", "p", "in", "r", ".", "arg", ".", "split", "(", "\"-\"", ")", "]", "for", "r", "in", "r_stmts", "]", ")", "return", ...
Pick the most recent revision date. `r_stmts` is a list of 'revision' statements.
[ "Pick", "the", "most", "recent", "revision", "date", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L652-L658
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.install_def
def install_def(self, name, dstmt, def_map, interleave=False): """Install definition `name` into the appropriate dictionary. `dstmt` is the definition statement ('typedef' or 'grouping') that is to be mapped to a RELAX NG named pattern '<define name="`name`">'. `def_map` must be either ...
python
def install_def(self, name, dstmt, def_map, interleave=False): """Install definition `name` into the appropriate dictionary. `dstmt` is the definition statement ('typedef' or 'grouping') that is to be mapped to a RELAX NG named pattern '<define name="`name`">'. `def_map` must be either ...
[ "def", "install_def", "(", "self", ",", "name", ",", "dstmt", ",", "def_map", ",", "interleave", "=", "False", ")", ":", "delem", "=", "SchemaNode", ".", "define", "(", "name", ",", "interleave", "=", "interleave", ")", "delem", ".", "attr", "[", "\"na...
Install definition `name` into the appropriate dictionary. `dstmt` is the definition statement ('typedef' or 'grouping') that is to be mapped to a RELAX NG named pattern '<define name="`name`">'. `def_map` must be either `self.local_defs` or `self.global_defs`. `interleave` determines t...
[ "Install", "definition", "name", "into", "the", "appropriate", "dictionary", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L666-L680
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.rng_annotation
def rng_annotation(self, stmt, p_elem): """Append YIN representation of extension statement `stmt`.""" ext = stmt.i_extension prf, extkw = stmt.raw_keyword (modname,rev)=stmt.i_module.i_prefixes[prf] prefix = self.add_namespace( statements.modulename_to_module(self.mo...
python
def rng_annotation(self, stmt, p_elem): """Append YIN representation of extension statement `stmt`.""" ext = stmt.i_extension prf, extkw = stmt.raw_keyword (modname,rev)=stmt.i_module.i_prefixes[prf] prefix = self.add_namespace( statements.modulename_to_module(self.mo...
[ "def", "rng_annotation", "(", "self", ",", "stmt", ",", "p_elem", ")", ":", "ext", "=", "stmt", ".", "i_extension", "prf", ",", "extkw", "=", "stmt", ".", "raw_keyword", "(", "modname", ",", "rev", ")", "=", "stmt", ".", "i_module", ".", "i_prefixes", ...
Append YIN representation of extension statement `stmt`.
[ "Append", "YIN", "representation", "of", "extension", "statement", "stmt", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L682-L696
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.propagate_occur
def propagate_occur(self, node, value): """Propagate occurence `value` to `node` and its ancestors. Occurence values are defined and explained in the SchemaNode class. """ while node.occur < value: node.occur = value if node.name == "define": ...
python
def propagate_occur(self, node, value): """Propagate occurence `value` to `node` and its ancestors. Occurence values are defined and explained in the SchemaNode class. """ while node.occur < value: node.occur = value if node.name == "define": ...
[ "def", "propagate_occur", "(", "self", ",", "node", ",", "value", ")", ":", "while", "node", ".", "occur", "<", "value", ":", "node", ".", "occur", "=", "value", "if", "node", ".", "name", "==", "\"define\"", ":", "break", "node", "=", "node", ".", ...
Propagate occurence `value` to `node` and its ancestors. Occurence values are defined and explained in the SchemaNode class.
[ "Propagate", "occurence", "value", "to", "node", "and", "its", "ancestors", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L698-L708
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.process_patches
def process_patches(self, pset, stmt, elem, altname=None): """Process patches for data node `name` from `pset`. `stmt` provides the context in YANG and `elem` is the parent element in the output schema. Refinements adding documentation and changing the config status are immediately appl...
python
def process_patches(self, pset, stmt, elem, altname=None): """Process patches for data node `name` from `pset`. `stmt` provides the context in YANG and `elem` is the parent element in the output schema. Refinements adding documentation and changing the config status are immediately appl...
[ "def", "process_patches", "(", "self", ",", "pset", ",", "stmt", ",", "elem", ",", "altname", "=", "None", ")", ":", "if", "altname", ":", "name", "=", "altname", "else", ":", "name", "=", "stmt", ".", "arg", "new_pset", "=", "{", "}", "augments", ...
Process patches for data node `name` from `pset`. `stmt` provides the context in YANG and `elem` is the parent element in the output schema. Refinements adding documentation and changing the config status are immediately applied. The returned tuple consists of: - a dictionary ...
[ "Process", "patches", "for", "data", "node", "name", "from", "pset", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L710-L757
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.lookup_expand
def lookup_expand(self, stmt, names): """Find schema nodes under `stmt`, also in used groupings. `names` is a list with qualified names of the schema nodes to look up. All 'uses'/'grouping' pairs between `stmt` and found schema nodes are marked for expansion. """ if not ...
python
def lookup_expand(self, stmt, names): """Find schema nodes under `stmt`, also in used groupings. `names` is a list with qualified names of the schema nodes to look up. All 'uses'/'grouping' pairs between `stmt` and found schema nodes are marked for expansion. """ if not ...
[ "def", "lookup_expand", "(", "self", ",", "stmt", ",", "names", ")", ":", "if", "not", "names", ":", "return", "[", "]", "todo", "=", "[", "stmt", "]", "while", "todo", ":", "pst", "=", "todo", ".", "pop", "(", ")", "for", "sub", "in", "pst", "...
Find schema nodes under `stmt`, also in used groupings. `names` is a list with qualified names of the schema nodes to look up. All 'uses'/'grouping' pairs between `stmt` and found schema nodes are marked for expansion.
[ "Find", "schema", "nodes", "under", "stmt", "also", "in", "used", "groupings", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L780-L805
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.type_with_ranges
def type_with_ranges(self, tchain, p_elem, rangekw, gen_data): """Handle types with 'range' or 'length' restrictions. `tchain` is the chain of type definitions from which the ranges may need to be extracted. `rangekw` is the statement keyword determining the range type (either 'range' o...
python
def type_with_ranges(self, tchain, p_elem, rangekw, gen_data): """Handle types with 'range' or 'length' restrictions. `tchain` is the chain of type definitions from which the ranges may need to be extracted. `rangekw` is the statement keyword determining the range type (either 'range' o...
[ "def", "type_with_ranges", "(", "self", ",", "tchain", ",", "p_elem", ",", "rangekw", ",", "gen_data", ")", ":", "ranges", "=", "self", ".", "get_ranges", "(", "tchain", ",", "rangekw", ")", "if", "not", "ranges", ":", "return", "p_elem", ".", "subnode",...
Handle types with 'range' or 'length' restrictions. `tchain` is the chain of type definitions from which the ranges may need to be extracted. `rangekw` is the statement keyword determining the range type (either 'range' or 'length'). `gen_data` is a function that generates the o...
[ "Handle", "types", "with", "range", "or", "length", "restrictions", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L807-L825
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.get_ranges
def get_ranges(self, tchain, kw): """Return list of ranges defined in `tchain`. `kw` is the statement keyword determining the type of the range, i.e. 'range' or 'length'. `tchain` is the chain of type definitions from which the resulting range is obtained. The returned value is...
python
def get_ranges(self, tchain, kw): """Return list of ranges defined in `tchain`. `kw` is the statement keyword determining the type of the range, i.e. 'range' or 'length'. `tchain` is the chain of type definitions from which the resulting range is obtained. The returned value is...
[ "def", "get_ranges", "(", "self", ",", "tchain", ",", "kw", ")", ":", "(", "lo", ",", "hi", ")", "=", "(", "\"min\"", ",", "\"max\"", ")", "ran", "=", "None", "for", "t", "in", "tchain", ":", "rstmt", "=", "t", ".", "search_one", "(", "kw", ")"...
Return list of ranges defined in `tchain`. `kw` is the statement keyword determining the type of the range, i.e. 'range' or 'length'. `tchain` is the chain of type definitions from which the resulting range is obtained. The returned value is a list of tuples containing the segments ...
[ "Return", "list", "of", "ranges", "defined", "in", "tchain", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L827-L850
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.handle_stmt
def handle_stmt(self, stmt, p_elem, pset={}): """ Run handler method for statement `stmt`. `p_elem` is the parent node in the output schema. `pset` is the current "patch set" - a dictionary with keys being QNames of schema nodes at the current level of hierarchy for which ...
python
def handle_stmt(self, stmt, p_elem, pset={}): """ Run handler method for statement `stmt`. `p_elem` is the parent node in the output schema. `pset` is the current "patch set" - a dictionary with keys being QNames of schema nodes at the current level of hierarchy for which ...
[ "def", "handle_stmt", "(", "self", ",", "stmt", ",", "p_elem", ",", "pset", "=", "{", "}", ")", ":", "if", "self", ".", "debug", ">", "0", ":", "sys", ".", "stderr", ".", "write", "(", "\"Handling '%s %s'\\n\"", "%", "(", "util", ".", "keyword_to_str...
Run handler method for statement `stmt`. `p_elem` is the parent node in the output schema. `pset` is the current "patch set" - a dictionary with keys being QNames of schema nodes at the current level of hierarchy for which (or descendants thereof) any pending patches exist. The values ...
[ "Run", "handler", "method", "for", "statement", "stmt", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L882-L915
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.handle_substmts
def handle_substmts(self, stmt, p_elem, pset={}): """Handle all substatements of `stmt`.""" for sub in stmt.substmts: self.handle_stmt(sub, p_elem, pset)
python
def handle_substmts(self, stmt, p_elem, pset={}): """Handle all substatements of `stmt`.""" for sub in stmt.substmts: self.handle_stmt(sub, p_elem, pset)
[ "def", "handle_substmts", "(", "self", ",", "stmt", ",", "p_elem", ",", "pset", "=", "{", "}", ")", ":", "for", "sub", "in", "stmt", ".", "substmts", ":", "self", ".", "handle_stmt", "(", "sub", ",", "p_elem", ",", "pset", ")" ]
Handle all substatements of `stmt`.
[ "Handle", "all", "substatements", "of", "stmt", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L917-L920
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.nma_attribute
def nma_attribute(self, stmt, p_elem, pset=None): """Map `stmt` to a NETMOD-specific attribute. The name of the attribute is the same as the 'keyword' of `stmt`. """ att = "nma:" + stmt.keyword if att not in p_elem.attr: p_elem.attr[att] = stmt.arg
python
def nma_attribute(self, stmt, p_elem, pset=None): """Map `stmt` to a NETMOD-specific attribute. The name of the attribute is the same as the 'keyword' of `stmt`. """ att = "nma:" + stmt.keyword if att not in p_elem.attr: p_elem.attr[att] = stmt.arg
[ "def", "nma_attribute", "(", "self", ",", "stmt", ",", "p_elem", ",", "pset", "=", "None", ")", ":", "att", "=", "\"nma:\"", "+", "stmt", ".", "keyword", "if", "att", "not", "in", "p_elem", ".", "attr", ":", "p_elem", ".", "attr", "[", "att", "]", ...
Map `stmt` to a NETMOD-specific attribute. The name of the attribute is the same as the 'keyword' of `stmt`.
[ "Map", "stmt", "to", "a", "NETMOD", "-", "specific", "attribute", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L942-L950
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.type_stmt
def type_stmt(self, stmt, p_elem, pset): """Handle ``type`` statement. Built-in types are handled by one of the specific type callback methods defined below. """ typedef = stmt.i_typedef if typedef and not stmt.i_is_derived: # just ref uname, dic = self.uniqu...
python
def type_stmt(self, stmt, p_elem, pset): """Handle ``type`` statement. Built-in types are handled by one of the specific type callback methods defined below. """ typedef = stmt.i_typedef if typedef and not stmt.i_is_derived: # just ref uname, dic = self.uniqu...
[ "def", "type_stmt", "(", "self", ",", "stmt", ",", "p_elem", ",", "pset", ")", ":", "typedef", "=", "stmt", ".", "i_typedef", "if", "typedef", "and", "not", "stmt", ".", "i_is_derived", ":", "uname", ",", "dic", "=", "self", ".", "unique_def_name", "("...
Handle ``type`` statement. Built-in types are handled by one of the specific type callback methods defined below.
[ "Handle", "type", "statement", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L1119-L1152
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.choice_type
def choice_type(self, tchain, p_elem): """Handle ``enumeration`` and ``union`` types.""" elem = SchemaNode.choice(p_elem, occur=2) self.handle_substmts(tchain[0], elem)
python
def choice_type(self, tchain, p_elem): """Handle ``enumeration`` and ``union`` types.""" elem = SchemaNode.choice(p_elem, occur=2) self.handle_substmts(tchain[0], elem)
[ "def", "choice_type", "(", "self", ",", "tchain", ",", "p_elem", ")", ":", "elem", "=", "SchemaNode", ".", "choice", "(", "p_elem", ",", "occur", "=", "2", ")", "self", ".", "handle_substmts", "(", "tchain", "[", "0", "]", ",", "elem", ")" ]
Handle ``enumeration`` and ``union`` types.
[ "Handle", "enumeration", "and", "union", "types", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L1223-L1226
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.mapped_type
def mapped_type(self, tchain, p_elem): """Handle types that are simply mapped to RELAX NG.""" SchemaNode("data", p_elem).set_attr("type", self.datatype_map[tchain[0].arg])
python
def mapped_type(self, tchain, p_elem): """Handle types that are simply mapped to RELAX NG.""" SchemaNode("data", p_elem).set_attr("type", self.datatype_map[tchain[0].arg])
[ "def", "mapped_type", "(", "self", ",", "tchain", ",", "p_elem", ")", ":", "SchemaNode", "(", "\"data\"", ",", "p_elem", ")", ".", "set_attr", "(", "\"type\"", ",", "self", ".", "datatype_map", "[", "tchain", "[", "0", "]", ".", "arg", "]", ")" ]
Handle types that are simply mapped to RELAX NG.
[ "Handle", "types", "that", "are", "simply", "mapped", "to", "RELAX", "NG", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L1262-L1265
train
mbj4668/pyang
pyang/translators/dsdl.py
HybridDSDLSchema.numeric_type
def numeric_type(self, tchain, p_elem): """Handle numeric types.""" typ = tchain[0].arg def gen_data(): elem = SchemaNode("data").set_attr("type", self.datatype_map[typ]) if typ == "decimal64": fd = tchain[0].search_one("fraction-digits").arg ...
python
def numeric_type(self, tchain, p_elem): """Handle numeric types.""" typ = tchain[0].arg def gen_data(): elem = SchemaNode("data").set_attr("type", self.datatype_map[typ]) if typ == "decimal64": fd = tchain[0].search_one("fraction-digits").arg ...
[ "def", "numeric_type", "(", "self", ",", "tchain", ",", "p_elem", ")", ":", "typ", "=", "tchain", "[", "0", "]", ".", "arg", "def", "gen_data", "(", ")", ":", "elem", "=", "SchemaNode", "(", "\"data\"", ")", ".", "set_attr", "(", "\"type\"", ",", "...
Handle numeric types.
[ "Handle", "numeric", "types", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/dsdl.py#L1267-L1277
train
mbj4668/pyang
pyang/grammar.py
add_stmt
def add_stmt(stmt, arg_rules): """Use by plugins to add grammar for an extension statement.""" (arg, rules) = arg_rules stmt_map[stmt] = (arg, rules)
python
def add_stmt(stmt, arg_rules): """Use by plugins to add grammar for an extension statement.""" (arg, rules) = arg_rules stmt_map[stmt] = (arg, rules)
[ "def", "add_stmt", "(", "stmt", ",", "arg_rules", ")", ":", "(", "arg", ",", "rules", ")", "=", "arg_rules", "stmt_map", "[", "stmt", "]", "=", "(", "arg", ",", "rules", ")" ]
Use by plugins to add grammar for an extension statement.
[ "Use", "by", "plugins", "to", "add", "grammar", "for", "an", "extension", "statement", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/grammar.py#L77-L80
train
mbj4668/pyang
pyang/grammar.py
add_to_stmts_rules
def add_to_stmts_rules(stmts, rules): """Use by plugins to add extra rules to the existing rules for a statement.""" def is_rule_less_than(ra, rb): rka = ra[0] rkb = rb[0] if not util.is_prefixed(rkb): # old rule is non-prefixed; append new rule after return F...
python
def add_to_stmts_rules(stmts, rules): """Use by plugins to add extra rules to the existing rules for a statement.""" def is_rule_less_than(ra, rb): rka = ra[0] rkb = rb[0] if not util.is_prefixed(rkb): # old rule is non-prefixed; append new rule after return F...
[ "def", "add_to_stmts_rules", "(", "stmts", ",", "rules", ")", ":", "def", "is_rule_less_than", "(", "ra", ",", "rb", ")", ":", "rka", "=", "ra", "[", "0", "]", "rkb", "=", "rb", "[", "0", "]", "if", "not", "util", ".", "is_prefixed", "(", "rkb", ...
Use by plugins to add extra rules to the existing rules for a statement.
[ "Use", "by", "plugins", "to", "add", "extra", "rules", "to", "the", "existing", "rules", "for", "a", "statement", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/grammar.py#L82-L106
train
mbj4668/pyang
pyang/grammar.py
chk_module_statements
def chk_module_statements(ctx, module_stmt, canonical=False): """Validate the statement hierarchy according to the grammar. Return True if module is valid, False otherwise. """ return chk_statement(ctx, module_stmt, top_stmts, canonical)
python
def chk_module_statements(ctx, module_stmt, canonical=False): """Validate the statement hierarchy according to the grammar. Return True if module is valid, False otherwise. """ return chk_statement(ctx, module_stmt, top_stmts, canonical)
[ "def", "chk_module_statements", "(", "ctx", ",", "module_stmt", ",", "canonical", "=", "False", ")", ":", "return", "chk_statement", "(", "ctx", ",", "module_stmt", ",", "top_stmts", ",", "canonical", ")" ]
Validate the statement hierarchy according to the grammar. Return True if module is valid, False otherwise.
[ "Validate", "the", "statement", "hierarchy", "according", "to", "the", "grammar", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/grammar.py#L570-L575
train
mbj4668/pyang
pyang/grammar.py
chk_statement
def chk_statement(ctx, stmt, grammar, canonical=False): """Validate `stmt` according to `grammar`. Marks each statement in the hierearchy with stmt.is_grammatically_valid, which is a boolean. Return True if stmt is valid, False otherwise. """ n = len(ctx.errors) if canonical == True: ...
python
def chk_statement(ctx, stmt, grammar, canonical=False): """Validate `stmt` according to `grammar`. Marks each statement in the hierearchy with stmt.is_grammatically_valid, which is a boolean. Return True if stmt is valid, False otherwise. """ n = len(ctx.errors) if canonical == True: ...
[ "def", "chk_statement", "(", "ctx", ",", "stmt", ",", "grammar", ",", "canonical", "=", "False", ")", ":", "n", "=", "len", "(", "ctx", ".", "errors", ")", "if", "canonical", "==", "True", ":", "canspec", "=", "grammar", "else", ":", "canspec", "=", ...
Validate `stmt` according to `grammar`. Marks each statement in the hierearchy with stmt.is_grammatically_valid, which is a boolean. Return True if stmt is valid, False otherwise.
[ "Validate", "stmt", "according", "to", "grammar", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/grammar.py#L577-L591
train
mbj4668/pyang
pyang/grammar.py
sort_canonical
def sort_canonical(keyword, stmts): """Sort all `stmts` in the canonical order defined by `keyword`. Return the sorted list. The `stmt` list is not modified. If `keyword` does not have a canonical order, the list is returned as is. """ try: (_arg_type, subspec) = stmt_map[keyword] ...
python
def sort_canonical(keyword, stmts): """Sort all `stmts` in the canonical order defined by `keyword`. Return the sorted list. The `stmt` list is not modified. If `keyword` does not have a canonical order, the list is returned as is. """ try: (_arg_type, subspec) = stmt_map[keyword] ...
[ "def", "sort_canonical", "(", "keyword", ",", "stmts", ")", ":", "try", ":", "(", "_arg_type", ",", "subspec", ")", "=", "stmt_map", "[", "keyword", "]", "except", "KeyError", ":", "return", "stmts", "res", "=", "[", "]", "keep", "=", "[", "s", "[", ...
Sort all `stmts` in the canonical order defined by `keyword`. Return the sorted list. The `stmt` list is not modified. If `keyword` does not have a canonical order, the list is returned as is.
[ "Sort", "all", "stmts", "in", "the", "canonical", "order", "defined", "by", "keyword", ".", "Return", "the", "sorted", "list", ".", "The", "stmt", "list", "is", "not", "modified", ".", "If", "keyword", "does", "not", "have", "a", "canonical", "order", "t...
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/grammar.py#L799-L828
train
mbj4668/pyang
pyang/xpath_lexer.py
scan
def scan(s): """Return a list of tokens, or throw SyntaxError on failure. """ line = 1 linepos = 1 pos = 0 toks = [] while pos < len(s): matched = False for (tokname, r) in patterns: m = r.match(s, pos) if m is not None: # found a match...
python
def scan(s): """Return a list of tokens, or throw SyntaxError on failure. """ line = 1 linepos = 1 pos = 0 toks = [] while pos < len(s): matched = False for (tokname, r) in patterns: m = r.match(s, pos) if m is not None: # found a match...
[ "def", "scan", "(", "s", ")", ":", "line", "=", "1", "linepos", "=", "1", "pos", "=", "0", "toks", "=", "[", "]", "while", "pos", "<", "len", "(", "s", ")", ":", "matched", "=", "False", "for", "(", "tokname", ",", "r", ")", "in", "patterns",...
Return a list of tokens, or throw SyntaxError on failure.
[ "Return", "a", "list", "of", "tokens", "or", "throw", "SyntaxError", "on", "failure", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/xpath_lexer.py#L112-L175
train
mbj4668/pyang
pyang/hello.py
HelloParser.yang_modules
def yang_modules(self): """ Return a list of advertised YANG module names with revisions. Avoid repeated modules. """ res = {} for c in self.capabilities: m = c.parameters.get("module") if m is None or m in res: continue res[m] = c.par...
python
def yang_modules(self): """ Return a list of advertised YANG module names with revisions. Avoid repeated modules. """ res = {} for c in self.capabilities: m = c.parameters.get("module") if m is None or m in res: continue res[m] = c.par...
[ "def", "yang_modules", "(", "self", ")", ":", "res", "=", "{", "}", "for", "c", "in", "self", ".", "capabilities", ":", "m", "=", "c", ".", "parameters", ".", "get", "(", "\"module\"", ")", "if", "m", "is", "None", "or", "m", "in", "res", ":", ...
Return a list of advertised YANG module names with revisions. Avoid repeated modules.
[ "Return", "a", "list", "of", "advertised", "YANG", "module", "names", "with", "revisions", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/hello.py#L75-L86
train
mbj4668/pyang
pyang/hello.py
HelloParser.get_features
def get_features(self, yam): """Return list of features declared for module `yam`.""" mcap = [ c for c in self.capabilities if c.parameters.get("module", None) == yam ][0] if not mcap.parameters.get("features"): return [] return mcap.parameters["features"].split(",")
python
def get_features(self, yam): """Return list of features declared for module `yam`.""" mcap = [ c for c in self.capabilities if c.parameters.get("module", None) == yam ][0] if not mcap.parameters.get("features"): return [] return mcap.parameters["features"].split(",")
[ "def", "get_features", "(", "self", ",", "yam", ")", ":", "mcap", "=", "[", "c", "for", "c", "in", "self", ".", "capabilities", "if", "c", ".", "parameters", ".", "get", "(", "\"module\"", ",", "None", ")", "==", "yam", "]", "[", "0", "]", "if", ...
Return list of features declared for module `yam`.
[ "Return", "list", "of", "features", "declared", "for", "module", "yam", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/hello.py#L88-L93
train
mbj4668/pyang
pyang/hello.py
HelloParser.registered_capabilities
def registered_capabilities(self): """Return dictionary of non-YANG capabilities. Only capabilities from the `CAPABILITIES` dictionary are taken into account. """ return dict ([ (CAPABILITIES[c.id],c) for c in self.capabilities if c.id in CAPABILITIES ])
python
def registered_capabilities(self): """Return dictionary of non-YANG capabilities. Only capabilities from the `CAPABILITIES` dictionary are taken into account. """ return dict ([ (CAPABILITIES[c.id],c) for c in self.capabilities if c.id in CAPABILITIES ])
[ "def", "registered_capabilities", "(", "self", ")", ":", "return", "dict", "(", "[", "(", "CAPABILITIES", "[", "c", ".", "id", "]", ",", "c", ")", "for", "c", "in", "self", ".", "capabilities", "if", "c", ".", "id", "in", "CAPABILITIES", "]", ")" ]
Return dictionary of non-YANG capabilities. Only capabilities from the `CAPABILITIES` dictionary are taken into account.
[ "Return", "dictionary", "of", "non", "-", "YANG", "capabilities", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/hello.py#L95-L102
train
mbj4668/pyang
pyang/util.py
listsdelete
def listsdelete(x, xs): """Return a new list with x removed from xs""" i = xs.index(x) return xs[:i] + xs[(i+1):]
python
def listsdelete(x, xs): """Return a new list with x removed from xs""" i = xs.index(x) return xs[:i] + xs[(i+1):]
[ "def", "listsdelete", "(", "x", ",", "xs", ")", ":", "i", "=", "xs", ".", "index", "(", "x", ")", "return", "xs", "[", ":", "i", "]", "+", "xs", "[", "(", "i", "+", "1", ")", ":", "]" ]
Return a new list with x removed from xs
[ "Return", "a", "new", "list", "with", "x", "removed", "from", "xs" ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/util.py#L76-L79
train
mbj4668/pyang
pyang/util.py
unique_prefixes
def unique_prefixes(context): """Return a dictionary with unique prefixes for modules in `context`. Keys are 'module' statements and values are prefixes, disambiguated where necessary. """ res = {} for m in context.modules.values(): if m.keyword == "submodule": continue prf = ne...
python
def unique_prefixes(context): """Return a dictionary with unique prefixes for modules in `context`. Keys are 'module' statements and values are prefixes, disambiguated where necessary. """ res = {} for m in context.modules.values(): if m.keyword == "submodule": continue prf = ne...
[ "def", "unique_prefixes", "(", "context", ")", ":", "res", "=", "{", "}", "for", "m", "in", "context", ".", "modules", ".", "values", "(", ")", ":", "if", "m", ".", "keyword", "==", "\"submodule\"", ":", "continue", "prf", "=", "new", "=", "m", "."...
Return a dictionary with unique prefixes for modules in `context`. Keys are 'module' statements and values are prefixes, disambiguated where necessary.
[ "Return", "a", "dictionary", "with", "unique", "prefixes", "for", "modules", "in", "context", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/util.py#L120-L135
train
mbj4668/pyang
setup.py
PyangDist.preprocess_files
def preprocess_files(self, prefix): """Change the installation prefix where necessary. """ if prefix is None: return files = ("bin/yang2dsdl", "man/man1/yang2dsdl.1", "pyang/plugins/jsonxsl.py") regex = re.compile("^(.*)/usr/local(.*)$") ...
python
def preprocess_files(self, prefix): """Change the installation prefix where necessary. """ if prefix is None: return files = ("bin/yang2dsdl", "man/man1/yang2dsdl.1", "pyang/plugins/jsonxsl.py") regex = re.compile("^(.*)/usr/local(.*)$") ...
[ "def", "preprocess_files", "(", "self", ",", "prefix", ")", ":", "if", "prefix", "is", "None", ":", "return", "files", "=", "(", "\"bin/yang2dsdl\"", ",", "\"man/man1/yang2dsdl.1\"", ",", "\"pyang/plugins/jsonxsl.py\"", ")", "regex", "=", "re", ".", "compile", ...
Change the installation prefix where necessary.
[ "Change", "the", "installation", "prefix", "where", "necessary", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/setup.py#L26-L45
train
mbj4668/pyang
pyang/__init__.py
Context.add_module
def add_module(self, ref, text, format=None, expect_modulename=None, expect_revision=None, expect_failure_error=True): """Parse a module text and add the module data to the context `ref` is a string which is used to identify the source of the text for...
python
def add_module(self, ref, text, format=None, expect_modulename=None, expect_revision=None, expect_failure_error=True): """Parse a module text and add the module data to the context `ref` is a string which is used to identify the source of the text for...
[ "def", "add_module", "(", "self", ",", "ref", ",", "text", ",", "format", "=", "None", ",", "expect_modulename", "=", "None", ",", "expect_revision", "=", "None", ",", "expect_failure_error", "=", "True", ")", ":", "if", "format", "==", "None", ":", "for...
Parse a module text and add the module data to the context `ref` is a string which is used to identify the source of the text for the user. used in error messages `text` is the raw text data `format` is one of 'yang' or 'yin'. Returns the parsed and validated module on s...
[ "Parse", "a", "module", "text", "and", "add", "the", "module", "data", "to", "the", "context" ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/__init__.py#L56-L113
train
mbj4668/pyang
pyang/__init__.py
Context.del_module
def del_module(self, module): """Remove a module from the context""" rev = util.get_latest_revision(module) del self.modules[(module.arg, rev)]
python
def del_module(self, module): """Remove a module from the context""" rev = util.get_latest_revision(module) del self.modules[(module.arg, rev)]
[ "def", "del_module", "(", "self", ",", "module", ")", ":", "rev", "=", "util", ".", "get_latest_revision", "(", "module", ")", "del", "self", ".", "modules", "[", "(", "module", ".", "arg", ",", "rev", ")", "]" ]
Remove a module from the context
[ "Remove", "a", "module", "from", "the", "context" ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/__init__.py#L138-L141
train
mbj4668/pyang
pyang/__init__.py
Context.get_module
def get_module(self, modulename, revision=None): """Return the module if it exists in the context""" if revision is None and modulename in self.revs: (revision, _handle) = self._get_latest_rev(self.revs[modulename]) if revision is not None: if (modulename,revision) in sel...
python
def get_module(self, modulename, revision=None): """Return the module if it exists in the context""" if revision is None and modulename in self.revs: (revision, _handle) = self._get_latest_rev(self.revs[modulename]) if revision is not None: if (modulename,revision) in sel...
[ "def", "get_module", "(", "self", ",", "modulename", ",", "revision", "=", "None", ")", ":", "if", "revision", "is", "None", "and", "modulename", "in", "self", ".", "revs", ":", "(", "revision", ",", "_handle", ")", "=", "self", ".", "_get_latest_rev", ...
Return the module if it exists in the context
[ "Return", "the", "module", "if", "it", "exists", "in", "the", "context" ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/__init__.py#L143-L151
train
mbj4668/pyang
pyang/plugin.py
init
def init(plugindirs=[]): """Initialize the plugin framework""" # initialize the builtin plugins from .translators import yang,yin,dsdl yang.pyang_plugin_init() yin.pyang_plugin_init() dsdl.pyang_plugin_init() # initialize installed plugins for ep in pkg_resources.iter_entry_points(grou...
python
def init(plugindirs=[]): """Initialize the plugin framework""" # initialize the builtin plugins from .translators import yang,yin,dsdl yang.pyang_plugin_init() yin.pyang_plugin_init() dsdl.pyang_plugin_init() # initialize installed plugins for ep in pkg_resources.iter_entry_points(grou...
[ "def", "init", "(", "plugindirs", "=", "[", "]", ")", ":", "from", ".", "translators", "import", "yang", ",", "yin", ",", "dsdl", "yang", ".", "pyang_plugin_init", "(", ")", "yin", ".", "pyang_plugin_init", "(", ")", "dsdl", ".", "pyang_plugin_init", "("...
Initialize the plugin framework
[ "Initialize", "the", "plugin", "framework" ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/plugin.py#L10-L63
train
mbj4668/pyang
pyang/yin_parser.py
YinParser.split_qname
def split_qname(qname): """Split `qname` into namespace URI and local name Return namespace and local name as a tuple. This is a static method.""" res = qname.split(YinParser.ns_sep) if len(res) == 1: # no namespace return None, res[0] else: ...
python
def split_qname(qname): """Split `qname` into namespace URI and local name Return namespace and local name as a tuple. This is a static method.""" res = qname.split(YinParser.ns_sep) if len(res) == 1: # no namespace return None, res[0] else: ...
[ "def", "split_qname", "(", "qname", ")", ":", "res", "=", "qname", ".", "split", "(", "YinParser", ".", "ns_sep", ")", "if", "len", "(", "res", ")", "==", "1", ":", "return", "None", ",", "res", "[", "0", "]", "else", ":", "return", "res" ]
Split `qname` into namespace URI and local name Return namespace and local name as a tuple. This is a static method.
[ "Split", "qname", "into", "namespace", "URI", "and", "local", "name" ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/yin_parser.py#L55-L64
train
mbj4668/pyang
pyang/yin_parser.py
YinParser.check_attr
def check_attr(self, pos, attrs): """Check for unknown attributes.""" for at in attrs: (ns, local_name) = self.split_qname(at) if ns is None: error.err_add(self.ctx.errors, pos, 'UNEXPECTED_ATTRIBUTE', local_name) elif ns...
python
def check_attr(self, pos, attrs): """Check for unknown attributes.""" for at in attrs: (ns, local_name) = self.split_qname(at) if ns is None: error.err_add(self.ctx.errors, pos, 'UNEXPECTED_ATTRIBUTE', local_name) elif ns...
[ "def", "check_attr", "(", "self", ",", "pos", ",", "attrs", ")", ":", "for", "at", "in", "attrs", ":", "(", "ns", ",", "local_name", ")", "=", "self", ".", "split_qname", "(", "at", ")", "if", "ns", "is", "None", ":", "error", ".", "err_add", "("...
Check for unknown attributes.
[ "Check", "for", "unknown", "attributes", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/yin_parser.py#L220-L230
train
mbj4668/pyang
pyang/yin_parser.py
YinParser.search_definition
def search_definition(self, module, keyword, arg): """Search for a defintion with `keyword` `name` Search the module and its submodules.""" r = module.search_one(keyword, arg) if r is not None: return r for i in module.search('include'): modulename = i.arg...
python
def search_definition(self, module, keyword, arg): """Search for a defintion with `keyword` `name` Search the module and its submodules.""" r = module.search_one(keyword, arg) if r is not None: return r for i in module.search('include'): modulename = i.arg...
[ "def", "search_definition", "(", "self", ",", "module", ",", "keyword", ",", "arg", ")", ":", "r", "=", "module", ".", "search_one", "(", "keyword", ",", "arg", ")", "if", "r", "is", "not", "None", ":", "return", "r", "for", "i", "in", "module", "....
Search for a defintion with `keyword` `name` Search the module and its submodules.
[ "Search", "for", "a", "defintion", "with", "keyword", "name", "Search", "the", "module", "and", "its", "submodules", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/yin_parser.py#L377-L390
train
mbj4668/pyang
pyang/translators/yang.py
emit_path_arg
def emit_path_arg(keywordstr, arg, fd, indent, max_line_len, line_len, eol): """Heuristically pretty print a path argument""" quote = '"' arg = escape_str(arg) if not(need_new_line(max_line_len, line_len, arg)): fd.write(" " + quote + arg + quote) return False ## FIXME: we should...
python
def emit_path_arg(keywordstr, arg, fd, indent, max_line_len, line_len, eol): """Heuristically pretty print a path argument""" quote = '"' arg = escape_str(arg) if not(need_new_line(max_line_len, line_len, arg)): fd.write(" " + quote + arg + quote) return False ## FIXME: we should...
[ "def", "emit_path_arg", "(", "keywordstr", ",", "arg", ",", "fd", ",", "indent", ",", "max_line_len", ",", "line_len", ",", "eol", ")", ":", "quote", "=", "'\"'", "arg", "=", "escape_str", "(", "arg", ")", "if", "not", "(", "need_new_line", "(", "max_l...
Heuristically pretty print a path argument
[ "Heuristically", "pretty", "print", "a", "path", "argument" ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/yang.py#L323-L356
train
mbj4668/pyang
pyang/translators/yang.py
emit_arg
def emit_arg(keywordstr, stmt, fd, indent, indentstep, max_line_len, line_len): """Heuristically pretty print the argument string with double quotes""" arg = escape_str(stmt.arg) lines = arg.splitlines(True) if len(lines) <= 1: if len(arg) > 0 and arg[-1] == '\n': arg = arg[:-1] + r'...
python
def emit_arg(keywordstr, stmt, fd, indent, indentstep, max_line_len, line_len): """Heuristically pretty print the argument string with double quotes""" arg = escape_str(stmt.arg) lines = arg.splitlines(True) if len(lines) <= 1: if len(arg) > 0 and arg[-1] == '\n': arg = arg[:-1] + r'...
[ "def", "emit_arg", "(", "keywordstr", ",", "stmt", ",", "fd", ",", "indent", ",", "indentstep", ",", "max_line_len", ",", "line_len", ")", ":", "arg", "=", "escape_str", "(", "stmt", ".", "arg", ")", "lines", "=", "arg", ".", "splitlines", "(", "True",...
Heuristically pretty print the argument string with double quotes
[ "Heuristically", "pretty", "print", "the", "argument", "string", "with", "double", "quotes" ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/translators/yang.py#L358-L404
train
mbj4668/pyang
pyang/plugins/sample-xml-skeleton.py
SampleXMLSkeletonPlugin.process_children
def process_children(self, node, elem, module, path, omit=[]): """Proceed with all children of `node`.""" for ch in node.i_children: if ch not in omit and (ch.i_config or self.doctype == "data"): self.node_handler.get(ch.keyword, self.ignore)( ch, elem, mo...
python
def process_children(self, node, elem, module, path, omit=[]): """Proceed with all children of `node`.""" for ch in node.i_children: if ch not in omit and (ch.i_config or self.doctype == "data"): self.node_handler.get(ch.keyword, self.ignore)( ch, elem, mo...
[ "def", "process_children", "(", "self", ",", "node", ",", "elem", ",", "module", ",", "path", ",", "omit", "=", "[", "]", ")", ":", "for", "ch", "in", "node", ".", "i_children", ":", "if", "ch", "not", "in", "omit", "and", "(", "ch", ".", "i_conf...
Proceed with all children of `node`.
[ "Proceed", "with", "all", "children", "of", "node", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/plugins/sample-xml-skeleton.py#L135-L140
train
mbj4668/pyang
pyang/plugins/sample-xml-skeleton.py
SampleXMLSkeletonPlugin.container
def container(self, node, elem, module, path): """Create a sample container element and proceed with its children.""" nel, newm, path = self.sample_element(node, elem, module, path) if path is None: return if self.annots: pres = node.search_one("presence") ...
python
def container(self, node, elem, module, path): """Create a sample container element and proceed with its children.""" nel, newm, path = self.sample_element(node, elem, module, path) if path is None: return if self.annots: pres = node.search_one("presence") ...
[ "def", "container", "(", "self", ",", "node", ",", "elem", ",", "module", ",", "path", ")", ":", "nel", ",", "newm", ",", "path", "=", "self", ".", "sample_element", "(", "node", ",", "elem", ",", "module", ",", "path", ")", "if", "path", "is", "...
Create a sample container element and proceed with its children.
[ "Create", "a", "sample", "container", "element", "and", "proceed", "with", "its", "children", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/plugins/sample-xml-skeleton.py#L142-L151
train
mbj4668/pyang
pyang/plugins/sample-xml-skeleton.py
SampleXMLSkeletonPlugin.leaf
def leaf(self, node, elem, module, path): """Create a sample leaf element.""" if node.i_default is None: nel, newm, path = self.sample_element(node, elem, module, path) if path is None: return if self.annots: nel.append(etree.Comment( ...
python
def leaf(self, node, elem, module, path): """Create a sample leaf element.""" if node.i_default is None: nel, newm, path = self.sample_element(node, elem, module, path) if path is None: return if self.annots: nel.append(etree.Comment( ...
[ "def", "leaf", "(", "self", ",", "node", ",", "elem", ",", "module", ",", "path", ")", ":", "if", "node", ".", "i_default", "is", "None", ":", "nel", ",", "newm", ",", "path", "=", "self", ".", "sample_element", "(", "node", ",", "elem", ",", "mo...
Create a sample leaf element.
[ "Create", "a", "sample", "leaf", "element", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/plugins/sample-xml-skeleton.py#L153-L166
train
mbj4668/pyang
pyang/plugins/sample-xml-skeleton.py
SampleXMLSkeletonPlugin.anyxml
def anyxml(self, node, elem, module, path): """Create a sample anyxml element.""" nel, newm, path = self.sample_element(node, elem, module, path) if path is None: return if self.annots: nel.append(etree.Comment(" anyxml "))
python
def anyxml(self, node, elem, module, path): """Create a sample anyxml element.""" nel, newm, path = self.sample_element(node, elem, module, path) if path is None: return if self.annots: nel.append(etree.Comment(" anyxml "))
[ "def", "anyxml", "(", "self", ",", "node", ",", "elem", ",", "module", ",", "path", ")", ":", "nel", ",", "newm", ",", "path", "=", "self", ".", "sample_element", "(", "node", ",", "elem", ",", "module", ",", "path", ")", "if", "path", "is", "Non...
Create a sample anyxml element.
[ "Create", "a", "sample", "anyxml", "element", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/plugins/sample-xml-skeleton.py#L168-L174
train
mbj4668/pyang
pyang/plugins/sample-xml-skeleton.py
SampleXMLSkeletonPlugin.list
def list(self, node, elem, module, path): """Create sample entries of a list.""" nel, newm, path = self.sample_element(node, elem, module, path) if path is None: return for kn in node.i_key: self.node_handler.get(kn.keyword, self.ignore)( kn, nel, ...
python
def list(self, node, elem, module, path): """Create sample entries of a list.""" nel, newm, path = self.sample_element(node, elem, module, path) if path is None: return for kn in node.i_key: self.node_handler.get(kn.keyword, self.ignore)( kn, nel, ...
[ "def", "list", "(", "self", ",", "node", ",", "elem", ",", "module", ",", "path", ")", ":", "nel", ",", "newm", ",", "path", "=", "self", ".", "sample_element", "(", "node", ",", "elem", ",", "module", ",", "path", ")", "if", "path", "is", "None"...
Create sample entries of a list.
[ "Create", "sample", "entries", "of", "a", "list", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/plugins/sample-xml-skeleton.py#L176-L188
train
mbj4668/pyang
pyang/plugins/sample-xml-skeleton.py
SampleXMLSkeletonPlugin.leaf_list
def leaf_list(self, node, elem, module, path): """Create sample entries of a leaf-list.""" nel, newm, path = self.sample_element(node, elem, module, path) if path is None: return minel = node.search_one("min-elements") self.add_copies(node, elem, nel, minel) s...
python
def leaf_list(self, node, elem, module, path): """Create sample entries of a leaf-list.""" nel, newm, path = self.sample_element(node, elem, module, path) if path is None: return minel = node.search_one("min-elements") self.add_copies(node, elem, nel, minel) s...
[ "def", "leaf_list", "(", "self", ",", "node", ",", "elem", ",", "module", ",", "path", ")", ":", "nel", ",", "newm", ",", "path", "=", "self", ".", "sample_element", "(", "node", ",", "elem", ",", "module", ",", "path", ")", "if", "path", "is", "...
Create sample entries of a leaf-list.
[ "Create", "sample", "entries", "of", "a", "leaf", "-", "list", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/plugins/sample-xml-skeleton.py#L190-L197
train
mbj4668/pyang
pyang/plugins/sample-xml-skeleton.py
SampleXMLSkeletonPlugin.sample_element
def sample_element(self, node, parent, module, path): """Create element under `parent`. Declare new namespace if necessary. """ if path is None: return parent, module, None elif path == []: # GO ON pass else: if node.arg ==...
python
def sample_element(self, node, parent, module, path): """Create element under `parent`. Declare new namespace if necessary. """ if path is None: return parent, module, None elif path == []: # GO ON pass else: if node.arg ==...
[ "def", "sample_element", "(", "self", ",", "node", ",", "parent", ",", "module", ",", "path", ")", ":", "if", "path", "is", "None", ":", "return", "parent", ",", "module", ",", "None", "elif", "path", "==", "[", "]", ":", "pass", "else", ":", "if",...
Create element under `parent`. Declare new namespace if necessary.
[ "Create", "element", "under", "parent", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/plugins/sample-xml-skeleton.py#L199-L220
train
mbj4668/pyang
pyang/plugins/sample-xml-skeleton.py
SampleXMLSkeletonPlugin.add_copies
def add_copies(self, node, parent, elem, minel): """Add appropriate number of `elem` copies to `parent`.""" rep = 0 if minel is None else int(minel.arg) - 1 for i in range(rep): parent.append(copy.deepcopy(elem))
python
def add_copies(self, node, parent, elem, minel): """Add appropriate number of `elem` copies to `parent`.""" rep = 0 if minel is None else int(minel.arg) - 1 for i in range(rep): parent.append(copy.deepcopy(elem))
[ "def", "add_copies", "(", "self", ",", "node", ",", "parent", ",", "elem", ",", "minel", ")", ":", "rep", "=", "0", "if", "minel", "is", "None", "else", "int", "(", "minel", ".", "arg", ")", "-", "1", "for", "i", "in", "range", "(", "rep", ")",...
Add appropriate number of `elem` copies to `parent`.
[ "Add", "appropriate", "number", "of", "elem", "copies", "to", "parent", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/plugins/sample-xml-skeleton.py#L222-L226
train
mbj4668/pyang
pyang/plugins/sample-xml-skeleton.py
SampleXMLSkeletonPlugin.list_comment
def list_comment(self, node, elem, minel): """Add list annotation to `elem`.""" lo = "0" if minel is None else minel.arg maxel = node.search_one("max-elements") hi = "" if maxel is None else maxel.arg elem.insert(0, etree.Comment( " # entries: %s..%s " % (lo, hi))) ...
python
def list_comment(self, node, elem, minel): """Add list annotation to `elem`.""" lo = "0" if minel is None else minel.arg maxel = node.search_one("max-elements") hi = "" if maxel is None else maxel.arg elem.insert(0, etree.Comment( " # entries: %s..%s " % (lo, hi))) ...
[ "def", "list_comment", "(", "self", ",", "node", ",", "elem", ",", "minel", ")", ":", "lo", "=", "\"0\"", "if", "minel", "is", "None", "else", "minel", ".", "arg", "maxel", "=", "node", ".", "search_one", "(", "\"max-elements\"", ")", "hi", "=", "\"\...
Add list annotation to `elem`.
[ "Add", "list", "annotation", "to", "elem", "." ]
f2a5cc3142162e5b9ee4e18d154568d939ff63dd
https://github.com/mbj4668/pyang/blob/f2a5cc3142162e5b9ee4e18d154568d939ff63dd/pyang/plugins/sample-xml-skeleton.py#L228-L237
train
quantmind/pulsar
pulsar/utils/slugify.py
slugify
def slugify(value, separator='-', max_length=0, word_boundary=False, entities=True, decimal=True, hexadecimal=True): '''Normalizes string, removes non-alpha characters, and converts spaces to ``separator`` character ''' value = normalize('NFKD', to_string(value, 'utf-8', 'ignore')) if un...
python
def slugify(value, separator='-', max_length=0, word_boundary=False, entities=True, decimal=True, hexadecimal=True): '''Normalizes string, removes non-alpha characters, and converts spaces to ``separator`` character ''' value = normalize('NFKD', to_string(value, 'utf-8', 'ignore')) if un...
[ "def", "slugify", "(", "value", ",", "separator", "=", "'-'", ",", "max_length", "=", "0", ",", "word_boundary", "=", "False", ",", "entities", "=", "True", ",", "decimal", "=", "True", ",", "hexadecimal", "=", "True", ")", ":", "value", "=", "normaliz...
Normalizes string, removes non-alpha characters, and converts spaces to ``separator`` character
[ "Normalizes", "string", "removes", "non", "-", "alpha", "characters", "and", "converts", "spaces", "to", "separator", "character" ]
fee44e871954aa6ca36d00bb5a3739abfdb89b26
https://github.com/quantmind/pulsar/blob/fee44e871954aa6ca36d00bb5a3739abfdb89b26/pulsar/utils/slugify.py#L32-L75
train
quantmind/pulsar
pulsar/utils/slugify.py
smart_truncate
def smart_truncate(value, max_length=0, word_boundaries=False, separator=' '): """ Truncate a string """ value = value.strip(separator) if not max_length: return value if len(value) < max_length: return value if not word_boundaries: return value[:max_length].strip(separat...
python
def smart_truncate(value, max_length=0, word_boundaries=False, separator=' '): """ Truncate a string """ value = value.strip(separator) if not max_length: return value if len(value) < max_length: return value if not word_boundaries: return value[:max_length].strip(separat...
[ "def", "smart_truncate", "(", "value", ",", "max_length", "=", "0", ",", "word_boundaries", "=", "False", ",", "separator", "=", "' '", ")", ":", "value", "=", "value", ".", "strip", "(", "separator", ")", "if", "not", "max_length", ":", "return", "value...
Truncate a string
[ "Truncate", "a", "string" ]
fee44e871954aa6ca36d00bb5a3739abfdb89b26
https://github.com/quantmind/pulsar/blob/fee44e871954aa6ca36d00bb5a3739abfdb89b26/pulsar/utils/slugify.py#L78-L103
train
quantmind/pulsar
pulsar/utils/pylib/redisparser.py
RedisParser.get
def get(self): '''Called by the protocol consumer''' if self._current: return self._resume(self._current, False) else: return self._get(None)
python
def get(self): '''Called by the protocol consumer''' if self._current: return self._resume(self._current, False) else: return self._get(None)
[ "def", "get", "(", "self", ")", ":", "if", "self", ".", "_current", ":", "return", "self", ".", "_resume", "(", "self", ".", "_current", ",", "False", ")", "else", ":", "return", "self", ".", "_get", "(", "None", ")" ]
Called by the protocol consumer
[ "Called", "by", "the", "protocol", "consumer" ]
fee44e871954aa6ca36d00bb5a3739abfdb89b26
https://github.com/quantmind/pulsar/blob/fee44e871954aa6ca36d00bb5a3739abfdb89b26/pulsar/utils/pylib/redisparser.py#L86-L91
train
quantmind/pulsar
pulsar/utils/pylib/redisparser.py
RedisParser.pack_pipeline
def pack_pipeline(self, commands): '''Packs pipeline commands into bytes.''' return b''.join( starmap(lambda *args: b''.join(self._pack_command(args)), (a for a, _ in commands)))
python
def pack_pipeline(self, commands): '''Packs pipeline commands into bytes.''' return b''.join( starmap(lambda *args: b''.join(self._pack_command(args)), (a for a, _ in commands)))
[ "def", "pack_pipeline", "(", "self", ",", "commands", ")", ":", "return", "b''", ".", "join", "(", "starmap", "(", "lambda", "*", "args", ":", "b''", ".", "join", "(", "self", ".", "_pack_command", "(", "args", ")", ")", ",", "(", "a", "for", "a", ...
Packs pipeline commands into bytes.
[ "Packs", "pipeline", "commands", "into", "bytes", "." ]
fee44e871954aa6ca36d00bb5a3739abfdb89b26
https://github.com/quantmind/pulsar/blob/fee44e871954aa6ca36d00bb5a3739abfdb89b26/pulsar/utils/pylib/redisparser.py#L114-L118
train
quantmind/pulsar
pulsar/cmds/pypi_version.py
PyPi.pypi_release
def pypi_release(self): """Get the latest pypi release """ meta = self.distribution.metadata pypi = ServerProxy(self.pypi_index_url) releases = pypi.package_releases(meta.name) if releases: return next(iter(sorted(releases, reverse=True)))
python
def pypi_release(self): """Get the latest pypi release """ meta = self.distribution.metadata pypi = ServerProxy(self.pypi_index_url) releases = pypi.package_releases(meta.name) if releases: return next(iter(sorted(releases, reverse=True)))
[ "def", "pypi_release", "(", "self", ")", ":", "meta", "=", "self", ".", "distribution", ".", "metadata", "pypi", "=", "ServerProxy", "(", "self", ".", "pypi_index_url", ")", "releases", "=", "pypi", ".", "package_releases", "(", "meta", ".", "name", ")", ...
Get the latest pypi release
[ "Get", "the", "latest", "pypi", "release" ]
fee44e871954aa6ca36d00bb5a3739abfdb89b26
https://github.com/quantmind/pulsar/blob/fee44e871954aa6ca36d00bb5a3739abfdb89b26/pulsar/cmds/pypi_version.py#L48-L55
train
quantmind/pulsar
pulsar/async/access.py
is_mainthread
def is_mainthread(thread=None): '''Check if thread is the main thread. If ``thread`` is not supplied check the current thread ''' thread = thread if thread is not None else current_thread() return isinstance(thread, threading._MainThread)
python
def is_mainthread(thread=None): '''Check if thread is the main thread. If ``thread`` is not supplied check the current thread ''' thread = thread if thread is not None else current_thread() return isinstance(thread, threading._MainThread)
[ "def", "is_mainthread", "(", "thread", "=", "None", ")", ":", "thread", "=", "thread", "if", "thread", "is", "not", "None", "else", "current_thread", "(", ")", "return", "isinstance", "(", "thread", ",", "threading", ".", "_MainThread", ")" ]
Check if thread is the main thread. If ``thread`` is not supplied check the current thread
[ "Check", "if", "thread", "is", "the", "main", "thread", "." ]
fee44e871954aa6ca36d00bb5a3739abfdb89b26
https://github.com/quantmind/pulsar/blob/fee44e871954aa6ca36d00bb5a3739abfdb89b26/pulsar/async/access.py#L113-L119
train
quantmind/pulsar
pulsar/async/access.py
process_data
def process_data(name=None): '''Fetch the current process local data dictionary. If ``name`` is not ``None`` it returns the value at``name``, otherwise it return the process data dictionary ''' ct = current_process() if not hasattr(ct, '_pulsar_local'): ct._pulsar_local = {} loc = c...
python
def process_data(name=None): '''Fetch the current process local data dictionary. If ``name`` is not ``None`` it returns the value at``name``, otherwise it return the process data dictionary ''' ct = current_process() if not hasattr(ct, '_pulsar_local'): ct._pulsar_local = {} loc = c...
[ "def", "process_data", "(", "name", "=", "None", ")", ":", "ct", "=", "current_process", "(", ")", "if", "not", "hasattr", "(", "ct", ",", "'_pulsar_local'", ")", ":", "ct", ".", "_pulsar_local", "=", "{", "}", "loc", "=", "ct", ".", "_pulsar_local", ...
Fetch the current process local data dictionary. If ``name`` is not ``None`` it returns the value at``name``, otherwise it return the process data dictionary
[ "Fetch", "the", "current", "process", "local", "data", "dictionary", "." ]
fee44e871954aa6ca36d00bb5a3739abfdb89b26
https://github.com/quantmind/pulsar/blob/fee44e871954aa6ca36d00bb5a3739abfdb89b26/pulsar/async/access.py#L126-L136
train
quantmind/pulsar
pulsar/async/access.py
thread_data
def thread_data(name, value=NOTHING, ct=None): '''Set or retrieve an attribute ``name`` from thread ``ct``. If ``ct`` is not given used the current thread. If ``value`` is None, it will get the value otherwise it will set the value. ''' ct = ct or current_thread() if is_mainthread(ct): ...
python
def thread_data(name, value=NOTHING, ct=None): '''Set or retrieve an attribute ``name`` from thread ``ct``. If ``ct`` is not given used the current thread. If ``value`` is None, it will get the value otherwise it will set the value. ''' ct = ct or current_thread() if is_mainthread(ct): ...
[ "def", "thread_data", "(", "name", ",", "value", "=", "NOTHING", ",", "ct", "=", "None", ")", ":", "ct", "=", "ct", "or", "current_thread", "(", ")", "if", "is_mainthread", "(", "ct", ")", ":", "loc", "=", "process_data", "(", ")", "elif", "not", "...
Set or retrieve an attribute ``name`` from thread ``ct``. If ``ct`` is not given used the current thread. If ``value`` is None, it will get the value otherwise it will set the value.
[ "Set", "or", "retrieve", "an", "attribute", "name", "from", "thread", "ct", "." ]
fee44e871954aa6ca36d00bb5a3739abfdb89b26
https://github.com/quantmind/pulsar/blob/fee44e871954aa6ca36d00bb5a3739abfdb89b26/pulsar/async/access.py#L139-L159
train
quantmind/pulsar
pulsar/utils/internet.py
parse_address
def parse_address(netloc, default_port=8000): '''Parse an internet address ``netloc`` and return a tuple with ``host`` and ``port``.''' if isinstance(netloc, tuple): if len(netloc) != 2: raise ValueError('Invalid address %s' % str(netloc)) return netloc # netloc = native_str(...
python
def parse_address(netloc, default_port=8000): '''Parse an internet address ``netloc`` and return a tuple with ``host`` and ``port``.''' if isinstance(netloc, tuple): if len(netloc) != 2: raise ValueError('Invalid address %s' % str(netloc)) return netloc # netloc = native_str(...
[ "def", "parse_address", "(", "netloc", ",", "default_port", "=", "8000", ")", ":", "if", "isinstance", "(", "netloc", ",", "tuple", ")", ":", "if", "len", "(", "netloc", ")", "!=", "2", ":", "raise", "ValueError", "(", "'Invalid address %s'", "%", "str",...
Parse an internet address ``netloc`` and return a tuple with ``host`` and ``port``.
[ "Parse", "an", "internet", "address", "netloc", "and", "return", "a", "tuple", "with", "host", "and", "port", "." ]
fee44e871954aa6ca36d00bb5a3739abfdb89b26
https://github.com/quantmind/pulsar/blob/fee44e871954aa6ca36d00bb5a3739abfdb89b26/pulsar/utils/internet.py#L17-L51
train
quantmind/pulsar
pulsar/utils/internet.py
is_socket_closed
def is_socket_closed(sock): # pragma nocover """Check if socket ``sock`` is closed.""" if not sock: return True try: if not poll: # pragma nocover if not select: return False try: return bool(select([sock], [], [], 0.0)[0]) ...
python
def is_socket_closed(sock): # pragma nocover """Check if socket ``sock`` is closed.""" if not sock: return True try: if not poll: # pragma nocover if not select: return False try: return bool(select([sock], [], [], 0.0)[0]) ...
[ "def", "is_socket_closed", "(", "sock", ")", ":", "if", "not", "sock", ":", "return", "True", "try", ":", "if", "not", "poll", ":", "if", "not", "select", ":", "return", "False", "try", ":", "return", "bool", "(", "select", "(", "[", "sock", "]", "...
Check if socket ``sock`` is closed.
[ "Check", "if", "socket", "sock", "is", "closed", "." ]
fee44e871954aa6ca36d00bb5a3739abfdb89b26
https://github.com/quantmind/pulsar/blob/fee44e871954aa6ca36d00bb5a3739abfdb89b26/pulsar/utils/internet.py#L101-L121
train
quantmind/pulsar
pulsar/utils/internet.py
close_socket
def close_socket(sock): '''Shutdown and close the socket.''' if sock: try: sock.shutdown(socket.SHUT_RDWR) except Exception: pass try: sock.close() except Exception: pass
python
def close_socket(sock): '''Shutdown and close the socket.''' if sock: try: sock.shutdown(socket.SHUT_RDWR) except Exception: pass try: sock.close() except Exception: pass
[ "def", "close_socket", "(", "sock", ")", ":", "if", "sock", ":", "try", ":", "sock", ".", "shutdown", "(", "socket", ".", "SHUT_RDWR", ")", "except", "Exception", ":", "pass", "try", ":", "sock", ".", "close", "(", ")", "except", "Exception", ":", "p...
Shutdown and close the socket.
[ "Shutdown", "and", "close", "the", "socket", "." ]
fee44e871954aa6ca36d00bb5a3739abfdb89b26
https://github.com/quantmind/pulsar/blob/fee44e871954aa6ca36d00bb5a3739abfdb89b26/pulsar/utils/internet.py#L124-L134
train
quantmind/pulsar
pulsar/apps/rpc/mixins.py
PulsarServerCommands.rpc_server_info
async def rpc_server_info(self, request): '''Return a dictionary of information regarding the server and workers. It invokes the :meth:`extra_server_info` for adding custom information. ''' info = await send('arbiter', 'info') info = self.extra_server_info(request, info)...
python
async def rpc_server_info(self, request): '''Return a dictionary of information regarding the server and workers. It invokes the :meth:`extra_server_info` for adding custom information. ''' info = await send('arbiter', 'info') info = self.extra_server_info(request, info)...
[ "async", "def", "rpc_server_info", "(", "self", ",", "request", ")", ":", "info", "=", "await", "send", "(", "'arbiter'", ",", "'info'", ")", "info", "=", "self", ".", "extra_server_info", "(", "request", ",", "info", ")", "try", ":", "info", "=", "awa...
Return a dictionary of information regarding the server and workers. It invokes the :meth:`extra_server_info` for adding custom information.
[ "Return", "a", "dictionary", "of", "information", "regarding", "the", "server", "and", "workers", "." ]
fee44e871954aa6ca36d00bb5a3739abfdb89b26
https://github.com/quantmind/pulsar/blob/fee44e871954aa6ca36d00bb5a3739abfdb89b26/pulsar/apps/rpc/mixins.py#L18-L30
train
quantmind/pulsar
pulsar/utils/pylib/events.py
Event.bind
def bind(self, callback): """Bind a ``callback`` to this event. """ handlers = self._handlers if self._self is None: raise RuntimeError('%s already fired, cannot add callbacks' % self) if handlers is None: handlers = [] self._handlers = handler...
python
def bind(self, callback): """Bind a ``callback`` to this event. """ handlers = self._handlers if self._self is None: raise RuntimeError('%s already fired, cannot add callbacks' % self) if handlers is None: handlers = [] self._handlers = handler...
[ "def", "bind", "(", "self", ",", "callback", ")", ":", "handlers", "=", "self", ".", "_handlers", "if", "self", ".", "_self", "is", "None", ":", "raise", "RuntimeError", "(", "'%s already fired, cannot add callbacks'", "%", "self", ")", "if", "handlers", "is...
Bind a ``callback`` to this event.
[ "Bind", "a", "callback", "to", "this", "event", "." ]
fee44e871954aa6ca36d00bb5a3739abfdb89b26
https://github.com/quantmind/pulsar/blob/fee44e871954aa6ca36d00bb5a3739abfdb89b26/pulsar/utils/pylib/events.py#L41-L50
train