
    .dg                       d Z ddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlmZ ddlmZmZmZ ddlmZmZmZ ddlmZ ddlmZ ddl	mZmZ dd	lmZmZ dd
lm Z  ddlm!Z!m"Z"m#Z#m$Z$m%Z% ddl&m'Z' ddl(m)Z)m*Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8  e/       r	 ddl9m:Z:m;Z<  e:d      Z=nddl(m<Z< dZ=e8d        Z?e8d        Z@e"dz
  ZA ej                  eAd       dZCddZDdZEdZFdZGdaHdaIg ZJd ZKd ZLd ZMddZNddZOd ZP G d d      ZQ eQ       ZRe d         ZSe dd!       ZT e-d"e+#      e dd$              ZUe d%        ZVe d&        ZWe d'        ZXe d(        ZYd) ZZd* Z[d+ Z\ e-e+,      d-        Z] e-e+,      d.        Z^ G d/ d0      Z_d1 Z`d2 Zadd3Zbd4 Zcd5 Zdd6 Zedd7Zfe5d8        Zgd9 Zhdd:Zidd;Zjd< Zkd= Zld>dddd?d@Zmd>dddd?dAZnddBZodC Zp edDdE      Zq epeqdF        edGdH      Zr eperdI        edJdK      Zs epesdL        edMdN      Zt epetdO        edPdQ      Zu G dR dPeu      Zv G dS dTew      Zx G dU dVex      Zy G dW dXey      Zz G dY dZez      Z{ G d[ d\      Z|d] Z} G d^ d_      Z~ G d` da      Z G db dc      Z G dd deew      ZdZddfg dddgdfdhZddfg diddjfdkZi Zdl Ze8dm        Zdn Zdo Zeee<   eee<   eee<   dZddpZddqZdr Z G ds dt      Z G du dv      Z G dw dxe      Zdy Z G dz d{e      Zd| Z G d} d~e      Z G d de      ZeZ G d d      Zy# e>$ r
 ddl(m<Z< Y w xY w)aT  
Generic support for objects with full-featured Parameters and
messaging.

This file comes from the Param library (https://github.com/holoviz/param)
but can be taken out of the param module and used on its own if desired,
either alone (providing basic Parameter support) or with param's
__init__.py (providing specialized Parameter types).
    N)getfullargspec)defaultdict
namedtupleOrderedDict)partialwrapsreduce)escape)chain)
itemgetter
attrgetter)FunctionType
MethodType)contextmanager)DEBUGINFOWARNINGERRORCRITICAL   )
serializer)DEFAULT_SIGNATUREParamFutureWarningSkip_deprecated_deprecate_positional_args_in_ipython_is_auto_name_is_mutable_container_recursive_repr_to_async_gen_validate_error_prefixaccept_argumentsiscoroutinefunctiondescendents	gen_types)
ParamPageripython_async_executorT)	metaclass)async_executorc               #      K   t         j                   t         j                   t        j                  j                  d      x} r| j                   y y wNnumpy)dtdatetimedatesysmodulesget
datetime64nps    3lib/python3.12/site-packages/param/parameterized.py	_dt_typesr8   F   s@     
++
''M[[__W%%r%mm &s   AAc               #   |   K   t          t        j                  j                  d      x} r| j                   y y wr,   )intr1   r2   r3   integerr5   s    r7   
_int_typesr<   M   s2     
I[[__W%%r%jj &s   :<VERBOSEc                    t         t        j                  d      }|j                  sr|j	                  t        j
                         t        j                  d      }t        j                         }|j                  |       |j                  |       nt         }| |S t        j                  |j                  dz   | z         S )Nparamz#%(levelname)s:%(name)s: %(message)s)fmt.)loggerlogging	getLoggerhandlerssetLevelr   	FormatterStreamHandlersetFormatter
addHandlername)rK   root_logger	formatterhandlers       r7   
get_loggerrO   [   s    ~''0##  .))9;I++-G  +""7+|  !1!1C!7$!>??    Fc                 ,    t         j                  |       S )z
    Appends a transform to extract potential parameter dependencies
    from an object.

    Arguments:
    ---------
    transform: Callable[Any, Any]

    )_reference_transformsappend)	transforms    r7   register_reference_transformrU   z   s     !''	22rP   c                 j    t         D ])  }t        | t              st        | d      r | S  ||       } + | S )a*  
    Applies transforms to turn objects which should be treated like
    a parameter reference into a valid reference that can be resolved
    by Param. This is useful for adding handling for depending on objects
    that are not simple Parameters or functions with dependency
    definitions.
    _dinfo)rR   
isinstance	Parameterhasattr)argrT   s     r7   transform_referencer\      s;     +	c9%h)?J n + JrP   c           	      P   di }}t        | d      r| j                  d   }| j                  j                  di       }|st        d |D              rJd |D        }|j	                         D ci c]&  \  }}|t        |j                  |j                        ( }}} | |i |S c c}}w )z
    Evaluates a function after resolving its dependencies.

    Calls and returns a function after resolving any dependencies
    stored on the _dinfo attribute and passing the resolved values
    as arguments.
     rW   dependencieskwc              3   <   K   | ]  }t        |t                y wN)rX   rY   ).0ds     r7   	<genexpr>z*eval_function_with_deps.<locals>.<genexpr>   s     EHq*Q	2H   c              3   \   K   | ]$  }t        |j                  |j                         & y wrb   )getattrownerrK   )rc   deps     r7   re   z*eval_function_with_deps.<locals>.<genexpr>   s      EHSGCIIsxx0Hs   *,)rZ   rW   r3   anyitemsrh   ri   rK   )functionargskwargsarg_depskw_depsnrj   s          r7   eval_function_with_depsrs      s     r&Dx"??>2//%%dB/cEHEEEHEDDKMMOTO&!SaCHH55OFTT$V$$ Us   ,+B"c                    |snt        | t        t        f      r t        |       d | D              S t        | t              r& t        |       d | j                         D              S t        | t              rFt        t        | j                        t        | j                        t        | j                              S t        |       } t        j                  |       }t        | d      st        |       s|rt!        |       } |rt#        |       } | S t        | t$              r t'        | j(                  | j*                        } | S )z2Resolves the current value of a dynamic reference.c              3   2   K   | ]  }t        |        y wrb   resolve_value)rc   vs     r7   re   z resolve_value.<locals>.<genexpr>   s     ;U=+Us   c              3   N   K   | ]  \  }}t        |      t        |      f  y wrb   rv   )rc   krx   s      r7   re   z resolve_value.<locals>.<genexpr>   s$     ZMDAqM!,mA.>?Ms   #%rW   )rX   listtupletypedictrl   slicerw   startstopstepr\   inspectisgeneratorfunctionrZ   r$   rs   r!   rY   rh   ri   rK   )value	recursiveis_gens      r7   rw   rw      s   	ED%=	)tE{;U;;;	E4	 tE{ZEKKMZZZ	E5	!%++&%**%%**%
 	

  &E((/Fuh#6u#='.!%(E L 
E9	%UZZ0LrP   c           
      8   |rt        | t        t        t        f      r#| D cg c]  }t	        ||      D ]  }|  c}}S t        | t
              r:| j                         D cg c]  }|D ]  }t	        ||      D ]  }|   c}}}S t        | t              rD| j                  | j                  | j                  fD cg c]  }t	        ||      D ]  }|  c}}S t        |       } t        | d      rt        | di       }t        |j                  dg             }t        |j                  di       j                               }g }	||z   D ]  }
t        |
t               rut#        |       }|
|j$                  v r|j$                  |
   }
nLd|
v r<|
j'                  d      }|}
|dd D ]  }t        |
|      }
 |
j$                  |d      }
nt        ||
      }
|	j)                  t	        |
              |	S t        | t*              r| gS g S c c}}w c c}}}w c c}}w )z7Resolves all parameters a dynamic reference depends on.rW   r_   r`   rA   N)rX   r{   r|   setresolve_refr~   rl   r   r   r   r   r\   rZ   rh   r3   valuesstrget_method_ownerr?   splitextendrY   )	referencer   rx   rkvodinforn   ro   refsr[   ri   pathattrs                 r7   r   r      s   i$s!34(Ly!+a2KQA2KAyLL	4( ) 1a 1"2a{STV_G`!AG`A2A 1aa	5) )PtP!ZefgirZsUVAZsAPtt#I.Iy(#	8R0EIInb12eiib)00236MC#s#(3%++%++c*CCZ99S>DC $Sb	%c40 !*))DH-C!%-CKKC() " 	Iy	){I9 Mats   H	%!HHc                     |S )z&To be removed when set_hook is removedr^   )objvals     r7   _identity_hookr      s    JrP   c                       e Zd ZdZd Zd Zy)
_Undefinedz_
    Dummy value to signal completely undefined values rather than
    simple None values.
    c                     t        d      )NzUse `is` to compare Undefined)RuntimeErrorselfs    r7   __bool__z_Undefined.__bool__   s     :;;rP   c                      y)Nz<Undefined>r^   r   s    r7   __repr__z_Undefined.__repr__   s    rP   N)__name__
__module____qualname____doc__r   r   r^   rP   r7   r   r      s    
<rP   r   c              #   p  K   | j                         } t        t        t        t        t
        t        g}g d}| |vrt        d| d|      t               }|j                         }|j                  ||j                  |                 	 d |j                  |       y# |j                  |       w xY ww)z)Temporarily modify param's logging level.)r   r   r   r   r   r=   zLevel z not in N)upperr   r   r   r   r   r=   	ExceptionrO   getEffectiveLevelrF   index)levellevelslevel_namesparam_loggerlogging_levels        r7   r   r      s      KKMET7E8W=FNKK&	&<==<L 224M&!2!25!9:;-
m,m,s   BB6
B  B6 B33B6c              #   b  K   | j                   j                  }|xs | j                   j                  | j                   _        	 d || j                   _        |r|s| j                   j                          yyy# || j                   _        |r|s| j                   j                          w w w xY ww)a  
    Internal version of batch_call_watchers, adding control over queueing and running.
    Only actually batches events if enable=True; otherwise a no-op. Only actually
    calls the accumulated watchers on exit if run=True; otherwise they remain queued.
    Nr?   _BATCH_WATCH_batch_call_watchers)parameterizedenablerunBATCH_WATCHs       r7   r   r   
  s       %%22K'-'Q1D1D1Q1QM$7+6({446 #3 ,7({446 #3s   A B/A9 2B/93B,,B/z"Use instead `batch_call_watchers`.	extra_msgwarning_catc              #   X   K   t        | ||      5  d  d d d        y # 1 sw Y   y xY wwrb   )r   )r   r   r   s      r7   batch_watchr     s"      
mVS	9 
:	9	9s   *	*'*c              #   &  K   | j                   j                  }d| j                   _        	 d || j                   _        |s| j                   j                          yy# || j                   _        |s| j                   j                          w w xY ww)a&  
    Context manager to batch events to provide to Watchers on a
    parameterized object.  This context manager queues any events
    triggered by setting a parameter on the supplied parameterized
    object, saving them up to dispatch them all at once when the
    context manager exits.
    TNr   )r   r   s     r7   batch_call_watchersr   #  s       %%22K'+M$7+6(446  ,7(446 s   (BA /B0BBc              #      K   | j                   j                  }t        |      t        |      z  | j                   _        	 d  || j                   _        y # || j                   _        w xY wwrb   )_param__privatesyncingr   )r   
parametersolds      r7   _syncingr   6  sV     

'
'
/
/C,/Hs:,FM!!)403%%-%%-s   =A, A A,A))A,c              #   6  K   | j                   j                  d      j                         }|D cg c]  }|j                   }}|D ]	  }d|_         	 d t	        ||      D ]  \  }}||_         yc c}w # t	        ||      D ]  \  }}||_         w xY ww)zi
    Temporarily set parameters on Parameterized object to constant=False
    to allow editing them.
    existingFN)r?   objectsr   constantzip)r   paramsp	constantsconsts        r7   edit_constantr   @  s        ((4;;=F%+,VVI,
 fi0JQAJ 1 - fi0JQAJ 1s(   .BA4BA9 !B9BBc              #     K   | j                   j                  }d| j                   _        t        | j                   j                        t        | j                   j                        }}	 d || j                   _        || j                   _        || j                   _        y# || j                   _        || j                   _        || j                   _        w xY ww)zw
    Context manager that discards any events within its scope
    triggered on the supplied parameterized object.
    TN)r?   r   r{   _state_watchers_events)r   r   watcherseventss       r7   discard_eventsr   Q  s       %%22K'+M$]00@@A]00889 H-+6(.6+&,# ,7(.6+&,#s   A&C)B! -4C!5CCc                 8    t        j                  |       ddd   S )z
    Return a list of the class hierarchy above (and including) the given class.

    Same as `inspect.getmro(class_)[::-1]`
    Nr   )r   getmroclass_s    r7   	classlistr   c  s     >>&!$B$''rP   c                     g }t        |       dd D cg c]  }| }}|D ]  }t        |d      s||j                  z  }  |S c c}w )z]
    Return a list of slot names for slots defined in `class_` and its
    superclasses.
    r   N	__slots__)r   rZ   r   )r   	all_slotscparent_param_classess       r7   get_all_slotsr   l  s[     I'0'8'=>'=!A'=>!1[!q{{"I " 	 ?s   	Ac                 h    t        t        |             D cg c]  }t        | |      r| c}S c c}w )z
    Return a list of slots for which values have been set.

    (While a slot might be defined, if a value for that slot hasn't
    been set, then it's an AttributeError to request the slot's
    value.)
    )r   r}   rZ   )instanceslots     r7   get_occupied_slotsr   |  s<     +4>: ':Tx% : ' ' 's   /)r   c                     t        d | |fD              r| |k(  S 	 t        d t        | |      D              S # t        $ r | |k(  cY S w xY w)a3  
    Return a single boolean for arg1==arg2, even for numpy arrays
    using element-wise comparison.

    Uses all(arg1==arg2) for sequences, and arg1==arg2 otherwise.

    If both objects have an '_infinitely_iterable' attribute, they are
    not be zipped together and are compared directly instead.
    c              3   4   K   | ]  }t        |d         yw)_infinitely_iterableNrZ   )rc   els     r7   re   zall_equal.<locals>.<genexpr>  s     
E272-.   c              3   ,   K   | ]  \  }}||k(    y wrb   r^   )rc   a1a2s      r7   re   zall_equal.<locals>.<genexpr>  s     :/B28/s   )allr   	TypeError)arg1arg2s     r7   	all_equalr     sU     
E$t
EETz:#dD/::: Tzs   7 AAc                       fd}|S )z[
    Class decorator for creating a class with a metaclass.

    .. deprecated:: 2.0.0
    c                    | j                   j                         }|j                  dd        |j                  dd        |j                  dd      D ]  }|j                  |         | j                  | j
                  |      S )N__dict____weakref__r   r^   )r   copypopr3   r   	__bases__)cls	orig_vars	slots_varr)   s      r7   wrapperzadd_metaclass.<locals>.wrapper  si    LL%%'	j$'mT*"{B7IMM)$ 8s}}i@@rP   r^   )r)   r   s   ` r7   add_metaclassr    s    A NrP   c                       e Zd ZdZd Zd Zy)
bothmethodz
    'optional @classmethod'

    A decorator that allows a method to receive either the class
    object (if called on the class) or the instance object
    (if called on the instance) as its first argument.
    c                     || _         y rb   method)r   r  s     r7   __init__zbothmethod.__init__  s	    rP   c                 t    || j                   j                  |      S | j                   j                  ||      S rb   )r  __get__)r   r   ri   s      r7   r	  zbothmethod.__get__  s6    ;;&&u-- ;;&&x77rP   N)r   r   r   r   r  r	  r^   rP   r7   r  r    s    8rP   r  c                 L    fd}t        || g|j                  d      z         S )Nc                     t        | |g S rb   )rh   )r   r   rn   s     r7   _getattrz_getattrr.<locals>._getattr  s    sD(4((rP   rA   )r	   r   )r   r   rn   r  s     ` r7   	_getattrrr    s$    )(SEDJJsO344rP   c                 (    d| j                   _        | S )z)Disables instance parameters on the classT)r   disable_instance_paramsr   s    r7   no_instance_paramsr    s    26C/JrP   c                     t        j                   |       }||_        i |_        |j                  j                  D ]@  }t        ||      }t        |      s|dk7  s!t        ||t        j                   |             B |S )zWReturn a Parameter object suitable for instantiation given the class's Parameter objectdefault)r   ri   r   	__class___all_slots_rh   r   setattr)paramobjri   r   srx   s        r7   _instantiate_param_objr    sl     			(AAG AJ [[$$AqM #YAq$))A,' % HrP   c                 L   t        | j                  dd      r|j                  rt        t        |       j                  dd      s`|j                  }|| j                  j
                  vr#t        ||       | j                  j
                  |<   | j                  j
                  |   }|S )z
    Given a Parameterized object and one of its class Parameter objects,
    return the appropriate Parameter object for this instance, instantiating
    it if need be.
    initializedFr  )rh   r   per_instancer}   rK   r   r  )r   r?   keys      r7   _instantiated_parameterr    s     	--}eDI[I[D'779RTYZjjm33:::8NuVc8dM))005--44S9LrP   c                       fd}|S )Nc                     |V|j                   j                  j                  | j                        }|t	        ||       }|| |ur|j                  ||       y  | ||      S rb   )r   r   r3   rK   r  __set__)r   r   r   instance_paramfs       r7   _fzinstance_descriptor.<locals>._f  si    ? 0077;;DIIFN%!8d!C)d..H&&sC0sC  rP   r^   )r#  r$  s   ` r7   instance_descriptorr%    s    	! IrP   c                 ~    t        j                  |       syt        | t              r| j                  } | j
                  S )z/Gets the instance that owns the supplied methodN)r   ismethodrX   r   func__self__r  s    r7   r   r   	  s0    F#&'"??rP   c                 R    t        j                  dt        d       t        |       S )zm
    Decorator to make a repr function return fillvalue for a recursive call

    .. deprecated:: 1.12.0
    zKrecursive_repr has been deprecated and will be removed in a future version.   category
stacklevel	fillvalue)warningswarn_ParamFutureWarningr    r/  s    r7   recursive_reprr4    s&     MMU$
 Y//rP   c           
      \    |rg }t        |      D ]  \  }}t        |      dkD  r|nd}t        |t              r7t        |      dk(  r)t        |d   t              r|j                  ||fz          _t        |t              r|j                  |t               |f       |j                  d||f        nT|rDt        |j                               D cg c]  \  }\  }}||t        |      dkD  r|ndf }}}}ndt               dfg}g g }	}|D ]  \  }}}t        |t              r(t        |t              r |       }nAddl
m}
  |
|      }n1t        |t              r!t        d |D              rddl
m}
  |
|      }t        |t              st        d      |	j                  |||f       |j                  |        t        t        |            t        |      k7  rt        d	      t         d
i       }|j!                  d|	i       t#                fd       }||_        |S c c}}}w )a  
    output allows annotating a method on a Parameterized class to
    declare that it returns an output of a specific type. The outputs
    of a Parameterized class can be queried using the
    Parameterized.param.outputs method. By default the output will
    inherit the method name but a custom name can be declared by
    expressing the Parameter type using a keyword argument.

    The simplest declaration simply declares the method returns an
    object without any type guarantees, e.g.:

      @output()

    If a specific parameter type is specified this is a declaration
    that the method will return a value of that type, e.g.:

      @output(param.Number())

    To override the default name of the output the type may be declared
    as a keyword argument, e.g.:

      @output(custom_name=param.Number())

    Multiple outputs may be declared using keywords mapping from output name
    to the type or using tuples of the same format, i.e. these two declarations
    are equivalent:

      @output(number=param.Number(), string=param.String())

      @output(('number', param.Number()), ('string', param.String()))

    output also accepts Python object types which will be upgraded to
    a ClassSelector, e.g.:

      @output(int)
    r   Nr+  r   )ClassSelectorr   c              3   <   K   | ]  }t        |t                y wrb   )rX   r}   )rc   ts     r7   re   zoutput.<locals>.<genexpr>`  s     -Q5ajD.A5rf   zVoutput type must be declared with a Parameter class, instance or a Python object type.z:When declaring multiple outputs each value must be unique.rW   outputsc                       | i |S rb   r^   )rn   r`   r(  s     r7   _outputzoutput.<locals>._outputp  s    TBrP   )	enumeratelenrX   r|   r   rS   rY   rl   r}   
