From 8dd4f567caffc8b7e27eeebc8f23a889a3168bbb Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Wed, 16 Jul 2025 13:05:32 +0200 Subject: [PATCH 1/3] feat: use non-GPL validator for rfc3987 Signed-off-by: Jan Kowalleck --- docs/validate.rst | 7 +++---- jsonschema/_format.py | 25 +++++++++++++++++++++++++ pyproject.toml | 1 + 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/docs/validate.rst b/docs/validate.rst index 91f0577b9..bc740e340 100644 --- a/docs/validate.rst +++ b/docs/validate.rst @@ -206,8 +206,6 @@ Or if you want to avoid GPL dependencies, a second extra is available: $ pip install jsonschema[format-nongpl] -At the moment, it supports all the available checkers except for ``iri`` and ``iri-reference``. - .. warning:: It is your own responsibility ultimately to ensure you are license-compliant, so you should be double checking your own dependencies if you rely on this extra. @@ -230,8 +228,8 @@ Checker Notes ``idn-hostname`` requires idna_ ``ipv4`` ``ipv6`` OS must have `socket.inet_pton` function -``iri`` requires rfc3987_ -``iri-reference`` requires rfc3987_ +``iri`` requires rfc3987_ or rfc3987-syntax_ +``iri-reference`` requires rfc3987_ or rfc3987-syntax_ ``json-pointer`` requires jsonpointer_ ``regex`` ``relative-json-pointer`` requires jsonpointer_ @@ -249,6 +247,7 @@ Checker Notes .. _rfc3339-validator: https://pypi.org/project/rfc3339-validator/ .. _rfc3986-validator: https://pypi.org/project/rfc3986-validator/ .. _rfc3987: https://pypi.org/pypi/rfc3987/ +.. _rfc3987-syntax: https://pypi.org/pypi/rfc3987-syntax/ .. _uri-template: https://pypi.org/pypi/uri-template/ .. _webcolors: https://pypi.org/pypi/webcolors/ diff --git a/jsonschema/_format.py b/jsonschema/_format.py index 9b4e67b63..6fc7a01e1 100644 --- a/jsonschema/_format.py +++ b/jsonschema/_format.py @@ -324,6 +324,31 @@ def is_uri_reference(instance: object) -> bool: return True return validate_rfc3986(instance, rule="URI_reference") + with suppress(ImportError): + from rfc3987_syntax import is_valid_syntax as _rfc3987_is_valid_syntax + + @_checks_drafts( + draft7="iri", + draft201909="iri", + draft202012="iri", + raises=ValueError, + ) + def is_iri(instance: object) -> bool: + if not isinstance(instance, str): + return True + return _rfc3987_is_valid_syntax("iri", instance) + + @_checks_drafts( + draft7="iri-reference", + draft201909="iri-reference", + draft202012="iri-reference", + raises=ValueError, + ) + def is_iri_reference(instance: object) -> bool: + if not isinstance(instance, str): + return True + return _rfc3987_is_valid_syntax("iri_reference", instance) + else: @_checks_drafts( diff --git a/pyproject.toml b/pyproject.toml index fc176a531..eef060cb5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,6 +62,7 @@ format-nongpl = [ "jsonpointer>1.13", "rfc3339-validator", "rfc3986-validator>0.1.0", + "rfc3987-syntax", "uri_template", "webcolors>=24.6.0", ] From 1a6067fc441177d1911446c7325eee7c776007ae Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Fri, 18 Jul 2025 09:33:47 +0200 Subject: [PATCH 2/3] adjust rfc3987-syntax min-version Signed-off-by: Jan Kowalleck --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index eef060cb5..cccf2ea54 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,7 +62,7 @@ format-nongpl = [ "jsonpointer>1.13", "rfc3339-validator", "rfc3986-validator>0.1.0", - "rfc3987-syntax", + "rfc3987-syntax>=1.1.0", "uri_template", "webcolors>=24.6.0", ] From 9889f69eb5ccb532e2147465697f30c82b2a8bb0 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Fri, 18 Jul 2025 11:23:09 -0400 Subject: [PATCH 3/3] Add the new functionality to the CHANGELOG. --- CHANGELOG.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ed0fa3b66..0d59e4e95 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,9 @@ +v4.25.0 +======= + +* Add support for the ``iri`` and ``iri-reference`` formats to the ``format-nongpl`` extra via the MIT-licensed ``rfc3987-syntax``. + They were alread supported by the ``format`` extra. (#1388). + v4.24.1 =======