
    ݝid             
       F   d Z dZdZdZdZdZdZddlmZ	   e	d	g d
      e ZeecZ
ZddlZej                  Z	 ej                  ej                  cZZdZdZ G d de      Z e       ZddlZefdZ ee      \  ZZZd Z G d de      Z e       Z e       Z [d Z! e!       \  a"a#a$[! G d de%      Z&dedZ'dedZ(dfdZ)dfdZ*d Z+ddl,Z, G d de,jZ                        Z.d Z/ G d  d!e      Z0 G d" d#e      Z1 G d$ d%e      Z2 G d& d'e3      Z4 G d( d)e4      Z5 G d* d+e4      Z6 G d, d-e4      Z7 G d. d/e4      Z8 G d0 d1e8      Z9 G d2 d3e9      Z: G d4 d5e8      Z; G d6 d7e;      Z< G d8 d9e      Z= G d: d;e      Z> G d< d=e      Z?d>Z@d?ZAd@ZBdAZCd?ZDdBZEdCZFdDZGdEZHdEZIdFZJdGZKdHZLdIZM G dJ dKeN      ZOdLZPdMZQdNZRdOZSdPZTePdQeQdReRdSeSdTeTdUiZUdVeSiZVdW ZWddXlXmYZZ ddYlm[Z\  G dZ d[eeO\      Z] G d] d^e      Z^dgd_a_dgd`a`dhdaZadgdbZb G dc dde      Zcy# e$ r ed   ed   cZZY w xY w)ia   A JSON data encoder and decoder.

 This Python module implements the JSON (http://json.org/) data
 encoding format; a subset of ECMAScript (aka JavaScript) for encoding
 primitive data types (numbers, strings, booleans, lists, and
 associative arrays) in a language-neutral simple text-based syntax.
 
 It can encode or decode between JSON formatted strings and native
 Python data types.  Normally you would use the encode() and decode()
 functions defined by this module, but if you want more control over
 the processing you can use the JSON class.

 This implementation tries to be as completely cormforming to all
 intricacies of the standards as possible.  It can operate in strict
 mode (which only allows JSON-compliant syntax) or a non-strict mode
 (which allows much more of the whole ECMAScript permitted syntax).
 This includes complete support for Unicode strings (including
 surrogate-pairs for non-BMP characters), and all number formats
 including negative zero and IEEE 754 non-numbers such a NaN or
 Infinity.

 The JSON/ECMAScript to Python type mappings are:
    ---JSON---             ---Python---
    null                   None
    undefined              undefined  (note 1)
    Boolean (true,false)   bool  (True or False)
    Integer                int or long  (note 2)
    Float                  float
    String                 str or unicode  ( "..." or u"..." )
    Array [a, ...]         list  ( [...] )
    Object {a:b, ...}      dict  ( {...} )
    
    -- Note 1. an 'undefined' object is declared in this module which
       represents the native Python value for this type when in
       non-strict mode.

    -- Note 2. some ECMAScript integers may be up-converted to Python
       floats, such as 1e+40.  Also integer -0 is converted to
       float -0, so as to preserve the sign (which ECMAScript requires).

    -- Note 3. numbers requiring more significant digits than can be
       represented by the Python float type will be converted into a
       Python Decimal type, from the standard 'decimal' module.

 In addition, when operating in non-strict mode, several IEEE 754
 non-numbers are also handled, and are mapped to specific Python
 objects declared in this module:

     NaN (not a number)     nan    (float('nan'))
     Infinity, +Infinity    inf    (float('inf'))
     -Infinity              neginf (float('-inf'))

 When encoding Python objects into JSON, you may use types other than
 native lists or dictionaries, as long as they support the minimal
 interfaces required of all sequences or mappings.  This means you can
 use generators and iterators, tuples, UserDict subclasses, etc.

 To make it easier to produce JSON encoded representations of user
 defined classes, if the object has a method named json_equivalent(),
 then it will call that method and attempt to encode the object
 returned from it instead.  It will do this recursively as needed and
 before any attempt to encode the object using it's default
 strategies.  Note that any json_equivalent() method should return
 "equivalent" Python objects to be encoded, not an already-encoded
 JSON-formatted string.  There is no such aid provided to decode
 JSON back into user-defined classes as that would dramatically
 complicate the interface.
 
 When decoding strings with this module it may operate in either
 strict or non-strict mode.  The strict mode only allows syntax which
 is conforming to RFC 7159 (JSON), while the non-strict allows much
 more of the permissible ECMAScript syntax.

 The following are permitted when processing in NON-STRICT mode:

    * Unicode format control characters are allowed anywhere in the input.
    * All Unicode line terminator characters are recognized.
    * All Unicode white space characters are recognized.
    * The 'undefined' keyword is recognized.
    * Hexadecimal number literals are recognized (e.g., 0xA6, 0177).
    * String literals may use either single or double quote marks.
    * Strings may contain \x (hexadecimal) escape sequences, as well as the
      \v and \0 escape sequences.
    * Lists may have omitted (elided) elements, e.g., [,,,,,], with
      missing elements interpreted as 'undefined' values.
    * Object properties (dictionary keys) can be of any of the
      types: string literals, numbers, or identifiers (the later of
      which are treated as if they are string literals)---as permitted
      by ECMAScript.  JSON only permits strings literals as keys.

 Concerning non-strict and non-ECMAScript allowances:

    * Octal numbers: If you allow the 'octal_numbers' behavior (which
      is never enabled by default), then you can use octal integers
      and octal character escape sequences (per the ECMAScript
      standard Annex B.1.2).  This behavior is allowed, if enabled,
      because it was valid JavaScript at one time.

    * Multi-line string literals:  Strings which are more than one
      line long (contain embedded raw newline characters) are never
      permitted. This is neither valid JSON nor ECMAScript.  Some other
      JSON implementations may allow this, but this module considers
      that behavior to be a mistake.

 References:
    * JSON (JavaScript Object Notation)
      <http://json.org/>
    * RFC 7159. The application/json Media Type for JavaScript Object Notation (JSON)
      <http://www.ietf.org/rfc/rfc7159.txt>
    * ECMA-262 3rd edition (1999)
      <http://www.ecma-international.org/publications/files/ecma-st/ECMA-262.pdf>
    * IEEE 754-1985: Standard for Binary Floating-Point Arithmetic.
      <http://www.cs.berkeley.edu/~ejr/Projects/ieee754/>
    
u8   Deron Meranda <http://deron.meranda.us/>, Niels Mündlerz$http://nielstron.github.io/demjson3/z
2021-09-08z3.0.5)          ul  Copyright (c) 2006-2021 Deron E. Meranda <http://deron.meranda.us/>, Niels Mündler

Licensed under GNU LGPL (GNU Lesser General Public License) version 3.0
or later.  See LICENSE.txt included with this software.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>
or <http://www.fsf.org/licensing/>.

r   )
namedtupleversion_info)majorminormicroN   zapplication/jsonjsonc                       e Zd ZdZd Zd Zy)_dummy_context_managerz5A context manager that does nothing on entry or exit.c                      y N selfs    F/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/demjson3.py	__enter__z _dummy_context_manager.__enter__   s        c                      yNFr   )r   exc_typeexc_valexc_tbs       r   __exit__z_dummy_context_manager.__exit__       r   N)__name__
__module____qualname____doc__r   r   r   r   r   r   r      s    ?r   r   c                    t         t        j                  t        j                  f}| t        j                  k(  rt        j
                  } t        | t        j                        r%| j                  }t        j                  |       }d }n | t        k(  r| }t        }d }nt        d      |5   |d      }d}d}	 |dz   }dd	|z  z   } ||d
z         }	dD ]  }
 |||
z         }|	|z   ||z   k(  s|} n |rn=dd	|dz
  z  z   }dd	|dz
  z  z   }d\  }}dD ]  }d}d}	 	 |dz   |z   t        |      z   }|dz   |z   t        |      z   } ||      |z   } ||      |z   }|r)t        |      d   j                         r ||      s|k(  rn|}|dz  }s	 |dz   |k(  r|dk(  r|}n|}||k  r|dk(  rd}nd}||z   dz  }	 |dz   |z   t        |      z   }|dz   |z   t        |      z   } ||      |z   } ||      |z   }|rt        |      d   j                         sd}n ||      s||k(  rd}	 |s|}n|} 	 ddd        t        dg d             S # |$ r d}Y w xY w# |$ r d}Y @w xY w# 1 sw Y   ;xY w)ab  Determines the precision and range of the given float type.

    The passed in 'number_type' argument should refer to the type of
    floating-point number.  It should either be the built-in 'float',
    or decimal context or constructor; i.e., one of:

        # 1. FLOAT TYPE
        determine_float_limits( float )

        # 2. DEFAULT DECIMAL CONTEXT
        determine_float_limits( decimal.Decimal )

        # 3. CUSTOM DECIMAL CONTEXT
        ctx = decimal.Context( prec=75 )
        determine_float_limits( ctx )

    Returns a named tuple with components:

         ( significant_digits,
           max_exponent,
           min_exponent )

    Where:
        * significant_digits -- maximum number of *decimal* digits
             that can be represented without any loss of precision.
             This is conservative, so if there are 16 1/2 digits, it
             will return 16, not 17.

        * max_exponent -- The maximum exponent (power of 10) that can
             be represented before an overflow (or rounding to
             infinity) occurs.

        * min_exponent -- The minimum exponent (negative power of 10)
             that can be represented before either an underflow
             (rounding to zero) or a subnormal result (loss of
             precision) occurs.  Note this is conservative, as
             subnormal numbers are excluded.

    c                 F    | j                         xs | j                         S r   )is_zerois_subnormalns    r   <lambda>z(determine_float_limits.<locals>.<lambda>   s    )H8H r   c                     | dk(  S Nr   r   r%   s    r   r'   z(determine_float_limits.<locals>.<lambda>   s
    a r   z5Expected a float type, e.g., float or decimal context0.0Nr   r
   z0.10	123456789z1.   NN)+-
   er0   float_limits)significant_digitsmax_exponentmin_exponent)
ValueErrordecimalOverflow	UnderflowDecimalDefaultContext
isinstanceContextcreate_decimallocalcontextfloatr   	TypeErrorstrisdigit_namedtuple)number_typenumeric_exceptions
create_numdecimal_ctxis_zero_or_subnormalzero	sigdigitsr&   pfxasfxbbasebase0minexpmaxexpexpsignminvmaxvss0ff0ms                           r   determine_float_limitsr^      s0   P %g&6&68I8IJgoo%,,+w/ //
**;7H		 
,/OPP	 Q% 
 	AAq.C39%A" sSy)H!d(+ !I   cY]++si!m,,#! 6	GDDs
W,s4y8Aw.T:B"1,A#B$.B q6!9,,.+A.BwD"9D# ( !8t##~!%!%D[#~!%!%D[Q&!s
W,s1v5Aw.Q7B"1,A#B$.B CF1I$5$5$7 -a0AG DD= 16	7Qf;N&" "] * AB * AMQ Qs\   *AI.,/I.>IA I.;>I!9:I.II.II.!I+(I.*I++I..I7c                  P    t        t              } | j                  | j                  fS r   )r^   rB   r5   r6   )vs    r   determine_float_precisionra   _  s!    u%A  !..11r   c                   &    e Zd ZdZg Zd Zd Zd Zy)_undefined_classz,Represents the ECMAScript 'undefined' value.c                      | j                   dz   S )Nz
.undefined)r   r   s    r   __repr__z_undefined_class.__repr__q  s    --r   c                      y)N	undefinedr   r   s    r   __str__z_undefined_class.__str__t  s    r   c                      yr   r   r   s    r   __bool__z_undefined_class.__bool__w  r   r   N)r   r   r   r    	__slots__re   rh   rj   r   r   r   rc   rc   l  s    6I.r   rc   c            	         	 t        d      } t        d      }t        d      }| ||fS # t        $ r 	 t        d      } t        d      }t        d      }n# t        $ r 	 ddl}ddl}t	        t
        j                  d	      j                               }t	        t
        j                  d
      j                               }t	        t
        j                  d      j                               }|j                  dk(  r@|j                  d|      d   } |j                  d|      d   }|j                  d|      d   }nQ|j                  d|ddd         d   } |j                  d|ddd         d   }|j                  d|ddd         d   }| }|dk7  rt        d      nT# t        t        f$ rB t        j                  d      } t        j                  d      }t        j                  d      }Y nw xY wY nw xY wY w xY w)ag  Try to return the Nan, Infinity, and -Infinity float values.

    This is necessarily complex because there is no standard
    platform-independent way to do this in Python as the language
    (opposed to some implementation of it) doesn't discuss
    non-numbers.  We try various strategies from the best to the
    worst.

    If this Python interpreter uses the IEEE 754 floating point
    standard then the returned values will probably be real instances
    of the 'float' type.  Otherwise a custom class object is returned
    which will attempt to simulate the correct behavior as much as
    possible.

    naninf-infNaNQINFz-INFr   N7ff80000000000007ff0000000000000bdc145651592979dbigdgeEz+Unpacking raw IEEE 754 floats does not workNaNInfinity	-Infinity)rB   r8   structsysbytes	bytearrayfromhexdecode	byteorderunpackrC   r9   r<   )	rm   rn   neginfr{   r|   xnanxinfxcheckchecks	            r   _nonnumber_float_constantsr     s    *6 ElElvL VK  $6#	6-C,C6]F 	66 #%%&89@@B Y../ABIIKL%%&89@@B
 ==E) --T215C --T215C"MM#v6q9E --T$B$Z8;C --T$B$Z8;C"MM#vdd|<Q?EL($%RSS )	* 6ooe,ooj1 5	65	6$6sX   !( 
G?!AG?
G8!D?F! G8!AG2/G81G22G85G?7G88G?>G?c                   8     e Zd ZdZ fdZed        Zd Z xZS )json_inta8  A subclass of the Python int/long that remembers its format (hex,octal,etc).

    Initialize it the same as an int, but also accepts an additional keyword
    argument 'number_format' which should be one of the NUMBER_FORMAT_* values.

        n = json_int( x[, base, number_format=NUMBER_FORMAT_DECIMAL] )

    c                     d|v r0|d   }|d= |t         t        t        t        t        fvrt        d      t         }t        t        | "  | g|i |}||_	        |S )Nnumber_formatz4json_int(): Invalid value for number_format argument)
NUMBER_FORMAT_DECIMALNUMBER_FORMAT_HEXNUMBER_FORMAT_OCTALNUMBER_FORMAT_LEGACYOCTALNUMBER_FORMAT_BINARYrC   superr   __new___jsonfmt)clsargskwargsr   obj	__class__s        r   r   zjson_int.__new__  ss    f$"?3M'%!#)$%    VWW1MHc*3@@@$
r   c                     | j                   S )z'The original radix format of the number)r   r   s    r   r   zjson_int.number_format  s     }}r   c                     | j                   }|t        k(  rt        | d      S |t        k(  rt        | d      S |t        k(  rt        | d      S |t
        k(  r| dk(  ry| dk  rd|  z  S d| z  S t        |       S )z5Returns the integer value formatted as a JSON literalz#xz#oz#br   r,   z-0%oz0%o)r   r   formatr   r   r   rD   )r   fmts     r   json_formatzjson_int.json_format  s    mm##$%%''$%%(($%%--qy$''t|#t9r   )	r   r   r   r    r   propertyr   r   __classcell__r   s   @r   r   r     s&    $  r   r   c                 f    |}t         j                  }||k  r| |   |vr|dz  }||k  r| |   |vr|S )Nr
   helpersunsafe_string_chars)rY   startendiunsafes        r   skipstringsafer   
  sL    A ((F
c'ad&( 	
Q	 c'ad&(
 Hr   c                     |}|t        |       }||k  r0| |   }|dk(  s|dk(  s|dk(  st        |      dk  r	 |S |dz  }||k  r0|S )N"'\   r
   )lenord)rY   r   r   r   cs        r   skipstringsafe_slowr     se    A
{!f
c'aD8qCx19A$H 	
Q	 c'
 Hr   c                     |s| j                  |       y t        |      D ],  \  }}|dkD  r| j                  |       | j                  |       . y r)   )extend	enumerateappend)orig_seqextension_seqsepcharr   xs        r   extend_list_with_sepr   #  sH    &m, 	DAq1u(OOA	r   c                 |    t        |      D ].  \  }}|dkD  r|r| j                  |       | j                  |       0 y r)   r   r   r   r   r   	separatorr   parts        r    extend_and_flatten_list_with_sepr   -  s;    ]+ 4q5YOOI&r   c                     t        |       S )zYTakes a list of byte values (numbers) and returns a bytes (Python 3) or string (Python 2)r}   	byte_lists    r   _make_raw_bytesr   9  s    r   c                       e Zd ZdZ eg d      Z eg d      Zed        Zedd       Z	edd       Z
edd       Zedd	       Zedd
       Zedd       Zy)utf32a  Unicode UTF-32 and UCS4 encoding/decoding support.

    This is for older Pythons whch did not have UTF-32 codecs.

    JSON requires that all JSON implementations must support the
    UTF-32 encoding (as well as UTF-8 and UTF-16).  But earlier
    versions of Python did not provide a UTF-32 codec, so we must
    implement UTF-32 ourselves in case we need it.

    See http://en.wikipedia.org/wiki/UTF-32

    )r   r         )r   r   r   r   c                    d}| j                         } | dv r6t        j                  t        j                  t        j
                  d      }|S | dv r6t        j                  t        j                  t        j                  d      }|S | dv r4t        j                  t        j                  t        j                  d      }|S )	zA standard Python codec lookup function for UCS4/UTF32.

        If if recognizes an encoding name it returns a CodecInfo
        structure which contains the various encode and decoder
        functions to use.

        N)UCS4BEzUCS-4BEzUCS-4-BEUTF32BEzUTF-32BEz	UTF-32-BEutf-32be)name)UCS4LEzUCS-4LEzUCS-4-LEUTF32LEzUTF-32LEz	UTF-32-LEutf-32le)UCS4zUCS-4UTF32zUTF-32zutf-32)
uppercodecs	CodecInfor   utf32be_encodeutf32be_decodeutf32le_encodeutf32le_decodeencoder   )r   cis     r   lookupzutf32.lookupR  s     zz| 
 
 !!$$e&:&:B  	  
 
 !!$$e&:&:B
 	 99!!%,,8LB	r   Nc                 H   ddl }ddl}t               j                  }fd}|s|j                  }|j                         d   dv rd}n&|j                         d   dv rd}nt        d|z        |j                  }	|rd	nd
}
d}|r4|r |t        j                         n |t        j                         |dz  }t        |       D ]R  \  }}t        |      }d|cxk  rdk  r#n n |dk(  rn|dk(  rd}nt        d| ||dz   d       | |	|
|             |dz  }T  |       |fS )a%  Encodes a Unicode string into a UTF-32 encoded byte string.

        Returns a tuple: (bytearray, num_chars)

        The errors argument should be one of 'strict', 'ignore', or 'replace'.

        The endianness should be one of:
            * 'B', '>', or 'big'     -- Big endian
            * 'L', '<', or 'little'  -- Little endien
            * None                   -- Default, from sys.byteorder

        If include_bom is true a Byte-Order Mark will be written to
        the beginning of the string, otherwise it will be omitted.

        r   Nc                      t               S r   r   )r[   s   r   tobyteszutf32.encode.<locals>.tobytes  s    8Or   zB>TzL<Fz8Invalid endianness %r: expected 'big', 'little', or None>L<Lr
        ignorereplace  r   z;surrogate code points from U+D800 to U+DFFF are not allowed)r|   r{   r~   r   r   r   r8   packr   BOM_UTF32_BEBOM_UTF32_LEr   r   UnicodeEncodeError)r   errors
endiannessinclude_bomr|   r{   writer   
big_endianr   packspec	num_charsposr   r&   r[   s                  @r   r   zutf32.encodew  sJ   " 	 K	 Ja T*J"t,JJZW  {{%44	e(()e(()NIn 	FCAA$f$X%y(A,aU  $x#$NI!	$ 	9%%r   c                 4    t         j                  | |d|      S )zMEncodes a Unicode string into a UTF-32LE (little endian) encoded byte string.Lr   r   r   r   r   r   r   r   s      r   r   zutf32.utf32le_encode       ||C3K|XXr   c                 4    t         j                  | |d|      S )zJEncodes a Unicode string into a UTF-32BE (big endian) encoded byte string.Br   r   r   s      r   r   zutf32.utf32be_encode  r   r   c           	      n   ddl }ddl}|j                  }|j                  }| j	                  t
        j                        rd}t        t
        j                        }n?| j	                  t
        j                        rd}t        t
        j                        }nd}d}|}	|dk(  r&|dk(  r|j                  j                         d   }n,|}n)|d   j                         }|r||k7  rt        d| d|d      t        |       |z
  dz  dk7  rt        d| |t        |       d      g }
|dk(  rd	nd
}d}t        |t        |       d      D ]  }| ||dz    } |||      d   }|	dz  }	||kD  sd|cxk  rdk  rn n|dk(  rt        d| ||dz   d|z        |dk(  r|
j                  t        d             i|dk(  r+|dkD  rd|fz  }nd|fz  }|D ]  }|
j                  |        |dk(  rd|fz  }|D ]  }|
j                  |        |
j                  t        j!                  |              dj#                  |
      |	fS )aG  Decodes a UTF-32 byte string into a Unicode string.

        Returns tuple (bytearray, num_bytes)

        The errors argument shold be one of 'strict', 'ignore',
        'replace', 'backslashreplace', or 'xmlcharrefreplace'.

        The endianness should either be None (for auto-guessing), or a
        word that starts with 'B' (big) or 'L' (little).

        Will detect a Byte-Order Mark. If a BOM is found and endianness
        is also set, then the two must match.

        If neither a BOM is found nor endianness is set, then big
        endian order is assumed.

        r   Nr   r   r   z&BOM does not match expected byte order   z%Data length not a multiple of 4 bytesr   r   r   r   strictzInvalid code point U+%04Xr   r   backslashreplace  \u%04xz\U%08xxmlcharrefreplacez&#%d; )r{   r|   
maxunicoder   
startswithr   r   r   r   r   r   UnicodeDecodeErrorranger   chrr   safe_unichrjoin)r   r   r   r{   r|   r  r   bom_endiannessr   	num_bytescharsr   r   seqr&   escesc_cs                    r   r   zutf32.decode  sg   & 	^^
 >>%,,- N**+E^^E../ N**+E!NE	% ]]00215
