o
    iwL                     @   s   d dl Z d dlZd dlZd dlZddlmZ ejd  dk r$eefZ	eZnefZ	e
Z			d%ddZ			d%dd	Zd
d Zdd Z					d&ddZ				d&ddZdd Zdd Zdd Zdd Zdd Zdd Zdd  Zdad!d" Zd#d$ ZdS )'    N   )Parser   Tc	           
      C   s"   |   }	t|	||||||||d	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.
    )encodingclsobject_hookparse_float	parse_intparse_constantobject_pairs_hookallow_duplicate_keys)readloads)
fpr   r   r   r   r	   r
   r   r   s r   D/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/json5/lib.pyload   s   
r   c	                    s   |du sJ dt jd dk rtd}	ntd}	t| |	r&|p d}| |} | s,tdt| d	}
|
 \}}}|r>t|d
d }|rG|}nrPfdd}ndd }|s^|  fdd}|pat}|pet	}|pi|}t
|||||S )a  Deserialize ``s`` (a ``str`` or ``unicode`` instance 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.
    Nz!Custom decoders are not supportedr   r        zutf-8z!Empty strings are not legal JSON5z<string>c                 S   s   t | ddddS )NInfinityinfNaNnan)floatreplace)r   r   r   r   _fp_constant_parserS   s   z"loads.<locals>._fp_constant_parserc                    s    t | S Ndictpairs)r   r   r   <lambda>Y   s    zloads.<locals>.<lambda>c                 S   s   t | S r   r   r    r   r   r   r"   [   s    c                    s
   t |  S r   )_reject_duplicate_keysr    )_orig_dictifyr   r   r"   _   s   
 )sysversion_infotype
isinstancedecode
ValueErrorr   parser   int	_walk_ast)r   r   r   r   r   r	   r
   r   r   decodable_typeparserasterr_r   dictifyr   )r$   r   r   r   4   s4   



r   c                 C   s8   t  }| D ]\}}||v rtd||| q|| S )Nz"Duplicate key "%s" found in object)setr*   add)r!   r3   keyskeyr2   r   r   r   r#   h   s   
r#   c                    s  | dkrd S | dkrdS | dkrdS | \}}|dkrJ| ds$| dr*|d	d
S d|v s6d|v s6d|v r:|S d|v sBd|v rF|S |S |dkrP|S |dkrpg }|D ]\}}	t|	 }
|||
f qX |S |dkr fdd|D S td|  )NNoneTrueTFalseFnumber0x0X   )base.eEr   r   stringobjectarrayc                    s   g | ]
}t | qS r   )r-   .0elr3   r
   r   r	   r   r   
<listcomp>   s    z_walk_ast.<locals>.<listcomp>zunknown el: )
startswithr-   append	Exception)rH   r3   r   r	   r
   tyvr!   r7   val_exprvalr   rI   r   r-   p   s<   
r-   Fc                 K   s0   | tt| ||||||||	|
|||d dS )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. 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 ``dump(obj, fp, quote_keys=True, trailing_commas=False,                    allow_duplicate_keys=True)``
    should produce exactly the same output as ``json.dump(obj, fp).``
    )objskipkeysensure_asciicheck_circular	allow_nanr   indent
