
    e
-                         d Z ddlZddlZ G d de          Z G d de          Zd Z G d d	          Z G d
 de          ZdS )zW
Classes used to support string serialization of Parameters and
Parameterized objects.
    Nc                       e Zd ZdS )UnserializableExceptionN__name__
__module____qualname__     0lib/python3.11/site-packages/param/serializer.pyr   r   	           Dr
   r   c                       e Zd ZdS )UnsafeserializableExceptionNr   r	   r
   r   r   r      r   r
   r   c                     d| ddigiS )zSExpress a JSON schema type as nullable to easily support Parameters that allow_NoneanyOftypenullr	   )	json_types    r   JSONNullabler      s    y66"2355r
   c                       e Zd ZdZedd            Zedd            Zedd            Zed             Zed             Z	dS )	SerializationzH
    Base class used to implement different types of serialization.
    Nc                     t           NNotImplementedErrorclspobjsubsets      r   schemazSerialization.schema   s    !!r
   c                     t           )z
        Serialize the parameters on a Parameterized object into a
        single serialized object, e.g. a JSON string.
        r   r   s      r   serialize_parametersz"Serialization.serialize_parameters   
     "!r
   c                     t           )z
        Deserialize a serialized object representing one or
        more Parameters into a dictionary of parameter values.
        r   )r   r   
serializedr   s       r   deserialize_parametersz$Serialization.deserialize_parameters&   r"   r
   c                     t           )z5
        Serialize a single parameter value.
        r   )r   r   pnames      r   serialize_parameter_valuez'Serialization.serialize_parameter_value.   
    
 "!r
   c                     t           )z7
        Deserialize a single parameter value.
        r   r   r   r'   values       r   deserialize_parameter_valuez)Serialization.deserialize_parameter_value5   r)   r
   r   )
r   r   r   __doc__classmethodr   r!   r%   r(   r-   r	   r
   r   r   r      s          " " " [" " " " [" " " " [" " " [" " " [" " "r
   r   c            	          e Zd ZdZdgZededed ed          diZ	e
d             Ze
d	             Ze
d$d            Ze
d%d            Ze
d%d            Ze
d             Ze
d$d            Ze
d             Ze
d             Ze
d&d            Ze
d&d            Ze
d&d            Ze
d&d            Ze
d&d            Ze
d&d            Ze
d&d            Ze
d&d            Ze
d             Ze
d&d            Ze
d&d            Ze
d&d            Ze
d&d            Z e
d&d            Z!e
d&d             Z"e
d&d!            Z#e
d&d"            Z$e
d&d#            Z%dS )'JSONSerializationz
    Class responsible for specifying JSON serialization, deserialization
    and JSON schemas for Parameters and Parameterized classes and
    objects.
    CallableintegernumberstringNr   c                 *    t          j        |          S r   )jsonloads)r   r$   s     r   r8   zJSONSerialization.loadsK   s    z*%%%r
   c                 *    t          j        |          S r   )r7   dumps)r   objs     r   r:   zJSONSerialization.dumpsO   s    z#r
   Fc                 z   i }|j                             d                                          D ]\  }}|||vr|                    |          ||<   |j        rHt          j        |j                                      dd                                          ||         d<   |j	        r|j	        ||         d<   |S )Nexistingsafe
 descriptiontitle)
paramobjectsitemsr   doctextwrapdedentreplacestriplabel)r   r   r?   r   r   nameps          r   r   zJSONSerialization.schemaS   s    z))*55;;== 	0 	0GD!!d&&8&8888..F4Lu `.6oae.D.D.L.LTSV.W.W.].]._._t]+w 0()tW%r
   c                    i }|j                             d                                          D ]>\  }}|||vr|j                             |          }|                    |          ||<   ?|                     |          S )Nr=   )rD   rE   rF   get_value_generator	serializer:   )r   r   r   
componentsrM   rN   r,   s          r   r!   z&JSONSerialization.serialize_parameters`   s    
z))*55;;== 	2 	2GD!!d&&8&8J22488E {{511Jtyy$$$r
   c                     |                      |          }i }|                                D ]1\  }}|||vr|j        |                             |          }|||<   2|S r   )r8   rF   rD   deserialize)r   r   serializationr   deserializedrR   rM   r,   s           r   r%   z(JSONSerialization.deserialize_parametersj   sw    yy//
'--// 	, 	,KD%!d&&8&8:d+77>>L+Jtr
   c                 X    |                                 dz   |z   }t          | |d          S )z7Returns specialized method if available, otherwise None_N)lowergetattr)r   ptypesuffixmethod_names       r   _get_methodzJSONSerialization._get_methodw   s-     kkmmC'&0sK...r
   c                     || j         v rt          |                     |d          }|r |||          }nd|                                i}|j        rt          |          n|S )Nr   r>   r   )unserializable_parameter_typesr   r^   rY   
