- Fix bug introduced by supporting spec-mandated truncations of ISO-8601

timezones.  A TypeError would be raised instead of Invalid.  See
  https://github.com/Pylons/colander/issues/111.

Ref issue #111.
This commit is contained in:
Chris McDonough
2013-05-31 11:53:18 -04:00
parent 8fc2685bdf
commit 7ec32b607f
4 changed files with 21 additions and 0 deletions

View File

@@ -1,3 +1,10 @@
Next release
------------
- Fix bug introduced by supporting spec-mandated truncations of ISO-8601
timezones. A TypeError would be raised instead of Invalid. See
https://github.com/Pylons/colander/issues/111.
1.0a4 (2013-05-21)
------------------

View File

@@ -129,6 +129,10 @@ def parse_date(datestring, default_timezone=UTC):
raise ParseError("Unable to parse date string %r" % datestring)
groups = m.groupdict()
tz = parse_timezone(groups["timezone"], default_timezone=default_timezone)
if (groups['year'] is None or
groups['month'] is None or
groups['day'] is None):
raise ParseError('Unable to parse date string %r' % datestring)
if groups["hour"] is None:
groups["hour"] = 0
if groups["minute"] is None:

View File

@@ -1954,6 +1954,12 @@ class TestDateTime(unittest.TestCase):
e = invalid_exc(typ.deserialize, node, 'garbage')
self.assertTrue('Invalid' in e.msg)
def test_deserialize_slashes_invalid(self):
node = DummySchemaNode(None)
typ = self._makeOne()
e = invalid_exc(typ.deserialize, node, '2013/05/31')
self.assertTrue('Invalid' in e.msg)
def test_deserialize_null(self):
import colander
node = DummySchemaNode(None)

View File

@@ -168,3 +168,7 @@ class Test_parse_date(unittest.TestCase):
datetime.datetime(2007, 1, 25, 0, 0, 0, 0,
tzinfo=UTC))
def test_slash_separated_raises_ParseError(self):
from ..iso8601 import ParseError
self.assertRaises(ParseError, self._callFUT, "2007/01/25")