Skip to content

Commit

Permalink
remove dead appstruct_children method
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdonc committed Sep 23, 2012
1 parent 4731931 commit 8845571
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 38 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Expand Up @@ -32,6 +32,10 @@ Features
- The ``preparer=`` argument to SchemaNodes may now be a sequence of
preparers.

- Added a ``cstruct_children`` method to SchemaNode.

- A new ``cstruct_children`` API should exist on schema types.

Backwards Incompatibilities
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
60 changes: 22 additions & 38 deletions colander/__init__.py
Expand Up @@ -407,9 +407,6 @@ def set_value(self, node, appstruct, path, value):
def get_value(self, node, appstruct, path):
raise AssertionError("Can't call 'get_value' on a leaf node.")

def appstruct_children(self, node, appstruct):
return []

def cstruct_children(self, node, cstruct):
return []

Expand Down Expand Up @@ -483,21 +480,20 @@ def _validate(self, node, value):
mapping = {'val':value, 'err':e})
)

def _struct_children(self, node, struct):
def cstruct_children(self, node, struct):
if struct is null:
value = {}
else:
value = self._validate(node, struct)
children = []
for num, subnode in enumerate(node.children):
name = subnode.name
subval = value.get(name, null)
subval = value.get(name, _marker)
if subval is _marker:
subval = subnode.serialize(null)
children.append(subval)
return children

cstruct_children = _struct_children
appstruct_children = _struct_children

def _impl(self, node, value, callback):
value = self._validate(node, value)

Expand Down Expand Up @@ -629,22 +625,21 @@ def _validate(self, node, value):

return list(value)

def _struct_children(self, node, struct):
def cstruct_children(self, node, cstruct):
childlen = len(node.children)
if struct is null:
struct = []
structlen = len(struct)
if cstruct is null:
cstruct = []
structlen = len(cstruct)
if structlen < childlen:
struct = list(struct)
struct.extend([null] * (childlen - structlen))
missing_children = self.children[childlen-structlen:]
cstruct = list(cstruct)
for child in missing_children:
cstruct.append(child.serialize(null))
elif structlen > childlen:
struct = struct[:childlen]
cstruct = cstruct[:childlen]
else:
struct = list(struct)
return struct

cstruct_children = _struct_children
appstruct_children = _struct_children
cstruct = list(cstruct)
return cstruct

def _impl(self, node, value, callback):
value = self._validate(node, value)
Expand Down Expand Up @@ -739,11 +734,10 @@ def get_value(self, node, appstruct, path):

class SequenceItems(list):
"""
List marker subclass for use by Sequence.appstruct_children and
Sequence.cstruct_children, which indicates to a caller of that method
that the result is from a sequence type. Usually these values need to be
treated specially, because all of the children of a Sequence are not
present in a schema.
List marker subclass for use by Sequence.cstruct_children, which indicates
to a caller of that method that the result is from a sequence type.
Usually these values need to be treated specially, because all of the
children of a Sequence are not present in a schema.
"""

class Sequence(Positional, SchemaType):
Expand Down Expand Up @@ -787,13 +781,10 @@ def _validate(self, node, value, accept_scalar):
mapping={'val':value})
)

def _struct_children(self, node, struct):
if struct is null:
def cstruct_children(self, node, cstruct):
if cstruct is null:
return SequenceItems([])
return SequenceItems(struct)

cstruct_children = _struct_children
appstruct_children = _struct_children
return SequenceItems(cstruct)

def _impl(self, node, value, callback, accept_scalar):
if accept_scalar is None:
Expand Down Expand Up @@ -1807,13 +1798,6 @@ def cstruct_children(self, cstruct):
return []
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):
""" Remove a subnode by name """
for idx, node in enumerate(self.children[:]):
Expand Down

0 comments on commit 8845571

Please sign in to comment.