issubclass r6  r   
ValueErrorr   rh   updater   rW   )r(  outputr`   r9  ioutrK   otypenames	processedr6  rW   r;  s   `            r7   rB  rB  !  s   L 'FAs[1_$A#u%#c(a-Js1vs<SsA4x(C%Y[!45c1~. ( 
 ,5RXXZ+@B+@'q-4 %c"gkt<+@ 	 B )+t,-29E!eQeT"%+*%U3u%#-Q5-Q*Q&!/E%+ A B B$q)*T "  3u:#e*$ + , 	, T8R(F
MM9i()
4[    GNNGBs   "H'c                 N   | j                  d      dk  sJ | j                         } t        j                  d|       }|j	                  d      }d|j	                  d      z   }t        j                  d|      }|j	                  d      }|j	                  d	      }|xs d
||xs dfS )z
    Parses param.depends specifications into three components:

    1. The dotted path to the sub-object
    2. The attribute being depended on, i.e. either a parameter or method
    3. The parameter attribute being depended on
    :r   z(?P<path>[^:]*):?(?P<what>.*)whatrA   r   z(?P<obj>.*)(\.)(?P<attr>.*)r   r   Nr   )countstriprematchgroup)specmrJ  r   r   r   s         r7   _parse_dependency_specrR  y  s     ::c?A::<D
0$7A776?DqwwvD
/6A
''%.C776?D;$dog--rP   c                    g g }}t        | j                  di       }|j                  dt        | j                  j
                              D ]  }| j                  | j                  n| j                  j
                  j                  |||      \  }}||z  }|D ]>  }	t        |	t              r|j                  |	       %t        |	||      \  }
}||
z  }||z  }@  ||fS )ac  
    Resolves dependencies declared on a Parameterized method.
    Dynamic dependencies, i.e. dependencies on sub-objects which may
    or may not yet be available, are only resolved if dynamic=True.
    By default intermediate dependencies, i.e. dependencies on the
    path to a sub-object are returned. For example for a dependency
    on 'a.b.c' dependencies on 'a' and 'b' are returned as long as
    intermediate=True.

    Returns lists of concrete dependencies on available parameters
    and dynamic dependencies specifications which have to resolved
    if the referenced sub-objects are defined.
    rW   r_   )rh   r  r3   r{   r   r?   inst_spec_to_objrX   PInforS   _params_depended_on)minfodynamicintermediatedepsdynamic_depsr   rd   ddepsddynamic_depsrj   method_depsmethod_dynamic_depss               r7   rW  rW    s     R,DELL(B/EYY~tEIIOO'<=-2ZZ-?		UZZVVccdegnp|}}%C#u%C 3FsGUa3b00# 33  > rP   c                 4   g }|D ]  }t        t        |       |j                        s|j                  |       4|j                  | n|j                  }t        ||j                  |j                  |j                  |j                     |j                        }|j                  |        |D ]h  }| j                  j                  |j                  |      \  }}|D ]7  }	t        |	t
              r|j                  |	       %|t        |	|      d   z  }9 j |S )a	  
    Resolves constant and dynamic parameter dependencies previously
    obtained using the _params_depended_on function. Existing resolved
    dependencies are updated with a supplied parameter instance while
    dynamic dependencies are resolved if possible.
    rT  r   rK   pobjrJ  rZ  r   )r>  r}   r   rS   rT  rV  rK   r?   rJ  rU  rP  rX   rW  )
r   resolvedrY  rZ  r_   rj   rT  subresolved_subdeps
             r7   _resolve_mcs_depsri    s     L$s)SWW-$hh&sCHH377CHH-CHH>C   //|/TQ!F&%(##F+ 3F VWX YY	 "  rP   c                  &   |j                  dd      }|j                  d      }|y| D ]  }|D ]  }|dk(  rS|j                  t        nt        |j                  |d      }|j                  t        nt        |j                  |d      }nl|j                  t        n#t        |j                  j
                  |   |d      }|j                  t        n#t        |j                  j
                  |   |d      }t        j                  ||      r  y  y)z
    Checks whether a subobject event should be skipped.
    Returns True if all the values on the new subobject
    match the values on the previous subobject.
    rJ  r   changedNFT)r3   r   	Undefinedr  newr?   
Comparatoris_equal)r   ro   rJ  rk  er   r   rm  s           r7   _skip_eventrq    s     ::fg&Djj#GAw#$55=iiq$6O#$55=iiq$6O#$55=iiAPTVZ6[#$55=iiAPTVZ6[&&sC0   rP   c                 ,   t        | j                  d         t        | j                  d   j                               z   }g }|D ]  }t        |t              rt        |       }|j                  d      ^ }}|D ]  }t        ||d      }|t        d       ||j                  v r&|j                  |   }||vsu|j                  |       t        t        ||            D ]  }||vs|j                  |        ||vs|j                  |        |S )zJExtract references from a method or function that declares the references.r_   r`   rA   Nz/Cannot depend on undefined sub-parameter {p!r}.)r{   rW   r   rX   r   r   r   rh   r@  r?   rS   extract_dependencies)	rm   subparametersr   r   ri   subpssubprc  sps	            r7   rs  rs    s   89$xt?T?[?[?]:^^MFa$X.EIUAtT2=$%VWW  EKK{{1~v%MM$'.wua/@AB'b) B f_MM!# $ MrP   r   rJ  rk  callbackrm   c                 b   K   |r ||  t         rt        || |ds |        d {    y y 7 wN)rJ  rk  rq  rJ  rk  ry  rm   r   s        r7   _async_callerr~    s3     &k6gNj Os   $/-/c                 8    |r ||  t        || |ds |       S y r{  r|  r}  s        r7   _sync_callerr    s&    &T7;z <rP   c                 z    t        | |      }t        |      rt        nt        }t	        |||||      }||_        |S )z
    Wraps a method call adding support for scheduling a callback
    before it is executed and skipping events if a subobject has
    changed but its values have not.
    rx  )rh   r$   r~  r  r   _watcher_name)r   method_namerJ  rk  ry  rm   _callercallers           r7   	_m_callerr    s>     t[)H28<m,GW48V^_F&FMrP   c                     || _         y)zAdd a docstring to a namedtupleN)r   )r   	docstrings     r7   _add_docr    s	    CKrP   rV  zinst cls name pobj whatan  
    Object describing something being watched about a Parameter.

    `inst`: Parameterized instance owning the Parameter, or None

    `cls`: Parameterized class owning the Parameter

    `name`: Name of the Parameter being watched

    `pobj`: Parameter object being watched

    `what`: What is being watched on the Parameter (either 'value' or a slot name)
    MInfozinst cls name methoda  
    Object describing a Parameterized method being watched.

    `inst`: Parameterized instance owning the method, or None

    `cls`: Parameterized class owning the method

    `name`: Name of the method being watched

    `method`: bound method of the object being watched
    DInforP  za
    Object describing dynamic dependencies.
    `spec`: Dependency specification to resolve
    Eventzwhat name obj cls old new typea{  
    Object representing an event that triggers a Watcher.

    `what`: What is being watched on the Parameter (either value or a slot name)

    `name`: Name of the Parameter that was set or triggered

    `obj`: Parameterized instance owning the watched Parameter, or None

    `cls`: Parameterized class owning the watched Parameter

    `old`: Previous value of the item being watched

    `new`: New value of the item being watched

    `type`: `triggered` if this event was triggered explicitly), `changed` if
    the item was set and watching for `onlychanged`, `set` if the item was set,
    or  None if type not yet known
    WatcherzCinst cls fn mode onlychanged parameter_names what queued precedencec                   (     e Zd ZdZ fdZd Z xZS )r  af  
    Object declaring a callback function to invoke when an Event is
    triggered on a watched item.

    `inst`: Parameterized instance owning the watched Parameter, or
    None

    `cls`: Parameterized class owning the watched Parameter

    `fn`: Callback function to invoke when triggered by a watched
    Parameter

    `mode`: 'args' for param.watch (call `fn` with PInfo object
    positional args), or 'kwargs' for param.watch_values (call `fn`
    with <param_name>:<new_value> keywords)

    `onlychanged`: If True, only trigger for actual changes, not
    setting to the current value

    `parameter_names`: List of Parameters to watch, by name

    `what`: What to watch on the Parameters (either 'value' or a slot
    name)

    `queued`: Immediately invoke callbacks triggered during processing
            of an Event (if False), or queue them up for processing
            later, after this event has been handled (if True)

    `precedence`: A numeric value which determines the precedence of
                  the watcher.  Lower precedence values are executed
                  with higher priority.
    c                     t        t        | j                  |            }|j                  |       d|vrd|d<   t	        |   | fi |S )z:Allows creating Watcher without explicit precedence value.
precedencer   )r~   r   _fieldsrA  super__new__)cls_rn   ro   r   r  s       r7   r  zWatcher.__new__s  sJ    c$,,-.fv%#$F< wt.v..rP   c                     t        |       }dj                  |j                  D cg c]  }| dt        | |       c}      }|j                   d| dS c c}w )N, =())r}   joinr  rh   r   )r   r   r#  attrss       r7   __str__zWatcher.__str__{  s\    4j		L1aS'$"2!56LM,,qq)) Ms   A)r   r   r   r   r  r  __classcell__r  s   @r7   r  r  Q  s    B/*rP   c                       e Zd ZdZd Zd Zy)ParameterMetaclassz>Metaclass allowing control over creation of Parameter classes.c           
         d|v r|d   |d<   t        t        d            |d<   i }t        t        d |D               D ]1  }|j	                  t
        j                  t        |dg                    3 d|vrg |d<   n'|j	                  t
        j                  |d                t        |      |d<   t        j                  | |||      S )Nr   
__classdocdocc              3   @   K   | ]  }|j                   d d d     y w)Nr   )__mro__)rc   bases     r7   re   z-ParameterMetaclass.__new__.<locals>.<genexpr>  s     EutTrT 2us   r   r  )propertyr   r   r   rA  r~   fromkeysrh   r{   r}   r  )mcs	classnamebases	classdictr   bclss         r7   r  zParameterMetaclass.__new__  s     	!$-i$8Il#  (
5(9:	) 	EuEFGDT]]74b+IJK H i'%'Ik"T]]9[+ABC#'	?	-  ||CE9==rP   c                 d    |dk(  rt         j                  | d      S t         j                  | |      S )Nr   r  )r}   __getattribute__)r  rK   s     r7   r  z#ParameterMetaclass.__getattribute__  s1    ? ((\::((T22rP   N)r   r   r   r   r  r  r^   rP   r7   r  r    s    H>:3rP   r  c                   L     e Zd ZdZed        Ze fd       Zed        Z xZS )_ParameterBasezb
    Base Parameter class used to dynamically update the signature of all
    the Parameters.
    c                 b    | j                   j                         }|j                  d      |d<   |S )N_labellabel)_slot_defaultsr   r   )r   defaultss     r7   _modified_slots_defaultsz'_ParameterBase._modified_slots_defaults  s.    %%**,$LL2rP   c                     t         |           	 | j                          y # t        $ r' t	        j
                  | j                        | _        Y y w xY wrb   )r  __init_subclass___update_signaturer   r   	signaturer  __signature__)r   r  s    r7   r  z _ParameterBase.__init_subclass__  sJ    !#	@!!# 	@ !( 1 1#,, ?C	@s   " -AAc           	         | j                         }i }t        | j                               D ]  \  }}|j                  j	                  d      r#t        j                  |j                        }|j                  j                         D ]+  \  }}|dk(  r|dk\  r(|j                  t
        j                  j                  k(  r:|j                  t
        j                  j                  t
        j                  j                   fv r{t#        |dd       t$        u r[||vrt'        d|d| j                  d      ||   }t)        |      rt+        |d      r|j,                  }|j/                  |	      }	n|}	|dk\  r*|	j/                  t
        j                  j0                  
      }	|j3                  ||	       .  d }
t5        |j7                         |
      }j/                  |      }|| _        y )Nrg  r   r   r  z	Argument z of Parameter z  has no entry in _slot_defaults.sig)r  )kindc                 T    | j                   t        j                  j                  k(  ryy)Nr   r   )r  r   	Signatureempty)r   s    r7   _sorterz1_ParameterBase._update_signature.<locals>._sorter  s     yyG--333rP   r  )r   )r  r<  mror   
startswithr   r  r  r   rl   r  r  r  r  rY   VAR_KEYWORDVAR_POSITIONALrh   rl  LookupErrorcallablerZ   r  replaceKEYWORD_ONLY
setdefaultsortedr   r  )r   r  new_parametersrC  klsr  pname	parameterr  new_parameterr  new_sigs               r7   r  z _ParameterBase._update_signature  s   //1	*FAs||&&s+##CLL1C$'NN$8$8$: yF?6i//73D3D3J3JJ>>g&7&7&C&CWEVEVEeEe%ff9i6)CH,)'ys||>N O7 7  'uoG(WWe-D")++$-$5$5g$5$FM$-M6$1$9$9w?P?P?]?]$9$^M))%?+ %;	 +6	   5 5 7WE+++8#rP   )	r   r   r   r   classmethodr  r  r  r  r  s   @r7   r  r    sF    
  
 
@ 
@ '$ '$rP   r  c                       e Zd ZdZg dZdej                  iZ edddddddddddd      Z	g dZ
ej                  	 d"dddddddddddd	d
       Zeefeeeeeeeeeeed	d       Zed        Zed        Zd#dZed        Zed        Zej.                  d        Zd Zd Z fdZd Zd Zd Zd Zd Ze d        Z!d Z"d Z#d Z$d Z%d Z&d  Z'd! Z( xZ)S )$rY   aQ  
    An attribute descriptor for declaring parameters.

    Parameters are a special kind of class attribute.  Setting a
    Parameterized class attribute to be a Parameter instance causes
    that attribute of the class (and the class's instances) to be
    treated as a Parameter.  This allows special behavior, including
    dynamically generated parameter values, documentation strings,
    constant and read-only parameters, and type or range checking at
    assignment time.

    For example, suppose someone wants to define two new kinds of
    objects Foo and Bar, such that Bar has a parameter delta, Foo is a
    subclass of Bar, and Foo has parameters alpha, sigma, and gamma
    (and delta inherited from Bar).  She would begin her class
    definitions with something like this::

       class Bar(Parameterized):
           delta = Parameter(default=0.6, doc='The difference between steps.')
           ...
       class Foo(Bar):
           alpha = Parameter(default=0.1, doc='The starting value.')
           sigma = Parameter(default=0.5, doc='The standard deviation.',
                           constant=True)
           gamma = Parameter(default=1.0, doc='The ending value.')
           ...

    Class Foo would then have four parameters, with delta defaulting
    to 0.6.

    Parameters have several advantages over plain attributes:

    1. Parameters can be set automatically when an instance is
       constructed: The default constructor for Foo (and Bar) will
       accept arbitrary keyword arguments, each of which can be used
       to specify the value of a Parameter of Foo (or any of Foo's
       superclasses).  E.g., if a script does this::

           myfoo = Foo(alpha=0.5)

       myfoo.alpha will return 0.5, without the Foo constructor
       needing special code to set alpha.

       If Foo implements its own constructor, keyword arguments will
       still be accepted if the constructor accepts a dictionary of
       keyword arguments (as in ``def __init__(self,**params):``), and
       then each class calls its superclass (as in
       ``super(Foo,self).__init__(**params)``) so that the
       Parameterized constructor will process the keywords.

    2. A Parameterized class need specify only the attributes of a
       Parameter whose values differ from those declared in
       superclasses; the other values will be inherited.  E.g. if Foo
       declares::

        delta = Parameter(default=0.2)

       the default value of 0.2 will override the 0.6 inherited from
       Bar, but the doc will be inherited from Bar.

    3. The Parameter descriptor class can be subclassed to provide
       more complex behavior, allowing special types of parameters
       that, for example, require their values to be numbers in
       certain ranges, generate their values dynamically from a random
       distribution, or read their values from a file or other
       external source.

    4. The attributes associated with Parameters provide enough
       information for automatically generating property sheets in
       graphical user interfaces, allowing Parameterized instances to
       be edited by users.

    Note that Parameters can only be used when set as class attributes
    of Parameterized classes. Parameters used as standalone objects,
    or as class attributes of non-Parameterized classes, will not have
    the behavior described here.
    )rK   r  r  r  instantiater   readonlypickle_default_value
allow_Noner  r   ri   
allow_refsnested_refsr  jsonNFT)r  r  r  r  r  r   r  r  r  r  r  r  )r  r  rK   r  r   r  r   ri   )r  r  r  r  r   r  r  r  r  r  r  c                     y rb   r^   r   r  r  r  r  r  r   r  r  r  r  r  r  s                r7   r  zParameter.__init__       	rP   c                   d| _         d| _        || _        || _        || _        || _        || _        |du xs |du | _        || _        || _	        | j                  |       || _        | j                  |	       i | _        |
| _        y)a  
        Initialize a new Parameter object and store the supplied attributes:

        default: the owning class's value for the attribute represented
        by this Parameter, which can be overridden in an instance.

        doc: docstring explaining what this parameter represents.

        label: optional text label to be used when this Parameter is
        shown in a listing. If no label is supplied, the attribute name
        for this parameter in the owning Parameterized object is used.

        precedence: a numeric value, usually in the range 0.0 to 1.0,
        which allows the order of Parameters in a class to be defined in
        a listing or e.g. in GUI menus. A negative precedence indicates
        a parameter that should be hidden in such listings.

        instantiate: controls whether the value of this Parameter will
        be deepcopied when a Parameterized object is instantiated (if
        True), or if the single default value will be shared by all
        Parameterized instances (if False). For an immutable Parameter
        value, it is best to leave instantiate at the default of
        False, so that a user can choose to change the value at the
        Parameterized instance level (affecting only that instance) or
        at the Parameterized class or superclass level (affecting all
        existing and future instances of that class or superclass). For
        a mutable Parameter value, the default of False is also appropriate
        if you want all instances to share the same value state, e.g. if
        they are each simply referring to a single global object like
        a singleton. If instead each Parameterized should have its own
        independently mutable value, instantiate should be set to
        True, but note that there is then no simple way to change the
        value of this Parameter at the class or superclass level,
        because each instance, once created, will then have an
        independently instantiated value.

        constant: if true, the Parameter value can be changed only at
        the class level or in a Parameterized constructor call. The
        value is otherwise constant on the Parameterized instance,
        once it has been constructed.

        readonly: if true, the Parameter value cannot ordinarily be
        changed by setting the attribute at the class or instance
        levels at all. The value can still be changed in code by
        temporarily overriding the value of this slot and then
        restoring it, which is useful for reporting values that the
        _user_ should never change but which do change during code
        execution.

        pickle_default_value: whether the default value should be
        pickled. Usually, you would want the default value to be pickled,
        but there are rare cases where that would not be the case (e.g.
        for file search paths that are specific to a certain system).

        per_instance: whether a separate Parameter instance will be
        created for every Parameterized instance. True by default.
        If False, all instances of a Parameterized class will share
        the same Parameter object, including all validation
        attributes (bounds, etc.). See also instantiate, which is
        conceptually similar but affects the Parameter value rather
        than the Parameter object.

        allow_None: if True, None is accepted as a valid value for
        this Parameter, in addition to any other values that are
        allowed. If the default value is defined as None, allow_None
        is set to True automatically.

        allow_refs: if True allows automatically linking parameter
        references to this Parameter, i.e. the parameter value will
        automatically reflect the current value of the reference that
        is passed in.

        nested_refs: if True and allow_refs=True then even nested objects
        such as dictionaries, lists, slices, tuples and sets will be
        inspected for references and will be automatically resolved.

        default, doc, and precedence all default to None, which allows
        inheritance of Parameter slots (attributes) from the owning-class'
        class hierarchy (see ParameterizedMetaclass).
        NT)rK   ri   r  r  r  r  r  r   r  r  _set_instantiater  _set_allow_Noner   r  r  s                r7   r  zParameter.__init__  s    l 	