+
#A,,.J*">(S!U,T 
 X"q($eSX/V 
 %,4$uc#h* 	5Aa!a%.Cx%a(ANI:~&A"7"7X%,aQ0Ka0O  y(LLV-116z'1$.'1$.!$ ,U+,22!QD.C!$ ,U+, W00345	56 	**r   c                 2    t         j                  | |d      S )zEDecodes a UTF-32LE (little endian) byte string into a Unicode string.r   r   r   r   r   r   r   s     r   r   zutf32.utf32le_decode       ||C3|??r   c                 2    t         j                  | |d      S )zBDecodes a UTF-32BE (big endian) byte string into a Unicode string.r   r  r  r  s     r   r   zutf32.utf32be_decode$  r  r   )r   NT)r   F)r   N)r   )r   r   r   r    r   r   r   staticmethodr   r   r   r   r   r   r   r   r   r   r   r   A  s     ##56L"#56L" "H C& C&J Y Y Y Y U+ U+n @ @ @ @r   r   c                      dd l } g }t        d      D cg c]  }t        |       c}D ]1  }|dk(  s|dk(  s| j                  |      dv s!|j	                  |       3 dj                  |      S c c}w )Nr      r   r   CcCfZlZpr  )unicodedatar	  r
  categoryr   r  )r!  r   r   r   s       r   _make_unsafe_string_charsr#  /  sm    F#El+c!f+ 8qDyK$8$8$;?W$WMM! 776? ,s   A.c                   "   e Zd ZdZdZdZ e       ZddlZej                  Z	dZ
 eg d      Zed        Zed	        Zed
        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed$d       Zed        Zed        Zed        Zed%d       Zed        Zed        Zed        Z ed        Z!ed        Z"ed        Z#ed        Z$ed        Z%ed         Z&ed!        Z'ed"        Z(ed#        Z)y)&r   zA set of utility functions.0123456789ABCDEFabcdef01234567r   NF)-breakcasecatchclassconstcontinuedebuggerdefaultdeletedoelseexportextendsfinallyforfunctionifimportin
instanceofletnewreturnr   switchthisthrowtrytypeofvarvoidwhilewithyieldenum
implements	interfacepackageprivate	protectedpublicstaticnulltruefalsec                     t        |       S )z`Constructs a byte array (bytes in Python 3, str in Python 2) from a list of byte values (0-255).)r   r   s    r   make_raw_byteszhelpers.make_raw_bytes}  s     y))r   c                 &    | t         j                  v S )zODetermines if the given character is a valid hexadecimal digit (0-9, a-f, A-F).)r   	hexdigitsr   s    r   is_hex_digitzhelpers.is_hex_digit  s     G%%%%r   c                 &    | t         j                  v S )z?Determines if the given character is a valid octal digit (0-7).)r   octaldigitsrW  s    r   is_octal_digitzhelpers.is_octal_digit  s     G''''r   c                     | dk(  xs | dk(  S )zCDetermines if the given character is a valid binary digit (0 or 1).r,   r+   r   rW  s    r   is_binary_digitzhelpers.is_binary_digit  s     Cx#18#r   c                 
    | dv S )zADetermines if the given character is a JSON white-space character 	
r   rW  s    r   char_is_json_wszhelpers.char_is_json_ws  s     I~r   c                     | dk\  rS| t         j                  kD  r@t         j                  |       \  }}|t        |      }|S t        |      t        |      z   }|S t        |       }|S )z@Just like Python's unichr() but works in narrow-Unicode Pythons.   )r   r  make_surrogate_pairr
  )	codepointw1w2r   s       r   r  zhelpers.safe_unichr  sm     I0B0B$B00;FBzG
  Gc"g%  IAr   c                 r    t        | t              st        |       } | dv ryddl}|j                  |       dk(  S )z>Determines if the given character is a Unicode space character 	
Tr   NZs)r>   rD   r!  r"  )r   r!  s     r   char_is_unicode_wszhelpers.char_is_unicode_ws  s;     !S!AA##A&$..r   c                 
    | dv S )z:Determines if the given character is a JSON line separatorz
r   rW  s    r   char_is_json_eolzhelpers.char_is_json_eol  s     F{r   c                 
    | dv S )zDetermines if the given character is a Unicode line or
        paragraph separator. These correspond to CR and LF as well as
        Unicode characters in the Zl or Zp categories.

        u   
  r   rW  s    r   char_is_unicode_eolzhelpers.char_is_unicode_eol  s     &&&r   c                 .    | j                         xs | dv S )zcDetermines if the character may be the first character of a
        JavaScript identifier.
        _$)isalpharW  s    r   char_is_identifier_leaderz!helpers.char_is_identifier_leader  s    
 yy{'a4i'r   c                 .    | j                         xs | dv S )zTDetermines if the character may be part of a JavaScript
        identifier.
        u   _$‌‍isalnumrW  s    r   char_is_identifier_tailzhelpers.char_is_identifier_tail  s    
 yy{3a#333r   c                 |    t        |      D ].  \  }}|dkD  r|r| j                  |       | j                  |       0 y r)   r   r   s        r   r   z(helpers.extend_and_flatten_list_with_sep  s;     / 	"GAt1u	*OOD!	"r   c                     ddl }| D cg c]"  }|j                  t        |            dk7  s!|$ }}t        |t              sdj	                  |      }|S c c}w )a  Filters out all Unicode format control characters from the string.

        ECMAScript permits any Unicode "format control characters" to
        appear at any place in the source code.  They are to be
        ignored as if they are not there before any other lexical
        tokenization occurs.  Note that JSON does not allow them,
        except within string literals.

        * Ref. ECMAScript section 7.1.
        * http://en.wikipedia.org/wiki/Unicode_control_characters

        There are dozens of Format Control Characters, for example:
            U+00AD   SOFT HYPHEN
            U+200B   ZERO WIDTH SPACE
            U+2060   WORD JOINER

        r   Nr  r  )r!  r"  rD   r>   r  )txtr!  r   txt2s       r   strip_format_control_charsz"helpers.strip_format_control_chars  sT    & 	Ga+"6"6s1v">$"FGG
 $$774=D Hs
   "AAc                 v   ddl }t        | |j                        r| S | j                         } ddl }t        j
                  r.t        j                  |       }|s	  |j                  |       }|S |S 	  |j                  |       }|S # t        $ r d}Y |S w xY w# t        $ r t        j                  |       }Y |S w xY w)zuWrapper around codecs.lookup().

        Returns None if codec not found, rather than raising a LookupError.
        r   N)	r   r>   r   lowerr   always_use_custom_codecsr   r   LookupError)encodingr   cdks      r   lookup_codeczhelpers.lookup_codec  s     	h 0 01O>>#++,,x(C'&--1C 
s
	-#fmmH- 
 # C 
  -ll8,
-s$   B 0B BBB87B8c                 :   | rt        |       dk(  ryg }t        dt        t        |       d            D ]3  }| |   }t        |t              rt        |      }|j                  |       5 ddl}d\  }}}t        |       dk\  r| dd }t        |       dk\  r| dd }t        |       dk\  r| dd }d\  }}	}
}}t        |       d	k\  r|d   }t        |       dk\  r|d	   }	t        |       dk\  r|d   }
t        |       dk\  r|d   }| d
   }t        |t              rt        |      }|r7t        |d      r||j                  k(  s|t        j                  k(  r	d}| dd } |S |r7t        |d      r||j                  k(  s|t        j                  k(  r	d}| dd } |S |r||j                  k(  r	d}| dd } |S |r||j                  k(  r	d}| dd } |S |r||j                  k(  r	d}| dd } |S t        |       dk\  r|dk(  r|	dk(  r|
dk(  r	|dk7  rd}|S t        |       dk\  r|dk7  r|	dk(  r|
dk(  r|dk(  r	|dk(  rd}|S t        |       dk\  r|dk(  r	|	dk7  rd}|S t        |       dk\  r|dk7  r|	dk(  r	|dk(  rd}|S t        d      |cxk  rdk  rd}|S  t        d      t        d      )zTakes a string (or byte array) and tries to determine the Unicode encoding it is in.

        Returns the encoding name, as a string.

        r   utf-8r   NNNNr.   r   )NNNNNr
   rw   r   r   r   r   zutf-16lezutf-16be	   utf8z6Can not determine the Unicode encoding for byte stream)r   r	  minr>   rD   r   r   r   hasattrr   r   r   BOM_UTF16_LEBOM_UTF16_BEBOM_UTF8r8   )rY   ordsr   r   r   bom2bom3bom4rO   rQ   r   rv   zr  s                 r   auto_detect_encodingzhelpers.auto_detect_encoding  s$    CFaK q#c!fa.) 	A!A!S!FKKN		 	+dDq6Q;Ra5Dq6Q;Ra5Dq6Q;Ra5D 51aAq6Q;QAq6Q;QAq6Q;QAq6Q;QAbEaAAV^,9L9L1L***!H!"AP O V^,9L9L1L***!H!"AD C df111!H!"A> = df111!H!"A8 7 dfoo-H!"A2 # FaKAFqAv!q&Q!V!H  FaKAFqAv!q&Q!VQ!H  Vq[Q!VQ!H  Vq[Q!VQ16!H  Y!"s"H  # UVV*UVVr   c                 p   t        | t              r t        dg d      | dd      }|S ||dk(  rt        j	                  |       }t        j                  |      }|st        d|z        	 |j                  t        j                  g       d       ddi} |j                  | fi |\  }}t        |      d	kD  r%|d	   d
k(  r|j                  |d	         d	   }|dd }n1t        |      d	kD  r!|d	   dk(  rt        |j                  | d	d	d      d} t        dg d      |||      }|S # t        $ r i }Y w xY w)a9  Takes a string (or byte array) and tries to convert it to a Unicode string.

        Returns a named tuple:  (string, codec, bom)

        The 'encoding' argument, if supplied, should either the name of
        a character encoding, or an instance of codecs.CodecInfo.  If
        the encoding argument is None or "auto" then the encoding is
        automatically determined, if possible.

        Any BOM (Byte Order Mark) that is found at the beginning of the
        input will be stripped off and placed in the 'bom' portion of
        the returned value.

        DecodedString)stringcodecbomNautoz"Can not find codec for encoding %rr   )r   r   r   u   ﻿r
   u   ￾z+Wrong byte order, found reversed BOM U+FFFE)r>   rD   rF   r   r  r  r  r   rT  rC   r   r   r  r   )ry  r  resr  cdk_kwunitxtnumbytesr  s           r   unicode_decodezhelpers.unicode_decodeh  sf     c3J+o/IJT4CF 
? 8v#5"77<&&x0C!"F"QRR.

711"5h
G #H-)szz#88FH 6{Q6!9#8jj+A.VqVAY(%:(HHc1a)V  J+o/IJSC 
+  s   +&D' 'D54D5c                     t        |       t        |      }}|dk  s|dkD  s
|dk  s|dkD  rt        d| |f      |dz
  }|dz
  }|dz  |z  }|dz  }t        j                  |      S )zTakes a pair of unicode surrogates and returns the equivalent unicode character.

        The input pair must be a surrogate pair, with c1 in the range
        U+D800 to U+DBFF and c2 in the range U+DC00 to U+DFFF.

        r        r   zillegal Unicode surrogate pairr2   rb  )r   JSONDecodeErrorr   r  )c1c2n1n2rO   rQ   r`   s          r   surrogate_pair_as_unicodez!helpers.surrogate_pair_as_unicode  sy     R#b'B;"v+fV!"BRHMMKK"WM	W""1%%r   c                     t        |       }t        j                  |      \  }}|t        |      fS t        |      t        |      fS )a  Takes a single unicode character and returns a sequence of surrogate pairs.

        The output of this function is a tuple consisting of one or two unicode
        characters, such that if the input character is outside the BMP range
        then the output is a two-character surrogate pair representing that character.

        If the input character is inside the BMP then the output tuple will have
        just a single character...the same one.

        )r   r   rc  r
  )r   r&   re  rf  s       r   unicode_as_surrogate_pairz!helpers.unicode_as_surrogate_pair  sE     F,,Q/B:G:GSW%%r   c                 T    | dk  r| dfS | dz
  }|dz	  dz  }|dz  }d|z  }d|z  }||fS )zJGiven a Unicode codepoint (int) returns a 2-tuple of surrogate codepoints.rb  Nr2   i  r   r  r   )rd  r`   vhvlre  rf  s         r   rc  zhelpers.make_surrogate_pair  sS     wt$$2gYb[b[Bxr   c                     t        | t        t        f      xr t        | t               xs@ | t        u xs6 | t
        u xs, | t        u xs" t        xr t        | t        j                        S )z:Is the object of a Python number type (excluding complex)?)	r>   intrB   boolrm   rn   r   r9   r<   )r   s    r   isnumbertypezhelpers.isnumbertype  sk     sS%L) *sD))>cz> cz> f}	>
 <JsGOO<	
r   c                     t        | t              r!| dk(  xr t        |       j                  d      S t        r<t        | t        j
                        r"| j                         xr | j                         S y)z$Is the number value a negative zero?        r1   F)r>   rB   reprr  r9   r<   r#   	is_signedr%   s    r   
is_negzerozhelpers.is_negzero  sV     a87Q 2 23 77Aw799;01;;=0r   c                     t        | t              r$| t        u xs | j                         dk(  xs | | k7  S t        r*t        | t        j
                        r| j                         S y)z#Is the number a NaN (not-a-number)?rm   F)r>   rB   rm   hexr9   r<   is_nanr%   s    r   r  zhelpers.is_nan  sP     a89quuw%/9169Aw788:r   c                     t        | t              r&| t        u xs | t        u xs | j	                         dv S t
        r*t        | t
        j                        r| j                         S y)zIs the number infinite?)rn   ro   F)r>   rB   rn   r   r  r9   r<   is_infiniter%   s    r   r  zhelpers.is_infinite  sP     a8HqF{Haeeg.HHAw7==?"r   c                 ~    t        | t              ryddl}t        | t        f      xs t        | |j                        S )z&Is the object of a Python string type?Tr   N)r>   rD   collections
UserString)r   r  s     r   isstringtypezhelpers.isstringtype  s5     c3#v&Q*S+:P:P*QQr   c                 0   d}| D ]  }d|cxk  rdk  rn nt        |      t        d      z
  }n^d|cxk  rdk  rn nt        |      t        d      z
  dz   }n5d|cxk  rdk  rn nt        |      t        d      z
  dz   }nt        d	|       |d
z  |z   } |S )z5Decodes a hexadecimal string into it's integer value.r   r,   9rO   r[   r2   AFzNot a hexadecimal number   r   r8   )	hexstringr&   r   rv   s       r   
decode_hexzhelpers.decode_hex  s      
	Aa3FSX%SFSX%*SFSX%* !;YGGR1A
	 r   c                     d}| D ]<  }d|cxk  rdk  rn nt        |      t        d      z
  }nt        d|       |dz  |z   }> |S )z0Decodes an octal string into it's integer value.r   r,   7zNot an octal number   r  )octalstringr&   r   rv   s       r   decode_octalzhelpers.decode_octal  sW      	Aa3FSX% !6DDQ!A	 r   c                 `    d}| D ]&  }|dk(  rd}n|dk(  rd}nt        d|       |dz  |z   }( |S )z0Decodes a binary string into it's integer value.r   r,   r+   r
   zNot an binary numberr.   )r8   )binarystringr&   r   rv   s       r   decode_binaryzhelpers.decode_binary$  sR      	ACxc !7FFQ!A	 r   c                    | j                   }| j                  }| j                  }t        |d      \  }}t        |d      \  }}dg}|r|j	                  d|z         |s|s|s|r|j	                  d       |r|j	                  d|z         |r|j	                  d|z         |s|r-|r|j	                  d||fz         n|j	                  d|z         t        |      d	k(  r|j	                  d
       dj                  |      S )z>Encodes a datetime.timedelta into ISO-8601 Time Period format.<   Pz%dDTz%dHz%dMz%d.%06dz%dr
   T0Sr  )dayssecondsmicrosecondsdivmodr   r   r  )tdrv   rY   msr]   hrO   s          r   format_timedelta_isozhelpers.format_timedelta_iso3  s     GGJJ__a}1a}1EHHUQYQ"HHSMHHUQYHHUQYaW,-"q6Q;HHUOwwqzr   r  r   )*r   r   r   r    rV  rZ  r#  r   r|   r  r~  	frozensetjavascript_reserved_wordsr  rT  rX  r[  r]  r`  r  rj  rl  rn  rr  rv  r   r{  r  r  r  r  r  rc  r  r  r  r  r  r  r  r  r  r   r   r   r   r   9  ss   %(IK35J$ !*1	
3!j * * & & ( ( $ $     / /   ' ' ( ( 4 4 " "  :  8 X Xt 3 3j & &  & &$ 	 	 	
 	
       R R  & 
 
    r   r   c                       e Zd ZdZddZed        Zed        Zed        Zed        Z	ed        Z
e
j                  d	        Z
ed
        Zej                  d        Zd ZddZd Zd Zd Zd Zy)position_markera  A position marks a specific place in a text document.
    It consists of the following attributes:

        * line - The line number, starting at 1
        * column - The column on the line, starting at 0
        * char_position - The number of characters from the start of
                          the document, starting at 0
        * text_after - (optional) a short excerpt of the text of
                       document starting at the current position

    Lines are separated by any Unicode line separator character. As an
    exception a CR+LF character pair is treated as being a single line
    separator demarcation.

    Columns are simply a measure of the number of characters after the
    start of a new line, starting at 0.  Visual effects caused by
    Unicode characters such as combining characters, bidirectional
    text, zero-width characters and so on do not affect the
    computation of the column regardless of visual appearance.

    The char_position is a count of the number of characters since the
    beginning of the document, starting at 0. As used within the
    buffered_stream class, if the document starts with a Unicode Byte
    Order Mark (BOM), the BOM prefix is NOT INCLUDED in the count.

    Nc                 X    || _         || _        || _        || _        d| _        d| _        y r   )_position_marker__char_position_position_marker__line_position_marker__column_position_marker__text_after_position_marker__at_end_position_marker__last_was_cr)r   offsetlinecolumn
text_afters        r   __init__zposition_marker.__init__o  s/    %&"r   c                     | j                   S )z2The current line within the document, starts at 1.)r  r   s    r   r  zposition_marker.linew  s     {{r   c                     | j                   S )z^The current character column from the beginning of the
        document, starts at 0.
        )r  r   s    r   r  zposition_marker.column|  s    
 }}r   c                     | j                   S )z^The current character offset from the beginning of the
        document, starts at 0.
        )r  r   s    r   char_positionzposition_marker.char_position  s    
 ###r   c                      | j                   dk(  S )z=Returns True if the position is at the start of the document.r   )r  r   s    r   at_startzposition_marker.at_start  s     !!Q&&r   c                     | j                   S )ztReturns True if the position is at the end of the document.

        This property must be set by the user.
        r  r   s    r   at_endzposition_marker.at_end       }}r   c                 $    t        |      | _        y)z*Sets the at_end property to True or False.N)r  r  )r   rQ   s     r   r  zposition_marker.at_end  s     Qr   c                     | j                   S )ztReturns a textual excerpt starting at the current position.

        This property must be set by the user.
        r  r   s    r   r  zposition_marker.text_after  r  r   c                     || _         y)z/Sets the text_after property to a given string.N)r  )r   values     r   r  zposition_marker.text_after  s     "r   c                     | j                   j                  d| j                  d| j                  d| j                  }| j
                  r|d| j
                  z  }|dz  }|S )Nz(offset=z,line=z,column=z,text_after=))r   r   r  r  r  r  r   rY   s     r   re   zposition_marker.__repr__  sU    NN##  KKMM	
 ??T__66A	Sr   c                     d| j                   | j                  | j                  fz  }| j                  r|dz  }n| j                  r|dz  }|r| j
                  r|d| j
                  z  z  }|S )zAReturns a human-readable description of the position, in English.zline %d, column %d, offset %dz (AT-START)z	 (AT-END)z	, text %r)r  r  r  r  r  r  )r   	show_textrY   s      r   describezposition_marker.describe  sm    +KKMM  /
 

 ==A[[A00Ar   c                 &    | j                  d      S )z Same as the describe() function.Tr  )r   r   s    r   rh   zposition_marker.__str__  s    }}t},,r   c                     | j                         }| j                  |_        | j                  |_        | j                  |_        | j                  |_        | j                  |_        | j                  |_        |S )z%Create a copy of the position object.)r   r  r  r  r  r  r  r  r   ps     r   copyzposition_marker.copy  s\    NN 00;;]]
((;;,,r   c                 p    | j                   sd| _        d| _        d| _        d| _        d| _        d| _        y)z.Set the position to the start of the document.NFr   r
   )r  r  r  r  r  r  r  r   s    r   rewindzposition_marker.rewind  s5    }}"DODK "r   c                 0   |rd| _         |D ]  }| xj                  dz  c_        |dk(  r| j                  rd| _        1t        j	                  |      r'| xj
                  dz  c_        d| _        |dk(  | _        m| xj                  dz  c_        d| _         y)zjAdvance the position from its current place according to
        the given string of characters.

        Nr
   
Fr   )r  r  r  r   rn  r  r  )r   rY   r   s      r   advancezposition_marker.advance  s    
 "DO 
	+A  A% DyT//%*",,Q/q  !%&$Y""%*"
	+r   )r   r
   r   NT)r   r   r   r    r  r   r  r  r  r  r  setterr  re   r   rh   r  r  r  r   r   r   r  r  S  s    6#     $ $ ' '   ]]      " "
-	#+r   r  c                   D   e Zd ZdZd&dZd Zd Zd Zd Zd Z	d'd	Z
d
 Zd Zed        Zed        Zed        Zed        Zed        Zed        Zd(dZd(dZd)dZd*dZed+d       Zd Zd,dZd Zd Zd(dZd(dZd Zd*dZ d Z!d  Z"d'd!Z#d" Z$d'd#Z%d'd$Z&d% Z'y)-buffered_streamzA helper class for the JSON parser.

    It allows for reading an input document, while handling some
    low-level Unicode issues as well as tracking the current position
    in terms of line and column position.

    Nc                 H    | j                          | j                  ||       y r   )resetset_text)r   ry  r  s      r   r  zbuffered_stream.__init__  s    

c8$r   c                     t               | _        g | _        t        j	                  g       | _        d| _        d| _        d| _        d| _	        d| _
        d| _        d| _        y)zClears the state to nothing.NFr   )r  _buffered_stream__pos_buffered_stream__saved_posr   rT  _buffered_stream__bom_buffered_stream__codec_buffered_stream__encoding _buffered_stream__input_is_bytes_buffered_stream__rawbuf_buffered_stream__raw_bytes_buffered_stream__cmaxnum_ws_skippedr   s    r   r  zbuffered_stream.reset  s_    $&
++

  %r   c                 j    | j                   j                  | j                  j                                y)NT)r  r   r  r  r   s    r   save_positionzbuffered_stream.save_position  s$    

 12r   c                 R    | j                   r| j                   j                          yyNTF)r  popr   s    r   clear_saved_positionz$buffered_stream.clear_saved_position  s#      "r   c                     	 | j                   j                         }|| _        y# t        $ r}t        d      |d }~ww xY w)NTz7Attempt to restore buffer position that was never saved)r  r#  r  
IndexError)r   old_poserrs      r   restore_positionz buffered_stream.restore_position  sJ    	&&**,G !DJ	  	aVW]``	as   $ 	>9>c                 T   |d | _         d | _        | j                   S t        |t        j                        r.|| _         | j                   j
                  | _        | j                   S || _        t        j                  |      | _         | j                   st        d|      | j                   S )N)no codec available for character encoding)	r  r  r>   r   r   r   r   r  r  )r   r  s     r   _find_codeczbuffered_stream._find_codec&  s    DL"DO || &"2"23#DL"ll//DO || 'DO"//9DL<<%?  ||r   c                 t   | j                          d| _        d| _        d| _        d| _        	 t
        j                  ||      }|j                  | _        |j                  | _        |j                  | _        t        | j                        | _        y# t        $ r  t        $ r}t        d      }||d}~ww xY w)zlChanges the input text document and rewinds the position to
        the start of the new document.

        Nr  r   z!a Unicode decoding error occurred)r  r  r  r  r  r   r  r  r  r  r   	JSONError	Exceptionr  )r   ry  r  decodedr(  newerrs         r   r  zbuffered_stream.set_text6  s     	
	-,,S(;G #==DL DJ#NNDMdmm,DK  	 	"$%HIFc!	"s   B B7$B22B7c                 j    d| j                   j                  d| j                  d| j                  dS )N<z at z text >)r   r   r  text_contextr   s    r   re   zbuffered_stream.__repr__O  s)    NN##JJ
 	
r   c                 8    | j                   j                          y)z8Resets the position back to the start of the input text.N)r  r  r   s    r   r  zbuffered_stream.rewindV  s    

