
    )gPU                     f   d dl Z d dlZd dlmZmZmZmZmZmZm	Z	m
Z
mZ d dlZddlmZ ddddddddddedee   d	dd
eeeeef   gef      deeegef      deeegef      deeegef      deeee
eef      gef      dedefdZddddddddddedee   d	dd
eeeeef   gef      deeegef      deeegef      deeegef      deeee
eef      gef      defdZd Zdeee
eef      gef   fdZddddddddddddddedededededed	ddeeeef      dee
eef      d eeegef      d!ed"ed#edefd$Zddddddddddddddededededed	ddeeeef      dee
eef      d eeegef      d!ed"ed#edefd%Zd&ee	e      d'ed(efd)Zd* Zd+ Zd, Zd- Zd. Zd/ Zdad0 Z d1 Z!y)2    N)	AnyCallableIOIterableMappingOptionalSetTupleUnion   )ParserTencodingclsobject_hookparse_float	parse_intparse_constantobject_pairs_hookallow_duplicate_keysfpr   r   r   r   r   r   r   r   returnc                J    | j                         }	t        |	||||||||	      S )a  Deserialize ``fp`` (a ``.read()``-supporting file-like object
    containing a JSON document) to a Python object.

    Supports almost the same arguments as ``json.load()`` except that:
        - the `cls` keyword is ignored.
        - an extra `allow_duplicate_keys` parameter supports checking for
          duplicate keys in a object; by default, this is True for
          compatibility with ``json.load()``, but if set to False and
          the object contains duplicate keys, a ValueError will be raised.
    r   )readloads)
r   r   r   r   r   r   r   r   r   ss
             )lib/python3.12/site-packages/json5/lib.pyloadr   !   s7    2 		A	%+1
 
    r   c                j   |J d       t        | t              r|xs d}| j                  |      } | st        d      t	        | d      }	|	j                         \  }
}}|rt        |      d }|r|}nrfd}nt        }|s|fd}|xs t        }|xs t        }|xs |}t        |
||||      S )a  Deserialize ``s`` (a string containing a JSON5 document) to a Python
    object.

    Supports the same arguments as ``json.load()`` except that:
        - the `cls` keyword is ignored.
        - an extra `allow_duplicate_keys` parameter supports checking for
          duplicate keys in a object; by default, this is True for
          compatibility with ``json.load()``, but if set to False and
          the object contains duplicate keys, a ValueError will be raised.
    z!Custom decoders are not supportedzutf-8z!Empty strings are not legal JSON5z<string>c                 X    t        | j                  dd      j                  dd            S )NInfinityinfNaNnan)floatreplace)r   s    r   _fp_constant_parserz"loads.<locals>._fp_constant_parsern   s%    QYYz5199%GHHr   c                 &     t        |             S N)dict)pairsr   s    r   dictifyzloads.<locals>.dictifyu   s    tE{++r   c                     t        |       S r*   )_reject_duplicate_keys)r,   _orig_dictifys    r   r-   zloads.<locals>.dictify}   s    )%??r   )

