-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
36 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,22 +32,14 @@ | |
|
||
""" Identify specific nodes in a JSON document (RFC 6901) """ | ||
|
||
from __future__ import unicode_literals | ||
|
||
# Will be parsed by setup.py to determine package metadata | ||
__author__ = 'Stefan Kögl <[email protected]>' | ||
__version__ = '2.4' | ||
__version__ = '3.0.0' | ||
__website__ = 'https://github.com/stefankoegl/python-json-pointer' | ||
__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 | ||
|
@@ -58,7 +50,6 @@ | |
import re | ||
import copy | ||
|
||
|
||
_nothing = object() | ||
|
||
|
||
|
@@ -145,7 +136,7 @@ def pairwise(iterable): | |
a, b = tee(iterable) | ||
for _ in b: | ||
break | ||
return izip(a, b) | ||
return zip(a, b) | ||
|
||
|
||
class JsonPointerException(Exception): | ||
|
@@ -259,12 +250,11 @@ def get_part(cls, doc, part): | |
else: | ||
raise JsonPointerException("Document '%s' does not support indexing, " | ||
"must be mapping/sequence or support __getitem__" % type(doc)) | ||
|
||
def get_parts(self): | ||
"""Returns the list of the parts. For example, JsonPointer('/a/b').get_parts() == ['a', 'b']""" | ||
|
||
return self.parts | ||
|
||
return self.parts | ||
|
||
def walk(self, doc, part): | ||
""" Walks one step in doc and returns the referenced part """ | ||
|
@@ -281,7 +271,7 @@ def walk(self, doc, part): | |
return doc[part] | ||
|
||
except IndexError: | ||
raise JsonPointerException("index '%s' is out of bounds" % (part, )) | ||
raise JsonPointerException("index '%s' is out of bounds" % (part,)) | ||
|
||
# Else the object is a mapping or supports __getitem__(so assume custom indexing) | ||
try: | ||
|
@@ -290,7 +280,6 @@ def walk(self, doc, part): | |
except KeyError: | ||
raise JsonPointerException("member '%s' not found in %s" % (part, doc)) | ||
|
||
|
||
def contains(self, ptr): | ||
""" Returns True if self contains the given ptr """ | ||
return self.parts[:len(ptr.parts)] == ptr.parts | ||
|
@@ -312,9 +301,10 @@ def join(self, suffix): | |
except: | ||
raise JsonPointerException("Invalid suffix") | ||
|
||
def __truediv__(self, suffix): # Python 3 | ||
def __truediv__(self, suffix): # Python 3 | ||
return self.join(suffix) | ||
__div__ = __truediv__ # Python 2 | ||
|
||
__div__ = __truediv__ # Python 2 | ||
|
||
@property | ||
def path(self): | ||
|
@@ -342,10 +332,10 @@ def __hash__(self): | |
return hash(tuple(self.parts)) | ||
|
||
def __str__(self): | ||
return encode_str(self.path) | ||
return self.path | ||
|
||
def __repr__(self): | ||
return "JsonPointer(" + repr(self.path) + ")" | ||
return type(self).__name__ + "(" + repr(self.path) + ")" | ||
|
||
@classmethod | ||
def from_parts(cls, parts): | ||
|
@@ -362,5 +352,6 @@ def from_parts(cls, parts): | |
def escape(s): | ||
return s.replace('~', '~0').replace('/', '~1') | ||
|
||
|
||
def unescape(s): | ||
return s.replace('~1', '/').replace('~0', '~') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
wheel | ||
twine>=1.11.0 | ||
setuptools>=38.6.0 | ||
twine>=5.1.0 | ||
setuptools>=70 | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters