
    hje                        d Z ddlmZ ddlZ ej        e          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 ddlmZ dd	lmZ d
dlmZ dZ G d d          ZdS )z^ Provide a utility class ``CodeRunner`` for use by handlers that execute
Python source code.

    )annotationsN)basename)CodeType
ModuleType)Callable   )PathLike)make_globally_unique_id   )handle_exception)
CodeRunnerc                  @   e Zd ZU dZded<   ded<   ded<   ded<   ded	<   d
ed<   ded<   ded<   ded<   ded<   ded<   ded<   d*d+dZed,d            Zed,d            Zed,d            Z	ed-d             Z
ed.d!            Zed/d"            Zd0d#Zd1d$Zd*d2d)ZdS )3r   z* Compile and run Python source code.

    zCodeType | None_code
str | None_doc_permanent_error_permanent_error_detailr	   _pathstr_source	list[str]_argvModuleType | None_packageboolran_failed_error_error_detailNsourcepathargvpackagereturnNonec                   |r"t          |          dk    rt          d          d| _        d| _        |                                  ddl}d| _        	 |                    |t          j	        |                    }t          ||dd          | _        t          t          | j        j        | j        j                            }|                    dd          | _        n# t"          $ rt}d| _        |j        $t          j                             |j                  nd	}	d
|	d|j        pd	 d|j        pd	 | _        t-          j                    | _        Y d}~nd}~ww xY w|| _        || _        || _        || _        d| _        dS )a  

        Args:
            source (str) :
                A string containing Python source code to execute

            path (str) :
                A filename to use in any debugging or error output

            argv (list[str]) :
                A list of string arguments to make available as ``sys.argv``
                when the code executes

            package (bool) :
                An optional package module to configure

        Raises:
            ValueError, if package is specified for an __init__.py

        __init__.pyz)__init__.py cannot have package specifiedNr   execT)filenamemodedont_inherit__doc__z???zInvalid syntax in z	 on line z:
F)r   
ValueErrorr   r   reset_run_errorsastr   parseosfspathcompiledictzipco_names	co_constsgetr   SyntaxErrorr)   r!   linenotext	traceback
format_excr   r   r   r   r   )
selfr    r!   r"   r#   r/   nodesder)   s
             Flib/python3.11/site-packages/bokeh/application/handlers/code_runner.py__init__zCodeRunner.__init__H   s   *  	Jx~~66HIII $'+$




	BIIfbioo66E FQUVVVDJS,dj.BCCDDAi..DII 	B 	B 	BDJ78z7Mrw''
333SXH$u$u$uahN_Z_$u$udedjdsns$u$uD!+4+?+A+AD((((((		B 

s   BC   
E*A*EEc                    | j         S )z7 Contents of docstring, if code contains one.

        )r   r>   s    rB   doczCodeRunner.doc{   s    
 y    c                ,    | j         | j        n| j         S )zH If code execution fails, may contain a related error message.

        )r   r   rE   s    rB   errorzCodeRunner.error   s    
 #3;t{{AVVrG   c                ,    | j         | j        n| j         S )zM If code execution fails, may contain a traceback or other details.

        )r   r   rE   s    rB   error_detailzCodeRunner.error_detail   s    
 &*%A%It!!tOkkrG   c                "    | j         p| j        du S )z, ``True`` if code execution failed

        N)r   r   rE   s    rB   failedzCodeRunner.failed   s    
 |1tzT11rG   c                    | j         S )z= The path that new modules will be configured with.

        )r   rE   s    rB   r!   zCodeRunner.path   s    
 zrG   c                    | j         S )z[ The configured source code that will be executed when ``run`` is
        called.

        )r   rE   s    rB   r    zCodeRunner.source   s     |rG   c                   |                                   | j        dS dt                                          dd          z   }t	          |          }t
          j                            | j                  |j	        d<   | j
        r;| j
        j        |_        t
          j                            | j                  g|_        t          | j                  dk    r1||_        t
          j                            | j                  g|_        |S )zN Make a fresh module to run in.

        Returns:
            Module

        N
bokeh_app_- __file__r'   )r.   r   r
   replacer   r1   r!   abspathr   __dict__r   __name____package__dirname__path__r   )r>   module_namemodules      rB   
new_modulezCodeRunner.new_module   s     	:4"%<%>%>%F%FsB%O%OOK((&(goodj&A&A
#= 	<!%!7F!wtz::;FODI-//!,F!wtz::;FOrG   c                0    d| _         d| _        d| _        dS )zg Clears any transient error conditions from a previous run.

        Returns
            None

        FN)r   r   r   rE   s    rB   r.   zCodeRunner.reset_run_errors   s      !rG   r]   r   
post_checkCallable[[], None] | Nonec                   t          j                    }t          t          j                  }t          t          j                  }t          j                            dt           j                            | j                             t           j        	                    | j                  g| j
        t          _        | j        J 	 t          | j        |j                   |r
 |             n'# t          $ r}t          | |           Y d}~nd}~ww xY wt          j        |           |t          _        |t          _        d| _        dS # t          j        |           |t          _        |t          _        d| _        w xY w)at   Execute the configured source code in a module and run any post
        checks.

        Args:
            module (Module) :
                A module to execute the configured code in.

            post_check (callable, optional) :
                A function that raises an exception if expected post-conditions
                are not met after code execution.

        r   NT)r1   getcwdlistsysr!   r"   insertrZ   r   r   r   r   r(   rW   	Exceptionr   chdirr   )r>   r]   r`   _cwd	_sys_path	_sys_argvrA   s          rB   runzCodeRunner.run   sB     y{{NN	NN	27??4:66777G$$TZ00>4:> z%%%	V_--- 
 	& 	& 	&T1%%%%%%%%	& HTNNN CH CHDHHH HTNNN CH CHDHOOOOs0   &C/ .E /
D9D	E DE 5F )N)
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`   ra   r$   r%   )rX   
__module____qualname__r,   __annotations__rC   propertyrF   rI   rK   rM   r!   r    r^   r.   rl    rG   rB   r   r   5   s              ''''OOOLLLIIIMMM/ / / / /f    X W W W XW l l l Xl 2 2 2 X2    X    X   0	" 	" 	" 	"% % % % % % %rG   r   )r,   
__future__r   logging	getLoggerrX   logr1   re   r<   os.pathr   typesr   r   typingr   
core.typesr	   util.serializationr
   handlerr   __all__r   rq   rG   rB   <module>r}      s    # " " " " " g!! 
			 



           & & & & & & & &       # " " " " " 9 9 9 9 9 9 % % % % % %{ { { { { { { { { {rG   