diff options
| author | Alexander Shorin <kxepal@gmail.com> | 2012-06-16 23:35:57 +0400 |
|---|---|---|
| committer | Alexander Shorin <kxepal@gmail.com> | 2012-06-16 23:35:57 +0400 |
| commit | be9be6d96366c899cb0793e6502a40ccaca57473 (patch) | |
| tree | 72d209c4b56269ba9d75a75c8cb015a55d0f7481 /jsonpatch.py | |
| parent | e90dba067e912ad65e5d7c0d519a5d97ed5f89d4 (diff) | |
| download | python-json-patch-be9be6d96366c899cb0793e6502a40ccaca57473.tar.gz | |
Let apply_patch to handle patch as JSON-encoded string.
Diffstat (limited to 'jsonpatch.py')
| -rw-r--r-- | jsonpatch.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/jsonpatch.py b/jsonpatch.py index 25d04d4..b93a14f 100644 --- a/jsonpatch.py +++ b/jsonpatch.py @@ -47,6 +47,9 @@ if sys.version_info < (2, 6): else: import json +if sys.version_info >= (3, 0): + basestring = (bytes, str) + class JsonPatchException(Exception): """Base Json Patch exception""" @@ -67,7 +70,7 @@ def apply_patch(doc, patch, in_place=False): :param doc: Document object. :type doc: dict - :param patch: JSON patch as list of dicts. + :param patch: JSON patch as list of dicts or raw JSON-encoded string. :type patch: list :param in_place: While :const:`True` patch will modify target document. @@ -89,7 +92,10 @@ def apply_patch(doc, patch, in_place=False): True """ - patch = JsonPatch(patch) + if isinstance(patch, basestring): + patch = JsonPatch.from_string(patch) + else: + patch = JsonPatch(patch) return patch.apply(doc, in_place) def make_patch(src, dst): |
