o \Փa8 @s dZddlmZddlZddlZddlZddlmZmZddl m Z m Z ddZ e Z d gZejejBejBZd d Ze\ZZZeeed Zed eZdddddddddZdZddeejdjeejfddZe pleZ edeZ!dZ"de!je"fddZ#e!je"fd d!Z$Gd"d d e%Z&dS)#zImplementation of JSONDecoder )absolute_importN)PY3unichr) make_scannerJSONDecodeErrorcCs(z ddlm}|WStyYdSw)Nr scanstring) _speedupsr ImportErrorrr 4/usr/lib/python3/dist-packages/simplejson/decoder.py_import_c_scanstring s   r JSONDecodercCsBtjdkrdd}td|\}}ntd}td}||| fS)N) 7FF80000000000007FF0000000000000hexz>ddnaninf)sys version_infodecodestructunpackfloat)_BYTESrrr r r _floatconstantss   r)z -InfinityInfinityNaNz(.*?)(["\\\x00-\x1f])"\/    )r r!r"bfnrtzutf-8Tc Csz|durt}g} | j} |d} |||} | durtd|| | }| \} }| r;|s7t| ts7t| |} | | |dkr@n|dkrS|rNd}t|||| |qz||}Wn tyftd|| w|dkrz||}Wntyd}t|||w|d7}nd }||d|d }|dd }t |d ks|d ks|dkrt|||dzt |d}Wnt yt|||dw|d 7}|dkr.|d@dkr.|||d dkr.||d |d}|dd }t |d kr.|d ks.|dks.zt |d}Wnt yt|||w|d@dkr.d|dd>|dB}|d7}t |}| |q|| |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.NrzUnterminated string starting atr r!zInvalid control character %r atuzInvalid \X escape sequence %rzInvalid \uXXXX escape sequencerxXiiiz\urii ) DEFAULT_ENCODINGappendrendgroups isinstanceunicode IndexErrorKeyErrorlenint ValueErrorr)sr7encodingstrict_b_m_join_PY3 _maxunicodechunks_appendbeginchunkcontent terminatormsgesccharescXuniesc2uni2r r r py_scanstring1s               "   DrUz [ \t\n\r]*z c Cs|\} } |dur i}|j} g} | | | d} | dkrZ| |vr.|| | } | | | d} | dkrP|dur@|| }|| dfSi} |durJ|| } | | dfS| dkrZtd| | | d7} t| | ||\}} | ||}| | | ddkr|| | } | | | ddkrtd| | | d7} z| | |vr| d7} | | |vr|| | d} Wn tyYnw|| | \}} | ||fz| | } | |vr|| | d} | | } Wn tyd} Ynw| d7} | dkrnP| d krtd | | dz%| | } | |vr!| d7} | | } | |vr!|| | d} | | } Wn ty.d} Ynw| d7} | dkr@td| | dq_|durN|| }|| fSt| } |dur[|| } | | fS) Nrr }z1Expecting property name enclosed in double quotesT:zExpecting ':' delimiterr-,zExpecting ',' delimiter or '}') setdefaultr7rr r;r6dict)staterArB scan_once object_hookobject_pairs_hookmemo_w_wsr@r7memo_getpairsnextcharresultkeyvaluer r r JSONObjects            7 rhc CsD|\}}g}|||d}||vr#|||d}|||d}|dkr-||dfS|dkr7td|||j} |||\} }|| |||d}||vrc|||d}|||d}|d7}|dkrp ||fS|dkr|td||dz|||vr|d7}|||vr|||d}Wn tyYnwq;)Nr]r-zExpecting value or ']'TrXzExpecting ',' delimiter or ']')r7rr6r;) r[r\r`rar@r7valuesrdrIrgr r r JSONArraysD      rkc@sBeZdZdZ   d ddZejefddZdejefd d Z dS) raSimple JSON 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 | +---------------+-------------------+ It also understands ``NaN``, ``Infinity``, and ``-Infinity`` as their corresponding ``float`` values, which is outside the JSON spec. NTcCsj|durt}||_||_||_|pt|_|pt|_|ptj |_ ||_ t |_ t|_t|_i|_t||_dS)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`). *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)r5rAr]r^r parse_floatr> parse_int _CONSTANTS __getitem__parse_constantrBrh parse_objectrk parse_arrayr parse_stringr_rr\)selfrAr]rlrmrprBr^r r r __init__.s.   zJSONDecoder.__init__cCsX|r t|tr t||j}||\}}|||}|t|kr*td||t||S)zzReturn the Python representation of ``s`` (a ``str`` or ``unicode`` instance containing a JSON document) z Extra data)r9bytesstrrA raw_decoder7r=r)rtr@r`rFobjr7r r r rks  zJSONDecoder.decodercCs|dkr td|||rt|tstdt||krsD      X  ^$