Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Truncated date input no longer raises ParseError
  • Loading branch information
lmctv committed Mar 19, 2013
1 parent cdc9eb8 commit fbae200
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions colander/__init__.py
Expand Up @@ -1407,13 +1407,8 @@ def deserialize(self, node, cstruct):
result = iso8601.parse_date(
cstruct, default_timezone=self.default_tzinfo)
except (iso8601.ParseError, TypeError) as e:
try:
year, month, day = map(int, cstruct.split('-', 2))
result = datetime.datetime(year, month, day,
tzinfo=self.default_tzinfo)
except Exception as e:
raise Invalid(node, _(self.err_template,
mapping={'val':cstruct, 'err':e}))
raise Invalid(node, _(self.err_template,
mapping={'val':cstruct, 'err':e}))
return result

class Date(SchemaType):
Expand Down Expand Up @@ -1479,15 +1474,11 @@ def deserialize(self, node, cstruct):
try:
result = iso8601.parse_date(cstruct)
result = result.date()
except (iso8601.ParseError, TypeError):
try:
year, month, day = map(int, cstruct.split('-', 2))
result = datetime.date(year, month, day)
except Exception as e:
raise Invalid(node,
_(self.err_template,
mapping={'val':cstruct, 'err':e})
)
except (iso8601.ParseError, TypeError) as e:
raise Invalid(node,
_(self.err_template,
mapping={'val':cstruct, 'err':e})
)
return result

class Time(SchemaType):
Expand Down

0 comments on commit fbae200

Please sign in to comment.