$&$ D(<H,< k*$8!Z((rP   c                     |S )zKGiven the parameter value, return a Python value suitable for serializationr^   r   r   s     r7   	serializezParameter.serialize  	     rP   c                     |S )zRGiven a serializable Python value, return a value that the parameter can be set tor^   r  s     r7   deserializezParameter.deserialize  r  rP   c           	          || j                   vr2t        d|dt        | j                   j                                     | j                   |   j	                  | j
                  j                  | ||      S )NMode ( not in available serialization formats safesubset)_serializersKeyErrorr{   keysparam_schemar  r   )r   r  r  modes       r7   schemazParameter.schema	  sx    )))U4(*RSWX\XiXiXnXnXpSqRtuvv  &33DNN4K4KT9=f 4 N 	NrP   c                     ddl m}  ||       S )aw  
        The reactive namespace.

        Provides reactive versions of operations that cannot be made reactive through operator overloading, such as
        `.rx.and_` and `.rx.bool`. Calling this namespace (`()`) returns a reactive expression.

        Returns
        -------
        Reactive expression
            The result of calling the reactive namespace is a reactive expression.

        User Guide
        ----------
        https://param.holoviz.org/user_guide/Reactive_Expressions.html#special-methods-on-rx

        Examples
        --------
        Create a Parameterized instance:

        >>> import param
        >>> class P(param.Parameterized):
        ...     a = param.Number()
        >>> p = P(a=1)

        Get the current value:

        >>> a = p.param.a.rx.value

        Call it to get a reactive expression:

        >>> rx_value = p.param.a.rx()

        r   )reactive_ops)reactiver  )r   r  s     r7   rxzParameter.rx  s    F 	+D!!rP   c                 t    | j                   r!| j                  t        | j                         S | j                  S rb   )rK   r  label_formatterr   s    r7   r  zParameter.label5  s+    99,"499--;;rP   c                     || _         y rb   )r  r   r   s     r7   r  zParameter.label<  s	    rP   c                 t    | j                   d| _        y |t        ur|| _        y | j                  d   | _        y )NTr  )r  r  rl  r  )r   r  s     r7   r  zParameter._set_allow_None@  s6    
 <<"DOy((DO"11,?DOrP   c                 t    | j                   rd| _        y|t        ur|| _        y| j                  d   | _        y)z)Constant parameters must be instantiated.Fr  N)r  r  rl  r  )r   r  s     r7   r  zParameter._set_instantiateL  s8    
 ==$D	)*D  $22=ADrP   c                    |dk(  rt        | dd       }|||k7  rt        d      || j                  j                  v }|dk7  xr |t        | dg       v }|s|st        |   ||      S t        | |t              }|r	 | j                  |||       t        |   ||       |r|t        ur| j                  |||       y y y # t        $ r Y ;w xY w)NrK   zMParameter name cannot be modified after it has been bound to a Parameterized.r  r   )	rh   AttributeErrorr  r  r  __setattr__NotImplemented_on_set_trigger_event)r   	attributer   rK   is_slothas_watcherr   r  s          r7   r  zParameter.__setattr__Y  s    4.DETM$ &M N N t~~9999,[gdJXZ>[1[;7&y%88 dI~6YU3 	Iu-3n4	36 5;	 " s   <B? ?	C
Cc           	      N   t        || j                  d | j                  ||d       }| j                  |   D ](  }| j                  j                  j                  ||       * | j                  j                  j                  s%| j                  j                  j                          y y )NrJ  rK   r   r   r   rm  r}   )r  rK   ri   r   r?   _call_watcherr   r   )r   r  r   rm  eventwatchers         r7   r  zParameter._trigger_eventr  s~    9499$DJJ3T3}}Y/GJJ**7E: 0zz,,JJ113 -rP   c                    t         j                  | |      }|t        u r5|dk7  r0t        | dd      #	 | j                  |   }t        |      r ||       }|S # t
        $ r,}t        d|d| j                  j                  d      |d}~ww xY w)z
        Allow slot values to be Undefined in an "unbound" parameter, i.e. one
        that is not (yet) owned by a Parameterized object, in which case their
        value will be retrieved from the _slot_defaults dictionary.
        rK   NSlot z on unbound parameter 1 has no default value defined in `_slot_defaults`)	objectr  rl  rh   r  r  r  r   r  )r   r  rx   rp  s       r7   r  zParameter.__getattribute__z  s     ##D#.	>cVmfd0K0S'', {dG  C7"89P9P8S TG G s   A 	B'BBc                      y)zl
        Can be overridden on subclasses to handle changes when parameter
        attribute is set.
        Nr^   )r   r  r   r   s       r7   r  zParameter._on_set      rP   c                      y)z
        Can be overridden on subclasses to update a Parameter state, i.e. slot
        values, after the slot values have been set in the inheritance procedure.
        Nr^   r   s    r7   _update_statezParameter._update_state  r  rP   c                     || j                   }|S 	 |j                  j                  | j                     }|S # t        t
        f$ r | j                   }Y |S w xY w)ah  
        Return the value for this Parameter.

        If called for a Parameterized class, produce that
        class's value (i.e. this Parameter object's 'default'
        attribute).

        If called for a Parameterized instance, produce that
        instance's value, if one has been set - otherwise produce the
        class's value (default).
        )r  r   r   rK   r  r  )r   r   objtyperesults       r7   r	  zParameter.__get__  sc     ;\\F 	&,,33DII>  #H- &&s   #7 AAc           	         | j                   }|| j                  r|j                  j                  r||j                  j                  v }|j
                  j                  | |      \  }}}}|j                  j                  }|'| j                  j
                  j                  ||       nT||v rP|sN||= ||j                  j                  v r3|j                  j                  j                  |      j                          |s|t        u ryt        | d      r@| j                  ||      }| j                  t         urt#        j$                  dt&        d       | j)                  |       t*        }	| j,                  s| j.                  r| j.                  rt1        d|z        || j2                  }	|| _        ng|j                  j                  s^|j                  j4                  j7                  | j                   | j2                        }	||j                  j4                  | j                   <   n|j                  j4                  j7                  | j                   | j2                        }	||	urt1        d|z        || j2                  }	|| _        nt9        |j                  t:              s.t;        t=        |      j                  j>                        |_        |j                  j4                  j7                  || j2                        }	||j                  j4                  |<   | jA                  ||       |?t        |d	      rtC        |j                  d
d      sy|j
                  jE                  |       || jF                  j7                  d      }
n`||j                  jF                  v rF|j                  jF                  |   j7                  d      }
|
| jF                  j7                  d      }
nd}
|| j                  n|}||
sytI        d||| j                  |	|d      }tK        |
d       D ]  }|j
                  jM                  ||         |j
                  jN                  s|j
                  jQ                          yy)a8  
        Set the value for this Parameter.

        If called for a Parameterized class, set that class's
        value (i.e. set this Parameter object's 'default' attribute).

        If called for a Parameterized instance, set the value of
        this Parameter on that instance (i.e. in the instance's
        `values` dictionary located in the private namespace `_param__private`,
        under the parameter's name).

        If the Parameter's constant attribute is True, only allows
        the value to be set for a Parameterized class or on
        uninitialized Parameterized instances.

        If the Parameter's readonly attribute is True, only allows the
        value to be specified in the Parameter declaration inside the
        Parameterized source code. A read-only parameter also
        cannot be set on a Parameterized class.

        Note that until we support some form of read-only
        object, it is still possible to change the attributes of the
        object stored in a constant or read-only Parameter (e.g. one
        item in a list).
        Nset_hookz$Number.set_hook has been deprecated.   r,  z+Read-only parameter '%s' cannot be modifiedz*Constant parameter '%s' cannot be modifiedexplicit_no_refsr   r  Fr   r
  c                     | j                   S rb   r  ws    r7   <lambda>z#Parameter.__set__.<locals>.<lambda>  s    allrP   r  ))rK   r  r   r  r   r?   _resolve_refr   ri   _update_ref
async_refsr   cancelrl  rZ   r  r   r1  r2  r3  	_validater  r   r  r   r  r   r3   rX   _InstancePrivater}   r  _post_setterrh   _update_depsr   r  r  r  r   r   )r   r   r   rK   r   refr[  is_asyncr   _oldr   r  r  s                r7   r!  zParameter.__set__  s   6 yy?t33F3F3R3Rc11999G'*yy'='=dC'H$CsH&&++D

  ,,T37gJ3..999''2266t<CCE3)+ 4$--S)C}}N2:0  	s==DMM}} MPT TUU||"((44**1155diiN8;##**4995**1155diiNd?#$PSW$WXX{||" "#"5"57GH*:)-c)B)B)S)S+C' **1155dDLLI36##**40#s#?3 12'#BUBUWdfk:lII""4(;}}((1HS((111**33D9==gFH==,,W5HKdjjS;h73DJJCd4 h,BCGII##GU3 Dyy%%II**, &rP   c                      y)z)Implements validation for parameter valueNr^   )r   r   r  s      r7   _validate_valuezParameter._validate_value   r  rP   c                 <    | j                  || j                         y)z<Implements validation for the parameter value and attributesN)r/  r  r  s     r7   r'  zParameter._validate#  s    S$//2rP   c                      y)z;Called after the parameter value has been validated and setNr^   )r   r   r   s      r7   r)  zParameter._post_setter'  r  rP   c                 2    t        d| j                  z        )Nz4Cannot delete '%s': Parameters deletion not allowed.)r   rK   r   r   s     r7   
__delete__zParameter.__delete__*  s    NQUQZQZZ[[rP   c                     d | j                   | j                  fvr]|| j                  k7  rNt        dj                  t	        |       j
                  | j                  | j                   j                  |            || _        y )NzThe {} parameter {!r} has already been assigned a name by the {} class, could not assign new name {!r}. Parameters may not be shared by multiple classes; ensure that you create a new parameter instance for each new class.)ri   rK   r  formatr}   r   )r   attrib_names     r7   
_set_nameszParameter._set_names-  sr    

DII..;$))3K  "@
 AGtDzGZGZ\`\e\e$(JJOO[ABC C  	rP   c                 j    | j                   j                  D ci c]  }|t        | |       c}S c c}w )zu
        All Parameters have slots, not a dict, so we have to support
        pickle and deepcopy ourselves.
        )r  r  rh   r   r   s     r7   __getstate__zParameter.__getstate__8  s4    
 7;nn6P6PQ6PdgdD))6PQQQs   0c                 N    |j                         D ]  \  }}t        | ||        y rb   rl   r  r   staterz   rx   s       r7   __setstate__zParameter.__setstate__?  s"    KKMDAqD!Q "rP   rb   FNr  )*r   r   r   r   r   r   JSONSerializationr  r~   r  _non_validated_slotstypingoverloadr  r   rl  r  r  r  r  r  r  r  setterr  r  r  r  r  r  r  r	  r%  r!  r/  r'  r)  r4  r8  r;  r@  r  r  s   @r7   rY   rY     s   LFMI J889L4%TeeN1 __  55TeRVe   ( c) Y&Y&/I'I9	c)  c)J    N #" #"J   \\ 
@B724(. l- l-\83J\	 R rP   rY   c                        e Zd ZdZdgZ eej                  dd      Zej                  	 ddddddddddddddd	       Z
eefed
 fd       Z
d Zd Zd Z xZS )Stringa  
    A String Parameter, with a default value and optional regular expression (regex) matching.

    Example of using a regex to implement IPv4 address matching::

      class IPAddress(String):
        '''IPv4 address as a string (dotted decimal notation)'''
       def __init__(self, default="0.0.0.0", allow_None=False, **kwargs):
           ip_regex = r'^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$'
           super(IPAddress, self).__init__(default=default, regex=ip_regex, **kwargs)

    regexr?  N)r  rI  FT)rI  r  r  r  r  r   r  r  r  r  r  r  c                     y rb   r^   )r   r  rI  r  r  r  r  r   r  r  r  r  r  r  s                 r7   r  zString.__init__X  r  rP   )rI  c                l    t        |   dd|i| || _        | j                  | j                         y )Nr  r^   )r  r  rI  r'  r  )r   r  rI  ro   r  s       r7   r  zString.__init__b  s/    33F3
t||$rP   c                     || j                   ry |4t        j                  ||      t        t	        |        d|d|d      y y )Nz value z does not match regex rA   )r  rM  rN  r@  r"   )r   r   rI  s      r7   _validate_regexzString._validate_regexh  s]    KDOO%!5!=)$/0w ?$iq*  ">rP   c                 t    |r|y t        |t              s#t        t        |        dt	        |       d      y )Nz) only takes a string value, not value of rA   )rX   r   r@  r"   r}   )r   r   r  s      r7   r/  zString._validate_valueq  sH    #+#s#)$/0 1  $S	{!-  $rP   c                 t    | j                  || j                         | j                  || j                         y rb   )r/  r  rM  rI  r  s     r7   r'  zString._validatez  s*    S$//2S$**-rP   )r?  )r   r   r   r   r   r~   rY   r  rD  rE  r  r   rl  rM  r/  r'  r  r  s   @r7   rH  rH  F  s     	I)22BdKN__ !55TeRVe   ( %9 %  %
.rP   rH  c                   $    e Zd ZdZdZi Zd Zd Zy)shared_parametersa  
    Context manager to share parameter instances when creating
    multiple Parameterized objects of the same type. Parameter default
    values are instantiated once and cached to be reused when another
    Parameterized object of the same type is instantiated.
    Can be useful to easily modify large collections of Parameterized
    objects at once and can provide a significant speedup.
    Fc                     dt         _        y )NT)rQ  _sharer   s    r7   	__enter__zshared_parameters.__enter__  s    #' rP   c                 0    dt         _        i t         _        y NF)rQ  rS  _shared_cache)r   exc_typeexc_valexc_tbs       r7   __exit__zshared_parameters.__exit__  s    #( *,'rP   N)r   r   r   r   rS  rW  rT  r[  r^   rP   r7   rQ  rQ    s     FM(-rP   rQ  c                 .     t                fd       }|S )z
    Decorator: call fn with the parameterized_instance's
    initialization flag set to False, then revert the flag.

    (Used to decorate Parameterized methods that must alter
    a constant Parameter.)
    c                     | j                   }|j                  j                  }d|j                  _         | g|i |}||j                  _        |S rV  )r   r   r  )self_rn   r`   parameterized_instanceoriginal_initializedretfns         r7   override_initializationz1as_uninitialized.<locals>.override_initialization  sV    !&5EEQQ=B..:$$$=Q..:
rP   )r   )rb  rc  s   ` r7   as_uninitializedrd    s#     2Y  #"rP   c            
           e Zd ZdZej
                  ej                  eej                  e	ej                   e
d      ej                  d ej                  iZeej                  iZed        Zed        Zed        Zy)rn  a  
    Comparator defines methods for determining whether two objects
    should be considered equal. It works by registering custom
    comparison functions, which may either be registed by type or with
    a predicate function. If no matching comparison can be found for
    the two objects the comparison will return False.

    If registered by type the Comparator will check whether both
    objects are of that type and apply the comparison. If the equality
    function is instead registered with a function it will call the
    function with each object individually to check if the comparison
    applies. This is useful for defining comparisons for objects
    without explicitly importing them.

    To use the Comparator simply call the is_equal function.
    Nc                     t        | d      S )Nr   r   r   s    r7   r"  zComparator.<lambda>  s    '!34rP   c                 4   | j                   j                         }| j                  j                         D ]  \  }} |       D ]  }|||<   	  |j                         D ]Z  \  }}	 t	        ||      xr t	        ||      }	|	r |||      c S t	        |t              s? ||      sH ||      sQ |||      c S  t	        |t        t        t        f      r| j                  ||      S t	        |t              r| j                  ||      S y# t
        $ r Y w xY wrV  )
equalitiesr   gen_equalitiesrl   rX   r   r   r{   r   r|   compare_iteratorr~   compare_mapping)
r   obj1obj2equalsgenopr8  eq_typeeqare_instancess
             r7   ro  zComparator.is_equal  s   $$&))//1GCUq	  2 "<<>KGR* *4 9 Wjw>W !dD>)'<0WT]wt}$~% * dT3./''d33d#&&tT22  s   %D	DDc                     t        |      t        |      ust        |      t        |      k7  ryt        ||      D ]  \  }}| j                  ||      r y yNFT)r}   r=  r   ro  )r   rm  rn  o1o2s        r7   rk  zComparator.compare_iterator  sN    :T$Z'3t9D	+A$oFB<<B' & rP   c                     t        |      t        |      ust        |      t        |      k7  ry|D ]"  }||v r| j                  ||   ||         r  y y yrv  )r}   r=  ro  )r   rm  rn  rz   s       r7   rl  zComparator.compare_mapping  sU    :T$Z'3t9D	+A%ADy||DGT!W5   rP   )r   r   r   r   numbersNumberoperatorrs  r   bytesr}   ri  r8   rj  r  ro  rk  rl  r^   rP   r7   rn  rn    s    $ 	X[[x{{T
HKK4hkkJ 	8;;N  ,    rP   rn  c                   (    e Zd ZdZdddZd Zd Zy)_ParametersRestorerzHContext-manager to handle the reset of parameter values after an update.N)r   c                B    || _         || _        |i | _        y || _        y rb   )_parameters_restore_refs)r   r   restorer   s       r7   r  z_ParametersRestorer.__init__  s"    %<R
T
rP   c                     | j                   S rb   )r  r   s    r7   rT  z_ParametersRestorer.__enter__  s    }}rP   c                     	 | j                   j                  t        | j                  fi | j                         i | _        y # i | _        w xY wrb   )r  _updater~   r  r  )r   rX  	exc_valuerZ  s       r7   r[  z_ParametersRestorer.__exit__  s<    	$$T$--%F4::%FGDMBDMs   9A 	A)r   r   r   r   r  rT  r[  r^   rP   r7   r  r    s    R48 2
rP   r  c                       e Zd ZdZd`dZed        Zej                  d        Zed        Zej                  d        Zed        Z	e	j                  d        Z	ed	        Z
e
j                  d
        Z
ed        Zej                  d        Zed        Zd Zd Z fdZd Zd Zd Zed        Zed        Zed        Zd Zd Zd Zd Zd Zed        ZdadZdbdZd Z d`d Z! e"       dcd!       Z# e$d"e%#      d$        Z& e$d%e%#      d&        Z'd'e(d(e)fd)Z* e$d*e%#      d+        Z+ e$d,e%#      d`d-       Z,e-fd.Z.e-fd/Z/ e$d0e%#      d1        Z0ed2        Z1dcd3Z2d4 Z3d5 Z4d6 Z5d7 Z6d8 Z7d`d9Z8ddd:Z9ded;Z:ddd<e;fd=Z<ded>Z=dfd?Z> e$d@e%#      dgdA       Z?dgdBZ@dC ZAdD ZBdE ZCdgdFZD e$dGe%#      dH        ZEdI ZFdhdJZGdidKZHdjdLZIdkdMZJdN ZKdjdOZL e$dPe%#      dQ        ZMdR ZN e$d"e%#      dS        ZOdT ZP e$dUe%#      dV        ZQ e$dWe%#      dX        ZR e$dYe%#      dZ        ZSd[ ZTd\ ZUd] ZV	 	 dld^ZWeX e"       	 	 dld_              ZY xZZS )m
Parametersaa  
    Object that holds the namespace and implementation of Parameterized
    methods as well as any state that is not in __slots__ or the
    Parameters themselves.

    Exists at both the metaclass level (instantiated by the metaclass)
    and at the instance level. Can contain state specific to either the
    class or the instance as necessary.
    c                      || _         || _        y)zj
        cls is the Parameterized class which is always set.
        self is the instance if set.
        N)r   r   )r^  r   r   s      r7   r  zParameters.__init__  s    
 	
