summaryrefslogtreecommitdiff
path: root/jsonpatch.py
diff options
context:
space:
mode:
authorStefan Kögl <stefan@skoegl.net>2017-12-03 23:02:18 +0100
committerStefan Kögl <stefan@skoegl.net>2017-12-03 23:02:18 +0100
commitaae608237495fb63d9428da84f36db96d4e4c9dd (patch)
tree459ebd258b9aae7bd5e88d216c6a45dcd222d62a /jsonpatch.py
parentdf0c56d592c9f1d0fada201b7fa66d9d359ac7a3 (diff)
downloadpython-json-patch-aae608237495fb63d9428da84f36db96d4e4c9dd.tar.gz
Expect path/from attributes also as JsonPoiner instances (#60)jsonptr
Diffstat (limited to 'jsonpatch.py')
-rw-r--r--jsonpatch.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/jsonpatch.py b/jsonpatch.py
index cd08a82..e8608ec 100644
--- a/jsonpatch.py
+++ b/jsonpatch.py
@@ -335,8 +335,14 @@ class PatchOperation(object):
"""A single operation inside a JSON Patch."""
def __init__(self, operation):
- self.location = operation['path']
- self.pointer = JsonPointer(self.location)
+
+ if isinstance(operation['path'], JsonPointer):
+ self.location = operation['path'].path
+ self.pointer = operation['path']
+ else:
+ self.location = operation['path']
+ self.pointer = JsonPointer(self.location)
+
self.operation = operation
def apply(self, obj):
@@ -493,7 +499,10 @@ class MoveOperation(PatchOperation):
def apply(self, obj):
try:
- from_ptr = JsonPointer(self.operation['from'])
+ if isinstance(self.operation['from'], JsonPointer):
+ from_ptr = self.operation['from']
+ else:
+ from_ptr = JsonPointer(self.operation['from'])
except KeyError as ex:
raise InvalidJsonPatch(
"The operation does not contain a 'from' member")