separatorsdefault	sort_keys
quote_keystrailing_commasr   N)writestrdumps)rR   r   rS   rT   rU   rV   r   rW   rX   rY   rZ   r[   r\   r   kwargsr   r   r   dump   s   )ra   c                 K   s~   | dddu sJ d|du r|du rd}nd}|pt}|r#t }nd}d}d}t| ||||||||	|
|||||\}}|S )aL  Serialize ``obj`` to a JSON5-formatted ``str``.

    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, : ),rb   r   F)get_raise_type_errorr4   _dumps)rR   rS   rT   rU   rV   r   rW   rX   rY   rZ   r[   r\   r   r`   seenlevelis_keyr2   rO   r   r   r   r_      s"   '

r_   c                 C   s  | du rd}np| du rd}ni| d u rd}nb| t dkr#|r d}nWt | t dkr1|r.d	}nIt t| t rCt| rC|r@d
}n7t t| tr_|rXt| rX|	sXt| sXd| fS dt| |fS t| t	rjt	
| }nt| t rut 
| }nd }|r|d urdd| fS |rdS tdt|  |d urd|fS |d urd}|
rd}t|t	kr|dkrdd| |  }|dd| |d   7 }nd}|d7 }nd||  }|d||d   7 }nd}d}|\}}||7 }|d urt| }||v rtd|| t| drt| drt| |||||||||	|
|||d ||||}n9t| dr@t| dr@t| |||||||||	|
|||d |||}nt|| |||||||||	|
||||d }|d ur`|| d|fS )NTtrueFfalsenullr   r   z-infz	-Infinityr   z"%s")FNinvalid key %sr   rc   r   
 r   zCircular reference detected.r6   __getitem____iter__)r   r*   r(   mathisnan	str_types	_is_ident_is_reserved_word	_dump_strr,   __repr__	TypeErrorreprr'   idr5   hasattr
_dump_dict_dump_arrayrf   remove)rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r   rg   rh   ri   r   end_str
indent_stritem_sepkv_sepir   r   r   rf     s   








rf   c                 C   s  | sdS |rt |  }n|  }d| }d}t }|D ]^}t||||||||||	|
|||dd\}}|rp|sH||v rCtdt| || |rN||7 }||| t| | |||||||||	|
|||ddd  7 }|d7 }q|sztd	t| q||d
 7 }|S )Nz{}{r   T)ri   zduplicate key %sFr   rm   })sortedr6   r4   rf   r*   rz   r5   ry   )rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r   rg   rh   r   r   r   r   r6   r   num_items_addednew_keysr7   	valid_keykey_strr   r   r   r}   o  sL   



r}   c                    sH   | sdS d| |  	
fdd| D  | d S )Nz[][c                    s4   g | ]}t |
	 d d qS )Fr   )rf   rF   r   rV   rU   rY   rT   rW   rh   r[   rg   rX   rS   rZ   r\   r   r   rJ     s    
z_dump_array.<locals>.<listcomp>])join)rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r   rg   rh   r   r   r   r   r   r   r~     s   &r~   c                 C   s|  dg}| D ]}|dkr| d q|dkr| d q|dkr%| d q|dkr/| d q|d	kr9| d
 q|dkrC| d q|dkrM| d q|dkrW| d q|dkra| d q|dkrk| d q|dkru| d q|s}| | qt|}|dkr|dk r| | q|dk r| dd|   q|d }d|d?  }d|d@  }| d ||f  qd!|d S )"N"\z\\z\"u    z\u2028u    z\u2029rn   z\nz\rz\bz\f	z\tz\v z\0       i   z\uz%04xi   
   i   i  z\u%04x\u%04xr   )rL   ordr   )rR   rT   retchorQ   highlowr   r   r   rw     sH   rw   c                 C   sT   t | } | rt| d s| d dvrdS | dd  D ]}t|s'|dvr' dS qdS )Nr   )$r2   Fr   T)r^   _is_id_start_is_id_continue)kr   r   r   r   ru     s   ru   c                 C      t | dv S )N)LuLlLiLtLmLoNlunicodedatacategoryr   r   r   r   r        r   c                 C   r   )N)r   r   r   r   r   r   r   NdMnMcPcr   r   r   r   r   r     r   r   c                 C   s2   t d u rtddg d d a t | d uS )N(|)$breakcasecatchclassconstcontinuedebuggerrY   deletedoelseenumexportextendsrk   finallyforfunctionifimportin
instanceofnewrl   returnsuperswitchthisthrowrj   trytypeofvarvoidwhilewithz)$)_reserved_word_rerecompiler   match)r   r   r   r   rv     s
   %&rv   c                 C   s   t dt|  )Nz%s is not JSON5 serializable)ry   rz   )rR   r   r   r   re     s   re   )NNNNNNNT)FTTTNNNNFFTT)rr   r   r%   r   r/   r   r&   r^   unicodert   r,   longr   r   r#   r-   ra   r_   rf   r}   r~   rw   ru   r   r   r   rv   re   r   r   r   r   <module>   sR   

4 
1
@n-)
.