Commits

Anonymous committed ddd4004

reverse the meaning of default and null

Comments (0)

Files changed (10)

 - Change default form action to the empty string (rather than ``.``).
   Thanks to Kiran.
 
+- Custom widgets must now check for ``colander.null`` rather than
+  ``None`` as the null sentinel value.
+
+- Dependency on a new (default_overhaul) version of Colander.
+
 0.2 (2010-05-13)
 ----------------
 
     def serialize(self, cstruct, readonly=False):
         """ Serialize the cstruct into HTML.  If ``readonly`` is
         ``True``, render a read-only rendering (no input fields)."""
-        if cstruct is colander.null:
-            cstruct = colander.default
+        if cstruct is colander.default:
+            cstruct = colander.null
         return self.widget.serialize(self, cstruct=cstruct, readonly=readonly)
 
     def deserialize(self, pstruct):

deform/templates/form.pt

                       tmpl field.widget.item_template"
           tal:repeat="f field.children"
           tal:replace="structure 
-                       rndr(tmpl,field=f,cstruct=cstruct.get(f.name, default))"/>
+                       rndr(tmpl,field=f,cstruct=cstruct.get(f.name, null))"/>
       
       <li class="buttons">
         <tal:block repeat="button field.buttons">

deform/templates/mapping.pt

        tal:define="rndr field.renderer;
                    tmpl field.widget.item_template"
        tal:repeat="f field.children"
-       tal:replace="structure rndr(tmpl,field=f,cstruct=cstruct.get(f.name, default))"/>
+       tal:replace="structure rndr(tmpl,field=f,cstruct=cstruct.get(f.name,null))"/>
     <input type="hidden" name="__end__" value="${field.name}:mapping"/>
   </ul>
   <!-- /mapping -->

deform/templates/readonly/form.pt

                   tmpl field.widget.readonly_item_template"
       tal:repeat="f field.children"
       tal:replace="structure 
-                  rndr(tmpl,field=f,cstruct=cstruct.get(f.name, default))"/>
+                  rndr(tmpl,field=f,cstruct=cstruct.get(f.name, null))"/>
   
 </div>

deform/templates/readonly/mapping.pt

                      tmpl field.widget.readonly_item_template"
          tal:repeat="f field.children"
          tal:replace="structure
-                        rndr(tmpl,field=f,cstruct=cstruct.get(f.name, default))"/>
+                        rndr(tmpl,field=f,cstruct=cstruct.get(f.name, null))"/>
   </ul>
   <!-- /mapping -->
 </div>

deform/tests/test_widget.py

         from deform.widget import TextInputWidget
         return TextInputWidget(**kw)
 
-    def test_serialize_default(self):
-        from colander import default
+    def test_serialize_null(self):
+        from colander import null
         widget = self._makeOne()
         renderer = DummyRenderer()
         field = DummyField(None, renderer=renderer)
-        widget.serialize(field, default)
+        widget.serialize(field, null)
         self.assertEqual(renderer.template, widget.template)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], '')
 
-    def test_serialize_not_default(self):
+    def test_serialize_not_null(self):
         widget = self._makeOne()
         renderer = DummyRenderer()
         schema = DummySchema()
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], cstruct)
 
-    def test_serialize_not_default_readonly(self):
+    def test_serialize_not_null_readonly(self):
         widget = self._makeOne()
         renderer = DummyRenderer()
         schema = DummySchema()
         result = widget.deserialize(field, pstruct)
         self.assertEqual(result, ' abc ')
 
-    def test_deserialize_default(self):
+    def test_deserialize_null(self):
+        from colander import null
         from colander import default
         widget = self._makeOne(strip=False)
         field = DummyField()
-        result = widget.deserialize(field, default)
+        result = widget.deserialize(field, null)
         self.assertEqual(result, default)
 
     def test_deserialize_emptystring(self):
         from deform.widget import DateInputWidget
         return DateInputWidget(**kw)
 
-    def test_serialize_default(self):
-        from colander import default
+    def test_serialize_null(self):
+        from colander import null
         widget = self._makeOne()
         renderer = DummyRenderer()
         field = DummyField(None, renderer=renderer)
-        widget.serialize(field, default)
+        widget.serialize(field, null)
         self.assertEqual(renderer.template, widget.template)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], '')
 
