
    hje                        d Z ddlmZ ddlZ ej        e          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 dd
lmZ dZ G d de          ZdS )zg Bokeh Application Handler to look for Bokeh server lifecycle callbacks
in a specified Python module.

    )annotationsN)
ModuleType   )PathLike)_check_callback   )
CodeRunner)LifecycleHandler)ServerLifecycleHandlerc                  |     e Zd ZdZg ddd fdZedd            Zedd            Zedd            ZddZ	 xZ
S )r   z? Load a script which contains server lifecycle callbacks.

    N)argvpackagefilenamer   r   	list[str]r   ModuleType | NonereturnNonec                   t                                                       t          |d          5 }|                                }ddd           n# 1 swxY w Y   t	          ||||           _         j        j        sF j                                         _        d fd} j        	                     j        |           dS dS )	a  

        Keyword Args:
            filename (str) : path to a module to load lifecycle callbacks from

            argv (list[str], optional) : a list of string arguments to use as
                ``sys.argv`` when the callback code is executed. (default: [])

        zutf-8)encodingN)r   r   r   c                 `   j         j        } d| v r| d         _        d| v r| d         _        d| v r| d         _        d| v r| d         _        t          j        dd           t          j        dd           t          j        dd           t          j        dd           d S )Non_server_loadedon_server_unloadedon_session_createdon_session_destroyed)server_context)what)session_context)_module__dict___on_server_loaded_on_server_unloaded_on_session_created_on_session_destroyedr   )contentsselfs    Klib/python3.11/site-packages/bokeh/application/handlers/server_lifecycle.pyextract_callbacksz:ServerLifecycleHandler.__init__.<locals>.extract_callbacksL   s    <0%11-56H-ID*'833/78L/MD,'833/78L/MD,)X5519:P1QD. 68KRdeeee 8:MThiiii 8:NUijjjj :<PWmnnnnnn    )r   r   )
super__init__openreadr	   _runnerfailed
new_moduler   run)r%   r   r   r   fsourcer'   	__class__s   `      r&   r*   zServerLifecycleHandler.__init__7   s    	(W--- 	VVXXF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 "&(D'JJJ|" 	><2244DLo o o o o o  LT\+<=====)	> 	>s   AAA
str | Nonec                    | j         j        S )zE If the handler fails, may contain a related error message.

        )r-   errorr%   s    r&   r6   zServerLifecycleHandler.error`   s    
 |!!r(   c                    | j         j        S )zJ If the handler fails, may contain a traceback or other details.

        )r-   error_detailr7   s    r&   r9   z#ServerLifecycleHandler.error_detailg   s    
 |((r(   boolc                    | j         j        S )z@ ``True`` if the lifecycle callbacks failed to execute

        )r-   r.   r7   s    r&   r.   zServerLifecycleHandler.failedn   s    
 |""r(   c                    | j         rdS dt          j                            t          j                            | j        j                            d         z   S )z_ The last path component for the basename of the path to the
        callback module.

        N/r   )r.   ospathsplitextbasenamer-   r7   s    r&   url_pathzServerLifecycleHandler.url_pathw   sK    
 ; 	R4 ))"'*:*:4<;L*M*MNNqQQQr(   )r   r   r   r   r   r   r   r   )r   r4   )r   r:   )__name__
__module____qualname____doc__r*   propertyr6   r9   r.   rB   __classcell__)r3   s   @r&   r   r   2   s          ACae %> %> %> %> %> %> %> %>R " " " X" ) ) ) X) # # # X#	R 	R 	R 	R 	R 	R 	R 	Rr(   r   )rF   
__future__r   logging	getLoggerrC   logr>   typesr   
core.typesr   util.callback_managerr   code_runnerr	   	lifecycler
   __all__r    r(   r&   <module>rT      s     # " " " " " g!! 
			       # " " " " " 4 4 4 4 4 4 # # # # # # ' ' ' ' ' 'NR NR NR NR NR- NR NR NR NR NRr(   