
    !LeqB                     @   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mZ d dlmZ d dlmZ d dlmZ d dlmZ d dl mZ  ej         ej        dej        j                   ej        d	ej        j                  g          Z G d
 de          Z G d dee          Z G d dee          Z G d dee           Z!defdZ"d Z#d4dZ$d Z%d Z&d5dZ'd Z(d Z)d fdZ*d Z+d Z,d  Z-d! Z. e"            d"             Z/ e"            d#             Z0 e"            d$             Z1d% Z2 e"            d&             Z3d5d'Z4 e"            d5d(            Z5d6d)Z6d* Z7d+ Z8d, Z9d- Z:d. Z;d/ Z< e"            d0             Z=d1 Z>ed2             Z?d3 Z@dS )7    N)defaultdictOrderedDict)contextmanager)Real)dedent)	get_ident)abcselfparamsc                       e Zd ZdZdS )ParamWarningzBase Param WarningN__name__
__module____qualname____doc__     ,lib/python3.11/site-packages/param/_utils.pyr   r      s        r   r   c                       e Zd ZdZdS )ParamPendingDeprecationWarningzParam PendingDeprecationWarning

    This warning type is useful when the warning is not meant to be displayed
    to REPL/notebooks users, as DeprecationWarning are displayed when triggered
    by code in __main__ (__name__ == '__main__' in a REPL).
    Nr   r   r   r   r   r      s           r   r   c                       e Zd ZdZdS )ParamDeprecationWarningz_Param DeprecationWarning

    Ignored by default except when triggered by code in __main__
    Nr   r   r   r   r   r   $              r   r   c                       e Zd ZdZdS )ParamFutureWarningz/Param FutureWarning

    Always displayed.
    Nr   r   r   r   r   r   +   r   r   r    c                       fd}|S )Nc                 L     t          j                    fd            }|S )z@Internal decorator used to mark functions/methods as deprecated.c                      j         d}r?t                    }|                                                    dd          }|dz   |z   }t	          j        |d            | i |S )Nz= has been deprecated and will be removed in a future version.
    )category
stacklevel)r   r   stripreplacewarningswarn)argskwargsmsgem	extra_msgfuncwarning_cats       r   innerz-_deprecated.<locals>.decorator.<locals>.inner5   s~    ]cccC %I&&XXZZ''c22Ci"nM#BBBB4((((r   	functoolswraps)r/   r1   r.   r0   s   ` r   	decoratorz_deprecated.<locals>.decorator3   sC    				) 	) 	) 	) 	) 	) 
		) r   r   )r.   r0   r5   s   `` r   _deprecatedr6   2   s*          r   c                     t          j                   }g g |j                                        D ]s\  }}|j        t           j        j        t           j        j        fv r                    |           D|j        t           j        j	        k    r                    |           tt          j                    fd            }|S )a   Internal decorator for methods that issues warnings for positional arguments
    Using the keyword-only argument syntax in pep 3102, arguments after the
    ``*`` will issue a warning when passed as a positional argument.
    Adapted from scikit-learn
    c                     j                             d          d         }t          |           t                    z
  }|dk    rd                    d |                   }t	          j        d| d| dt          d           t          d |         | | d                    }|                    d	 |D                         | d |          i |S  | i |S )
