[Checkins]
SVN: z3c.schema2xml/branches/jw-experiment/src/z3c/schema2xml/
Check deserialized value against the Choice's vocabulary.
Jan-Wijbrand Kolman
janwijbrand at gmail.com
Wed Mar 19 12:18:03 EDT 2008
Log message for revision 84785:
Check deserialized value against the Choice's vocabulary.
Changed:
U z3c.schema2xml/branches/jw-experiment/src/z3c/schema2xml/README.txt
U z3c.schema2xml/branches/jw-experiment/src/z3c/schema2xml/_schema2xml.py
-=-
Modified: z3c.schema2xml/branches/jw-experiment/src/z3c/schema2xml/README.txt
===================================================================
--- z3c.schema2xml/branches/jw-experiment/src/z3c/schema2xml/README.txt 2008-03-19 16:03:37 UTC (rev 84784)
+++ z3c.schema2xml/branches/jw-experiment/src/z3c/schema2xml/README.txt 2008-03-19 16:18:03 UTC (rev 84785)
@@ -447,7 +447,7 @@
Choice
------
-Choice fields. For now, we only work with Choice fields that have
+Choice fields. For now, we only work with Choice fields that have
text values::
@@ -482,6 +482,19 @@
>>> new_choice.choice is None
True
+Only values that are actually available in the Choice's source are allowed. Other
+values will result in an error::
+
+ >>> xml = '''
+ ... <container>
+ ... <choice>gamma</choice>
+ ... </container>
+ ... '''
+ >>> deserialize(xml, IWithChoice, new_choice)
+ Traceback (most recent call last):
+ ...
+ ConstraintNotSatisfied: gamma
+
Set
---
@@ -516,3 +529,20 @@
>>> deserialize(xml, IWithSet, new_set)
>>> new_set.set
set(['alpha', 'beta'])
+
+Only values that are actually available in the value_type's source are allowed.
+Other values will result in an error::
+
+ >>> xml = '''
+ ... <container>
+ ... <set>
+ ... <choice>alpha</choice>
+ ... <choice>beta</choice>
+ ... <choice>gamma</choice>
+ ... </set>
+ ... </container>
+ ... '''
+ >>> deserialize(xml, IWithSet, new_set)
+ Traceback (most recent call last):
+ ...
+ ConstraintNotSatisfied: gamma
Modified: z3c.schema2xml/branches/jw-experiment/src/z3c/schema2xml/_schema2xml.py
===================================================================
--- z3c.schema2xml/branches/jw-experiment/src/z3c/schema2xml/_schema2xml.py 2008-03-19 16:03:37 UTC (rev 84784)
+++ z3c.schema2xml/branches/jw-experiment/src/z3c/schema2xml/_schema2xml.py 2008-03-19 16:18:03 UTC (rev 84785)
@@ -125,14 +125,16 @@
class Choice(grok.Adapter):
grok.context(IChoice)
grok.implements(IXMLGenerator)
-
+
def output(self, container, value):
element = etree.SubElement(container, self.context.__name__)
element.text = value
def input(self, element):
- if element.text is not None:
- return element.text
+ value = element.text
+ if value is not None:
+ self.context.validate(value) # raises an error if not valid.
+ return value
return None
class Set(grok.Adapter):
More information about the Checkins
mailing list