summaryrefslogtreecommitdiff
path: root/jsonpatch.py
diff options
context:
space:
mode:
authorAlexander Shorin <kxepal@gmail.com>2012-06-21 02:25:29 +0400
committerAlexander Shorin <kxepal@gmail.com>2012-06-21 02:25:29 +0400
commitadd518a3e0fbc680c22a3581420efb1c80235fb5 (patch)
tree018620b4b79aa8ea6ac9593328508d828a4d8af9 /jsonpatch.py
parent9f11add93705c9081cbbd56fa78bef48ed843edc (diff)
downloadpython-json-patch-add518a3e0fbc680c22a3581420efb1c80235fb5.tar.gz
Make docs be more sphnix friendly.
Diffstat (limited to 'jsonpatch.py')
-rw-r--r--jsonpatch.py28
1 files changed, 23 insertions, 5 deletions
diff --git a/jsonpatch.py b/jsonpatch.py
index baf83f9..67bdfdb 100644
--- a/jsonpatch.py
+++ b/jsonpatch.py
@@ -71,7 +71,7 @@ def apply_patch(doc, patch, in_place=False):
:type doc: dict
:param patch: JSON patch as list of dicts or raw JSON-encoded string.
- :type patch: list
+ :type patch: list or str
:param in_place: While :const:`True` patch will modify target document.
By default patch will be applied to document copy.
@@ -142,8 +142,9 @@ class JsonPatch(object):
>>> lpatch == patch.patch
True
- Also JsonPatch could be converted directly to bool if it contains any
- operation statements:
+ Also JsonPatch could be converted directly to :class:`bool` if it contains
+ any operation statements:
+
>>> bool(patch)
True
>>> bool(JsonPatch([]))
@@ -151,6 +152,7 @@ class JsonPatch(object):
This behavior is very handy with :func:`make_patch` to write more readable
code:
+
>>> old = {'foo': 'bar', 'numbers': [1, 3, 4, 8]}
>>> new = {'baz': 'qux', 'numbers': [1, 4, 7]}
>>> patch = make_patch(old, new)
@@ -184,7 +186,13 @@ class JsonPatch(object):
@classmethod
def from_string(cls, patch_str):
- """Creates JsonPatch instance from string source."""
+ """Creates JsonPatch instance from string source.
+
+ :param patch_str: JSON patch as raw string.
+ :type patch_str: str
+
+ :return: :class:`JsonPatch` instance.
+ """
patch = json.loads(patch_str)
return cls(patch)
@@ -251,7 +259,17 @@ class JsonPatch(object):
return json.dumps(self.patch)
def apply(self, obj, in_place=False):
- """Applies the patch to given object."""
+ """Applies the patch to given object.
+
+ :param obj: Document object.
+ :type obj: dict
+
+ :param in_place: Tweaks way how patch would be applied - directly to
+ specified `obj` or to his copy.
+ :type in_place: bool
+
+ :return: Modified `obj`.
+ """
if not in_place:
obj = copy.deepcopy(obj)