N.r   , z	Passing 'z&' as positional argument(s) to 'param.z{' has been deprecated since Param 2.0.0 and will raise an error in a future version, please pass them as keyword arguments.r#   )r%   c                     i | ]\  }}||	S r   r   ).0nameargs      r   
<dictcomp>z=_deprecate_positional_args.<locals>.inner.<locals>.<dictcomp>b   s    ???s4???r   )	r   splitlenjoinr(   r)   r   zipupdate)	r*   r+   r=   n_extra_args
extra_argszip_argsr/   kwonly_argspos_or_kw_argss	         r   r1   z)_deprecate_positional_args.<locals>.innerR   s    &&s++A.4yy3~#6#66!;}}#=>>JM9J 9 9d 9 9 9 /    ;}}5t\MNN7KLLHMM??h???@@@4n}n-8888tT$V$$$r   )inspect	signature
parametersitemskind	ParameterPOSITIONAL_OR_KEYWORDPOSITIONAL_ONLYappendKEYWORD_ONLYr3   r4   )r/   rK   r=   paramr1   rH   rI   s   `    @@r   _deprecate_positional_argsrU   B   s     !$''INK +1133 % %e:'+A7CTCdeee!!$''''Z7,999t$$$_T% % % % % % %* Lr   ...c                       fd}|S )zGDecorator to make a repr function return fillvalue for a recursive callc                 6     t                       fd}|S )Nc                     t          |           t                      f}|v rS                     |           	  | g|R i |}                    |           n#                     |           w xY w|S N)idr   adddiscard)r
   r*   r+   keyresult	fillvaluerepr_runninguser_functions        r   wrapperz=_recursive_repr.<locals>.decorating_function.<locals>.wrapperr   s    T((IKK'Cl""  S!!!*&t=d===f==$$S))))$$S))))Ms   A A4)set)rb   rc   ra   r`   s   ` @r   decorating_functionz,_recursive_repr.<locals>.decorating_functiono   s8    uu		 		 		 		 		 		 		 r   r   )r`   re   s   ` r   _recursive_reprrf   l   s$         r   c                 8    t          j        d| z   dz   |          S )N^z	[0-9]{5}$)rematch)
class_nameinstance_names     r   _is_auto_namerm      s    8C
N;.>>>r   c                     t          j                    }|D ];}t          j        d| z   dz   |j                  }|r|                    d          c S <dS )z
    Go up the stack and attempt to find a Parameter declaration of the form
    `pname = param.Parameter(` or `pname = pm.Parameter(`.
    z^(\S+)\s*=\s*(param|pm)\.z\(   N)	tracebackextract_stackri   rj   linegroup)pclassstackframerj   s       r   _find_pnamerw      sl    
 #%%E " "5>F
SS 	";;q>>!!!	"" "r   c                     ddl m} t          |           j        }| j        =t          | j                  |u r| j        j        }nt          | j                  j        }nd}| j        }g }|r|                    d|d           |                    | d           |r#|r| d| }n|}|                    |           n9	 t          |          }|r|                    |           n# t          $ r Y nw xY wd	                    |          S )	a	  
    Generate an error prefix suitable for Parameters when they raise a validation
    error.

    - unbound and name can't be found: "Number parameter"
    - unbound and name can be found: "Number parameter 'x'"
    - bound parameter: "Number parameter 'P.x'"
    r   )ParameterizedMetaclassNz
Attribute z ofz
 parameterr9   r"   )
param.parameterizedry   typer   ownerr=   rR   rw   	ExceptionrB   )	parameter	attributery   rt   pownerpnameoutdescs           r   _validate_error_prefixr      sT    ;:::::)__%F"	  $:::_-FF)/**3FFNE
C 2

0	000111JJ&$$$%%%  	&&u&&DDD

d;	''E )

e<((( 	 	 	D	88C==s   'C+ +
C87C8c                 ~    t          t          |           t          j        t          j        t          j        f          S )zTTrue for mutable containers, which typically need special handling when being copied)
issubclassr{   r	   MutableSequence
MutableSetMutableMapping)values    r   _is_mutable_containerr      s'    d5kkC$7I[#\]]]r   c                 X    |                                  }|                    |           |S )zR
    Small utility to update a copy of a dict with the provided keyword args.
    )copyrD   )
dictionaryr+   ds      r   _dict_updater      s*     	AHHVHr   c                     | S rZ   r   xs    r   <lambda>r      s    ! r   c                     t          t                    }| D ]&}| ||                                       |           '|                                S )zD
    Groupby implementation which does not require a prior sort
    )r   listrR   rM   )lr^   r   items       r   full_groupbyr      sQ     	DA " "	##d))D!!!!7799r   c                     t          t          d          sdS ddl}	 t          j        |           p|                    |           S # t
          $ r Y dS w xY w)zE
    Whether the function is an asynchronous coroutine function.
    iscoroutinefunctionFr   N)hasattrrJ   asyncioisasyncgenfunctionr   AttributeError)functionr   s     r   r   r      sw     7122 uNNN&x00 2''11	
    uus   (A 
AAc              #      K   | D ]It          fdt          t          t          fD                       rt	                    E d{V  EV  JdS )a-  
    Flatten an arbitrarily nested sequence.

    Inspired by: pd.core.common.flatten

    Parameters
    ----------
    line : sequence
        The sequence to flatten

    Notes
    -----
    This only flattens list, tuple, and dict sequences.

    Returns
    -------
    flattened : generator
    c              3   8   K   | ]}t          |          V  d S rZ   )
isinstance)r<   tpelements     r   	<genexpr>zflatten.<locals>.<genexpr>   s-      EE2z'2&&EEEEEEr   N)anyr   tupledictflatten)rr   r   s    @r   r   r      s|      &   EEEE$t1DEEEEE 	w''''''''''MMMM	 r   c                 F     t          j                    fd            }|S )z8
    Decorator for decorators that accept arguments
    c                        fdS )Nc                      | gR i S rZ   r   )actual_fr*   fr+   s    r   r   z.accept_arguments.<locals>._f.<locals>.<lambda>  s!    ( <T < < <V < < r   r   )r*   r+   r   s   ``r   _fzaccept_arguments.<locals>._f   s    <<<<<<<r   r2   )r   r   s   ` r   accept_argumentsr      s8     _Q= = = = =Ir   c                 8    t          |           r
 |             S | S )z
    A helper function that produces an actual parameter from a stored
    object: if the object is callable, call it, otherwise return the
    object.
    )callable	value_objs    r   _produce_valuer     s&     	 y{{r   c                      t          |           S )z
    A helper function that produces an actual parameter from a stored
    object: if the object is callable, call it, otherwise return the
    object.

    .. deprecated:: 2.0.0
    )r   r   s    r   produce_valuer     s     )$$$r   c                      t          |           S )z
    Safely casts any object to unicode including regular string
    (i.e. bytes) types in python 2.

    .. deprecated:: 2.0.0
    )strobjs    r   
