remove dead appstruct_children method
This commit is contained in:
@@ -32,6 +32,10 @@ Features
|
|||||||
- The ``preparer=`` argument to SchemaNodes may now be a sequence of
|
- The ``preparer=`` argument to SchemaNodes may now be a sequence of
|
||||||
preparers.
|
preparers.
|
||||||
|
|
||||||
|
- Added a ``cstruct_children`` method to SchemaNode.
|
||||||
|
|
||||||
|
- A new ``cstruct_children`` API should exist on schema types.
|
||||||
|
|
||||||
Backwards Incompatibilities
|
Backwards Incompatibilities
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|||||||
@@ -407,9 +407,6 @@ class SchemaType(object):
|
|||||||
def get_value(self, node, appstruct, path):
|
def get_value(self, node, appstruct, path):
|
||||||
raise AssertionError("Can't call 'get_value' on a leaf node.")
|
raise AssertionError("Can't call 'get_value' on a leaf node.")
|
||||||
|
|
||||||
def appstruct_children(self, node, appstruct):
|
|
||||||
return []
|
|
||||||
|
|
||||||
def cstruct_children(self, node, cstruct):
|
def cstruct_children(self, node, cstruct):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@@ -483,7 +480,7 @@ class Mapping(SchemaType):
|
|||||||
mapping = {'val':value, 'err':e})
|
mapping = {'val':value, 'err':e})
|
||||||
)
|
)
|
||||||
|
|
||||||
def _struct_children(self, node, struct):
|
def cstruct_children(self, node, struct):
|
||||||
if struct is null:
|
if struct is null:
|
||||||
value = {}
|
value = {}
|
||||||
else:
|
else:
|
||||||
@@ -491,13 +488,12 @@ class Mapping(SchemaType):
|
|||||||
children = []
|
children = []
|
||||||
for num, subnode in enumerate(node.children):
|
for num, subnode in enumerate(node.children):
|
||||||
name = subnode.name
|
name = subnode.name
|
||||||
subval = value.get(name, null)
|
subval = value.get(name, _marker)
|
||||||
|
if subval is _marker:
|
||||||
|
subval = subnode.serialize(null)
|
||||||
children.append(subval)
|
children.append(subval)
|
||||||
return children
|
return children
|
||||||
|
|
||||||
cstruct_children = _struct_children
|
|
||||||
appstruct_children = _struct_children
|
|
||||||
|
|
||||||
def _impl(self, node, value, callback):
|
def _impl(self, node, value, callback):
|
||||||
value = self._validate(node, value)
|
value = self._validate(node, value)
|
||||||
|
|
||||||
@@ -629,22 +625,21 @@ class Tuple(Positional, SchemaType):
|
|||||||
|
|
||||||
return list(value)
|
return list(value)
|
||||||
|
|
||||||
def _struct_children(self, node, struct):
|
def cstruct_children(self, node, cstruct):
|
||||||
childlen = len(node.children)
|
childlen = len(node.children)
|
||||||
if struct is null:
|
if cstruct is null:
|
||||||
struct = []
|
cstruct = []
|
||||||
structlen = len(struct)
|
structlen = len(cstruct)
|
||||||
if structlen < childlen:
|
if structlen < childlen:
|
||||||
struct = list(struct)
|
missing_children = self.children[childlen-structlen:]
|
||||||
struct.extend([null] * (childlen - structlen))
|
cstruct = list(cstruct)
|
||||||
|
for child in missing_children:
|
||||||
|
cstruct.append(child.serialize(null))
|
||||||
elif structlen > childlen:
|
elif structlen > childlen:
|
||||||
struct = struct[:childlen]
|
cstruct = cstruct[:childlen]
|
||||||
else:
|
else:
|
||||||
struct = list(struct)
|
cstruct = list(cstruct)
|
||||||
return struct
|
return cstruct
|
||||||
|
|
||||||
cstruct_children = _struct_children
|
|
||||||
appstruct_children = _struct_children
|
|
||||||
|
|
||||||
def _impl(self, node, value, callback):
|
def _impl(self, node, value, callback):
|
||||||
value = self._validate(node, value)
|
value = self._validate(node, value)
|
||||||
@@ -739,11 +734,10 @@ class Tuple(Positional, SchemaType):
|
|||||||
|
|
||||||
class SequenceItems(list):
|
class SequenceItems(list):
|
||||||
"""
|
"""
|
||||||
List marker subclass for use by Sequence.appstruct_children and
|
List marker subclass for use by Sequence.cstruct_children, which indicates
|
||||||
Sequence.cstruct_children, which indicates to a caller of that method
|
to a caller of that method that the result is from a sequence type.
|
||||||
that the result is from a sequence type. Usually these values need to be
|
Usually these values need to be treated specially, because all of the
|
||||||
treated specially, because all of the children of a Sequence are not
|
children of a Sequence are not present in a schema.
|
||||||
present in a schema.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Sequence(Positional, SchemaType):
|
class Sequence(Positional, SchemaType):
|
||||||
@@ -787,13 +781,10 @@ class Sequence(Positional, SchemaType):
|
|||||||
mapping={'val':value})
|
mapping={'val':value})
|
||||||
)
|
)
|
||||||
|
|
||||||
def _struct_children(self, node, struct):
|
def cstruct_children(self, node, cstruct):
|
||||||
if struct is null:
|
if cstruct is null:
|
||||||
return SequenceItems([])
|
return SequenceItems([])
|
||||||
return SequenceItems(struct)
|
return SequenceItems(cstruct)
|
||||||
|
|
||||||
cstruct_children = _struct_children
|
|
||||||
appstruct_children = _struct_children
|
|
||||||
|
|
||||||
def _impl(self, node, value, callback, accept_scalar):
|
def _impl(self, node, value, callback, accept_scalar):
|
||||||
if accept_scalar is None:
|
if accept_scalar is None:
|
||||||
@@ -1807,13 +1798,6 @@ class SchemaNode(object):
|
|||||||
return []
|
return []
|
||||||
return cstruct_children(self, cstruct)
|
return cstruct_children(self, cstruct)
|
||||||
|
|
||||||
def appstruct_children(self, appstruct):
|
|
||||||
appstruct_children = getattr(self.typ, 'appstruct_children', None)
|
|
||||||
if appstruct_children is None:
|
|
||||||
# bw compat for types created before this method was required
|
|
||||||
return []
|
|
||||||
return appstruct_children(self, appstruct)
|
|
||||||
|
|
||||||
def __delitem__(self, name):
|
def __delitem__(self, name):
|
||||||
""" Remove a subnode by name """
|
""" Remove a subnode by name """
|
||||||
for idx, node in enumerate(self.children[:]):
|
for idx, node in enumerate(self.children[:]):
|
||||||
|
|||||||
Reference in New Issue
Block a user