summaryrefslogtreecommitdiff
path: root/jsonpointer.py
diff options
context:
space:
mode:
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)