isinstancebytesdecode
ValueErrorr   parser+   r&   int	_walk_ast)r   r   r   r   r   r   r   r   r   parserasterr_r(   r-   r0   s      `           @r   r   r   H   s    2 ;;;;;!U&wHHX<==Az"F,,.KCa
oI #		, 	@ &K SI#:':NS';	>JJr   c                     t               }| D ])  \  }}||v rt        d| d      |j                  |       +  ||       S )NzDuplicate key "z" found in object)setr4   add)r,   r-   keyskeyr;   s        r   r/   r/      sJ    5DQ$;se3DEFF  5>r   r-   c           
         | dk(  ry | dk(  ry| dk(  ry| \  }}|dk(  rX|j                  d      s|j                  d      r
 ||d	
      S d|v sd|v sd|v r ||      S d|v sd|v r ||      S  ||      S |dk(  r|S |dk(  r6g }|D ]'  \  }}	t        |	||||      }
|j                  ||
f       )  ||      S |dk(  r|D  cg c]  } t        | ||||       c} S t        d| z         c c} w )NNoneTrueTFalseFnumber0x0X   )base.eEr"   r$   stringobjectarrayzunknown el: )
startswithr7   appendr4   )elr-   r   r   r   tyvr,   r@   val_exprvals              r   r7   r7      s;    
V|	V|	W}EB	X~<<d!3QR((!8sax3!8q>!?eqj!!$$|	X~	X~MC';	>C LL#s$	 
 u~	W} 
 b';	>J
 	
 ^b(
))	
s    C'F)skipkeysensure_asciicheck_circular	allow_nanr   indent
separatorsdefault	sort_keys
quote_keystrailing_commasr   objrW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   c                T    ~|j                  t        | ||||||||	|
|||             y)a  Serialize ``obj`` to a JSON5-formatted stream to ``fp``,
    a ``.write()``-supporting file-like object.

    Supports the same arguments as ``json.dump()``, except that:

    - The ``cls`` keyword is not supported.
    - The ``encoding`` keyword is ignored; Unicode strings are always
      written.
    - By default, object keys that are legal identifiers are not quoted;
      if you pass ``quote_keys=True``, they will be.
    - By default, if lists and objects span multiple lines of output (i.e.,
      when ``indent`` >=0), the last item will have a trailing comma
      after it. If you pass ``trailing_commas=False``, it will not.
    - If you use a number, a boolean, or ``None`` as a key value in a dict,
      it will be converted to the corresponding JSON string value, e.g.
      "1", "true", or "null". By default, ``dump()`` will match the `json`
      modules behavior and produce malformed JSON if you mix keys of
      different types that have the same converted value; e.g.,
      ``{1: "foo", "1": "bar"}`` produces '{"1": "foo", "1": "bar"}', an
      object with duplicated keys. If you pass
      ``allow_duplicate_keys=False``, an exception will be raised instead.
    - If `quote_keys` is true, then keys of objects will be enclosed in
      quotes, as in regular JSON. Otherwise, keys will not be enclosed in
      quotes unless they contain whitespace.
    - If `trailing_commas` is false, then commas will not be inserted after
      the final elements of objects and arrays, as in regular JSON.
      Otherwise, such commas will be inserted.
    - If `allow_duplicate_keys` is false, then only the last entry with a
      given key will be written. Otherwise, all entries with the same key
      will be written.

    Calling ``dump(obj, fp, quote_keys=True, trailing_commas=False,                    allow_duplicate_keys=True)``
    should produce exactly the same output as ``json.dump(obj, fp).``
    )ra   rW   rX   rY   rZ   r   r[   r\   r]   r^   r_   r`   r   N)writedumps)ra   r   rW   rX   rY   rZ   r   r[   r\   r]   r^   r_   r`   r   kwargss                  r   dumprf      sC    l 	HH%)!!+!5	
r   c                    |j                  dd      J d       ~||d}nd}|xs t        }|rt               }nd}d}d}t        | ||||||||	|
|||||      \  }}|S )aQ  Serialize ``obj`` to a JSON5-formatted string.

    Supports the same arguments as ``json.dumps()``, except that:

    - The ``cls`` keyword is not supported.
    - The ``encoding`` keyword is ignored; Unicode strings are always
      written.
    - By default, object keys that are legal identifiers are not quoted;
      if you pass ``quote_keys=True``, they will be.
    - By default, if lists and objects span multiple lines of output (i.e.,
      when ``indent`` >=0), the last item will have a trailing comma
      after it. If you pass ``trailing_commas=False``, it will not.
    - If you use a number, a boolean, or ``None`` as a key value in a dict,
      it will be converted to the corresponding JSON string value, e.g.
      "1", "true", or "null". By default, ``dump()`` will match the `json`
      modules behavior and produce malformed JSON if you mix keys of
      different types that have the same converted value; e.g.,
      ``{1: "foo", "1": "bar"}`` produces '{"1": "foo", "1": "bar"}', an
      object with duplicated keys. If you pass
      ``allow_duplicate_keys=False``, an exception will be raised instead.
    - If `quote_keys` is true, then keys of objects will be enclosed
      in quotes, as in regular JSON. Otheriwse, keys will not be enclosed
      in quotes unless they contain whitespace.
    - If `trailing_commas` is false, then commas will not be inserted after
      the final elements of objects and arrays, as in regular JSON.
      Otherwise, such commas will be inserted.
    - If `allow_duplicate_keys` is false, then only the last entry with a
      given key will be written. Otherwise, all entries with the same key
      will be written.

    Calling ``dumps(obj, quote_keys=True, trailing_commas=False,                     allow_duplicate_keys=True)``
    should produce exactly the same output as ``json.dumps(obj).``
    r   Nz!Custom encoders are not supported)z, : ),rh   r   F)get_raise_type_errorr=   _dumps)ra   rW   rX   rY   rZ   r   r[   r\   r]   r^   r_   r`   r   re   seenlevelis_keyr;   rT   s                      r   rd   rd     s    h ::eT"*O,OO*>%J$J**G#&5EFDAq" Hr   rm   rn   ro   c                    | du rd}n| du rd}n| d}n| t        d      k(  r|rd}nt               | t        d      k(  r|rd	}nt               t        | t               r$t        j                  |       r|rd
}nt               t        | t
              r,|rt        |       r|	st        |       sd| fS dt        | |      fS t        | t              rt        j                  |       }n(t        | t               rt         j                  |       }nd }|r$|dd| dfS |ryt        dt        |              |d|fS |Wd}|
rd}t        |t              r*|dkD  rdd|z  |z  z   }|dd|z  |dz
  z  z   z  }n#d}|dz  }nd||z  z   }|d||dz
  z  z   z  }nd}d}|\  }}||z  }|+t        |       }||v rt        d      |j                  |       t        | d      r,t        | d      r t!        | |||||||||	|
|||dz   ||||      }nYt        | d      r+t        | d      rt#        | |||||||||	|
|||dz   |||      }n"t%         ||       |||||||||	|
||||      d   }||j'                         d|fS )NTtrueFfalsenullr#   r"   z-infz	-Infinityr$   ")FNzinvalid key  ri   r   
 r   zCircular reference detected.r?   __getitem____iter__)r&   r4   r1   mathisnanstr	_is_ident_is_reserved_word	_dump_strr6   __repr__	TypeErrorrepridr>   hasattr
