diff options
author | Stefan Kögl <stefan@skoegl.net> | 2012-12-14 12:37:18 +0100 |
---|---|---|
committer | Stefan Kögl <stefan@skoegl.net> | 2012-12-14 12:37:18 +0100 |
commit | 16a766075173d4437c26bc5551b5efab1669afbd (patch) | |
tree | 0c610d6a6a3bd1b639e5c6704f6a12208b7365b4 | |
parent | 0fc6dbdc067a28222ece0a4e853a7298efba1b73 (diff) | |
download | python-json-patch-16a766075173d4437c26bc5551b5efab1669afbd.tar.gz |
various smaller bugfixes
-rw-r--r-- | jsonpatch.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/jsonpatch.py b/jsonpatch.py index ef1734d..0eb3e55 100644 --- a/jsonpatch.py +++ b/jsonpatch.py @@ -350,7 +350,10 @@ class RemoveOperation(PatchOperation): def apply(self, obj): subobj, part = self.pointer.to_last(obj) - del subobj[part] + try: + del subobj[part] + except KeyError as ex: + raise JsonPatchConflict(ex) class AddOperation(PatchOperation): @@ -426,7 +429,10 @@ class TestOperation(PatchOperation): def apply(self, obj): try: subobj, part = self.pointer.to_last(obj) - val = self.pointer.walk(subobj, part) + if part is None: + val = subobj + else: + val = self.pointer.walk(subobj, part) except JsonPointerException: exc_info = sys.exc_info() @@ -439,7 +445,7 @@ class TestOperation(PatchOperation): if 'value' in self.operation: value = self.operation['value'] if val != value: - raise JsonPatchTestFailed('%s is not equal to tested value %s' % (val, value)) + raise JsonPatchTestFailed('%s is not equal to tested value %s (types %s and %s)' % (val, value, type(val), type(value))) class CopyOperation(PatchOperation): |