rP   c                 H    | j                   j                  j                  d   S Nr   self_or_clsr   parameters_stater^  s    r7   r   zParameters._BATCH_WATCH  s      00AA-PPrP   c                 J    || j                   j                  j                  d<   y r  r  r^  r   s     r7   r   zParameters._BATCH_WATCH  s    LQ))::=IrP   c                 H    | j                   j                  j                  d   S NTRIGGERr  r  s    r7   _TRIGGERzParameters._TRIGGER  s      00AA)LLrP   c                 J    || j                   j                  j                  d<   y r  r  r  s     r7   r  zParameters._TRIGGER!  s    HM))::9ErP   c                 H    | j                   j                  j                  d   S Nr   r  r  s    r7   r   zParameters._events%  s      00AA(KKrP   c                 J    || j                   j                  j                  d<   y r  r  r  s     r7   r   zParameters._events)  s    GL))::8DrP   c                 H    | j                   j                  j                  d   S Nr   r  r  s    r7   r   zParameters._state_watchers-  s      00AA*MMrP   c                 J    || j                   j                  j                  d<   y r  r  r  s     r7   r   zParameters._state_watchers1  s    IN)):::FrP   c                 p    | j                   t        d      | j                   j                  j                  S )z Dictionary of instance watchers.zUAccessing `.param.watchers` is only supported on a Parameterized instance, not class.r   r   r   r   r  s    r7   r   zParameters.watchers5  s0     ::sttzz))222rP   c                 h    | j                   t        d      || j                   j                  _        y )NzSSetting `.param.watchers` is only supported on a Parameterized instance, not class.r  r  s     r7   r   zParameters.watchers<  s*    ::qrr.3

""+rP   c                 J    | j                   | j                  S | j                   S rb   )r   r   r  s    r7   r  zParameters.self_or_clsB  s    !JJ.uyy>EJJ>rP   c                 8   |j                  d      |j                  d      }}||n|}|j                  j                  D ]4  }d|z   }||v s|j                  |      |j                  j                  |<   6 |j	                         D ]  \  }}t        | ||        y )Nr   r   rg  )r3   r   r  r   rl   r  )r   r?  r^  r   r  rz   r  rx   s           r7   r@  zParameters.__setstate__F  s    YYv&		%(8s$0ec,,==Aa%Ce|BG))C.++<<Q? > KKMDAqD!Q "rP   c                 ~    | j                   }|| j                  |   S | j                  d      |   }t        ||      S )z'Returns the class or instance parameterFr   )r   _cls_parametersr   r  )r^  r  rT  r   s       r7   __getitem__zParameters.__getitem__Q  sC    zz<((--MM5M)#.&tQ//rP   c                 L    t         |          t        | j                        z   S )zAdds parameters to dir)r  __dir__r{   r  )r^  r  s    r7   r  zParameters.__dir__Y  s     w 4(=(=#>>>rP   c              #   8   K   | j                   E d{    y7 w)z,Iterates over the parameters on this object.Nr  r  s    r7   __iter__zParameters.__iter__]  s     ((((s   c                     || j                   v S rb   r  )r^  r?   s     r7   __contains__zParameters.__contains__a  s    ----rP   c                 2   | j                   j                  d      }|t        || j                  v r| j	                  |      S | j
                  %t        d| j                  j                   d|      t        d| j                  j                   d|      )z.Extends attribute access to parameter objects.r   ztype object 'z.param' has no attribute 'z .param' object has no attribute )r   r3   r  r  r  r   r   r   )r^  r   r   s      r7   __getattr__zParameters.__getattr__d  s    nn  ';  5((($$T**ZZ =1C1C0DD]^b]e!fgg 1UYY%7%7$88XY]X`!abbrP   c                 &    || j                   _        y rb   r   rK   )r^  rK   s     r7   	_set_namezParameters._set_nameq  s    

rP   c                 `    | j                  d| j                  j                  t        fz         y )Nz%s%05d)r  r   r   object_countr  s    r7   _generate_namezParameters._generate_nameu  s"    EII$6$6#EEFrP   c                     | j                   }i }i }| j                  }|j                         D ]4  \  }}|j                  r|dk7  r|||<   |j                  s*|dk7  s0|||<   6 |j                         D ]  }| j                  |        |j                         D ]  }| j                  |d        i i }	}|j                         D ]1  \  }
}| j                  j                  |
      d   }|s$t        |j                  j                   d|
      |j                  |
      }||j                  s|
| j                  j                  j                  vrP	 | j!                  ||      \  }}}}|r6t%        j&                  d|
d|j(                   d	| d
| d dt*        d       t-        ||
|       | j!                  ||      \  }}}}|
||	|
<   |||
<   |r|t.        u r|t0        u r%t-        ||
|       4 |	|fS # t"        $ r d}Y w xY w)a  
        Initialize default and keyword parameter values.

        First, ensures that values for all Parameters with 'instantiate=True'
        (typically used for mutable Parameters) are copied directly into each object,
        to ensure that there is an independent copy of the value (to avoid surprising
        aliasing errors). Second, ensures that Parameters with 'constant=True' are
        referenced on the instance, to make sure that setting a constant
        Parameter on the class doesn't affect already created instances. Then
        sets each of the keyword arguments, raising when any of them are not
        defined as parameters.
        rK   F)deepcopyr   z/.__init__() got an unexpected keyword argument Nz
Parameter z on z, is being given a valid parameter reference zg but is implicitly allow_refs=False. In future allow_refs will be enabled by default and the reference z* will be resolved to its underlying value zv. Please explicitly set allow_ref on the Parameter definition to declare whether references should be resolved or not.   r,  )r   r  rl   r  r   r   _instantiate_paramr   get_param_descriptorr   r  r   r3   r  r   r  r#  r   r1  r2  ri   r3  r  rl  r   )r^  r   r   params_to_deepcopyparams_to_refr   r  r   r[  r   rK   r   descrc  r+  rg  re  ref_depsr,  s                      r7   _setup_paramszParameters._setup_paramsy  sD    zz''HE1}}&,-"5)'(e$	 ( $**,A$$Q' -%%'A$$Q$7 ( dID#9911$7:D~~../ 0((,x1 
 ;;t$D|4??
 uyy88III#.3.@.@s.K+Q!  (TZZL A)), .--0E 2%%-J /9	9 &9'(
 dC( 160B0B40M-C8X T
%T
X%:h$>NdH-Q (R Tz1 % #"#s   G??HHc                 b   t        t              }|j                         D ]  \  }}|D ]w  }t        |t              r+||j
                     j                  ||j                  f       >t        |      D ],  }||j
                     j                  ||j                  f       . y  |j                         D ]y  \  }}t        | \  }	}| j                  j                  j                  j                  |	|j                  j                  | j                  t        t!        |            d      f       { y )Nr   r  )r   r{   rl   rX   rY   ri   rS   rK   rs  r   r   r   ref_watchersr?   _watch
_sync_refsr   )
r^  r   groupsr  subrefsr   rw  ri   pnamesrefnamess
             r7   _setup_refszParameters._setup_refs  s    T""jjlNE7a+177O**E166?;215rxx(//0@A 6  + $\\^ME6"F|HfJJ&&33::""5#3#3T#f+5FSU"V<  ,rP   c                    | j                   j                  }||j                  v r)|j                  j                  |      j	                          |j
                  D ]D  \  }}|j                  |j                  n|j                  }|j                  j                  |       F g | j                   j                  _        t        | j                   j                  j                  fi ||i}|j                         D ci c]  \  }}|t        |       }}}| j                  |       || j                   j                  _        y c c}}w rb   )r   r   r%  r   r&  r  rT  r   r?   unwatchr~   r   rl   r   r  )	r^  rK   r+  param_privaterg  r  dep_objr   r[  s	            r7   r$  zParameters._update_ref  s    

22=+++$$((.557'44JAw%,\\%9gkkw||GMM!!'* 5 35

""/EJJ..33Cc{C8<

E94k#&&E$*.

""' Fs   ;Ec                    i }| j                   j                  j                  j                         D ]  \  }}| |   j                  }t        ||      }t        j                  |      }t        |      xs |}t        fd|D              s|s\	 t        ||      }	|	t        u s|	t        u rz|r!t        t        | j                  ||	             |	||<    t!        | j                         5  t#        | j                   |      5  | j%                  |       d d d        d d d        y # t        $ r	 t        }	Y w xY w# 1 sw Y   'xY w# 1 sw Y   y xY w)Nc              3      K   | ]>  }D ]7  }|j                   |j                  u xr |j                  |j                  k(   9 @ y wrb   )ri   r   rK   )rc   rj   rp  r   s      r7   re   z(Parameters._sync_refs.<locals>.<genexpr>  s@     cds\bWX		QUU*Asxx166/AA\bAds   AA)r   r   r   rl   r  r   r   r   r$   rk   rw   r   rl  r*   r   
_async_refr   r   rA  )
r^  r   updatesr  r+  r   r[  r   r,  new_vals
    `        r7   r  zParameters._sync_refs  s%   **4499??AJE3e00IsI.D005F*3/96Hcdcclt$'Y7 $'Y"6wu'7'7HI$GEN' B* 5::&%**g.W% / '&  $#$ /. '&s6   D%+ED:E%D76D7:E	?EEc                 V   t        j                  |      }t        |      xs |}t        ||j                        }|s
|s|sd d |dfS |}	 t        ||j                        }|r,t        t        | j                  |j                  |             d }||||fS # t        $ r	 t        }Y Ew xY w)N)r   F)r   r   r$   r   r  rw   r   rl  r*   r   r  rK   )r^  rc  r   r   r,  r[  r+  s          r7   r#  zParameters._resolve_ref  s    ,,U3&u-75D,<,<=Fue++	!%43C3CDE 75#3#3TYYFGED%))  	E	s   B B('B(c                   K   | j                   j                  j                  s!t        t	        | j
                  ||             y t        j                         }| j                   j                  j                  j                  |      }|$|| j                   j                  j                  |<   n5||ur1| j                   j                  j                  |   j                          	 t        |t        j                        r?|2 3 d {   }t        | j                   |f      5  | j                  ||i       d d d        =t        | j                   |f      5  	 | j                  || d {   i       d d d        | j                   j                  j                  j                  |      |u r"| j                   j                  j                  |= y y 7 # 1 sw Y   xY w6 d7 u# t         $ r Y yw xY w# 1 sw Y   ~xY w# | j                   j                  j                  j                  |      |u r"| j                   j                  j                  |= w w xY wwrb   )r   r   r  r*   r   r  asynciocurrent_taskr%  r3   r&  rX   typesAsyncGeneratorTyper   rA  r   )r^  r  	awaitabler  running_tasknew_objs         r7   r  zParameters._async_ref  s    zz))5575#3#3UIFG++-zz11<<@@G;GEJJ&&11%8-JJ&&11%8??A	A)U%=%=>%. 7'!%**uh7eW%56 87 ejj5(3e9_%=> 4 zz))4488?<OJJ..99%@ P777 &/ .=  43 zz))4488?<OJJ..99%@ Ps   C I#G9 ?GGGG9 G3 G9 G-G&G'	G0G9 8AIGG		G9 G	G*'G-)G**G--G62G9 9AIIc                 X    t         j                  |j                  |j                         S )zu
        Predicate that determines whether a Event object has actually
        changed such that old != new.
        )rn  ro  r   rm  )r   r  s     r7   _changedzParameters._changed(  s"     &&uyy%))<<<rP   c                 .   |rt         j                  nd }| j                  }|xs |j                  j                  }|xs |j
                  }t        j                  rlt        t        |            |j
                  f}|t        j                  v rt        j                  |   }n8 ||j                        }|t        j                  |<   n ||j                        }|||<   t        |t              r'|r$t        dz  a|j                  j!                          y y y )Nc                     | S rb   r^   rg  s    r7   r"  z/Parameters._instantiate_param.<locals>.<lambda>4  s    rP   r   )r   r  r   r   r   rK   rQ  rS  r   r}   rW  r  rX   Parameterizedr  r?   r  )	r^  	param_objdict_r  r  instantiatorr   	param_key
new_objects	            r7   r  zParameters._instantiate_param0  s     )1t}}kzz4--44#Y^^##T$Z)..9I-;;;.<<YG
))*;*;<
=G!//	:%i&7&78Jc
j-0XAL ++- 6>0rP   c           	         | j                   }g }t        |      j                  j                  d   D ]0  \  }}}}}	|	D 
cg c](  }
|"|
j                  j                  d      d   |k(  s'|
* }	}
|rt        t              }t        ||g       D ]K  }|t        |j                        t        |j                        |j                  f   j                  d |f       M |j                         D ]  }| j                  ||||        t!        | j                   |      }|r||vr|j                  |       nm|	ri|j"                  j$                  j'                  |g       D ]?  }|j                  |j                  n|j                  j                  j)                  |       A nmt        t              }|	D ]^  }t        |g |g      D ]K  }|t        |j                        t        |j                        |j                  f   j                  ||f       M ` |j                         D ]?  }| j                  |||||      }|j"                  j$                  |   j                  |       A 3 |D ]	  } |         y c c}
w )NwatchrA   r   )r   r}   r?   _dependsrP  r   r   r{   ri  idrT  r   rJ  rS   r   _watch_grouprh   r   dynamic_watchersr   r  )r^  r  initr   init_methodsr  queuedon_initr   rY  rd   constant_groupedrj   rO  rQ  r!  groupedddepr  s                      r7   r*  zParameters._update_depsK  s'   jj:>s)//:R:RSZ:[6FFGXw #*d'QY->!&&,,sBSTUBVZcBcq'Gd#.t#4 ,S(B?C$blBswwK%JKRRTXZ]S^_ @-446E&&sFFEB 7EJJ/q4 ''*,,==AA&"MAffnQUU!&&??GGJ N  "$'G,S"tf=CR\2cgg;ABII4QT+V >   !),,S&&%S##44V<CCGL *3 ;\8 AC 3 es   (I4(I4c                    }g}|j                   j                  d      dd D ]2  }t        ||j                  d      d   d      }|j                  |       4 |j                  |j
                  n|j                  }||dd vrdd|j                  fS |j                  |      }	d}
|	dkD  rfd}
dj                  |j                   j                  d      d   j                  d      |	dz   d       }|dk(  r&t        |d   j                        D cg c]  }| }}n|g}d|j                   v r|j                   j                  d      d   }n|j                  }||
|fS c c}w )	a  
        If a subobject whose parameters are being depended on changes
        we should only trigger events if the actual parameter values
        of the new object differ from those on the old subobject,
        therefore we accumulate parameters to compare on a subobject
        change event.

        Additionally we need to make sure to notify the parent object
        if a subobject changes so the dependencies can be
        reinitialized so we return a callback which updates the
        dependencies.
        rA   Nr   rI  r   c                  <    j                   j                         y)z
                If a subobject changes, we need to notify the main
                object to update the dependencies.
                N)r?   r*  )r   r  r   s    r7   ry  z2Parameters._resolve_dynamic_deps.<locals>.callback  s    
 		&&y1rP   r   r?   )rP  r   rh   rS   rT  r   rJ  r   r  r{   r?   )r   r   dynamic_dep	param_depr  subobjsubobjssubpathr  depthry  r   rw  	subparamsrJ  s    `  `          r7   _resolve_dynamic_depsz Parameters._resolve_dynamic_depsm  sf    %"''--c23B7GVW]]3%7%:DAFNN6" 8 $->>#9)--y~~'#2,&y~~--g&192 HH[%%++C0399#>uQwxHI<&*72;+<+<&=>&=&=I>I+"""##))#.r2D>>D(D(( ?s   	E!c                    |d   \  }}|j                   |j                  n|j                   }g }	|D ]/  \  }
}|j                  |	vs|	j                  |j                         1 |dd|j                  }}}n| j                  ||||      \  }}}t        |||||      }|j                  j                  ||	|j                  |d      S )ab  
        Sets up a watcher for a group of dependencies. Ensures that
        if the dependency was dynamically generated we check whether
        a subobject change event actually causes a value change and
        that we update the existing watchers, i.e. clean up watchers
        on the old subobject and create watchers on the new subobject.
        r   Nr   )r  r  )	rT  r   rK   rS   rJ  r  r  r?   r  )r^  r   rK   r  rO  r  r  r  r  r   rg  gr  ry  rJ  mcallers                   r7   r  zParameters._watch_group  s     "'qY#,>>#9)--y~~DAqvvV#aff%  (,dINNxI(-(C(C[)Y)8%Ix CtYA}}##VY^^Fr $ K 	KrP   c                 .    t        | j                  |      S rb   )_parameterized_repr_htmlr  )r^  opens     r7   _repr_html_zParameters._repr_html_  s    '(9(94@@rP   zfUse instead `for k,v in p.param.objects().items(): print(f"{p.__class__.name}.{k}={repr(v.default)}")`r   c                     | j                   }|j                  j                         D ]J  \  }}t        |t              st        |j                  dz   |z   dz   t        |j                        z          L y)z
        Print the default values of all cls's Parameters.

        .. deprecated:: 1.12.0
            Use instead `for k,v in p.param.objects().items(): print(f"{p.__class__.name}.{k}={repr(v.default)}")`
        rA   r  N)	r   r   rl   rX   rY   printr   reprr  )r^  r   r  r   s       r7   print_param_defaultszParameters.print_param_defaults  s[     ii||))+GC#i(cll3&s*C/ckk1BBC ,rP   zUse instead `p.param.default =`c                 6    | j                   }t        |||       y)z
        Set the default value of param_name.

        Equivalent to setting param_name on the class.

        .. deprecated:: 1.12.0
             Use instead `p.param.default =`
        N)r   r  )r^  
