o
    [Zh%                     @   s   d Z ddlZddlZddlZddlZejZG dd dejZG dd de	Z
dd Zd	d
 Zdd Zdd ZdddZdddZ	dd ZejZejZdS )zImproved JSON serialization.
    Nc                       s    e Zd ZdZ fddZ  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                    s.   z|j }W | S  ty   Y nw t |S N)__getstate__AttributeErrorsuperdefault)selfvalueZ	get_state	__class__ J/var/www/html/lang_env/lib/python3.10/site-packages/debugpy/common/json.pyr      s   zJsonEncoder.default)__name__
__module____qualname____doc__r   __classcell__r   r   r
   r   r      s    r   c                   @   sJ   e Zd ZdZeZ	 eddZ	 dd Zdd Zdd	 Z	d
d Z
dd ZdS )
JsonObjectzzA wrapped Python object that formats itself as JSON when asked for a string
    representation via str() or format().
       )indentc                 C   s   t |trJ || _d S r   )
isinstancer   r	   )r   r	   r   r   r   __init__-   s   
zJsonObject.__init__c                 C   s   t r   )NotImplementedErrorr   r   r   r   r   1   s   zJsonObject.__getstate__c                 C   s   t | jS r   )builtinsreprr	   r   r   r   r   __repr__4   s   zJsonObject.__repr__c                 C      t | S r   )formatr   r   r   r   __str__7      zJsonObject.__str__c                 C   s4   |rd| d }t |d| ji}n| 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encoderr   r   r   
__format__:   s   

zJsonObject.__format__N)r   r   r   r   r   r"   r$   r   r   r   r   r)   r   r   r   r   r   "   s    
r   c              	   C   s<   |D ]}t |tjrz|| W   S  ty   Y qw qdS )zGConvert value (str) to number, otherwise return None if is not possibleN)
issubclassnumbersNumber
ValueError)r	   	classinfoZone_infor   r   r   
_converter`   s   r/   c                     s6   t  sJ |ddt |rJ  fd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                    s\   r| dkst |  r| S t|  }|r|S s | dkr tdtdddd  D  )Nr   zmust be specifiedzmust be  or c                 s   s    | ]}|j V  qd S r   )r   ).0tr   r   r   	<genexpr>   s    z,of_type.<locals>.validate.<locals>.<genexpr>)r   r/   r-   	TypeErrorjoin)r	   Zconverted_valuer.   r0   r   r   validateu   s   
zof_type.<locals>.validatelenpop)r.   kwargsr8   r   r7   r   of_typej   s
   r=   c                    s    fd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                    s2   | dkr S t | t r| S tdt j)Nr   zmust be {0})r   typer5   r   r   r	   r   r   r   r8      s
   zdefault.<locals>.validater   )r   r8   r   r@   r   r      s   r   c                     s6   t sJ |dd t |rJ  fd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.
    r0   Fc                    s2    r
| dkr
d S | v r| S t dt)Nr   r   zmust be one of: {0!r})r-   r   listr?   r0   valuesr   r   r8      s
   zenum.<locals>.validater9   )rC   r<   r8   r   rB   r   enum   s
   	rD   Fc                    s   sdd nt tst trtdu rdd nNt tr1dd D fddn;t tradt  krCd	ksFJ  J td
d D d dd	 \  fddntfddfdd}|S )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   s   | S r   r   )xr   r   r   <lambda>       zarray.<locals>.<lambda>Nc                 S   s   dS )NTr   )_r   r   r   rF      rG   c                 S   s   h | ]}t |qS r   operatorindexr2   nr   r   r   	<setcomp>   s    zarray.<locals>.<setcomp>c                    s*   t |  v pdddd t D S )Nmust have {0} elementsr1   c                 s   s    | ]}t |V  qd S r   )strrL   r   r   r   r4      s    z*array.<locals>.<lambda>.<locals>.<genexpr>)r:   r   r6   sortedr?   sizer   r   rF      s         c                 s   s    | ]}t |V  qd S r   rI   rL   r   r   r   r4      s    zarray.<locals>.<genexpr>r   r   c                    s8   t | k rdS  d urt |  k rd S dS )Nzmust have at least {0} elementszmust have at most {0} elementsTr:   r   r?   )max_lenmin_lenr   r   rF      s
   

c                    s   t |  kp
d S )NrO   rV   r?   rR   r   r   rF      s   c                    s   | dkrg } nrt | ttfs| g} tt|  | }|dur%t|t| D ](\}}z || |< W q) ttfyQ } zt|dt| d| d }~ww | S )Nr   T[] )	r   rA   dictr=   r-   	enumerater5   r>   r   )r	   Zsize_erriitemexc)validate_itemvalidate_size	vectorizer   r   r8      s    zarray.<locals>.validate)r   r>   tupler=   setr:   rJ   rK   )r`   rb   rS   r8   r   )rW   rX   rS   r`   ra   rb   r   array   s$   



 
re   c                    s,   t  ts
t  trt   fd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                    sz   | dkri S t t|   r;|  D ](\}}z || |< W q ttfy: } zt|dt| d| d }~ww | S )Nr   rY   rZ   )r=   r[   itemsr5   r-   r>   r   )r	   kvr_   validate_valuer   r   r8     s   zobject.<locals>.validate)r   r>   rc   r=   )rj   r8   r   ri   r   object   s   rk   c                 C   r   r   )r   r?   r   r   r   r     r    r   )FFN)F)r   r   jsonr+   rJ   JSONDecoderZJsonDecoderJSONEncoderr   rk   r   r/   r=   r   rD   re   r   dumpsloadsr   r   r   r   <module>   s"   >


O"
