U
      e;                  	   @   sR  d Z ddlmZ ddlZddlZddlZddlmZmZ ddl	m
Z
mZ dd Ze Zd	gZejejB ejB Zd
d Ze \ZZZeeedZedeZdddddddddZdZeedreZn
d*ddZedjfddZ ddeejd j!eej"e fd!d"Z#ep
e#Z$ed#eZ%d$Z&de%je&fd%d&Z'e%je&fd'd(Z(G d)d	 d	e)Z*dS )+zImplementation of JSONDecoder
    )absolute_importN   )PY3unichr)make_scannerJSONDecodeErrorc                  C   s.   zddl m}  | W S  tk
r(   Y d S X d S )Nr   
scanstring)Z	_speedupsr	   ImportErrorr    r   1lib/python3.8/site-packages/simplejson/decoder.py_import_c_scanstring
   s
    r   JSONDecoderc                  C   sB   t jdk r&dd} td| \}}ntd}td}||| fS )N)      Z 7FF80000000000007FF0000000000000hexz>ddnaninf)sysversion_infodecodestructZunpackfloat)Z_BYTESr   r   r   r   r   _floatconstants   s    

r   )z	-InfinityZInfinityNaNz(.*?)(["\\\x00-\x1f])"\/
	)r   r   r   bfnrtzutf-8get_int_max_str_digits  c                 C   s(   t | |kr td|t | f t| S )zBackport of the integer string length conversion limitation

        https://docs.python.org/3/library/stdtypes.html#int-max-str-digits
        zIExceeds the limit (%s) for integer string conversion: value has %s digits)len
ValueErrorint)sZINT_MAX_STR_DIGITSr   r   r   bounded_int4   s    r.   z^[0-9a-fA-F]{4}$c                 C   sj   d}| ||d  }||s,t || |d zt|d|d fW S  tk
rd   t || |d Y nX dS )z5Scan a four digit hex number from s[end:end + 4]
    zInvalid \uXXXX escape sequence   r      N)r   r,   r+   )r-   end_mmsgescr   r   r   scan_four_digit_hex>   s    r5   T c
                 C   s  |dkrt }g }
|
j}|d }|| |}|dkr<td| ||}| }| \}}|rx|spt|tspt||}|| |dkrqn(|dkr|rd}t|| |n
|| qz| | }W n  tk
r   td| |Y nX |dkr$z|| }W n& tk
r   d}t|| |Y nX |d7 }n|	| |d \}}|d	kr|d
@ dkr| ||d  dkr|	| |d \}}|d
@ dkrd|d d> |d B  }|}t	|}|| q||
|fS )a  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.Nr   zUnterminated string starting atr   r   zInvalid control character %r atuzInvalid \X escape sequence %ri  i   i   r   z\ui   i   
   )
DEFAULT_ENCODINGappendr   r1   groups
isinstanceZunicode
IndexErrorKeyErrorr   )r-   r1   encodingstrictZ_br2   Z_join_PY3Z_maxunicodeZ_scan_four_digit_hexZchunks_appendZbeginchunkZprev_endZcontent
terminatorr3   r4   charZuniZuni2Zend2r   r   r   py_scanstringJ   sr    
  
  





rF   z
[ \t\n\r]*z 	
c	                 C   s  | \}	}
|d kri }|j }g }|	|
|
d  }|dkr||kr\||	|
 }
|	|
|
d  }|dkr|d k	r||}||
d fS i }|d k	r||}||
d fS |dkrtd|	|
|
d7 }
t|	|
||\}}
|||}|	|
|
d  dkr||	|
 }
|	|
|
d  dkrtd|	|
|
d7 }
z:|	|
 |kr^|
d7 }
|	|
 |kr^||	|
d  }
W n tk
rv   Y nX ||	|
\}}
|||f z0|	|
 }||kr||	|
d  }
|	|
 }W n tk
r   d}Y nX |
d7 }
|dkrqn|dkrtd	|	|
d zJ|	|
 }||krZ|
d7 }
|	|
 }||krZ||	|
d  }
|	|
 }W n tk