allow_Noner   )r   r[   rN   r?   r   dispatch_methodr   s          r   param_schemazJSONSerialization.param_schema}   ss    C666))//%:: 	-$_QT222FFekkmm,F'(|?|F###?r
   c                     |j                             |          }|                     |j         |                             |                    S r   )rD   rP   r:   rQ   r+   s       r   r(   z+JSONSerialization.serialize_parameter_value   s>    
..u55yyE*44U;;<<<r
   c                 l    |                      |          }|j        |                             |          S r   )r8   rD   rT   r+   s       r   r-   z-JSONSerialization.deserialize_parameter_value   s.    		%  z% ,,U333r
   c                      ddl m} t          |t                    rd fd|D             iS | j        v rd j        |         iS t          ||          rd|j                            |          dS ddiS )N   )Parameterizedr   c                 :    g | ]}                     |          S r	   )class__schema).0cls_r   s     r   
<listcomp>z3JSONSerialization.class__schema.<locals>.<listcomp>   s'    III$c//55IIIr
   r   objectr   
properties)parameterizedrh   
isinstancetuplejson_schema_literal_types
issubclassrD   r   )r   class_r?   rh   s   `   r   rj   zJSONSerialization.class__schema   s    000000fe$$ 	&IIII&IIIJJs444C9&ABB.. 	&$FL4G4G4M4MNNNH%%r
   c                 4    |du rd}t          |          ddiS )NTzLArray is not guaranteed to be safe for serialization as the dtype is unknownr   arrayr   r   rN   r?   msgs       r   array_schemazJSONSerialization.array_schema   s+    4<<;C-c222  r
   c                 :    |                      |j        |          S Nr>   )rj   rv   r   rN   r?   s      r   classselector_schemaz&JSONSerialization.classselector_schema   s       555r
   c                 4    |du rd}t          |          ddiS )NTzZDict is not guaranteed to be safe for serialization as the key and value types are unknownr   rn   ry   rz   s       r   dict_schemazJSONSerialization.dict_schema   s,    4<<JC-c222!!r
   c                     dddS )Nr5   z	date-timer   formatr	   r   s      r   date_schemazJSONSerialization.date_schema   s     K888r
   c                     dddS )Nr5   dater   r	   r   s      r   calendardate_schemaz%JSONSerialization.calendardate_schema   s     F333r
   c                 D    ddi}|j         |j         |d<   |j         |d<   |S )Nr   rx   minItemsmaxItems)lengthr   rN   r?   r   s       r   tuple_schemazJSONSerialization.tuple_schema   s1    '"8"#(F:"#(F:r
   c                     d|j         j                                        i}|                     ||j        |j                  S )Nr   )	__class__r   rY   declare_numeric_boundsboundsinclusive_boundsr   s       r   number_schemazJSONSerialization.number_schema   s:    !+.44668))&!(A<NOOOr
   c                 `    |+|\  }}||d         rdnd}|||<   ||d         rdnd}|||<   |S )zCGiven an applicable numeric schema, augment with bounds informationNr   minimumexclusiveMinimumrg   maximumexclusiveMaximumr	   )r   r   r   r   lowhighkeys          r   r   z(JSONSerialization.declare_numeric_bounds   s]      KS$#3A#6Nii<N!s#3A#6Nii<N"sr
   c                 ,    |                      |          S r   )r   r   s      r   integer_schemaz JSONSerialization.integer_schema   s      ###r
   c                 B    |                      ||          }ddi|d<   |S Nr>   r   r4   additionalItems)r   r   s       r   numerictuple_schemaz%JSONSerialization.numerictuple_schema   s/    !!!$!//%+X$6 !r
   c                 0    |                      ||          S r~   )r   r   s      r   xycoordinates_schemaz&JSONSerialization.xycoordinates_schema   s    &&qt&444r
   c                     |                      ||          }|                     ddi|j        |j                  }||d<   |S r   )r   r   r   r   )r   rN   r?   r   bounded_numbers        r   range_schemazJSONSerialization.range_schema   sP    !!!$!//33X!*<> >$2 !r
   c                     ddi}|du r|j         d}t          |          |j        |                     |j         |          |d<   |S )Nr   rx   TzPList without a class specified cannot be guaranteed to be safe for serializationr>   rF   )	item_typer   rv   rj   )r   rN   r?   r   r{   s        r   list_schemazJSONSerialization.list_schema   s\    '"4<<AK/2C-c2228!//$/GGF7Or
   c                      	  fd|j         D             }d|i}|j         |d<   |S #  |du rd}t          |          i cY S xY w)Nc                 H    g | ]}d j         t          |                   iS r   rt   r   rk   r;   r   s     r   rm   z;JSONSerialization.objectselector_schema.<locals>.<listcomp>   s<     3 3 3!$ %c&CDII&NO 3 3 3r
   r   enumTzfObjectSelector cannot be guaranteed to be safe for serialization due to unserializable type in objects)rE   r   r   rN   r?   allowed_typesr   r{   s   `     r   objectselector_schemaz'JSONSerialization.objectselector_schema   s}    	3 3 3 3()	3 3 3M}-FYF6NM	t||M1#666IIIs	   "& Ac                      	  fd|j                                         D             }d|i}|j         |d<   |S #  |du rd}t          |          i cY S xY w)Nc                 H    g | ]}d j         t          |                   iS r   r   r   s     r   rm   z5JSONSerialization.selector_schema.<locals>.<listcomp>	  s<     < < <!$ %c&CDII&NO < < <r
   r   r   Tz`Selector cannot be guaranteed to be safe for serialization due to unserializable type in objects)rE   valuesr   r   s   `     r   selector_schemaz!JSONSerialization.selector_schema  s    	< < < <()	(8(8(:(:< < <M}-FYF6NM	t||M1#666IIIs	   48 Ac                     |j         
|du rd}ddiS |j         D ]9}t          |          | j        vr!dt          |          z  }t          |          :dd|j         idS )NTz]ListSelector cannot be guaranteed to be safe for serialization as allowed objects unspecifiedr   rx   z%ListSelector cannot serialize type %sr   )r   rF   )rE   r   rt   r   )r   rN   r?   r{   r;   s        r   listselector_schemaz%JSONSerialization.listselector_schema  s    9t||FG$$9 	3 	3CCyy ====S		I-c222 >  619*=>>>r
   c                 $   ddi}|du rd}t          |          |j        	ddi|d<   |S d\  }}t          |j        t                    r|j        |j        }}n$t          |j        t                    r
|j        \  }}t          |j        t                    st          |j        t                    r	d||d|d<   t          |j        t
                    st          |j        t                    rBd	 | j                                        D             }d
|ifd|j        D             }d|d|d<   d\  }	}
t          |j	        t                    r|j	        |j	        }
}	n$t          |j	        t                    r
|j	        \  }	}
|	|	|d<   |
|
|d<   |S )Nr   rx   TzYDataFrame is not guaranteed to be safe for serialization as the column dtypes are unknownrn   rF   )NN)r   r   r   c                     g | ]}d |iS r   r	   )rk   els     r   rm   z6JSONSerialization.dataframe_schema.<locals>.<listcomp>8  s    ZZZRfR[ZZZr
   r   c                     i | ]}|S r	   r	   )rk   rM   allowable_typess     r   
<dictcomp>z6JSONSerialization.dataframe_schema.<locals>.<dictcomp>:  s    FFFD$FFFr
   ro   r   r   )
r   columnsrr   intrs   listsetrt   r   rows)r   rN   r?   r   r{   mincolsmaxcolsliteral_typesrp   minrowsmaxrowsr   s              @r   dataframe_schemaz"JSONSerialization.dataframe_schema"  s   '"4<<DC-c2229%x0F7OM%ai%% 	) y!)WGG	5)) 	) yGWai%% 	5AIu)E)E 	5(0g,3 5  5F7O ai&& 	L*QY*D*D 	LZZ33P3W3W3Y3YZZZM&6OFFFFAIFFFJ(0
KKF7O%afc"" 	& vqvWGG&& 	& vGW!(F:!(F:r
   )FNr   )F)&r   r   r   r.   r`   r   floatstrr   rt   r/   r8   r:   r   r!   r%   r^   rc   r(   r-   rj   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	   r
   r   r1   r1   =   s         '1\" 	IuXs8T

F!
 & & [&   [ 
 
 
 [
 % % % [%    [ / / [/
 @ @ @ [@ = = [= 4 4 [4 	& 	& 	& [	& ! ! ! [! 6 6 6 [6 " " " [" 9 9 9 [9 4 4 4 [4    [ P P P [P 
 
 [
 $ $ $ [$    [
 5 5 5 [5    [    [    [    [ 
? 
? 
? [
? % % % [% % %r
   r1   )	r.   r7   rH   	Exceptionr   r   r   r   r1   r	   r
   r   <module>r      s    
  	 	 	 	 	i 	 	 		 	 	 	 	) 	 	 	6 6 6%" %" %" %" %" %" %" %"PK K K K K K K K K Kr
   