_dump_dict_dump_arrayrl   remove)ra   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   r   rm   rn   ro   r   end_str
indent_stritem_sepkv_sepis                        r   rl   rl   ]  s   $ d{			e	A,	f	A,	C	DJJsOA,	C	#%c*9YsL111	C	 LL	C	NN3=1QCq>!,tCyk233}QwGfc"z!C&L5$88
4#,%!)"<<<!
4.Jtf	222G
!Hf
HsG9;<<
 sF] ; AI%
( 
m	$j)A AI#
( CL 
  !$ A!8Or   c                    | sy|rt        | j                               }n| j                         }d|z   }d}t               }|D ]  }t        ||||||||||	|
|||d      \  }}|r|s%|s,||v rt	        dt        |             |j                  |       |r||z  }|||z   t        | |   |||||||||	|
|||d      d   z   z  }|dz  } ||d	z   z  }|S )
Nz{}{r   T)ro   zduplicate key Fr   })sortedr?   r=   rl   r4   r   r>   )ra   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   r   rm   rn   r   r   r   r   r?   r   num_items_addednew_keysr@   	valid_keykey_strs                            r   r   r     sG   ( chhj!xxzjAOuH# 
	7$ I#(" >$s)!=>>LL!MA	C$  !	
* 	1g j 3AHr   c                     | syd|z   |j                  | D cg c]  }t        ||||||||||	|
|||d      d     c}      z   |z   dz   S c c}w )Nz[][Fr   ])joinrl   )ra   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   r   rm   rn   r   r   r   rR   s                     r   r   r   \  s    & 
	
--& %$ B#  "#(  !" %
	
0 1	2 3	s   #A	
c                 T   dg}| D ]  }|dk(  r|j                  d       |dk(  r|j                  d       2|dk(  r|j                  d       I|dk(  r|j                  d       `|d	k(  r|j                  d
       w|dk(  r|j                  d       |dk(  r|j                  d       |dk(  r|j                  d       |dk(  r|j                  d       |dk(  r|j                  d       |dk(  r|j                  d       |s|j                  |       t        |      }d|cxk  rdk  rn n|j                  |       C|dk  r|j                  d|d       _|dz
  }d|dz	  z   }d|dz  z   }|j                  d|dd|d        d j                  |      dz   S )!Nrt   \z\\z\"u    z\u2028u    z\u2029rv   z\nz\rz\bz\f	z\tz\v z\0       i   z\u04xi   
   i   i  ru   )rQ   ordr   )ra   rX   retchorV   highlows           r   r   r     s   %C:JJv3YJJu8^JJy!8^JJy!4ZJJu4ZJJu4ZJJu4ZJJu4ZJJu4ZJJu4ZJJuJJrNBAQ}}

2U

S3=)'k+e,

Sc
#c#Y78G H 773<#r   c                 l    | rt        | d         s| d   dvry| dd  D ]  }t        |      r|dvs y y)Nr   )$r;   Fr   T)_is_id_start_is_id_continue)kr   s     r   r}   r}     sE    L1&1Q4z+Aer"r';  r   c                 0    t        j                  |       dv S )N)LuLlLiLtLmLoNlunicodedatacategoryr   s    r   r   r     s    # (  r   c                 0    t        j                  |       dv S )N)r   r   r   r   r   r   r   NdMnMcPcr   r   s    r   r   r     s    # (  r   c                     t         ,t        j                  ddj                  g d      z   dz         a t         j	                  |       d uS )N(|)$breakcasecatchclassconstcontinuedebuggerr]   deletedoelseenumexportextendsrr   finallyforfunctionifimportin
instanceofnewrs   r   superswitchthisthrowrq   trytypeofvarvoidwhilewithz)$)_reserved_word_rerecompiler   match)r   s    r   r~   r~     sW      JJhh%'(R S)+
X ""1%T11r   c                 0    t        t        |        d      )Nz is not JSON5 serializable)r   r   )ra   s    r   rk   rk     s    
tCyk!;<
==r   )"rz   r   typingr   r   r   r   r   r   r	   r
   r   r   r8   r   r|   boolr   r   r/   r7   r6   rf   rd   rl   r   r   r   r}   r   r   r   r~   rk    r   r   <module>r      sr    	
 
 
   #@D260459 	!%$
$ sm$ 
	$
 (GCH$5#6#;<=$ (C5#:./$ #,-$ XseSj12$  (5c?+,c12$ $ 	$T #@D260459 	!%<K
<K sm<K 
	<K
 (GCH$5#6#;<=<K (C5#:./<K #,-<K XseSj12<K  (5c?+,c12<K <K~%*xc3h01367%*X (,,0.2 !%G	G
G 	G
 G G G 
G U38_%G sCx)G hucz*+G G G G GZ (,,0.2 !%X	X X 	X
 X X 
X U38_%X sCx)X hucz*+X X X X Xvc 3s8
c c cLVr0f&R	   12h>r   