File: _json.py

package info (click to toggle)
cherrypy3 18.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,248 kB
  • sloc: python: 17,559; makefile: 29; sh: 8
file content (24 lines) | stat: -rw-r--r-- 439 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""JSON support.

Expose preferred json module as json and provide encode/decode
convenience functions.
"""

try:
    # Prefer simplejson
    import simplejson as json
except ImportError:
    import json


__all__ = ['json', 'encode', 'decode']


decode = json.JSONDecoder().decode
_encode = json.JSONEncoder().iterencode


def encode(value):
    """Encode to bytes."""
    for chunk in _encode(value):
        yield chunk.encode('utf-8')