param_namer   r   s       r7   set_defaultzParameters.set_default  s     iiJu%rP   r
  r  c                     | j                   }t        j                  |||       t        j	                  |||       |j
                  j                  j                          y)a  
        Add a new Parameter object to this class.

        This method allows dynamically adding a Parameter to the class, resulting in behavior equivalent to declaring
        the Parameter in the class's source code.

        Parameters
        ----------
        param_name : str
            The name of the parameter to add.
        param_obj : Parameter
            The Parameter object to add.

        Examples
        --------
        Create a Parameterized class:

        >>> import param
        >>> class P(param.Parameterized):
        ...     a = param.Number()
        ...     b = param.String()
        >>> p = P()

        Add a new parameter to the class `P` via the class namespace `P.param`:

        >>> P.param.add_parameter('c', param.Tuple(default=(1, 2, 3)))
        >>> print(p.c)
        (1, 2, 3)

        Add a new parameter to the class `P` via the instance namespace `p.param`:

        >>> p.param.add_parameter('d', param.Tuple(default=(3, 2, 1)))
        >>> p.d
        (3, 2, 1)

        N)r   r}   r  ParameterizedMetaclass_initialize_parameterr   r   clear)r^  r
  r  r   s       r7   add_parameterzParameters.add_parameter  sJ    R iij)444S*iP""((*rP   z"Use instead `.param.add_parameter`c                 &    | j                  ||      S )zg
        Add a new Parameter object into this object's class.

        .. deprecated :: 1.12.0
        )r  )r^  r
  r  s      r7   _add_parameterzParameters._add_parameter	  s     "":y99rP   z2Use instead `.param.values()` or `.param['param']`c                 8    | j                  d      }||S ||   S )a  
        Return the Parameters of this class as the
        dictionary {name: parameter_object}

        Includes Parameters from this class and its
        superclasses.

        .. deprecated:: 1.12.0
            Use instead `.param.values()` or `.param['param']`
        r   r  )r   )r^  parameter_namepdicts      r7   r   zParameters.params	  s*     z2!L((rP   c                x   i }| j                   | j                   j                  }t        |t        u r|nt	        |fi |      }|D ]I  }||v r||j
                  v r|j
                  |   ||<   )||j                  v s8|j                  |   ||<   K t	         | j                  |fi |      }t        | ||      S )a  
        Update multiple parameters of this object or class before triggering events.

        Allows setting the parameters of the object or class using a dictionary, an iterable, or keyword arguments
        in the form of `param=value`. The specified parameters will be updated to the given values.

        This method can also be used as a context manager to temporarily set and then reset parameter values.

        Parameters
        ----------
        **params : dict or iterable or keyword arguments
            The parameters to update, provided as a dictionary, iterable, or keyword arguments in `param=value` format.

        User Guide
        ----------
        https://param.holoviz.org/user_guide/Parameters.html#other-parameterized-methods

        Examples
        --------
        Create a Parameterized class:

        >>> import param
        >>> class P(param.Parameterized):
        ...    a = param.String()
        ...    b = param.String()

        Define the instance:

        >>> p = P(a="0. Hello", b="0. World")

        Use `.update` to update the parameters:

        >>> p.param.update(a="1. Hello", b="2. World")
        >>> p.a, p.b
        ('1. Hello', '1. World')

        Update the parameters temporarily:

        >>> with p.param.update(a="2. Hello", b="2. World"):
        ...     print(p.a, p.b)
        2. Hello 2. World

        >>> p.a, p.b
        ('1. Hello', '1. World')

        Lets see that events are triggered **after** all parameters have been updated

        >>> @param.depends(p.param.a, watch=True)
        ... def print_a_b(a):
        ...     print(p.a, p.b)
        >>> my_param.param.update(a="3. Hello",b="3. World")
        3. Hello 3. World

        )r   r  r   )	r   r   r{   rl  r~   r   r%  r  r  )r^  r[   ro   r   privater   r  r  s           r7   rA  zParameters.update$	  s    n ::!jj00GC9$4&$s:Mf:MNFD=gll*"),,u"5DKg000")"4"4U";DK   }u}}S3F34"eW4PPrP   c                   | j                   }d| _         | j                  }|t        urt        |fi |}|D cg c]  }|| v rt	        | |   d      r| }}|D ]  }d| |   _         | j                         }|j                         D 	ci c]  \  }}	||v s|||    }
}}	|j                         D ]B  \  }}	|| vr+d| _         t        |d| j                  j                         	 t        |||	       D || _         |s| j                          |D ],  }| |   }d|_        t        |||j                         d|_        . |
S c c}w c c}	}w # t        $ r	 d| _          w xY w)NT_autotrigger_valuer   Fz is not a parameter of resetz	set-reset)r   r  rl  r~   rZ   _moder   rl   r@  r   r   r  r   r   _autotrigger_reset_value)r^  r[   ro   r   r  rz   trigger_paramstpr   rx   r  r   s               r7   r  zParameters._updatei	  s   ((!''i#((F 
!EzgeAh0DE v 	 

 !B#E"IO ! ,2LLNJNDAqa6k1fQi<NJllnFQ~%*" A5(?		@R@R?S!TUUQ* % )&&( Bb	AAGKQ%?%?@!AG	 !
 =
 K  %*"s   E
EE(EE zUse instead `.param.update`c                     | j                   }|r;t        |      dk(  r|d   |vr|s|d   ||d   <   nt        d|j                  z        | j	                  |      S )a  
        For each param=value keyword argument, sets the corresponding
        parameter of this object or class to the given value.

        For backwards compatibility, also accepts
        set_param("param",value) for a single parameter value using
        positional arguments, but the keyword interface is preferred
        because it is more compact and can set multiple values.

        .. deprecated:: 1.12.0
            Use instead `.param.update`
        r+  r   r   z-Invalid positional arguments for %s.set_param)r  r=  r@  rK   rA  )r^  rn   ro   r  s       r7   	set_paramzParameters.set_param	  sh     ''4yA~$q'"7"&q'tAw !P"-"2"2"4 5 5||F##rP   c                    | j                   }|j                  j                  }|r|S i }t        |      D ]:  }|j                  j                         D ]  \  }}t        |t              s|||<    < ||j                  _        |S )z
        Class parameters are cached because they are accessed often,
        and parameters are rarely added (and cannot be deleted)
        )r   r   r   r   r   rl   rX   rY   )r^  r   r  	paramdictr   rK   r   s          r7   r  zParameters._cls_parameters	  s}     ii##**L	nF#__224	cc9-&)IdO 5 % &/"rP   c                    | j                   /| j                   j                  j                  s|du rt        d      | j                  }|r| j                   |dk(  rmt        | j                   j                  dd      rJ| j                   j                  j                  r*t        |fi | j                   j                  j                  S |S |D ci c]  }|| j                   j                  |    c}S |S c c}w )a  
        Returns the Parameters of this instance or class

        If instance=True and called on a Parameterized instance it
        will create instance parameters for all Parameters defined on
        the class. To force class parameters to be returned use
        instance=False. Since classes avoid creating instance
        parameters unless necessary you may also request only existing
        instance parameters to be returned by setting
        instance='existing'.
        Ta  Looking up instance Parameter objects (`.param.objects()`) until the Parameterized instance has been fully initialized is not allowed. Ensure you have called `super().__init__(**params)` in your Parameterized constructor before trying to access instance Parameter objects, or looking up the class Parameter objects with `.param.objects(instance=False)` may be enough for your use case.r   r  F)	r   r   r  r   r  rh   r   r~   r?   )r^  r   r  rz   s       r7   r   zParameters.objects	  s     ::!%***D*D*P*PU]aeUe3  %%

.:%5::55}eLQVQ[Q[QkQkQrQrK)C)C)J)JKK8=>15::++A..>> ?s   !C2c                 F   | j                   +| j                   j                  j                  st        d      | D cg c]  }t	        | |   d      r| }}|D ci c]  }||v r|| |   j
                   }}| j                  }| j                  }g | _        g | _        | j                         }|D ci c]  }|||   
 }	}d| _	        | j                  t        |	fi |       d| _	        | xj                  |z  c_        | xj                  |z  c_        yc c}w c c}w c c}w )ad  
        Trigger watchers for the given set of parameter names. Watchers
        will be triggered whether or not the parameter values have
        actually changed. As a special case, the value will actually be
        changed for a Parameter of type Event, setting it to True so
        that it is clear which Event parameter has been triggered.
        NzTriggering watchers on a partially initialized Parameterized instance is not allowed. Ensure you have called super().__init__(**params) in the Parameterized instance constructor before trying to set up a watcher.r  TF)r   r   r  r   rZ   r  r   r   r   r  rA  r~   )
r^  param_namesr   r  triggersr   r   param_valuesrK   r   s
             r7   triggerzParameters.trigger	  s>    ::!%***D*D*P*P\  &+ FU$U1X/CD U F ,A+qK/? eAh111+ 	 A (( "||~7BC{t$T**{CT&-H-.)FA Ds   DD1Dc           	          |rd}n|j                   rdnd}t        |j                  |j                  |j                  |j
                  |j                  |j                  |      S )zFReturns an updated Event object with the type field set appropriately.	triggeredrk  r   r
  )onlychangedr  rJ  rK   r   r   r   rm  )r^  r  r  r*  
event_types        r7   _update_event_typezParameters._update_event_type
  sO    $J&-&9&9uJ%**5::599%))		
D 	DrP   c                 r   |j                   dk(  r|i }}n&d|D ci c]  }|j                  |j                   }}}t        |j                        rAt
        t        d|j                  z        t        t        |j                  g|i |       y 	  |j                  |i | y c c}w # t        $ r Y y w xY w)Nrn   r^   zCould not execute %s coroutine function. Please register a asynchronous executor on param.parameterized.async_executor, which schedules the function on an event loop.)	r  rK   rm  r$   rb  r*   r   r   r   )r   r  r   rn   ro   r  s         r7   _execute_watcherzParameters._execute_watcher

  s    <<6!!2&D6J6%

EII 56&JDwzz*%" $N $+::	$. / /
 77::???@

D+F+  K  s   B%B* *	B65B6c                    | j                   rnj                  r| j                  |      sy| j                  rV| j                  j                  |       t        fd| j                  D              s| j                  j                         yy| j                  || j                         }t        | j                  j                  d      5  | j                  |f       ddd       y# 1 sw Y   yxY w)z=Invoke the given watcher appropriately given an Event object.Nc              3   &   K   | ]  }|u  
 y wrb   r^   )rc   r!  r  s     r7   re   z+Parameters._call_watcher.<locals>.<genexpr>'
  s     C-Bw!|-Bs   Fr   r   )r  r+  r  r   r   rS   rk   r   r-  r   r  r  r/  )r^  r  r  s    ` r7   r  zParameters._call_watcher
  s    >>  %..*?MM  'CU-B-BCC%%,,W5 D ,,WeU^^LE%e&7&7TYZ&&w9 [ZZs   C++C4c           
      ^   | j                   r
t        | j                   D cg c]  }|j                  |j                  f|f c}      }| j                  dd }g | _         g | _        t        |d       D ]  }|j                  D cg c]>  }||j                  f|v r,| j                  ||||j                  f   | j                        @ }}t        | j                  |j                  d      5  | j                  ||       ddd        | j                   r	yyc c}w c c}w # 1 sw Y   xY w)z
        Batch call a set of watchers based on the parameter value
        settings in kwargs using the queued Event and watcher objects.
        Nc                     | j                   S rb   r  r   s    r7   r"  z1Parameters._batch_call_watchers.<locals>.<lambda>:
  s    !,,rP   r  Fr2  )r   r   rK   rJ  r   r  parameter_namesr-  r  r   r  r  r/  )r^  r  
event_dictr   r  rK   r   s          r7   r   zParameters._batch_call_watchers.
  s,   
 mm$38==&B3@% ).

EJJ'?&G3@&B CJ,,Q/HEM$&E!!(0FG '.&=&=A&=d"GLL1Z?  227JgllG[<\38>>C&=  A *%*;*;GNNX]^**7F; _^ H mm&BA _^s   !DAD,D##D,	c                    | j                   }||_        t        |t              rd|f}n|f}|j                  j                  d      j                         D ]D  \  }}t        |d      s |j                  | s#|j                  j                  |      }||_        F |r1	 t        ||      }|D ]  }	|	j                  j                  ||         yy# t        $ r g }Y 2w xY w)a  
        Set time_fn for all Dynamic Parameters of this class or
        instance object that are currently being dynamically
        generated.

        Additionally, sets _Dynamic_time_fn=time_fn on this class or
        instance object, so that any future changes to Dynamic
        Parmeters can inherit time_fn (e.g. if a Number is changed
        from a float to a number generator, the number generator will
        inherit time_fn).

        If specified, sublistattr is the name of an attribute of this
        class or instance that contains an iterable collection of
        subobjects on which set_dynamic_time_fn should be called.  If
        the attribute sublistattr is present on any of the subobjects,
        set_dynamic_time_fn() will be called for those, too.
        Nr   _value_is_dynamic)r  _Dynamic_time_fnrX   r}   r?   r   rl   rZ   r8  get_value_generatorrh   r  set_dynamic_time_fn)
r^  time_fnsublistattrr  arr   r   r  sublistr   s
             r7   r;  zParameters.set_dynamic_time_fnB
  s    $ '''.$k$'k"AA$$,,Z8>>@CAaq-.&1&&*#))==a@A)0A&	 A !+k: 		--gkB   " s   C CCc           	          | j                   }|t        j                  vr6t        d|dt	        t        j                  j                                     t        j                  |   } |j                  ||      S )a(  
        Return the serialized parameters of the Parameterized object.

        Parameters
        ----------
        subset : list, optional
            A list of parameter names to serialize. If None, all parameters will be serialized. Defaults to None.
        mode : str, optional
            The serialization format. By default, only 'json' is supported. Defaults to 'json'.

        Returns
        -------
        Any
            The serialized value.

        User Guide
        ----------
        https://param.holoviz.org/user_guide/Serialization_and_Persistence.html#serializing-with-json

        Examples
        --------
        Create a Parameterized instance and serialize its parameters:

        >>> import param
        >>> class P(param.Parameterized):
        ...     a = param.Number()
        ...     b = param.String()
        >>> p = P(a=1, b="hello")

        Serialize parameters:

        >>> serialized_data = p.param.serialize_parameters()
        >>> print(serialized_data)
        {"name": "P00002", "a": 1, "b": "hello"}

        r  r  r  )r  rY   r  r@  r{   r  serialize_parameters)r^  r  r  r  r   s        r7   rB  zParameters.serialize_parametersk
  ss    J ''y---uTH,TUYZcZpZpZuZuZwUxT{|}}++D1
.z..{6JJrP   c           	          | j                   }|t        j                  vr6t        d|dt	        t        j                  j                                     t        j                  |   } |j                  ||      S Nr  r  )r  rY   r  r@  r{   r  serialize_parameter_value)r^  r  r  r  r   s        r7   serialize_valuezParameters.serialize_value
  sp    ''y---uTH,TUYZcZpZpZuZuZwUxT{|}}++D1
3z33KGGrP   returnc                 j    | j                   }t        j                  |   } |j                  |||      S )a*  
        Deserialize the given serialized data. This data can be used to create a
        `Parameterized` object or update the parameters of an existing `Parameterized` object.

        Parameters
        ----------
        serialization : str
            The serialized parameter data as a JSON string.
        subset : list of str, optional
            A list of parameter names to deserialize. If `None`, all parameters will be
            deserialized. Defaults to `None`.
        mode : str, optional
            The serialization format. By default, only 'json' is supported.
            Defaults to 'json'.

        Returns
        -------
        dict
            A dictionary with parameter names as keys and deserialized values.

        User Guide
        ----------
        https://param.holoviz.org/user_guide/Serialization_and_Persistence.html#serializing-with-json

        Examples
        --------
        >>> import param
        >>> class P(param.Parameterized):
        ...     a = param.Number()
        ...     b = param.String()
        ...
        >>> serialized_data = '{"a": 1, "b": "hello"}'
        >>> deserialized_data = P.param.deserialize_parameters(serialized_data)
        >>> print(deserialized_data)
        {'a': 1, 'b': 'hello'}
        >>> instance = P(**deserialized_data)

        rA  )r  rY   r  deserialize_parameters)r^  serializationr  r  r  r   s         r7   rI  z!Parameters.deserialize_parameters
  s8    N ''++D1
0z00mTZ[[rP   c           	          | j                   }|t        j                  vr6t        d|dt	        t        j                  j                                     t        j                  |   } |j                  |||      S rD  )r  rY   r  r@  r{   r  deserialize_parameter_value)r^  r  r   r  r  r   s         r7   deserialize_valuezParameters.deserialize_value
  sr    ''y---uTH,TUYZcZpZpZuZuZwUxT{|}}++D1
5z55k5%PPrP   c           	          | j                   }|t        j                  vr6t        d|dt	        t        j                  j                                     t        j                  |   } |j                  |||      S )zAReturns a schema for the parameters on this Parameterized object.r  r  r  )r  rY   r  r@  r{   r  r  )r^  r  r  r  r  r   s         r7   r  zParameters.schema
  sr    ''y---uTH,TUYZcZpZpZuZuZwUxT{|}}++D1
 z  4GGrP   z
        Use `.param.values().items()` instead (or `.param.values()` for the
        common case of `dict(....param.get_param_values())`)
    c                 z    | j                  |      }|j                         D cg c]	  \  }}||f c}}S c c}}w )a  
        Return a list of name,value pairs for all Parameters of this
        object.

        When called on an instance with onlychanged set to True, will
        only return values that are not equal to the default value
        (onlychanged has no effect when called on a class).

        .. deprecated:: 1.12.0
            Use `.param.values().items()` instead (or `.param.values()` for the
            common case of `dict(....param.get_param_values())`)
        )r   rl   )r^  r+  valsrz   rx   s        r7   get_param_valueszParameters.get_param_values
  s8    " ||K(#'::<0<41aA<000s   7c                    | j                   }g }|j                  j                  d      j                         D ]~  \  }}|j                  j	                  |      }|dk(  r#|r!t        | j                  j                  |      rI|r!t        j                  ||j                        rl|j                  ||f        |j                  t        d             t        |      S )a*  
        Return a dictionary of name,value pairs for the Parameters of this
        object.

        When called on an instance with onlychanged set to True, will
        only return values that are not equal to the default value
        (onlychanged has no effect when called on a class).
        r   rK   r   r  )r  r?   r   rl   r:  r   r   r   rn  ro  r  rS   sortr   r~   )r^  r+  r  rP  rK   r   r   s          r7   r   zParameters.values
  s     ''$**22:>DDFID#%%99$?Ev~+-		@R@RTY2Zj&9&9%&MT5M* G 			jm	$DzrP   c                    | j                   }|j                  j                  d      j                  |      }|st	        ||      S d\  }}t        |t              r|}n|}t        |d      s|j                  ||      S |j                  ||      S )z
        Force a new value to be generated for the dynamic attribute
        name, and return it.

        If name is not dynamic, its current value is returned
        (i.e. equivalent to getattr(name).
        r   NN_force)
r  r?   r   r3   rh   rX   r}   rZ   r	  rV  )r^  rK   
cls_or_slfr  r   slfs         r7   force_new_dynamic_valuez"Parameters.force_new_dynamic_value  s     &&
$$,,Z8<<TB	:t,,Sj&CCy*$$S#..##C--rP   c                    | j                   }|j                  j                  d      j                  |      }|st	        ||      }|S t        |d      r4|j                  D cg c]  }|j                  j                  |       }}|S t        |d      st	        ||      }|S t        |t              r3||j                  j                  v r|j                  j                  |   }|S |j                  }|S c c}w )a  
        Return the value or value-generating object of the named
        attribute.

        For most parameters, this is simply the parameter's value
        (i.e. the same as getattr()), but Dynamic parameters have
        their value-generating object returned.
        r   attribsr8  )r  r?   r   r3   rh   rZ   r[  r:  rX   r  r   r   r  r^  rK   rW  r  r   r>  s         r7   r:  zParameters.get_value_generator  s     &&
$$,,Z8<<TB	Jt,E( # Yy)FOFWFWXFWZ%%99!<FWEX   #67Jt,E  *m4A[A[AbAb9b"2299$?
  "))! Ys   !"C2c                    | j                   }|j                  j                  d      j                  |      }|st	        ||      }|S t        |d      r4|j                  D cg c]  }|j                  j                  |       }}|S t        |d      st	        ||      }|S t        |t              r|j                  d|      }|S |j                  |d      }|S c c}w )z
        Return the current value of the named attribute without modifying it.

        Same as getattr() except for Dynamic parameters, which have their
        last generated value returned.
        r   r[  _inspectN)r  r?   r   r3   rh   rZ   r[  inspect_valuerX   r}   r^  r\  s         r7   r_  zParameters.inspect_value>  s     &&
$$,,Z8<<TB	Jt,E  Yy)@I@Q@QR@Q1Z%%33A6@QER  :.Jt,E  *T*!**4
;  "**:d; Ss   !"Cc                     t        | j                  |      }t        | j                  | j                  ||      }t        |d|      \  }}| j                  |S t        | j                  |||      S )am  
        Given the name of a method, returns a PInfo object for each dependency
        of this method. See help(PInfo) for the contents of these objects.

        By default intermediate dependencies on sub-objects are not
        returned as these are primarily useful for internal use to
        determine when a sub-object dependency has to be updated.
        r   rT  rK   r  F)rY  rZ  rd  )rh   r  r  r   r   rW  ri  )r^  rK   rZ  r  rX  r[  rY  s          r7   method_dependencieszParameters.method_dependenciesV  sq     **D1%))%**4#%+5|=g::K JJgLB 	BrP   z(Use instead `.param.method_dependencies`c                 &     | j                   |i |S )a  
        Given the name of a method, returns a PInfo object for each dependency
        of this method. See help(PInfo) for the contents of these objects.

        By default intermediate dependencies on sub-objects are not
        returned as these are primarily useful for internal use to
        determine when a sub-object dependency has to be updated.

        .. deprecated: 2.0.0
            Use instead `.param.method_dependencies`
        )rb  )r^  rn   ro   s      r7   params_depended_onzParameters.params_depended_onj  s     )u(($9&99rP   c                     i }t        | j                        D ]T  }t        |      D ]D  }t        | j                  |      }t        |di       }d|vr+|d   D ]  \  }}}||}|||f||<    F V |S )z
        Returns a mapping between any declared outputs and a tuple
        of the declared Parameter type, the output method, and the
        index into the output if multiple outputs are returned.
        rW   r9  )r   r   dirrh   r  )	r^  r9  r   rK   r  r   overriderE  idxs	            r7   r9  zParameters.outputsy  s     UYY'CC !2!2D9"5E),1),<(HeS+'%*FC$8GDM -= ! ( rP   c           
         t        |t              rit        |j                  t              r|j                  nd}||j                  n
t	        |      }t        |||j                  |d      }|dk(  rg g fS |gg fS t        |      \  }}}	|| j                  }
n9|sg t        |      gfS t        | j                  |j                  d      d         s4t        d|dd d	| j                   d
|j                  d      d   d      t        | j                  |dd d      }
|
|dd j                  d      }g }t        |      dk\  ru|rsd}|}|2|r0|dd }t        | j                  dj                  |      d      }||r0|r9| j!                  dj                  |dt        |      dz          ||      \  }}||z  }||dk(  rg fS t        |      gfS t        |
t              r|
dfnt	        |
      |
f\  }}|dk(  rX| j!                  |dd ||      \  }}|
j"                  D ],  }|
j"                  j!                  |||      \  }}||z  }||z  }. ||fS ||
j"                  v rt        ||||
j"                  |   |	      }nt        |
|      rXt%        |
|      }t        |t              rg g fS t        |t&        t(        f      rt+        ||||      }nHt        d|d|
 d      t%        |
dd      rg |dk(  rg fS t        |      gfS t        d|d|
 d      ||s|gg fS | j!                  |dd ||      \  }}|dk7  r|j-                  |       ||fS )a  
        Resolves a dependency specification into lists of explicit
        parameter dependencies and dynamic dependencies.

        Dynamic dependencies are specifications to be resolved when
        the sub-object whose parameters are being depended on is
        defined.

        During class creation dynamic=False which means sub-object
        dependencies are not resolved. At instance creation and
        whenever a sub-object is set on an object this method will be
        invoked to determine whether the dependency is available.

        For sub-object dependencies we also return dependencies for
        every part of the path, e.g. for a dependency specification
        like "a.b.c" we return dependencies for sub-object "a" and the
        sub-sub-object "b" in addition to the dependency on the actual
        parameter "c" on object "b". This is to ensure that if a
        sub-object is swapped out we are notified and can update the
        dynamic dependency to the new object. Even if a sub-object
        dependency can only partially resolved, e.g. if object "a"
        does not yet have a sub-object "b" we must watch for changes
        to "b" on sub-object "a" in case such a subobject is put in "b".
        Nr   rb  only)rP  rA   r   zDependency z could not be resolved, z has no parameter or attribute z_. Ensure the object being depended on is declared before calling the Parameterized constructor.r   r?   )rT  r   rK   r  z
Attribute z could not be resolved on abstract)rX   rY   ri   r  r}   rV  rK   rR  r  r  rZ   r   r  r  r=  r  rU  r?   rh   r   r   r  rS   )r^  rP  rY  rZ  rT  r   infor   r   rJ  srcr   r[  sub_srcr  subdepsrg  r\  r   
param_depsparam_dynamic_depsattr_objs                         r7   rU  zParameters._spec_to_obj  s   2 dI&!+DJJ!F4::DD $$**$t*Cd$))"2D%/2R??dVR??06T4;##C4()))5,,ciinQ.?@$!#ab',DUEVEVDW X558YYs^A5F4I J11  E--s13x>C{12w}}S)
 t9>l"G"G!/g")#2,"+E,=,=sxx?PRV"W "/g %*%7%7HHT/3w<>%:;Wl&T
<6#9RQQ4@P?QQQ#-c4#8S$KtCy#>N	T7?!&!3!3CGWl!SD,YY141G1G7T`1a.
.
" 22  %%SYYd$!iioD:DS$sD)H(M22vH|Z&@A$Cd$,. %z$9STWSXXY%Z[[S*d+\V3rKK%T:J9KKK :dX5OPSuTU!VWW;l62:"//AB,Ol6!KK\!!rP   c                 D   | j                   +| j                   j                  j                  st        d      |j                  }|D ]  }|| j
                  j                  vr/t        dj                  || j
                  j                              | j                   V|dk(  rQ| j                   j                  j                  }||vri ||<   |||   vrg ||   |<    t        ||   |   |      |       | |   j                  }||vrg ||<    t        ||   |      |        y )Nz(Un)registering a watcher on a partially initialized Parameterized instance is not allowed. Ensure you have called super().__init__(**) in the Parameterized instance constructor before trying to set up a watcher.z<{} parameter was not found in list of parameters of class {}r   )r   r   r  r   r5  r   r?   r@  r6  r   r   rh   )r^  actionr  rJ  r5  r  r   s          r7   _register_watcherzParameters._register_watcher  s+   ::!%***D*D*P*PX  "11-NUYY__4  "::@&QVQZQZQcQc:df f zz%$'/ ::55>>!1/1H^,x7757H^,T2?06?H 099x'%'HTN//8! .rP   c                 N    |dk  rt        d      | j                  ||||||      S )a  
        Register the given callback function `fn` to be invoked for
        events on the indicated parameters.

        `what`: What to watch on each parameter; either the value (by
        default) or else the indicated slot (e.g. 'constant').

        `onlychanged`: By default, only invokes the function when the
        watched item changes, but if `onlychanged=False` also invokes
        it when the `what` item is set to its current value again.

        `queued`: By default, additional watcher events generated
        inside the callback fn are dispatched immediately, effectively
        doing depth-first processing of Watcher events. However, in
        certain scenarios, it is helpful to wait to dispatch such
        downstream events until all events that triggered this watcher
        have been processed. In such cases setting `queued=True` on
        this Watcher will queue up new downstream events generated
        during `fn` until `fn` completes and all other watchers
        invoked by that same event have finished executing),
        effectively doing breadth-first processing of Watcher events.

        `precedence`: Declares a precedence level for the Watcher that
        determines the priority with which the callback is executed.
        Lower precedence levels are executed earlier. Negative
        precedences are reserved for internal Watchers, i.e. those
        set up by param.depends.

        When the `fn` is called, it will be provided the relevant
        Event objects as positional arguments, which allows it to
        determine which of the possible triggering events occurred.

        Returns a Watcher object.

        See help(Watcher) and help(Event) for the contents of those objects.
        r   yUser-defined watch callbacks must declare a positive precedence. Negative precedences are reserved for internal Watchers.)r@  r  )r^  rb  r5  rJ  r+  r  r  s          r7   r  zParameters.watch	  s<    J > C D D ||B{FJWWrP   c                     t        |t              rt        |      n|f}t        | j                  | j
                  |d|||||	      }| j                  d||       |S )Nrn   	rT  r   rb  r  r+  r5  rJ  r  r  rS   )rX   r{   r|   r  r   r   ru  r^  rb  r5  rJ  r+  r  r  r  s           r7   r  zParameters._watch4  s\    4>PT4U%0\k[muzzuyyRf&1?#FzK 	'48rP   c                     	 | j                  d||j                         y# t        $ r! | j                  dt	        |       d       Y yw xY w)zYRemove the given Watcher object (from `watch` or `watch_values`) from this object's list.remove)rJ  zNo such watcher z to remove.N)ru  rJ  r   warningr   )r^  r  s     r7   r  zParameters.unwatch<  sL    	H##HgGLL#I 	HMM,S\N+FG	Hs   ! 'A
Ac                     |dk  rt        d      |dk(  sJ t        |t              rt        |      }n|f}t	        | j
                  | j                  |d|||||	      }| j                  d||       |S )a  
        Easier-to-use version of `watch` specific to watching for changes in parameter values.

        Only allows `what` to be 'value', and invokes the callback `fn` using keyword
        arguments <param_name>=<new_value> rather than with a list of Event objects.
        r   rw  r   ro   ry  rS   )r@  rX   r{   r|   r  r   r   ru  rz  s           r7   watch_valueszParameters.watch_valuesC  s     > C D D wot,#O4O.0OuzzuyyR'[*9!'J@ 	'48rP   z@Use instead `{k:v.default for k,v in p.param.objects().items()}`c                    | j                   }i }|j                  j                  d      j                         D ]K  \  }}|j                  r	 |j
                  r|j                  j                  |||       |j                  ||<   M |S )a2  
        Return {parameter_name:parameter.default} for all non-constant
        Parameters.

        Note that a Parameter for which instantiate==True has its default
        instantiated.

        .. deprecated:: 1.12.0
            Use instead `{k:v.default for k,v in p.param.objects().items()}`
        r   )r  r  )r   r?   r   rl   r   r  r  r  )r^  r   rd   r
  r?   s        r7   r  zParameters.defaults]  sz     zz!%!3!3J!?!E!E!GJ~~  