as_unicoder     s     s88Or   c                     t           j        j        dk    ot           j        j        dk    }t           j        j        dk    p|}t	          | t
                    p|ot	          | t                    S )z
    Predicate checking for ordered dictionaries. OrderedDict is always
    ordered, and vanilla Python dictionaries are ordered for Python 3.6+

    .. deprecated:: 2.0.0
          )sysversion_infomajorminorr   r   r   )r   py3_ordered_dictsvanilla_odictss      r   is_ordered_dictr   +  s`     )/14W3;K;QUV;V&,q0F5FNa+''SN,Rz!T?R?RSr   c                     t          | t          j        j                  rt	          |           S t          | t          j        j                  r+t	          d |                                 D                       S | S )a~  
    Return a hashable version of the given object x, with lists and
    dictionaries converted to tuples.  Allows mutable objects to be
    used as a lookup key in cases where the object has not actually
    been mutated. Lookup will fail (appropriately) in cases where some
    part of the object has changed.  Does not (currently) recursively
    replace mutable subobjects.
    c                     g | ]	\  }}||f
S r   r   )r<   kvs      r   
<listcomp>z_hashable.<locals>.<listcomp>D  s     111!qe111r   )r   collectionsr	   r   r   r   rM   r   s    r   	_hashabler   8  sg     ![_455 Qxx	A{5	6	6 11qwwyy111222r   c                      t          |           S )a  
    Return a hashable version of the given object x, with lists and
    dictionaries converted to tuples.  Allows mutable objects to be
    used as a lookup key in cases where the object has not actually
    been mutated. Lookup will fail (appropriately) in cases where some
    part of the object has changed.  Does not (currently) recursively
    replace mutable subobjects.

    .. deprecated:: 2.0.0
    )r   r   s    r   hashabler   J  s     Q<<r   c                    t                      }i }g }|T|                                D ]?\  }}	 ||t          |          <   # t          $ r |                    ||f           Y <w xY w| D ]|r't                    |v r|t                             }not          fd|D                       rfd|D             d         }n?t          d          rj        }n't          d          rj        }nt                    }||<   |S )z
    Given a list of objects, returns a dictionary mapping from
    string name for the object to the object itself. Accepts
    an optional name,obj dictionary, which will override any other
    name if that item is present in the dictionary.
    Nc              3   &   K   | ]\  }}|u V  d S rZ   r   )r<   _r   r   s      r   r   z_named_objs.<locals>.<genexpr>n  s+      44fq!444444r   c                 "    g | ]\  }}|u 	|S r   r   )r<   r   r   r   s      r   r   z_named_objs.<locals>.<listcomp>o  s"    999v1Sr   r   r=   r   )
r   rM   r   	TypeErrorrR   r   r   r=   r   r   )objlist	namesdictobjs	objtonameunhashablesr   r   r   s          @r   _named_objsr   Y  s]    ==DIKOO%% 	+ 	+DAq+*+	)A,,'' + + +""Aq6*****+    		3944)C..)AA444444444 	9999999!<AAS&!! 	AAS*%% 	AACAQKs   A!A'&A'c                 $    t          | |          S )a  
    Given a list of objects, returns a dictionary mapping from
    string name for the object to the object itself. Accepts
    an optional name,obj dictionary, which will override any other
    name if that item is present in the dictionary.

    .. deprecated:: 2.0.0
    )r   )r   )r   r   s     r   
named_objsr   {  s     w)4444r   c           	         |P| |t          d|  d| d| d          || z
  }| |dz  z   }t          |t          |                    s| |dz  z   }n`t          |t                    st	          d|z            |dk    r||dz   f}n|dk    r	| d	|z  f}nd	|z  | f}| |d         } ||d         }|t          || z
  |z            }| ||z  z   }| |cxk    r|k    sn t          d
