
    Xh%                         d Z ddlZddlZddlZddlZej
                  Z G d dej                        Z G d de	      Z
d Zd Zd	 Zd
 ZddZddZ	d Zej"                  Zej$                  Zy)zImproved JSON serialization.
    Nc                   "     e Zd ZdZ fdZ xZS )JsonEncoderzCustomizable JSON encoder.

    If the object implements __getstate__, then that method is invoked, and its
    result is serialized instead of the object itself.
    c                 h    	 |j                   } |       S # t        $ r Y nw xY wt        |   |      S N)__getstate__AttributeErrorsuperdefault)selfvalue	get_state	__class__s      G/var/www/html/myenv/lib/python3.12/site-packages/debugpy/common/json.pyr
   zJsonEncoder.default   sB    	**I ;  		 wu%%s    	"")__name__
__module____qualname____doc__r
   __classcell__)r   s   @r   r   r      s    & &    r   c                   H    e Zd ZdZeZ	  ed      Z	 d Zd Zd Z	d Z
d Zy	)

JsonObjectzzA wrapped Python object that formats itself as JSON when asked for a string
    representation via str() or format().
       )indentc                 6    t        |t              rJ || _        y r   )
isinstancer   r   )r   r   s     r   __init__zJsonObject.__init__-   s    eZ000
r   c                     t         r   )NotImplementedErrorr   s    r   r   zJsonObject.__getstate__1   s    !!r   c                 @    t        j                  | j                        S r   )builtinsreprr   r   s    r   __repr__zJsonObject.__repr__4   s    }}TZZ((r   c                     t        |       S r   )formatr   s    r   __str__zJsonObject.__str__7   s    d|r   c                     |r!d|z   dz   }t        |d| j                  i      }n| j                  }|j                  | j                        S )a  If format_spec is empty, uses self.json_encoder to serialize self.value
        as a string. Otherwise, format_spec is treated as an argument list to be
        passed to self.json_encoder_factory - which defaults to JSONEncoder - and
        then the resulting formatter is used to serialize self.value as a string.

        Example::

            format("{0} {0:indent=4,sort_keys=True}", json.repr(x))
        zjson_encoder_factory()json_encoder_factory)evalr)   json_encoderencoder   )r   format_specmake_encoderencoders       r   
