@@ -196,27 +196,14 @@ def set(self, doc, value, inplace=True):
196
196
def get_part (self , doc , part ):
197
197
""" Returns the next step in the correct type """
198
198
199
- if isinstance (doc , Mapping ):
200
- return part
201
-
202
- elif isinstance (doc , Sequence ):
203
-
199
+ if isinstance (doc , Sequence ):
204
200
if part == '-' :
205
201
return part
206
-
207
202
if not RE_ARRAY_INDEX .match (str (part )):
208
203
raise JsonPointerException ("'%s' is not a valid list index" % (part , ))
209
-
210
204
return int (part )
211
-
212
- elif hasattr (doc , '__getitem__' ):
213
- # Allow indexing via ducktyping if the target has defined __getitem__
214
- return part
215
-
216
205
else :
217
- raise JsonPointerException ("Document '%s' does not support indexing, "
218
- "must be dict/list or support __getitem__" % type (doc ))
219
-
206
+ return part
220
207
221
208
def walk (self , doc , part ):
222
209
""" Walks one step in doc and returns the referenced part """
@@ -231,6 +218,10 @@ def walk(self, doc, part):
231
218
raise JsonPointerException ("member '%s' not found in %s" % (part , doc ))
232
219
except IndexError :
233
220
raise JsonPointerException ("index '%s' is out of bounds" % (part , ))
221
+ except TypeError :
222
+ raise JsonPointerException ("Document '%s' does not support indexing, "
223
+ "must be dict/list or support __getitem__" % type (doc ))
224
+
234
225
235
226
def contains (self , ptr ):
236
227
"""Returns True if self contains the given ptr"""
0 commit comments