Format: application/x-python-code
⬇ Download File (9.2 KB)
   1  o
   2  
   3  ��h�&�@s�dZddlZddlZddlZddlZejZGdd�dej�ZGdd�de	�Z
   4  dd�Zd	d
   5  �Zdd�Z
   6  d
   7  d�Zddd�Zddd�Z	dd�ZejZejZdS)zImproved JSON serialization.
   8  �Ncs eZdZdZ�fdd�Z�ZS)�JsonEncoderz�Customizable JSON encoder.
   9  
  10      If the object implements __getstate__, then that method is invoked, and its
  11      result is serialized instead of the object itself.
  12      cs.z|j}W|�StyYnwt��|�S�N)�__getstate__�AttributeError�super�default)�self�valueZ	get_state��	__class__��Ic:\Users\shubh\Videos\agent\nova\Lib\site-packages\debugpy/common/json.pyrs��zJsonEncoder.default)�__name__�
  13  __module__�__qualname__�__doc__r�
  14  __classcell__rrr
  15  r
  16  rsrc@sJeZdZdZeZ	edd�Z	dd�Zdd�Zdd	�Z	d
  17  d�Z
  18  dd
  19  �ZdS)�
  20  JsonObjectzzA wrapped Python object that formats itself as JSON when asked for a string
  21      representation via str() or format().
  22      �)�indentcCst|t�rJ�||_dSr)�
  23  isinstancerr	)rr	rrr
  24  �__init__-s
  25  zJsonObject.__init__cCst�r)�NotImplementedError�rrrr
  26  r1szJsonObject.__getstate__cCst�|j�Sr)�builtins�reprr	rrrr
  27  �__repr__4szJsonObject.__repr__cC�t|�Sr)�formatrrrr
  28  �__str__7�zJsonObject.__str__cCs4|rd|d}t|d|ji�}n|j}|�|j�S)a�If format_spec is empty, uses self.json_encoder to serialize self.value
  29          as a string. Otherwise, format_spec is treated as an argument list to be
  30          passed to self.json_encoder_factory - which defaults to JSONEncoder - and
  31          then the resulting formatter is used to serialize self.value as a string.
  32  
  33          Example::
  34  
  35              format("{0} {0:indent=4,sort_keys=True}", json.repr(x))
  36          zjson_encoder_factory(�)�json_encoder_factory)�evalr"�json_encoder�encoder	)r�format_spec�make_encoder�encoderrrr
  37  �
  38  __format__:s
  39  
  40  �zJsonObject.__format__N)rrrrrr"r$rrrrr)rrrr
  41  r"s
  42  rc	Cs<|D]}t|tj�rz||�WStyYqwqdS)zGConvert value (str) to number, otherwise return None if is not possibleN)�
  43  issubclass�numbers�Number�
  44  ValueError)r	�	classinfoZone_inforrr
  45  �
  46  _converter`s���r/cs6t��sJ�|�dd��t|�rJ���fdd�}|S)z�Returns a validator for a JSON property that requires it to have a value of
  47      the specified type. If optional=True, () is also allowed.
  48  
  49      The meaning of classinfo is the same as for isinstance().
  50      �optionalFcs\�r|dkst|��r
  51  |St|��}|r|S�s |dkr td��tdd�dd��D����)Nrzmust be specifiedzmust be � or css�|]}|jVqdSr)r)�.0�trrr
  52  �	<genexpr>s�z,of_type.<locals>.validate.<locals>.<genexpr>)rr/r-�	TypeError�join)r	Zconverted_value�r.r0rr
  53  �validateus
  54  zof_type.<locals>.validate��len�pop)r.�kwargsr8rr7r
  55  �of_typejs
  56  r=cs�fdd�}|S)z�Returns a validator for a JSON property with a default value.
  57  
  58      The validator will only allow property values that have the same type as the
  59      specified default value.
  60      cs2|dkr�St|t���r|Std�t��j���)Nrzmust be {0})r�typer5rr�r	�rrr
  61  r8�s
  62  zdefault.<locals>.validater)rr8rr@r
  63  r�srcs6t��sJ�|�dd��t|�rJ���fdd�}|S)z�Returns a validator for a JSON enum.
  64  
  65      The validator will only allow the property to have one of the specified values.
  66  
  67      If optional=True, and the property is missing, the first value specified is used
  68      as the default.
  69      r0Fcs2�r
  70  |dkr
  71  �dS|�vr|Std�t�����)Nrrzmust be one of: {0!r})r-r�listr?�r0�valuesrr
  72  r8�s
  73  zenum.<locals>.validater9)rCr<r8rrBr
  74  �enum�s
  75  	rDFcs��sdd��nt�t�st�t�rt����durdd��nNt�t�r1dd��D���fdd��n;t�t�radt��krCd	ksFJ�J�td
  76  d��D����dd
  77  d	�\����fdd��nt�����fdd�����fdd�}|S)a�Returns a validator for a JSON array.
  78  
  79      If the property is missing, it is treated as if it were []. Otherwise, it must
  80      be a list.
  81  
  82      If validate_item=False, it's treated as if it were (lambda x: x) - i.e. any item
  83      is considered valid, and is unchanged. If validate_item is a type or a tuple,
  84      it's treated as if it were json.of_type(validate).
  85  
  86      Every item in the list is replaced with validate_item(item) in-place, propagating
  87      any exceptions raised by the latter. If validate_item is a type or a tuple, it is
  88      treated as if it were json.of_type(validate_item).
  89  
  90      If vectorize=True, and the value is neither a list nor a dict, it is treated as
  91      if it were a single-element list containing that single value - e.g. "foo" is
  92      then the same as ["foo"]; but {} is an error, and not [{}].
  93  
  94      If size is not None, it can be an int, a tuple of one int, a tuple of two ints,
  95      or a set. If it's an int, the array must have exactly that many elements. If it's
  96      a tuple of one int, it's the minimum length. If it's a tuple of two ints, they
  97      are the minimum and the maximum lengths. If it's a set, it's the set of sizes that
  98      are valid - e.g. for {2, 4}, the array can be either 2 or 4 elements long.
  99      cSs|Srr)�xrrr
 100  �<lambda>��zarray.<locals>.<lambda>NcSsdS)NTr)�_rrr
 101  rF�rGcSsh|]}t�|��qSr��operator�index�r2�nrrr
 102  �	<setcomp>�szarray.<locals>.<setcomp>cs*t|��vpd�d�dd�t��D���S)N�must have {0} elementsr1css�|]}t|�VqdSr)�strrLrrr
 103  r4�s�z*array.<locals>.<lambda>.<locals>.<genexpr>)r:rr6�sortedr?��sizerr
 104  rF�s���css�|]}t�|�VqdSrrIrLrrr
 105  r4�s�zarray.<locals>.<genexpr>rrcs8t|��krd���S�durt|��krd���SdS)Nzmust have at least {0} elementszmust have at most {0} elementsT�r:rr?)�max_len�min_lenrr
 106  rF�s
 107  
 108  �
 109  �cst|��kp
 110  d���S)NrOrVr?rRrr
 111  rF�scs�|dkrg}n�rt|ttf�s|g}tt�|��|�}|dur%t|��t|�D](\}}z�|�||<Wq)ttfyQ}zt|�dt|��d|����d}~ww|S)NrT�[�] )	rrA�dictr=r-�	enumerater5r>r)r	Zsize_err�i�item�exc)�
 112  validate_item�
 113  validate_size�	vectorizerr
 114  r8�s ��zarray.<locals>.validate)rr>�tupler=�setr:rJrK)r`rbrSr8r)rWrXrSr`rarbr
 115  �array�s$
 116  
 117  
 118  
 119   
 120  recs,t�t�s
 121  t�t�rt����fdd�}|S)avReturns a validator for a JSON object.
 122  
 123      If the property is missing, it is treated as if it were {}. Otherwise, it must
 124      be a dict.
 125  
 126      If validate_value=False, it's treated as if it were (lambda x: x) - i.e. any
 127      value is considered valid, and is unchanged. If validate_value is a type or a
 128      tuple, it's treated as if it were json.of_type(validate_value).
 129  
 130      Every value in the dict is replaced with validate_value(value) in-place, propagating
 131      any exceptions raised by the latter. If validate_value is a type or a tuple, it is
 132      treated as if it were json.of_type(validate_value). Keys are not affected.
 133      csz|dkriStt�|��r;|��D](\}}z�|�||<Wqttfy:}zt|�dt|��d|����d}~ww|S)NrrYrZ)r=r[�itemsr5r-r>r)r	�k�vr_��validate_valuerr
 134  r8s��zobject.<locals>.validate)rr>rcr=)rjr8rrir
 135  �object�s
 136  rkcCrr)rr?rrr
 137  rr r)FFN)F)rr�jsonr+rJ�JSONDecoderZJsonDecoder�JSONEncoderrrkrr/r=rrDrer�dumps�loadsrrrr
 138  �<module>s">
 139  
 140  
 141  O"
 142