-    def test_serialize_not_default(self):
+    def test_serialize_not_null(self):
         widget = self._makeOne()
         renderer = DummyRenderer()
         schema = DummySchema()
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], cstruct)
 
-    def test_serialize_not_default_readonly(self):
+    def test_serialize_not_null_readonly(self):
         widget = self._makeOne()
         renderer = DummyRenderer()
         schema = DummySchema()
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], cstruct)
 
-    def test_deserialize_default(self):
+    def test_deserialize_null(self):
         from colander import default
+        from colander import null
         widget = self._makeOne()
         field = DummyField()
-        result = widget.deserialize(field, default)
+        result = widget.deserialize(field, null)
         self.assertEqual(result, default)
 
     def test_deserialize_emptystring(self):
         from deform.widget import HiddenWidget
         return HiddenWidget(**kw)
     
-    def test_serialize_default(self):
-        from colander import default
+    def test_serialize_null(self):
+        from colander import null
         widget = self._makeOne()
         renderer = DummyRenderer()
         field = DummyField(None, renderer=renderer)
-        widget.serialize(field, default)
+        widget.serialize(field, null)
         self.assertEqual(renderer.template, widget.template)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], '')
 
-    def test_serialize_not_default(self):
+    def test_serialize_not_null(self):
         widget = self._makeOne()
         renderer = DummyRenderer()
         schema = DummySchema()
         result = widget.deserialize(field, pstruct)
         self.assertEqual(result, 'abc')
 
-    def test_deserialize_default(self):
+    def test_deserialize_null(self):
         from colander import default
+        from colander import null
         widget = self._makeOne(strip=False)
         field = DummyField()
-        result = widget.deserialize(field, default)
+        result = widget.deserialize(field, null)
         self.assertEqual(result, default)
 
 class TestPasswordWidget(TestTextInputWidget):
         from deform.widget import CheckboxWidget
         return CheckboxWidget(**kw)
 
-    def test_serialize_default(self):
-        from colander import default
+    def test_serialize_null(self):
+        from colander import null
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
         widget = self._makeOne()
-        widget.serialize(field, default)
+        widget.serialize(field, null)
         self.assertEqual(renderer.template, widget.template)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], 'false')
 
-    def test_serialize_not_default(self):
+    def test_serialize_not_null(self):
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], cstruct)
 
-    def test_serialize_not_default_readonly(self):
+    def test_serialize_not_null_readonly(self):
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], cstruct)
 
-    def test_deserialize_default(self):
-        from colander import default
+    def test_deserialize_null(self):
+        from colander import null
         widget = self._makeOne()
         field = DummyField()
-        result = widget.deserialize(field, default)
+        result = widget.deserialize(field, null)
         self.assertEqual(result, 'false')
 
     def test_deserialize_true_val(self):
         from deform.widget import RadioChoiceWidget
         return RadioChoiceWidget(**kw)
 
-    def test_serialize_default(self):
-        from colander import default
+    def test_serialize_null(self):
+        from colander import null
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
         widget = self._makeOne()
-        widget.serialize(field, default)
+        widget.serialize(field, null)
         self.assertEqual(renderer.template, widget.template)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], '')
 
-    def test_serialize_default_alternate_null_value(self):
-        from colander import default
+    def test_serialize_null_alternate_null_value(self):
+        from colander import null
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
         widget = self._makeOne()
         widget.null_value = 'fred'
-        widget.serialize(field, default)
+        widget.serialize(field, null)
         self.assertEqual(renderer.template, widget.template)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], 'fred')
 
-    def test_serialize_not_default(self):
+    def test_serialize_not_null(self):
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], cstruct)
 
-    def test_serialize_not_default_readonly(self):
+    def test_serialize_not_null_readonly(self):
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], cstruct)
 
-    def test_deserialize_default(self):
+    def test_deserialize_null(self):
         from colander import default
+        from colander import null
         widget = self._makeOne()
         field = DummyField()
-        result = widget.deserialize(field, default)
+        result = widget.deserialize(field, null)
         self.assertEqual(result, default)
 
     def test_deserialize_other(self):
         from deform.widget import SelectWidget
         return SelectWidget(**kw)
 
-    def test_serialize_default(self):
-        from colander import default
+    def test_serialize_null(self):
+        from colander import null
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
         widget = self._makeOne()
