summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2019-01-05 11:55:55 +0000
committerJulian Berman <Julian@GrayVines.com>2019-01-05 11:55:55 +0000
commit7925e8704433534657ea5aeb7664dff68cd6ddd6 (patch)
tree8a28ac4e17174befcb7d0ec880042d6d80a21f08
parent2f3fb3c9bd7ec8c6d43e045df6786b82223a0545 (diff)
downloadjsonschema-7925e8704433534657ea5aeb7664dff68cd6ddd6.tar.gz
Grudgingly add an inline implementation of relative JSON Pointers.
-rw-r--r--jsonschema/_format.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/jsonschema/_format.py b/jsonschema/_format.py
index e06f540..1354164 100644
--- a/jsonschema/_format.py
+++ b/jsonschema/_format.py
@@ -338,6 +338,33 @@ else:
return jsonpointer.JsonPointer(instance)
+ # TODO: I don't want to maintain this, so it
+ # needs to go either into jsonpointer (pending
+ # https://github.com/stefankoegl/python-json-pointer/issues/34) or
+ # into a new external library.
+ @_checks_drafts(
+ draft7="relative-json-pointer",
+ raises=jsonpointer.JsonPointerException,
+ )
+ def is_relative_json_pointer(instance):
+ # Definition taken from:
+ # https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01#section-3
+ if not isinstance(instance, str_types):
+ return True
+ non_negative_integer, rest = [], ""
+ for i, character in enumerate(instance):
+ if character.isdigit():
+ non_negative_integer.append(character)
+ continue
+
+ if not non_negative_integer:
+ return False
+
+ rest = instance[i:]
+ break
+ return (rest == "#") or jsonpointer.JsonPointer(rest)
+
+
try:
import uritemplate.exceptions
except ImportError: