From c63c6368ebbf0f8b6d023f936f93816b3f95ee83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Wed, 26 May 2021 13:56:49 +0200 Subject: [PATCH] fix the module --- README.md | 3 +++ docs/usage.rst | 36 ++++++++++++++++++++++++++++++++++++ minijson/__init__.py | 5 ++++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a924bd1..7e3e3d9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ MiniJSON ======== +[](http://minijson.readthedocs.io/en/latest/?badge=latest) + +MiniJSON is a codec for a compact binary representation of a subset of JSON. Usage ----- diff --git a/docs/usage.rst b/docs/usage.rst index 0c73cb9..f985e4b 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -24,3 +24,39 @@ And the following exceptions: .. autoclass:: minijson.EncodingError .. autoclass:: minijson.DecodingError + +Controlling float output +------------------------ + +By default, floats are output as IEEE 754 single. To switch to double just call: + +.. autofunction:: minijson.switch_default_double + +or to go again into singles: + +.. autofunction:: minijson.switch_default_float + +Serializing objects +------------------- + +If you got an object, whose entire contents can be extracted from it's :code:`__dict__`, +and which can be instantiated with a constructor providing this :code:`__dict__` as keyword +arguments to the program, you can use functions below to serialize/unserialize them: + +.. autofunction:: minijson.dumps_object + +.. autofunction:: minijson.loads_object + +Example: + +.. code-block:: python + + from minijson import loads_object, dumps_object + + class Test: + def __init__(self, a): + self.a = a + + a = Test(3) + b = dumps_object(a) + loads_object(b, Test) diff --git a/minijson/__init__.py b/minijson/__init__.py index 709fcab..fd95c4a 100644 --- a/minijson/__init__.py +++ b/minijson/__init__.py @@ -1,3 +1,6 @@ from .routines import dumps, loads, switch_default_double, switch_default_float, \ - dumps_object, loads_object + dumps_object, loads_object, parse, dump from .exceptions import MiniJSONError, EncodingError, DecodingError + +__all__ = ['dumps', 'loads', 'switch_default_float', 'switch_default_double', + 'dumps_object', 'loads_object', 'parse', 'dump'] -- GitLab