r   c                     | j                   S )z;The codec object used to perform Unicode decoding, or None.)r  r   s    r   r  zbuffered_stream.codecZ  s     ||r   c                     | j                   S )zThe Unicode Byte-Order Mark (BOM), if any, that was present
        at the start of the input text.  The returned BOM is a string
        of the raw bytes, and is not Unicode-decoded.

        )r  r   s    r   r  zbuffered_stream.bom_  s     zzr   c                 .    | j                   j                  S )z<The current character offset from the start of the document.)r  r  r   s    r   cposzbuffered_stream.cposh  s     zz'''r   c                 ~    | j                   j                         }| j                  |_        | j                  |_        |S )zUThe current position (as a position_marker object).
        Returns a copy.

        )r  r  r5  r  r  r  s     r   positionzbuffered_stream.positionm  s1     JJOO((;;r   c                 .    | j                   j                  S )zmReturns True if the position is currently at the start of
        the document, or False otherwise.

        )r  r  r   s    r   r  zbuffered_stream.at_startx  s     zz"""r   c                 (    | j                         }| S )zkReturns True if the position is currently at the end of the
        document, of False otherwise.

        )peekr   r   s     r   r  zbuffered_stream.at_end  s     IIKur   c                     | j                         }|sy|rt        j                  |      S t        j                  |      S )zXReturns True if the current position contains a white-space
        character.

        F)r?  r   rj  r`  )r   allow_unicode_whitespacer   s      r   at_wszbuffered_stream.at_ws  s:    
 IIK%--a00**1--r   c                     | j                         }|sy|rt        j                  |      S t        j                  |      S )zaReturns True if the current position contains an
        end-of-line control character.

        T)r?  r   rn  rl  )r   allow_unicode_eolr   s      r   at_eolzbuffered_stream.at_eol  s:    
 IIK..q11++A..r   c                 h    | j                   |z   }|dk  s|| j                  k\  ry| j                  |   S )zReturns the character at the current position, or at a
        given offset away from the current position.  If the position
        is beyond the limits of the document size, then an empty
        string '' is returned.

        r   r  r:  r  r  )r   r  r   s      r   r?  zbuffered_stream.peek  s6     IIq5A$}}Qr   c                 r    | j                   |z   }||z   }|dk  s|| j                  k\  ry| j                  || S )ad  Returns one or more characters starting at the current
        position, or at a given offset away from the current position,
        and continuing for the given span length.  If the offset and
        span go outside the limit of the current document size, then
        the returned string may be shorter than the requested span
        length.

        r   r  rH  )r   spanr  r   js        r   peekstrzbuffered_stream.peekstr  sA     IIHq5A$}}Qq!!r   c                 ~    t        |d      }| j                  |dz         }|syt        |      |kD  r|d|dz
   dz   }|S )zmA short human-readable textual excerpt of the document at
        the current position, in English.

        r   r
   r  Nr   ...)maxrL  r   )r   context_sizerY   s      r   r5  zbuffered_stream.text_context  sQ     <+LL)*q6L $L1$%-Ar   c                 @    | j                  t        |            }||k(  S )zDetermines if the text at the current position starts with
        the given string.

        See also method: pop_if_startswith()

        )rL  r   r   rY   s2s      r   r  zbuffered_stream.startswith  s     \\#a&!Bwr   c                     | j                   }| j                  j                  | j                  |             | j                   |z
  S )zAdvances the current position by one (or the given number)
        of characters.  Will not advance beyond the end of the
        document.  Returns the number of characters skipped.

        )r:  r  r  rL  )r   rJ  r   s      r   skipzbuffered_stream.skip  s6     II

4<<-.yy1}r   c                     | j                   }	 | j                         }|r ||      rn| j                  j                  |       7| j                   |z
  S )a  Advances the current position until a given predicate test
        function succeeds, or the end of the document is reached.

        Returns the actual number of characters skipped.

        The provided test function should take a single unicode
        character and return a boolean value, such as:

            lambda c : c == '.'   # Skip to next period

        See also methods: skipwhile() and popuntil()

        )r:  r?  r  r  )r   testfnr   r   s       r   	skipuntilzbuffered_stream.skipuntil  sN     II		Aq	

""1%  yy1}r   c                 ,    | j                  fd      S )a  Advances the current position until a given predicate test
        function fails, or the end of the document is reached.

        Returns the actual number of characters skipped.

        The provided test function should take a single unicode
        character and return a boolean value, such as:

            lambda c : c.isdigit()   # Skip all digits

        See also methods: skipuntil() and popwhile()

        c                      |        S r   r   r   rW  s    r   r'   z+buffered_stream.skipwhile.<locals>.<lambda>  s    F1I r   )rX  )r   rW  s    `r   	skipwhilezbuffered_stream.skipwhile  s     ~~566r   c                     | j                   j                  }	 | j                         }|r| j                   j                  |kD  r)|dk(  r#| j                         dk(  r| j	                          yU)zAdvances the current position to the start of the next
        line.  Will not advance beyond the end of the file.  Note that
        the two-character sequence CR+LF is recognized as being just a
        single end-of-line marker.

        r  r
  N)r  r  r#  r?  rU  )r   rE  lnr   s       r   skip_to_next_linez!buffered_stream.skip_to_next_line  sV     ZZ__
A

",9!4IIK r   c                     |r | j                  t        j                        }n| j                  t        j                        }| xj                  |z  c_        |S )zqAdvances the current position past all whitespace, or until
        the end of the document is reached.

        )r\  r   rj  r`  r  )r   rB  r&   s      r   skipwszbuffered_stream.skipws  sE    
 $w99:Aw667Aq r   c                 `    | j                         }|r| j                  j                  |       |S )zReturns the character at the current position and advances
        the position to the next character.  At the end of the
        document this function returns an empty string.

        r?  r  r  r@  s     r   r#  zbuffered_stream.pop#  s)     IIKJJq!r   c                 b    | j                  |      }|r| j                  j                  |       |S )a'  Returns a string of one or more characters starting at the
        current position, and advances the position to the following
        character after the span.  Will not go beyond the end of the
        document, so the returned string may be shorter than the
        requested span.

        )rL  r  r  )r   rJ  r  rY   s       r   popstrzbuffered_stream.popstr.  s,     LLJJq!r   c                 r    | j                         }|r% ||      r| j                  j                  |       |S y)z|Just like the pop() function, but only returns the
        character if the given predicate test function succeeds.
        r  rc  )r   rW  r   s      r   popifzbuffered_stream.popif;  s2     IIKJJq!Hr   c                     t        t        t        f      st              | j                         }|r|v r| j	                  fd      }|S y)zPops a sequence of characters at the current position
        as long as each of them is in the given set of characters.

        c                     | xr | v S r   r   )r   r  s    r   r'   z.buffered_stream.pop_while_in.<locals>.<lambda>N  s    (8a5j r   N)r>   setr  r?  popwhile)r   r  r   rY   s    `  r   pop_while_inzbuffered_stream.pop_while_inE  sH    
 %#y!12JEIIKe89AHr   c                     | j                         }|r6t        j                  |      r!| j                  t        j                        }|S y)z|Pops the sequence of characters at the current position
        that match the syntax for a JavaScript identifier.

        N)r?  r   rr  rk  rv  )r   matchr   rY   s       r   pop_identifierzbuffered_stream.pop_identifierR  s;    
 IIK2215g==>AHr   c                 |    | j                  t        |            }||k7  ry| j                  j                  |       |S )zpPops the sequence of characters if they match the given string.

        See also method: startswith()

        N)rL  r   r  r  rR  s      r   pop_if_startswithz!buffered_stream.pop_if_startswith]  s7     \\#a&!7

2	r   c                     g }d}|||k  r3| j                  |      }|sn|j                  |       |dz  }|-||k  r3dj                  |      S )ak  Pops all the characters starting at the current position as
        long as each character passes the given predicate function
        test.  If maxchars a numeric value instead of None then then
        no more than that number of characters will be popped
        regardless of the predicate test.

        See also methods: skipwhile() and popuntil()

        r   r
   r  )rg  r   r  )r   rW  maxcharsrY   r   r   s         r   rk  zbuffered_stream.popwhilei  s`     !h,

6"AHHQKFA !h, wwqzr   c                 0    | j                  fd|      S )zJust like popwhile() method except the predicate function
        should return True to stop the sequence rather than False.

        See also methods: skipuntil() and popwhile()

        c                      |        S r   r   r[  s    r   r'   z*buffered_stream.popuntil.<locals>.<lambda>  s    6!9} r   rs  )rk  )r   rW  rs  s    ` r   popuntilzbuffered_stream.popuntil}  s     }}4x}HHr   c                     t        |t              r3| j                  |j                  |j                  z
  |j                        S | j                  |      S )a  Returns the character at the given index relative to the current position.

        If the index goes beyond the end of the input, or prior to the
        start when negative, then '' is returned.

        If the index provided is a slice object, then that range of
        characters is returned as a string. Note that a stride value other
        than 1 is not supported in the slice.  To use a slice, do:

            s = my_stream[ 1:4 ]

        )r>   slicerL  stopr   r?  )r   indexs     r   __getitem__zbuffered_stream.__getitem__  s?     eU#<<

U[[ 8%++FF99U##r   )r  Nr   r  r   r
   r   )   )r
   )(r   r   r   r    r  r  r   r$  r)  r,  r  re   r  r   r  r  r:  r<  r  r  rC  rF  r?  rL  r5  r  rU  rX  r\  r_  ra  r#  re  rg  rl  ro  rq  rk  rw  r|  r   r   r   r  r    s    %  -2
     ( (   # #  ./
 "  	.7 
		
(I$r   r  c                       e Zd ZdZy)JSONExceptionz+Base class for all JSON-related exceptions.Nr   r   r   r    r   r   r   r  r    s    5r   r  c                       e Zd ZdZy)JSONSkipHookzAn exception to be raised by user-defined code within hook
    callbacks to indicate the callback does not want to handle the
    situation.

    Nr  r   r   r   r  r         	r   r  c                       e Zd ZdZy)JSONStopProcessingzCan be raised by anyplace, including inside a hook function, to
    cause the entire encode or decode process to immediately stop
    with an error.

    Nr  r   r   r   r  r    r  r   r  c                       e Zd Zy)	JSONAbortN)r   r   r   r   r   r   r  r    s    r   r  c                   x     e Zd ZdZ eg d      Z fdZed        Zej                  d        Zd Z
ddZ xZS )	r.  a|  Base class for all JSON-related errors.

    In addition to standard Python exceptions, these exceptions may
    also have additional properties:

        * severity - One of: 'fatal', 'error', 'warning', 'info'
        * position - An indication of the position in the input where the error occured.
        * outer_position - A secondary position (optional) that gives
          the location of the outer data item in which the error
          occured, such as the beginning of a string or an array.
        * context_description - A string that identifies the context
          in which the error occured.  Default is "Context".
    )fatalerrorwarninginfoc                    d| _         d | _        d | _        d | _        t	        |j                               D ]  \  }}|dk(  r:|| j                  vr$t        | j                  j                  d|      || _         E|dk(  r|| _
        R|dk(  r|| _        _|dk(  s|dk(  r|| _        qt        | j                  j                  d|d	       t        t        | 6  |g|  || _        y )
Nr  severityz given invalid severity r<  outer_positioncontext_descriptioncontextz does not accept z keyword argument)r  	_positionr  r  listitems
severitiesrC   r   r   r<  r   r.  r  message)r   r  r   r   kwvalr   s         r   r  zJSONError.__init__  s    "#' FLLN+ 	GBZdoo-#:>..:Q:QSVW  !$z! #''&)#,,i+.(~~..4 	$ 	i'7$7r   c                     | j                   S r   r  r   s    r   r<  zJSONError.position  s    ~~r   c                 ,    |dk(  rd| _         y || _         y r)   r  )r   r   s     r   r<  zJSONError.position  s    !8DN DNr   c                 &   | j                   j                  d| j                  }| j                  dd  D ]
  }|d|z  } | j                  r|d| j                  z  }| j
                  r|d| j
                  z  }|d| j                  dz  }|S )N(r
   , z, position=z, outer_position=z, severity=r  )r   r   r  r   r<  r  r  )r   rY   rO   s      r   re   zJSONError.__repr__  s    ~~..=12 	A1A	==DMM33A$*=*=??A	00r   c                 t   |r#|j                         j                  d      dz   }nd}|}| j                  dk(  r|dz  }nD| j                  r3|d| j                  j                  | j                  j                  fz  z  }n|dz  }|d| j                  j                         d| j                  z  }t        | j                        d	kD  rU|dz  }t        | j                  d	d        D ]5  \  }}|d	kD  r|d
z  }t        |      }t        |      dkD  r|d d dz   }||z  }7 | }|rt        |d      rt        |j                  t              rg|j                  }t        |      j!                         }	|	st        |      j!                         }	|d|	j!                         j#                  dd      z  z  }nd }|r|ru| j                  i| j                  dk(  r|dz  }nT|d| j                  j%                  d      z  }| j                  j&                  r|d| j                  j&                  z  }|r| j(                  r| j*                  r| j*                  j                         }
nd}
|d|
d| j(                  j%                  d      z  }| j(                  j&                  r|d| j(                  j&                  z  }|S )N:r  r   z0:0:z%d:%d:z     : r
   r     rN  	__cause__z
   |  Cause: %sr
  z
   |         z
   |  At start of inputz

   |  At Fr  z
   |    near text: r?   z
   |  z started at z
   |    with text: )rstripr<  r  r  r  
capitalizer  r   r   r   r  r  r>   r  r/  rD   stripr   r   r  r  r  )r   show_positionsfilenamerN   r(  anumrO   astre2e2desccdescs              r   pretty_descriptionzJSONError.pretty_description  s   //#**3/#5CC==A6MC]]8t}}114==3G3GHHHC6MCDMM446EEtyy>A4KC$TYYqr]3 a!84KCAwt9r>9u,Dt r;'Jr||Y,O\\R!"X^^-F*V\\^-C-C+.     dmm7}}!22$--*@*@5*@*QSS==++8P8PRRCd11''00;;=!##,,u,= C ""--D4G4G4R4RTT
r   )TN)r   r   r   r    r  r  r  r   r<  r  re   r  r   r   s   @r   r.  r.    sP     @AJ4   __! !	9r   r.  c                       e Zd ZdZy)r  zKAn exception class raised when a JSON decoding error (syntax error) occurs.Nr  r   r   r   r  r  9  s    Ur   r  c                   "     e Zd ZdZ fdZ xZS )JSONDecodeHookErrorzAn exception that occured within a decoder hook.

    The original exception is available in the 'hook_exception' attribute.
    c                 p   || _         |sd}|\  }| _        | _        t        |      | _        d|d| j                   | j                  j
                  j                  nd d| j                  j                  d}t        |      dk\  r|dt        |d         z   z  }|dd  }t        t        | .  |g|i | y )	Nr  Hook  raised z while decoding type <r4  r
   r  r   )	hook_namehook_exceptionhook_tracebacktypeobject_typer   r   r   rD   r   r  r  	r   r  exc_infoencoded_objr   r   r   msgr   s	           r   r  zJSONDecodeHookError.__init__E  s    ")H=E:$%t':,"". ))22 %%
 t9>4#d1g,&&C8D!41#GGGr   r   r   r   r    r  r   r   s   @r   r  r  ?      
H Hr   r  c                       e Zd ZdZy)JSONEncodeErrorzSAn exception class raised when a python object can not be encoded as a JSON string.Nr  r   r   r   r  r  X  s    ]r   r  c                   "     e Zd ZdZ fdZ xZS )JSONEncodeHookErrorzAn exception that occured within an encoder hook.

    The original exception is available in the 'hook_exception' attribute.
    c                    || _         |sd}|\  }| _        | _        t        |      | _        d| j                   d| j                   | j                  j
                  j                  nd d| j                  j                  d}t        |      dk\  r|dt        |d         z   z  }|dd  }t        t        | .  |g|i | y )	Nr  r  r  z while encoding type <r4  r
   r  r   )r  r  r  r  r  r   r   r   rD   r   r  r  r  s	           r   r  zJSONEncodeHookError.__init__d  s    ")H=E:$%t':,NN"". ))22 %%
 t9>4#d1g,&&C8D!41#GGGr   r  r   s   @r   r  r  ^  r  r   r  c                   <    e Zd ZdZd
dZd Zd Zd Zd Zd Z	d	 Z
y)encode_statezjAn internal transient object used during JSON encoding to
    record the current construction state.

    Nc                     g | _         |sd | _        d| _        || _        d| _        y || _        |j                  dz   | _        |j                  | _        |j                  | _        y )Nr   Fr
   )chunksparent
nest_leveloptionsescape_unicode_test)r   jsoptsr  s      r   r  zencode_state.__init__  s[    DKDO!DL',D$ DK$//!3DO'-'A'AD$!>>DLr   c                     t        |       S )N)r  )r  r   s    r   make_substatezencode_state.make_substate  s    4((r   c                 \    | j                   j                  |j                          g |_         y r   )r  r   r   other_states     r   join_substatezencode_state.join_substate  s"    ;--.r   c                 :    | j                   j                  |       y)z5Adds a string to the end of the current JSON documentN)r  r   r  s     r   r   zencode_state.append  s    1r   c                 J    dj                  | j                        }g | _        |S )z<Returns the accumulated string and resets the state to emptyr  )r  r  r  s     r   combinezencode_state.combine  s     GGDKK r   c                 j    | j                   |j                   k(  xr | j                  |j                  k(  S r   r  r  r  s     r   __eq__zencode_state.__eq__  s0    OO{555 2{111	
r   c                     | j                   |j                   k7  r| j                   |j                   k  S | j                  |j                  k  S r   r  r  s     r   __lt__zencode_state.__lt__  s>    ??k444??[%;%;;;{{[////r   r/   )r   r   r   r    r  r  r  r   r  r  r  r   r   r   r  r  |  s*    
*) 
0r   r  c                   V    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZd Zed        ZddZy)decode_statisticszHAn object that records various statistics about a decoded JSON document.r  ii  i ii   l    l         l    l c                    d| _         d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _	        d| _
        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d | _        d | _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        y r)   )	max_depthmax_items_in_arraymax_items_in_objectnum_intsnum_ints_8bitnum_ints_16bitnum_ints_32bitnum_ints_53bitnum_ints_64bitnum_ints_longnum_negative_zero_intstotal_charsnum_negative_zero_floats
num_floatsnum_floats_decimalnum_stringsmax_string_lengthtotal_string_lengthmin_codepointmax_codepoint
num_arraysnum_objects	num_bools	num_nullsnum_undefinedsnum_nansnum_infinitiesnum_commentsnum_identifiersnum_excess_whitespacer   s    r   r  zdecode_statistics.__init__  s    "##$ &'#()%"#!"#$ !! %&"r   c                     | j                   S )z7Misspelled 'num_infinities' for backwards compatibility)r  r   s    r   num_infiniteszdecode_statistics.num_infinites  s     """r   c                 z   dd l }dd| j                  | j                  | j                  fz  d| j                  | j
                  | j                  fz  d| j                  | j                  | j                  fz  d| j                  | j                  | j                  fz  d| j                  | j                  | j                  fz  d| j                   z  d	| j"                  z  d
| j$                  z  dd| j&                  z  d| j(                  z  d| j&                  | j(                  z   z  d| j*                  z  dd| j,                  z  d| j.                  z  d| j0                  z  d| j2                  z  dd| j4                  z  d| j6                  z  d| j8                  z  g}| j:                  Nd| j:                  z  }	 |j=                  t?        | j:                              }|jC                  d|dd|d       n|jC                  dd z         | jD                  Nd| jD                  z  }	 |j=                  t?        | jD                              }|jC                  d!|dd|d       n|jC                  d"d z         |jG                  d#d$| jH                  z  d%| jJ                  z  d&| jL                  z  d'| jN                  z  d(| jP                  z  d)| jR                  z  d*| jT                  z  d+| jV                  z  g	       | jX                  dk(  r|jC                  d,       nE|jC                  d-| jZ                  | jX                  | jZ                  d.z  | jX                  z  fz         |r%d/j]                  |D cg c]  }||z   	 c}      d/z   S d/j]                  |      d/z   S # t@        $ r d}Y w xY w# t@        $ r d}Y qw xY wc c}w )0Nr   zNumber of integers:z    8-bit:     %5d   (%d to %d)z   16-bit:     %5d   (%d to %d)z   32-bit:     %5d   (%d to %d)z6 > 53-bit:     %5d   (%d to %d - overflows JavaScript)z   64-bit:     %5d   (%d to %d)zD > 64 bit:     %5d   (not portable, may require a "Big Num" package)z   total ints: %5dz>   Num -0:     %5d   (negative-zero integers are not portable)zNumber of floats:z   doubles:    %5dz1 > doubles:    %5d   (will overflow IEEE doubles)z   total flts: %5dz@   Num -0.0:   %5d   (negative-zero floats are usually portable)z
Number of:z   nulls:      %5dz   booleans:   %5dz   arrays:     %5dz   objects:    %5dzStrings:z   number:         %5d stringsz!   max length:     %5d charactersz)   total chars:    %5d across all stringsU+%04Xz? UNKNOWN CHARACTERz   min codepoint: z>6z  (r  z   min codepoint: %6s)zn/az   max codepoint: z   max codepoint: %6szOther JavaScript items:z   NaN:         %5dz   Infinite:    %5dz   undefined:   %5dz   Comments:    %5dz   Identifiers: %5dzMax items in any array: %5dzMax keys in any object: %5dzMax nesting depth:      %5dz-Unnecessary whitespace:     0 of 0 charactersz5Unnecessary whitespace: %5d of %d characters (%.2f%%)g      Y@r
  )/r!  r  int8_minint8_maxr  	int16_min	int16_maxr  	int32_min	int32_maxr  double_int_mindouble_int_maxr  	int64_min	int64_maxr  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r
  r8   r   r  r   r  r  r  r  r  r  r  r  r  r  r  )r   prefixr!  linescpcharnamerY   s          r   r  z$decode_statistics.pretty_description  s    "-!!4==$--@A-""DNNDNNCD-""DNNDNNCDD""D$7$79L9LMN-""DNNDNNCDR  ! 4==0L))* 4??2?%%& DOOd6M6M$MNN++, 4>>1 4>>1 4??2 4#3#33,t/?/??/$2H2HH7$:R:RRA!
F )D...B1&++C0B0B,CD LL"hGHLL08;<)D...B1&++C0B0B,CD LL"hGHLL08;<)%5%(;(;;%(;(;;%(9(99%(<(<<-0G0GG-0H0HH->
	
 q LLHILLG..$$..69I9II 99%8Qfqj89D@@99U#d**W  101  101> 9s*   1$N $N& *N8N#"N#&N54N5Nr  )r   r   r   r    r  r  r  r  r	  r  r  r  r  r
  r  r   r  r  r   r   r   r  r    sW    RHHIIII"I'I N#N#'J # #U+r   r  c                       e Zd ZdZddZd Zed        Zed        Zed        Z	ddZ
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)decode_statezxAn internal transient object used during JSON decoding to
    record the current parsing state and error messages.

    Nc                 2    | j                          || _        y r   )r  r  )r   r  s     r   r  zdecode_state.__init__N	  s    

r   c                     d| _         g | _        d| _        d| _        t	               | _        d| _        d| _        d| _        y)z.Clears all errors, statistics, and input text.Nr   F)	bufr   r   	cur_depthr  stats_have_warned_nonbmp_have_warned_long_string_have_warned_max_depthr   s    r   r  zdecode_state.resetR	  s@    &(
#( (-%&+#r   c                     | j                   ryyr"  )	has_fatalr   s    r   should_stopzdecode_state.should_stop]	  s    >>r   c                 v    t        | j                  D cg c]  }|j                  dv s| c}      dkD  S c c}w )"Have any errors been seen already?r  r  r   r   r   r  r   r(  s     r   
has_errorszdecode_state.has_errorsc	  s5     Rs||?Q/QRSVWW	
R   66c                 v    t        | j                  D cg c]  }|j                  dv s| c}      dkD  S c c}w )r   )r  r   r"  r#  s     r   r  zdecode_state.has_fatalj	  s2     4;;MC#,,*2LCMNQRRRMr%  c                 :   | j                          	 t        ||      | _        | j                  j                  r<| j	                  | j
                  j                  d| j                  j                         	 | j                  s| j                  dd	       yy# t        $ r)}d|_        d|_        | j                  |       Y d}~Nd}~wt        $ rJ}t        ddd      }	 ||# t        $ r}| j                  |       Y d}~nd}~ww xY wd| _        Y d}~d}~ww xY w)
z8Initialize the state by setting the input document text.r  z5JSON document was prefixed by a BOM (Byte Order Mark)r   r  NzError while reading inputr<  r  z%Aborting, can not read JSON document.r<  )r  r  r  r  	push_condr  r.  r<  r  push_exceptionr/  r  
push_fatal)r   ry  r  r(  r1  s        r   	set_inputzdecode_state.set_inputo	  s     	

	&sX>DH  xx||LL$$KHHLL
 xxOOCaOP +  	%CL"CL$$ 		$+a'F)#%" )##C(()DHH		sG   B 	D CDDC""	D+D<DD
DDc                 :    | j                   j                  |       y)z1Add an already-built exception to the error list.N)r   r   )r   excs     r   r,  zdecode_state.push_exception	  s    3r   c                 :    d|d<    | j                   |g|i | y)zCreate a fatal error.r  r  N_decode_state__push_errr   r  r   r   s       r   r-  zdecode_state.push_fatal	  $    $z1$1&1r   c                 :    d|d<    | j                   |g|i | y)zCreate an error.r  r  Nr2  r4  s       r   
push_errorzdecode_state.push_error	  r5  r   c                 :    d|d<    | j                   |g|i | y)zCreate a warning.r  r  Nr2  r4  s       r   push_warningzdecode_state.push_warning	  s$    &z1$1&1r   c                 :    d|d<    | j                   |g|i | y)zCreate a informational message.r  r  Nr2  r4  s       r   	push_infozdecode_state.push_info	  s$    #z1$1&1r   c                 l    |t         k(  ry|t        k(  rd|d<   nd|d<    | j                  |g|i | y)zCreates an conditional error or warning message.

        The behavior value (from json_options) controls whether
        a message will be pushed and whether it is an error
        or warning message.

        Nr  r  r  )ALLOWWARNr3  )r   behavior_valuer  r   r   s        r   r+  zdecode_state.push_cond	  sC     U"t#!*F:!(F:1$1&1r   c                 D   d}d}d}d}t        |j                               D ]5  \  }}	|dk(  r|	}|dk(  r|	}|dk(  r|	}|dk(  s|dk(  r|	}+t        d|       |"| j                  r| j                  j                  }t        |g|||||d	}
| j                  |
       y)
z"Stores an error in the error list.Nr  r<  r  r  r  r  zUnknown keyword argument)r<  r  r  r  )r  r  rC   r  r<  r  r,  )r   r  r   r   r<  r  r  r  r  r  r(  s              r   
__push_errzdecode_state.__push_err	  s    "FLLN+ 
	@GBZ''!$z!,,i&)# :B??
	@ xx((H
 
) 3
 	C r   c                 P   | j                   }t        |j                  | j                        |_        | j                  si| j                  | j
                  j                  kD  rEd| _        | j                  | j
                  j                  d| j
                  j                  z         y y y )NTzBArrays or objects nested deeper than %d levels may not be portable)	r  rO  r  r  r  r  warn_max_depthr+  non_portabler   r   sts      r   update_depth_statszdecode_state.update_depth_stats	  s    ZZ2<<8++!<!<<*.D'NN))T,,--. = ,r   c                 x   | j                   }|xj                  dz  c_        t        |j                  t	        |            |_        |xj
                  t	        |      z  c_        | j                  j                  rtt	        |      | j                  j                  kD  rR| j                  sFd| _         | j                  | j                  j                  d| j                  j                  z  fi | t	        |      dkD  rt        t        |            }t        t        |            }|j                  ||_        ||_        n6t        |j                  |      |_        t        |j                  |      |_        |dkD  r@| j                  s3d| _         | j                  | j                  j                  d|z  fi | y y y y )Nr
   Tz*Strings longer than %d may not be portabler   r  zBStrings containing non-BMP characters (U+%04X) may not be portable)r  r  rO  r  r   r  r  warn_string_lengthr  r+  rD  r   r  r  r  r  )r   rY   r   rF  mincpmaxcps         r   update_string_statsz decode_state.update_string_stats	  su   ZZ
!"2#7#7Q@
#a&(LL++A88811,0D)DNN))<,,112 	 q6A:AKEAKE'#( #( #&r'7'7#? #&r'7'7#? v~d&>&>+/(LL--X 	 '?~ r   c                     | j                   }|xj                  dz  c_        |j                  dk(  r) | j                  | j                  j                  dfi | y y )Nr
   z4Negative zero (-0) integers are usually not portable)r  r  r+  r  rD  rE  s      r   update_negzero_int_statsz%decode_state.update_negzero_int_stats
  sW    ZZ
!!Q&!$$)DNN))F  *r   c                     | j                   }|xj                  dz  c_        |j                  dk(  r) | j                  | j                  j                  dfi | y y )Nr
   z0Negative zero (-0.0) numbers may not be portable)r  r  r+  r  rD  rE  s      r   update_negzero_float_statsz'decode_state.update_negzero_float_stats
  sW    ZZ
##q(#&&!+DNN))B  ,r   c                    | j                   }d|v r|d= t        j                  |      r | j                  di | t        j	                  |      r|xj
                  dz  c_        t        |t        j                        rN|xj                  dz  c_	        |j                  dk(  r) | j                  | j                  j                  dfi | y y t        |t              r|xj                  dz  c_        y y )Nsignr
   zGFloats larger or more precise than an IEEE "double" may not be portabler   )r  r   r  rP  r  r  r>   r9   r<   r  r+  r  rD  rB   r  )r   float_valuer   rF  s       r   update_float_statszdecode_state.update_float_stats
  s    ZZVvk*+D++5f5{+"k7??3!!Q&!$$)LL--]  * U+MMQM ,r   c                    |j                  dd      }d|v r|d= |dk(  r|dk  r | j                  di | |dk  r| }| j                  }|xj                  dz  c_        |j                  |cxk  r|j
                  k  rn n|xj                  dz  c_        n|j                  |cxk  r|j                  k  rn n|xj                  dz  c_	        n|j                  |cxk  r|j                  k  rn n|xj                  dz  c_        nM|j                  |cxk  r|j                  k  rn n|xj                  dz  c_        n|xj                   dz  c_        ||j"                  k  s|j$                  |k  rN|xj&                  dz  c_        |j&                  dk(  r) | j(                  | j*                  j,                  dfi | y y y )NrR  r
   r   z-Integers larger than 53-bits are not portabler   )getrN  r  r  r  r  r  r  r  r  r  r	  r  r  r  r  r  r
  r  r  r+  r  rD  )r   	int_valuer   rR  rF  s        r   update_integer_statsz!decode_state.update_integer_stats-
  s|   zz&!$Vv>dQh)D))3F3!8"
IZZ
q;;)2r{{2!\\Y6",,6"\\Y6",,6"\\Y6",,6"!r(((B,=,=	,I"  A%LL--C  & -Jr   r   )r   r   r   r    r  r  r   r  r$  r  r.  r,  r-  r7  r9  r;  r+  r3  rG  rL  rN  rP  rT  rX  r   r   r   r  r  H	  s    
	,  
 
 
 S SQ< 2
2
2
2
2 !:!F,r   r  r   warntolerantallowforbidr  rB   r9   r  legacyoctaloctalbinaryc                   "     e Zd ZdZ fdZ xZS )_behaviors_metaclassa  Meta class used to establish a set of "behavior" options.

    Classes that use this meta class must defined a class-level
    variable called '_behaviors' that is a list of tuples, each of
    which describes one behavior and is like: (behavior_name,
    documentation).  Also define a second class-level variable called
    '_behavior_values' which is a list of the permitted values for
    each behavior, each being strings.

    For each behavior (e.g., pretty), and for each value (e.g.,
    yes) the following methods/properties will be created:

      * pretty - value of 'pretty' behavior (read-write)
      * ispretty_yes - returns True if 'pretty' is 'yes'

    For each value (e.g., pink) the following methods/properties
    will be created:

      * all_behaviors - set of all behaviors (read-only)
      * pink_behaviors - set of behaviors with value of 'pink' (read-only)
      * set_all('pink')
      * set_all_pink()    - set all behaviors to value of 'pink'

    c                 ,   |j                  d      }t        d d      |d<   |j                  d      }d }||d<   d	 }||d
<   d }||d<   |D ]  \  }	}
d|d|	z   <   |D ]f  }|dz   |	z   }|	|fd}t        ||j                         dz   |
z         |d|z   <   |	|fd}||_        d|	z   dz   |z   dz   |_        |||j                  <   h |	fd}|	fd}t        |||
      ||	<    t        d        }||d<   d |d<   d |d<   |D ]k  }|fd}t        |d |z   dz         ||dz   <   |ffd!	}d"|z   |_        d#|z   dz   |_        |||j                  <   t        |ffd$	d%|z   dz         |d&|z   <   m d' }||d(<   t
        t        |   | |||      S ))N_behavior_valuesc                 ,    t        | j                        S r   )rj  rc  r   s    r   r'   z._behaviors_metaclass.__new__.<locals>.<lambda>
  s    T223 r   zSet of possible behavior values)docvalues
_behaviorsc                 T    	 t        | d|z         S # t        $ r t        d|      w xY w)z&Returns the value for a given behavior
_behavior_Unknown behavior)getattrAttributeErrorr8   r   r   s     r   get_behaviorz2_behaviors_metaclass.__new__.<locals>.get_behavior
  s6    ;t\D%899! ; !3T::;s    'rn  c                     || j                   vrt        d|      d|z   }t        | |      rt        | ||       yt        d|      )z&Changes the value for a given behaviorzUnknown value for behaviorri  rj  N)rc  r8   r  setattr)r   r   r  varnames       r   set_behaviorz2_behaviors_metaclass.__new__.<locals>.set_behavior
  sL    D111 !=uEE"T)GtW%gu- !3T::r   rr  c                 T    | j                   D ]  \  }}||k(  s|c S  t        d|      )z-Returns documentation about a given behavior.zNo such behavior)rg  rl  )r   r   r&   re  s       r   describe_behaviorz7_behaviors_metaclass.__new__.<locals>.describe_behavior
  s5    // ?39J? %%7>>r   rt  Tri  _c                 *    | j                  |      |k(  S r   rn  )r   r   forvals      r   getxz*_behaviors_metaclass.__new__.<locals>.getx
  s    ,,T2f<<r   r  is_c                 &    | j                  ||      S r   rr  )r   _name_values      r   r'   z._behaviors_metaclass.__new__.<locals>.<lambda>
  s    4;L;L6< r   zSet behavior z to .c                 $    | j                  |      S r   rw  rm  s     r   get_value_for_behaviorz<_behaviors_metaclass.__new__.<locals>.get_value_for_behavior
  s    ((..r   c                 (    | j                  ||       y r   r|  r   r  r   s      r   set_value_for_behaviorz<_behaviors_metaclass.__new__.<locals>.set_value_for_behavior
  s    !!$.r   c                 X    t        | j                  D cg c]  }|d   	 c}      S c c}w )z)Returns the names of all known behaviors.r   )rj  rg  )r   ts     r   all_behaviorsz3_behaviors_metaclass.__new__.<locals>.all_behaviors
  s%     doo6!6776s   'r  c                 z    || j                   vrt        d|      | j                  D ]  }t        | d|z   |        y)z.Changes all behaviors to have the given value.rj  ri  N)rc  r8   r  rp  r  s      r   set_allz-_behaviors_metaclass.__new__.<locals>.set_all
  sD    D111 !3U;;** :lT159:r   r  c                     || j                   vrt        d|      | j                  D ]  }t        | d|z         |k7  s y y)z5Determines if all the behaviors have the given value.rj  ri  FT)rc  r8   r  rk  r  s      r   is_allz,_behaviors_metaclass.__new__.<locals>.is_all
  sO    D111 !3U;;** !4!45> ! r   r  c           	      p    t        | j                  D cg c]  }t        | |      |k(  r| c}      S c c}w r   )rj  r  rk  r  s      r   getbehaviorsforz5_behaviors_metaclass.__new__.<locals>.getbehaviorsfor
  sA     %)$6$6 "4.%7  s   3z+Return the set of behaviors with the value c                      | |      S r   r   )r   r~  r  s     r   r'   z._behaviors_metaclass.__new__.<locals>.<lambda>
  s    74+@ r   set_all_zSet all behaviors to value c                      | |      S r   r   )r   r`   r  s     r   r'   z._behaviors_metaclass.__new__.<locals>.<lambda>
  s    &q/ r   z/Determines if all the behaviors have the value is_all_c                 h    | j                   |j                   k7  ry| j                  |j                  k(  S )z1Determines if two options objects are equivalent.F)r  allowed_behaviorsr   others     r   behaviors_eqz2_behaviors_metaclass.__new__.<locals>.behaviors_eq
  s0    !!U%8%88))U-D-DDDr   r  )rV  r   r  r   r    r   ra  r   )r   clsnamebasesattrsrf  	behaviorsrn  rr  rt  r   re  r`   vsry  fnsetr  r  r  r  setfnr  r  r  r   s                        @@r   r   z_behaviors_metaclass.__new__
  sJ   -."31
h IIl+		; !-n	; !-n	? &7!"" 	ID#)-E,%& .Wt^$( = %-allns2S8%ebj! ,0  "$ /$ 6 ?! Cc I(-enn%." 37 / :> / #&(>CE$K3	: 
	8 
	8 "/o	: #i	 !h 	A,-  '/AAEK'E!l"#
 )*@E'!^EN9A=CEM$)E%..!#+ 1EICO$E)a- +	4	E 'h)37WeUSSr   )r   r   r   r    r   r   r   s   @r   ra  ra  h
  s    2AT ATr   ra  nonepreservealphaalpha_cismartz*Do not sort, resulting order may be randomz)Preserve original order when reformattingzSort strictly alphabeticallyz$Sort alphabetically case-insensitivez-Sort alphabetically and numerically (DEFAULT)r   c                    d}d}t        d      }| sd} | S t        | t              r|| z  } | S t        | t              rt	        |       }g }d}||k  r| |   |v rNd}||k  r2| |   |v r+|dz  }|t        | |         |z
  z  }|dz  }||k  r| |   |v r+|j                  ||z         n'|j                  | |   j                                |dz  }||k  rdj                  |      } | S t        |       } | S )Nz%012d
0123456789r,   r  r   r2   r
   )r   r>   r  rD   r   r   r   r  )keynumfmtdigitsrL   keylenwordsr   nums           r   smart_sort_transformr    s&   FFs8D* J) 
C	sl& J% 
C	S&j1v&jSVv%52IC3s1v;--CFA &jSVv%5 Vc\*SV\\^,Q &j ggen J #hJr   )Enum)OrderedDictc                      e Zd ZdZeeefZdZd Z	d Z
d Zd ZddZddZd d
Zed        Zej$                  d        Zed        Zej$                  d        Zed        Zed        Zed        Zed        Zed        Zd	efdZd!dZd!dZed        Zej$                  d        Zed        Zd Zed        Z ed        Z!e!j$                  d        Z!y	)"json_optionszAOptions to determine how strict the decoder or encoder should be.))all_numeric_signsz<Numbers may be prefixed by any '+' and '-', e.g., +4, -+-+77)any_type_at_startzCA JSON document may start with any type, not just arrays or objects)commentsz2JavaScript comments, both /*...*/ and //... styles)control_char_in_stringz>Strings may contain raw control characters without \u-escaping)hex_numberszHexadecimal numbers, e.g., 0x1f)binary_numberszBinary numbers, e.g., 0b1001)octal_numberszKNew-style octal numbers, e.g., 0o731  (see leading-zeros for legacy octals))initial_decimal_pointzFFloating-point numbers may start with a decimal point (no units digit))extended_unicode_escapesz>Extended Unicode escape sequence \u{..} for non-BMP characters)js_string_escapesz=All JavaScript character \-escape sequences may be in strings)leading_zeroszFNumbers may have extra leading zeros (see --leading-zero-radix option))non_numbersz0Non-numbers may be used, such as NaN or Infinity)nonescape_characterszIUnknown character \-escape sequences stand for that character (\Q -> 'Q'))identifier_keyszHJavaScript identifiers are converted to strings when used as object keys)nonstring_keyszJValue types other than strings (or identifiers) may be used as object keys)omitted_array_elementszHArrays may have omitted/elided elements, e.g., [1,,3] == [1,undefined,3])single_quoted_stringszLStrings may be delimited with both double (") and single (') quotation marks)trailing_commaz9A final comma may end the list of array or object members)trailing_decimal_pointzUFloating-point number may end with a decimal point and no following fractional digits)undefined_valuesz,The JavaScript 'undefined' value may be used)format_control_charsz;Unicode "format control characters" may appear in the input)unicode_whitespacez:Treat any Unicode whitespace character as valid whitespace)r  zNumbers may have leading zeros)duplicate_keyszObjects may have repeated keys)	zero_bytezFStrings may contain U+0000, which may not be safe for C-based programs)r  z>A JSON document may start with a Unicode BOM (Byte Order Mark))rD  zGAnything technically valid but likely to cause data portablibity issuesc                    g d| _         t        | _        d| _        t        | _        d| _        t        | _        t        rt        j                  nd | _        d| _        d| _        d| _        d| _        d| _        d | _        d| _        d| _        d| _        d| _        d| _        d| _        t0        | _        d	| _        d
| _        d | _        d| _        d | _        y )N)leading_zero_radixencode_namedtuple_as_objectencode_enum_asencode_compactlyescape_unicodealways_escape_charsrI  rC  int_as_floatdecimal_context
float_typekeep_formatdate_formatdatetime_formattime_formattimedelta_format	sort_keysindent_amountindent_tab_widthindent_limitmax_items_per_linepy2str_encodingr  FTr   r   @   isor.   r   r
   )_plain_attrsSTRICTNESS_WARN
strictness_leading_zero_radix
SORT_SMART
_sort_keysr  NUMBER_AUTOr  r9   r=   r  r  r  _encode_enum_asr  r  r  rI  rC  r  r  r  r  
SORT_ALPHAr  r  r  r  r  r  r   s    r   reset_to_defaultszjson_options.reset_to_defaults  s    
2 *#$ $!%9@w55d +/(% $# 	  #)  $  %# ! "#  $r   c           	         | j                          d|v r
|d   | _        t        |j                               D ]  \  }}|dk(  r|| _        |dk(  r|dk(  r|s"| j                          3|dk(  s|dk(  rNt        |      sI| j                  t        d      | _        f| j                  j                  t        d             |dk(  rE|s| j                  t        |      | _        | j                  j                  t        |             |d	k(  rt        |      | _
        |d
k(  rt        |      | _        |dk(  rD|t        t        t        fv r	|| _        #t!        d|d|d| j"                  j$                        |dk(  s|dk(  rt&        s]|r|dk(  rt&        j(                  | _        {|dk(  rt&        j,                  | _        |dk(  rt&        j.                  | _        t1        |t&        j2                        r	|| _        t1        |t4              s|d   j6                  r(t5        |      }t'        j2                  |      | _        t!        d|d      |dv rt8        t:        t<        t<        t<        d|   }t1        |t>              r=|jA                  dd      jC                         D cg c]  }|jA                  dd       }}|D ]  }| jE                  ||        |jG                  d      sD|jG                  d      s3|jG                  d      s"|jG                  d       s|jG                  d!      r|jC                  dd"      \  }}|d#k(  r2|r| jE                  |t8               @| jE                  |t<               X|d$v r2|r| jE                  |t<               v| jE                  |t8               |d%k(  s|r| jE                  |t:               | jE                  |t8               || jH                  v rtK        | ||       t!        d&|d| j"                  j$                         yc c}w )'a  Set JSON encoding and decoding options.

        If 'strict' is set to True, then only strictly-conforming JSON
        output will be produced.  Note that this means that some types
        of values may not be convertable and will result in a
        JSONEncodeError exception.

        If 'compactly' is set to True, then the resulting string will
        have all extraneous white space removed; if False then the
        string will be "pretty printed" with whitespace and indentation
        added to make it more readable.

        If 'escape_unicode' is set to True, then all non-ASCII characters
        will be represented as a unicode escape sequence; if False then
        the actual real unicode character will be inserted if possible.

        The 'escape_unicode' can also be a function, which when called
        with a single argument of a unicode character will return True
        if the character should be escaped or False if it should not.

        r   	compactlywarnings	html_safexml_safeNz<>/&always_escaper  r  r  zUnknown option z for argument z to initialize r9   r  r.  basicextendedr   )preczOption for zi should be a decimal.Context, a number of significant digits, or one of 'default','basic', or 'extended'.)r[  rY  r\  preventdeny,r  r1   ru  allow_forbid_prevent_deny_warn_r
   r[  )r\  r  r  rY  zUnknown keyword argument )&r  r  r  r  r  suppress_warningsr  r  rj  updater  r  r  NUMBER_FLOATNUMBER_DECIMALr  r8   r   r   r9   r=   r  BasicContextExtendedContextr>   r?   r  rE   r=  r>  FORBIDrD   r   splitrr  r  r  rp  )r   r   r  r  r  actionrQ   behaviors           r   r  zjson_options.__init__  s   , 	 v$X.DOFLLN+ [	GB[ (+%xz!**,{"bJ&69//736v;00077FD&//736s800077CA~%$(I!}$#'9 |#;nEE&)DO$DNN$;$;=  yB*;$;#"2/6/E/E,/6/C/C,
*/6/F/F,#C9/2,#C-Q"3x/6D/I,(!$  EE" $%"  c3'8;C8M8S8S8UV1199S#.VCV # 8H%%h78 h'==+==,==)==)#%88C#3 W$))(E:))(F;<<))(F;))(E:v%))(D9))(E:t(((b#& 4>>224 q[	v Ws   9Qc                 H    | j                         }|j                  |        |S r   )r   	copy_fromr  s     r   r  zjson_options.copyL  s     r   c                    | |u ry |j                   | _         | j                  D ]#  }| j                  ||j                  |             % | j                  D ]q  }t        ||      }t        |t              r|j                         }n5t        r/t        |t        j                        rt        j                  |      }t        | ||       s y r   )r  r  rr  rn  r  rk  r>   rj  r  r9   r<   rp  )r   r  r   r  s       r   r  zjson_options.copy_fromQ  s    5=**&& 	>DdE$6$6t$<=	> %% 	%D%&C#s#hhjZW__=ooc*D$$	%r   c                 P    | j                   |z
  }|dk  rd}t        ||      }d|z  S )Nr   r  )r  rO  )r   
min_spacessubtractr&   s       r   spaces_to_next_indent_levelz(json_options.spaces_to_next_indent_levelc  s3    )q5A
AQwr   c                     | j                   || j                   kD  r| j                   }n|}|| j                  z  }| j                  r$t        || j                        \  }}d|z  d|z  z   S d|z  S )z/Returns a whitespace string used for indenting.r  r  )r  r  r  r  )r   levelr&   twsws        r   indentation_for_levelz"json_options.indentation_for_levelj  sv    (UT5F5F-F!!AA	T  At445FB"9sRx''7Nr   Nc                 f    t        |      }|dk  rt        d|      || _        || _        || _        y)a  Changes the indentation properties when outputting JSON in non-compact mode.

        'num_spaces' is the number of spaces to insert for each level
        of indentation, which defaults to 2.

        'tab_width', if not 0, is the number of spaces which is equivalent
        to one tab character.  Tabs will be output where possible rather
        than runs of spaces.

        'limit', if not None, is the maximum indentation level after
        which no further indentation will be output.

        r   z&indentation amount can not be negativeN)r  r8   r  r  r  )r   
num_spaces	tab_widthlimitr&   s        r   
set_indentzjson_options.set_indentw  s:     
Oq5EqII )!r   c                     | j                   S )z:The method used to sort dictionary keys when encoding JSON)r  r   s    r   r  zjson_options.sort_keys  s     r   c                     |st         | _        y t        |      r|| _        y |t        v r|| _        y |t        v rt        |   | _        y |rt
        | _        y t        d|z        )NzNot a valid sorting method: %r)	SORT_NONEr  callablesorting_methodssorting_method_aliasesr  r8   )r   methods     r   r  zjson_options.sort_keys  sZ    'DOf$DO&$DO--4V<DO(DO=FGGr   c                     | j                   S )z-The strategy for encoding Python Enum values.)r  r   s    r   r  zjson_options.encode_enum_as  s     ###r   c                 0    |dvrt        d      || _        y )N)r   qnamer  z8encode_enum_as must be one of 'name','qname', or 'value')r8   r  )r   r  s     r   r  zjson_options.encode_enum_as  s    00WXX"r   c                 `    | j                   t        k(  r| j                  j                  d      S y)z3The numeric value 0.0, either a float or a decimal.r*   r  r  r  r  r@   r   s    r   
zero_floatzjson_options.zero_float  s*     ??n,''66u==r   c                 `    | j                   t        k(  r| j                  j                  d      S y)z4The numeric value -0.0, either a float or a decimal.z-0.0       r   r   s    r   negzero_floatzjson_options.negzero_float  s*     ??n,''66v>>r   c                 j    | j                   t        k(  r| j                  j                  d      S t        S )z3The numeric value NaN, either a float or a decimal.rx   )r  r  r  r@   rm   r   s    r   rm   zjson_options.nan  s,     ??n,''66u==Jr   c                 j    | j                   t        k(  r| j                  j                  d      S t        S )z8The numeric value Infinity, either a float or a decimal.ry   )r  r  r  r@   rn   r   s    r   rn   zjson_options.inf  s,     ??n,''66zBBJr   c                 j    | j                   t        k(  r| j                  j                  d      S t        S )z9The numeric value -Infinity, either a float or a decimal.rz   )r  r  r  r@   r   r   s    r   r   zjson_options.neginf  s,     ??n,''66{CCMr   c                    t        |t              r
|dk  rd}nd}t        |t              r,|j                  d      s|j                  d      r
|d   }|dd }| j                  rmt        |t              r| j
                  t        k(  r3| j                  j                  |      }|dk(  r|j                         }no|dk(  r|dk(  r| j                  }nWd|cxk  rdk  rn nt        |      }|dk(  r8|dz  }n1t        |      }|t        k(  st        |      |k7  rD| j
                  t        k7  r1| j                  j                  |      }|dk(  r|j                         }n|dk(  r|dz  }n| j                  ||      }| j                  |dd |d   d	k  rd
ndz   |      }|t        k(  s||k(  r~| j
                  t        k7  rk| j                  ||      }nXt        |t              r|}|dk(  rA|dk(  r| j                  }n/|dz  }n)	 t        |      }|dk(  r|dk(  r| j                  }n|dz  }	 t        |t              r| j$                  rt'        ||      }|S # t         $ r | j"                  }Y Bw xY w)zMakes an integer value according to the current options.

        First argument should be a string representation of the number,
        or an integer.

        Returns a number value, which could be an int, float, or decimal.

        r   r1   r0   r
   NlI5 l   I5 rw   5r  r,   r   )r>   r  rD   r  r  r  r  r  r@   copy_negater$  rB   rn   r  
make_floatmake_decimalr8   rm   r  r   )r   rY   rR  r   r&   r  s         r   make_intzjson_options.make_int  s7    dC axa||C ALL$5tabE!S!??n4,,;;A>As{MMO!V**A%=o=aAs{RaASCFaKT__5T 00??B3; !AROOAt,__QsVaesls%LdSHRT__-L))!T2A3As{6**AGA	 F 3;Av ..Ra$"2"2-8A  HHs   I I,+I,c                 P   | j                   t        k(  r| j                  ||      S |j                  d      s|j                  d      r|d   }|dd }nt	        |t
              r
|dk  rd}nd}	 | j                  j                  |      }|dk(  r|j                         }|S # t        j                  $ r | j                  j                  d      }Y |S t        j                  $ rB |dk(  r| j                  j                  d      }Y |S | j                  j                  d      }Y |S w xY w)	z0Converts a string into a decimal or float value.r1   r0   r   r
   Nrx   rz   ry   )r  r  r,  r  r>   r  r  r@   r+  r9   InvalidOperationr:   r   rY   rR  r[   s       r   r-  zjson_options.make_decimal  s"   ??l*??1d++<<S 1Q4D!"Ac"ax	$$$33A6A s{MMO '' 	;$$33E:A   	Ds{((77D 	 ((77
C 	Ds   .B   .D%2D%D%$D%c                 B   t         r%| j                  t        k(  r| j                  ||      S |j	                  d      s|j	                  d      r|d   }|dd }nt        |t              r
|dk  rd}nd}	 t        |      }|dk(  r|dz  }|S # t        $ r
 t        }Y |S w xY w)z0Converts a string into a float or decimal value.r1   r0   r   r
   Nrw   )
r9   r  r  r-  r  r>   r  rB   r8   rm   r1  s       r   r,  zjson_options.make_float4  s    t.8$$Q--<<S 1Q4D!"Ac"ax	aA s{R  	A 	s   4B BBc                     | j                   S )z=The radix to be used for numbers with leading zeros.  8 or 10r  r   s    r   r  zjson_options.leading_zero_radixK  s     '''r   c                     t        |t              r	 t        |      }|dvrt        d	      || _        y # t        $ r1 |j	                         }|dk(  s
|dk(  s|dk(  rd}n|dk(  s|dk(  rd}Y Pw xY w)
Nr^  oct8r  r9   decr2   r  r2   z.Radix must either be 8 (octal) or 10 (decimal))r>   rD   r  r8   r}  r  )r   radixs     r   r  zjson_options.leading_zero_radixP  s    eS!E
 MNN#(   G#u~#Ei'5E>Es   4 7A.-A.c                 &    ddd| j                      S )Nr^  r9   r9  r4  r   s    r   leading_zero_radix_as_wordz'json_options.leading_zero_radix_as_word_  s    	*4+C+CDDr   c                 J    | j                   D ]  }| j                  |d        y )Nr[  )warn_behaviorsrr  rm  s     r   r  zjson_options.suppress_warningsc  s'    '' 	-DdG,	-r   c                 L    | j                   j                  | j                        S )zVReturns the set of all behaviors that are not forbidden (i.e., are allowed or warned).)allow_behaviorsunionr>  r   s    r   allow_or_warn_behaviorsz$json_options.allow_or_warn_behaviorsg  s!     ##))$*=*=>>r   c                     | j                   S r   )_strictnessr   s    r   r  zjson_options.strictnessl  s    r   c                 j   |t         k(  rt         | _        | j                          n|t        k(  s|du rct        | _        d| _        | j                          | j                          | j                          | j                          | j                          n|t        k(  s|du rst        | _        | j                          | j                          | j                          | j                          d| _        | j                          | j                          nt        d|z        | j!                          y)zPChanges whether the options should be re-configured for strict JSON conformance.TFr  zUnknown strictness options %rN)r  rD  set_all_warnSTRICTNESS_STRICTr  set_all_forbidwarn_duplicate_keyswarn_zero_bytewarn_bomwarn_non_portableSTRICTNESS_TOLERANTset_all_allowwarn_leading_zerosr  allow_non_portabler8   allow_any_type_at_start)r   r   s     r   r  zjson_options.strictnessp  s     _$.D((FdN0D$D!$$&!MMO""$**fo2D $$&!##%&'D#MMO##%<vEFF$$&r   r~  r}  r   N)r0   )"r   r   r   r    r=  r>  r   rc  rg  r  r  r  r  r
  r  r  r   r  r  r  r!  r$  rm   rn   r   r   r.  r-  r,  r  r<  r  rB  r  r   r   r   r  r  :  s   KtV,TJl=$~wr
