
    e9                       d Z ddlm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 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mZ ddl Z ddl!Z"ddl#Z#ddl$m%Z% ddl&m'Z' ddl(m)Z) ddl*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4 ddl5m6Z6m7Z7m8Z8m9Z9m:Z:  ej;        d          Z< e)e j=                  Z>dZ? ej@        d          ZA G d d          ZB eBd          ZCd ZDd ZEdFdZFdGd ZGdHd!ZHd" fd#ZId$ ZJd% ZKd& ZLdId)ZMd* ZNd+ ZOdJdKd/ZP G d0 d1          ZQdLd3ZRdMd5ZSd6 ZTdNd7ZUdOd8ZV ej@        d9          ZWdPd<ZXdQd?ZYdRdAZZdB Z[dC Z\dD Z]dE Z^dS )Sz7
Various general utilities used in the panel codebase.
    )annotationsN)OrderedDictdefaultdict)MutableMappingMutableSequence)datetime)partial)escape)import_module)AnyAnyStr)_default_resolver)Model)Version   )
datetime_typesis_dataframeis_holoviews	is_numberis_parameterized	is_series
isdatetimeisfileisInisurl)edit_readonlyextract_dependenciesget_method_ownerparam_watchersrecursive_parameterizedz
panel.utilgMb@z	^.*\d{5}$c                      e Zd ZdZd Zd ZdS )LazyHTMLSanitizerzg
    Wraps bleach.sanitizer.Cleaner lazily importing it on the first
    call to the clean method.
    c                "    d | _         || _        d S N)_cleaner_kwargs)selfkwargss     3lib/python3.11/site-packages/panel/util/__init__.py__init__zLazyHTMLSanitizer.__init__;   s        c                    | j          dd l} |j        j        di | j        | _         | j                             |          S )Nr    )r%   bleach	sanitizerCleanerr&   clean)r'   textr.   s      r)   r1   zLazyHTMLSanitizer.clean?   sH    = MMM4F,4DDt|DDDM}""4(((r+   N)__name__
__module____qualname____doc__r*   r1   r-   r+   r)   r"   r"   5   s<         
  ) ) ) ) )r+   r"   T)stripc                    t          | t                    rt          |           S t          | t                    r+t          d |                                 D                       S | S )Nc                    g | ]	\  }}||f
S r-   r-   ).0kvs      r)   
<listcomp>zhashable.<locals>.<listcomp>L   s     111!qe111r+   )
isinstancer   tupler   itemsxs    r)   hashablerC   H   s[    !_%% Qxx	A~	&	& 11qwwyy111222r+   c                    t          |          D ](\  }}|| u r|c S 	 || k    r|c S # t          $ r Y %w xY wt          d| z            )z
    Returns the index of an object in a list of objects. Unlike the
    list.index method this function only checks for identity not
    equality.
    z%s not in list)	enumerate	Exception
ValueError)objobjsios       r)   indexOfrL   P   s     $  188HHH	Cxx  	 	 	D	
%+
,
,,s   )
66namestrreturnc                z    t          j        d|           }|r#| d|                     |d                            n| S )zA
    Removes the integer id from a Parameterized class name.
    z\D+(\d{5,})Nr   )refindallindex)rM   matchs     r)   
param_namerU   a   s@     J~t,,E*/94%E!H%%%&&T9r+      , c                f   t          | t                    r%dd                    d | D                       z   dz   }t          | t          j                  rt          |           j        }nt          |           }t          |          |k    r||dz  d         }d}|D ]#}||v r|	                    |          |dz  z   } n$|r||k     r|dz   }d}t          | t                    rd}n6t          | t                    rd	}nt          | t          t          f          rd
}|d|dz            dz   |z   S |S )z
    Returns an abbreviated repr for the supplied object. Attempts to
    find a natural break point while adhering to the maximum length.
    [z, c                ,    g | ]}t          |          S r-   )abbreviated_repr)r:   r<   s     r)   r=   z$abbreviated_repr.<locals>.<listcomp>o   s!     D D D!1!!4!4 D D Dr+   ]   Nr    z])}z...)r>   listjoinparamParameterizedtyper3   reprlenrS   r   dictset)value
max_lengthnatural_breaksvreprabbrevnatural_breakbrkend_chars           r)   r]   r]   i   sg   
 % Ldii D De D D DEEEK%,-- U$U
