[Checkins] SVN: cipher.lazydate/trunk/ LazyDate('') is interpreted as None

Andrey Lebedev cvs-admin at zope.org
Tue Dec 11 10:04:05 UTC 2012


Log message for revision 128580:
  LazyDate('') is interpreted as None
  
  

Changed:
  _U  cipher.lazydate/trunk/
  U   cipher.lazydate/trunk/CHANGES.txt
  A   cipher.lazydate/trunk/MANIFEST.in
  U   cipher.lazydate/trunk/setup.py
  _U  cipher.lazydate/trunk/src/
  U   cipher.lazydate/trunk/src/cipher/lazydate/lazydate.py
  U   cipher.lazydate/trunk/src/cipher/lazydate/tests/test_lazydate.py

-=-

Property changes on: cipher.lazydate/trunk
___________________________________________________________________
Added: svn:ignore
   + bin
dist
develop-eggs
parts
.installed.cfg


Modified: cipher.lazydate/trunk/CHANGES.txt
===================================================================
--- cipher.lazydate/trunk/CHANGES.txt	2012-12-10 23:13:47 UTC (rev 128579)
+++ cipher.lazydate/trunk/CHANGES.txt	2012-12-11 10:04:04 UTC (rev 128580)
@@ -2,6 +2,10 @@
 CHANGES
 =======
 
+1.1 (2012-12-11)
+
+- LazyDate('') is interpreted as None
+
 1.0.1 (2012-10-22)
 
 - Fix packaging bugs.

Added: cipher.lazydate/trunk/MANIFEST.in
===================================================================
--- cipher.lazydate/trunk/MANIFEST.in	                        (rev 0)
+++ cipher.lazydate/trunk/MANIFEST.in	2012-12-11 10:04:04 UTC (rev 128580)
@@ -0,0 +1,3 @@
+include *.txt
+include buildout.cfg
+recursive-include src *.py

Modified: cipher.lazydate/trunk/setup.py
===================================================================
--- cipher.lazydate/trunk/setup.py	2012-12-10 23:13:47 UTC (rev 128579)
+++ cipher.lazydate/trunk/setup.py	2012-12-11 10:04:04 UTC (rev 128580)
@@ -23,7 +23,7 @@
 
 setup(
     name='cipher.lazydate',
-    version='1.1dev',
+    version='1.1',
     description='Human-friendly zope.schema datetime field',
     url="http://pypi.python.org/pypi/cipher.lazydate/",
     author='Zope Foundation and Contributors',


Property changes on: cipher.lazydate/trunk/src
___________________________________________________________________
Added: svn:ignore
   + cipher.lazydate.egg-info


Modified: cipher.lazydate/trunk/src/cipher/lazydate/lazydate.py
===================================================================
--- cipher.lazydate/trunk/src/cipher/lazydate/lazydate.py	2012-12-10 23:13:47 UTC (rev 128579)
+++ cipher.lazydate/trunk/src/cipher/lazydate/lazydate.py	2012-12-11 10:04:04 UTC (rev 128580)
@@ -25,11 +25,15 @@
 
     def datetime(self):
         timetuple, result = self._parse()
+        if not timetuple:
+            return None
         dt = datetime.datetime(*timetuple[:6])
         return self._addTimeZone(dt)
 
     def date(self):
         timetuple, result = self._parse()
+        if not timetuple:
+            return None
         dt = datetime.datetime(*timetuple[:3])
         return self._addTimeZone(dt)
 
@@ -44,6 +48,9 @@
     def _parse(self):
         # Try dateutil.parser first, since it does a better job with real
         # dates.
+        if not self.spec:
+            return None, 0
+
         try:
             dt = dateutil.parser.parse(self.spec)
         except ValueError:
@@ -81,6 +88,9 @@
         zope.schema.Object.__init__(self, interfaces.ILazyDate, **kw)
 
     def fromUnicode(self, strvalue):
+        if strvalue == '':
+            return None
+
         value = self.valueFactory(strvalue)
         if not value.validate():
             raise ValueError(strvalue)

Modified: cipher.lazydate/trunk/src/cipher/lazydate/tests/test_lazydate.py
===================================================================
--- cipher.lazydate/trunk/src/cipher/lazydate/tests/test_lazydate.py	2012-12-10 23:13:47 UTC (rev 128579)
+++ cipher.lazydate/trunk/src/cipher/lazydate/tests/test_lazydate.py	2012-12-11 10:04:04 UTC (rev 128580)
@@ -161,6 +161,27 @@
 
     """
 
+def doctest_LazyDateField_empty():
+    """LazyDateField converts empty strings to None
+        >>> field = lazydate.LazyDateField(title=u'Date')
+        >>> print field.fromUnicode('')
+        None
+    """
+
+def doctest_LazyDateF_empty():
+    """LazyDate converts '' to None
+
+        >>> ld = lazydate.LazyDate('')
+        >>> ld.validate()
+        0
+
+        >>> print ld.date()
+        None
+
+        >>> print ld.datetime()
+        None
+
+    """
 def test_suite():
     return doctest.DocTestSuite(
         optionflags=doctest.REPORT_NDIFF|doctest.ELLIPSIS,



More information about the checkins mailing list