55import urllib .parse
66from typing import Any , Iterable , Literal , Mapping , Sequence , TYPE_CHECKING , Union , overload
77
8- from jschon .exceptions import JSONPointerError , RelativeJSONPointerError
8+ from jschon .exc import (
9+ JSONPointerMalformedError ,
10+ JSONPointerReferenceError ,
11+ RelativeJSONPointerMalformedError ,
12+ RelativeJSONPointerReferenceError ,
13+ )
914
1015if TYPE_CHECKING :
1116 from jschon .json import JSON
@@ -74,16 +79,16 @@ def __new__(cls, *values: Union[str, Iterable[str]]) -> JSONPointer:
7479
7580 :param values: each value may either be an RFC 6901 string, or an iterable
7681 of unescaped keys
77- :raise JSONPointerError : if a string argument does not conform to the RFC
78- 6901 syntax
82+ :raise JSONPointerMalformedError : if a string argument does not conform to
83+ the RFC 6901 syntax
7984 """
8085 self = object .__new__ (cls )
8186 self ._keys = []
8287
8388 for value in values :
8489 if isinstance (value , str ):
8590 if not JSONPointer ._json_pointer_re .fullmatch (value ):
86- raise JSONPointerError (f"'{ value } ' is not a valid JSON pointer" )
91+ raise JSONPointerMalformedError (f"'{ value } ' is not a valid JSON pointer" )
8792 self ._keys .extend (self .unescape (token ) for token in value .split ('/' )[1 :])
8893
8994 elif isinstance (value , JSONPointer ):
@@ -179,8 +184,8 @@ def evaluate(self, document: Any) -> Any:
179184 will always fail.
180185
181186 :param document: any Python object
182- :raise JSONPointerError : if `self` references a non-existent location
183- within `document`
187+ :raise JSONPointerReferenceError : if `self` references a non-existent
188+ location in `document`
184189 """
185190
186191 def resolve (value , keys ):
@@ -203,7 +208,7 @@ def resolve(value, keys):
203208 except (KeyError , IndexError ):
204209 pass
205210
206- raise JSONPointerError (f"Path '{ self } ' not found in document" )
211+ raise JSONPointerReferenceError (f"Path '{ self } ' not found in document" )
207212
208213 return resolve (document , collections .deque (self ._keys ))
209214
@@ -283,13 +288,13 @@ def __new__(
283288 a value of 0, which is not allowed by the grammar, is treated as if
284289 there is no adjustment.
285290 :param ref: a :class:`JSONPointer` instance, or the literal ``'#'``
286- :raise RelativeJSONPointerError : for any invalid arguments
291+ :raise RelativeJSONPointerMalformedError : for any invalid arguments
287292 """
288293 self = object .__new__ (cls )
289294
290295 if value is not None :
291296 if not (match := RelativeJSONPointer ._regex .fullmatch (value )):
292- raise RelativeJSONPointerError (f"'{ value } ' is not a valid relative JSON pointer" )
297+ raise RelativeJSONPointerMalformedError (f"'{ value } ' is not a valid relative JSON pointer" )
293298
294299 up , over , ref = match .group ('up' , 'over' , 'ref' )
295300 self .up = int (up )
@@ -337,25 +342,25 @@ def evaluate(self, document: JSON) -> Union[int, str, JSON]:
337342 node = document
338343 for _ in range (self .up ):
339344 if node .parent is None :
340- raise RelativeJSONPointerError ('Up too many levels' )
345+ raise RelativeJSONPointerReferenceError ('Up too many levels' )
341346 node = node .parent
342347
343348 if self .over :
344349 if node .parent is None :
345- raise RelativeJSONPointerError ('No containing node for index adjustment' )
350+ raise RelativeJSONPointerReferenceError ('No containing node for index adjustment' )
346351 if node .parent .type != "array" :
347- raise RelativeJSONPointerError (f'Index adjustment not valid for type { node .parent .type } ' )
352+ raise RelativeJSONPointerReferenceError (f'Index adjustment not valid for type { node .parent .type } ' )
348353 adjusted = int (node .key ) + self .over
349354 if adjusted < 0 or adjusted >= len (node .parent ):
350- raise RelativeJSONPointerError (f'Index adjustment out of range' )
355+ raise RelativeJSONPointerReferenceError (f'Index adjustment out of range' )
351356 node = node .parent [adjusted ]
352357
353358 if self .index :
354359 if node .parent is None :
355- raise RelativeJSONPointerError ('No containing node' )
360+ raise RelativeJSONPointerReferenceError ('No containing node' )
356361 return int (node .key ) if node .parent .type == "array" else node .key
357362
358363 try :
359364 return self .path .evaluate (node )
360- except JSONPointerError as e :
361- raise RelativeJSONPointerError from e
365+ except JSONPointerReferenceError as e :
366+ raise RelativeJSONPointerReferenceError from e
0 commit comments