From 3cac2f33cb2822c025a1189189c5205fa435dc37 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sun, 29 Oct 2017 14:32:29 -0400 Subject: [PATCH] Start on uri-template based on the provisional API. Will probably change as https://github.com/python-hyper/uritemplate/pull/36 is merged. --- jsonschema/_format.py | 16 ++++++++++++++++ setup.py | 8 +++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/jsonschema/_format.py b/jsonschema/_format.py index 0ffcdf440..f680ecb2c 100644 --- a/jsonschema/_format.py +++ b/jsonschema/_format.py @@ -299,6 +299,22 @@ def is_json_pointer(instance): return jsonpointer.JsonPointer(instance) +try: + import uritemplate.exceptions +except ImportError: + pass +else: + @_checks_drafts( + draft6="uri-template", raises=uritemplate.exceptions.InvalidTemplate, + ) + def is_uri_template( + instance, + template_validator=uritemplate.Validator().force_balanced_braces(), + ): + template = uritemplate.URITemplate(instance) + return template_validator.validate(template) + + draft3_format_checker = FormatChecker(_draft_checkers["draft3"]) draft4_format_checker = FormatChecker(_draft_checkers["draft4"]) draft6_format_checker = FormatChecker(_draft_checkers["draft6"]) diff --git a/setup.py b/setup.py index e9515e285..9a566c57b 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,13 @@ ] extras_require = { - "format" : ["jsonpointer>1.13", "rfc3987", "strict-rfc3339", "webcolors"], + "format": [ + "jsonpointer>1.13", + "rfc3987", + "strict-rfc3339", + "uritemplate>3.0.0", + "webcolors", + ], ":python_version=='2.7'": ["functools32"], }