5zzJz1}~~&! 	 	Cf}} &S 1 1JM A   	+]Z77&*JeT"" 	HH{++ 	HHc{++ 	H]jl]#e+h66Lr+   c                   t          |           j        }g }t          | j                                                                                  D ]:\  }}| j        |         j        }||u }|svt          |t          j	                  r5t          |t          j	                  rt          j
        ||d          }n*d}n'	 t          ||k              }n# t          $ r d}Y nw xY w|r|t          |t                    r|dk    rt          |t                    r|g k    rt          |t                    r|i k    r|r||v s|dk    r|                    |          rt#          |          }|                    | d|            <|S )zq
    Returns a list of reprs for parameters on the parameterized object.
    Skips default and empty values.
    T)	equal_nanFNr`   rM   =)rf   r3   sortedrd   valuesr@   defaultr>   npndarrayarray_equalboolrF   rN   rb   ri   
startswithr]   append)parameterizedskipclsparam_reprspr<   rx   equals           r)   r   r      s   
 }


&CK}*113399;;<< ' '1%a(0W 
	"!RZ(( 	"grz22 "N1gFFFEE!EE" G,,EE  " " "!EEE"  	&(Y3 	&AGGX4   	&Q"WWh4   	&Q"WWh 	&qDyya6kkall36G6Gk("1%%aa::!::&&&&s   =CC C c                    | S r$   r-   rA   s    r)   <lambda>r      s    ! r+   c                    t          t                    }| D ]&}| ||                                       |           '|                                S )zD
    Groupby implementation which does not require a prior sort
    )r   rb   r~   r@   )lkeyditems       r)   full_groupbyr      sQ     	DA " "	##d))D!!!!7799r+   c                h    t          | t          j                  rt          j        | dz            } | S )zB
    Retrieve the value tuple as a tuple of datetime objects.
      )r>   numbersNumberr   utcfromtimestamprk   s    r)   value_as_datetimer      s1     %(( 8)%$,77Lr+   c                    t          | t          j                  r*t          j        | dz                                            } n)t          | t                    r|                                 } | S )Nr   )r>   r   r   r   r   dater   s    r)   value_as_dater      s\    %(( )%$,77<<>>	E8	$	$ 

Lr+   c                v    |                      t          j        j                                                  dz  S )zJ
    Converts a datetime to a UTC timestamp used by Bokeh internally.
    )tzinfor   )replacedttimezoneutc	timestampr   s    r)   datetime_as_utctimestampr      s-     ===00::<<tCCr+   querydict[str, Any]c           
        t          t          j        | dd                             }i }|                                D ]\  }}|                                rt          |          ||<   -t          |          rt          |          ||<   O|                    d          rs	 t          j
        |          ||<   }# t          $ rM 	 t          j        |          ||<   n1# t          $ r$ t                              d|d| d           Y nw xY wY w xY w|                                dv r|                                dk    ||<   
|||<   |S )	zt
    Parses a url query string, e.g. ?a=1&b=2.1&c=string, converting
    numeric strings to int or float types.
    r   N)r[   {zCould not parse value z of query parameter z. Parameter will be ignored.)truefalser   )ri   urlparse	parse_qslr@   isdigitintr   floatr}   jsonloadsrF   astliteral_evallogwarninglower)r   
query_dictparsed_queryr;   r<   s        r)   parse_queryr      s   
 h(qrr3344J#%L  ""    199;; 	 !!ffLOOq\\ 	 #AhhLOO\\*%% 	 	"&*Q--Q   &)&6q&9&9LOO    KK5 5 5! 5 5 5     WWYY+++ggii61LOOLOOs6   %B==
DC D +DDDDDc                    t          | t                    r|                     d          } t          j        |                               d          }t          |                    d                    S )Nutf-8asciiru   )r>   rN   encodebase64urlsafe_b64encodedecoderstrip)inputencodeds     r)   base64url_encoder      s]    % &W%%&u--44W==Gw~~c""###r+   c                    t          | t                    r|                     d          } t          |           dz  }|dk    r| dd|z
  z  z  } t	          j        |           S )Nr      r      =)r>   rN   r   rh   r   urlsafe_b64decode)r   rems     r)   base64url_decoder      sa    % &W%%
e**q.C
QwwS!!#E***r+   tokensignedr|   c                   |rJd| v rF|                      d                              dd          \  }}|                    dd          \  }}n| }t          j        t          |                              d                    S )z1
    Decodes a signed or unsigned JWT token.
    .r      .r   )r   rsplitsplitr   r   r   r   )r   r   signing_input_payload_segments        r)   decode_tokenr      s       #,, <<0077a@@q*00q99??:&77>>wGGHHHr+   c                      e Zd Zd Zd ZdS )classpropertyc                    || _         d S r$   f)r'   r   s     r)   r*   zclassproperty.__init__  s    r+   c                ,    |                      |          S r$   r   )r'   rH   owners      r)   __get__zclassproperty.__get__  s    vve}}r+   N)r3   r4   r5   r*   r   r-   r+   r)   r   r     s2              r+   r   urlc                    |                      d          dd         }d                    d                    |                               d          dd                   S )zL
    Strips the protocol and domain from a URL returning just the path.
    z//r   N/)r   rc   )r   subpathss     r)   url_pathr     sQ     yyqrr"H88CHHX&&,,S11!""5666r+   Fc                   ddl m} ddlm} d |j                                        D             }|p|                     d          d         }||          }|j        }	|	d u p||	v }
| t          j	        v rP|
rNt          t          j	        |          |          }|j         d| t          j        vrt          j        |           |S |r+t           j        j                            | d| d           n|
s[|j        rTt           j        j                            d	|d
|d           |	|g|j        |j        <   n|	                    |           nn|
s,t           j        j                            d	|d|d           n@|>|j        d         |j        v r*t           j        j                            | d| d           t          t3          |           |          S )Nr_   )panel_extension)statec                    i | ]\  }}||	S r-   r-   )r:   extmodules      r)   
<dictcomp>zlazy_load.<locals>.<dictcomp>  s+       #V  r+   r   z was not imported on instantiation and may not render in a notebook. Restart the notebook kernel and ensure you load it as part of the extension using:

pn.extension('z')
z!pn.extension was initialized but z extension was not loaded. Since the application is still launching the extension was loaded automatically but we strongly recommend you load the extension explicitly with the following argument(s):

pn.extension(z)
z extension was not loaded. In order for the required resources to be initialized ensure the extension is loaded with the following argument(s):

pn.extension(idz was not imported on instantiation may not render in the served application. Ensure you add the following to the top of your application:

pn.extension(')configr   io.stater   _importsr@   r   _extensionssysmodulesgetattrr4   r   model_class_reverse_mapr   addrd   mainr   _is_launching_extensions_curdocr~   ref_viewsr   )r   modelnotebookrootr   	extensionr   external_modulesext_nameloaded_extensionsloaded	model_clss               r)   	lazy_loadr     s   555555       '0'9'?'?'A'A   
&c""2&C'H)$&G(6G*GFCK/77	",,U,,E4QQQ!),,, #

   - - #&- - -	
 	
 	
 	
  
+ 
 	
  + + + !$	+ + +	
 	
 	
 $08zEu|,,$$X.... 

  + + + !$+ + +	
 	
 	
 	
 
	dhtn<<
   - - #&- - -	
 	
 	
 =((%000r+   c                      fd}|S )Nc                d    | j         }d| _         	  | g|R i | || _         d S # || _         w xY w)NT)	_updating)r'   argsr(   updatingfns       r)   wrappedzupdating.<locals>.wrappedT  sT    >	&Bt%d%%%f%%%%DNNNXDN%%%%s   & 	/r-   )r  r  s   ` r)   r  r  S  s#    & & & & & Nr+   c                Z    |                      ||          } t          |           di |S )N)include_defaultsinclude_undefinedr-   )properties_with_valuesrf   )bokeh_modelr  r  
