Skip to content
Snippets Groups Projects
Commit e6d38ed2 authored by Ladislav Lhotka's avatar Ladislav Lhotka
Browse files

Reimplement method InstanceNode::is_structured.

parent 84520f54
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@
from datetime import datetime
from typing import Any, Callable, List, Tuple
from .constants import YangsonException
from .instvalue import ArrayValue, ObjectValue, StructuredValue, Value
from .instvalue import ArrayValue, ObjectValue, Value
from .typealiases import *
class JSONPointer(tuple):
......@@ -44,10 +44,6 @@ class InstanceNode:
"""Return the receiver's namespace."""
return self.schema_node.ns
def is_structured(self):
"""Return ``True`` if the receiver has a structured value."""
return isinstance(self.value, StructuredValue)
def path(self) -> str:
"""Return JSONPointer of the receiver."""
parents = []
......@@ -250,6 +246,10 @@ class RootNode(InstanceNode):
return RootNode(newval if newval else self.value, self.schema_node,
newts if newts else self._timestamp)
def is_structured(self):
"""Return ``True`` if the receiver has a structured value."""
return True
def ancestors_or_self(
self, qname: Union[QualName, bool] = None) -> List["RootNode"]:
"""Return the list of receiver's XPath ancestors."""
......@@ -282,6 +282,10 @@ class ObjectMember(InstanceNode):
res[self.name] = self.value
return res
def is_structured(self) -> bool:
"""Return ``True`` if the receiver has a structured value."""
return not isinstance(self.schema_node, LeafNode)
def _pointer_fragment(self) -> str:
return self.name
......@@ -353,6 +357,10 @@ class ArrayEntry(InstanceNode):
res += self.after
return res
def is_structured(self) -> bool:
"""Return ``True`` if the receiver has a structured value."""
return not isinstance(self.schema_node, LeafListNode)
def _pointer_fragment(self) -> int:
return len(self.before)
......@@ -652,4 +660,5 @@ class MaxElements(InstanceError):
return "{} more than {} entries".format(
super().__str__(), self.instance.schema_node.max_elements)
from .schema import CaseNode, DataNode, NonexistentSchemaNode, TerminalNode
from .schema import (CaseNode, DataNode, LeafNode, LeafListNode,
NonexistentSchemaNode, TerminalNode)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment