Author: ianb
Date: 2008-09-18 18:02:05 -0600 (Thu, 18 Sep 2008)
New Revision: 3594

Modified:
   FormEncode/trunk/formencode/foreach.py
Log:
Make ForEach.if_missing act even better and more conformant (handle 
ForEach(if_missing=NoDefault), and ForEach.if_missing)

Modified: FormEncode/trunk/formencode/foreach.py
===================================================================
--- FormEncode/trunk/formencode/foreach.py      2008-09-18 23:58:45 UTC (rev 
3593)
+++ FormEncode/trunk/formencode/foreach.py      2008-09-19 00:02:05 UTC (rev 
3594)
@@ -43,7 +43,7 @@
     convert_to_list = True
     if_empty = NoDefault
     repeating = True
-    _if_missing = NoDefault
+    _if_missing = ()
     
     def attempt_convert(self, value, state, validate):
         if self.convert_to_list:
@@ -112,19 +112,22 @@
     def empty_value(self, value):
         return []
 
-    def _if_missing__get(self):
-        if self._if_missing is NoDefault:
-            return []
-        return self._if_missing
+    class _IfMissing(object):
+        def __get__(self, obj, type=None):
+            if obj is None:
+                return []
+            elif obj._if_missing is ForEach._if_missing:
+                return []
+            else:
+                return obj._if_missing
+        def __set__(self, obj, value):
+            obj._if_missing = value
+        def __delete__(self, obj):
+            obj._if_missing = NoDefault
 
-    def _if_missing__set(self, value):
-        self._if_missing = value
+    if_missing = _IfMissing()
+    del _IfMissing
 
-    def _if_missing__del(self):
-        self._if_missing = NoDefault
-
-    if_missing = property(_if_missing__get, _if_missing__set, _if_missing__del)
-
     def _convert_to_list(self, value):
         if isinstance(value, (str, unicode)):
             return [value]


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
FormEncode-CVS mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/formencode-cvs

Reply via email to