Skip to content

Commit cd08b02

Browse files
committed
Add to docs and relax restrictions
1 parent 66d77d4 commit cd08b02

File tree

2 files changed

+44
-21
lines changed

2 files changed

+44
-21
lines changed

docs/validate.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,29 @@ to validate. Their names can be viewed by inspecting the
219219
...'uri']
220220

221221

222+
The actual functions that do the validation are also exposed, in case there is
223+
any use for them. They are listed below, along with any limitations they come
224+
with.
225+
226+
222227
.. autofunction:: is_date_time
228+
229+
.. autofunction:: is_date
230+
231+
.. autofunction:: is_time
232+
233+
.. autofunction:: is_regex
234+
235+
.. autofunction:: is_css21_color
236+
237+
.. autofunction:: is_css3_color
238+
239+
.. autofunction:: is_uri
240+
241+
.. autofunction:: is_email
242+
243+
.. autofunction:: is_ip_address
244+
245+
.. autofunction:: is_ipv6
246+
247+
.. autofunction:: is_host_name

jsonschema.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from __future__ import division, unicode_literals
1313

1414
import collections
15+
import datetime
1516
import itertools
1617
import json
1718
import numbers
@@ -569,17 +570,16 @@ def is_date_time(instance):
569570
True
570571
>>> is_date_time("1970-01-01 00:00:00 GMT")
571572
False
572-
573-
.. note:: Does not check whether year, month, day, hour, minute and
574-
second components have values in the correct ranges.
575-
576573
>>> is_date_time("0000-58-59T60:61:62")
577-
True
574+
False
578575
579576
"""
580577

581-
pattern = r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?$"
582-
return bool(re.match(pattern, instance))
578+
try:
579+
datetime.datetime.strptime(instance, "%Y-%m-%dT%H:%M:%S.%f")
580+
return True
581+
except ValueError:
582+
return False
583583

584584

585585
@FormatChecker.cls_checks("date")
@@ -594,17 +594,16 @@ def is_date(instance):
594594
True
595595
>>> is_date("12/31/1970")
596596
False
597-
598-
.. note:: Does not check whether year, month and day components have
599-
values in the correct ranges.
600-
601597
>>> is_date("0000-13-32")
602-
True
598+
False
603599
604600
"""
605601

606-
pattern = r"^\d{4}-\d{2}-\d{2}$"
607-
return bool(re.match(pattern, instance))
602+
try:
603+
datetime.datetime.strptime(instance, "%Y-%m-%d")
604+
return True
605+
except ValueError:
606+
return False
608607

609608

610609
@FormatChecker.cls_checks("time")
@@ -619,17 +618,16 @@ def is_time(instance):
619618
True
620619
>>> is_time("11:59:59 PM")
621620
False
622-
623-
.. note:: Does not check whether hour, minute and second components
624-
have values in the correct ranges.
625-
626621
>>> is_time("59:60:61")
627-
True
622+
False
628623
629624
"""
630625

631-
pattern = r"^\d{2}:\d{2}:\d{2}$"
632-
return bool(re.match(pattern, instance))
626+
try:
627+
datetime.datetime.strptime(instance, "%H:%M:%S")
628+
return True
629+
except ValueError:
630+
return False
633631

634632

635633
@FormatChecker.cls_checks("uri")

0 commit comments

Comments
 (0)