%$"*   H H $ $ # #
            $3H CJ8. ( ( ) ) E E- ? ?     ' 'r   r  )	metaclassc                   n   e Zd ZdZdZddddddd	d
dZddddddd	d
ddd
ZddddddddZddiZdZ	dZ
d Zed        Zd Zd Zd Zd  ZdDd"Zd# Zd$ Zd% Zd& Zd' Zd( Zd) Zd* Zd+ Zd, Zd- Zd. ZdEd/Zd0 Z d1 Z!d2 Z"d3 Z#d4 Z$dFd5Z%dGd6Z&d7 Z'd8 Z(d9 Z)dDd:Z*d; Z+d< Z,d= Z-d> Z.d? Z/d@ Z0dDdAZ1dB Z2dC Z3y!)HJSONa^  An encoder/decoder for JSON data streams.

    Usually you will call the encode() or decode() methods.  The other
    methods are for lower-level processing.

    Whether the JSON parser runs in strict mode (which enforces exact
    compliance with the JSON spec) or the more forgiving non-string mode
    can be affected by setting the 'strict' argument in the object's
    initialization; or by assigning True or False to the 'strict'
    property of the object.

    You can also adjust a finer-grained control over strictness by
    allowing or forbidding specific behaviors.  You can get a list of
    all the available behaviors by accessing the 'behaviors' property.
    Likewise the 'allowed_behaviors' and 'forbidden_behaviors' list which
    behaviors will be allowed and which will not.  Call the allow()
    or forbid() methods to adjust these.

    z"'r   /r   r
  r  r  )r   rV  r   rQ   r[   r&   rr  r    )
