ž
¦ÿf°; c @ s d Z d d l Z y d d l m Z Wn e k
r@ d Z Yn Xy d d l m Z Wn e k
ro d Z Yn Xe j d ƒ Z
e j d ƒ Z e j d ƒ Z i d d 6d
d 6d d
6d d 6d d 6d d 6d d 6Z
x3 e d ƒ D]% Z e
j e e ƒ d j e ƒ ƒ qá We d ƒ Z e Z d d „ Z d d „ Z e p=e Z Gd d „ d e ƒ Z e e e e e e e e! e" d d „ Z# d S(! u Implementation of JSONEncoder
i N( u encode_basestring_ascii( u make_encoderu [\x00-\x1f\\"\b\f\n\r\t]u ([\\"]|[^\ -~])s [€-ÿ]u \\u \u \"u "u \bu u \fu u \nu
u \ru
u \tu i u \u{0:04x}u infc C s$ d d „ } d t j | | ƒ d S( u5 Return a JSON representation of a Python string
c S s t | j d ƒ S( Ni ( u
ESCAPE_DCTu group( u match( ( u1 /opt/alt/python33/lib64/python3.3/json/encoder.pyu replace% s u" encode_basestring..replaceu "( u ESCAPEu sub( u su replace( ( u1 /opt/alt/python33/lib64/python3.3/json/encoder.pyu encode_basestring! s u encode_basestringc C s$ d d „ } d t j | | ƒ d S( uA Return an ASCII-only JSON representation of a Python string
c S s“ | j d ƒ } y t | SWnq t k
rŽ t | ƒ } | d k rP d j | ƒ S| d 8} d | d ?d @B} d | d @B} d j | | ƒ SYn Xd S( Ni i u \u{0:04x}i Ø i
iÿ i Ü u \u{0:04x}\u{1:04x}( u groupu
ESCAPE_DCTu KeyErroru ordu format( u matchu su nu s1u s2( ( u1 /opt/alt/python33/lib64/python3.3/json/encoder.pyu replace. s
u+ py_encode_basestring_ascii..replaceu "( u ESCAPE_ASCIIu sub( u su replace( ( u1 /opt/alt/python33/lib64/python3.3/json/encoder.pyu py_encode_basestring_ascii* s u py_encode_basestring_asciic
B sq | Ee Z d Z d Z d Z d Z d
d d d d
d d d d d „ Z d d „ Z
d d „ Z d
d
d „ Z d S( u JSONEncoderuZ Extensible JSON encoder for Python data structures.
Supports the following objects and types by default:
+-------------------+---------------+
| Python | JSON |
+===================+===============+
| dict | object |
+-------------------+---------------+
| list, tuple | array |
+-------------------+---------------+
| str | string |
+-------------------+---------------+
| int, float | number |
+-------------------+---------------+
| True | true |
+-------------------+---------------+
| False | false |
+-------------------+---------------+
| None | null |
+-------------------+---------------+
To extend this to recognize other objects, subclass and implement a
``.default()`` method with another method that returns a serializable
object for ``o`` if possible, otherwise it should call the superclass
implementation (to raise ``TypeError``).
u , u : c C ss | | _ | | _ | | _ | | _ | | _ | | _ | d k rW | \ | _ | _ n | d k ro | | _ n d S( uH Constructor for JSONEncoder, with sensible defaults.
If skipkeys is false, then it is a TypeError to attempt
encoding of keys that are not str, int, float or None. If
skipkeys is True, such items are simply skipped.
If ensure_ascii is true, the output is guaranteed to be str
objects with all incoming non-ASCII characters escaped. If
ensure_ascii is false, the output can contain non-ASCII characters.
If check_circular is true, then lists, dicts, and custom encoded
objects will be checked for circular references during encoding to
prevent an infinite recursion (which would cause an OverflowError).
Otherwise, no such check takes place.
If allow_nan is true, then NaN, Infinity, and -Infinity will be
encoded as such. This behavior is not JSON specification compliant,
but is consistent with most JavaScript based encoders and decoders.
Otherwise, it will be a ValueError to encode such floats.
If sort_keys is true, then the output of dictionaries will be
sorted by key; this is useful for regression tests to ensure
that JSON serializations can be compared on a day-to-day basis.
If indent is a non-negative integer, then JSON array
elements and object members will be pretty-printed with that
indent level. An indent level of 0 will only insert newlines.
None is the most compact representation. Since the default
item separator is ', ', the output might include trailing
whitespace when indent is specified. You can use
separators=(',', ': ') to avoid this.
If specified, separators should be a (item_separator, key_separator)
tuple. The default is (', ', ': '). To get the most compact JSON
representation you should specify (',', ':') to eliminate whitespace.
If specified, default is a function that gets called for objects
that can't otherwise be serialized. It should return a JSON encodable
version of the object or raise a ``TypeError``.
N(
u skipkeysu ensure_asciiu check_circularu allow_nanu sort_keysu indentu Noneu item_separatoru
key_separatoru default( u selfu skipkeysu ensure_asciiu check_circularu allow_nanu sort_keysu indentu
separatorsu default( ( u1 /opt/alt/python33/lib64/python3.3/json/encoder.pyu __init__b s - u JSONEncoder.__init__c C s t t | ƒ d ƒ ‚ d S( ul Implement this method in a subclass such that it returns
a serializable object for ``o``, or calls the base implementation
(to raise a ``TypeError``).
For example, to support arbitrary iterators, you could
implement default like this::
def default(self, o):
try:
iterable = iter(o)
except TypeError:
pass
else:
return list(iterable)
# Let the base class default method raise the TypeError
return JSONEncoder.default(self, o)
u is not JSON serializableN( u TypeErroru repr( u selfu o( ( u1 /opt/alt/python33/lib64/python3.3/json/encoder.pyu defaultš s u JSONEncoder.defaultc C su t | t ƒ r/ | j r" t | ƒ St | ƒ Sn | j | d d ƒ} t | t t f ƒ sh t | ƒ } n d j | ƒ S( u¦ Return a JSON string representation of a Python data structure.
>>> JSONEncoder().encode({"foo": ["bar", "baz"]})
'{"foo": ["bar", "baz"]}'
u _one_shotu T(
u
isinstanceu stru ensure_asciiu encode_basestring_asciiu encode_basestringu
iterencodeu Trueu listu tupleu join( u selfu ou chunks( ( u1 /opt/alt/python33/lib64/python3.3/json/encoder.pyu encode¯ s
u JSONEncoder.encodec
C sï | j r i } n d } | j r* t } n t } | j t t t d d „ } | r© t d k r© | j d k r© t | | j
| | j | j | j | j
| j | j ƒ } n9 t | | j
| | j | | j | j | j
| j | ƒ
} | | d ƒ S( uØ Encode the given object and yield each string
representation as available.
For example::
for chunk in JSONEncoder().iterencode(bigobject):
mysocket.write(chunk)
c S sl | | k r d } n4 | | k r* d } n | | k r? d } n
| | ƒ S| sh t d t | ƒ ƒ ‚ n | S( Nu NaNu Infinityu -Infinityu2 Out of range float values are not JSON compliant: ( u
ValueErroru repr( u ou allow_nanu _repru _infu _neginfu text( ( u1 /opt/alt/python33/lib64/python3.3/json/encoder.pyu floatstr× s
u( JSONEncoder.iterencode..floatstri N( u check_circularu Noneu ensure_asciiu encode_basestring_asciiu encode_basestringu allow_nanu
FLOAT_REPRu INFINITYu c_make_encoderu indentu defaultu
key_separatoru item_separatoru sort_keysu skipkeysu _make_iterencode( u selfu ou _one_shotu markersu _encoderu floatstru _iterencode( ( u1 /opt/alt/python33/lib64/python3.3/json/encoder.pyu
iterencodeÄ s&