diff options
author | Ben Kehoe <ben@kehoe.io> | 2022-02-20 14:09:08 -0700 |
---|---|---|
committer | Ben Kehoe <ben@kehoe.io> | 2022-02-20 14:09:08 -0700 |
commit | 04e4ac28b935f7538fa54d8ffd385549015040b5 (patch) | |
tree | bca054ff89807085fedf18f87e12b8b49dec5d6c /jsonpointer.py | |
parent | 66ec8f71ac52384cc61d1db88672a86903671de4 (diff) | |
download | python-json-pointer-04e4ac28b935f7538fa54d8ffd385549015040b5.tar.gz |
Add __str__ and __repr__ methods
Diffstat (limited to 'jsonpointer.py')
-rw-r--r-- | jsonpointer.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/jsonpointer.py b/jsonpointer.py index d353632..3eaea19 100644 --- a/jsonpointer.py +++ b/jsonpointer.py @@ -44,8 +44,10 @@ __license__ = 'Modified BSD License' try: from itertools import izip str = unicode + encode_str = lambda u: u.encode("raw_unicode_escape") except ImportError: # Python 3 izip = zip + encode_str = lambda u: u try: from collections.abc import Mapping, Sequence @@ -322,6 +324,12 @@ class JsonPointer(object): def __hash__(self): return hash(tuple(self.parts)) + def __str__(self): + return encode_str(self.path) + + def __repr__(self): + return "JsonPointer(" + repr(self.path) + ")" + @classmethod def from_parts(cls, parts): """Constructs a JsonPointer from a list of (unescaped) paths |