diff options
Diffstat (limited to 'jsonpointer.py')
-rw-r--r-- | jsonpointer.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/jsonpointer.py b/jsonpointer.py index 3eaea19..d9fe0c0 100644 --- a/jsonpointer.py +++ b/jsonpointer.py @@ -54,7 +54,7 @@ try: except ImportError: # Python 3 from collections import Mapping, Sequence -from itertools import tee +from itertools import tee, chain import re import copy @@ -299,6 +299,23 @@ class JsonPointer(object): """ Returns True if self contains the given ptr """ return self.contains(item) + def join(self, suffix): + """ Returns a new JsonPointer with the given suffix append to this ptr """ + if isinstance(suffix, JsonPointer): + suffix_parts = suffix.parts + elif isinstance(suffix, str): + suffix_parts = JsonPointer(suffix).parts + else: + suffix_parts = suffix + try: + return JsonPointer.from_parts(chain(self.parts, suffix_parts)) + except: + raise JsonPointerException("Invalid suffix") + + def __truediv__(self, suffix): # Python 3 + return self.join(suffix) + __div__ = __truediv__ # Python 2 + @property def path(self): """Returns the string representation of the pointer |