U
    /e%                     @   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                    s2   z
|j }W n tk
r   Y nX | S t |S N)__getstate__AttributeErrorsuperdefault)selfvalueZ	get_state	__class__ 7/tmp/pip-unpacked-wheel-dg3irmqq/debugpy/common/json.pyr      s    
zJsonEncoder.default)__name__
__module____qualname____doc__r   __classcell__r   r   r
   r   r      s   r   c                   @   sF   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t|| _d S r   )
isinstancer   AssertionErrorr	   )r   r	   r   r   r   __init__-   s    zJsonObject.__init__c                 C   s   t d S 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   s   t | S r   )formatr   r   r   r   __str__7   s    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 ]4}t |tjrz|| W   S  tk
r6   Y qX 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t|ddt |r$t 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  d S )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-   r/   r   r   validateu   s    
zof_type.<locals>.validatelenr   pop)r-   kwargsr7   r   r6   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                    s6   | dkr S t | t r| S tdt jd S )Nr   zmust be {0})r   typer4   r   r   r	   r   r   r   r7      s
    zdefault.<locals>.validater   )r   r7   r   r?   r   r      s    r   c                     s6   t st|dd t |r$t 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.
    r/   Fc                    s6    r| dkrd S | kr | S t dtd S )Nr   r   zmust be one of: {0!r})r,   r   listr>   r/   valuesr   r   r7      s
    zenum.<locals>.validater8   )rB   r;   r7   r   rA   r   enum   s
    	rC   Fc                    s   sdd nt ts"t tr*tdkr<dd nt trbdd D fddntt trdt  krd	ksn t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   rE      rF   c                 S   s   h | ]}t |qS r   operatorindexr1   nr   r   r   	<setcomp>   s     zarray.<locals>.<setcomp>c                    s*   t |  kp(dddd t D S )Nmust have {0} elementsr0   c                 s   s   | ]}t |V  qd S r   )strrK   r   r   r   r3      s     z*array.<locals>.<lambda>.<locals>.<genexpr>)r9   r   r5   sortedr>   sizer   r   rE      s          c                 s   s   | ]}t |V  qd S r   rH   rK   r   r   r   r3      s     zarray.<locals>.<genexpr>r   r   c                    s8   t | k rdS  d k	r4t |  k r4d S dS )Nzmust have at least {0} elementszmust have at most {0} elementsTr9   r   r>   )max_lenmin_lenr   r   rE      s    

c                    s   t |  kpd S )NrN   rU   r>   rQ   r   r   rE      s    c                    s   | dkrg } nr&t | ttfs&| g} tt|  | }|dk	rJt|t| D ]\\}}z || |< W qR ttfk
r } z t|dt| d| W 5 d }~X Y qRX qR| S )Nr   T[] )	r   r@   dictr<   r,   	enumerater4   r=   r   )r	   Zsize_erriitemexc)validate_itemvalidate_size	vectorizer   r   r7      s    0zarray.<locals>.validate)	r   r=   tupler<   setr9   r   rI   rJ   )r_   ra   rR   r7   r   )rV   rW   rR   r_   r`   ra   r   array   s$    




rd   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                    s   | dkri S t t|   r|  D ]\\}}z || |< W q$ ttfk
r~ } z t|dt| d| W 5 d }~X Y q$X q$| S )Nr   rX   rY   )r<   rZ   itemsr4   r,   r=   r   )r	   kvr^   validate_valuer   r   r7     s    0zobject.<locals>.validate)r   r=   rb   r<   )ri   r7   r   rh   r   object   s    rj   c                 C   s   t | S r   )r   r>   r   r   r   r     s    r   )FFN)F)r   r   jsonr*   rI   JSONDecoderZJsonDecoderJSONEncoderr   rj   r   r.   r<   r   rC   rd   r   dumpsloadsr   r   r   r   <module>   s    >

O
"