diff --git a/docs/validate.rst b/docs/validate.rst index 91f0577b..bc740e34 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 9b4e67b6..6fc7a01e 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 fc176a53..cccf2ea5 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>=1.1.0", "uri_template", "webcolors>=24.6.0", ]