--e1*-M!MMAjM "H rP   c                    | j                   }t        |j                        j                  |      rQt        rt        t              rt	               dz   |z   } t        |j                        j                  ||g|i | yy)z
        Calls the logger returned by the get_logger() function,
        prepending the result of calling dbprint_prefix() (if any).

        See python's logging module for details.
        )rK   z: N)r  rO   rK   isEnabledFordbprint_prefixr  log)r^  r   msgrn   r`   r  s         r7   
__db_printzParameters.__db_printv  sq     '';++,99%@(>":$&-31JK,,-11%JtJrJ ArP   c                     | j                   }|j                  j                         j                         D ]"  \  }}t	        |j
                   d| d|        $ y)z
        Print the values of all this object's Parameters.

        .. deprecated:: 1.12.0
            Use instead `for k,v in p.param.objects().items(): print(f"{p.__class__.name}.{k}={repr(v.default)}")`
        rA   z = N)r   r?   r   rl   r  rK   )r^  r   rK   r   s       r7   print_param_valueszParameters.print_param_values  sN     zz**,224ID#TYYKqc#/0 5rP   c                 :     | j                   t        |g|i | y)z
        Print msg merged with args as a warning, unless module variable
        warnings_as_exceptions is True, then raise an Exception
        containing the arguments.

        See Python's logging module for details of message formatting.
        N)r  r   r^  r  rn   r`   s       r7   r}  zParameters.warning  s     			'3,,,rP   z,Use instead `.param.log(param.MESSAGE, ...)`c                 :     | j                   t        |g|i | y)z
        Print msg merged with args as a message.

        See Python's logging module for details of message formatting.

        .. deprecated:: 1.12.0
            Use instead `.param.log(param.MESSAGE, ...)`
        N)_Parameters__db_printr   r  s       r7   messagezParameters.message  s      	c-4-"-rP   z,Use instead `.param.log(param.VERBOSE, ...)`c                 :     | j                   t        |g|i | y)z
        Print msg merged with args as a verbose message.

        See Python's logging module for details of message formatting.

        .. deprecated:: 1.12.0
            Use instead `.param.log(param.VERBOSE, ...)`
        N)r  r=   r  s       r7   verbosezParameters.verbose  s      	0d0R0rP   z*Use instead `.param.log(param.DEBUG, ...)`c                 :     | j                   t        |g|i | y)z
        Print msg merged with args as a debugging statement.

        See Python's logging module for details of message formatting.

        .. deprecated:: 1.12.0
            Use instead `.param.log(param.DEBUG, ...)`
        N)r  r   r  s       r7   debugzParameters.debug  s      	s.D.2.rP   c                     |t         u r t        rt        d||z  z         t        dz  a | j                  ||g|i | y)a   
        Print msg merged with args as a message at the indicated logging level.

        Logging levels include those provided by the Python logging module
        plus VERBOSE, either obtained directly from the logging module like
        `logging.INFO`, or from parameterized like `param.parameterized.INFO`.

        Supported logging levels include (in order of severity)
        DEBUG, VERBOSE, INFO, WARNING, ERROR, CRITICAL

        See Python's logging module for details of message formatting.
        z	Warning: r   N)r   warnings_as_exceptionsr   warning_countr  )r^  r   r  rn   r`   s        r7   r  zParameters.log  sK     G%cDj 899 q 1d1b1rP   c                    | j                   }t        |t              st        d      |j                  j                  d      j                         D ]  \  }}|j                  j                  |      }t        |d      rK|j                  j                  |j                         |j                  j                  |j                         xt        |d      st        |t              s|j                           y)a  
        Save this instance's state.

        For Parameterized instances, this includes the state of
        dynamically generated values.

        Subclasses that maintain short-term state should additionally
        save and restore that state using _state_push() and
        _state_pop().

        Generally, this method is used by operations that need to test
        something without permanently altering the objects' state.
        z1_state_push is not implemented at the class levelr   _Dynamic_last_state_pushN)r  rX   r  NotImplementedErrorr?   r   rl   r:  rZ   _saved_Dynamic_lastrS   r  _saved_Dynamic_time_Dynamic_timer  r^  r   r  r   r  s        r7   r  zParameters._state_push  s       $.%&YZZ

**:6<<>HE1

..u5Aq)%%,,Q__=%%,,Q__= =)j=.I ?rP   c                    | j                   }t        |t              st        d      |j                  j                  d      j                         D ]  \  }}|j                  j                  |      }t        |d      r?|j                  j                         |_        |j                  j                         |_        lt        |d      syt        |t              s|j                           y)ze
        Restore the most recently saved state.

        See _state_push() for more details.
        z0_state_pop is not implemented at the class levelr   r  
_state_popN)r  rX   r  r  r?   r   rl   r:  rZ   r  r   r  r  r  r  r  s        r7   r  zParameters._state_pop  s       $.%&XYY

**:6<<>HE1

..u5Aq)"#"7"7";";"="#"7"7";";"=<(Z--H ?rP   c           
          | j                   }t        |t              st        d       t	        | j
                  ||||||             S )z
        (Experimental) Pretty printed representation that may be
        evaluated with eval. See pprint() function for more details.
        z,pprint is not implemented at the class level)importsprefixunknown_valuequalify	separator)r  rX   r  r  r   _pprint)r^  r  r  r  r  r  r   s          r7   pprintzParameters.pprint  sR       $.%&TUUZwu}}dGF%2GyZ \ 	\rP   c           	      t   |g }t        t        |            |d d  | j                  }|j                  d      }|j	                  d|z         |j	                  d|d   z         | j
                  j                  t              }| j
                  j                         }	t        t        |       j                        }
d|
j                  vs|
j                  d   dk7  r"t        dt        |       j                   d      |
j                  dd  }|
j                  d|
j                  d t        |
j                          }t!        t#        |
j                  t        |
j                         d  |
j                              }n|g }}| j
                  j%                  d	      t'        t'        |      fd
      }g g g }}}||z   D ]
  }||v r	|dk(  r9|	|   4t)        j*                  d| j,                  j                  z   dz   |	|         rG||	v rt/        |	|   ||g ||      nd }|#|du rt1        | j2                   d|      ||}||v r||	v r||   |	|   k(  r||v r|j	                  |       nJ||v s0t5        |
d      r|
j6                  t5        |
d      r"|
j8                  |j	                  | d|        |j	                  |        |r|dz   nd}||z   |
j:                  rd|
j:                  z  gng z   }|dj=                  | j,                  j                  d|z   |z   j?                  |            z   S )NrA   	import %sr   )r+  r   r  zD.__init__.__signature__' must contain 'self' as its first Parameter.r   r   c                 X    |    j                   t        d       S |    j                   S )Ninf)r  float)rz   r   s    r7   r"  z$Parameters._pprint.<locals>.<lambda>7  s5    (m66> #5\> 4%a=334rP   r  rK   ^z[0-9]+$)r  settingsr  r  Fz: unknown value of varkwkeywordsr  r?  z**%sz{}({}),) r{   r   r   r   rS   r?   r   script_repr_suppress_defaultsr   r}   r  rn   r  r   r  r=  r~   r   r   r  rM  rN  r  r  r   rK   rZ   r  r  varargsr6  r  )r   r  r  r  r  r  modbitschanged_paramsr   rP  rn   posargsro   orderingarglistr  rG  rz   r   	qualifier	argumentsr   s                         @r7   r  zParameters._pprint  s(    ?G#g,'
 ooyy~{3'{47*+**7T*U""$d4j112"diilf&<QtDz2233wxyyyy}==$ii 4#dmm"4!45G#diiT]]);(;(<=t}}MNF"BVGZZ''
3
>"56 (*2r9AI~x F{q	 5$&HHS1H1H-H-RTZ[\T]$^ 01F{ 6!9gfb)6#*,@D  } E)#tyyk1DQE$JKK"*)E V!v+6!9q	3I8G|u%v+4)tzz/E4,$--2K 1#Qug/QE !H #*C#Ir	h&T\\6DLL+@*AWYZ	8??4>>+B+Bc)mTZFZE`E`ajEklllrP   rb   )NNTrV  T)Nr  )r  rA  FTT)r   )r   TFr   )r   TFr   )N <?>Fr?  )[r   r   r   r   r  r  r   rF  r  r   r   r   r  r@  r  r  r  r  r  rd  r  r  r  r  r$  r  r#  r  r  r  r  r*  r  r  r    r  r   r3  r  r  r   rY   r  r  r   rl  rA  r  r   r  r   r(  r-  r/  r  r   r;  rB  rF  r~   rI  rM  r  rQ  r   rY  r:  r_  rb  rd  r9  rU  ru  r  r  r  r  r  r  r  r}  r  r  r  r  r  r  r  staticmethodr  r  r  s   @r7   r  r    sx    Q Q R R M M __N N L L ^^M M N N O O 3 3 __4 4
 ? ?	 0?).c   G G H HT"/&6* A6 = =.6 D,)\K2 A A   H  Vi  j
D j
D <J]^
& _
&-+ -+ -+` ?M`a: b: O]pq) r)& $ CQJ % %P 8FYZ$ [$,  0@*@D(: <('CR)KVH)\RV )\VQH   )*1	*1 *.2!F0B( ESfg: h:&`"D96)XVH4 ]k~ @0K    H  Vi  j	1 j	1- IWjk	. l	. IWjk	1 l	1 GUhi	/ j	/28 6" ?D(*\ >C(*Gm  GmrP   r  c                   |    e Zd ZdZd Zd Zd Zd Zd Zd Z	 e
e	      Z e
e      Zd Z e
e      Zd	 Zd
 Zd Zy)r  a,  
    The metaclass of Parameterized (and all its descendents).

    The metaclass overrides type.__setattr__ to allow us to set
    Parameter values on classes without overwriting the attribute
    descriptor.  That is, for a Parameterized class of type X with a
    Parameter y, the user can type X.y=3, which sets the default value
    of Parameter y to be 3, rather than overwriting y with the
    constant value 3 (and thereby losing all other info about that
    Parameter, such as the doc string, bounds, etc.).

    The __init__ method is used when defining a Parameterized class,
    usually when the module where that class is located is imported
    for the first time.  That is, the __init__ in this metaclass
    initializes the *class* object, while the __init__ method defined
    in each Parameterized class is called for each new instance of
    that class.

    Additionally, a class can declare itself abstract by having an
    attribute __abstract set to True. The 'abstract' attribute can be
    used to find out if a class is abstract or not.
    c                    t         j                  | |||       t               }|D ]5  }t        |t              s|t        |j
                  j                        z  }7 t        t        |            }|| _        | j                  ||       t        |       | _        |j                         D cg c]  \  }}t        |t              r||f }	}}|	D ]  \  }
}| j                  |
|        |j                         D cg c]   \  }}t!        |d      r|||j"                  f" }}}g }|D ]e  \  }}}|j%                  dd      }|j%                  dd      }t'        | d||      }t)        |d      \  }}|sM|j+                  ||d	k(  |||f       g g }t-        |       dd
 ddd
   D ]  }t!        |d      s|j.                  j0                  d   D ]\  t3        | d   d      }t3        |dddi      }t5        fd||z   D              r:|j%                  d      sL|j+                         ^  d||z   i| j.                  _        t6        r| j9                          yyc c}}w c c}}w )a  
        Initialize the class object (not an instance of the class, but
        the class itself).

        Initializes all the Parameters by looking up appropriate
        default values (see __param_inheritance()) and setting
        attrib_names (see _set_names()).
        r  rW   r  Fr  Nra  )rY  r  r   _param__parametersr   c              3   4   K   | ]  }d    |d    k(    yw)r   Nr^   )rc   r!  rj   s     r7   re   z2ParameterizedMetaclass.__init__.<locals>.<genexpr>  s      F4EqCFadN4Es   )r}   r  r   r>  r  r   r  _ClassPrivater{   !_ParameterizedMetaclass__set_namer  r  rl   rX   rY   r  rZ   rW   r3   r  rW  rS   r   r?   r  rh   rk   docstring_signature(_ParameterizedMetaclass__class_docstring)r  rK   r  r  r  r  r   rr   r   r   r
  r?   rQ  	dependersr  r  r   r  r  rX  r[  r\  
_inheritedr   rj   s                           @r7   r  zParameterizedMetaclass.__init__}  sg    	c4. 5D$. C(<(<(M(M$NN   (>N9OP-tU#!+C ,1;;= 3=!Q#Ay1 !f=
 3 !+Ju%%j%8 !+ 5:KKM .M&1a8, AHH%M	 . #,D&%IIgu-Eii	51Gc4!')E!4UE!JD,tUh%6|TU $- 
S>#2&tt,C3 45yy))'2 c!fd37E2BCFF:4EFF		'*%%c* 3 - &z&'89		!!# G3.s   /I!?%I'c                    |j                  dd      }|ct        |      t        urt        d|dt        |       d      |j                  r#|j                  | _        d| j                  _        y|| _        yt        |       ddd   }d}|D ])  }t        |d	      s|j                  j                  s'd} n |s|| _        yy)
a  
        Give Parameterized classes a useful 'name' attribute that is by
        default the class name, unless a class in the hierarchy has defined
        a `name` String Parameter with a defined `default` value, in which case
        that value is used to set the class name.
        rK   NzParameterized class z0 cannot override the 'name' Parameter with type z>. Overriding 'name' is only allowed with a 'String' Parameter.Tr   Fr   )
r3   r}   rH  r   r  rK   r   renamedr   rZ   )r  rK   r  
name_paramclassesfound_renamedr   s          r7   
__set_namez!ParameterizedMetaclass.__set_name  s     YYvt,
!Jv-*4( 366::6F5G HSS 
 !!%--.2##+nTrT*G!M1/0Q5F5F5N5N$(M  ! !rP   c                     t         rt        sy| j                  r| j                  nd}t        |       }|dz   |z   | _        y)z
        Customize the class docstring with a Parameter table if
        `docstring_describe_params` and the `param_pager` is available.
        Nr?  
)docstring_describe_paramsparam_pagerr   )r  class_docstrdescriptions      r7   __class_docstringz(ParameterizedMetaclass.__class_docstring  s8    
 )&)kks{{r!#&"T)K7rP   c                 J    |j                  |       | j                  ||       y rb   )r8  *_ParameterizedMetaclass__param_inheritance)r  r
  r?   s      r7   r  z,ParameterizedMetaclass._initialize_parameter  s"     	$
E2rP   c                 r    	 t        | d| j                  j                  d      z        S # t        $ r Y yw xY w)a  
        Return True if the class has an attribute __abstract set to True.
        Subclasses will return False unless they themselves have
        __abstract set to true.  This mechanism allows a class to
        declare itself to be abstract (e.g. to avoid it being offered
        as an option in a GUI), without the "abstract" property being
        inherited by its subclasses (at least one of which is
        presumably not abstract).
        z_%s__abstractrg  F)rh   r   lstripr  r  s    r7   __is_abstractz$ParameterizedMetaclass.__is_abstract  s:     	3s||/B/B3/GGHH 		s   '* 	66c           	         | j                   j                  r| j                   j                  S t        j                  | j                        t        k7  ryt               g }}t        | j                               D ]  }g }t        |j                  j                               D ]J  \  }}t        |t              s||vs|j                  r)|j                  |       |j                  |       L |j                  |        t        |      D cg c]  }|D ]  }|  }	}}t        j                   |	D cg c]0  }t        j                  |t        j                  j"                        2 c}      x| j                   _        }
|
S c c}}w c c}w )aK  
        For classes with a constructor signature that matches the default
        Parameterized.__init__ signature (i.e. ``__init__(self, **params)``)
        this method will generate a new signature that expands the
        parameters. If the signature differs from the default the
        custom signature is returned.
        N)r   r  r   r  r   r   reversedr  r  r   rl   rX   rY   r  rS   addr  r  )r  processed_kwskeyword_groupsr   keyword_grouprz   rx   grpr   r  r  s              r7   __get_signaturez&ParameterizedMetaclass.__get_signature  sY    ((&&000 S\\*.??(+r~CGGI&CMs||11341a+0Fqzz!((+!%%a( 5 !!-0 ' #+>":I":3SrBSB":I4;4E4EG
 a!2!2!?!?@G
 5 	%	  JG
s   F55F
c                     | j                   S rb   )r  r  s    r7   
_get_paramz!ParameterizedMetaclass._get_param$  s    %%%rP   c                 t   | j                  |      \  }}|rht        |t              sX|| k7  r3t        j                  |      }| |_        t
        j                  | ||       | j                  |   j                  d|       yt
        j                  | ||       t        |t              r| j                  ||       yy)a_  
        Implements 'self.attribute_name=value' in a way that also supports Parameters.

        If there is already a descriptor named attribute_name, and
        that descriptor is a Parameter, and the new value is *not* a
        Parameter, then call that Parameter's __set__ method with the
        specified value.

        In all other cases set the attribute normally (i.e. overwrite
        the descriptor).  If the new value is a Parameter, once it has
        been set we make sure that the value is inherited from
        Parameterized superclasses as described in __param_inheritance().
        N)
