diff options
author | Stefan Kögl <stefan@skoegl.net> | 2018-04-02 17:55:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-02 17:55:00 +0200 |
commit | 0c96a53bb3495772193fd98ff18a0ded10128be3 (patch) | |
tree | cc53424049ee3b71c053fc03d30b17be9362b0ce /jsonpatch.py | |
parent | 3c621da9b77ee57dcfd42887b460e1ffb66528b2 (diff) | |
parent | aae608237495fb63d9428da84f36db96d4e4c9dd (diff) | |
download | python-json-patch-0c96a53bb3495772193fd98ff18a0ded10128be3.tar.gz |
Merge pull request #75 from stefankoegl/jsonptr
Expect path/from attributes also as JsonPoiner instances (#60)
Diffstat (limited to 'jsonpatch.py')
-rw-r--r-- | jsonpatch.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/jsonpatch.py b/jsonpatch.py index 06e4f94..326608e 100644 --- a/jsonpatch.py +++ b/jsonpatch.py @@ -333,8 +333,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): @@ -491,7 +497,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") |