From 4c5cb493f2a8e41fd05b9b25df419701e215812a Mon Sep 17 00:00:00 2001 From: kafkaf- Date: Fri, 14 Nov 2014 16:18:39 +0200 Subject: Using the same handling for the case in which the doc is a mapping or an object that support __getitem__(but not a sequence), Updated the tests --- jsonpointer.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'jsonpointer.py') diff --git a/jsonpointer.py b/jsonpointer.py index b3f0362..06d2cb7 100644 --- a/jsonpointer.py +++ b/jsonpointer.py @@ -225,15 +225,7 @@ class JsonPointer(object): assert (type(doc) in (dict, list) or hasattr(doc, '__getitem__')), "invalid document type %s" % (type(doc),) - if isinstance(doc, Mapping): - try: - return doc[part] - - except KeyError: - raise JsonPointerException("member '%s' not found in %s" % (part, doc)) - - elif isinstance(doc, Sequence): - + if isinstance(doc, Sequence): if part == '-': return EndOfList(doc) @@ -243,10 +235,14 @@ class JsonPointer(object): except IndexError: raise JsonPointerException("index '%s' is out of bounds" % (part, )) - else: - # Object supports __getitem__, assume custom indexing + # Else the object is a mapping or supports __getitem__(so assume custom indexing) + try: return 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 len(self.parts) > len(ptr.parts) and \ -- cgit v1.2.1