rv   d}Y nX |
d7 }
|dkrtd
|	|
d q|d k	r||}||
fS t|}|d k	r||}||
fS )Nr   r   }z8Expecting property name enclosed in double quotes or '}':zExpecting ':' delimiterr6   ,zExpecting ',' delimiter or '}'z1Expecting property name enclosed in double quotes)
setdefaultr1   r   r	   r=   r:   dict)stater?   r@   	scan_onceobject_hookobject_pairs_hookmemo_w_wsr-   r1   Zmemo_getZpairsnextcharresultkeyvaluer   r   r   
JSONObject   s     







 

rW   c           
      C   sN  | \}}g }|||d  }||krF|||d   }|||d  }|dkrZ||d fS |dkrntd|||j}|||\}	}||	 |||d  }||kr|||d   }|||d  }|d7 }|dkrڐqFn|dkrtd||d z:|| |kr*|d7 }|| |kr*|||d   }W qt tk
rB   Y qtX qt||fS )Nr   ]r6   zExpecting value or ']'rI   zExpecting ',' delimiter or ']')r1   r   r:   r=   )
rL   rM   rQ   rR   r-   r1   valuesrS   rB   rV   r   r   r   	JSONArray   s<    rZ   c                   @   s<   e Zd ZdZdddZejefddZd	ejefd
dZ	dS )r   a3  Simple JSON <http://json.org> decoder

    Performs the following translations in decoding by default:

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

    When allow_nan=True, it also understands
    ``NaN``, ``Infinity``, and ``-Infinity`` as
    their corresponding ``float`` values, which is outside the JSON spec.

    NTFc	           	      C   sr   |dkrt }|| _|| _|| _|p$t| _|p.t| _|pB|r@tj	pBd| _
|| _t| _t| _t| _i | _t| | _dS )a	  
        *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`).

        *allow_nan*, if True (default false), will allow the parser to
        accept the non-standard floats ``NaN``, ``Infinity``, and ``-Infinity``.

        *parse_constant*, if specified, will be
        called with one of the following strings: ``'-Infinity'``,
        ``'Infinity'``, ``'NaN'``. It is not recommended to use this feature,
        as it is rare to parse non-compliant JSON containing these values.

        *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)r9   r?   rN   rO   r   parse_floatr.   	parse_int
_CONSTANTS__getitem__parse_constantr@   rW   Zparse_objectrZ   Zparse_arrayr	   Zparse_stringrP   r   rM   )	selfr?   rN   r[   r\   r_   r@   rO   Z	allow_nanr   r   r   __init__;  s    1

zJSONDecoder.__init__c                 C   sX   |rt |trt|| j}| |\}}||| }|t|krTtd||t||S )zzReturn the Python representation of ``s`` (a ``str`` or ``unicode``
        instance containing a JSON document)

        z
Extra data)r<   bytesstrr?   
raw_decoder1   r*   r   )r`   r-   rQ   rA   objr1   r   r   r   r   {  s    zJSONDecoder.decoder   c                 C   s   |dk rt d|||r*t|ts*tdt||krxt|| }|dkrT|d7 }n$|dkrx|||d  dkrx|d7 }| j|||| d	S )
a  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.
        Optionally, ``idx`` can be used to specify an offset in ``s`` where
        the JSON document begins.

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

        r   zExpecting valuez$Input string must be text, not bytesi  r         u   ï»¿)idx)r   r<   rc   	TypeErrorr*   ordrM   r1   )r`   r-   rh   rQ   rA   Zord0r   r   r   rd     s    
zJSONDecoder.raw_decode)NNNNNTNF)
__name__
__module____qualname____doc__ra   
WHITESPACEmatchr   r   rd   r   r   r   r   r     s            
@)r)   )+rn   Z
__future__r   rer   r   compatr   r   scannerr   r   r   Zc_scanstring__all__VERBOSE	MULTILINEDOTALLFLAGSr   r   ZPosInfZNegInfr]   compileZSTRINGCHUNKZ	BACKSLASHr9   hasattrr,   r.   rp   r5   join
maxunicoderF   r	   ro   ZWHITESPACE_STRrW   rZ   objectr   r   r   r   r   <module>   s`   	      


   
K
 
^$