ó
jš¤Mc           @   s   d  Z  d d l Z d d l Z d d l Z d d l m Z d „  Z e ƒ  Z d g Z e j	 e j
 Be j BZ d „  Z e ƒ  \ Z Z Z d e f d „  ƒ  YZ d	 „  Z d d
 „ Z i e d 6e d 6e d 6Z e j d e ƒ Z i d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6Z d Z d e e e j d  „ Z e pDe Z e j d! e ƒ Z d" Z  d e j e  d# „ Z! e j e  d$ „ Z" d e# f d% „  ƒ  YZ$ d S(&   s   Implementation of JSONDecoder
iÿÿÿÿN(   t   make_scannerc          C   s1   y d d l  m }  |  SWn t k
 r, d  SXd  S(   Niÿÿÿÿ(   t
   scanstring(   t   simplejson._speedupsR   t   ImportErrort   None(   R   (    (    s6   /usr/lib/python2.7/dist-packages/simplejson/decoder.pyt   _import_c_scanstring   s
    t   JSONDecoderc          C   ss   d j  d ƒ }  t j d k rM |  d  d  d  d … |  d d  d  d … }  n  t j d |  ƒ \ } } | | | f S(   Nt    7FF80000000000007FF0000000000000t   hext   bigi   iÿÿÿÿt   dd(   t   decodet   syst	   byteordert   structt   unpack(   t   _BYTESt   nant   inf(    (    s6   /usr/lib/python2.7/dist-packages/simplejson/decoder.pyt   _floatconstants   s
    /t   JSONDecodeErrorc           B   s   e  Z d  Z d d „ Z RS(   sØ  Subclass of ValueError with the following additional properties:

    msg: The unformatted error message
    doc: The JSON document being parsed
    pos: The start index of doc where parsing failed
    end: The end index of doc where parsing failed (may be None)
    lineno: The line corresponding to pos
    colno: The column corresponding to pos
    endlineno: The line corresponding to end (may be None)
    endcolno: The column corresponding to end (may be None)

    c         C   s¡   t  j |  t | | | d | ƒƒ | |  _ | |  _ | |  _ | |  _ t | | ƒ \ |  _ |  _	 | d  k	 r‹ t | | ƒ \ |  _ |  _ n d \ |  _ |  _ d  S(   Nt   end(   NN(   t
   ValueErrort   __init__t   errmsgt   msgt   doct   posR   t   linecolt   linenot   colnoR   t	   endlinenot   endcolno(   t   selfR   R   R   R   (    (    s6   /usr/lib/python2.7/dist-packages/simplejson/decoder.pyR   -   s    "				N(   t   __name__t
   __module__t   __doc__R   R   (    (    (    s6   /usr/lib/python2.7/dist-packages/simplejson/decoder.pyR       s   c         C   sQ   |  j  d d | ƒ d } | d k r. | } n | |  j d d | ƒ } | | f S(   Ns   
i    i   (   t   countt   rindex(   R   R   R   R   (    (    s6   /usr/lib/python2.7/dist-packages/simplejson/decoder.pyR   :   s
    	c   	      C   ss   t  | | ƒ \ } } | d  k r; d } | |  | | | f St  | | ƒ \ } } d } | |  | | | | | | f S(   Ns   %s: line %d column %d (char %d)s8   %s: line %d column %d - line %d column %d (char %d - %d)(   R   R   (	   R   R   R   R   R   R   t   fmtR   R    (    (    s6   /usr/lib/python2.7/dist-packages/simplejson/decoder.pyR   C   s    s	   -Infinityt   Infinityt   NaNs   (.*?)(["\\\x00-\x1f])u   "t   "u   \s   \u   /t   /u   t   bu   t   fu   
t   nu   t   ru   	t   ts   utf-8c         C   sø  | d k r t } n  g  } | j } | d } x´| |  | ƒ }	 |	 d k ra t d |  | ƒ ‚ n  |	 j ƒ  } |	 j ƒ  \ }
 } |
 r³ t |
 t ƒ s¦ t |
 | ƒ }
 n  | |
 ƒ n  | d k rÃ PnD | d k r| r÷ d | f } t | |  | ƒ ‚ q| | ƒ q1 n  y |  | } Wn# t k
 r:t d |  | ƒ ‚ n X| d k r˜y | | } Wn3 t	 k
 rŠd t
 | ƒ } t | |  | ƒ ‚ n X| d 7} n@|  | d | d !} | d } t | ƒ d	 k räd
 } t | |  | ƒ ‚ n  t | d ƒ } d | k o
d k n rÆt j d k rÆd } |  | d | d !d k sTt | |  | ƒ ‚ n  |  | d | d !} t | ƒ d	 k rt | |  | ƒ ‚ n  t | d ƒ } d | d d >| d B} | d 7} n  t | ƒ } | } | | ƒ q1 d j | ƒ | f S(   s®  Scan the string s for a JSON string. End is the index of the
    character in s after the quote that started the JSON string.
    Unescapes all valid JSON string escape sequences and raises ValueError
    on attempt to decode an invalid string. If strict is False then literal
    control characters are allowed in the string.

    Returns a tuple of the decoded string and the index of the character in s
    after the end quote.i   s   Unterminated string starting atR*   s   \s   Invalid control character %r att   us   Invalid \escape: i   i   s   Invalid \uXXXX escapei   i Ø  iÿÛ  iÿÿ  s#   Invalid \uXXXX\uXXXX surrogate pairi   s   \ui   i   i
   i Ü  i   u    N(   R   t   DEFAULT_ENCODINGt   appendR   R   t   groupst
   isinstancet   unicodet
   IndexErrort   KeyErrort   reprt   lent   intR   t
   maxunicodet   unichrt   join(   t   sR   t   encodingt   strictt   _bt   _mt   chunkst   _appendt   begint   chunkt   contentt
   terminatorR   t   esct   chart   next_endt   unit   esc2t   uni2(    (    s6   /usr/lib/python2.7/dist-packages/simplejson/decoder.pyt   py_scanstring`   sp    
		


+s
   [ \t\n\r]*s    	
c	         C   sø  |  \ }	 }
 | d  k r! i  } n  | j } g  } |	 |
 |
 d !} | d k r| | k r‚ | |	 |
 ƒ j ƒ  }
 |	 |
 |
 d !} n  | d k rã | d  k	 r´ | | ƒ } | |
 d f Si  } | d  k	 rÕ | | ƒ } n  | |
 d f S| d k rt d |	 |
 ƒ ‚ qn  |
 d 7}
 x‘t r¤t |	 |
 | | ƒ \ } }
 | | | ƒ } |	 |
 |
 d !d k rŸ| |	 |
 ƒ j ƒ  }
 |	 |
 |
 d !d k rŸt d |	 |
 ƒ ‚ qŸn  |
 d 7}
 yM |	 |
 | k rõ|
 d 7}
 |	 |
 | k rõ| |	 |
 d ƒ j ƒ  }
 qõn  Wn t k
 r	n Xy | |	 |
 ƒ \ } }
 Wn# t k
 rHt d |	 |
 ƒ ‚ n X| j | | f ƒ y@ |	 |
 } | | k r›| |	 |
 d ƒ j ƒ  }
 |	 |
 } n  Wn t k
 rµd } n X|
 d 7}
 | d k rÐPn% | d	 k rõt d
 |	 |
 d ƒ ‚ n  yc |	 |
 } | | k rW|
 d 7}
 |	 |
 } | | k rW| |	 |
 d ƒ j ƒ  }
 |	 |
 } qWn  Wn t k
 rqd } n X|
 d 7}
 | d k rt d |	 |
 d ƒ ‚ qqW| d  k	 rÇ| | ƒ } | |
 f St	 | ƒ } | d  k	 rî| | ƒ } n  | |
 f S(   Ni   R*   t   }s   Expecting property namet   :s   Expecting : delimiters   Expecting objectt    t   ,s   Expecting , delimiter(
   R   t
   setdefaultR   R   t   TrueR   R7   t   StopIterationR3   t   dict(   t   .0R@   RA   t	   scan_oncet   object_hookt   object_pairs_hookt   memot   _wt   _wsR?   R   t   memo_gett   pairst   nextchart   resultt   keyt   value(    (    s6   /usr/lib/python2.7/dist-packages/simplejson/decoder.pyt
   JSONObject´   s’    			
	

#








c   
      C   sÅ  |  \ } } g  } | | | d !} | | k r\ | | | d ƒ j  ƒ  } | | | d !} n  | d k rv | | d f S| j } x9t rºy | | | ƒ \ }	 } Wn# t k
 rÆ t d | | ƒ ‚ n X| |	 ƒ | | | d !} | | k r| | | d ƒ j  ƒ  } | | | d !} n  | d 7} | d k r5Pn! | d k rVt d | | ƒ ‚ n  yM | | | k r¢| d 7} | | | k r¢| | | d ƒ j  ƒ  } q¢n  Wq‚ t k
 r¶q‚ Xq‚ W| | f S(   Ni   t   ]s   Expecting objectRT   s   Expecting , delimiter(   R   R3   RV   RW   R   R7   (
   RY   RZ   R^   R_   R?   R   t   valuesRb   RE   Re   (    (    s6   /usr/lib/python2.7/dist-packages/simplejson/decoder.pyt	   JSONArray  s@    			


#c           B   sG   e  Z d  Z d d d d d e d d „ Z e j d „ Z d d „ Z	 RS(   s  Simple JSON <http://json.org> decoder

    Performs the following translations in decoding by default:

    +---------------+-------------------+
    | JSON          | Python            |
    +===============+===================+
    | object        | dict              |
    +---------------+-------------------+
    | array         | list              |
    +---------------+-------------------+
    | string        | unicode           |
    +---------------+-------------------+
    | number (int)  | int, long         |
    +---------------+-------------------+
    | number (real) | float             |
    +---------------+-------------------+
    | true          | True              |
    +---------------+-------------------+
    | false         | False             |
    +---------------+-------------------+
    | null          | None              |
    +---------------+-------------------+

    It also understands ``NaN``, ``Infinity``, and ``-Infinity`` as
    their corresponding ``float`` values, which is outside the JSON spec.

    c         C   s‹   | |  _  | |  _ | |  _ | p$ t |  _ | p3 t |  _ | pE t j |  _	 | |  _
 t |  _ t |  _ t |  _ i  |  _ t |  ƒ |  _ d S(   s	  
        *encoding* determines the encoding used to interpret any
        :class:`str` objects decoded by this instance (``'utf-8'`` by
        default).  It has no effect when decoding :class:`unicode` objects.

        Note that currently only encodings that are a superset of ASCII work,
        strings of other encodings should be passed in as :class:`unicode`.

        *object_hook*, if specified, will be called with the result of every
        JSON object decoded and its return value will be used in place of the
        given :class:`dict`.  This can be used to provide custom
        deserializations (e.g. to support JSON-RPC class hinting).

        *object_pairs_hook* is an optional function that will be called with
        the result of any object literal decode with an ordered list of pairs.
        The return value of *object_pairs_hook* will be used instead of the
        :class:`dict`.  This feature can be used to implement custom decoders
        that rely on the order that the key and value pairs are decoded (for
        example, :func:`collections.OrderedDict` will remember the order of
        insertion). If *object_hook* is also defined, the *object_pairs_hook*
        takes priority.

        *parse_float*, if specified, will be called with the string of every
        JSON float to be decoded.  By default, this is equivalent to
        ``float(num_str)``. This can be used to use another datatype or parser
        for JSON floats (e.g. :class:`decimal.Decimal`).

        *parse_int*, if specified, will be called with the string of every
        JSON int to be decoded.  By default, this is equivalent to
        ``int(num_str)``.  This can be used to use another datatype or parser
        for JSON integers (e.g. :class:`float`).

        *parse_constant*, if specified, will be called with one of the
        following strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``.  This
        can be used to raise an exception if invalid JSON numbers are
        encountered.

        *strict* controls the parser's behavior when it encounters an
        invalid control character in a string. The default setting of
        ``True`` means that unescaped control characters are parse errors, if
        ``False`` then control characters will be allowed in strings.

        N(   R@   R[   R\   t   floatt   parse_floatR;   t	   parse_intt
   _CONSTANTSt   __getitem__t   parse_constantRA   Rf   t   parse_objectRi   t   parse_arrayR   t   parse_stringR]   R    RZ   (   R!   R@   R[   Rk   Rl   Ro   RA   R\   (    (    s6   /usr/lib/python2.7/dist-packages/simplejson/decoder.pyR   R  s    .								c         C   ss   |  j  | d | | d ƒ j ƒ  ƒ\ } } | | | ƒ j ƒ  } | t | ƒ k ro t d | | t | ƒ ƒ ‚ n  | S(   sz   Return the Python representation of ``s`` (a ``str`` or ``unicode``
        instance containing a JSON document)

        t   idxi    s
   Extra data(   t
   raw_decodeR   R:   R   (   R!   R?   R^   t   objR   (    (    s6   /usr/lib/python2.7/dist-packages/simplejson/decoder.pyR     s
    *i    c         C   sL   y |  j  | | ƒ \ } } Wn# t k
 rA t d | | ƒ ‚ n X| | f S(   sL  Decode a JSON document from ``s`` (a ``str`` or ``unicode``
        beginning with a JSON document) and return a 2-tuple of the Python
        representation and the index in ``s`` where the document ended.

        This can be used to decode a JSON document from a string that may
        have extraneous data at the end.

        s   No JSON object could be decoded(   RZ   RW   R   (   R!   R?   Rs   Ru   R   (    (    s6   /usr/lib/python2.7/dist-packages/simplejson/decoder.pyRt   ˜  s
    	N(
   R"   R#   R$   R   RV   R   t
   WHITESPACEt   matchR   Rt   (    (    (    s6   /usr/lib/python2.7/dist-packages/simplejson/decoder.pyR   4  s   		9(%   R$   t   reR   R   t   simplejson.scannerR    R   t   c_scanstringt   __all__t   VERBOSEt	   MULTILINEt   DOTALLt   FLAGSR   R)   t   PosInft   NegInfR   R   R   R   R   Rm   t   compilet   STRINGCHUNKt	   BACKSLASHR2   RV   Rw   RP   R   Rv   t   WHITESPACE_STRRf   Ri   t   objectR   (    (    (    s6   /usr/lib/python2.7/dist-packages/simplejson/decoder.pyt   <module>   s>   							
&NZ$