Skip to content

Commit 7925e87

Browse files
committed
Grudgingly add an inline implementation of relative JSON Pointers.
1 parent 2f3fb3c commit 7925e87

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

jsonschema/_format.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,33 @@ def is_json_pointer(instance):
338338
return jsonpointer.JsonPointer(instance)
339339

340340

341+
# TODO: I don't want to maintain this, so it
342+
# needs to go either into jsonpointer (pending
343+
# https://github.com/stefankoegl/python-json-pointer/issues/34) or
344+
# into a new external library.
345+
@_checks_drafts(
346+
draft7="relative-json-pointer",
347+
raises=jsonpointer.JsonPointerException,
348+
)
349+
def is_relative_json_pointer(instance):
350+
# Definition taken from:
351+
# https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01#section-3
352+
if not isinstance(instance, str_types):
353+
return True
354+
non_negative_integer, rest = [], ""
355+
for i, character in enumerate(instance):
356+
if character.isdigit():
357+
non_negative_integer.append(character)
358+
continue
359+
360+
if not non_negative_integer:
361+
return False
362+
363+
rest = instance[i:]
364+
break
365+
return (rest == "#") or jsonpointer.JsonPointer(rest)
366+
367+
341368
try:
342369
import uritemplate.exceptions
343370
except ImportError:

0 commit comments

Comments
 (0)