Skip to content

Commit 0db6f12

Browse files
committed
Merge remote-tracking branch 'naimetti/format-nongpl'
* naimetti/format-nongpl: format_nongpl docs, and style fixes Add format validators as separate modules non GPL format option
2 parents 5ca2fff + f7ea84d commit 0db6f12

File tree

5 files changed

+61
-16
lines changed

5 files changed

+61
-16
lines changed

docs/spelling-wordlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ HD
3939

4040
Berman
4141
Freenode
42+
GPL

docs/validate.rst

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,26 @@ to validate. Their names can be viewed by inspecting the
321321
`FormatChecker.checkers` attribute. Certain checkers will only be
322322
available if an appropriate package is available for use. The easiest way to
323323
ensure you have what is needed is to install ``jsonschema`` using the
324-
``format`` setuptools extra -- i.e.
324+
``format`` or ``format_nongpl`` setuptools extra -- i.e.
325325

326326
.. code-block:: sh
327327
328328
$ pip install jsonschema[format]
329329
330-
which will install all of the below dependencies for all formats. The
331-
more specific list of available checkers, along with their requirement
330+
which will install all of the below dependencies for all formats.
331+
332+
Or if you want to install MIT-license compatible dependencies only:
333+
334+
.. code-block:: sh
335+
336+
$ pip install jsonschema[format_nongpl]
337+
338+
The non-GPL extra is intended to not install any direct dependencies
339+
that are GPL (but that of course end-users should do their own verification).
340+
At the moment, it supports all the available checkers except for ``iri`` and
341+
``iri-reference``.
342+
343+
The more specific list of available checkers, along with their requirement
332344
(if any,) are listed below.
333345

334346
.. note::
@@ -342,7 +354,7 @@ Checker Notes
342354
========================= ====================
343355
``color`` requires webcolors_
344356
``date``
345-
``date-time`` requires strict-rfc3339_
357+
``date-time`` requires strict-rfc3339_ or rfc3339-validator_
346358
``email``
347359
``hostname``
348360
``idn-hostname`` requires idna_
@@ -353,9 +365,9 @@ Checker Notes
353365
``json-pointer`` requires jsonpointer_
354366
``regex``
355367
``relative-json-pointer`` requires jsonpointer_
356-
``time`` requires strict-rfc3339_
357-
``uri`` requires rfc3987_
358-
``uri-reference`` requires rfc3987_
368+
``time`` requires strict-rfc3339_ or rfc3339-validator_
369+
``uri`` requires rfc3987_ or rfc3986-validator_
370+
``uri-reference`` requires rfc3987_ or rfc3986-validator_
359371
========================= ====================
360372

361373

@@ -365,7 +377,8 @@ Checker Notes
365377
.. _rfc5322: https://tools.ietf.org/html/rfc5322#section-3.4.1
366378
.. _strict-rfc3339: https://pypi.org/pypi/strict-rfc3339/
367379
.. _webcolors: https://pypi.org/pypi/webcolors/
368-
380+
.. _rfc3339-validator: https://pypi.org/project/rfc3339-validator/
381+
.. _rfc3986-validator: https://pypi.org/project/rfc3986-validator/
369382

370383
.. note::
371384

jsonschema/_format.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,27 @@ def is_idn_host_name(instance):
248248
try:
249249
import rfc3987
250250
except ImportError:
251-
pass
251+
try:
252+
from rfc3986_validator import validate_rfc3986
253+
except ImportError:
254+
pass
255+
else:
256+
@_checks_drafts(name="uri")
257+
def is_uri(instance):
258+
if not isinstance(instance, str_types):
259+
return True
260+
return validate_rfc3986(instance, rule="URI")
261+
262+
@_checks_drafts(
263+
draft6="uri-reference",
264+
draft7="uri-reference",
265+
raises=ValueError,
266+
)
267+
def is_uri_reference(instance):
268+
if not isinstance(instance, str_types):
269+
return True
270+
return validate_rfc3986(instance, rule="URI_reference")
271+
252272
else:
253273
@_checks_drafts(draft7="iri", raises=ValueError)
254274
def is_iri(instance):
@@ -280,15 +300,19 @@ def is_uri_reference(instance):
280300

281301

282302
try:
283-
import strict_rfc3339
303+
from strict_rfc3339 import validate_rfc3339
284304
except ImportError:
285-
pass
286-
else:
305+
try:
306+
from rfc3339_validator import validate_rfc3339
307+
except ImportError:
308+
validate_rfc3339 = None
309+
310+
if validate_rfc3339:
287311
@_checks_drafts(name="date-time")
288312
def is_datetime(instance):
289313
if not isinstance(instance, str_types):
290314
return True
291-
return strict_rfc3339.validate_rfc3339(instance)
315+
return validate_rfc3339(instance)
292316

293317
@_checks_drafts(draft7="time")
294318
def is_time(instance):

setup.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ format =
4141
rfc3987
4242
strict-rfc3339
4343
webcolors
44+
format_nongpl =
45+
idna
46+
jsonpointer>1.13
47+
webcolors
48+
rfc3986-validator>0.1.0
49+
rfc3339-validator
4450

4551
[options.entry_points]
4652
console_scripts =

tox.ini

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
envlist =
3-
py{35,36,37,38,py,py3}-{build,tests}
3+
py{35,36,37,38,py,py3}-{build,tests,tests_nongpl},
44
demo
55
readme
66
safety
@@ -22,8 +22,9 @@ whitelist_externals =
2222
virtualenv
2323
commands =
2424
perf,tests: {envbindir}/python -m pip install '{toxinidir}[format]'
25+
tests_nongpl: {envbindir}/python -m pip install '{toxinidir}[format_nongpl]'
2526

26-
tests: {envbindir}/trial {posargs:jsonschema}
27+
tests,tests_nongpl: {envbindir}/trial {posargs:jsonschema}
2728
tests: {envpython} -m doctest {toxinidir}/README.rst
2829

2930
perf: mkdir {envtmpdir}/benchmarks/
@@ -53,7 +54,7 @@ deps =
5354

5455
perf: pyperf
5556

56-
tests,coverage,codecov: -r{toxinidir}/test-requirements.txt
57+
tests,tests_nongpl,coverage,codecov: -r{toxinidir}/test-requirements.txt
5758

5859
coverage,codecov: coverage
5960
codecov: codecov

0 commit comments

Comments
 (0)