Merge pull request #117 from davisagli/master
Minor edits to extending docs
This commit is contained in:
@@ -33,6 +33,7 @@ serializes a boolean to the string ``true`` or ``false`` or the special
|
|||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
:linenos:
|
:linenos:
|
||||||
|
|
||||||
|
from colander import Invalid
|
||||||
from colander import null
|
from colander import null
|
||||||
|
|
||||||
class Boolean(object):
|
class Boolean(object):
|
||||||
@@ -40,12 +41,12 @@ serializes a boolean to the string ``true`` or ``false`` or the special
|
|||||||
if appstruct is null:
|
if appstruct is null:
|
||||||
return null
|
return null
|
||||||
if not isinstance(appstruct, bool):
|
if not isinstance(appstruct, bool):
|
||||||
raise Invalid(node, '%r is not a boolean')
|
raise Invalid(node, '%r is not a boolean' % appstruct)
|
||||||
return appstruct and 'true' or 'false'
|
return appstruct and 'true' or 'false'
|
||||||
|
|
||||||
def deserialize(self, node, cstruct):
|
def deserialize(self, node, cstruct):
|
||||||
if cstruct is null:
|
if cstruct is null:
|
||||||
return null
|
return null
|
||||||
if not isinstance(cstruct, basestring):
|
if not isinstance(cstruct, basestring):
|
||||||
raise Invalid(node, '%r is not a string' % cstruct)
|
raise Invalid(node, '%r is not a string' % cstruct)
|
||||||
value = cstruct.lower()
|
value = cstruct.lower()
|
||||||
@@ -53,7 +54,7 @@ serializes a boolean to the string ``true`` or ``false`` or the special
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def cstruct_children(self):
|
def cstruct_children(self, node, cstruct):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
Here's how you would use the resulting class as part of a schema:
|
Here's how you would use the resulting class as part of a schema:
|
||||||
|
Reference in New Issue
Block a user