ó
è¾bc           @   s  d  Z  d d l Z y d d l m Z Wn e k
 r? d Z n Xy d d l m Z Wn e k
 rm d Z n 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 j Z d „  Z d „  Z e p8e Z d e f d „  ƒ  YZ e e e e e e e  e! e" e# e$ d „ Z% d S(   s   Implementation of JSONEncoder
iÿÿÿÿN(   t   encode_basestring_ascii(   t   make_encoders   [\x00-\x1f\\"\b\f\n\r\t]s   ([\\"]|[^\ -~])s   [\x80-\xff]s   \\s   \s   \"t   "s   \bs   s   \fs   s   \ns   
s   \rs   s   \ts   	i    s	   \u{0:04x}t   infc         C   s!   d „  } d t  j | |  ƒ d S(   s5   Return a JSON representation of a Python string

    c         S   s   t  |  j d ƒ S(   Ni    (   t
   ESCAPE_DCTt   group(   t   match(    (    s"   /usr/lib/python2.7/json/encoder.pyt   replace%   s    R   (   t   ESCAPEt   sub(   t   sR   (    (    s"   /usr/lib/python2.7/json/encoder.pyt   encode_basestring!   s    	c         C   s]   t  |  t ƒ r6 t j |  ƒ d k	 r6 |  j d ƒ }  n  d „  } d t t j | |  ƒ ƒ d S(   sA   Return an ASCII-only JSON representation of a Python string

    s   utf-8c         S   s’   |  j  d ƒ } y t | SWnp t k
 r t | ƒ } | d k  rP d j | ƒ S| d 8} d | d ?d @B} d | d @B} d j | | ƒ Sn Xd  S(	   Ni    i   s	   \u{0:04x}i Ø  i
   iÿ  i Ü  s   \u{0:04x}\u{1:04x}(   R   R   t   KeyErrort   ordt   format(   R   R
   t   nt   s1t   s2(    (    s"   /usr/lib/python2.7/json/encoder.pyR   0   s    
R   N(   t
   isinstancet   strt   HAS_UTF8t   searcht   Nonet   decodet   ESCAPE_ASCIIR	   (   R
   R   (    (    s"   /usr/lib/python2.7/json/encoder.pyt   py_encode_basestring_ascii*   s    $	t   JSONEncoderc        
   B   s\   e  Z d  Z d Z d Z e e e e e d d d d d „	 Z d „  Z	 d „  Z
 e d „ Z RS(	   sZ  Extensible JSON <http://json.org> encoder for Python data structures.

    Supports the following objects and types by default:

    +-------------------+---------------+
    | Python            | JSON          |
    +===================+===============+
    | dict              | 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   : s   utf-8c
   
      C   s|   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | d k	 rW | \ |  _ |  _ n  |	 d k	 ro |	 |  _	 n  | |  _
 d S(   s°	  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, long, float or None.  If
        skipkeys is True, such items are simply skipped.

        If *ensure_ascii* is true (the default), all non-ASCII
        characters in the output are escaped with \uXXXX sequences,
        and the results are str instances consisting of ASCII
        characters only.  If ensure_ascii is False, a result may be a
        unicode instance.  This usually happens if the input contains
        unicode strings or the *encoding* parameter is used.

        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``.

        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.

        N(   t   skipkeyst   ensure_asciit   check_circulart	   allow_nant	   sort_keyst   indentR   t   item_separatort   key_separatort   defaultt   encoding(
   t   selfR   R   R   R   R   R    t
   separatorsR$   R#   (    (    s"   /usr/lib/python2.7/json/encoder.pyt   __init__e   s    4						c         C   s   t  t | ƒ d ƒ ‚ d S(   sl  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)

        s    is not JSON serializableN(   t	   TypeErrort   repr(   R%   t   o(    (    s"   /usr/lib/python2.7/json/encoder.pyR#   ¥   s    c         C   s»   t  | t ƒ ru t  | t ƒ rU |  j } | d k	 rU | d k rU | j | ƒ } qU n  |  j rh t | ƒ St | ƒ Sn  |  j	 | d t
 ƒ} t  | t t f ƒ s® t | ƒ } n  d j | ƒ S(   s¦   Return a JSON string representation of a Python data structure.

        >>> JSONEncoder().encode({"foo": ["bar", "baz"]})
        '{"foo": ["bar", "baz"]}'

        s   utf-8t	   _one_shott    N(   R   t
   basestringR   R$   R   R   R   R    R   t
   iterencodet   Truet   listt   tuplet   join(   R%   R*   t	   _encodingt   chunks(    (    s"   /usr/lib/python2.7/json/encoder.pyt   encodeº   s    		
c         C   s  |  j  r i  } n d } |  j r* t } n t } |  j d k rT | |  j d „ } n  |  j t t t d „ } | rÔ t	 d k	 rÔ |  j
 d k rÔ |  j rÔ t	 | |  j | |  j
 |  j |  j |  j |  j |  j ƒ	 } n9 t | |  j | |  j
 | |  j |  j |  j |  j | ƒ
 } | | d ƒ S(   sØ   Encode the given object and yield each string
        representation as available.

        For example::

            for chunk in JSONEncoder().iterencode(bigobject):
                mysocket.write(chunk)

        s   utf-8c         S   s+   t  |  t ƒ r! |  j | ƒ }  n  | |  ƒ S(   N(   R   R   R   (   R*   t   _orig_encoderR3   (    (    s"   /usr/lib/python2.7/json/encoder.pyt   _encoderç   s    c         S   sl   |  |  k r d } n4 |  | k r* d } n |  | k r? d } n
 | |  ƒ S| sh t  d t |  ƒ ƒ ‚ n  | S(   Nt   NaNt   Infinitys	   -Infinitys2   Out of range float values are not JSON compliant: (   t
   ValueErrorR)   (   R*   R   t   _reprt   _inft   _neginft   text(    (    s"   /usr/lib/python2.7/json/encoder.pyt   floatstrì   s    			
i    N(   R   R   R   R    R   R$   R   t
   FLOAT_REPRt   INFINITYt   c_make_encoderR    R   R#   R"   R!   R   t   _make_iterencode(   R%   R*   R+   t   markersR7   R?   t   _iterencode(    (    s"   /usr/lib/python2.7/json/encoder.pyR.   Ô   s*    
				N(   t   __name__t
   __module__t   __doc__R!   R"   t   FalseR/   R   R'   R#   R5   R.   (    (    (    s"   /usr/lib/python2.7/json/encoder.pyR   F   s   	>		c            sÙ   ‡  ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ f d †  ‰ ‡  ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡	 ‡
 ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ f d †  ‰ ‡  ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ f d †  ‰ ˆ S(   Nc   
      3   s8  |  s d Vd  Sˆ d  k	 rO ˆ |  ƒ } | ˆ k rB ˆ  d ƒ ‚ n  |  ˆ | <n  d } ˆ d  k	 r” | d 7} d d ˆ | } ˆ | } | | 7} n d  } ˆ } t } xF|  D]>} | rÂ t } n | } ˆ | ˆ ƒ ré | ˆ | ƒ Vq­ | d  k r| d Vq­ | t k r| d Vq­ | t k r1| d	 Vq­ ˆ | ˆ ˆ f ƒ rX| ˆ | ƒ Vq­ ˆ | ˆ
 ƒ ry| ˆ | ƒ Vq­ | Vˆ | ˆ ˆ f ƒ r¥ˆ | | ƒ } n0 ˆ | ˆ	 ƒ rÆˆ | | ƒ } n ˆ | | ƒ } x | D] }	 |	 VqÜWq­ W| d  k	 r| d 8} d d ˆ | Vn  d
 Vˆ d  k	 r4ˆ | =n  d  S(   Ns   []s   Circular reference detectedt   [i   s   
t    t   nullt   truet   falset   ](   R   R/   RI   (
   t   lstt   _current_indent_levelt   markeridt   buft   newline_indentt	   separatort   firstt   valueR4   t   chunk(   R:   R7   t	   _floatstrt   _indentt   _item_separatorRE   t   _iterencode_dictt   _iterencode_listR-   t   dictt   floatt   idt   intR   R0   t   longRD   R   R1   (    s"   /usr/lib/python2.7/json/encoder.pyR]      s^    

	
c         3   s  |  s d Vd  Sˆ d  k	 rO ˆ |  ƒ } | ˆ k rB ˆ  d ƒ ‚ n  |  ˆ | <n  d Vˆ d  k	 rŽ | d 7} d d ˆ | } ˆ | } | Vn d  } ˆ } t } ˆ
 rÄ t |  j ƒ  d d „  ƒ} n |  j ƒ  } x÷| D]ï\ } } ˆ | ˆ ƒ rõ n§ ˆ | ˆ ƒ rˆ | ƒ } n‰ | t k r(d	 } nt | t k r=d
 } n_ | d  k rRd } nJ ˆ | ˆ ˆ f ƒ rvˆ | ƒ } n& ˆ	 r‚q× n t d t | ƒ d ƒ ‚ | r«t } n | Vˆ | ƒ Vˆ Vˆ | ˆ ƒ rÝˆ | ƒ Vq× | d  k rñd Vq× | t k rd	 Vq× | t k rd
 Vq× ˆ | ˆ ˆ f ƒ r<ˆ | ƒ Vq× ˆ | ˆ ƒ rYˆ | ƒ Vq× ˆ | ˆ ˆ f ƒ r€ˆ | | ƒ }	 n0 ˆ | ˆ ƒ r¡ˆ | | ƒ }	 n ˆ | | ƒ }	 x |	 D] }
 |
 Vq·Wq× W| d  k	 rô| d 8} d d ˆ | Vn  d Vˆ d  k	 rˆ | =n  d  S(   Ns   {}s   Circular reference detectedt   {i   s   
RK   t   keyc         S   s   |  d S(   Ni    (    (   t   kv(    (    s"   /usr/lib/python2.7/json/encoder.pyt   <lambda>i  R,   RM   RN   RL   s   key s    is not a stringt   }(   R   R/   t   sortedt   itemst	   iteritemsRI   R(   R)   (   t   dctRQ   RR   RT   R!   RV   Ri   Rd   RW   R4   RX   (   R:   R7   RY   RZ   R[   RE   R\   R]   t   _key_separatort	   _skipkeyst
   _sort_keysR-   R^   R_   R`   Ra   R   R0   Rb   RD   R   R1   (    s"   /usr/lib/python2.7/json/encoder.pyR\   U  s„    

				
c         3   s†  ˆ |  ˆ ƒ r ˆ |  ƒ Vne|  d  k r1 d VnQ|  t k rE d Vn=|  t k rY d Vn)ˆ |  ˆ ˆ f ƒ r| ˆ |  ƒ Vnˆ |  ˆ	 ƒ r™ ˆ |  ƒ Vné ˆ |  ˆ ˆ f ƒ rÐ xÑ ˆ |  | ƒ D] } | Vq¾ Wn² ˆ |  ˆ ƒ rx  ˆ |  | ƒ D] } | Vqï Wn ˆ d  k	 rAˆ
 |  ƒ } | ˆ k r4ˆ  d ƒ ‚ n  |  ˆ | <n  ˆ |  ƒ }  x ˆ |  | ƒ D] } | Vq]Wˆ d  k	 r‚ˆ | =n  d  S(   NRL   RM   RN   s   Circular reference detected(   R   R/   RI   (   R*   RQ   RX   RR   (   R:   t   _defaultR7   RY   RE   R\   R]   R-   R^   R_   R`   Ra   R   R0   Rb   RD   R   R1   (    s"   /usr/lib/python2.7/json/encoder.pyRE   ¡  s8    	(    (   RD   Ro   R7   RZ   RY   Rl   R[   Rn   Rm   R+   R:   R-   R^   R_   R`   Ra   R   R0   Rb   R   R1   (    (   R:   Ro   R7   RY   RZ   R[   RE   R\   R]   Rl   Rm   Rn   R-   R^   R_   R`   Ra   R   R0   Rb   RD   R   R1   s"   /usr/lib/python2.7/json/encoder.pyRC     s    E5NLB(&   RH   t   ret   _jsonR    t   c_encode_basestring_asciit   ImportErrorR   R   RB   t   compileR   R   R   R   t   ranget   it
   setdefaultt   chrR   R_   RA   t   __repr__R@   R   R   t   objectR   R:   R-   R^   R`   Ra   R   R0   Rb   R   R1   RC   (    (    (    s"   /usr/lib/python2.7/json/encoder.pyt   <module>   sN   


#				Í