o
    à›hî&  ã                   @   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 )ÚJsonEncoderz§Customizable 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__© úIc:\Users\shubh\Videos\agent\nova\Lib\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 )zÍReturns 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 )z±Returns 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 )zèReturns 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"
