Pointer Backends¶
This module contains the pointer backend protocol and related backend-level
utilities used by JSONPointer.
PointerBackend
¶
Bases: Protocol
NOTE: also require that parent pointers are constructable from parts[:-1] OR require that in certain methods! Protocol for custom JSON Pointer backends.
This library is pointer-backend agnostic. By default it uses jsonpointer.JsonPointer,
but advanced users may plug in a custom backend (different parsing or escaping rules, richer
pointer objects, alternative traversal semantics, and so on).
A backend only needs to provide a small pointer-shaped surface area:
- Constructible from a pointer string.
- Exposes unescaped path tokens via
parts. - Can be reconstructed from tokens via
from_parts. - Can resolve a pointer against a document via
resolve. - Has a round-trippable string form via
__str__.
Notes
- The backend defines its own pointer syntax; there is no universal "root" string.
- Round-trip invariants should hold for the backend's canonical string form:
PointerBackend(x)equalsPointerBackend(str(PointerBackend(x)))andPointerBackend(x)equalsPointerBackend.from_parts(PointerBackend(x).parts). - The library may cache backend instances; implementations should be immutable or otherwise safe to reuse across calls.
- Backends may raise whatever exceptions are natural for them. Higher-level APIs normalize backend failures into library patch errors for a consistent user experience.
Source code in jsonpatchx/backend.py
parts
abstractmethod
property
¶
Unescaped backend-specific tokens.
from_parts(parts)
abstractmethod
classmethod
¶
Construct a pointer from unescaped tokens.
Implementations may accept tokens beyond strings (e.g. ints) and stringify them,
but must preserve the invariant that from_parts(ptr.parts) round-trips.
Source code in jsonpatchx/backend.py
resolve(doc)
abstractmethod
¶
Resolve the pointer against a document using backend-defined traversal semantics.
Implementations typically follow dict/list traversal rules, but the library does not require a particular exception type on failure.
Source code in jsonpatchx/backend.py
TargetState
¶
Bases: Enum
Internal: classification of JSONPointer target resolution states.
Only use when subclassing JSONPointer for custom stateful behaviors.
Source code in jsonpatchx/backend.py
classify_state(ptr, doc)
¶
Internal: Classify the state of a JSONPointer resolution against a document.
Only use when subclassing JSONPointer for custom stateful behaviors.