-        widget.serialize(field, default)
+        widget.serialize(field, null)
         self.assertEqual(renderer.template, widget.template)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], '')
 
-    def test_serialize_default_alternate_null_value(self):
-        from colander import default
+    def test_serialize_null_alternate_null_value(self):
+        from colander import null
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
         widget = self._makeOne()
         widget.null_value = 'fred'
-        widget.serialize(field, default)
+        widget.serialize(field, null)
         self.assertEqual(renderer.template, widget.template)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], 'fred')
 
-    def test_serialize_not_default(self):
+    def test_serialize_not_null(self):
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], cstruct)
 
-    def test_serialize_not_default_readonly(self):
+    def test_serialize_not_null_readonly(self):
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], cstruct)
 
-    def test_deserialize_default(self):
+    def test_deserialize_null(self):
         from colander import default
+        from colander import null
         widget = self._makeOne()
         field = DummyField()
-        result = widget.deserialize(field, default)
+        result = widget.deserialize(field, null)
         self.assertEqual(result, default)
 
     def test_deserialize_null_value(self):
         from deform.widget import CheckboxChoiceWidget
         return CheckboxChoiceWidget(**kw)
 
-    def test_serialize_default(self):
-        from colander import default
+    def test_serialize_null(self):
+        from colander import null
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
         widget = self._makeOne()
-        widget.serialize(field, default)
+        widget.serialize(field, null)
         self.assertEqual(renderer.template, widget.template)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], ())
 
-    def test_serialize_not_default(self):
+    def test_serialize_not_null(self):
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], cstruct)
 
-    def test_serialize_not_default_readonly(self):
+    def test_serialize_not_null_readonly(self):
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], cstruct)
 
-    def test_deserialize_default(self):
+    def test_deserialize_null(self):
         from colander import default
+        from colander import null
         widget = self._makeOne()
         field = DummyField()
-        result = widget.deserialize(field, default)
+        result = widget.deserialize(field, null)
         self.assertEqual(result, default)
 
     def test_deserialize_single_string(self):
         from deform.widget import CheckedInputWidget
         return CheckedInputWidget(**kw)
 
-    def test_serialize_default(self):
-        from colander import default
+    def test_serialize_null(self):
+        from colander import null
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
-        field.default = None
         widget = self._makeOne()
-        widget.serialize(field, default)
+        widget.serialize(field, null)
         self.assertEqual(renderer.template, widget.template)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], '')
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
-        field.default = None
         widget = self._makeOne()
         widget.serialize(field, True)
         self.assertEqual(renderer.template, widget.template)
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
-        field.default = None
         widget = self._makeOne()
         widget.serialize(field, False)
         self.assertEqual(renderer.template, widget.template)
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
-        field.default = None
         widget = self._makeOne()
         widget.serialize(field, True, readonly=True)
         self.assertEqual(renderer.template, widget.readonly_template)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], True)
 
-    def test_deserialize_default(self):
+    def test_deserialize_null(self):
         from colander import default
+        from colander import null
         widget = self._makeOne()
         field = DummyField()
-        result = widget.deserialize(field, default)
+        result = widget.deserialize(field, null)
         self.assertEqual(result, default)
 
     def test_deserialize_nonmatching(self):
         self.assertEqual(result, 'password')
         self.assertEqual(field.error, None)
 
-
 class TestCheckedPasswordWidget(TestCheckedInputWidget):
     def _makeOne(self, **kw):
         from deform.widget import CheckedPasswordWidget
         from deform.widget import FileUploadWidget
         return FileUploadWidget(tmpstore, **kw)
 
-    def test_serialize_default(self):
-        from colander import default
+    def test_serialize_null(self):
+        from colander import null
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
-        field.default = None
         tmpstore = DummyTmpStore()
         widget = self._makeOne(tmpstore)
-        widget.serialize(field, default)
+        widget.serialize(field, null)
         self.assertEqual(renderer.template, widget.template)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], {})
         self.assertEqual(renderer.template, widget.readonly_template)
         self.assertEqual(tmpstore['uid'], existing)
 
-    def test_deserialize_default(self):
+    def test_deserialize_null(self):
         from colander import default
+        from colander import null
         schema = DummySchema()
         field = DummyField(schema)
         tmpstore = DummyTmpStore()
         widget = self._makeOne(tmpstore)
