Do not hide any problems.
This commit is contained in:
29
jsonpatch.py
29
jsonpatch.py
@@ -131,15 +131,20 @@ class PatchOperation(object):
|
|||||||
def _step(self, obj, loc_part, must_exist=True):
|
def _step(self, obj, loc_part, must_exist=True):
|
||||||
""" Goes one step in a locate() call """
|
""" Goes one step in a locate() call """
|
||||||
|
|
||||||
# Its not clear if a location "1" should be considered as 1 or "1"
|
if isinstance(obj, dict):
|
||||||
# We prefer the integer-variant if possible
|
part_variants = [loc_part]
|
||||||
part_variants = self._try_parse(loc_part) + [loc_part]
|
for variant in part_variants:
|
||||||
|
if variant not in obj:
|
||||||
for variant in part_variants:
|
continue
|
||||||
try:
|
|
||||||
return obj[variant], variant
|
return obj[variant], variant
|
||||||
except:
|
elif isinstance(obj, list):
|
||||||
continue
|
part_variants = [int(loc_part)]
|
||||||
|
for variant in part_variants:
|
||||||
|
if variant >= len(obj):
|
||||||
|
continue
|
||||||
|
return obj[variant], variant
|
||||||
|
else:
|
||||||
|
raise ValueError('list or dict expected, got %r' % type(obj))
|
||||||
|
|
||||||
if must_exist:
|
if must_exist:
|
||||||
raise JsonPatchConflict('key %s not found' % loc_part)
|
raise JsonPatchConflict('key %s not found' % loc_part)
|
||||||
@@ -147,14 +152,6 @@ class PatchOperation(object):
|
|||||||
return obj, part_variants[0]
|
return obj, part_variants[0]
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _try_parse(val, cls=int):
|
|
||||||
try:
|
|
||||||
return [cls(val)]
|
|
||||||
except:
|
|
||||||
return []
|
|
||||||
|
|
||||||
|
|
||||||
class RemoveOperation(PatchOperation):
|
class RemoveOperation(PatchOperation):
|
||||||
""" Removes an object property or an array element
|
""" Removes an object property or an array element
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user