diff options
| author | Stefan Kögl <stefan@skoegl.net> | 2012-12-14 09:10:07 +0100 |
|---|---|---|
| committer | Stefan Kögl <stefan@skoegl.net> | 2012-12-14 09:10:07 +0100 |
| commit | bb46b6568f0296f700178dd5081c80e2c7b2e73e (patch) | |
| tree | 54f690f6020ef1f9cdc27f109d66d5e8916b95bd /jsonpatch.py | |
| parent | 4803b288c247fcd364977c1901de1dab514cb3eb (diff) | |
| download | python-json-patch-bb46b6568f0296f700178dd5081c80e2c7b2e73e.tar.gz | |
use from/path instead of path/to for move, copy
Diffstat (limited to 'jsonpatch.py')
| -rw-r--r-- | jsonpatch.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/jsonpatch.py b/jsonpatch.py index 8faad2b..1c93ac3 100644 --- a/jsonpatch.py +++ b/jsonpatch.py @@ -409,16 +409,15 @@ class MoveOperation(PatchOperation): """Moves an object property or an array element to new location.""" def apply(self, obj): - subobj, part = self.pointer.to_last(obj) + from_ptr = jsonpointer.JsonPointer(self.operation['from']) + subobj, part = from_ptr.to_last(obj) value = subobj[part] - to_ptr = jsonpointer.JsonPointer(self.operation['to']) - - if self.pointer.contains(to_ptr): + if from_ptr.contains(self.pointer): raise JsonPatchException('Cannot move values into its own children') - RemoveOperation({'op': 'remove', 'path': self.location}).apply(obj) - AddOperation({'op': 'add', 'path': self.operation['to'], 'value': value}).apply(obj) + RemoveOperation({'op': 'remove', 'path': self.operation['from']}).apply(obj) + AddOperation({'op': 'add', 'path': self.location, 'value': value}).apply(obj) class TestOperation(PatchOperation): @@ -447,6 +446,7 @@ class CopyOperation(PatchOperation): """ Copies an object property or an array element to a new location """ def apply(self, obj): - subobj, part = self.pointer.to_last(obj) + from_ptr = jsonpointer.JsonPointer(self.operation['from']) + subobj, part = from_ptr.to_last(obj) value = copy.deepcopy(subobj[part]) - AddOperation({'op': 'add', 'path': self.operation['to'], 'value': value}).apply(obj) + AddOperation({'op': 'add', 'path': self.location, 'value': value}).apply(obj) |
