_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
75
19.8k
language
stringclasses
1 value
meta_information
dict
q16000
BaseId.script
train
def script(self): """Returns a Script object representing a contract script portion of a payment to the destination.""" # The script object is cached, since constructing it may involve # a number of string-manipulation operations. if getattr(self, '_script', None) is None: ...
python
{ "resource": "" }
q16001
_ChainedHashAlgorithm.copy
train
def copy(self): "Return a clone of this hash object." other = _ChainedHashAlgorithm(self._algorithms) other._hobj = deepcopy(self._hobj) other._fobj = deepcopy(self._fobj) return other
python
{ "resource": "" }
q16002
_ChainedHashAlgorithm._finalize
train
def _finalize(self): "Computes _fobj, the completed hash." hobj = self._hobj for hashname in self._algorithms[1:]: fobj = hashlib.new(hashname) fobj.update(hobj.digest()) hobj = fobj self._fobj = hobj
python
{ "resource": "" }
q16003
_ChainedHashAlgorithm.update
train
def update(self, *args): "Appends any passed in byte arrays to the digest object." for string in args: self._hobj.update(string) self._fobj = None
python
{ "resource": "" }
q16004
BaseAuthTreeLink.count
train
def count(self): "The number of items, pruned or otherwise, contained by this branch." if getattr(self, '_count', None) is None: self._count = getattr(self.node, 'count', 0) return self._count
python
{ "resource": "" }
q16005
BaseAuthTreeLink.size
train
def size(self): "The canonical serialized size of this branch." if getattr(self, '_size', None) is None: self._size = getattr(self.node, 'size', 0) return self._size
python
{ "resource": "" }
q16006
BaseAuthTreeNode._forward_iterator
train
def _forward_iterator(self): "Returns a forward iterator over the trie" path = [(self, 0, Bits())] while path: node, idx, prefix = path.pop() if idx==0 and node.value is not None and not node.prune_value: yield (self._unpickle_key(prefix), self._unpickle_v...
python
{ "resource": "" }
q16007
BaseAuthTreeNode.trim
train
def trim(self, prefixes): "Prunes any keys beginning with the specified the specified prefixes." _prefixes, prefixes = set(map(lambda k:self._prepare_key(k), prefixes)), list() for t in lookahead(sorted(_prefixes)): if t[1] is not None: if t[0] == commonprefix(t): ...
python
{ "resource": "" }
q16008
ScriptPickler.dump
train
def dump(self, script, file=None): "Write a compressed representation of script to the Pickler's file object." if file is None: file = self._file self._dump(script, file, self._protocol, self._version)
python
{ "resource": "" }
q16009
ScriptPickler.dumps
train
def dumps(self, script): "Return a compressed representation of script as a binary string." string = BytesIO() self._dump(script, string, self._protocol, self._version) return string.getvalue()
python
{ "resource": "" }
q16010
ScriptPickler.load
train
def load(self, file=None): "Read and decompress a compact script from the Pickler's file object." if file is None: file = self._file script_class = self.get_script_class() script = self._load(file, self._protocol, self._version) return script_class(script)
python
{ "resource": "" }
q16011
ScriptPickler.loads
train
def loads(self, string): "Decompress the passed-in compact script and return the result." script_class = self.get_script_class() script = self._load(BytesIO(string), self._protocol, self._version) return script_class(script)
python
{ "resource": "" }
q16012
merkle
train
def merkle(hashes, func=_merkle_hash256): """Convert an iterable of hashes or hashable objects into a binary tree, construct the interior values using a passed-in constructor or compression function, and return the root value of the tree. The default compressor is the hash256 function, resulting in root...
python
{ "resource": "" }
q16013
b58encode
train
def b58encode(b, errors='strict'): "Encode bytes to a base58-encoded string." len_ = len(b) # Convert big-endian bytes to integer n = BigInteger.deserialize(BytesIO(b), len_) # Divide that integer into base58 res = [] while n > 0: n, r = divmod (n, 58) res.append(b58digits[...
python
{ "resource": "" }
q16014
b58decode
train
def b58decode(s, errors='strict'): "Decode a base58-encoding string, returning bytes." if not s: return (b'', 0) # Convert the string to an integer n = 0 for c in s: n *= 58 if c not in b58digits: raise InvalidBase58Error(u"character %r is not a valid base58 " ...
python
{ "resource": "" }
q16015
info
train
def info(torrent_path): """Print out information from .torrent file.""" my_torrent = Torrent.from_file(torrent_path) size = my_torrent.total_size click.secho('Name: %s' % my_torrent.name, fg='blue') click.secho('Files:') for file_tuple in my_torrent.files: click.secho(file_tuple.name)...
python
{ "resource": "" }
q16016
create
train
def create(source, dest, tracker, open_trackers, comment, cache): """Create torrent file from a single file or a directory.""" source_title = path.basename(source).replace('.', '_').replace(' ', '_') dest = '%s.torrent' % path.join(dest, source_title) click.secho('Creating torrent from %s ...' % sourc...
python
{ "resource": "" }
q16017
Torrent.files
train
def files(self): """Files in torrent. List of namedtuples (filepath, size). :rtype: list[TorrentFile] """ files = [] info = self._struct.get('info') if not info: return files if 'files' in info: base = info['name'] ...
python
{ "resource": "" }
q16018
Torrent.info_hash
train
def info_hash(self): """Hash of torrent file info section. Also known as torrent hash.""" info = self._struct.get('info') if not info: return None return sha1(Bencode.encode(info)).hexdigest()
python
{ "resource": "" }
q16019
Torrent.to_file
train
def to_file(self, filepath=None): """Writes Torrent object into file, either :param filepath: """ if filepath is None and self._filepath is None: raise TorrentError('Unable to save torrent to file: no filepath supplied.') if filepath is not None: self._f...
python
{ "resource": "" }
q16020
Torrent.create_from
train
def create_from(cls, src_path): """Returns Torrent object created from a file or a directory. :param str src_path: :rtype: Torrent """ is_dir = isdir(src_path) target_files, size_data = cls._get_target_files_info(src_path) SIZE_MIN = 32768 # 32 KiB SIZE...
python
{ "resource": "" }
q16021
Torrent.from_file
train
def from_file(cls, filepath): """Alternative constructor to get Torrent object from file. :param str filepath: :rtype: Torrent """ torrent = cls(Bencode.read_file(filepath)) torrent._filepath = filepath return torrent
python
{ "resource": "" }
q16022
humanize_filesize
train
def humanize_filesize(bytes_size): """Returns human readable filesize. :param int bytes_size: :rtype: str """ if not bytes_size: return '0 B' names = ('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB') name_idx = int(math.floor(math.log(bytes_size, 1024))) size = round(b...
python
{ "resource": "" }
q16023
upload_to_cache_server
train
def upload_to_cache_server(fpath): """Uploads .torrent file to a cache server. Returns upload file URL. :rtype: str """ url_base = 'http://torrage.info' url_upload = '%s/autoupload.php' % url_base url_download = '%s/torrent.php?h=' % url_base file_field = 'torrent' try: im...
python
{ "resource": "" }
q16024
get_open_trackers_from_remote
train
def get_open_trackers_from_remote(): """Returns open trackers announce URLs list from remote repo.""" url_base = 'https://raw.githubusercontent.com/idlesign/torrentool/master/torrentool/repo' url = '%s/%s' % (url_base, OPEN_TRACKERS_FILENAME) try: import requests response = requests.g...
python
{ "resource": "" }
q16025
get_open_trackers_from_local
train
def get_open_trackers_from_local(): """Returns open trackers announce URLs list from local backup.""" with open(path.join(path.dirname(__file__), 'repo', OPEN_TRACKERS_FILENAME)) as f: open_trackers = map(str.strip, f.readlines()) return list(open_trackers)
python
{ "resource": "" }
q16026
Bencode.encode
train
def encode(cls, value): """Encodes a value into bencoded bytes. :param value: Python object to be encoded (str, int, list, dict). :param str val_encoding: Encoding used by strings in a given object. :rtype: bytes """ val_encoding = 'utf-8' def encode_str(v): ...
python
{ "resource": "" }
q16027
Bencode.decode
train
def decode(cls, encoded): """Decodes bencoded data introduced as bytes. Returns decoded structure(s). :param bytes encoded: """ def create_dict(items): # Let's guarantee that dictionaries are sorted. k_v_pair = zip(*[iter(items)] * 2) return ...
python
{ "resource": "" }
q16028
Bencode.read_string
train
def read_string(cls, string): """Decodes a given bencoded string or bytestring. Returns decoded structure(s). :param str string: :rtype: list """ if PY3 and not isinstance(string, byte_types): string = string.encode() return cls.decode(string)
python
{ "resource": "" }
q16029
Bencode.read_file
train
def read_file(cls, filepath): """Decodes bencoded data of a given file. Returns decoded structure(s). :param str filepath: :rtype: list """ with open(filepath, mode='rb') as f: contents = f.read() return cls.decode(contents)
python
{ "resource": "" }
q16030
create_csp_header
train
def create_csp_header(cspDict): """ create csp header string """ policy = ['%s %s' % (k, v) for k, v in cspDict.items() if v != ''] return '; '.join(policy)
python
{ "resource": "" }
q16031
csp_header
train
def csp_header(csp={}): """ Decorator to include csp header on app.route wrapper """ _csp = csp_default().read() _csp.update(csp) _header = '' if 'report-only' in _csp and _csp['report-only'] is True: _header = 'Content-Security-Policy-Report-Only' else: _header = 'Content-Securit...
python
{ "resource": "" }
q16032
csp_default.read
train
def read(self): """ read default csp settings from json file """ with open(self.default_file) as json_file: try: return json.load(json_file) except Exception as e: raise 'empty file'
python
{ "resource": "" }
q16033
csp_default.update
train
def update(self,updates={}): """ update csp_default.json with dict if file empty add default-src and create dict """ try: csp = self.read() except: csp = {'default-src':"'self'"} self.write(csp) csp.update(updates) self.write(csp)
python
{ "resource": "" }
q16034
ImageSetUploadView.get_image_set
train
def get_image_set(self): """ Obtain existing ImageSet if `pk` is specified, otherwise create a new ImageSet for the user. """ image_set_pk = self.kwargs.get("pk", None) if image_set_pk is None: return self.request.user.image_sets.create() return get_ob...
python
{ "resource": "" }
q16035
tracer_config
train
def tracer_config(__init__, app, args, kwargs): """ Wraps the Tornado web application initialization so that the TornadoTracing instance is created around an OpenTracing-compatible tracer. """ __init__(*args, **kwargs) tracing = app.settings.get('opentracing_tracing') tracer_callable = app....
python
{ "resource": "" }
q16036
TornadoTracing._apply_tracing
train
def _apply_tracing(self, handler, attributes): """ Helper function to avoid rewriting for middleware and decorator. Returns a new span from the request with logged attributes and correct operation name from the func. """ operation_name = self._get_operation_name(handler) ...
python
{ "resource": "" }
q16037
execute
train
def execute(func, handler, args, kwargs): """ Wrap the handler ``_execute`` method to trace incoming requests, extracting the context from the headers, if available. """ tracing = handler.settings.get('opentracing_tracing') with tracer_stack_context(): if tracing._trace_all: ...
python
{ "resource": "" }
q16038
on_finish
train
def on_finish(func, handler, args, kwargs): """ Wrap the handler ``on_finish`` method to finish the Span for the given request, if available. """ tracing = handler.settings.get('opentracing_tracing') tracing._finish_tracing(handler) return func(*args, **kwargs)
python
{ "resource": "" }
q16039
log_exception
train
def log_exception(func, handler, args, kwargs): """ Wrap the handler ``log_exception`` method to finish the Span for the given request, if available. This method is called when an Exception is not handled in the user code. """ # safe-guard: expected arguments -> log_exception(self, typ, value, t...
python
{ "resource": "" }
q16040
SchemaNode.schema_root
train
def schema_root(self) -> "SchemaTreeNode": """Return the root node of the receiver's schema.""" sn = self while sn.parent: sn = sn.parent return sn
python
{ "resource": "" }
q16041
SchemaNode.content_type
train
def content_type(self) -> ContentType: """Return receiver's content type.""" return self._ctype if self._ctype else self.parent.content_type()
python
{ "resource": "" }
q16042
SchemaNode.data_parent
train
def data_parent(self) -> Optional["InternalNode"]: """Return the closest ancestor data node.""" parent = self.parent while parent: if isinstance(parent, DataNode): return parent parent = parent.parent
python
{ "resource": "" }
q16043
SchemaNode.iname
train
def iname(self) -> InstanceName: """Return the instance name corresponding to the receiver.""" dp = self.data_parent() return (self.name if dp and self.ns == dp.ns else self.ns + ":" + self.name)
python
{ "resource": "" }
q16044
SchemaNode.data_path
train
def data_path(self) -> DataPath: """Return the receiver's data path.""" dp = self.data_parent() return (dp.data_path() if dp else "") + "/" + self.iname()
python
{ "resource": "" }
q16045
SchemaNode._node_digest
train
def _node_digest(self) -> Dict[str, Any]: """Return dictionary of receiver's properties suitable for clients.""" res = {"kind": self._yang_class()} if self.mandatory: res["mandatory"] = True if self.description: res["description"] = self.description return...
python
{ "resource": "" }
q16046
SchemaNode._iname2qname
train
def _iname2qname(self, iname: InstanceName) -> QualName: """Translate instance name to qualified name in the receiver's context. """ p, s, loc = iname.partition(":") return (loc, p) if s else (p, self.ns)
python
{ "resource": "" }
q16047
SchemaNode._handle_substatements
train
def _handle_substatements(self, stmt: Statement, sctx: SchemaContext) -> None: """Dispatch actions for substatements of `stmt`.""" for s in stmt.substatements: if s.prefix: key = ( sctx.schema_data.modules[sctx.text_mid].prefix_map[s.prefix][0] ...
python
{ "resource": "" }
q16048
SchemaNode._follow_leafref
train
def _follow_leafref( self, xpath: "Expr", init: "TerminalNode") -> Optional["DataNode"]: """Return the data node referred to by a leafref path. Args: xpath: XPath expression compiled from a leafref path. init: initial context node """ if isinstance(xp...
python
{ "resource": "" }
q16049
SchemaNode._nacm_default_deny_stmt
train
def _nacm_default_deny_stmt(self, stmt: Statement, sctx: SchemaContext) -> None: """Set NACM default access.""" if not hasattr(self, 'default_deny'): return if stmt.keyword == "default-deny-all": self.default_deny = DefaultDeny.all elif stmt.keyword == "default-de...
python
{ "resource": "" }
q16050
InternalNode.get_child
train
def get_child(self, name: YangIdentifier, ns: YangIdentifier = None) -> Optional[SchemaNode]: """Return receiver's schema child. Args: name: Child's name. ns: Child's namespace (= `self.ns` if absent). """ ns = ns if ns else self.ns todo...
python
{ "resource": "" }
q16051
InternalNode.get_schema_descendant
train
def get_schema_descendant( self, route: SchemaRoute) -> Optional[SchemaNode]: """Return descendant schema node or ``None`` if not found. Args: route: Schema route to the descendant node (relative to the receiver). """ node = self for p ...
python
{ "resource": "" }
q16052
InternalNode.get_data_child
train
def get_data_child(self, name: YangIdentifier, ns: YangIdentifier = None) -> Optional["DataNode"]: """Return data node directly under the receiver.""" ns = ns if ns else self.ns todo = [] for child in self.children: if child.name == name and child.ns ==...
python
{ "resource": "" }
q16053
InternalNode.filter_children
train
def filter_children(self, ctype: ContentType = None) -> List[SchemaNode]: """Return receiver's children based on content type. Args: ctype: Content type. """ if ctype is None: ctype = self.content_type() return [c for c in self.children if ...
python
{ "resource": "" }
q16054
InternalNode.data_children
train
def data_children(self) -> List["DataNode"]: """Return the set of all data nodes directly under the receiver.""" res = [] for child in self.children: if isinstance(child, DataNode): res.append(child) elif not isinstance(child, SchemaTreeNode): ...
python
{ "resource": "" }
q16055
InternalNode._child_inst_names
train
def _child_inst_names(self) -> Set[InstanceName]: """Return the set of instance names under the receiver.""" return frozenset([c.iname() for c in self.data_children()])
python
{ "resource": "" }
q16056
InternalNode._make_schema_patterns
train
def _make_schema_patterns(self) -> None: """Build schema pattern for the receiver and its data descendants.""" self.schema_pattern = self._schema_pattern() for dc in self.data_children(): if isinstance(dc, InternalNode): dc._make_schema_patterns()
python
{ "resource": "" }
q16057
InternalNode._handle_child
train
def _handle_child( self, node: SchemaNode, stmt: Statement, sctx: SchemaContext) -> None: """Add child node to the receiver and handle substatements.""" if not sctx.schema_data.if_features(stmt, sctx.text_mid): return node.name = stmt.argument node.ns = sctx.defau...
python
{ "resource": "" }
q16058
InternalNode._uses_stmt
train
def _uses_stmt(self, stmt: Statement, sctx: SchemaContext) -> None: """Handle uses statement.""" if not sctx.schema_data.if_features(stmt, sctx.text_mid): return grp, gid = sctx.schema_data.get_definition(stmt, sctx) if stmt.find1("when"): sn = GroupNode() ...
python
{ "resource": "" }
q16059
InternalNode._container_stmt
train
def _container_stmt(self, stmt: Statement, sctx: SchemaContext) -> None: """Handle container statement.""" self._handle_child(ContainerNode(), stmt, sctx)
python
{ "resource": "" }
q16060
InternalNode._identity_stmt
train
def _identity_stmt(self, stmt: Statement, sctx: SchemaContext) -> None: """Handle identity statement.""" if not sctx.schema_data.if_features(stmt, sctx.text_mid): return id = (stmt.argument, sctx.schema_data.namespace(sctx.text_mid)) adj = sctx.schema_data.identity_adjs.setde...
python
{ "resource": "" }
q16061
InternalNode._list_stmt
train
def _list_stmt(self, stmt: Statement, sctx: SchemaContext) -> None: """Handle list statement.""" self._handle_child(ListNode(), stmt, sctx)
python
{ "resource": "" }
q16062
InternalNode._choice_stmt
train
def _choice_stmt(self, stmt: Statement, sctx: SchemaContext) -> None: """Handle choice statement.""" self._handle_child(ChoiceNode(), stmt, sctx)
python
{ "resource": "" }
q16063
InternalNode._case_stmt
train
def _case_stmt(self, stmt: Statement, sctx: SchemaContext) -> None: """Handle case statement.""" self._handle_child(CaseNode(), stmt, sctx)
python
{ "resource": "" }
q16064
InternalNode._leaf_stmt
train
def _leaf_stmt(self, stmt: Statement, sctx: SchemaContext) -> None: """Handle leaf statement.""" node = LeafNode() node.type = DataType._resolve_type( stmt.find1("type", required=True), sctx) self._handle_child(node, stmt, sctx)
python
{ "resource": "" }
q16065
InternalNode._leaf_list_stmt
train
def _leaf_list_stmt(self, stmt: Statement, sctx: SchemaContext) -> None: """Handle leaf-list statement.""" node = LeafListNode() node.type = DataType._resolve_type( stmt.find1("type", required=True), sctx) self._handle_child(node, stmt, sctx)
python
{ "resource": "" }
q16066
InternalNode._rpc_action_stmt
train
def _rpc_action_stmt(self, stmt: Statement, sctx: SchemaContext) -> None: """Handle rpc or action statement.""" self._handle_child(RpcActionNode(), stmt, sctx)
python
{ "resource": "" }
q16067
InternalNode._notification_stmt
train
def _notification_stmt(self, stmt: Statement, sctx: SchemaContext) -> None: """Handle notification statement.""" self._handle_child(NotificationNode(), stmt, sctx)
python
{ "resource": "" }
q16068
InternalNode._anydata_stmt
train
def _anydata_stmt(self, stmt: Statement, sctx: SchemaContext) -> None: """Handle anydata statement.""" self._handle_child(AnydataNode(), stmt, sctx)
python
{ "resource": "" }
q16069
InternalNode._ascii_tree
train
def _ascii_tree(self, indent: str, no_types: bool, val_count: bool) -> str: """Return the receiver's subtree as ASCII art.""" def suffix(sn): return f" {{{sn.val_count}}}\n" if val_count else "\n" if not self.children: return "" cs = [] for c in self.child...
python
{ "resource": "" }
q16070
SchemaTreeNode._annotation_stmt
train
def _annotation_stmt(self, stmt: Statement, sctx: SchemaContext) -> None: """Handle annotation statement.""" if not sctx.schema_data.if_features(stmt, sctx.text_mid): return dst = stmt.find1("description") self.annotations[(stmt.argument, sctx.default_ns)] = Annotation( ...
python
{ "resource": "" }
q16071
DataNode.orphan_instance
train
def orphan_instance(self, rval: RawValue) -> "ObjectMember": """Return an isolated instance of the receiver. Args: rval: Raw value to be used for the returned instance. """ val = self.from_raw(rval) return ObjectMember(self.iname(), {}, val, None, self, datetime.now(...
python
{ "resource": "" }
q16072
DataNode.split_instance_route
train
def split_instance_route(self, route: "InstanceRoute") -> Optional[Tuple[ "InstanceRoute", "InstanceRoute"]]: """Split `route` into the part up to receiver and the rest. Args: route: Absolute instance route (the receiver should correspond to an instance node on t...
python
{ "resource": "" }
q16073
ListNode._check_list_props
train
def _check_list_props(self, inst: "InstanceNode") -> None: """Check uniqueness of keys and "unique" properties, if applicable.""" if self.keys: self._check_keys(inst) for u in self.unique: self._check_unique(u, inst)
python
{ "resource": "" }
q16074
ListNode.orphan_entry
train
def orphan_entry(self, rval: RawObject) -> "ArrayEntry": """Return an isolated entry of the receiver. Args: rval: Raw object to be used for the returned entry. """ val = self.entry_from_raw(rval) return ArrayEntry(0, EmptyList(), EmptyList(), val, None, self, ...
python
{ "resource": "" }
q16075
ChoiceNode._active_case
train
def _active_case(self, value: ObjectValue) -> Optional["CaseNode"]: """Return receiver's case that's active in an instance node value.""" for c in self.children: for cc in c.data_children(): if cc.iname() in value: return c
python
{ "resource": "" }
q16076
LeafListNode.default
train
def default(self) -> Optional[ScalarValue]: """Default value of the receiver, if any.""" if self.mandatory: return None if self._default is not None: return self._default return (None if self.type.default is None else ArrayValue([self.type.default]...
python
{ "resource": "" }
q16077
RpcActionNode._input_stmt
train
def _input_stmt(self, stmt: Statement, sctx: SchemaContext) -> None: """Handle RPC or action input statement.""" self.get_child("input")._handle_substatements(stmt, sctx)
python
{ "resource": "" }
q16078
RpcActionNode._output_stmt
train
def _output_stmt(self, stmt: Statement, sctx: SchemaContext) -> None: """Handle RPC or action output statement.""" self.get_child("output")._handle_substatements(stmt, sctx)
python
{ "resource": "" }
q16079
LinkedList.from_list
train
def from_list(cls, vals: List[Value] = [], reverse: bool = False) -> "LinkedList": """Create an instance from a standard list. Args: vals: Python list of instance values. """ res = EmptyList() for v in (vals if reverse else vals[::-1]): res = cls(v, res) ...
python
{ "resource": "" }
q16080
InstanceNode.path
train
def path(self) -> Tuple[InstanceKey]: """Return the list of keys on the path from root to the receiver.""" res = [] inst: InstanceNode = self while inst.parinst: res.insert(0, inst._key) inst = inst.parinst return tuple(res)
python
{ "resource": "" }
q16081
InstanceNode.put_member
train
def put_member(self, name: InstanceName, value: Value, raw: bool = False) -> "InstanceNode": """Return receiver's member with a new value. If the member is permitted by the schema but doesn't exist, it is created. Args: name: Instance name of the member. ...
python
{ "resource": "" }
q16082
InstanceNode.up
train
def up(self) -> "InstanceNode": """Return an instance node corresponding to the receiver's parent. Raises: NonexistentInstance: If there is no parent. """ ts = max(self.timestamp, self.parinst.timestamp) return self.parinst._copy(self._zip(), ts)
python
{ "resource": "" }
q16083
InstanceNode.top
train
def top(self) -> "InstanceNode": """Return an instance node corresponding to the root of the data tree.""" inst = self while inst.parinst: inst = inst.up() return inst
python
{ "resource": "" }
q16084
InstanceNode.goto
train
def goto(self, iroute: "InstanceRoute") -> "InstanceNode": """Move the focus to an instance inside the receiver's value. Args: iroute: Instance route (relative to the receiver). Returns: The instance node corresponding to the target instance. Raises: ...
python
{ "resource": "" }
q16085
InstanceNode.peek
train
def peek(self, iroute: "InstanceRoute") -> Optional[Value]: """Return a value within the receiver's subtree. Args: iroute: Instance route (relative to the receiver). """ val = self.value sn = self.schema_node for sel in iroute: val, sn = sel.peek_...
python
{ "resource": "" }
q16086
InstanceNode.validate
train
def validate(self, scope: ValidationScope = ValidationScope.all, ctype: ContentType = ContentType.config) -> None: """Validate the receiver's value. Args: scope: Scope of the validation (syntax, semantics or all). ctype: Receiver's content type. Raises:...
python
{ "resource": "" }
q16087
InstanceNode.add_defaults
train
def add_defaults(self, ctype: ContentType = None) -> "InstanceNode": """Return the receiver with defaults added recursively to its value. Args: ctype: Content type of the defaults to be added. If it is ``None``, the content type will be the same as receiver's. """ ...
python
{ "resource": "" }
q16088
InstanceNode._node_set
train
def _node_set(self) -> List["InstanceNode"]: """XPath - return the list of all receiver's nodes.""" return list(self) if isinstance(self.value, ArrayValue) else [self]
python
{ "resource": "" }
q16089
InstanceNode._children
train
def _children(self, qname: Union[QualName, bool] = None) -> List["InstanceNode"]: """XPath - return the list of receiver's children.""" sn = self.schema_node if not isinstance(sn, InternalNode): return [] if qname: cn = sn.get_data_child(*qname) ...
python
{ "resource": "" }
q16090
InstanceNode._descendants
train
def _descendants(self, qname: Union[QualName, bool] = None, with_self: bool = False) -> List["InstanceNode"]: """XPath - return the list of receiver's descendants.""" res = ([] if not with_self or (qname and self.qual_name != qname) else [self]) for c in self....
python
{ "resource": "" }
q16091
ObjectMember.qual_name
train
def qual_name(self) -> QualName: """Return the receiver's qualified name.""" p, s, loc = self._key.partition(":") return (loc, p) if s else (p, self.namespace)
python
{ "resource": "" }
q16092
ObjectMember.sibling
train
def sibling(self, name: InstanceName) -> "ObjectMember": """Return an instance node corresponding to a sibling member. Args: name: Instance name of the sibling member. Raises: NonexistentSchemaNode: If member `name` is not permitted by the schema. ...
python
{ "resource": "" }
q16093
ObjectMember.look_up
train
def look_up(self, **keys: Dict[InstanceName, ScalarValue]) -> "ArrayEntry": """Return the entry with matching keys. Args: keys: Keys and values specified as keyword arguments. Raises: InstanceValueError: If the receiver's value is not a YANG list. Nonexisten...
python
{ "resource": "" }
q16094
ObjectMember._zip
train
def _zip(self) -> ObjectValue: """Zip the receiver into an object and return it.""" res = ObjectValue(self.siblings.copy(), self.timestamp) res[self.name] = self.value return res
python
{ "resource": "" }
q16095
ArrayEntry.previous
train
def previous(self) -> "ArrayEntry": """Return an instance node corresponding to the previous entry. Raises: NonexistentInstance: If the receiver is the first entry of the parent array. """ try: newval, nbef = self.before.pop() except Index...
python
{ "resource": "" }
q16096
ArrayEntry.next
train
def next(self) -> "ArrayEntry": """Return an instance node corresponding to the next entry. Raises: NonexistentInstance: If the receiver is the last entry of the parent array. """ try: newval, naft = self.after.pop() except IndexError: raise N...
python
{ "resource": "" }
q16097
ArrayEntry.insert_before
train
def insert_before(self, value: Union[RawValue, Value], raw: bool = False) -> "ArrayEntry": """Insert a new entry before the receiver. Args: value: The value of the new entry. raw: Flag to be set if `value` is raw. Returns: An instance n...
python
{ "resource": "" }
q16098
ArrayEntry._zip
train
def _zip(self) -> ArrayValue: """Zip the receiver into an array and return it.""" res = list(self.before) res.reverse() res.append(self.value) res.extend(list(self.after)) return ArrayValue(res, self.timestamp)
python
{ "resource": "" }
q16099
ArrayEntry._ancestors_or_self
train
def _ancestors_or_self( self, qname: Union[QualName, bool] = None) -> List[InstanceNode]: """XPath - return the list of receiver's ancestors including itself.""" res = [] if qname and self.qual_name != qname else [self] return res + self.up()._ancestors(qname)
python
{ "resource": "" }