U
    /e'                     @  s   d Z ddlmZ ddlZe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	dlmZ dZG dd deZdS )ze Bokeh Application Handler to look for Bokeh server request callbacks
in a specified Python module.

    )annotationsN)
ModuleType)List   )PathLike)_check_callback   )
CodeRunner)RequestHandler)ServerRequestHandlerc                      s   e Zd ZU dZded< g dddddd	d
 fddZeddddZeddddZeddddZ	ddddZ
  ZS )r   z\ Load a script which contains server request handler callbacks.

    .. autoclasstoc::

    r   _moduleN)argvpackager   z	List[str]zModuleType | NoneNone)filenamer   r   returnc             	     sx   t    t|ddd}| }W 5 Q R X t||||d _ jjst j  _dd fdd} j	 j| d	S )
a  

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

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

        rzutf-8)encoding)r   r   r   c                    s.    j j} d| kr| d  _t jddd d S )Nprocess_request)request)what)r   __dict__Z_process_requestr   )contentsself U/tmp/pip-unpacked-wheel-f5fndrjf/bokeh/application/handlers/server_request_handler.pyextract_callbacksQ   s    
z8ServerRequestHandler.__init__.<locals>.extract_callbacksN)
super__init__openreadr	   _runnerfailedZ
new_moduler   run)r   r   r   r   fsourcer   	__class__r   r   r    <   s    

zServerRequestHandler.__init__z
str | Noner   c                 C  s   | j jS )zE If the handler fails, may contain a related error message.

        )r#   errorr   r   r   r   r*   \   s    zServerRequestHandler.errorc                 C  s   | j jS )zJ If the handler fails, may contain a traceback or other details.

        )r#   error_detailr   r   r   r   r+   c   s    z!ServerRequestHandler.error_detailboolc                 C  s   | j jS )zF ``True`` if the request handler callbacks failed to execute

        )r#   r$   r   r   r   r   r$   j   s    zServerRequestHandler.failedc                 C  s.   | j r
dS dtjtj| jjd  S dS )z_ The last path component for the basename of the path to the
        callback module.

        N/r   )r$   ospathsplitextbasenamer#   r   r   r   r   url_paths   s    zServerRequestHandler.url_path)__name__
__module____qualname____doc____annotations__r    propertyr*   r+   r$   r2   __classcell__r   r   r(   r   r   3   s   
  r   )r6   
__future__r   logging	getLoggerr3   logr.   typesr   typingr   Z
core.typesr   Zutil.callback_managerr   Zcode_runnerr	   Zrequest_handlerr
   __all__r   r   r   r   r   <module>   s   
