Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- Add an ``sdefault`` property to ``colander.SchemaNode`` objects.

  • Loading branch information...
commit a9d94df919fc0c9dabaff1a4c01fba641bd5e62c 1 parent c326bb5
@mcdonc mcdonc authored
Showing with 19 additions and 0 deletions.
  1. +2 −0  CHANGES.txt
  2. +8 −0 colander/__init__.py
  3. +9 −0 colander/tests.py
View
2  CHANGES.txt
@@ -4,6 +4,8 @@ Changes
Next release
------------
+- Add an ``sdefault`` property to ``colander.SchemaNode`` objects.
+
- Add a ``clone`` method to ``colander.SchemaNode`` objects.
- Add a ``__str__`` method to the ``colander.Invalid`` exception that
View
8 colander/__init__.py
@@ -641,6 +641,14 @@ def required(self):
schema """
return self.default is _missing
+ @property
+ def sdefault(self):
+ """ Return the *serialized* default of the node default or
+ ``None`` if there is no default."""
+ if self.default is _missing:
+ return None
+ return self.typ.serialize(self, self.default)
+
def deserialize(self, value):
""" Derialize the value based on the schema represented by this
node """
View
9 colander/tests.py
@@ -940,6 +940,15 @@ def test_required_false(self):
node = self._makeOne(None, default=1)
self.assertEqual(node.required, False)
+ def test_sdefault_missing(self):
+ node = self._makeOne(None)
+ self.assertEqual(node.sdefault, None)
+
+ def test_sdefault_not_missing(self):
+ typ = DummyType()
+ node = self._makeOne(typ, default=1)
+ self.assertEqual(node.sdefault, 1)
+
def test_deserialize_no_validator(self):
typ = DummyType()
node = self._makeOne(typ)
Please sign in to comment.
Something went wrong with that request. Please try again.