__format__zJsonObject.__format__:   sS      3[@3FL5t7P7PQG ''G~~djj))r   N)r   r   r   r   r   r)   r+   r   r   r#   r&   r0    r   r   r   r   "   s8     ';'q1LK")*r   r   c                 z    |D ]'  }t        |t        j                        s	  ||       c S  y# t        $ r Y 6w xY w)zGConvert value (str) to number, otherwise return None if is not possibleN)
issubclassnumbersNumber
ValueError)r   	classinfoone_infos      r   
_converterr9   `   sB     h/&  s   .	::c                  n     t               sJ |j                  dd      t        |      rJ  fd}|S )zReturns a validator for a JSON property that requires it to have a value of
    the specified type. If optional=True, () is also allowed.

    The meaning of classinfo is the same as for isinstance().
    optionalFc                     r| dk(  st        |       r| S t        |       }|r|S s| dk(  rt        d      t        ddj	                  d D              z         )Nr1   zmust be specifiedzmust be  or c              3   4   K   | ]  }|j                     y wr   )r   ).0ts     r   	<genexpr>z,of_type.<locals>.validate.<locals>.<genexpr>   s     4SAQZZ4Ss   )r   r9   r6   	TypeErrorjoin)r   converted_valuer7   r;   s     r   validatezof_type.<locals>.validateu   sc    "E9)EL(	:O&& !455J4S4S)SSTTr   lenpop)r7   kwargsrE   r;   s   `  @r   of_typerJ   j   s:     y>>zz*e,H6{?
U Or   c                       fd}|S )zReturns a validator for a JSON property with a default value.

    The validator will only allow property values that have the same type as the
    specified default value.
    c                     | dk(  rS t        | t                    r| S t        dj                  t              j                              )Nr1   zmust be {0})r   typerB   r%   r   )r   r
   s    r   rE   zdefault.<locals>.validate   sB    B;NtG}-LM00g1G1GHIIr   r1   )r
   rE   s   ` r   r
   r
      s    J Or   c                  n     t               sJ |j                  dd      t        |      rJ  fd}|S )zReturns a validator for a JSON enum.

    The validator will only allow the property to have one of the specified values.

    If optional=True, and the property is missing, the first value specified is used
    as the default.
    r;   Fc                 n    r
| dk(  rd   S | v r| S t        dj                  t                          )Nr1   r   zmust be one of: {0!r})r6   r%   list)r   r;   valuess    r   rE   zenum.<locals>.validate   s=    !9f_L4;;DLIJJr   rF   )rQ   rI   rE   r;   s   `  @r   enumrR      s:     v;;zz*e,H6{?K Or   c                      sd  n+t         t              st         t              rt                d nt        t              r)D ch c]  }t        j                  |       c}fdngt        t              r=dt              cxk  rdk  sJ  J t        d D              dz   dd \  fd	nt        j                        fd
 fd}|S c c}w )a  Returns a validator for a JSON array.

    If the property is missing, it is treated as if it were []. Otherwise, it must
    be a list.

    If validate_item=False, it's treated as if it were (lambda x: x) - i.e. any item
    is considered valid, and is unchanged. If validate_item is a type or a tuple,
    it's treated as if it were json.of_type(validate).

    Every item in the list is replaced with validate_item(item) in-place, propagating
    any exceptions raised by the latter. If validate_item is a type or a tuple, it is
    treated as if it were json.of_type(validate_item).

    If vectorize=True, and the value is neither a list nor a dict, it is treated as
    if it were a single-element list containing that single value - e.g. "foo" is
    then the same as ["foo"]; but {} is an error, and not [{}].

    If size is not None, it can be an int, a tuple of one int, a tuple of two ints,
    or a set. If it's an int, the array must have exactly that many elements. If it's
    a tuple of one int, it's the minimum length. If it's a tuple of two ints, they
    are the minimum and the maximum lengths. If it's a set, it's the set of sizes that
    are valid - e.g. for {2, 4}, the array can be either 2 or 4 elements long.
    c                     | S r   r1   )xs    r   <lambda>zarray.<locals>.<lambda>   s    ! r   c                      y)NTr1   )_s    r   rV   zarray.<locals>.<lambda>   s    r   c                     t        |       v xs0 dj                  dj                  d t              D                    S )Nmust have {0} elementsr=   c              3   2   K   | ]  }t        |        y wr   )strr?   ns     r   rA   z*array.<locals>.<lambda>.<locals>.<genexpr>   s     9qCF9s   )rG   r%   rC   sortedr   sizes    r   rV   zarray.<locals>.<lambda>   s=    J$ '..9F4L99 r         c              3   F   K   | ]  }t        j                  |        y wr   )operatorindexr]   s     r   rA   zarray.<locals>.<genexpr>   s     51X^^A&5s   !r   r   c                     t        |       k  rdj                        S t        |       k  rdj                        S dS )Nzmust have at least {0} elementszmust have at most {0} elementsTrG   r%   )r   max_lenmin_lens    r   rV   zarray.<locals>.<lambda>   sV    5zG# .44W=  "s5zG'; 288A 
  r   c                 F    t        |       k(  xs dj                        S )NrZ   rh   r`   s    r   rV   zarray.<locals>.<lambda>   s%    J$G":"A"A$"G r   c                 R   | dk(  rg } nrt        | t        t        f      s| g}  t        t              |         |       }|durt	        |      t        |       D ]  \  }}	  |      | |<    | S # t        t        f$ r%} t        |      dt        |       d|       d }~ww xY w)Nr1   T[] )	r   rP   dictrJ   r6   	enumeraterB   rM   r"   )r   size_erriitemexcvalidate_itemvalidate_size	vectorizes        r   rE   zarray.<locals>.validate   s    B;Ez%$>GEe '4X&& ' 	6GAt6(.a	6
  z* 6d3i!DG9Bse 4556s   #A22B& B!!B&)r   rM   tuplerJ   setre   rf   rG   )ru   rw   ra   r^   rE   ri   rj   rv   s   ```  @@@r   arrayrz      s    2 #	M4	(J}e,L.|&	D#	+/0aq!0
 
D%	 CI""""""555 7NAa0
 ~~d#
& OW 1s   C'c                 h     t         t              st         t              rt                 fd}|S )av  Returns a validator for a JSON object.

    If the property is missing, it is treated as if it were {}. Otherwise, it must
    be a dict.

    If validate_value=False, it's treated as if it were (lambda x: x) - i.e. any
    value is considered valid, and is unchanged. If validate_value is a type or a
    tuple, it's treated as if it were json.of_type(validate_value).

    Every value in the dict is replaced with validate_value(value) in-place, propagating
    any exceptions raised by the latter. If validate_value is a type or a tuple, it is
    treated as if it were json.of_type(validate_value). Keys are not affected.
    c                     | dk(  ri S  t        t              |        r$| j                         D ]  \  }}	  |      | |<    | S # t        t        f$ r%} t        |      dt        |       d|       d }~ww xY w)Nr1   rm   rn   )rJ   ro   itemsrB   r6   rM   r"   )r   kvrt   validate_values       r   rE   zobject.<locals>.validate  s    B;Ie :1:-a0E!H:
  ":. :#$s)aQy3%$899:s   AA: A55A:)r   rM   rx   rJ   )r   rE   s   ` r   objectr      s.     .$':ne+L 0 Or   c                     t        |       S r   )r   )r   s    r   r"   r"     s    er   )FFN)F)r   r!   jsonr4   re   JSONDecoderJsonDecoderJSONEncoderr   r   r   r9   rJ   r
   rR   rz   r"   dumpsloadsr1   r   r   <module>r      s~   
     &$"" &"0* 0*|4$0L^D 	



r   