r   r   r   rQ   r[   r&   rY  r  r`   r,   z\nz\tz\bz\rz\fz\"z\\)r
  r  rW  r  rX  r   r   z\/z3{}[]"\,:0123456789.-+abcdefghijklmnopqrstuvwxyz 	
)decode_numberdecode_floatdecode_objectdecode_arraydecode_stringencode_valueencode_dictencode_dict_keyencode_sequenceencode_bytesencode_defaultc                    ddl }|j                         }| j                  D ]1  }||v r| j                  |||          ||=  | j                  |d       3 d|v r|d   | _        nt        di || _        t        dd      D cg c]I  }d|cxk  xr dk  nc xr5 t        |      | j                  vxr |j                  t        |            dvK c}| _
        yc c}w )	a  Creates a JSON encoder/decoder object.

        You may pass encoding and decoding options either by passing
        an argument named 'json_options' with an instance of a
        json_options class; or with individual keyword/values that will
        be used to initialize a new json_options object.

        You can also set hooks by using keyword arguments using the
        hook name; e.g., encode_dict=my_hook_func.

        r   Nr  r         r  r   )r!  r  all_hook_namesset_hook_optionsr  r	  r
  _rev_escapesr"  _asciiencodable)r   r   r!  hooknamer   s        r   r  zJSON.__init__  s     	++ 	.H6!hx(898$h-	. V#">2DM(262DM 1c]	 
  !McM MAd///M((Q04LLM 
  
s   ACc                     | j                   S )z{The optional behaviors used, e.g., the JSON conformance
        strictness.  Returns an instance of json_options.

        )rl  r   s    r   r  zJSON.options  r  r   c                 (    | j                  |d       y)z:Unsets a hook callback, as previously set with set_hook().N)rk  r   ro  s     r   
clear_hookzJSON.clear_hook  s    h%r   c                 H    | j                   D ]  }| j                  |        y)z=Unsets all hook callbacks, as previously set with set_hook().N)rj  rs  rr  s     r   clear_all_hookszJSON.clear_all_hooks  s#    ++ 	&HOOH%	&r   c                     || j                   v r1|dz   }|dk7  rt        |      st        d|z        t        | ||       yt        d|z        )a	  Sets a user-defined callback function used during encoding or decoding.

        The 'hookname' argument must be a string containing the name of
        one of the available hooks, listed below.

        The 'function' argument must either be None, which disables the hook,
        or a callable function.  Hooks do not stack, if you set a hook it will
        undo any previously set hook.

        Netsted values.  When decoding JSON that has nested objects or
        arrays, the decoding hooks will be called once for every
        corresponding value, even if nested.  Generally the decoding
        hooks will be called from the inner-most value outward, and
        then left to right.

        Skipping. Any hook function may raise a JSONSkipHook exception
        if it does not wish to handle the particular invocation.  This
        will have the effect of skipping the hook for that particular
        value, as if the hook was net set.

        AVAILABLE HOOKS:

        * decode_string
            Called for every JSON string literal with the
            Python-equivalent string value as an argument. Expects to
            get a Python object in return.

        * decode_float:
            Called for every JSON number that looks like a float (has
            a ".").  The string representation of the number is passed
            as an argument.  Expects to get a Python object in return.

        * decode_number:
            Called for every JSON number. The string representation of
            the number is passed as an argument.  Expects to get a
            Python object in return.  NOTE: If the number looks like a
            float and the 'decode_float' hook is set, then this hook
            will not be called.

        * decode_array:
            Called for every JSON array. A Python list is passed as
            the argument, and expects to get a Python object back.
            NOTE: this hook will get called for every array, even
            for nested arrays.

        * decode_object:
            Called for every JSON object.  A Python dictionary is passed
            as the argument, and expects to get a Python object back.
            NOTE: this hook will get called for every object, even
            for nested objects.

        * encode_value:
            Called for every Python object which is to be encoded into JSON.

        * encode_dict:
            Called for every Python dictionary or anything that looks
            like a dictionary.

        * encode_dict_key:
            Called for every dictionary key.

        * encode_sequence:
            Called for every Python sequence-like object that is not a
            dictionary or string. This includes lists and tuples.

        * encode_bytes:
            Called for every Python bytes or bytearray type; or for
            any memoryview with a byte ('B') item type.  (Python 3 only)

        * encode_default:
            Called for any Python type which can not otherwise be converted
            into JSON, even after applying any other encoding hooks.

        _hookNz+Hook %r must be None or a callable functionzUnknown hook name %r)rj  r  r8   rp  )r   ro  r6  atts       r   rk  zJSON.set_hook  s`    V t***W$C4(: AHL  D#x(3h>??r   c                 X    |r|| j                   vryt        | |dz         }t        |      S )NFrw  )rj  rk  r  )r   r  hooks      r   has_hookzJSON.has_hookl  s0    IT-@-@@tY01~r   Nc                    ddl }|| j                  vrt        d|z        t        | |dz         }t	        |      st        d|      	  ||g|i |}|S # t        $ r  t        $ r[}	 |j                         }
|j                  d      rt        }nt        }t        |	t              rd}nd} |||
|g|||d	}||	d}	~	ww xY w)
zWrapper function to invoke a user-supplied hook function.

        This will capture any exceptions raised by the hook and do something
        appropriate with it.

        r   NzNo such hook %rrw  zHook is not callable: encode_r  r  r)  )r|   rj  rl  rk  r  rC   r  r/  r  r  r  r  r>   r  )r   r  input_objectr<  r   r   r|   rz  rvalr(  r  ex_classr  r1  s                 r   	call_hookzJSON.call_hookr  s     	D/// !2Y!>??tY01~$@AA	"6t6v6D2 1  	 	"#s||~H##I...#12"" 	
 "!F c!+	"s   
A C*AC  Cc                     | j                   j                  s|dv S t        |t              st        |      }|dv ryddl}|j                  |      dk(  S )zDetermines if the given character is considered as white space.

        Note that Javscript is much more permissive on what it considers
        to be whitespace than does JSON.

        Ref. ECMAScript section 7.2

        r_  rh  Tr   Nri  )r  r  r>   rD   r!  r"  )r   r   r!  s      r   iswsz	JSON.isws  sR     ||..	>!a%FM!''*d22r   c                 0    |dk(  s|dk(  ry|dk(  s|dk(  ryy)zqDetermines if the given character is considered a line terminator.

        Ref. ECMAScript section 7.3

        r  r
  Tu    u    Fr   r@  s     r   
islinetermzJSON.islineterm  s'     9T	=AMr   c                    |j                   }|j                  d        |j                         }| j                  |       |j                  r|j                  d|j                         |S |j                  d|z  |j                         |S )zJTry to recover after a syntax error by locating the next "known" position.c                 8    | dv xs t         j                  |       S )Nz	,:[]{}"';)r   rn  rW  s    r   r'   z%JSON.recover_parser.<locals>.<lambda>  s    \ 1 SW5P5PQR5S r   z.Could not recover parsing after previous errorr*  z%Recovering parsing after character %r)r  rX  r?  ra  r  r;  r<  )r   stater  stopchars       r   recover_parserzJSON.recover_parser  s    iiST88:E::OO@3<<   	 OO7(B   r   c                     |j                   }|j                  }|j                         }|r|dk7  r|j                  d||       y|j                  xj
                  dz  c_        y)zIntermediate-level decoder for ECMAScript 'null' keyword.

        Takes a string and a starting index, and returns a Python
        None object and the index of the next unparsed character.

        rP  zExpected a 'null' keyword'r*  r
   N)r  r<  ro  r7  r  r  r   r  r  start_positionr  s        r   decode_nullzJSON.decode_null  sb     ii!R6\92W  KK!!Q&!r   c                 &    |j                  d       y)z,Produces the ECMAScript 'undefined' keyword.rg   Nr   r   r  s     r   encode_undefinedzJSON.encode_undefined  s    [!r   c                 &    |j                  d       y)z!Produces the JSON 'null' keyword.rP  Nr  r  s     r   encode_nullzJSON.encode_null  s    Vr   c                     |j                   }|j                  }|j                         }|r|dvr|j                  d||       |dk(  S |j                  xj
                  dz  c_        |dk(  S )zIntermediate-level decode for JSON boolean literals.

        Takes a string and a starting index, and returns a Python bool
        (True or False) and the index of the next unparsed character.

        )rQ  rR  z%Expected a 'true' or 'false' keyword'r*  r
   rQ  )r  r<  ro  r7  r  r  r  s        r   decode_booleanzJSON.decode_boolean  sv     ii!R007n  
 V| KK!!Q&!V|r   c                 J    |j                  t        |      rd       yd       y)z7Encodes the Python boolean into a JSON Boolean literal.rQ  rR  N)r   r  )r   bvalr  s      r   encode_booleanzJSON.encode_boolean  s    tDzV7w7r   c                    |j                   }| j                  |       |j                  }| j                  d      s| j                  d      r|j	                         }|r|dv r|j                          |j                  d      }d|v r| j                  d      rd}n| j                  d      rd}nd}|r'	 | j                  |||      }|j                          |S |j                          d}	d	}
d
}d
}|j	                         }|rX|dv rT|dk(  r|	dz  }	n|dk(  rd}|
dz  }
|j                          | j                  |      d	kD  rd}|j	                         }|r|dv rT|
dkD  s|r(|j!                  | j"                  j$                  d|       |r|j'                  d|       |sI|j'                  d|       | j)                  |       | j*                  xj,                  dz  c_        t        S |j/                         s|dv r|j1                  d       }|dk(  r]|j!                  | j"                  j2                  d|       |j*                  xj4                  dz  c_        | j"                  j6                  S |dk(  rx|j!                  | j"                  j2                  d|       |j*                  xj8                  dz  c_        |	d	k  r| j"                  j:                  S | j"                  j<                  S |j'                  d||       t        S |dk(  r|j	                  d      dv r|j?                  d      }|j1                  t@        jB                        }|j!                  | j"                  jD                  d||z   |       tG        |      d	k(  r*|j'                  d|       | j)                  |       t        S t@        jI                  |      }|jK                  ||	|       |j"                  jM                  ||	tN               }|S |dk(  r|j	                  d      d!v r|j?                  d      }|j1                  t@        jP                        }|j!                  | j"                  jR                  d"||z   |       tG        |      d	k(  r*|j'                  d#|       | j)                  |       t        S t@        jU                  |      }|jK                  ||	|       |j"                  jM                  ||	tV               }|S |dk(  r|j	                  d      d$v r|j?                  d      }|j1                  t@        jX                        }|j!                  | j"                  jZ                  d%||z   |       tG        |      d	k(  r*|j'                  d&|       | j)                  |       t        S t@        j]                  |      }|jK                  ||	|       |j"                  jM                  ||	t^               }|S |j1                  d'       }tG        |      }|d	k(  r|j'                  d(|       d
}g }g }g }d}d	}d
}d
}d)}ta        |      D ]  \  }}|dk(  r7|d)k7  r-|j'                  d*||       | j)                  |       t        c S d+}d}B|d,v r7|d-k(  r-|j'                  d*||       | j)                  |       t        c S d-}d}}|dv r7|d-k7  s|r-|j'                  d*||       | j)                  |       t        c S |}|d)k(  r|jc                  |       |d+k(  r|jc                  |       |d-k(  s|jc                  |        d.je                  |      }d.je                  |      }d.je                  |      } |xs | }!|s-|s+|j'                  d*||       | j)                  |       t        S |r-|s+|j!                  | j"                  jf                  d/||       d}|r-| s+|j'                  d0||       | j)                  |       t        S |s,|j!                  | j"                  jh                  d1||       d}ntG        |      dkD  r|d	   dk(  rd}| j"                  jj                  r*|j!                  | j"                  jl                  d2||       nV| j"                  jn                  r@|j!                  | j"                  jl                  d3| j"                  jp                  z  ||       tG        ||z   js                  dd4      ju                               }|ri|!rg| j"                  jv                  d5k(  rN	 t@        jU                  |      }|jK                  ||	|       |j"                  jM                  ||	tz               }|S | r	 t}        |       }"|dk(  r|" }"nd	}"|sO|"d	k\  rJt}        |      }|"d	k7  r|d8|"z  z  }|jK                  ||	|       |j"                  jM                  ||	      }|S 	 |"t~        k  s|"t        kD  s	|t        kD  r|j"                  j                  ||	      }n|j"                  j                  ||	      }|j                  ||	|       |S # t        $ r Y 	t        $ r"}|j                  |       t        }Y d}~	d}~ww xY w# tx        $ r> |j'                  d6||       | j)                  |       | j"                  j6                  cY S w xY w# tx        $ r. |j'                  d7||       | j)                  |       t        cY S w xY w# tx        $ r2}|j'                  d9|j                  z  ||       t        }Y d}~|S d}~ww xY w):a  Intermediate-level decoder for JSON numeric literals.

        Takes a string and a starting index, and returns a Python
        suitable numeric type and the index of the next unparsed character.

        The returned numeric type can be either of a Python int,
        long, or float.  In addition some special non-numbers may
        also be returned such as nan, inf, and neginf (technically
        which are Python floats, but have no numeric value.)

        Ref. ECMAScript section 8.5.

        r\  r]  z-+0123456789.z$-+0123456789abcdefABCDEFNaNInfinity.r  Nr*  r
   r   Fz+-r1   rw   r0   Tz3Numbers may only have a single "-" as a sign prefixz>Spaces may not appear between a +/- number sign and the digitsz Missing numeric value after signrp  c                 .    | j                         xs | dv S )Nrp  rt  rW  s    r   r'   z$JSON.decode_number.<locals>.<lambda>N  s    		(@qDy r   rx   z+NaN literals are not allowed in strict JSONry   z0Infinity literals are not allowed in strict JSONzUnknown numeric value keywordr,   )r   Xr.   z3Hexadecimal literals are not allowed in strict JSONzHexadecimal number is invalid)rR  r<  r*  )oOz-Octal literals are not allowed in strict JSONzOctal number is invalid)rQ   r   z.Binary literals are not allowed in strict JSONzBinary number is invalidc                 
    | dv S )Nz0123456789.+-eEr   rW  s    r   r'   z$JSON.decode_number.<locals>.<lambda>  s    A1B,B r   zMissing numeric valueunitsz