-        result = widget.deserialize(field, default)
+        result = widget.deserialize(field, null)
         self.assertEqual(result, default)
 
     def test_deserialize_no_file_selected_no_previous_file(self):
         from deform.widget import DatePartsWidget
         return DatePartsWidget(**kw)
 
-    def test_serialize_default(self):
-        from colander import default
+    def test_serialize_null(self):
+        from colander import null
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
         widget = self._makeOne()
-        widget.serialize(field, default)
+        widget.serialize(field, null)
         self.assertEqual(renderer.template, widget.template)
         self.assertEqual(renderer.kw['year'], '')
         self.assertEqual(renderer.kw['month'], '')
         self.assertEqual(renderer.kw['day'], '')
 
-    def test_serialize_not_default(self):
+    def test_serialize_not_null(self):
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
         self.assertEqual(renderer.kw['month'], '12')
         self.assertEqual(renderer.kw['day'], '1')
 
-    def test_serialize_not_default_readonly(self):
+    def test_serialize_not_null_readonly(self):
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
         self.assertEqual(renderer.kw['month'], '12')
         self.assertEqual(renderer.kw['day'], '1')
 
-    def test_deserialize_not_default(self):
+    def test_deserialize_not_null(self):
         schema = DummySchema()
         field = DummyField(schema, None)
         widget = self._makeOne()
                                     {'year':'01', 'month':'2', 'day':'3'})
         self.assertEqual(result, '01-2-3')
 
-    def test_deserialize_default(self):
+    def test_deserialize_null(self):
         from colander import default
+        from colander import null
         schema = DummySchema()
         field = DummyField(schema, None)
         widget = self._makeOne()
-        result = widget.deserialize(field, default)
+        result = widget.deserialize(field, null)
         self.assertEqual(result, default)
 
     def test_deserialize_incomplete(self):
                         field, {'year':'1', 'month':'', 'day':''})
         self.assertEqual(e.msg, 'Incomplete')
 
+
 class TestMappingWidget(unittest.TestCase):
     def _makeOne(self, **kw):
         from deform.widget import MappingWidget
         return MappingWidget(**kw)
 
-    def test_serialize_default(self):
-        from colander import default
+    def test_serialize_null(self):
+        from colander import null
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
         widget = self._makeOne()
-        widget.serialize(field, default)
+        widget.serialize(field, null)
         self.assertEqual(renderer.template, widget.template)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], {})
 
-    def test_serialize_not_default(self):
+    def test_serialize_not_null(self):
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], cstruct)
 
-    def test_serialize_not_default_readonly(self):
+    def test_serialize_not_null_readonly(self):
         renderer = DummyRenderer()
         schema = DummySchema()
         field = DummyField(schema, renderer)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], cstruct)
 
-    def test_deserialize_default(self):
-        from colander import default
+    def test_deserialize_null(self):
+        from colander import null
         widget = self._makeOne()
         field = DummyField()
-        result = widget.deserialize(field, default)
+        result = widget.deserialize(field, null)
         self.assertEqual(result, {})
 
-    def test_deserialize_non_default(self):
+    def test_deserialize_non_null(self):
         widget = self._makeOne()
         field = DummyField()
         inner_field = DummyField()
         self.assertEqual(urllib.unquote(result), 'abc')
         self.assertEqual(protofield.cloned, True)
 
-    def test_serialize_default(self):
-        from colander import default
+    def test_serialize_null(self):
+        from colander import null
         renderer = DummyRenderer('abc')
         schema = DummySchema()
         field = DummyField(schema, renderer)
         inner = DummyField()
         field.children=[inner]
         widget = self._makeOne()
-        result = widget.serialize(field, default)
+        result = widget.serialize(field, null)
         self.assertEqual(result, 'abc')
         self.assertEqual(len(renderer.kw['subfields']), 0)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], [])
         self.assertEqual(renderer.template, widget.template)
 
-    def test_serialize_default_render_initial_item(self):
-        from colander import default
+    def test_serialize_null_render_initial_item(self):
+        from colander import null
         renderer = DummyRenderer('abc')
         schema = DummySchema()
         field = DummyField(schema, renderer)
         field.children=[inner]
         widget = self._makeOne()
         widget.render_initial_item = True
