o
    i%                     @   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value	get_state	__class__ N/var/www/edux/Edux_v2/venv/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	   	classinfoone_infor   r   r   
_converter`   s   r1   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   r1   r.   	TypeErrorjoin)r	   converted_valuer/   r2   r   r   validateu   s   
zof_type.<locals>.validatelenpop)r/   kwargsr;   r   r:   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   typer7   r   r   r	   r   r   r   r;      s
   zdefault.<locals>.validater   )r   r;   r   rC   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.
    r2   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   listrB   r2   valuesr   r   r;      s
   zenum.<locals>.validater<   )rF   r?   r;   r   rE   r   enum   s
   	rG   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   rI      rJ   c                 S   s   h | ]}t |qS r   operatorindexr4   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} elementsr3   c                 s   s    | ]}t |V  qd S r   )strrO   r   r   r   r6      s    z*array.<locals>.<lambda>.<locals>.<genexpr>)r=   r   r8   sortedrB   sizer   r   rI      s         c                 s   s    | ]}t |V  qd S r   rL   rO   r   r   r   r6      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   rB   )max_lenmin_lenr   r   rI      s
   

c                    s   t |  kp
d S )NrR   rY   rB   rU   r   r   rI      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   rD   dictr@   r.   	enumerater7   rA   r   )r	   size_erriitemexc)validate_itemvalidate_size	vectorizer   r   r;      s    zarray.<locals>.validate)r   rA   tupler@   setr=   rM   rN   )rd   rf   rV   r;   r   )rZ   r[   rV   rd   re   rf   r   array   s$   



 
ri   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   r\   r]   )r@   r^   itemsr7   r.   rA   r   )r	   kvrc   validate_valuer   r   r;     s   zobject.<locals>.validate)r   rA   rg   r@   )rn   r;   r   rm   r   object   s   ro   c                 C   r   r   )r   rB   r   r   r   r     r!   r   )FFN)F)r   r   jsonr,   rM   JSONDecoderJsonDecoderJSONEncoderr   ro   r   r1   r@   r   rG   ri   r   dumpsloadsr   r   r   r   <module>   s"   >


O"