Bad numberfractioneEexponentr  z@Bad number, decimal point must be followed by at least one digitzBad number, exponent is missingz@Bad number, decimal point must be preceded by at least one digitz(Numbers may not have extra leading zerosz6Numbers may not have leading zeros; interpreting as %sr  r  z#Bad number, not a valid octal valuezBad number, bad exponentr2   zBad number, %s)Fr  ra  r<  r{  r?  r   rl  r  r$  r  r.  r,  rg   r)  rU  skipws_nocommentsr+  r  r  r7  r  r  r  rq  rk  r  r  rm   r  r   rn   re  r   rX  r  r   r  rX  r.  r   r[  r  r  r   r]  r  r  r   r   r   r  r  r  is_forbid_leading_zerosr  is_warn_leading_zerosr<  r   r  r  r8   r   r  float_minexpfloat_maxexpfloat_sigdigitsr-  r,  rT  r  )#r   r  r  r  r   nbrr  r  r(  rR  
sign_countsign_saw_plussign_saw_wsr  r  r  ivalr&   numberimaxhas_leading_zerounits_digitsfraction_digitsexponent_digitsesignrM   saw_decimal_pointsaw_exponentin_partr   units_s
fraction_s
exponent_s
is_integerr  s#                                      r   r\  zJSON.decode_number  s+    iiE ==)T]]>-J
AQ/)!!#&&'ST#:$--"? .I]]?3 /I $I	#"nnYnnU 002"
$$& 
HHJAICxbyc $!OJHHJ%%e,q0"
A AI >]OO..E'  
 P'   2^   &JJ%%*%YY[AI@ABU{LL,,A+   
 $$)$||'''z!LL,,F+   
 **a/*!8<<...<<+++  3R. !  !  #X388A;*4ZZ]F\\'"6"67FOO((E'	   6{a  3n !  ##E*  %%f-D&&t$&P&&tTAR&SAH#X388A;*4ZZ]F\\'"8"89FOO**?'	   6{a  !:^ T##E*  ''/D&&t$&P&&tTAT&UAH#X388A;*4ZZ]F\\'"9"9:FOO++@'	   6{a  !;n U##E*  ((0D&&t$&P&&tTAU&VAH \\"BCFv;Dqy  !8> R$L O OEI % L G!&) 218')((v(W++E2(((G(,%$Y*,((v(W++E2(((G#'L$Y*,((v(W++E2((E')$++A. J.'..q1 J.'..q192: ggl+G1J1J 0?<@J:  v O##E*   LL77V+	    !
J  5v !  ##E*  LL66V+	    W!gajC&7#' <<77OO22B!/	 $  \\77OO22P,,AAB!/ $  Wz1::3DJJLMI  J4<<3R3RVW3W	,"//8D **4d^*TMM**$.G +   %":H C< (yH %Q7|q=B(N*D**4d^*TMM**46& H!T </#l2$6!MM66vtD!MM44VTB ,,QTN,SHQ	 ( $ (,,S1'(^ " ,$$=!/ % 
 ''.<<+++,$ " %$$2F^ %  ''.$$%< " "$$(3;;6 %  "A H"s\   4i 4j k ,Al 	j"j*jjAkk4ll	m'm		mc                    t        |t              r$|j                  rt        d|      |j                  }t        |t
              r |j                  |j                                yt        |t              r|j                  t        |             yt        |t        j                        r|j                         r|j                  d       y|j                         r4|j                         r|j                  d       y|j                  d       yt        |      j                         }d|vr	d|vr|dz   }|j                  |       y|t         u r|j                  d       y|t"        u r|j                  d       y|t$        u r|j                  d       yt        |t&              rt)        |      j                         }d	|v rd
|v s	|t$        k(  r|j                  d       yd	|v s|t"        u r|j                  d       yd|v s|t         u r|j                  d       y|j                  t)        |             yt+        dt-        |            )aG  Encodes a Python numeric type into a JSON numeric literal.

        The special non-numeric values of float('nan'), float('inf')
        and float('-inf') are translated into appropriate JSON
        literals.

        Note that Python complex types are not handled, as there is no
        ECMAScript equivalent type.

        zBCan not encode a complex number that has a non-zero imaginary partNrx   rz   ry   r3   r  z.0rn   r1   rm   zAencode_number expected an integral, float, or decimal number type)r>   compleximagr  realr   r   r   r  rD   r9   r<   r  r  r  r}  rm   rn   r   rB   r  rC   r  )r   r&   r  rY   reprns        r   encode_numberzJSON.encode_numberG  s    a!vv%X  Aa"LL)aLLQ a)xxzU#  ;;=LL-  LL, 	 FLLNa<CqLDAQ 8LL#XLL$&[LL%5! GMMOE3%<AK[)%18Z(%18U# T!W%SQ r   c                    |j                   }| j                  |       |j                         dk(  rnCdk(  r'|j                  | j                  j
                  d       n|j                  d       t        S |j                  }|j                          | j                  j                  r| j                  }n| j                  }| j                  j                   }g }|j                  }d}d}	d}
d}d}|s
|s|j                  r|j                  d|d	       n|j                         }|rd
t!        |      cxk  rdk  r7n n4|j#                         }	 t$        j'                  ||      } ||       d}d}	|j-                  d      dk7  r-|j                  d|	|d       |j*                  } |d       d}d}	|k(  r|j                          d}n.|dk(  r|j                  }|j                          |j                         }|s#|j                  d||d       |j*                  }nt$        j/                  |      rd|cxk  rdk  rn nd}nd}|j1                  t$        j.                  |      }t$        j3                  |      }|dk(  r/|j                  | j                  j4                  dd|z   ||d       n.|j                  | j                  j6                  dd|z   ||d       |j*                  }|dk  r |t9        |             n |t$        j;                  |             n||v r|j                           |||          n|dk(  s|dk(  r|j                          d|z   }d}|dk(  rZ|j                         d k(  rD|j                          |d z  }d!}d}|j                  | j                  j<                  d"||d       n;d#}n8|j                  | j                  j>                  d$||d       |j*                  }d}|j1                  t$        j@                  |      }|rL|j                         |k7  r)|j                  d%|z  ||z   ||d       |j*                  }n|j                          ||z   |z   }|s%|j                  d&|||d       |j*                  }d'}n;|r$tC        |      |k7  r|j                  d(|||d       t$        jE                  |      }|d)kD  r|j                  d*||z   |z   ||d       d'}|r0t9        |      }	 t$        j'                  ||      } ||       d}d}	n|dk  rN|dk(  r6|j                  | j                  j4                  d||d       |j*                  } |t9        |             nud+|cxk  rd,k  r n nt9        |      }|jG                         }	nJd
|cxk  rdk  r.n n+|j                  d-||d       |j*                  } |d       n |t$        j;                  |             n|j                  | j                  jH                  d.d|z   ||d       |j*                  } ||       |j                          nt!        |      d/k  rt!        |      dk(  r@|j                  | j                  j4                  d|j                  |d       |j*                  }| jK                  |      rU|
s:|j                  d0d1t!        |      z  |j                  |d       |j*                  }d}
 ||       |j                          n|r ||       |j                          n|j                  d2d1t!        |      z  |j                  |d       |j*                  }|j                          nyd+t!        |      cxk  rd,k  r.n n+|j#                         }|j                  jG                         }	n7|j1                  fd3      }|s ||       |j                          n ||       |s|s|r!|j                  d|	|d        |d       d}d}	|s|j                  d4|j                  |d       |j*                  rt        S djM                  |      }|jO                  ||5       | jQ                  d6      r	 | jS                  d6||5      }|S |S # t(        $ r* |j                  d||f|	|d       |j*                  }d}Y kw xY w# t(        $ r* |j                  d||f|	|d       |j*                  }d}Y w xY w# tT        $ r Y |S tV        $ r"}|jY                  |       t        }Y d}~|S d}~ww xY w)7zIntermediate-level decoder for JSON string literals.

        Takes a string and a starting index, and returns a Python
        string (or unicode string) and the index of the next unparsed
        character.

        r   r   z>String literals must use double quotation marks in strict JSONz&String literal must be properly quotedNFz String literal is not terminatedStringr  r  r  r   zIllegal Unicode surrogate pairr<  r  r  u   �r.   z\uz:High unicode surrogate must be followed by a low surrogateTr   z&Escape in string literal is incompleter,   3r   rv  r   zBZero-byte character (U+0000) in string may not be universally safez;JSON does not allow octal character escapes other than "\0"ri  ur   r  {}z)JSON strings do not allow \u{...} escapesr   z*JSON strings may not use the \x hex-escapez/Unicode escape sequence is missing closing '%s'z.numeric character escape sequence is truncatedr   z.escape sequence has too few hexadecimal digitsi z$Unicode codepoint is beyond U+10FFFFr   r  z;Low unicode surrogate must be proceeded by a high surrogatez0String escape code is not allowed in strict JSONr   zALine terminator characters must be escaped inside string literalsr  z>Control characters must be escaped inside JSON string literalsc                 6    | t         j                  vxr | k7  S r   r   )r   quotes    r   r'   z$JSON.decode_string.<locals>.<lambda>  s    aw'B'BBQqEz r   z6String literal is not terminated with a quotation markr*  r`  )-r  ra  r?  r+  r  r  r7  rg   r<  rU  is_forbid_js_string_escapes_escapes_json_escapes_js is_forbid_control_char_in_stringr   r  r   r#  r   r  r8   r  rL  r[  rk  r  r  r  r
  r  r  r  rX  r   r  r  r  r  r  rL  r{  r  r  r.  r,  )r   r  r  string_positionescapes	ccallowedr  _appendhigh_surrogatehighsur_positionhad_lineterm_errorsaw_final_quoter  r   low_surrogateucescape_position	maxdigitsr  r&   
esc_opener
esc_closeresc_sequencerd  chunkrY   r(  r  s                              @r   r`  zJSON.decode_string  s	    iiE
C<c\OO22P
 EF,,
<<33((G&&GEEE	--  #  !+zz  6#2$ ! 
 
A SV-v-$'GGIM&$>>*M BK%)N'+$[[^u,$$T!1'6 (	 %  #("3"3KH%%)N'+$Ez
"&d"%,,
HHJ$$@!0'6 (	 %  #("3"3K++A. a3$%	$%	 \\'*@*@9\UF,,V4AAv LL22` 6M%4+:$, (   LL66Z 6M%4+:$, (  #("3"3K3wA 3 3A 67'\HHJGAJ'#XcHHJ!%J!#JCx88:,HHJ&#-J),J(,I!OO $ E E L)8/>(0 ,  )*I LL::I%4+:$, (  ',&7&7$%	 \\'*>*>\SF!88:3!,, Q",!- *V 3)8/>(0 -  +0*;*;KHHJ#-#6#CL!((L(%4+:$, )  ',&7&7$*	$V	)A!,, P ,)8/>(0 -  %,$6$6v$>	 8+((B&/*<%4+:$, )  %+	%(+I*!(!B!B ."B  )-+/("S$>!OO $ 6 6 d)8/>(0 ,  +0*;*;KI/966),%* ,;+?+?+A(966((Y%4+:$,	 )  ',&7&7)   3 3I >? OO99Jq!0'6 ( $  #("3"3KAJHHJQ4q6Q;OO..\!$'6 ( $  #("3"3K??1%-((_$s1v-%(\\+:$, )  ',&7&7-1*AJHHJAJHHJ$$X 3q6)!$'6 ( %  #("3"3KHHJ3q6+V+!$#&<<#4#4#6  Q AJHHJEN "+D	 L). 	   H!N#H. 	    GGFO!!!o!> ==)NN?ANP qg	 & 	&((<+];%5+:$, )  ',&7&7%	&J  * 	*!,, @!/ ?)9/>(0 -  +0*;*;K!)B	*R      $$S)sB   b# c d #/cc/dd	ee#e  ec                 "   ddl }ddl}ddl}| j                  j                  t        ||j                        rfd}n(r$t        |t              s|j                        }d}nd}g }|j                  d       | j                  }| j                  }	| j                  }
|j                  j                  }|j                  }d}t        |      }||k  r|r |||         }n||   }t!        |      }|dk  r|
|   r|t        |t"              rl|r||v sf|}|dz  }||k  r;|r |||         }n||   }t!        |      }|dk  r|
|   r|r||v s|dz  }nn||k  r;|j                  t        |||              n||v r|j                  ||          |dz  }n|dk  r|j                  d|z         |dz  }nd	|cxk  rd
k  rn nd}|j$                  dk(  rhd	|cxk  rdk  r]n nZ|dz   |k  rR|}|dz  }|r |||         }n||   }t!        |      }|dz  }d|cxk  rd
k  rn n|}|j                  d||fz         d}|sd|z  }t'        d|      |dk  r||r||v rd}n,|j)                  |      dv rd}nt+        |      r	 ||      }n|}|r.||	v r|j                  |	|          n&|j                  d|z         n|j                  |       |dz  }n|r||v rd}n,|j)                  |      dv rd}nt+        |      r	 ||      }n|}|r8t,        j/                  |      D ]  }|j                  dt!        |      z         ! n|j                  |       |dz  }||k  r|j                  d       |j                  dj1                  |             y)z3Encodes a Python string into a JSON string literal.r   Nc                 f    | j                   }r!t        |t              s|j                        S |S r   )datar>   rD   r   )r   r  	py2strencs     r   tocharz"JSON.encode_string.<locals>.tochar  s,    VVZC%899Y//Ir   r   r  r
   r   r  r   r   Fr  r  r  z\u%04x\u%04xTr  z7can not include or escape a Unicode surrogate characterr  r  )r!  r|   r  r  r  r>   r  rD   r   r   rm  _optional_rev_escapesrn  r  r  r   r   r  r  r  r"  r  r   r  r  )r   rY   r  r!  r|   r  r  r  revesc	optrevescasciiencodabler  
encunicoder   r  r   cordrK  handled_raw_surrogates
hsurrogate
lsurrogatecnamedoesc	surrogater  s                           @r   encode_stringzJSON.encode_string  s   
 	 LL00	a//0 z!S1#AF Fc""..	--99..
1v$h1Q4LaDq6Ds
"4(z40&1+=
 Q$h"1Q4LaDq6Ds
*40!.13EQ $h c!Aa&k*ffQi(Qi$./Q4)6) */&NNf,$0&0Q$ "&JFA"1Q4LaDq6DFA//%)
oZ8P&PQ15.-$tOE)QSX   Q-%7 E ))!,0HH Ej)&qME&EI~il3i$&67MM!$Q !Q-%7 E ))!,0HH Ej)&qME&E%,%F%Fq%I B	i#i.&@AB MM!$QS $hV 	cRWWV_%r   c                    |j                   }| j                  |       |j                  }d}|j                         }|s|j	                  d|       |S |dk(  r#d}|j
                  xj                  dz  c_        |S |dk(  r#d}|j
                  xj                  dz  c_        |S |dk(  r#d	}|j
                  xj                  dz  c_        |S |d
k(  rP|j                  | j                  j                  d||       t        }|j
                  xj                  dz  c_        |S |dk(  s|dk(  r|j                  | j                  j                  d|z  ||       | j                  d      r	 | j                  d||      }|S | j                  d      r	 | j                  d||      }|S |dk(  r7|j
                  xj&                  dz  c_        |j                  j(                  }|S |j
                  xj*                  dz  c_        |j                  j,                  }|S |r|t.        j0                  v r|j3                  d||       |j                  | j                  j4                  d||       |j
                  xj6                  dz  c_        | j9                  |      }|S |j	                  d||       t        }|j
                  xj6                  dz  c_        |S # t         $ r Y =t"        $ r!}|j%                  |       t        cY d}~S d}~ww xY w# t         $ r Y ut"        $ r!}|j%                  |       t        cY d}~S d}~ww xY w)zDecodes an identifier/keyword.NzExpected an identifierr*  rP  r
   rQ  TrR  Frg   z2Strict JSON does not allow the 'undefined' keywordrx   ry   z*%s literals are not allowed in strict JSONr]  r\  z(Identifier is a JavaScript reserved wordz5JSON does not allow identifiers to be used as stringszUnknown identifier)r  ra  r<  ro  r7  r  r  r  r+  r  r  rg   r  r  r{  r  r  r.  r,  r  rm   r  rn   r   r  r9  r  r  decode_javascript_identifier)	r   r  identifier_as_stringr  r  r   r  r  r(  s	            r   decode_identifierzJSON.decode_identifier  sA   iiE!5OR 
Q 6\CKK!!Q&!L 
K 6\CKK!!Q&!F 
E 7]CKK!!Q&!@ 
 ;OO--D'	   CKK&&!+&n 
m 5[B*,OO((<rA'	   }}^,..n.UC J/.."~.VC JU{$$)$mm''2 
/ **a/*mm'', 
' $:::&&B!/ ' 
 LL00K+	    ++q0+77;
 
   !5rN S++q0+
Y $   %((-$$% $   %((-$$%sH   (K L 	L#L+LLL	MM#L?9M?Mc                    |j                   }| j                  j                  }|j                  d      }|dk7  r|dk7  ry|j	                  | j                  j
                  d       |j                  }|j                  d       |dk(  }d}|j                  s|rQ|j                  d      dk(  r|j                  d       d}nk|j                  d      dk(  r:|j                  d	|d
       n%|j                  |      r|j                  |       d}n|j                          |j                  s|s|r|j                  d|d
       |j                  xj                  dz  c_        y)zSkips an ECMAScript comment, either // or /* style.

        The contents of the comment are returned as a string, as well
        as the index of the character immediately after the comment.

        r.   ///*Nz'Comments are not allowed in strict JSONFz*/Tz%Multiline /* */ comments may not nestCommentr  zComment was never terminatedr
   )r  r  r  rL  r+  r  r<  rU  r  r7  rF  r_  r#  r  r  )r   r  r  uniwsrY   r  	multiline	saw_closes           r   skip_commentzJSON.skip_comment  sB    ii//KKN9dLL!!#L	
 I		**;;q>T)HHQK $I[[^t+$$?'5 ) %  ::e$))%0 $IGGI# **& Y.-!  
 	  A% r   c                 b    |j                   j                  | j                  j                         S )z+Skips whitespace (will not allow comments).)r  ra  r  is_forbid_unicode_whitespacer  s     r   r  zJSON.skipws_nocomments  s$    yyDLL$M$M MNNr   c                     |j                   }| j                  j                   }|j                  s_|j	                  d      }|dk(  s|dk(  r| j                  |       n$|j                  |      r|j                  |       ny|j                  s^yy)aZ  Skips all whitespace, including comments and unicode whitespace

        Takes a string and a starting index, and returns the index of the
        next non-whitespace character.

        If the 'skip_comments' behavior is True and not running in
        strict JSON mode, then comments will be skipped over just like
        whitespace.

        r.   r  r  N)r  r  r  r  rL  r  rC  ra  )r   r  r  r  r   s        r   ra  zJSON.skipws  sr     iiLL333**AADyAI!!%(5!

5! **r   c                    |j                   ry|j                  }| j                  |       |j                         }|dvr|j	                  d       y|j
                  }|j                          |dk(  rd}d}g }n4d}d}|j                  j                  t        k(  rt        rt               }ni }d	}| j                  |       |j                         }	|	|k(  r|j                          d}
nd}d}
|
s|j                  s|j                   s| j                  |       |j                         }	|	d
k(  rn`|	dk(  r|s|r|j	                  d|d       ni|j                  | j                  j                  d|d       |j                  t               |j                   r|j                   xj"                  dz  c_        |j                          d}|	|k(  rk|sU|r*|j                  | j                  j$                  d|d       n)|j                  | j                  j$                  d|d       |j                          d}
nV|	dv r$|rd}nd}|j	                  d||	fz  ||       d}
n.|j                   rn |j
                  }|r| j'                  |d      }n| j'                  |d      }|t(        u r| j+                  |      }|dvr|j                   rn|r|rd}nd}|j	                  d|||       d}| j                  |       |j                   rn|rJd}|}|}t,        j/                  |      sWt,        j1                  |      r+|j                  | j                  j2                  d||d       n|j	                  d||d       d}|j                         }	|	dk7  r|j	                  d||d       |j                          | j                  |       | j'                  |      }| j                  |       |s||v r+|j                  | j                  j4                  d|||d       |d
k(  r*|j                  | j                  j6                  d||d       |||<   |dz  }n|j                  |       |dz  }|
s|j                  s|j                   s|j                   ra|r0t9        |j                   j:                  |      |j                   _        n/t9        |j                   j<                  |      |j                   _        |j                   r|S |
s+|r|j	                  d|d       n|j	                  d |d       |rI|j                   xj>                  dz  c_        | jA                  d!      r	 | jC                  d!||"      }|S |S |j                   xjJ                  dz  c_%        | jA                  d#      r	 | jC                  d#||"      }|S |S # tD        $ r Y |S tF        $ r"}|jI                  |       t        }Y d}~|S d}~ww xY w# tD        $ r Y |S tF        $ r"}|jI                  |       t        }Y d}~|S d}~ww xY w)$zOIntermediate-level JSON decoder for composite literal types (array and object).N{[z)Composite data must start with "[" or "{"[F]Tr  r   r  r  z/Can not omit elements of an object (dictionary)Objectr  z(Can not omit elements of an array (list)Arrayr
   zJStrict JSON does not allow a final comma in an object (dictionary) literalzCStrict JSON does not allow a final comma in an array (list) literalz]}zExpected a '%c' but saw '%c'r  r  z#Values must be separated by a commar  z=JSON only permits string literals as object properties (keys)zIObject properties (keys) must be string literals, numbers, or identifiersz/Missing value for object property, expected ":"zObject contains duplicate keyz=Using an empty string "" as an object key may not be portablez-Object literal (dictionary) is not terminatedz&Array literal (list) is not terminatedr^  r*  r_  )&r  r  ra  r?  r7  r<  rU  r  r  SORT_PRESERVE_OrderedDictr  r+  r  r   rg   r  r  r  	decodeobjsyntax_errorr  r   r  r  r  r  rD  rO  r  r  r  r{  r  r  r.  r,  r  )r   r  r  openerr  isdictcloserr   	num_itemsr   done	saw_valuer  value_positionr  	recover_c	skip_itemr  key_positionr  r(  s                        r   decode_compositezJSON.decode_composite+  s9   iiEHI
S=FFCFF}}&&-7L"n	EHHJ;HHJDID3::e6G6GE"HHJ7#X$!!,, Q/=(0 -  "OO $ C C J/=(/	 ,   JJy1${{ % : :a ? :HHJ %I&[$!!OO $ ; ; l/=(0	 ,  "OO $ ; ; e/=(/	 ,  HHJD$Y ( '$$6&!D'5 % % 
  D$$ "%..T.JC..U.KC,& $ 3 3E :I + $$ ( '$$=!/'5 %	 %  !	E"$$ %IC#1L"//4"//4!OO $ ; ; _)5/=(0 ,  ",, k)5/=(0	 -  )-I
ACx((M%3+9$,	 )  HHJKK&>>%0DKK&$#:!OO $ ; ; ? #)5/=(0 ,  "9!OO $ 9 9 _)5/=(0 ,  $(C!Q	JJsONIs 3::e6G6Gx ;;25KK33Y3/ 25KK22I2. J   C#1$ !    <#1# !  KK##q(#}}_-$..#.WC  
s
 KK""a'"}}^,$..~.VC 
s
 $  
 ! $((-#C 
$ $  
 ! $((-#C
$s<   -W 6X 	XX"W??X	X=X=X88X=c                     |S )a  Convert a JavaScript identifier into a Python string object.

        This method can be overriden by a subclass to redefine how JavaScript
        identifiers are turned into Python objects.  By default this just
        converts them into strings.

        r   rm  s     r   r  z!JSON.decode_javascript_identifier  s	     r   c                    |j                   }d}| j                  |       |j                  r|j                  d       |j	                         }|dv rN|xj
                  dz  c_        	 |j                          | j                  |      }|xj
                  dz  c_        |S |r&|j                  | j                  j                  d       || j                  v r| j                  |      }|S |j                         s|dv r| j                  |      }|S |j                         s|dv r| j!                  ||      }|S |j                  d	|z         |j#                          | j%                  |       t&        }|S # |xj
                  dz  c_        w xY w)
a.  Intermediate-level JSON decoder.

        Takes a string and a starting index, and returns a two-tuple consting
        of a Python object and the index of the next unparsed character.

        If there is no value at all (empty string, etc), then None is
        returned instead of a tuple.

        NzUnexpected end of inputr  r
   z:JSON document must start with an object or array type onlyz.+-rp  r  z/Can not decode value starting with character %r)r  ra  r  r7  r?  r  rG  r  r+  r  r  _string_quotesr`  rE   r\  rq  r  rU  r  r  )r   r  r  at_document_startr  r   r   s          r   r  zJSON.decodeobj&  sw    iiE::67HHJ9OOq O%((*++E21$( 
% !LL22P D'''((/ 
 U
((/ 
 T	,,0D -  
	   !RUV!VW
##E*"
) 1$s   '!E5 5Fc                    t        | j                        }|j                  ||       |j                  s| j	                  |       |j                  s	 | j                  |       |r`|j                  rT|j                  j                  |j                  _        |j                  j                  j                  |j                  _        t#        dg d      }|rH|r( ||j$                  |j&                  |j                        S  ||j$                  |j&                  d      S |j&                  D cg c]  }|j(                  d	v s| }	}|	r|	d
   |r ||j$                  d|j                        S |j$                  S # t        $ r}|j                  |       Y d}~5d}~wt        $ rX}t        dd|j                  j                        }	 ||# t        $ r}|j                  |       Y d}~nd}~ww xY wY d}~d}~ww xY wc c}w )a  Decodes a JSON-encoded string into a Python object.

        The 'return_errors' parameter controls what happens if the
        input JSON has errors in it.

            * False: the first error will be raised as a Python
              exception. If there are no errors then the corresponding
              Python object will be returned.

            * True: the return value is always a 2-tuple: (object, error_list)

        )r  r(  NzAn unexpected failure occuredr  )r  r<  json_results)objectr   r  r!  r   )r  r  r.  r$  _JSON__sanity_check_start