-        result = widget.serialize(field, default)
+        result = widget.serialize(field, null)
         self.assertEqual(result, 'abc')
         self.assertEqual(len(renderer.kw['subfields']), 1)
         self.assertEqual(renderer.kw['field'], field)
-        self.assertEqual(renderer.kw['cstruct'], [default])
+        self.assertEqual(renderer.kw['cstruct'], [null])
         self.assertEqual(renderer.template, widget.template)
 
     def test_serialize_add_subitem_value(self):
-        from colander import default
+        from colander import null
         renderer = DummyRenderer('abc')
         schema = DummySchema()
         field = DummyField(schema, renderer)
         field.children=[inner]
         widget = self._makeOne()
         widget.add_subitem_text_template = 'Yo ${subitem_description}'
-        widget.serialize(field, default)
+        widget.serialize(field, null)
         self.assertEqual(renderer.kw['add_subitem_text'].interpolate(),
                          'Yo description')
 
     def test_serialize_subitem_value(self):
-        from colander import default
+        from colander import null
         renderer = DummyRenderer('abc')
         schema = DummySchema()
         field = DummyField(schema, renderer)
         inner = DummyField()
         field.children=[inner]
         widget = self._makeOne()
-        widget.serialize(field, default)
+        widget.serialize(field, null)
         self.assertEqual(renderer.kw['item_field'], inner)
 
-    def test_serialize_not_default(self):
+    def test_serialize_not_null(self):
         renderer = DummyRenderer('abc')
         schema = DummySchema()
         field = DummyField(schema, renderer)
         self.assertEqual(renderer.kw['cstruct'], ['123'])
         self.assertEqual(renderer.template, widget.template)
 
-    def test_serialize_not_default_readonly(self):
+    def test_serialize_not_null_readonly(self):
         renderer = DummyRenderer('abc')
         schema = DummySchema()
         field = DummyField(schema, renderer)
         self.assertEqual(renderer.kw['cstruct'], ['123'])
         self.assertEqual(renderer.template, widget.template)
 
-    def test_deserialize_default(self):
-        from colander import default
+    def test_deserialize_null(self):
+        from colander import null
         field = DummyField()
         inner_field = DummyField()
         field.children = [inner_field]
         widget = self._makeOne()
-        result = widget.deserialize(field, default)
+        result = widget.deserialize(field, null)
         self.assertEqual(result, [])
         self.assertEqual(field.sequence_fields, [])
 
-    def test_deserialize_not_default(self):
+    def test_deserialize_not_null(self):
         field = DummyField()
         inner_field = DummyField()
         inner_field.widget = DummyWidget()
         from deform.widget import TextAreaCSVWidget
         return TextAreaCSVWidget(**kw)
 
-    def test_serialize_default(self):
-        from colander import default
+    def test_serialize_null(self):
+        from colander import null
         widget = self._makeOne()
         renderer = DummyRenderer()
         field = DummyField(None, renderer=renderer)
-        widget.serialize(field, default)
+        widget.serialize(field, null)
         self.assertEqual(renderer.template, widget.template)
         self.assertEqual(renderer.kw['field'], field)
         self.assertEqual(renderer.kw['cstruct'], '')
         self.assertRaises(colander.Invalid, widget.deserialize, field, pstruct)
         self.assertEqual(field.unparseable, pstruct)
 
-    def test_deserialize_default(self):
+    def test_deserialize_null(self):
+        from colander import null
         from colander import default
         widget = self._makeOne(strip=False)
         schema = DummySchema()
         schema.required = False
         field = DummyField(schema=schema)
-        result = widget.deserialize(field, default)
+        result = widget.deserialize(field, null)
         self.assertEqual(result, default)
 
     def test_deserialize_emptystring(self):
 import StringIO
 import urllib
 
+from colander import default
 from colander import Invalid
-from colander import default
+from colander import null
+
 from deform.i18n import _
 
 class Widget(object):
     mask_placeholder = "_"
 
     def serialize(self, field, cstruct, readonly=False):
-        if cstruct is default:
+        if cstruct is null:
             cstruct = ''
         template = readonly and self.readonly_template or self.template
         return field.renderer(template, field=field, cstruct=cstruct)
 
     def deserialize(self, field, pstruct):