|  d| d| d          | ||fS )z=Return min, max, value given input values with possible None.Nz$unable to infer range, value from: (r:   )r#   zexpected a real number, got: %rr   ro   r   z'value must be between min and max (min=z, value=z, max=)
ValueErrorr   r{   r   r   int)minmaxr   stepdiffvrangeticks          r   _get_min_max_valuer     s    };#+MsMMcMMUMMM   Sytax %d,, 	&419%E%&& 	G=EFFFA::UQY'FFQYYfag&FFgv&F;)C;)CECK4'((dTk!%3c3ccPUcc]`cccdddU?r   c                    t           j                            |          s#t          d                    ||                    t           j                            |          \  }}|dv r%t           j                            |          d         }|| v r | |         |          S t          d                    |||d                    t          |                                         )z
    Call deserialization routine with path according to extension.
    ext_to_routine should be a dictionary mapping each supported
    file extension to a corresponding loading function.
    z@Could not parse file '{}' as {}: does not exist or is not a file>   .gz.xz.bz2.zipro   zrCould not parse file '{}' as {}: no deserialization method for files with '{}' extension. Supported extensions: {}r:   )	ospathisfileFileNotFoundErrorformatsplitextr   rB   sorted)ext_to_routiner   	type_namerootexts        r   _deserialize_from_pathr     s     7>>$ (vdI&&( ( 	(   &&ID#
,,, gt$$Q' n"~c"4(((
	6$	3		&2H2H(I(IJJL L Lr   c                     t          | t          j                  rdS t          | d          rt          | d          rdS t          | d          rdS dS )NT__int____add__qdivF)r   numbersNumberr   r   s    r   
_is_numberr     s^    #w~&& tt #y
!
! gc9&=&= tt	f		 ddr   c                 4    	 | j         S # t          $ r Y dS w xY w)NF)abstractr   )class_s    r   _is_abstractr    s1       uus   	 
c                 J   t          | t                    sJ | g}g }t          |          rn|                    d          }|                    d|           |                                D ]}||vr||vr|                    |            t          |          n|ddd         S )z
    Return a list of the class hierarchy below (and including) the given class.

    The list is ordered from least- to most-specific.  Can be useful for
    printing the contents of an entire class hierarchy.
    r   N)r   r{   rA   popinsert__subclasses__rR   )r  qr   r   bs        r   descendentsr    s     fT"""""	A
C
a&& EE!HH

1Q!!## 	 	Azzasll a&&  ttt9r   c                 4    d t          |           D             S )a^  
    Return a dictionary containing all subclasses of the specified
    parentclass, including the parentclass.  Only classes that are
    defined in scripts that have been run or modules that have been
    imported are included, so the caller will usually first do ``from
    package import *``.

    Only non-abstract classes will be included.
    c                 <    i | ]}t          |          |j        |S r   )r  r   )r<   cs     r   r?   z(concrete_descendents.<locals>.<dictcomp>  s6     $ $ $Q??$AJq $ $ $r   )r  )parentclasss    r   concrete_descendentsr    s*    $ $+k":": $ $ $ $r   c                     ddl m}mm  |fd|                                D             | gz             t          fd|                                D                       S )z
    Given a dict of (pathname,path) pairs, removes any prefix shared by all pathnames.
    Helps keep menu items short yet unambiguous.
    r   )commonprefixdirnamesepc                 ,    g | ]} |          z   S r   r   )r<   r=   r  r  s     r   r   z%_abbreviate_paths.<locals>.<listcomp>   s&    LLL774==,LLLr   c                 H    g | ]\  }}|t                    d          |fS rZ   )rA   )r<   r=   r   prefixs      r   r   z%_abbreviate_paths.<locals>.<listcomp>  s1    WWWid4c&kkll+D1WWWr   )os.pathr  r  r  keysr   rM   )pathspecnamed_pathsr  r  r  r  s      @@@r   _abbreviate_pathsr    s    
 3222222222\LLLLL9I9I9K9KLLLhZWXXFWWWW;CTCTCVCVWWWXXXr   c                 "    t          | |          S )z
    Given a dict of (pathname,path) pairs, removes any prefix shared by all pathnames.
    Helps keep menu items short yet unambiguous.

    .. deprecated:: 2.0.0
    )r  )r  r  s     r   abbreviate_pathsr    s     X{333r   c                     t          | t          j                  rBt          | t          j                  s(t          j        |                                 dd          S | S )z
    Internal function that will convert date objs to datetime objs, used
    for comparing date and datetime objects without error.
    Nr   )r   dtdatedatetime	timetupler   s    r   _to_datetimer%    sN    
 !RW /jBK&@&@ /{AKKMM"1"-..Hr   c               #      K   	 dV  dS # t           $ r; ddl}  | j                    \  }}}t          |j         d| | j                   Y dS w xY w)zUseful utility for writing docs that need to show expected errors.
    Shows exception only, concisely, without a traceback.
    Nr   z: )file)r}   r   exc_infoprintr   stderr)r   etyper   tbs       r   exceptions_summarizedr-    s~      
= = = =


'3<>>ub**5**<<<<<<<=s   
 AAAc                  F    	 t                       dS # t          $ r Y dS w xY w)NTF)get_ipython	NameErrorr   r   r   _in_ipythonr1  '  s7    t   uus    
  )rV   rZ   )NN)Ar   r#  r!  rJ   r3   r   r   ri   r   rp   r(   r   r   
contextlibr   r   textwrapr   	threadingr   r	   	SignaturerO   rP   VAR_KEYWORDDEFAULT_SIGNATUREWarningr   PendingDeprecationWarningr   DeprecationWarningr   FutureWarningr   r6   rU   rf   rm   rw   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r%  r-  r1  r   r   r   <module>r<     sl                 				 				 



      0 0 0 0 0 0 0 0 % % % % % %                        %G%Gfg/EFFGh 1 =>>'   
    7       \3L       l,>       }    *A     & & &T   *? ? ?	" 	" 	"% % % %P^ ^ ^
   $         4  	 	 	 % % %    	T 	T 	T  $      D 	5 	5 	5 	5" " " "JL L L4      ($ $ $Y Y Y 4 4 4   	= 	= 	=    r   