Skip to content

Commit f49fe39

Browse files
committed
Only allow RFC 3339 date times, not all of ISO 8601.
Closes #115
1 parent 766c02b commit f49fe39

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

docs/validate.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,22 @@ ipv4
284284
ipv6 OS must have :func:`socket.inet_pton` function
285285
email
286286
uri requires rfc3987_
287-
date-time requires isodate_
287+
date-time requires strict-rfc3339_ [#]_
288288
date
289289
time
290290
regex
291291
color requires webcolors_
292292
========== ====================
293293

294294

295+
.. [#] For backwards compatibility, isodate_ is also supported, but it will
296+
allow any `ISO 8601 <http://en.wikipedia.org/wiki/ISO_8601>`_ date-time,
297+
not just `RFC 3339 <http://www.ietf.org/rfc/rfc3339.txt>`_ as mandated by
298+
the JSON Schema specification.
299+
300+
301+
.. _isodate: http://pypi.python.org/pypi/isodate/
295302
.. _isodate: http://pypi.python.org/pypi/isodate/
296303
.. _rfc3987: http://pypi.python.org/pypi/rfc3987/
304+
.. _strict-rfc3339: http://pypi.python.org/pypi/strict-rfc3339/
297305
.. _webcolors: http://pypi.python.org/pypi/webcolors/

jsonschema/_format.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,17 @@ def is_uri(instance):
154154

155155

156156
try:
157-
import isodate
157+
import strict_rfc3339
158158
except ImportError:
159-
pass
159+
try:
160+
import isodate
161+
except ImportError:
162+
pass
163+
else:
164+
_err = (ValueError, isodate.ISO8601Error)
165+
_checks_drafts("date-time", raises=_err)(isodate.parse_datetime)
160166
else:
161-
_err = (ValueError, isodate.ISO8601Error)
162-
_checks_drafts("date-time", raises=_err)(isodate.parse_datetime)
167+
_checks_drafts("date-time")(strict_rfc3339.validate_rfc3339)
163168

164169

165170
_checks_drafts("regex", raises=re.error)(re.compile)

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ deps =
4949

5050
[testenv:all]
5151
deps =
52-
isodate
5352
lxml
5453
pytest
5554
sphinx
55+
strict-rfc3339
5656
webcolors
5757

5858
[flake8]

0 commit comments

Comments
 (0)