ó ÖÉÎSc @@sôdZddlmZddlZddlmZddlmZddlm Z m Z m Z m Z m Z mZd„Zeƒ\ZZdd lmZejd ƒZejd ƒZejd ƒZid d6dd6dd6dd6dd6dd6dd6Zx1edƒD]#Zejeeƒdefƒq Wx1ddgD]#Zeje eƒdefƒq=WeZee dƒd„Zed „Z ep”e Z!d!e"fd"„ƒYZ#d#e#fd$„ƒYZ$ee%e ee&e'e(e e)e*e+e,d%„ Z-dS(&sImplementation of JSONEncoder i(tabsolute_importN(t itemgetter(tDecimali(tutunichrt binary_typet string_typest integer_typestPY3cC@s=y$ddlm}|j|jfSWntk r8dSXdS(Ni(t _speedups(NN(tR tencode_basestring_asciit make_encodert ImportErrortNone(R ((s8/usr/lib/python2.7/vendor-packages/simplejson/encoder.pyt_import_speedupss  (tPosInfu[\x00-\x1f\\"\b\f\n\r\t

]s([\\"]|[^\ -~])s [\x80-\xff]s\\s\s\"t"s\bss\fs s\ns s\rs s\ts i s\u%04xi( i) cC@s|r*t|tƒr`|jdƒ}q`n6t|tƒr`tj|ƒdk r`|jdƒ}nd„}|tj||ƒ|S(s5Return a JSON representation of a Python string sutf-8cS@st|jdƒS(Ni(t ESCAPE_DCTtgroup(tmatch((s8/usr/lib/python2.7/vendor-packages/simplejson/encoder.pytreplace3sN( t isinstanceRtdecodetstrtHAS_UTF8tsearchRtESCAPEtsub(tst_PY3t_qR((s8/usr/lib/python2.7/vendor-packages/simplejson/encoder.pytencode_basestring)s$ cC@s‡|r*t|tƒr`|jdƒ}q`n6t|tƒr`tj|ƒdk r`|jdƒ}nd„}dttj||ƒƒdS(sAReturn an ASCII-only JSON representation of a Python string sutf-8cS@sŽ|jdƒ}y t|SWnltk r‰t|ƒ}|dkrNd|fS|d8}d|d?d@B}d|d@B}d||fSnXdS( Niis\u%04xiØi iÿiÜs \u%04x\u%04x(RRtKeyErrortord(RRtnts1ts2((s8/usr/lib/python2.7/vendor-packages/simplejson/encoder.pyRBs      RN( RRRRRRRt ESCAPE_ASCIIR(RRR((s8/usr/lib/python2.7/vendor-packages/simplejson/encoder.pytpy_encode_basestring_ascii8s$ t JSONEncodercB@steZdZdZdZeeeeeddddeeeedeedd„Zd„Z d„Z ed„Z RS( sZExtensible JSON encoder for Python data structures. Supports the following objects and types by default: +-------------------+---------------+ | Python | JSON | +===================+===============+ | dict, namedtuple | object | +-------------------+---------------+ | list, tuple | array | +-------------------+---------------+ | str, unicode | string | +-------------------+---------------+ | int, long, 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``). s, s: sutf-8cC@s||_||_||_||_||_| |_| |_| |_| |_||_ ||_ ||_ ||_ |dk ržt|tƒ rž|d}n||_|dk rÈ|\|_|_n|dk ràd|_n| dk rø| |_n||_dS(sConstructor for JSONEncoder, with sensible defaults. If skipkeys is false, then it is a TypeError to attempt encoding of keys that are not str, int, long, 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 unicode characters escaped. If ensure_ascii is false, the output will be unicode object. 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 string, then JSON array elements and object members will be pretty-printed with a newline followed by that string repeated for each level of nesting. ``None`` (the default) selects the most compact representation without any newlines. For backwards compatibility with versions of simplejson earlier than 2.1.0, an integer is also accepted and is converted to a string with that many spaces. If specified, separators should be an (item_separator, key_separator) tuple. The default is (', ', ': ') if *indent* is ``None`` and (',', ': ') otherwise. 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``. If encoding is not None, then all input strings will be transformed into unicode using that encoding prior to JSON-encoding. The default is UTF-8. If use_decimal is true (not the default), ``decimal.Decimal`` will be supported directly by the encoder. For the inverse, decode JSON with ``parse_float=decimal.Decimal``. If namedtuple_as_object is true (the default), objects with ``_asdict()`` methods will be encoded as JSON objects. If tuple_as_array is true (the default), tuple (and subclasses) will be encoded as JSON arrays. If bigint_as_string is true (not the default), ints 2**53 and higher or lower than -2**53 will be encoded as strings. This is to avoid the rounding that happens in Javascript otherwise. If int_as_string_bitcount is a positive number (n), then int of size greater than or equal to 2**n or lower than or equal to -2**n will be encoded as strings. If specified, item_sort_key is a callable used to sort the items in each dictionary. This is useful if you want to sort items other than in alphabetical order by key. If for_json is true (not the default), objects with a ``for_json()`` method will use the return value of that method for encoding as JSON instead of the object. If *ignore_nan* is true (default: ``False``), then out of range :class:`float` values (``nan``, ``inf``, ``-inf``) will be serialized as ``null`` in compliance with the ECMA-262 specification. If true, this will override *allow_nan*. t t,N(tskipkeyst ensure_asciitcheck_circulart allow_nant sort_keyst use_decimaltnamedtuple_as_objectttuple_as_arraytbigint_as_stringt item_sort_keytfor_jsont ignore_nantint_as_string_bitcountRRRtindenttitem_separatort key_separatortdefaulttencoding(tselfR+R,R-R.R/R8t separatorsR<R;R0R1R2R3R4R5R6R7((s8/usr/lib/python2.7/vendor-packages/simplejson/encoder.pyt__init__xs.T                    cC@stt|ƒdƒ‚dS(s$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) return JSONEncoder.default(self, o) s is not JSON serializableN(t TypeErrortrepr(R=to((s8/usr/lib/python2.7/vendor-packages/simplejson/encoder.pyR;äscC@sÕt|tƒrF|j}|dk rF|dk rF|j|ƒ}qFnt|tƒru|jrht|ƒSt|ƒSn|j |dt ƒ}t|t t fƒs®t |ƒ}n|jrÄdj |ƒSdj |ƒSdS(sÕReturn a JSON string representation of a Python data structure. >>> from simplejson import JSONEncoder >>> JSONEncoder().encode({"foo": ["bar", "baz"]}) '{"foo": ["bar", "baz"]}' sutf-8t _one_shotR uN(RRR<RRRR,R R t iterencodetTruetlistttupletjoin(R=RBt _encodingtchunks((s8/usr/lib/python2.7/vendor-packages/simplejson/encoder.pytencodeøs       c C@sª|jri}nd}|jr*t}nt}|jdkrT||jd„}n|j|jtt t d„}i}|j rˆdn|j }|r!t dk r!|j dkr!t ||j||j |j|j|j|j|j||j|j|j||j|j|j|jtƒ}nft||j||j ||j|j|j|j||j|j|j||j|j|jdtƒ}z||dƒSWd|jƒXdS(sØEncode the given object and yield each string representation as available. For example:: for chunk in JSONEncoder().iterencode(bigobject): mysocket.write(chunk) sutf-8cS@s+t|tƒr!|j|ƒ}n||ƒS(N(RRR(RBt _orig_encoderRI((s8/usr/lib/python2.7/vendor-packages/simplejson/encoder.pyt_encoder(scS@s{||krd}n4||kr*d}n||kr?d}n ||ƒS|rXd}n|swtdt|ƒƒ‚n|S(NtNaNtInfinitys -Infinitytnulls2Out of range float values are not JSON compliant: (t ValueErrorRA(RBR.R6t_reprt_inft_neginfttext((s8/usr/lib/python2.7/vendor-packages/simplejson/encoder.pytfloatstr-s        i5RiN(R-RR,R R R<R.R6t FLOAT_REPRRR3R7tc_make_encoderR8R;R:R9R/R+R0R1R2R4R5Rt_make_iterencodetclear( R=RBRCtmarkersRMRVtkey_memoR7t _iterencode((s8/usr/lib/python2.7/vendor-packages/simplejson/encoder.pyRDsB        N( t__name__t __module__t__doc__R9R:tFalseRERR?R;RKRD(((s8/usr/lib/python2.7/vendor-packages/simplejson/encoder.pyR(Xs    f  tJSONEncoderForHTMLcB@s#eZdZd„Zed„ZRS(s"An encoder that produces JSON safe to embed in HTML. To embed JSON content in, say, a script tag on a web page, the characters &, < and > should be escaped. They cannot be escaped with the usual entities (e.g. &) because they are not expanded within