_do_decoder  r,  r/  r  r  r<  r  r  r  r  r  rF   r   r   r  )
r   ry  r  return_errorsreturn_statsr  r(  r1  result_typer   s
             r   r   zJSON.decodeS  s    T\\2 	h/ %%e,.& EII05		0H0HEKK-&+ii&8&8&F&FEKK# ".2OP"599ellEKKHH"599ellDAA &+\\XcS\\EW5WcXFXQi"599dEKK@@yy C ! *$$S)) 	.(3$"YY//
. c)  .((--.-	.2 YsT   E: -HH:	G>FG>&"G9	G	G0G+&G9+G00G99G>c                    d}|j                   j                  d      }t        |      dk\  r|dd \  }}|| j                  v r	 |S t	        |      dk  s*t	        |      dkD  st	        |      dk  st	        |      dkD  rs| j                  |      sb| j                  |      sQddl}|j                  t        |            }|j                  t        |            }|dvs|dvr|j                  d       |S )	a  Check that the document seems sane by looking at the first couple characters.

        Check that the decoding seems sane.  Per RFC 4627 section 3:
            "Since the first two characters of a JSON text will
             always be ASCII characters [RFC0020], ..."
        [WAS removed from RFC 7158, but still valid via the grammar.]

        This check is probably not necessary, but it allows us to
        raise a suitably descriptive error rather than an obscure
        syntax error later on.

        Note that the RFC requirements of two ASCII characters seems
        to be an incorrect statement as a JSON string literal may have
        as it's first character any unicode character.  Thus the first
        two characters will always be ASCII, unless the first
        character is a quotation mark.  And in non-strict mode we can
        also have a few other characters too.

        Tr.   Nrh  r  r   )ri  r  r   r  z8The input is gibberish, is the Unicode encoding correct?)
r  rL  r   r  r   r  r!  r"  rD   r-  )	r   r  is_saner  firstsecondr!  catfirst	catseconds	            r   __sanity_check_startzJSON.__sanity_check_start  s    ( ""1%v;!"2AJME6+++. ) Z$&#e*t*;Fd*c&kD.@99U+DIIf4E
 '*33CJ?H + 4 4S[ AI'??9 U D ((V r   c                    |j                   }| j                  |       |j                  r|j                  d       y|j                  j
                  r*t        j                  |j                  j
                        }nt        }|5  | j                  |d      |_
        ddd       |j                  s0| j                  |       |j                  s|j                  d       yyy# 1 sw Y   FxY w)zThis is the internal function that does the JSON decoding.

        Called by the decode() method, after it has performed any Unicode decoding, etc.
        zNo value to decodeT)r  Nz'Unexpected text after end of JSON value)r  ra  r  r7  r  r  r9   rA   r   r  r   r  )r   r  r  dec_ctxs       r   r   zJSON._do_decode  s    
 iiE::12}},,!..u}}/L/LM0 J NN5DNI	J $$E"zz$$%NO " %J Js   C""C+c                 F   dd l }d}|d}|S |t        u rd}|S t        |t              rd}|S t        |t        t
        t        f      s t        rt        |t        j                        rd}|S t        |t              st        j                  |      rd}|S t        |t              rd}|S t        |t              rXt        |d	      rLt        |j                         r7| j"                  j$                  }|r|d
u st        |      r ||      rd}|S d}|S t        |t&        t        t(        t*        f      rd}|S t        |d      st        |d      rt        |d      rd}|S t        ||j                         rd}|S t        ||j,                        rd}|S t        ||j.                        rd}|S t        ||j0                        rd}|S t2        dk\  rt        |t4        t6        f      rd}|S t2        dk\  rt        |t8              rd}|S t:        t        |t:              rd}|S d}|S )Nr   r  rP  rg   r  r  r  dict_asdictTr   sequenceiterkeysr|  keysdatetimedatetime	timedeltar   r}   
memoryviewrH  )r3  rg   r>   r  r  rB   r  r9   r<   rD   r   r  r.  tupler  r  r/  r  r  r  rj  r  r4  r5  r6  	_py_majorr}   r~   r7  _enum)r   r   r3  r   enc_nts        r   _classify_for_encodingzJSON._classify_for_encoding  sN   ;A` _ IA\ [ T"AX W c5'23
38AP O S!W%9%9#%>AL I #t$F C 3&C+S[[) AAv~(62Bvc{$A4 1 #A0 / C$sI!>?, + j)]+V0D$ # C!2!23  C/  C/  C!3!34  aJsUI4F$G  aJsJ$? 
 	 "z#u'=  r   c                 b   ddl }t        | j                        }|d}nHt        ||j                        r|}|j
                  }n#t        j                  |      }|st        d|      | j                  j                  r;t        | j                  j                        r| j                  j                  |_        n| j                  j                  dk(  s|r|j
                  j                         dk(  r	d |_        nc|j
                  dk(  r	d |_        nK|r1|j
                  j                         j                  d	      rd
|_        n|j                  fd}||_        |#	 |j                  t        j                         \  }}| j%                  ||       | j                  j&                  s|j)                  d       |j+                         }
||
}|S 	 |j                  |
      \  }}|S # t"        $ r}	t        d|j
                  z        |	d}	~	ww xY w# t,        $ r}	t        d      }||	d}	~	ww xY w)a  Encodes the Python object into a JSON string representation.

        This method will first attempt to encode an object by seeing
        if it has a json_equivalent() method.  If so than it will
        call that method and then recursively attempt to encode
        the object resulting from that call.

        Next it will attempt to determine if the object is a native
        type or acts like a squence or dictionary.  If so it will
        encode that object directly.

        Finally, if no other strategy for encoding the object of that
        type exists, it will call the encode_default() method.  That
        method currently raises an error, but it could be overridden
        by subclasses to provide a hook for extending the types which
        can be encoded.

        r   Nr+  Tasciic                     t        |       dk\  S )Nri  r   rW  s    r   r'   zJSON.encode.<locals>.<lambda>C  s    c!fn r   z	iso8859-1c                     t        |       dk\  S )Nr  r@  rW  s    r   r'   zJSON.encode.<locals>.<lambda>E  s    c!fo r   utfFc                 6    	  |        y# t         $ r Y yw xY w)NFT)r   )r   enc_funcs    r   escape_unicode_hardwayz+JSON.encode.<locals>.escape_unicode_hardwayP  s(    %   % . $#$s    	z3Output encoding %s is not sufficient to encode JSONr
  z!a Unicode encoding error occurred)r   r  r  r>   r   r   r   r  r  r  r  r  r}  r  r   rU  json_syntax_charactersUnicodeError
_do_encoder  r   r  r   )r   r   r  r   r  r  rE  outputncharsr(  r  r1  rD  s               @r   r   zJSON.encode  s    & 	 T\\* C&"2"23CxxH&&x0C%?  <<&&8DLL4O4O+P(,(C(CE% ++t388>>#w. -E)[(,E))44U; -2)
 ::% -C) !$D,G,G!H 	U#||,,LL F &!$F!3
 +   %ICHHT" & &()LM#%&s0    "G( H (	H1H

H	H.H))H.c                    | j                  |      }| j                  d      rD|}	 | j                  d|      }||ur+|}| j                  |      }||k7  r| j	                  ||       yt        |d      r| j                  ||      }|ry|dk(  r| j                  |       y|dk(  r3| j                  j                  s| j                  |       yt        d      |dk(  r| j                  ||       y|dk(  r	 | j                  ||       y|d	k(  r| j!                  ||       y|d
k(  r| j#                  ||       y|dk(  r| j%                  ||       y|dk(  r| j'                  ||       y|dk(  r| j)                  ||       y|dk(  r| j+                  ||       y| j-                  ||       y# t        $ r Y w xY w# t        $ r2}	 | j                  ||       n# t        $ r}||d}~ww xY wY d}~yd}~ww xY w)zInternal encode function.ra  Njson_equivalentrP  rg   z.strict JSON does not permit "undefined" valuesr  r  r  rH  r3  r4  r5  r6  )r<  r{  r  r  rH  r  encode_equivalentr  r  is_forbid_undefined_valuesr  r  r  r  try_encode_defaultr/  r  encode_enumencode_datetimeencode_dateencode_timeencode_timedeltaencode_composite)	r   r   r  obj_classificationorig_objprev_clssuccesserr1err2s	            r   rH  zJSON._do_encodev  s   !88===(Hnn^S9 ("-%)%@%@%E"%1OOC/3)*,,S%8G'U#;.<<::%%e,%&VWW6)U+8+	)""3.  8+sE*6)S%(:-  e,6)S%(6)S%(;.!!#u- !!#u-e   8 # ))++C7  )D() 8	)sG   F+ 5F; +	F87F8;	G6GG1	G)!G$$G))G11G6c                     | j                   j                  }|dk(  r| j                  t        |      |       y|dk(  r| j	                  |j
                  |       y| j                  |j                  |       y)z%Encode a Python Enum value into JSON.r  r  N)r  r  r  rD   rH  r  r   )r   r  r  eass       r   rP  zJSON.encode_enum  sY    ll))'>s3x/G^OOCIIu-sxx/r   c                     | j                   j                  }|r|dk(  rd}| j                  |j                  |      |       y )Nr  z%Y-%m-%d)r  r  r  strftime)r   dtr  r   s       r   rR  zJSON.encode_date  s8    ll&&cUlC2;;s+U3r   c                    | j                   j                  }| xs |dk(  }|r|j                  dk(  rd}nd}|j                  |      }|r|j	                  d      s|j	                  d      r|d d dz   }| j                  ||       y )	Nr  r   z%Y-%m-%dT%H:%M:%S%zz%Y-%m-%dT%H:%M:%S.%f%z-00:00+00:00Zr  r  microsecondr_  endswithr  )r   r`  r  r   is_isorY   s         r   rQ  zJSON.encode_datetime  s    ll**(C5L~~"+.KKajj*ajj.B#2A1e$r   c                    | j                   j                  }| xs |dk(  }|r|j                  dk(  rd}nd}|j                  |      }|r|j	                  d      s|j	                  d      r|d d dz   }| j                  ||       y )	Nr  r   zT%H:%M:%S%zzT%H:%M:%S.%f%zrb  rc  rd  re  rf  )r   r  r  r   ri  rY   s         r   rS  zJSON.encode_time  s    ll**(C5L}}!#&JJsOajj*ajj.B#2A1e$r   c                     | j                   j                  }|r|dk(  rt        j                  |      }n|dk(  rt	        |      }nt        d|z        | j                  ||       y )Nr  hmszUnknown timedelta_format %r)r  r  r   r  rD   r8   r  )r   r  r  r   rY   s        r   rT  zJSON.encode_timedelta  s[    ll++cUl,,R0AE\BA:S@AA1e$r   c                 
   |s| j                  |      }|dk(  r|j                         }d}|dk(  r!|j                  dk(  r|j                         }d}d}|dk(  rd}n|dk(  rd	}n|dk(  rd
}| j	                  |      rD	 | j                  ||      }||ur-|}|}| j                  |      }||k7  r| j                  ||       y|dk(  }d}|r't        |d      r	 t        |j                               }n	 t        |      }|2	 t        |      }	| j                  j                  }
|
sM| j                  j!                  |j"                        }| j                  j!                  |j"                  dz         }d}|rd}d}|
rd}nd}nd}d}|
s%| j                  j%                  t        |            }|j'                  |       |j'                  |       g }g }	 d}	 t)        |      }|dz  }||u rt+        d|      |r||   }| j	                  d      r	 | j                  d|      }|}| j	                  d      r	 | j                  d|      }|}t,        j/                  |      sCt,        j1                  |      r"| j                  j2                  st+        d|      t+        d|      |j'                  ||dz
  f       |j5                         }| j                  ||       |rD|j'                         |j5                         }| j                  |       |j7                  |       |j'                  |       \| jS                  ||       y# t        $ r Y w xY w# t        $ r Y dw xY w# t        $ r Y tw xY w# t        $ r d}	Y ww xY w# t        $ r Y pw xY w# t        $ r Y Zw xY w# t8        $ r Y nw xY w|r| j                  j:                  t<        k(  r#t>        rtA        |t>              rtB        ntD        rtB        t<        fv rdnytG              r|jI                  fd       nXtD        k(  r|jI                  d        n;tJ        k(  r|jI                  d        ns	tL        k(  r|jI                  d        |D cg c]
  }||d       nc c}w }}|
rd }n>t        |      | j                  jN                  k  rd!}n|j'                  d"z          d#|z   }tQ        |      D ],  \  }}|dkD  r|j'                  |       |j7                  |       . |
s?|	| j                  jN                  kD  r|j'                  d"z          n|j'                  d$       |j'                  |       y)%a  Encodes just composite objects: dictionaries, lists, or sequences.

        Basically handles any python type for which iter() can create
        an iterator object.

        This method is not intended to be called directly.  Use the
        encode() method instead.

        r   r.  r7  r   r}   Nrb  r0  rd  re  r1  r   r
   r  r  r  r  z : r  r  )r	  z%trying to encode an infinite sequencera  rc  zBobject properties (dictionary keys) must be strings in strict JSONzPobject properties (dictionary keys) can only be strings or numbers in ECMAScriptc                 $     | d         | d   fS r)   r   )r  srts    r   r'   z'JSON.encode_composite.<locals>.<lambda>  s    3qt9ad2C r   )r  c                 (    t        | d         | d   fS r)   )r  r  s    r   r'   z'JSON.encode_composite.<locals>.<lambda>  s    3G!3MqQRt2T r   c                 D    t        | d         j                         | d   fS r)   )rD   r   rq  s    r   r'   z'JSON.encode_composite.<locals>.<lambda>  s    3qt9??3Dad2K r   c                     t        | d         S r)   )rD   rq  s    r   r'   z'JSON.encode_composite.<locals>.<lambda>  s    #ad) r   r  r  r
  z,
r  )*r<  r/  r   r   r{  r  rH  r  r  iterr2  rl  rC   r   r  r  r  r  r
  r   nextr  r   r  r  is_allow_nonstring_keysr  r  StopIterationr  r	  r
  r>   r  r  r  sortSORT_ALPHA_CIr  r  r   rO  )r   r   r  rV  r  new_objrX  r  itnumitemsr  indent0indentspaces_after_openerr  r  	dictcolonparts	part_keyspart_idxobj2obj3newobjnewkeysubstate	substate2pkseppnumro  s                                @r   rU  zJSON.encode_composite  s    "!%!<!<S!A -++-C!' -#**2C++-C!( 	'%I:-)I7*&I==#..C8 #%!C1H)-)D)DS)I&)X5 U3 $v- gc:.#((*%#Y
 >s8
 55I,,<<U=M=MN;;E<L<Lq<PQ"$ #I %I&*ll&N&N [ 'O '# LL LL,- EI78DMHs{-CS  "4y  ==8.)-)M (.==):;.)-8I4)P (.  '33D9&33D9'+||'K'K*9(l(,+& %&
 '6$v$('" !" "(($1)=>  %224HOOD(3 	2$,$:$:$<	i8 ..y9LL*e F ##C/S   , " 
    d $0 % $% $0 % $%< !  ll,,-'#
3(E'(ci%??Cc]NN(CNEJ&NN(TNVM)NN(KNMC:-NN(;N=?4=>bU2a5\>>E>Ut||>>> TF]+fn"+E"2 .h!8LL%##H-.
 dll===LL0LL%LL s   =M M 1M$  M4 ;N& N  N& 4N C+N& 	MM	M! M!$	M10M14NN	NN& NN& 	N#N& "N##N& &	N21N2Rc                     t        |d      rHt        t        |d            r3|j                         }||u rt	        d|      | j                  ||       yy)aN  This method is used to encode user-defined class objects.

        The object being encoded should have a json_equivalent()
        method defined which returns another equivalent object which
        is easily JSON-encoded.  If the object in question has no
        json_equivalent() method available then None is returned
        instead of a string so that the encoding will attempt the next
        strategy.

        If a caller wishes to disable the calling of json_equivalent()
        methods, then subclass this class and override this method
        to just return None.

        rL  z9object has a json_equivalent() method that returns itselfTF)r  r  rk  rL  r  rH  )r   r   r  r  s       r   rM  zJSON.encode_equivalent  sa     3)*xC*+0
 &&(Ds{%OQT  OOD%(r   c                     |}| j                  d      r)	 | j                  d|      }||ur| j                  ||      S t	        d|      # t        $ r Y w xY w)Nrf  z0can not encode object into a JSON representation)r{  r  rH  r  r  )r   r   r  rW  s       r   rO  zJSON.try_encode_default  sj    ==)*7nn%5s; h&??366 PRUVV   s   A	 		AAr   )F)FF)NFF)4r   r   r   r    r  r  r  rm  r  rF  rj  r  r   r  rs  ru  rk  r{  r  r  r  r  r  r  r  r  r  r\  r  r`  r  r  r  r  ra  r  r  r  r   r  r   r<  r   rH  rP  rR  rQ  rS  rT  rU  rM  rO  r   r   r   rU  rU    s   ( N 	M K" L !%LVN&
P  &&
S@j(T3(
" "$8JX
BHpdO&bSj,&\O,ob+Z:!x0dP25ncJ:.x04%%%L0\:Wr   rU  c                 @    t        di |}|j                  | |      }|S )a
  Encodes a Python object into a JSON-encoded string.

    * 'strict'    (Boolean, default False)

        If 'strict' is set to True, then only strictly-conforming JSON
        output will be produced.  Note that this means that some types
        of values may not be convertable and will result in a
        JSONEncodeError exception.

    * 'compactly'    (Boolean, default True)

        If 'compactly' is set to True, then the resulting string will
        have all extraneous white space removed; if False then the
        string will be "pretty printed" with whitespace and
        indentation added to make it more readable.

    * 'encode_namedtuple_as_object'  (Boolean or callable, default True)

        If True, then objects of type namedtuple, or subclasses of
        'tuple' that have an _asdict() method, will be encoded as an
        object rather than an array.
        If can also be a predicate function that takes a namedtuple
        object as an argument and returns True or False.

    * 'indent_amount'   (Integer, default 2)

        The number of spaces to output for each indentation level.
        If 'compactly' is True then indentation is ignored.

    * 'indent_limit'    (Integer or None, default None)

        If not None, then this is the maximum limit of indentation
        levels, after which further indentation spaces are not
        inserted.  If None, then there is no limit.

    CONCERNING CHARACTER ENCODING:

    The 'encoding' argument should be one of:

        * None - The return will be a Unicode string.
        * encoding_name - A string which is the name of a known
              encoding, such as 'UTF-8' or 'ascii'.
        * codec - A CodecInfo object, such as as found by codecs.lookup().
              This allows you to use a custom codec as well as those
              built into Python.

    If an encoding is given (either by name or by codec), then the
    returned value will be a byte array (Python 3), or a 'str' string
    (Python 2); which represents the raw set of bytes.  Otherwise,
    if encoding is None, then the returned value will be a Unicode
    string.

    The 'escape_unicode' argument is used to determine which characters
    in string literals must be \u escaped.  Should be one of:

        * True  -- All non-ASCII characters are always \u escaped.
        * False -- Try to insert actual Unicode characters if possible.
        * function -- A user-supplied function that accepts a single
             unicode character and returns True or False; where True
             means to \u escape that character.

    Regardless of escape_unicode, certain characters will always be
    \u escaped. Additionaly any characters not in the output encoding
    repertoire for the encoding codec will be \u escaped as well.

    r   )rU  r   )r   r  r   rK  rI  s        r   r   r     s%    H 	vAXXc8$FMr   c                    d}d}d}d}d}|j                         }g }t        |j                               D ]  \  }	}