r  rX   rY   r   ri   r}   r  r   r!  r  )r  attribute_namer   r  owning_classs        r7   r  z"ParameterizedMetaclass.__setattr__)  s      "%!9!9.!I	,Zi8s" IIi0	"%	  ^I>LL(00e< S6%	*''u= +rP   c           	      D   t        |      }t        j                  |j                        }t	        |d|        |d= d|v rt	        |d|        |d= t        |       ddd   }d}|D ]]  }|j                  j                  |      }t        |t              s/|j                  du rd|_
        t        |      }	t        |	|      r\d}_ |d= i i }}
d}|j                         D ]N  }|D ]  }|j                  j                  |      }|t        ||      s-t        ||      }|j                  |t              }|t        u rX||u r]|t        u r|||<   |s|so n||j                   vrd} n |j                  |t              t        u r'	 |j"                  |   }t'        |      r||
|<   |||<   |dk(  s| j(                  j*                  }|j,                  du r|j/                  |j0                         |j,                  du s$|j0                  |v s4|j3                  |j0                         Q |j5                         D ]P  \  }}t	        |||       |dk7  st        ||      }t7        |      s1t	        ||t9        j8                  |             R |
j5                         D ]  \  }}t	        || ||              |j;                          |s|r*|j<                  	 |j?                  |j<                         yyy# t$        $ r}t%        d|d	|d
      |d}~ww xY w# t@        $ rv}tC        |       d}djE                  d | jF                  dd D              }|s|r
|d| dz  }n|r|s|d| jH                  d| dz  }n	 |d| z  }tK        |      |d}~ww xY w)a  
        Look for Parameter values in superclasses of this
        Parameterized class.

        Ordinarily, when a Python object is instantiated, attributes
        not given values in the constructor will inherit the value
        given in the object's class, or in its superclasses.  For
        Parameters owned by Parameterized classes, we have implemented
        an additional level of default lookup, should this ordinary
        lookup return only `Undefined`.

        In such a case, i.e. when no non-`Undefined` value was found for a
        Parameter by the usual inheritance mechanisms, we explicitly
        look for Parameters with the same name in superclasses of this
        Parameterized class, and use the first such value that we
        find.

        The goal is to be able to set the default value (or other
        slots) of a Parameter within a Parameterized class, just as we
        can set values for non-Parameter objects in Parameterized
        classes, and have the values inherited through the
        Parameterized hierarchy as usual.

        Note that instantiate is handled differently: if there is a
        parameter with the same name in one of the superclasses with
        instantiate set to True, this parameter will inherit
        instantiate=True.
        ri   r  Nr   FTr  r  z of parameter r  r  r  z9 failed to validate its default value on class creation. r  c              3   4   K   | ]  }|j                     y wrb   r   )rc   klasss     r7   re   z=ParameterizedMetaclass.__param_inheritance.<locals>.<genexpr>  s     #R@QuENN@Qr   r   zpThe Parameter is defined with attributes which when combined with attributes inherited from its parent classes (z7) make it invalid. Please fix the Parameter attributes.z)The Parameter type changed between class z  and one of its parent classes (z7) which made it invalid. Please fix the Parameter type.z
Validation failed with:
)&r}   r~   r  r  r  r   r   r3   rX   rY   r  r>  r  rZ   rh   rl  rC  r  r  r  r   r  r  rS   rK   r|  rl   r   r   r  r  r'  r   r"   r  r  r   r   )r  r
  r?   p_typeslotssuperstype_change
superclasssuper_param
super_type	callablesslot_valuesslot_overriddenr   scls	new_param	new_value	old_valuedefault_valrp  r  r   rx   rb  r  parentss                             r7   __param_inheritancez*ParameterizedMetaclass.__param_inheritanceH  s   > ef001 	w$'N E9c*i 3"%
  J$--11*=Kk95&&$.$(!k*Jj&1" ! - !#R;	JJLD
  !MM--j9	$GIt,D#It4	'OOD)<		))+)+(1K% '+5#=#==*.- 0 tY/9<"'"6"6t"<K K(&1IdO(3K%%#&#6#6#G#G ##u,$++EJJ7%%-%**@P2P$++EJJ7_ !d ',,.KD%E4' y E4((+E416 / ")HD"E4E+ *
 	 /emm.G/. /H/U   "x~j^ DD D `  //67 8: :))#RAb@Q#RR"$$+9 -??C !CCLLCS T::A CJKC 4QC88"3'Q.//s1   K<L  <	LLL 	N)A1NNc                     t        |       }|ddd   D ]3  }|j                  j                  |      }t        |t              s/||fc S  y)a  
        Goes up the class hierarchy (starting from the current class)
        looking for a Parameter class attribute param_name. As soon as
        one is found as a class attribute, that Parameter is returned
        along with the class in which it is declared.
        Nr   rU  )r   r   r3   rX   rY   )r  r
  r  r   r  s        r7   r  z+ParameterizedMetaclass.get_param_descriptor  sJ     C.2A

z2I)I. {"  rP   N)r   r   r   r   r  r  r  r  $_ParameterizedMetaclass__is_abstract&_ParameterizedMetaclass__get_signaturer  r  rk  r  r?   r  r  r  r^   rP   r7   r  r  e  s^    .=$~ <	83*< _-M&H& Z E>>f/PrP   r  
    r  c           	          |g }t        | ||||||      }t        t        |            }|rdj                  |      dz   nd}	|	|z   S )aV  
    Variant of pprint() designed for generating a (nearly) runnable script.

    The output of script_repr(parameterized_obj) is meant to be a
    string suitable for running using `python file.py`. Not every
    object is guaranteed to have a runnable script_repr
    representation, but it is meant to be a good starting point for
    generating a Python script that (after minor edits) can be
    evaluated to get a newly initialized object similar to the one
    provided.

    The new object will only have the same parameter state, not the
    same internal (attribute) state; the script_repr captures only
    the state of the Parameters of that object and not any other
    attributes it may have.

    If show_imports is True (default), includes import statements
    for each of the modules required for the objects being
    instantiated. This list may not be complete, as it typically
    includes only the imports needed for the Parameterized object
    itself, not for values that may have been supplied to Parameters.

    Apart from show_imports, accepts the same arguments as pprint(),
    so see pprint() for explanations of the arguments accepted. The
    default values of each of these arguments differ from pprint() in
    ways that are more suitable for saving as a separate script than
    for e.g. pretty-printing at the Python prompt.
    r  z

r?  )r  r{   r   r  )
r   r  r  r  r  r  r  show_importsrepimports_strs
             r7   script_reprr	    sY    > 
gvx)%C 3w< G3?499W%.RKrP   r  r?  c                    |g }t        | t              rt        | |||      }|S t        |       t        v rt        t        |          | |||      }|S t        | t              rd}|S t        | t
              s!t        |       t        u r5t        | t
              r%| j                  j                  ||dz   |||      }|S t        |       }|S )a  
    Pretty printed representation of a parameterized
    object that may be evaluated with eval.

    Similar to repr except introspection of the constructor (__init__)
    ensures a valid and succinct representation is generated.

    Only parameters are represented (whether specified as standard,
    positional, or keyword arguments). Parameters specified as
    positional arguments are always shown, followed by modified
    parameters specified as keyword arguments, sorted by precedence.

    unknown_value determines what to do where a representation cannot be
    generated for something required to recreate the object. Such things
    include non-parameter positional and keyword arguments, and certain
    values of parameters (e.g. some random state objects).

    Supplying an unknown_value of None causes unrepresentable things
    to be silently ignored. If unknown_value is a string, that
    string will appear in place of any unrepresentable things. If
    unknown_value is False, an Exception will be raised if an
    unrepresentable value is encountered.

    If supplied, imports should be a list, and it will be populated
    with the set of imports required for the object and all of its
    parameter values.

    If qualify is True, the class's path will be included (e.g. "a.b.C()"),
    otherwise only the class will appear ("C()").

    Parameters will be separated by a comma only by default, but the
    separator parameter allows an additional separator to be supplied
    (e.g. a newline could be supplied to have each Parameter appear on a
    separate line).

    Instances of types that require special handling can use the
    script_repr_reg dictionary. Using the type as a key, add a
    function that returns a suitable representation of instances of
    that type, and adds the required import statement. The repr of a
    parameter can be suppressed by returning None from the appropriate
    hook in script_repr_reg.
    Nz    )r  r  r  r  r  )
rX   r}   type_script_reprscript_repr_reg_no_script_reprr  r>  r?   r  r  )r   r  r  r  r  r  r  r  s           r7   r  r  4  s    X #ds76(; J 
co	%d3i(WVHE J 
C	) J 
C	'DI,=*SR_B`IIWVF] '}"+  - J IJrP   c           	          g }| D ]  }|j                  t        ||||             ! t        | t              rd\  }}nt        | t              rd\  }}nt
        |dj                  |      z   |z   }|S )N)[])r  r  r  )rS   r  rX   r{   r|   r  r  )		containerr  r  r  r  rC  d1d2r  s	            r7   container_script_reprr  {  su    FfQwvh78  )D!2	Ie	$2!!
388FBC JrP   c               #      K   t         j                  j                  d      x} r| j                   t         j                  j                  d      x}r|j                   y y w)Nrandomznumpy.random)r1   r2   r3   RandomRandomState)r  nprs     r7   r  r    sQ      **v*mmkkoon--s-oo .s   A!A#c                 j    | j                   }| j                  }|j                  d|z         |dz   |z   S )Nr  rA   )r   r   rS   )rb  r  r  r  rK   modules         r7   function_script_reprr    s3    ;;D]]FNN;v%&#:d?rP   c                 p    | j                   }|dk7  r|j                  d|z         |dz   | j                  z   S )N__builtin__r  rA   )r   rS   r   )type_r  r  r  r  s        r7   r  r    s9    F}{6)*#:enn$$rP   c                 h    t        |       |dz
  kD  r| d|dz
   dz   n| }t        j                  |      S )z2Return HTML-safe truncated version of given stringr+  Nz..)r=  htmlr
   )str_maxlenr  s      r7   truncater$    s7    ),TfQh)?4&(t#dC;;srP   c                 z   t        |t              s!t        |      t        u r-t        |t              r|j                  j                  d      }n2t        |d      r|j                         }nt        t        |      |      }t        |d      r|j                  d}nQt        |d      rY|j                  \  }}|j                  \  }	}
|dn|	rdndt        |      z   }|dn|
rd	nd
t        |      z   }||r|rdndz   |z   }nt        |j                        }nt        |d      r?|j                  r3dj                  t        t        t        |j                                    }nt        |d      rTt        |j                   t"              r#dj                  d |j                   D              }nB|j                   j$                  }n+t        |d      r|j&                  d|j&                   d}nd}|j(                  rdj                  d d|fD              }n&|j*                  rdj                  d d|fD              }t-        |dd      rdj                  d d|fD              }|j.                  r'dt1        |j.                  j3                                dnd}d| d|  d| d|j4                  j$                   d | d!S )"z?HTML representation for a single Parameter object and its valueF)r  r  boundsr?  inclusive_boundsz>=>z<=<r  r   r   z | c              3   4   K   | ]  }|j                     y wrb   r  )rc   r  s     r7   re   z"_get_param_repr.<locals>.<genexpr>  s     Ar   rI  zregex(r  r  c              3   &   K   | ]	  }|s|  y wrb   r^   rc   r  s     r7   re   z"_get_param_repr.<locals>.<genexpr>  s     G%AQ!%A   z<i>read-only</i>c              3   &   K   | ]	  }|s|  y wrb   r^   r,  s     r7   re   z"_get_param_repr.<locals>.<genexpr>       F%@A!%@r-  z<i>constant</i>r  c              3   &   K   | ]	  }|s|  y wrb   r^   r,  s     r7   re   z"_get_param_repr.<locals>.<genexpr>  r/  r-  z<i>nullable</i>z) class="param-doc-tooltip" data-tooltip=""z(<tr>  <td><p style="margin-bottom: 0px;"z:</p></td>  <td style="max-width: 200px; text-align:left;">z$</td>  <td style="text-align:left;">z%</td>  <td style="max-width: 300px;">z</td></tr>
)rX   r  r}   r>  r?   r  rZ   r$  r  r&  r'  r   r   r  r{   mapr   r|   r   rI  r  r   rh   r  r
   rL  r  )r  r   r   vallendoclenr   range_blbuiliulbubtooltips                 r7   _get_param_reprr=    sd   #}%$s)t*;
3P]@^		%%5%1	m	$!cF+q(88FQ)*HHEBr&&EBrzs2w'FBzs2w'FB2"4"5:F!((^F	I	1994D!)) 456	H	ahh&ZZAAAFXX&&F	G	!4!''!$zzG&8&%AGG	
F&7%@FFq,&F&7%@FFVWV[V[9&:O9PPQRacG//6iq ><<A7 C**+++*>*>)? @++1( 3		rP   c                 8    t         t              r j                  }|j                  dz   }d}n }|j                  }d}d}|rdnd} j                  j                         j                         }dj                   fd|D              }d| d	| d
| d| d| dS )z.HTML representation for a Parameterized object()ValueDefaulta  
.param-doc-tooltip{
  position: relative;
  cursor: help;
}
.param-doc-tooltip:hover:after{
  content: attr(data-tooltip);
  background-color: black;
  color: #fff;
  border-radius: 3px;
  padding: 10px;
  position: absolute;
  z-index: 1;
  top: -5px;
  left: 100%;
  margin-left: 10px;
  min-width: 250px;
}
.param-doc-tooltip:hover:before {
  content: "";
  position: absolute;
  top: 50%;
  left: 100%;
  margin-top: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: transparent black transparent transparent;
}
z openr?  c              3   X   K   | ]!  \  }}t        ||j                  |          # y wrb   )r=  r?   )rc   r  r   r   s      r7   re   z+_parameterized_repr_html.<locals>.<genexpr>  s.      5'383 'sC>'3s   '*z<style>z</style>
<details z<>
 <summary style="display:list-item; outline:none;">
  <tt>z</tt>
 </summary>
 <div style="padding-left:10px; padding-bottom:5px;">
  <table style="max-width:100%; border:1px solid #AAAAAA;">
   <tr><th style="text-align:left;">Name</th><th style="text-align:left;">z?</th><th style="text-align:left;">Type</th><th>Range</th></tr>
