File: __init__.py

package info (click to toggle)
python-jsonext 0.4.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 152 kB
  • sloc: makefile: 151; python: 144; sh: 19
file content (27 lines) | stat: -rw-r--r-- 728 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""JSON-rendering helpers.

This module provides mixins for the stdlib :class:`json.JSONEncoder` class,
adding serialization methods for other object types, such as
:class:`~datetime.datetime` objects or iterables.

All these are ready to use by using :data:`~jsonext.dumps`.
"""

import functools
import json

from .mixins import (
    JSONDateTimeMixin, JSONIterableMixin, JSONToDictMixin, JSONStringifyMixin,
)
from .wrappers import ISO88601Wrapper


class JSONEncoder(JSONDateTimeMixin, JSONIterableMixin, JSONToDictMixin,
                  JSONStringifyMixin, json.JSONEncoder):
    pass


JSONDecoder = ISO88601Wrapper(json.JSONDecoder())

dumps = functools.partial(json.dumps, cls=JSONEncoder)
loads = JSONDecoder.decode