e f1 @sdZddlZddlmZyddlmZWnek rPdZYnXdgZej ej Bej BZ e dZe dZe dZd d Zdd d Zied 6ed6ed6Zejde Zidd6dd6dd6dd6dd6dd6dd6dd6ZddZd eejd!d"ZepHeZejd#e Zd$Zdejed%d&Zejed'd(ZGd)ddeZdS)*zImplementation of JSONDecoder N)scanner) scanstring JSONDecodernaninfz-infcCsst|trd}nd}|j|d|d}|dkrP|d}n||j|d|}||fS)Ns  r) isinstancebytescountrindex)docposnewlinelinenocolnor1/opt/alt/python34/lib64/python3.4/json/decoder.pylinecols   rc Cswt||\}}|dkr=d}|j||||St||\}}d}|j|||||||S)Nz#{0}: line {1} column {2} (char {3})z?{0}: line {1} column {2} - line {3} column {4} (char {5} - {6}))rformat) msgr rendrrZfmtZ endlinenoZendcolnorrrerrmsg!s rz -InfinityZInfinityNaNz(.*?)(["\\\x00-\x1f])"\/b frn r tc Cs||d|d}t|dkrc|ddkrcyt|dSWqctk r_YqcXnd}tt|||dS)NrZxXzInvalid \uXXXX escape)lenint ValueErrorr)srescrrrr _decode_uXXXX=s" r.TcCsRg}|j}|d}x#|||}|dkrRttd||n|j}|j\} } | r|| n| dkrPnL| dkr|rdj| } tt| ||q|| qny||} Wn*tk rttd||YnX| dkr}y|| } Wn9tk rodj| } tt| ||YnX|d7}nt||}|d 7}d |kod knr%|||d d kr%t||d}d|kodknr%d|d d>|dB}|d7}q%nt |} || qWdj ||fS)aScan 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.rNzUnterminated string starting atrrz"Invalid control character {0!r} atuzInvalid \escape: {0!r}r&iiz\uiii ) appendr+rrgroupsr IndexErrorKeyErrorr.chrjoin)r,rstrictZ_bZ_mZchunks_appendZbeginchunkZcontentZ terminatorrr-charZuniZuni2rrr py_scanstringGsT              6 r>z [ \t\n\r]*z c$Cs|\}} g} | j} |dkr0i}n|j} || | d} | dkr| |kr||| j} || | d} n| dkr|dk r|| }|| dfSi} |dk r|| } n| | dfS| dkrttd|| qn| d7} xkt|| |\}} | ||}|| | ddkr||| j} || | ddkrttd|| qn| d7} yM|| |kr | d7} || |kr ||| dj} q nWntk r"YnXy||| \}} WnCtk r}z#ttd||jdWYdd}~XnX| ||fy@|| } | |kr||| dj} || } nWntk rd} YnX| d7} | dkrPn+| d kr2ttd || dn||| j} || | d} | d7} | dkr)ttd|| dq)q)W|dk r|| }|| fSt | } |dk r|| } n| | fS) Nrr}z1Expecting property name enclosed in double quotes:zExpecting ':' delimiterzExpecting valuer3,zExpecting ',' delimiter) r4 setdefaultrr+rrr6 StopIterationvaluedict) s_and_endr: scan_once object_hookobject_pairs_hookmemo_w_wsr,rZpairsZ pairs_appendZmemo_getnextcharresultkeyrDerrrrr JSONObjects               # 1              rQc Cs|\}}g}|||d}||krb|||dj}|||d}n|dkr|||dfS|j}xdy|||\} }WnCtk r} z#ttd|| jdWYdd} ~ XnX|| |||d}||krA|||dj}|||d}n|d7}|dkr[Pn+|dkrttd||dnyM|||kr|d7}|||kr|||dj}qnWqtk rYqXqW||fS)Nr]zExpecting valuerAzExpecting ',' delimiter)rr4rCr+rrDr6) rFrGrKrLr,rvaluesrMr;rDrPrrr JSONArrays@    1      #  rTc@sUeZdZdZddddddddZejddZdd d ZdS) raSimple JSON decoder Performs the following translations in decoding by default: +---------------+-------------------+ | JSON | Python | +===============+===================+ | object | dict | +---------------+-------------------+ | array | list | +---------------+-------------------+ | string | str | +---------------+-------------------+ | number (int) | int | +---------------+-------------------+ | 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. NTcCs||_|pt|_|p!t|_|p3tj|_||_||_ t |_ t |_ t|_i|_tj||_dS)aD``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 ``dict``. This can be used to provide custom deserializations (e.g. to support JSON-RPC class hinting). ``object_pairs_hook``, if specified will be called with the result of every JSON object decoded with an ordered list of pairs. The return value of ``object_pairs_hook`` will be used instead of the ``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, 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. 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. 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. If ``strict`` is false (true is the default), then control characters will be allowed inside strings. Control characters in this context are those with character codes in the 0-31 range, including ``'\t'`` (tab), ``'\n'``, ``'\r'`` and ``'\0'``. N)rHfloat parse_floatr* parse_int _CONSTANTS __getitem__parse_constantr:rIrQZ parse_objectrTZ parse_arrayrZ parse_stringrJrZ make_scannerrG)selfrHrVrWrZr:rIrrr__init__s&       zJSONDecoder.__init__cCsy|j|d||dj\}}|||j}|t|kruttd||t|n|S)zlReturn the Python representation of ``s`` (a ``str`` instance containing a JSON document). idxrz Extra data) raw_decoderr)r+r)r[r,rKobjrrrrdecodeRs *$zJSONDecoder.decodercCsly|j||\}}WnCtk ra}z#ttd||jdWYdd}~XnX||fS)a=Decode a JSON document from ``s`` (a ``str`` 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. zExpecting valueN)rGrCr+rrD)r[r,r]r_rrPrrrr^]s 1zJSONDecoder.raw_decode) __name__ __module__ __qualname____doc__r\ WHITESPACEmatchr`r^rrrrrs  1 ) rdreZjsonrZ_jsonrZ c_scanstring ImportError__all__VERBOSE MULTILINEDOTALLFLAGSrUrZPosInfZNegInfrrrXcompileZ STRINGCHUNKZ BACKSLASHr.rfr>reZWHITESPACE_STRrQrTobjectrrrrrs<         & = P%