Make docs be more sphnix friendly.

This commit is contained in:
Alexander Shorin
2012-06-21 02:25:29 +04:00
parent 9f11add937
commit add518a3e0

View File

@@ -71,7 +71,7 @@ def apply_patch(doc, patch, in_place=False):
:type doc: dict :type doc: dict
:param patch: JSON patch as list of dicts or raw JSON-encoded string. :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. :param in_place: While :const:`True` patch will modify target document.
By default patch will be applied to document copy. By default patch will be applied to document copy.
@@ -142,8 +142,9 @@ class JsonPatch(object):
>>> lpatch == patch.patch >>> lpatch == patch.patch
True True
Also JsonPatch could be converted directly to bool if it contains any Also JsonPatch could be converted directly to :class:`bool` if it contains
operation statements: any operation statements:
>>> bool(patch) >>> bool(patch)
True True
>>> bool(JsonPatch([])) >>> bool(JsonPatch([]))
@@ -151,6 +152,7 @@ class JsonPatch(object):
This behavior is very handy with :func:`make_patch` to write more readable This behavior is very handy with :func:`make_patch` to write more readable
code: code:
>>> old = {'foo': 'bar', 'numbers': [1, 3, 4, 8]} >>> old = {'foo': 'bar', 'numbers': [1, 3, 4, 8]}
>>> new = {'baz': 'qux', 'numbers': [1, 4, 7]} >>> new = {'baz': 'qux', 'numbers': [1, 4, 7]}
>>> patch = make_patch(old, new) >>> patch = make_patch(old, new)
@@ -184,7 +186,13 @@ class JsonPatch(object):
@classmethod @classmethod
def from_string(cls, patch_str): 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) patch = json.loads(patch_str)
return cls(patch) return cls(patch)
@@ -251,7 +259,17 @@ class JsonPatch(object):
return json.dumps(self.patch) return json.dumps(self.patch)
def apply(self, obj, in_place=False): 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: if not in_place:
obj = copy.deepcopy(obj) obj = copy.deepcopy(obj)