summaryrefslogtreecommitdiff
path: root/jsonpatch.py
diff options
context:
space:
mode:
authorStefan Kögl <stefan@skoegl.net>2012-09-11 11:43:32 +0200
committerStefan Kögl <stefan@skoegl.net>2012-09-11 11:43:32 +0200
commit3829275ade689224dfe48ec503b9204e40a6723c (patch)
treebd409a6553ec357dda195ced6c61aa0155aa378b /jsonpatch.py
parent1e4abe62e8fba313f73b7d93f7002bd7647e58a9 (diff)
downloadpython-json-patch-3829275ade689224dfe48ec503b9204e40a6723c.tar.gz
add "copy" operation, fixes #7
Diffstat (limited to 'jsonpatch.py')
-rw-r--r--jsonpatch.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/jsonpatch.py b/jsonpatch.py
index 7c8fa8f..5dac4a1 100644
--- a/jsonpatch.py
+++ b/jsonpatch.py
@@ -169,7 +169,8 @@ class JsonPatch(object):
'add': AddOperation,
'replace': ReplaceOperation,
'move': MoveOperation,
- 'test': TestOperation
+ 'test': TestOperation,
+ 'copy': CopyOperation,
}
def __str__(self):
@@ -414,3 +415,12 @@ class TestOperation(PatchOperation):
value = self.operation['value']
subobj, part = self.locate(obj, self.location)
assert subobj[part] == value
+
+
+class CopyOperation(PatchOperation):
+ """ Copies an object property or an array element to a new location """
+
+ def apply(self, obj):
+ subobj, part = self.locate(obj, self.location)
+ value = subobj[part]
+ AddOperation(self.operation['to'], {'value': value}).apply(obj)