@@ -193,7 +193,7 @@ def to_last(self, doc):
193
193
for part in self .parts [:- 1 ]:
194
194
doc = self .walk (doc , part )
195
195
196
- return doc , self .get_part (doc , self .parts [- 1 ])
196
+ return doc , JsonPointer .get_part (doc , self .parts [- 1 ])
197
197
198
198
def resolve (self , doc , default = _nothing ):
199
199
"""Resolves the pointer against doc and returns the referenced object"""
@@ -228,7 +228,8 @@ def set(self, doc, value, inplace=True):
228
228
parent [part ] = value
229
229
return doc
230
230
231
- def get_part (self , doc , part ):
231
+ @classmethod
232
+ def get_part (cls , doc , part ):
232
233
"""Returns the next step in the correct type"""
233
234
234
235
if isinstance (doc , Mapping ):
@@ -239,7 +240,7 @@ def get_part(self, doc, part):
239
240
if part == '-' :
240
241
return part
241
242
242
- if not self ._RE_ARRAY_INDEX .match (str (part )):
243
+ if not JsonPointer ._RE_ARRAY_INDEX .match (str (part )):
243
244
raise JsonPointerException ("'%s' is not a valid sequence index" % part )
244
245
245
246
return int (part )
@@ -252,12 +253,17 @@ def get_part(self, doc, part):
252
253
else :
253
254
raise JsonPointerException ("Document '%s' does not support indexing, "
254
255
"must be mapping/sequence or support __getitem__" % type (doc ))
256
+
257
+ def get_parts (self ):
258
+ """Returns the list of the parts. For example, JsonPointer('/a/b').get_parts() == ['a', 'b']"""
259
+
260
+ return self .parts
255
261
256
262
257
263
def walk (self , doc , part ):
258
264
""" Walks one step in doc and returns the referenced part """
259
265
260
- part = self .get_part (doc , part )
266
+ part = JsonPointer .get_part (doc , part )
261
267
262
268
assert hasattr (doc , '__getitem__' ), "invalid document type %s" % (type (doc ),)
263
269
0 commit comments