z
  </table>
 </div>
</details>
)rX   r  r  rK   r?   r   rl   r  )	r   r  r   titlevalue_fieldtooltip_cssopenstrr'  contentss	   `        r7   r  r    s    !]#kk4K: g2G77>>#))+Lww 5'35 5H + 9  U VaTa  bb* ,		,rP   c                   6    e Zd ZdZg dZ	 	 	 	 	 ddZd Zd Zy)r  a#  
    parameters_state: dict
        Dict holding some transient states
    disable_instance_params: bool
        Whether to disable instance parameters
    renamed: bool
        Whethe the class has been renamed by a super class
    params: dict
        Dict of parameter_name:parameter
    r  r  r  r   r  r  r  Nc                     |ddg g d}|| _         || _        || _        |i n|| _        d| _        d | _        |g | _        y || _        y NF)r   r  r   r   rI  )r   r  r  r  r  r   s         r7   r  z_ClassPrivate.__init__>  sh     #$ 	  !1'>$"Nb &6&>DTrP   c                 V    | j                   D ci c]  }|t        | |       c}S c c}w rb   r   rh   r:  s     r7   r;  z_ClassPrivate.__getstate__U  *    6:nnEndgdD))nEEE   &c                 N    |j                         D ]  \  }}t        | ||        y rb   r=  r>  s       r7   r@  z_ClassPrivate.__setstate__X  "    KKMDAqD!Q "rP   )NFNFNr   r   r   r   r   r  r;  r@  r^   rP   r7   r  r  (  s0    	I  %U.F rP   r  c                   <    e Zd ZdZg dZ	 	 	 	 	 	 	 	 ddZd Zd Zy)r(  as  
    initialized: bool
        Flag that can be tested to see if e.g. constant Parameters can still be set
    parameters_state: dict
        Dict holding some transient states
    dynamic_watchers: defaultdict
        Dynamic watchers
    ref_watchers: list[Watcher]
        Watchers used for internal references
    params: dict
        Dict of parameter_name:parameter
    refs: dict
        Dict of parameter name:reference
    watchers: dict
        Dict of dict:
            parameter_name:
                parameter_attribute (e.g. 'value'): list of `Watcher`s
    values: dict
        Dict of parameter name: value
    )r  r  r  r   r%  r   r  r   r   r   r  Nc	                    || _         |g n|| _        t               | _        |ddg g d}g | _        i | _        || _        |t        t              n|| _	        |i n|| _
        |i n|| _        |i n|| _        |i | _        y || _        y rK  )r  r  r   r   r  r%  r  r   r{   r  r   r   r   r   )	r   r  r  r  r   r   r   r   r  s	            r7   r  z_InstancePrivate.__init__  s     '&6&>DTu#$ 	   05E5MD 1Sc"Nb,BD	&.H"NbrP   c                 V    | j                   D ci c]  }|t        | |       c}S c c}w rb   rM  r:  s     r7   r;  z_InstancePrivate.__getstate__  rN  rO  c                 N    |j                         D ]  \  }}t        | ||        y rb   r=  r>  s       r7   r@  z_InstancePrivate.__setstate__  rQ  rP   )FNNNNNNNrR  r^   rP   r7   r(  r(  ]  s8    *I  7<F rP   r(  c                   h    e Zd ZdZ eddd      Zd Zed        Zd Z	d	 Z
 e       d
        Zd Zy)r  a  
    Base class for named objects that support Parameters and message
    formatting.

    Automatic object naming: Every Parameterized instance has a name
    parameter.  If the user doesn't designate a name=<str> argument
    when constructing the object, the object will be given a name
    consisting of its class name followed by a unique 5-digit number.

    Automatic parameter setting: The Parameterized __init__ method
    will automatically read the list of keyword parameters.  If any
    keyword matches the name of a Parameter (see Parameter class)
    defined in the object's class or any of its superclasses, that
    parameter in the instance will get the value given as a keyword
    argument.  For example:

    >>> class Foo(Parameterized):
    ...     xx = Parameter(default=1)

    >>> foo = Foo(xx=20)

    in this case foo.xx gets the value 20.

    When initializing a Parameterized instance ('foo' in the example
    above), the values of parameters can be supplied as keyword
    arguments to the constructor (using parametername=parametervalue);
    these values will override the class default values for this one
    instance.

    If no 'name' parameter is supplied, self.name defaults to the
    object's class name with a unique number appended to it.

    Message formatting: Each Parameterized instance has several
    methods for optionally printing output. This functionality is
    based on the standard Python 'logging' module; using the methods
    provided here, wraps calls to the 'logging' module's root logger
    and prepends each message with information about the instance
    from which the call was made. For more information on how to set
    the global logging level and change the default message prefix,
    see documentation for the 'logging' module.
    NTz+
        String identifier for this object.)r  r   r  c                 8   t        | j                  t              s.t        t        |       j                  j                        | _        | j
                  j                  j                  | j                  j                  k(  r| j
                  j                           | j
                  j                  di |\  }}t        dz  ad| j                  _        | j
                  j                  |       | j
                  j                  d       || j                  _        y )Nr  r   T)r  r^   )rX   r   r(  r}   r  r?   rK   r  r  r   r  r  r  r  r  r*  r   )r   r   r   r[  s       r7   r  zParameterized.__init__  s     $..0@A#3!%d!;!;!L!L$D  ::??""dnn&=&==JJ%%'-TZZ--77
d+/(

t$

T*$(!rP   c                 0    t        | j                  |       S )a>  
        The `.param` namespace for `Parameterized` classes and instances.

        This namespace provides access to powerful methods and properties for managing
        parameters in a `Parameterized` object. It includes utilities for adding parameters,
        updating parameters, debugging, serialization, logging, and more.

        User Guide
        ----------
        For more details on parameter objects and instances, see:
        https://param.holoviz.org/user_guide/Parameters.html#parameter-objects-and-instances

        Examples
        --------
        Basic usage of `.param` in a `Parameterized` class:

        >>> import param
        >>>
        >>> class MyClass(param.Parameterized):
        ...     value = param.Parameter()
        >>>
        >>> my_instance = MyClass(value=0)

        Access the `value` parameter of `my_instance`:

        >>> my_instance.param.value  # the Parameter instance

        Note that this is different from the current `value` of `my_instance`:

        >>> my_instance.value  # the current parameter value
        0

        r   )r  r  r   s    r7   r?   zParameterized.param  s    F $..t44rP   c                 x    | j                   j                         }t        |       D ]  }t        | |      ||<    |S )z
        Save the object's state: return a dictionary that is a shallow
        copy of the object's __dict__ and that also includes the
        object's __slots__ (if it has any).
        )r   r   r   rh   )r   r?  r   s      r7   r;  zParameterized.__getstate__  s<     ""$&t,D!$t,E$K - rP   c                 2   t        |       j                  j                  }t        |      | _        d| j                  _        |j                  dd      }|t        |      }|j                  r|j                  }|j                         D ]  \  }}|j                         D ]  \  }}g }	|D ]  }
t        |
      }|
j                  | |d<   |
j                  }t        |d      rt        | |j                        |d<   n0t        |      |
j                  u rt        | |j                         |d<   |	j#                  t%        |         |	||   |<     |j'                  dd       |j                         D ]  \  }}t)        | ||        d	| j                  _        y)
z
        Restore objects from the state dictionary to this object.

        During this process the object is considered uninitialized.
        r  Fr   Nr   r  r+  r?   T)r}   r   r  r(  r  r3   r   rl   r{   rT  rb  rZ   r  r  r   rh   r   rS   r  r   r  )r   r?  r  r   param_watchersr   r  r   r   new_watchersr  watcher_argsrb  rK   r   s                  r7   r@  zParameterized.__setstate__)  st     :55FF/AQR+0())$5t<".@PQO ##,55N*0025&+kkmND(#%L#+'+G}"<<3.2LO$ZZ"27.7b>N>N.OLO-b1W\\A.5dBKK.HLO$++G\,BC $, /;N1%d+ '4 3 			'4 ++-JDDe$ (+/(rP   c                    	 | j                   j                         j                         D cg c]  \  }}| d| }}}| j                  j
                  dz   dj                  |      z   dz   S c c}}w # t        $ r g }Y Aw xY w)a  
        Provide a nearly valid Python representation that could be used to recreate
        the item with its parameters, if executed in the appropriate environment.

        Returns 'classname(parameter1=x,parameter2=y,...)', listing
        all the parameters of this object.
        r  r  r  r  )r?   r   rl   r   r  r   r  )r   rK   r   r  s       r7   r   zParameterized.__repr__P  s    	)-):):)<)B)B)DF)DID#  &#))D  F ~~&&,tyy/BBSHH	F 	H	s!   +A5 A/A5 /A5 5BBc                 P    d| j                   j                   d| j                   dS )zCReturn a short representation of the name and class of this object.r)  r  r(  )r  r   rK   r   s    r7   r  zParameterized.__str__`  s&    4>>**+1TYYKq99rP   )r   r   r   r   rH  rK   r  r  r?   r;  r@  r    r   r  r^   rP   r7   r  r    s`    (T $ 4. /D)2 "5 "5L(%0N I I:rP   r  c                      t        d       t        d       t        d       t        d       t        t              } | j                  d        | D ]  }|j	                           t        d       y)z5Print the default values for all imported Parameters.O_______________________________________________________________________________r?  z3                           Parameter Default Valuesc                     | j                   S rb   r  )xs    r7   r"  z*print_all_param_defaults.<locals>.<lambda>l  s    ajjrP   r  N)r  r%   r  rS  r  )r  r   s     r7   print_all_param_defaultsre  e  sZ    	
[\	"I	
?@	"I-(GLL(L)	  	
[\rP   c                   V    e Zd ZdZddZd Zd Zd Zd Zd Z	d Z
dd
Zd Zd Zd Zy	)ParamOverridesz
    A dictionary that returns the attribute of a specified object if
    that attribute is not present in itself.

    Used to override the parameters of an object.
    c                     || _         t        j                  | |       |r| j                  |      | _        y| j                  |       y)a  

        If allow_extra_keywords is False, then all keys in the
        supplied dict_ must match parameter names on the overridden
        object (otherwise a warning will be printed).

        If allow_extra_keywords is True, then any items in the
        supplied dict_ that are not also parameters of the overridden
        object will be available via the extra_keywords() method.
        N)_overriddenr~   r  _extract_extra_keywords_extra_keywords_check_params)r   
overriddenr  allow_extra_keywordss       r7   r  zParamOverrides.__init__  s>      &d5!!%!=!=e!DD u%rP   c                     | j                   S )z
        Return a dictionary containing items from the originally
        supplied `dict_` whose names are not parameters of the
        overridden object.
        )rk  r   s    r7   extra_keywordszParamOverrides.extra_keywords  s     ###rP   c                 Z    | D ci c]  }|| j                         vs|| |    c}S c c}w )z
        Return a dictionary containing items from the originally
        supplied `dict_` whose names are parameters of the
        overridden object (i.e. not extra keywords/parameters).
        )rp  r   r  s     r7   param_keywordszParamOverrides.param_keywords  s4     +/S$3#T=P=P=R2RT#Y$SSSs   ((c                 .    t        | j                  |      S rb   )rh   ri  r  s     r7   __missing__zParamOverrides.__missing__  s    t''--rP   c                 ^    t         j                  |       dt        | j                        z  z   S )Nz overriding params from %s)r~   r   r  ri  r   s    r7   r   zParamOverrides.__repr__  s'    }}T"#?TEUEU@V#VVVrP   c                 $    | j                  |      S rb   )r  r  s     r7   r  zParamOverrides.__getattr__  s     %%rP   c                 z    |j                  d      s| j                  ||       y t        j                  | ||       y )Nrg  )r  __setitem__r~   r  )r   rK   r   s      r7   r  zParamOverrides.__setattr__  s2     s#T#&T$s+rP   Nc                 0    	 | |   S # t         $ r |cY S w xY wrb   )r  )r   r  r  s      r7   r3   zParamOverrides.get  s%    	9 	N	s    c                 R    || j                   v xs || j                  j                  v S rb   )r   ri  r?   rr  s     r7   r  zParamOverrides.__contains__  s'    dmm#Dsd.>.>.D.D'DDrP   c                     t        | j                  j                        }|D ]#  }||vs| j                  j                  d|       % y)zx
        Print a warning if params contains something that is not a
        Parameter of the overridden object.
        z''%s' will be ignored (not a Parameter).N)r{   ri  r?   r}  )r   r   overridden_object_paramsitems       r7   rl  zParamOverrides._check_params  sC    
 $((8(8(>(>#? D33

""#LTR rP   c                     i }t        | j                  j                        }|j                         D ]  \  }}||vs|||<    |S )zk
        Return any items in params that are not also
        parameters of the overridden object.
        )r{   ri  r?   rl   )r   r   rp  r}  rK   r   s         r7   rj  z&ParamOverrides._extract_extra_keywords  sO    
 #'(8(8(>(>#? ID#33%(t$ (
 rP   r  rb   )r   r   r   r   r  rp  rs  ru  r   r  r  r3   r  rl  rj  r^   rP   r7   rg  rg  w  sB    &0$T.W&,ESrP   rg  c                 ,    t         j                  |       S rb   )r  r  r  s    r7   _new_parameterizedr    s      %%rP   c                   H    e Zd ZdZdZd Zed        Zd Zd Z	d Z
	 	 d
d	Zy)ParameterizedFunctiona@  
    Acts like a Python function, but with arguments that are Parameters.

    Implemented as a subclass of Parameterized that, when instantiated,
    automatically invokes __call__ and returns the result, instead of
    returning an instance of the class.

    To obtain an instance of this class, call instance().
    Tc                 4    | j                   j                  dz   S )Nr?  )r  r   r   s    r7   r  zParameterizedFunction.__str__  s    ~~&&t++rP   c                 X   t        | t              r| }nJ|}| j                  j                         }|j	                  |       |j                  d       | j                  }t        j                  |      }t        j                  |fi | d|v r|d   |_
        |S | j                  |_
        |S )zs
        Return an instance of this class, copying parameters from any
        existing instance provided.
        rK   )rX   r  r?   r   rA  r   r  r  r  r  r   rK   )r  r   r   r   rT  s        r7   r   zParameterizedFunction.instance  s     {#9:CA &&--/FMM!JJv''C""3't-f-VfVndm /:.>.>dmrP   c                     | j                         }|j                  j                  | j                          |j                  |i |S rb   )r   r?   r  r   __call__)r   rn   r   rT  s       r7   r  zParameterizedFunction.__new__  s:     

V__-t}}d,V,,rP   c                     t        d      )Nz#Subclasses must implement __call__.)r  )r   rn   r`   s      r7   r  zParameterizedFunction.__call__  s    !"GHHrP   c                 T    t         j                  |       }t        | j                  f|fS rb   )r  r;  r  r  )r   r?  s     r7   
__reduce__z ParameterizedFunction.__reduce__  s*     &2248
 #DNN#4U;;rP   Nc                     | j                   j                  |||||      }| j                  j                  }|j	                  d|z  d|z        S )zv
        Same as self.param.pprint, except that X.classname(Y
        is replaced with X.classname.instance(Y
        )r  r  r  z.%s(z.%s.instance()r?   r  r  r   r  )r   r  r  r  r  r  r   r  s           r7   r  zParameterizedFunction._pprint!  sV     JJgf,9&-	  C ..))	yy	)/)*CDDrP   )Nr  r  Fr?  )r   r   r   r    _ParameterizedFunction__abstractr  r  r   r  r  r  r  r^   rP   r7   r  r    sG     J,  (-I< CH)+
ErP   r  c                   R    e Zd ZdZ edd      Z edd      Z ei d      Zd Zy)	default_label_formatterzIDefault formatter to turn parameter names into appropriate widget labels.Tz8
        Whether or not the label should be capitalized.)r  r  zC
        Whether or not underscores should be replaced with spaces.z
        Allows custom labels to be specified for specific parameter
        names using a dictionary where key is the parameter name and the
        value is the desired label.c                     || j                   v r| j                   |   S | j                  r|j                  dd      }| j                  r|d d j	                         |dd  z   }|S )Nrg  r  r   )	overridesreplace_underscoresr  
capitalizer   )r   r  s     r7   r  z default_label_formatter.__call__<  s_    DNN">>%((##MM#c*E??"1IOO%ab	1ErP   N)	r   r   r   r   rY   r  r  r  r  r^   rP   r7   r  r  .  sD    S4 .; <J $D 7F G " +' (I
rP   r  c                   ,    e Zd ZdZddZddZd Zd Zy)	overridable_propertyz
    The same as Python's "property" attribute, but allows the accessor
    methods to be overridden in subclasses.

    .. deprecated:: 2.0.0
    Nc                 t    t        j                  dt        d       || _        || _        || _        || _        y )Nz)overridable_property has been deprecated.r+  )r  r-  r.  )r1  r2  r3  fgetfsetfdelr   )r   r  r  r  r  s        r7   r  zoverridable_property.__init__[  s5    ?(	

 			rP   c                    || S | j                   t        d      | j                   j                  dk(  s| j                   j                  s| j                  |      S  t        || j                   j                               S )Nzunreadable attribute<lambda>)r  r  r   rh   )r   r   r  s      r7   r	  zoverridable_property.__get__f  sj    ;K99 !78899+4993E3E99S>!373		 2 2355rP   c                    | j                   t        d      | j                   j                  dk(  s| j                   j                  s| j                  ||       y  t        || j                   j                        |       y )Nzcan't set attributer  )r  r  r   rh   )r   r   r   s      r7   r!  zoverridable_property.__set__p  s_    99 !67799+4993E3EIIc5!,GC++,U3rP   c                     | j                   t        d      | j                   j                  dk(  s| j                   j                  s| j                  |       y  t        || j                   j                                y )Nzcan't delete attributer  )r  r  r   rh   r3  s     r7   r4  zoverridable_property.__delete__x  sZ    99 !9::99+4993E3EIIcN,GC++,.rP   )NNNNrb   )r   r   r   r   r  r	  r!  r4  r^   rP   r7   r  r  N  s    	64/rP   r  rb   r  r  r  )z...)r   NN)   )r  (   )r   r  r   r/   r.   r!  r   rC   rz  r|  rM  r1   r  rD  r1  r   collectionsr   r   r   	functoolsr   r   r	   r
   	itertoolsr   r   r   r   r   
contextlibr   r   r   r   r   r   r?  r   _utilsr   r   r3  r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   ipythonr'   r(   r*   r  ModuleNotFoundErrorr8   r<   r=   addLevelNamerB   rO   r  r  r  r  r  rR   rU   r\   rs   rw   r   r   r   rl  r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r%  r   r4  rB  rR  rW  ri  rq  rs  r~  r  r  r  rV  r  r  r  _Watcherr  r}   r  r  rY   rH  rQ  rd  rn  r  r  r  r  r	  r  r  r  r  r  r  r{   r|   r  r$  r=  r  r  r(  r  re  r~   rg  r  r  r  r  r  r^   rP   r7   <module>r     s           	 
    " < < , ,   + * % 9 9     * =+Q 40 'K    
 (   Wi ( 
@(       
3%"0 D
   L	 - -$ 7 7" ;I\]  ^
 7 7$ 4 4    - -"( 	' ,- .4 ,- . 8 8*5$$0 T Tn.&:4.4 '.tdUY   'td 

 	756 	 	723 
	 	7F# 	 	7<= 	* i!fg-*h -*d&3 &3RA$1 A$HR	  R	 l6.Y 6.r- -*#&F FR $`m `mF3WT W@ #  "(RDD(X Hr?F &  % . .  4  3l7z2  2 jG  G T{:4 {:|
]$jT j\&BEM BEJ3 0 *0/ 0/_P  +**+s   1M MM