
    -e<                        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
Z
ddlmZ ddlmZ ddlmZmZmZmZ ddlmZ dZd$d%dZdZd&d'dZd&d(dZej        d)d*d#            ZdS )+zD Provide utility functions for implementing the ``bokeh`` command.

    )annotationsN)Iterator)Application)DirectoryHandlerHandlerNotebookHandlerScriptHandler)warn) build_single_handler_application!build_single_handler_applicationsdiereport_server_init_errors   messagestrstatusintreturnNonec                d    t          | t          j                   t          j        |           dS )a	   Print an error message and exit.

    This function will call ``sys.exit`` with the given ``status`` and the
    process will terminate.

    Args:
        message (str) : error message to print

        status (int) : the exit status to pass to ``sys.exit``

    )fileN)printsysstderrexit)r   r   s     2lib/python3.11/site-packages/bokeh/command/util.pyr   r   6   s/     
'
####HV    a9  
It looks like you might be running the main.py of a directory app directly.
If this is the case, to enable the features of directory style apps, you must
call "bokeh serve" on the directory instead. For example:

    bokeh serve my_app_dir/

If this is not the case, renaming main.py will suppress this warning.
pathargvlist[str] | Noner   c           	        |pg }t           j                            t           j                            |                     } t           j                            |           rt          | |          }nt           j                            |           r|                     d          rt          | |          }nt|                     d          r;|                     d          rt          t                     t          | |          }n$t          d| z            t          d| z            |j        r#t          d|  d|j         d	|j         d
          t#          |          }|S )a;   Return a Bokeh application built using a single handler for a script,
    notebook, or directory.

    In general a Bokeh :class:`~bokeh.application.application.Application` may
    have any number of handlers to initialize |Document| objects for new client
    sessions. However, in many cases only a single handler is needed. This
    function examines the ``path`` provided, and returns an ``Application``
    initialized with one of the following handlers:

    * :class:`~bokeh.application.handlers.script.ScriptHandler` when ``path``
      is to a ``.py`` script.

    * :class:`~bokeh.application.handlers.notebook.NotebookHandler` when
      ``path`` is to an ``.ipynb`` Jupyter notebook.

    * :class:`~bokeh.application.handlers.directory.DirectoryHandler` when
      ``path`` is to a directory containing a ``main.py`` script.

    Args:
        path (str) : path to a file or directory for creating a Bokeh
            application.

        argv (seq[str], optional) : command line arguments to pass to the
            application handler

    Returns:
        :class:`~bokeh.application.application.Application`

    Raises:
        RuntimeError

    Notes:
        If ``path`` ends with a file ``main.py`` then a warning will be printed
        regarding running directory-style apps by passing the directory instead.

    )filenamer   z.ipynbz.pyzmain.pyz7Expected a '.py' script or '.ipynb' notebook, got: '%s'z4Path for Bokeh server application does not exist: %szError loading z:


 )osr   abspath
expanduserisdirr   isfileendswithr   r
   DIRSTYLE_MAIN_WARNINGr	   
ValueErrorfailedRuntimeErrorerrorerror_detailr   )r   r   handlerapplications       r   r   r   O   sa   J :2D7??27--d3344D 
w}}T X"Dt<<<			 
X=="" 	_%t$???GG]]5!! 	_}}Y'' ,*+++#T===GGVY]]^^^ORVVWWW~ a_D__w}__H\___```g&&Kr   paths	list[str]argvsdict[str, list[str]] | Nonedict[str, Application]c                    i }|pi }| D ]d}t          ||                    |g                     }|j        d                                         }|sd|v rt	          d|z            d}|||<   e|S )a{   Return a dictionary mapping routes to Bokeh applications built using
    single handlers, for specified files or directories.

    This function iterates over ``paths`` and ``argvs`` and calls
    :func:`~bokeh.command.util.build_single_handler_application` on each
    to generate the mapping.

    Args:
        paths (seq[str]) : paths to files or directories for creating Bokeh
            applications.

        argvs (dict[str, list[str]], optional) : mapping of paths to command
            line arguments to pass to the handler for each path

    Returns:
        dict[str, Application]

    Raises:
        RuntimeError

    r   /z%Don't know the URL path to use for %s)r   gethandlersurl_pathr.   )r3   r5   applicationsr   r2   routes         r   r   r      s    , ,.LKRE 	* 	*6tUYYtR=P=PQQ$Q'0022 	l"""#Jd#STTTE)Ur   address
str | Noneport
int | NonekwargsIterator[None]c              +    K   	 dV  dS # t           $ r}|j        t          j        k    rt                              d|           nd|j        t          j        k    rt                              d|            n3t          j        |j                 }t                              d||           t          j        d           Y d}~dS d}~ww xY w)a   A context manager to help print more informative error messages when a
    ``Server`` cannot be started due to a network problem.

    Args:
        address (str) : network address that the server will be listening on

        port (int) : network address that the server will be listening on

    Example:

        .. code-block:: python

            with report_server_init_errors(**server_kwargs):
                server = Server(applications, **server_kwargs)

        If there are any errors (e.g. port or address in already in use) then a
        critical error will be logged and the process will terminate with a
        call to ``sys.exit(1)``

    Nz4Cannot start Bokeh server, port %s is already in usez5Cannot start Bokeh server, address '%s' not availablez"Cannot start Bokeh server [%s]: %rr   )	OSErrorerrno
EADDRINUSElogcriticalEADDRNOTAVAIL	errorcoder   r   )r?   rA   rC   ecodenames        r   r   r      s      ,
   7e&&&LLOQUVVVVW+++LLPRYZZZZqw/HLL=xKKKs   
 
CB)CC)r   )r   r   r   r   r   r   )N)r   r   r   r    r   r   )r3   r4   r5   r6   r   r7   )NN)r?   r@   rA   rB   rC   r   r   rD   )__doc__
__future__r   logging	getLogger__name__rI   
contextlibrG   r%   r   typingr   bokeh.applicationr   bokeh.application.handlersr   r   r   r	   bokeh.util.warningsr
   __all__r   r+   r   r   contextmanagerr    r   r   <module>r\      sl    # " " " " " g!!      				 



       * ) ) ) ) )            % $ $ $ $ $     ? ? ? ? ?B$ $ $ $ $N       r   