summaryrefslogtreecommitdiff
path: root/jsonpointer.py
diff options
context:
space:
mode:
authorStefan Kögl <stefan@skoegl.net>2013-01-06 10:57:13 +0100
committerStefan Kögl <stefan@skoegl.net>2013-01-06 10:57:13 +0100
commit55198aa4cb5c7d3d503e8cb9e717433688af8d8f (patch)
tree03d56d54d64ce83a71f561ffa1eec0340691ce0e /jsonpointer.py
parent2537956503ea982f0fa29f54399677605a60218d (diff)
downloadpython-json-pointer-55198aa4cb5c7d3d503e8cb9e717433688af8d8f.tar.gz
unambiguous array indices make pointers comparable
Diffstat (limited to 'jsonpointer.py')
-rw-r--r--jsonpointer.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/jsonpointer.py b/jsonpointer.py
index cbb9137..e6ddb4a 100644
--- a/jsonpointer.py
+++ b/jsonpointer.py
@@ -30,9 +30,9 @@
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
-""" Identify specific nodes in a JSON document (according to draft 07) """
+""" Identify specific nodes in a JSON document (according to draft 08) """
-# http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-07
+# http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-08
# Will be parsed by setup.py to determine package metadata
__author__ = 'Stefan Kögl <stefan@skoegl.net>'
@@ -205,6 +205,23 @@ class JsonPointer(object):
self.parts[:len(ptr.parts)] == ptr.parts
+ def __eq__(self, other):
+ """ compares a pointer to another object
+
+ Pointers can be compared by comparing their strings (or splitted
+ strings), because no two different parts can point to the same
+ structure in an object (eg no different number representations) """
+
+ if not isinstance(other, JsonPointer):
+ return False
+
+ return self.parts == other.parts
+
+
+ def __hash__(self):
+ return hash(tuple(self.parts))
+
+
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = tee(iterable)