-        if pstruct is default:
+        if pstruct is null:
             return default
         if self.strip:
             pstruct = pstruct.strip()
     size = None
 
     def serialize(self, field, cstruct, readonly=False):
-        if cstruct is default:
+        if cstruct is null:
             cstruct = ''
         template = readonly and self.readonly_template or self.template
         return field.renderer(template, field=field, cstruct=cstruct)
 
     def deserialize(self, field, pstruct):
-        if pstruct in ('', default):
+        if pstruct in ('', null):
             return default
         return pstruct
 
     hidden = True
 
     def serialize(self, field, cstruct, readonly=False):
-        if cstruct is default:
+        if cstruct is null:
             cstruct = ''
         return field.renderer(self.template, field=field, cstruct=cstruct)
 
     def deserialize(self, field, pstruct):
-        if pstruct is default:
+        if pstruct is null:
             return default
         return pstruct
 
     readonly_template = 'readonly/checkbox'
 
     def serialize(self, field, cstruct, readonly=False):
-        if cstruct is default:
+        if cstruct is null:
             cstruct = self.false_val
         template = readonly and self.readonly_template or self.template
         return field.renderer(template, field=field, cstruct=cstruct)
 
     def deserialize(self, field, pstruct):
-        if pstruct is default:
+        if pstruct is null:
             return self.false_val
         return (pstruct == self.true_val) and self.true_val or self.false_val
 
     values = ()
 
     def serialize(self, field, cstruct, readonly=False):
-        if cstruct is default:
+        if cstruct is null:
             cstruct = self.null_value
         template = readonly and self.readonly_template or self.template
         return field.renderer(template, field=field, cstruct=cstruct)
 
     def deserialize(self, field, pstruct):
-        if pstruct in (default, self.null_value):
+        if pstruct in (null, self.null_value):
             return default
         return pstruct
 
 
 
     def serialize(self, field, cstruct, readonly=False):
-        if cstruct is default:
+        if cstruct is null:
             cstruct = ()
         template = readonly and self.readonly_template or self.template
         return field.renderer(template, field=field, cstruct=cstruct)
 
     def deserialize(self, field, pstruct):
-        if pstruct is default:
+        if pstruct is null:
             return default
         if isinstance(pstruct, basestring):
             return (pstruct,)
     mask_placeholder = "_"
 
     def serialize(self, field, cstruct, readonly=False):
-        if cstruct is default:
+        if cstruct is null:
             cstruct = ''
         confirm = getattr(field, 'confirm', '')
         template = readonly and self.readonly_template or self.template
                               )
 
     def deserialize(self, field, pstruct):
-        if pstruct is default:
+        if pstruct is null:
             return default
         value = pstruct.get('value') or ''
         confirm = pstruct.get('confirm') or ''
     category = 'structural'
 
     def serialize(self, field, cstruct, readonly=False):
-        if cstruct is default:
+        if cstruct is null:
             cstruct = {}
         template = readonly and self.readonly_template or self.template
         return field.renderer(template, field=field, cstruct=cstruct,
-                              default=default)
+                              null=null)
 
     def deserialize(self, field, pstruct):
         error = None
         result = {}
 
-        if pstruct is default:
+        if pstruct is null:
             pstruct = {}
 
         for num, subfield in enumerate(field.children):
             name = subfield.name
-            subval = pstruct.get(name, default)
+            subval = pstruct.get(name, null)
             try:
                 result[name] = subfield.deserialize(subval)
             except Invalid, e:
         # automated testing; finding last node)
         item_field = field.children[0].clone()
         proto = field.renderer(self.item_template, field=item_field,
-                               cstruct=default, parent=field)
+                               cstruct=null, parent=field)
         if isinstance(proto, unicode):
             proto = proto.encode('utf-8')
         proto = urllib.quote(proto)
         return proto
 
     def serialize(self, field, cstruct, readonly=False):
-        if cstruct is default:
+        if cstruct is null:
             if self.render_initial_item:
-                cstruct = [default]
+                cstruct = [null]
             else:
                 cstruct = []
 
         result = []
         error = None
 
-        if pstruct is default:
+        if pstruct is null:
             pstruct = []
 
         field.sequence_fields = []
             [random.choice(string.uppercase+string.digits) for i in range(10)])
 
     def serialize(self, field, cstruct, readonly=False):