propertiess       r)   clone_modelr  ^  sB    33)=N 4  J 4**z***r+   c                    t          | t                    r| j        } t          | t                    t          | d          r| j        S t          |           S )z=
    Returns the name of a function (or its string repr)
    r3   )r>   r	   funchasattrr3   rN   )r  s    r)   function_namer  e  sW     T7
#
# y T7
#
# tZ   }t99r+   zi((?P<weeks>\d+?)w)?((?P<days>\d+?)d)?((?P<hours>\d+?)h)?((?P<minutes>\d+?)m)?((?P<seconds>\d+?\.?\d*?)s)?time_strdt.timedelta | Nonec                    t                               |           }|sd S |                                }i }|                                D ]\  }}|rt	          |          ||<   t          j        di |S )Nr-   )_period_regexrT   	groupdictr@   r   r   	timedelta)r  parts
parts_dicttime_paramsrM   r   s         r)   parse_timedeltar  r  s    ))E t""JK%%'' ) )	q 	) %aK<&&+&&&r+   pathAnyStr | os.PathLikec                z    t           j                            t           j                            |                     S )z1Expanduser and then abspath for a given path
    )osr  abspath
expanduser)r  s    r)   fullpathr!  ~  s(     7??27--d33444r+   versionc                `    d}t          j        ||           }|r|                                S | S )a  Extract the final release and if available pre-release (alpha, beta,
    release candidate) segments of a PEP440 version, defined with three
    components (major.minor.micro).

    Useful to avoid nbsite/sphinx to display the documentation HTML title
    with a not so informative and rather ugly long version (e.g.
    ``0.13.0a19.post4+g0695e214``). Use it in ``conf.py``::

        version = release = base_version(package.__version__)

    Return the version passed as input if no match is found with the pattern.
    z%([\d]+\.[\d]+\.[\d]+(?:a|rc|b)?[\d]*))rQ   rT   group)r"  patternrT   s      r)   base_versionr&    s5     7GHWg&&E {{}}r+   c                x    	 t          j        |                               |           dS # t          $ r Y dS w xY w)NTF)pathlibPathrelative_torF   )r  
other_paths     r)   r*  r*    sL    T&&z222t   uus   '+ 
99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 r$   )r>   )r:   tpelements     r)   	<genexpr>zflatten.<locals>.<genexpr>  s-      EE2z'2&&EEEEEEr+   N)anyrb   r?   ri   flatten)liner/  s    @r)   r2  r2    s|      &   EEEE$t1DEEEEE 	w''''''''''MMMM	 r+   c                   g }| j         D ]7}t          |t                    s|                    |           .g }|D ]}t          |t                    s|                    |           -t	          |d                   }d|v sd|v r|d         dv rwt          j        fdj        D                       }t          |d                   t          |          k    rt          j	        ||d                   }|d         |d         |f}|                    |           t          |          }|                    |           9|S )a/  
    Updates the todo items on a pandas Styler object to apply to a new
    DataFrame.

    Arguments
    ---------
    styler: pandas.io.formats.style.Styler
      Styler objects
    new_df: pd.DataFrame
      New DataFrame to update the styler to do items

    Returns
    -------
    todos: list
    r   _background_gradient_barr   )r   r   c                8    g | ]}|         j         j        d v S )uif)dtypekind)r:   colnew_dfs     r)   r=   z!styler_update.<locals>.<listcomp>  s5     $ $ $8;F3K%*e3$ $ $r+   r_   )
_todor>   r?   r~   rN   ry   arraycolumnsrh   logical_and)stylerr<  todostodoopsopop_fnappliess    `      r)   styler_updaterH    s^     E  $&& 	LL 	 	Bb%(( 

21JJE&%//6U??1QW( $ $ $ $?E~$ $ $   r!u::W-- nWbe<<GeRUG,JJrNNNNSzzTLr+   c                    t          | t          j                  r-|                     d                              t                    } | S )Nzdatetime64[ms])r>   ry   
datetime64astyper   r   s    r)   try_datetime64_to_datetimerL    s<    %'' @-..55h??Lr+   )rM   rN   rO   rN   )rV   rW   r$   )r   rN   rO   r   )T)r   rN   r   r|   rO   r   )r   rN   rO   rN   )FNN)FF)rO   rN   )r  rN   rO   r  )r  r  rO   r  )r"  rN   rO   rN   )_r6   
__future__r   r   r   r   r   r   loggingr   r  r(  rQ   r   urllib.parseparser   collectionsr   r   collections.abcr   r   	functoolsr	   htmlr
   	importlibr   typingr   r   bokehnumpyry   rd   bokeh.core.has_propsr   bokeh.modelr   packaging.versionr   checksr   r   r   r   r   r   r   r   r   r   
parametersr   r   r   r   r    	getLoggerr   __version__bokeh_versionBOKEH_JS_NATcompilePARAM_NAME_PATTERNr"   HTML_SANITIZERrC   rL   rU   r]   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r!  r&  r*  r2  rH  rL  r-   r+   r)   <module>re     s    # " " " " " 



         				  				 



       0 0 0 0 0 0 0 0 ; ; ; ; ; ; ; ;                   # # # # # #               2 2 2 2 2 2       % % % % % %                                    
 g%%)** #RZ-- ) ) ) ) ) ) ) )  #"...  - - -": : : :   B   B $        D D D   <$ $ $	+ 	+ 	+	I 	I 	I 	I 	I       7 7 7 741 41 41 41n  + + + +    
  H  I  I	' 	' 	' 	'5 5 5 5   ,    4% % %P    r+   