Add some basic docstring(s)
Change-Id: I8a7b188b89552b9e0c84558774ebd1913236dc98
This commit is contained in:
committed by
Davanum Srinivas (dims)
parent
94bff36bdf
commit
692ae4c397
@@ -163,23 +163,53 @@ def to_primitive(value, convert_instances=False, convert_datetime=True,
|
||||
return six.text_type(value)
|
||||
|
||||
|
||||
def dumps(value, default=to_primitive, **kwargs):
|
||||
def dumps(obj, default=to_primitive, **kwargs):
|
||||
"""Serialize ``obj`` to a JSON formatted ``str``.
|
||||
:param obj: object to be serialized
|
||||
:param default: function that returns a serializable version of an object
|
||||
:param kwargs: extra named parameters, please see documentation
|
||||
of `json.dumps <https://docs.python.org/2/library/json.html#basic-usage>`_
|
||||
:returns: json formatted string
|
||||
"""
|
||||
if is_simplejson:
|
||||
kwargs['namedtuple_as_object'] = False
|
||||
return json.dumps(value, default=default, **kwargs)
|
||||
return json.dumps(obj, default=default, **kwargs)
|
||||
|
||||
|
||||
def dump(obj, fp, *args, **kwargs):
|
||||
"""Serialize ``obj`` as a JSON formatted stream to ``fp``
|
||||
:param obj: object to be serialized
|
||||
:param fp: a ``.write()``-supporting file-like object
|
||||
:param args: extra arguments, please see documentation
|
||||
of `json.dump <https://docs.python.org/2/library/json.html#basic-usage>`_
|
||||
:param kwargs: extra named parameters, please see documentation
|
||||
of `json.dump <https://docs.python.org/2/library/json.html#basic-usage>`_
|
||||
"""
|
||||
if is_simplejson:
|
||||
kwargs['namedtuple_as_object'] = False
|
||||
return json.dump(obj, fp, *args, **kwargs)
|
||||
|
||||
|
||||
def loads(s, encoding='utf-8', **kwargs):
|
||||
"""Deserialize ``s`` (a ``str`` or ``unicode`` instance containing a JSON
|
||||
:param s: string to deserialize
|
||||
:param encoding: encoding used to interpret the string
|
||||
:param kwargs: extra named parameters, please see documentation
|
||||
of `json.loads <https://docs.python.org/2/library/json.html#basic-usage>`_
|
||||
:returns: python object
|
||||
"""
|
||||
return json.loads(encodeutils.safe_decode(s, encoding), **kwargs)
|
||||
|
||||
|
||||
def load(fp, encoding='utf-8', **kwargs):
|
||||
"""Deserialize ``fp`` (a ``.read()``-supporting file-like object containing
|
||||
a JSON document) to a Python object.
|
||||
:param fp: a ``.write()``-supporting file-like object
|
||||
:param encoding: encoding used to interpret the string
|
||||
:param kwargs: extra named parameters, please see documentation
|
||||
of `json.loads <https://docs.python.org/2/library/json.html#basic-usage>`_
|
||||
:returns: python object
|
||||
"""
|
||||
return json.load(codecs.getreader(encoding)(fp), **kwargs)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user