|	dk(  rt        |
      }|j	                  |	       (|	dk(  rt        |
      }|j	                  |	       J|	dk(  r|
}|j	                  |	       c|	dk(  r|
}|j	                  |	       ||	dk(  s|
}|j	                  |	        |D ]  }	||	=  t        di |}|j                  | ||xs ||xs |      }|rId	dl}|d
u r|j                  }|j                  D ]&  }|j                  |j                  |      dz          ( |rsd	dl}|d
u r|j                  }|j                  rS|j                  d|z         |j                  |j                  j                  d             |j                  d|z         |S )a  Decodes a JSON-encoded string into a Python object.

    == Optional arguments ==

    * 'encoding'  (string, default None)

       This argument provides a hint regarding the character encoding
       that the input text is assumed to be in (if it is not already a
       unicode string type).

       If set to None then autodetection of the encoding is attempted
       (see discussion above). Otherwise this argument should be the
       name of a registered codec (see the standard 'codecs' module).

    * 'strict'    (Boolean, default False)

        If 'strict' is set to True, then those strings that are not
        entirely strictly conforming to JSON will result in a
        JSONDecodeError exception.

    * 'return_errors'    (Boolean, default False)

        Controls the return value from this function. If False, then
        only the Python equivalent object is returned on success, or
        an error will be raised as an exception.

        If True then a 2-tuple is returned: (object, error_list). The
        error_list will be an empty list [] if the decoding was
        successful, otherwise it will be a list of all the errors
        encountered.  Note that it is possible for an object to be
        returned even if errors were encountered.

    * 'return_stats'    (Boolean, default False)

        Controls whether statistics about the decoded JSON document
        are returns (and instance of decode_statistics).

        If True, then the stats object will be added to the end of the
        tuple returned.  If return_errors is also set then a 3-tuple
        is returned, otherwise a 2-tuple is returned.

    * 'write_errors'    (Boolean OR File-like object, default False)

        Controls what to do with errors.

        - If False, then the first decoding error is raised as an exception.
        - If True, then errors will be printed out to sys.stderr.
        - If a File-like object, then errors will be printed to that file.

        The write_errors and return_errors arguments can be set
        independently.

    * 'filename_for_errors'   (string or None)

        Provides a filename to be used when writting error messages.

    * 'allow_xxx', 'warn_xxx', and 'forbid_xxx'    (Booleans)

        These arguments allow for fine-adjustments to be made to the
        'strict' argument, by allowing or forbidding specific
        syntaxes.

        There are many of these arguments, named by replacing the
        "xxx" with any number of possible behavior names (See the JSON
        class for more details).

        Each of these will allow (or forbid) the specific behavior,
        after the evaluation of the 'strict' argument.  For example,
        if strict=True then by also passing 'allow_comments=True' then
        comments will be allowed.  If strict=False then
        forbid_comments=True will allow everything except comments.

    Unicode decoding:
    -----------------
    The input string can be either a python string or a python unicode
    string (or a byte array in Python 3).  If it is already a unicode
    string, then it is assumed that no character set decoding is
    required.

    However, if you pass in a non-Unicode text string (a Python 2
    'str' type or a Python 3 'bytes' or 'bytearray') then an attempt
    will be made to auto-detect and decode the character encoding.
    This will be successful if the input was encoded in any of UTF-8,
    UTF-16 (BE or LE), or UTF-32 (BE or LE), and of course plain ASCII
    works too.

    Note though that if you know the character encoding, then you
    should convert to a unicode string yourself, or pass it the name
    of the 'encoding' to avoid the guessing made by the auto
    detection, as with

        python_object = demjson.decode( input_bytes, encoding='utf8' )

    Callback hooks:
    ---------------
    You may supply callback hooks by using the hook name as the
    named argument, such as:
        decode_float=decimal.Decimal

    See the hooks documentation on the JSON.set_hook() method.

    FNr!  r"  write_errorsfilename_for_errorswrite_stats)r  r!  r"  r   T)r  r
  z%s----- Begin JSON statistics
z   | )r  z%s----- End of JSON statistics
r   )r  r  r  r  r   rU  r   r|   stderrr   r   r  r  )ry  r  r   r!  r"  r  r  r  todelr  r  rK  resultr|   r(  s                  r   r   r   -  s   R MLLK[[]FE' C  IMLL>!9LLL>!LLL(("%LL= KLL"  2J 	vA XX$4"1k	  F 4::L== 	C&&0C&DtK	
 $**K<<?BUUVfll==W=MN@CVVWMr   c                    ddl }ddl}|sd}t        | t              r| st	        d      |s4|j
                  j                  |       rt        |j                  d| z        t        |fd|i|}	 t        | d      }	 |j                  |       |j                          y# |j                          w xY w# t        $ r  w xY w)a  Encodes a Python object into JSON and writes into the given file.

    If no encoding is given, then UTF-8 will be used.

    See the encode() function for a description of other possible options.

    If the file already exists and the 'overwrite' option is not set
    to True, then the existing file will not be overwritten.  (Note,
    there is a subtle race condition in the check so there are
    possible conditions in which a file may be overwritten)

    r   Nr  Expected a file namezFile exists: %rr  wb)oserrnor>   rD   rC   pathexistsIOErrorEEXISTr   openr   closer/  )	r  r   r  	overwriter   r  r  jsondatafps	            r   encode_to_filer    s     h$H.//1ell$5$@AAc7H77H(D!	HHXHHJBHHJ  s   /B3 <B B03B>c                     t        | t              r/	 t        | d      }	 |j                         }|j	                          nt        d      t        |fd|i|S # |j	                          w xY w# t
        $ r  w xY w)zwDecodes JSON found in the given file.

    See the decode() function for a description of other possible options.

    rbr  r  )r>   rD   r  readr  r/  rC   r   )r  r  r   r  r  s        r   decode_filer    sy     (C 	h%B779
.//(8X888 
  		s   A. A A+.A9c                   l    e Zd ZdZdZdZdZdZddZe	d        Z
	 	 	 	 	 	 	 	 dd	Z	 	 	 	 	 	 	 dd
Zd Zy)jsonlinta  This class contains most of the logic for the "jsonlint" command.

    You generally create an instance of this class, to defined the
    program's environment, and then call the main() method.  A simple
    wrapper to turn this into a script might be:

        import sys, demjson
        if __name__ == '__main__':
            lint = demjson.jsonlint( sys.argv[0] )
            return lint.main( sys.argv[1:] )

    a  Usage: %(program_name)s [<options> ...] [--] inputfile.json ...

With no input filename, or "-", it will read from standard input.

The return status will be 0 if the file is conforming JSON (per the
RFC 7159 specification), or non-zero otherwise.

GENERAL OPTIONS:

 -v | --verbose    Show details of lint checking
 -q | --quiet      Don't show any output (except for reformatting)

STRICTNESS OPTIONS (WARNINGS AND ERRORS):

 -W | --tolerant   Be tolerant, but warn about non-conformance (default)
 -s | --strict     Be strict in what is considered conforming JSON
 -S | --nonstrict  Be tolerant in what is considered conforming JSON

 --allow=...      -\
 --warn=...         |-- These options let you pick specific behaviors.
 --forbid=...     -/      Use --help-behaviors for more

STATISTICS OPTIONS:

 --stats       Show statistics about JSON document

REFORMATTING OPTIONS:

 -f | --format     Reformat the JSON text (if conforming) to stdout
 -F | --format-compactly
        Reformat the JSON simlar to -f, but do so compactly by
        removing all unnecessary whitespace

 -o filename | --output filename
        The filename to which reformatted JSON is to be written.
        Without this option the standard output is used.

 --[no-]keep-format   Try to preserve numeric radix, e.g., hex, octal, etc.
 --html-safe          Escape characters that are not safe to embed in HTML/XML.

 --sort <kind>     How to sort object/dictionary keys, <kind> is one of:
%(sort_options_help)s

 --indent tabs | <nnn>   Number of spaces to use per indentation level,
                         or use tab characters if "tabs" given.

UNICODE OPTIONS:

 -e codec | --encoding=codec     Set both input and output encodings
 --input-encoding=codec          Set the input encoding
 --output-encoding=codec         Set the output encoding

    These options set the character encoding codec (e.g., "ascii",
    "utf-8", "utf-16").  The -e will set both the input and output
    encodings to the same thing.  The output encoding is used when
    reformatting with the -f or -F options.

    Unless set, the input encoding is guessed and the output
    encoding will be "utf-8".

OTHER OPTIONS:

 --recursion-limit=nnn     Set the Python recursion limit to number
 --leading-zero-radix=8|10 The radix to use for numbers with leading
                           zeros. 8=octal, 10=decimal.

REFORMATTING / PRETTY-PRINTING:

    When reformatting JSON with -f or -F, output is only produced if
    the input passed validation.  By default the reformatted JSON will
    be written to standard output, unless the -o option was given.

    The default output codec is UTF-8, unless an encoding option is
    provided.  Any Unicode characters will be output as literal
    characters if the encoding permits, otherwise they will be
    \u-escaped.  You can use "--output-encoding ascii" to force all
    Unicode characters to be escaped.

MORE INFORMATION:

    Use '%(program_name)s --version [-v]' to see versioning information.
    Use '%(program_name)s --copyright' to see author and copyright details.
    Use '%(program_name)s [-W|-s|-S] --help-behaviors' for help on specific checks.

    %(program_name)s is distributed as part of the "demjson" Python module.
    See %(homepage)s
EWOKNc                    ddl }ddl}|| _        |j                  j	                  |      | _        |r|| _        n|j                  | _        |r|| _        n|j                  | _        |r|| _        y|j                  | _        y)a  Create an instance of a "jsonlint" program.

        You can optionally pass options to define the program's environment:

          * program_name  - the name of the program, usually sys.argv[0]
          * stdin   - the file object to use for input, default sys.stdin
          * stdout  - the file object to use for outut, default sys.stdout
          * stderr  - the file object to use for error output, default sys.stderr

        After creating an instance, you typically call the main() method.

        r   N)	r  r|   program_pathr  basenameprogram_namestdinstdoutr  )r   r  r  r  r  r  r|   s          r   r  zjsonlint.__init__y  se     	(GG,,\:DJDJ DK**DK DK**DKr   c           
          dj                  t        t        j                               D cg c]  \  }}|t        k7  r	d|dd| c}}      }| j
                  | j                  t        |dz  S c c}}w )z>A multi-line string containing the program usage instructions.r
  z
          z>12z - )r  homepagesort_options_help)r  sortedr  r  r  _jsonlint_usager  __homepage__)r   smsdsorthelps       r   usagezjsonlint.usage  sv     99 %_%:%:%<=B? *,R0
 ## --$!)'
 
 	
s   A1
c
           
         | j                   }
d }|r|}nd }	 t        ||dd||||	      }|j                  D cg c]  }|j                  dv s| }}|j                  D cg c]  }|j                  dv s| }}|r| j                   }
n|r| j                  }
n| j
                  }
|rG|	j                         }t        |_        |dk(  rd|_	        nd|_	        t        |j                  ||      }|
|fS c c}w c c}w # t        $ r?}| j                   }
|r$|j                  ||j                         d       Y d }~|
|fS d }~wt        $ r:}| j                   }
|r|j                  |t!        |      d       Y d }~|
|fS d }~ww xY w)	NT)r  r!  r"  r  r  r  r  r!  )r  r  F)r  r  r
  )SUCCESS_FAILr   r   r  SUCCESS_WARNING
SUCCESS_OKr  rM  r  r  r   r  r.  r   r  r/  rD   )r   r  
verbose_fpreformat
show_statsinput_encodingoutput_encodingr  rN   jsonoptsrY  reformattedstats_fpresultsr(  r   r  encoptss                     r   _lintcheck_datazjsonlint._lintcheck_data  s    ##!HH)	'"!'$$'%	G(  '~~AS1SF  (/~~V9UVHV++..//"--/%8"{*/3G,/4G,$NN_7 %%/ W  	M''G  S#2H2H2J!KL: %%9  	=''G  S#c(!;<2 %%9	=s:   C; C1C1 C64C6;	F2D>>F
-E??Fc
           
      .   dd l }
d }|r|dk(  r+d}| j                  j                         }|rM| j                  }n@d|z  }	 t	        |d      }|j                         }|j                          |r| j                  }| j                  ||||||||	      \  }}|| j                  k7  r~|r||r 	 t	        |d	      }|j                  |       |S t        |
j                  d      r'| j                  j                  j                  |       |S | j                  j                  |       |S || j                  k(  r|r|j                  d|z         |S || j                  k(  r|r|j                  d|z         |S |r|j                  d|z         |S # t        $ r@}| j                  j                  |dt        |      d       | j                  cY d }~S d }~ww xY w# t        $ r7}| j                  j                  |dt        |      d       d
}Y d }~|S d }~ww xY w)Nr   r1   z	<stdin>: z%s: r  r  r
  )r  r  r  r  r  rN   r  r  Fbufferz%sok
z%sok, with warnings
z%shas errors
)r|   r  r  r  r  r  r  r   rD   r  r  r  r  r  r  r  )r   r  output_filenameverboser  r  r  r  r  r  r|   r  rN   r  r  r(  rY  r  s                     r   
_lintcheckzjsonlint._lintcheck  s    	
8s?Czz(H![[
8#C)(D)779
 ![[
#33!!)+  4 	 
 d'''H$ot4BHH[)$  JJ KK&&,,[9  KK%%k2  'JX^,  ,,,4s:;  -34O  )!!SX">?(((),  $KK%%CS&BC#G #$s5   ,F )G 	G5GGG	H,HHc                    ddl }ddl}ddl}d}d}d}d}d}	d}
d}d}t        t        ddd}	 |j                  |d	g d
      \  }}|D ]  \  }}|dv sd} |D ]  \  }}|dv r'| j                  j                  | j                          y|dk(  r| j                  j                  dd| j                  iz         | j                  j                  d|d   z         | j                  j                  ddz         | j                  j                  d       t        dci |}t        |j                        D ]h  }|j                  |      }|j!                  |      }| j                  j                  |j#                         dd|j%                  dd      dd|d       j  y|dk(  r| j                  j                  | j                  d t&        d!t(        d t*        d"       |dk(  r#| j                  j                  d#t,        d       |dk(  rQ| j                  j                  d$|j.                  j%                  dd      d       | j                  j                  d%       | j                  j                  d&|j0                  fz         | j                  j                  d'|j2                  d       | j                  j                  d(t4        fz         | j                  j                  d)t6        fz         t9        d*      t9        d+      k(  rd,}nd-}| j                  j                  d.|d       t:        rd-}nd,}| j                  j                  d/|d        y|d0k(  rl| j                  j                  | j                  d1       | j                  j                  d2t<        d3       | j                  j                  t>                y|dv rd}|d4v rd}|d5v rt@        |d<   d|d6<   |d7v rtB        |d<   |d8v rt        |d<   |d9v r	d}d|d:<   |d;v r	d|d:<   d<}|d=v rd}	|d>v r|}
|d?v r|}|}d}|d@v r|}d} |dAv r|}|dBv rd|dC<   |dDv r"|dEd }||v r||xx   dF|z   z  cc<   2|||<   9|dGv rd|d6<   D|dHv rd|d6<   O|dIk(  r||dJ<   [|dKv r!|dLv rdM|dN<   dM|dO<   o	 tE        |      |dN<   |dQk(  r	 tE        |      |dO<   |dSk(  r	 tE        |      |dT<   |dVk(  rK|j#                         }|dWk(  rtH        |dX<   |dYk(  rtJ        |dX<   |dZk(  rtL        |dX<   t        |dX<   |d[k(  ra	 tE        |      }d\} |jN                         }||kD  r"| j                  j                  d]||fz          y||kD  sN |jP                  |       b| j                  j                  d_|z          y d|d`<   t        dci |}|sdg}|D ]-  }	 | jS                  ||
|||	|||a      }|| jT                  k7  rd}/ |syy# |j
                  $ r@}| j                  j                  d|j                  d| j                  d       Y d}~yd}~ww xY w# tF        $ r | j                  j                  dP       Y  yw xY w# tF        $ r | j                  j                  dR       Y  yw xY w# tF        $ r | j                  j                  dU       Y  yw xY w# tF        $ r" | j                  j                  d^|z         Y  yw xY w# tV        $ r1 |j                  j                  db        |jX                  d       Y nw xY w)dai  The main routine for program "jsonlint".

        Should be called with sys.argv[1:] as its sole argument.

        Note sys.argv[0] which normally contains the program name
        should not be passed to main(); instead this class itself
        is initialized with sys.argv[0].

        Use "--help" for usage syntax, or consult the 'usage' member.

        r   NTr  Fr  d   )r  r   r  r  zvqfFe:o:sSW) r  quietr   zformat-compactlyr  rI  r   	nonstrictrY  z	html-safezxml-safez	encoding=zinput-encoding=zoutput-encoding=zsort=zrecursion-limit=zleading-zero-radix=zkeep-formatzno-keep-formatzindent=zindent-amount=zindent-limit=zindent-tab-width=zmax-items-per-line=zallow=zwarn=zforbid=zdeny=helpzhelp-behaviorsversion	copyrightzError: z.  Use "z  --help" for usage information.
r
   )z-vz	--verbose)z-hz--helpz--help-behaviorsa#  
BEHAVIOR OPTIONS:

These set of options let you control which checks are to be performed.
They may be turned on or off by listing them as arguments to one of
the options --allow, --warn, or --forbid ; for example:

    %(program_name)s --allow comments,hex-numbers --forbid duplicate-keys

r  z"The default shown is for %s mode

r   z%-7s %-25s %s
)DefaultBehavior_nameDescriptionzU------- ------------------------- --------------------------------------------------
r  r  ru  r1   25r
  z	--versionz (z
) version z)
zdemjson from zPython version: z%This python implementation supports:
z  * Max unicode: U+%X
z  * Unicode version: z*  * Floating-point significant digits: %d
z'  * Floating-point max 10^exponent: %d
r  r#  NoYesz%  * Floating-point has signed-zeros: z   * Decimal (bigfloat) support: z--copyrightz9 is distributed as part of the "demjson" python package.
zSee z


)z-qz--quiet)z-sz--strictr  )z-Sz--nonstrict)z-Wz
--tolerant)z-fz--formatr  )z-Fz--format-compactlyr  )z--stats)z-oz--output)z-ez
--encodingz--output-encodingz--input-encoding)z--html-safez
--xml-safer  )z--allowz--warnz--forbidr.   r  )z--keep-format)z--no-keep-formatz--leading-zero-radixr  )z--indentz--indent-amount)tabtabsr  r  r  z$Indentation amount must be a number
zindent-tab-widthz'Indentation tab width must be a number
z--max-items-per-liner  z$Max items per line must be a number
z--sortr  r  r  r  z--recursion-limiti z3Recursion limit must be a number between %d and %d
z%Recursion limit must be a number: %r
zUnknown option %r
r  )r  r  r  r  r  r  r  z
jsonlint interrupted!
r   )-r|   getoptr!  r  r  GetoptErrorr  r   r  r  r  r  r  r  r  rn  rt  r}  r   r   __version____date____file__r  r  unidata_versionr  r  rD   r9   r  __credits__rG  rM  r  r8   r  ry  r	  getrecursionlimitsetrecursionlimitr  r  KeyboardInterruptexit) r   argvr|   r  r!  recursion_limitrY  r  r  r  r  r  r  	kwoptionsoptsr   r(  optr  rK  r  r`   descszerohas_decr  r  	max_limit	old_limitr  fnrcs                                    r   mainzjsonlint.main-  s    	('
! $%"	
	,	!%JD$\  	HC))	
  o	HC&&!!$**-**!!	 &t'8'89
: !!:Yx=PP !!%(SS !!"RS -9- &q 7 Hx0A..x8DKK%%779h&6&6sC&@$H #!!(((KK d?KK%%X&GHd?KK%%25++2E2EdC2PR KK%%&NOKK%%&?3>>BS&STKK%%7B7R7RT KK%%E*,- KK%%Bl_T 3x3t9, $ %KK%%GLN "'"&KK%%BIK %!!((+ !!L"BC!!+.++))**&7	(#+0	-(--&9	(#,,&5	(#**05	,-4404	,-&$!
**"%,,!$"%!&,-"%!&+,!$55)-	+&99QRY&f%s2%(+If%**+/	-(--+0	-(..25	./77/)12Io.45I01!58X	/2 **47HI01 ..69#hI23 iik'>-7Ik*J&-:Ik*J&-:Ik*-7Ik*++?&)#hO
 !'I 5 5 5 7I&2))R()45  !(94---o>!!"7#"=>_o	d (+	#$,), 6D 	B__$3#%)#1$3% % 	 ( $G!	* { !! 	KK77D--/ 	` & !))*QR ! " KK%%&PQ " KK%%&MN  " KK%%&NQT&TUV % 

  !<=sq   X& Y8Z#4[[96*\'&Y556Y00Y58$Z Z #$[
[$[65[69'\$#\$'6]! ]!)r  NNN)NFFNNTr  N)FFFNNTN)r   r   r   r    r  r  r  r  r  r   r  r  r  r  r   r   r   r  r    s    VOn LOJ%@ 
 
$ >&H BHbr   r  rR  r  r   )r  F)dr    
__author__r  r  r  __version_info__r  r  r   rF   r  r   r|   vir   r   r9  	_py_minorrl  content_typefile_extr  r   r9   rB   r^   r  r  r  ra   rc   rg   r  r   rm   rn   r   r  r   r   r   r   r   r   r   r   r   r#  r   r  r  r/  r  r  r  r  r.  r  r  r  r  r  r  r  rG  r  rM  r=  r>  r   r  r  r  r   r   r   r   r   r  ra  r  r	  r  ry  r  r  r  r  rH  r  r:  r  r
  r  rU  r   r   r  r  r  r   r   r   <module>r      sS  rh H
5 . 2K;~/JK  $%5  (88RXXIy "V  01   (- N"b /EU.K +|2v  	!;| ./ S&2s 2r
	
 f@F f@\Rf Rt[+f [+F`$f `$P	I 		= 		 		 	z zz	i 	H/ H2	i 	H/ H<.06 .0lN+ N+lD6 DV    	  "  )   [T4 [T| 	

 ;>.9? . <  4O	'6%9 O	'nM%W6 M%WfJFRcL"J90v W{  (a5"Q%Iy(s   H H H 