-        if cstruct is default:
+        if cstruct is null:
             cstruct = {}
         if cstruct:
             uid = cstruct['uid']
         return field.renderer(template, field=field, cstruct=cstruct)
 
     def deserialize(self, field, pstruct):
-        if pstruct is default:
+        if pstruct is null:
             return default
 
         upload = pstruct.get('upload')
     assume_y2k = True
 
     def serialize(self, field, cstruct, readonly=False):
-        if cstruct is default:
+        if cstruct is null:
             year = ''
             month = ''
             day = ''
                               year=year, month=month, day=day)
 
     def deserialize(self, field, pstruct):
-        if pstruct is default:
+        if pstruct is null:
             return default
         else:
             if self.assume_y2k:
     rows = None
 
     def serialize(self, field, cstruct, readonly=False):
-        if cstruct is default:
+        if cstruct is null:
             cstruct = []
         textrows = getattr(field, 'unparseable', None)
         if textrows is None:
         return field.renderer(template, field=field, cstruct=textrows)
         
     def deserialize(self, field, pstruct):
-        if pstruct is default:
+        if pstruct is null:
             return default
         if not pstruct.strip():
             return default

deformdemo/app.py

         return getattr(self.widget, name)
 
     def serialize(self, field, cstruct, readonly=False):
-        if cstruct is colander.default:
+        if cstruct is colander.null:
             cstruct = []
         textrows = getattr(field, 'unparseable', None)
         if textrows is None:
 
     def deserialize(self, field, pstruct):
         text = self.widget.deserialize(field, pstruct)
-        if text is colander.default:
-            return colander.default
+        if text in (colander.null, colander.default):
+            return text
         if not text.strip():
             return colander.default
         try:
    :linenos:
 
     from deform.widget import Widget
+    from colander import null
     import cgi
 
     class MyInputWidget(Widget):
         def serialize(self, field, cstruct=None, readonly=False):
-            if cstruct is None:
-                cstruct = field.default
-            if cstruct is None:
-                cstruct = ''
+            if cstruct is null:
+                cstruct = u''
             quoted = cgi.escape(cstruct, quote='"')
             return u'<input type="text" value="%s">' % quoted
 
 serialization, no matter whether it is provided data by its caller or
 not.  Usually, the value of ``cstruct`` will contain appropriate data
 that can be used directly by the widget's rendering logic.  But
-sometimes it will be ``None``.  It will be ``None`` when a form which
-uses this widget is serialized without any data; for example an "add
-form".
+sometimes it will be ``colander.null``.  It will be ``colander.null``
+when a form which uses this widget is serialized without any data; for
+example an "add form".
 
 All widgets *must* check if the value passed as ``cstruct`` is
-``None`` during ``serialize``.  Widgets are responsible for handling
-this eventuality, often by attempting to use the value of
-``field.default``, which will be the default value of the
-:term:`schema node` related to this widget, if any.  If ``cstruct`` is
-``None`` and ``field.default`` is *also* ``None``, it means the field
-has no default value (it is a "required" field).  In this case, the
-widget is responsible for providing a suitable default value for
-``cstruct`` itself.  
+``colander.null`` during ``serialize``.  Widgets are responsible for
+handling this eventuality, often by serializing a logically "empty"
+value.
 
 Regardless of how the widget attempts to compute the default value, it
-must still be able to return a rendering when ``cstruct`` is ``None``
-and ``field.default`` is ``None``.  In the example case above, if both
-``cstruct`` and ``field.default`` are ``None``, the widget uses the
+must still be able to return a rendering when ``cstruct`` is
+``colander.null``.  In the example case above, the widget uses the
 empty string as the ``cstruct`` value, which is appropriate for this
 type of "scalar" input widget; for a more "structural" kind of widget
 the default might be something else like an empty dictionary or list.
    :linenos:
 
     from deform.widget import Widget
+    from colander import null
+    from colander import default
     import cgi
 
     class MyInputWidget(Widget):
         def serialize(self, field, cstruct=None, readonly=False):
-            if cstruct is None:
-                cstruct = field.default
-            if cstruct is None:
-                cstruct = ''
+            if cstruct is null:
+                cstruct = u''
             return '<input type="text" value="%s">' % cgi.escape(cstruct)
 
         def deserialize(self, field, pstruct=None):
-            ...
+            if cstruct is null:
+                return default
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.