
    -e-                    R   U d Z ddlmZ ddlZ ej        e          ZddlmZm	Z	 ddl
mZmZmZmZmZ ddlmZ ddlmZ dd	lmZ erdd
lmZ ddlmZ ddlmZ ddlmZ dZeg df         Zded<    G d d          Z  G d de          Z! G d de          Z"ee"gdf         Z#dS )a   Provide the ``Application`` class.

Application instances are factories for creating new Bokeh Documents.

When a Bokeh server session is initiated, the Bokeh server asks the Application
for a new Document to service the session. To do this, the Application first
creates a new empty Document, then it passes this new Document to the
``modify_document`` method of each of its handlers. When all handlers have
updated the Document, it is used to service the user session.

    )annotationsN)ABCMetaabstractmethod)TYPE_CHECKINGAny	AwaitableCallableClassVar   )ID)Document)settings)HTTPServerRequest)	TypeAlias)ServerSession   )Handler)ApplicationServerContextSessionContextr   Callbackc                      e Zd ZU dZdZded<   ded<   ded<   d	ed
<   ddd+dZed,d            Zed-d            Z	ed.d            Z
ed/d            Zd0dZd1dZd2dZd3d!Zd3d"Zd4d%Zd4d&Zd5d*ZdS )6r   z: An Application is a factory for Document instances.

    TzClassVar[bool]_is_a_bokeh_application_class
str | None_static_pathzlist[Handler]	_handlersdict[str, Any] | None	_metadataN)metadatahandlersr   r   returnNonec               d    d| _         g | _        || _        |D ]}|                     |           dS )a?   Application factory.

        Args:
            handlers (seq[Handler]): List of handlers to call.
                The URL is taken from the first one only.

        Keyword Args:
            metadata (dict): arbitrary user-supplied JSON data to make available
                with the application.

                The server will provide a URL ``http://applicationurl/metadata``
                which returns a JSON blob of the form:

                .. code-block:: json

                    {
                        "data": {
                            "hi": "hi",
                            "there": "there"
                        },
                        "url": "/myapp"
                    }

                The user-supplied metadata is returned as-is under the
                ``"data"`` key in the blob.

        N)r   r   r   add)selfr   r    hs       =lib/python3.11/site-packages/bokeh/application/application.py__init__zApplication.__init__X   sD    8 !! 	 	AHHQKKKK	 	    tuple[Handler, ...]c                *    t          | j                  S )zL The ordered list of handlers this Application is configured with.

        )tupler   r%   s    r'   r    zApplication.handlers|   s    
 T^$$$r)   c                    | j         S )zO Arbitrary user-supplied metadata to associate with this application.

        )r   r-   s    r'   r   zApplication.metadata   s    
 ~r)   boolc                >    t          d | j        D                       S )


        c              3  $   K   | ]}|j         V  d S )N)safe_to_fork).0handlers     r'   	<genexpr>z+Application.safe_to_fork.<locals>.<genexpr>   s%      FFG7'FFFFFFr)   )allr   r-   s    r'   r3   zApplication.safe_to_fork   s#    
 FFt~FFFFFFr)   c                    | j         S )zI Path to any (optional) static resources specified by handlers.

        )r   r-   s    r'   static_pathzApplication.static_path   s    
   r)   r5   c                T   | j                             |           d | j        D             }|                    d           t	          |          dk    rt          dt          |          z            t	          |          dk    r|                                | _        dS d| _        dS )z Add a handler to the pipeline used to initialize new documents.

        Args:
            handler (Handler) : a handler for this Application to use to
                process Documents

        c                6    h | ]}|                                 S  )r9   )r4   r&   s     r'   	<setcomp>z"Application.add.<locals>.<setcomp>   s     ???A???r)   Nr   z/More than one static path requested for app: %r)	r   appendr    discardlenRuntimeErrorlistpopr   )r%   r5   static_pathss      r'   r$   zApplication.add   s     	g&&& @????T"""|q  PSWXdSeSeefff!## , 0 0 2 2D $Dr)   r   c                L    t                      }|                     |           |S )zO Creates and initializes a document using the Application's handlers.

        )r   initialize_document)r%   docs     r'   create_documentzApplication.create_document   s&     jj  %%%
r)   rG   c                    | j         D ]E}|                    |           |j        r't                              d||j        |j                   Ft          j                    r|                                 dS dS )zD Fills in a new document using the Application's handlers.

        z,Error running application handler %r: %s %s N)	r   modify_documentfailedlogerrorerror_detailr   perform_document_validationvalidate)r%   rG   r&   s      r'   rF   zApplication.initialize_document   s      	f 	fA c"""x f		H!QWVWVdeee/11 	LLNNNNN	 	r)   server_contextr   c                D    | j         D ]}|                    |           dS )z Invoked to execute code when a new session is created.

        This method calls ``on_server_loaded`` on each handler, in order,
        with the server context passed as the only argument.

        N)r   on_server_loadedr%   rQ   r&   s      r'   rS   zApplication.on_server_loaded   s6      	/ 	/A~....	/ 	/r)   c                D    | j         D ]}|                    |           dS )a{   Invoked to execute code when the server cleanly exits. (Before
        stopping the server's ``IOLoop``.)

        This method calls ``on_server_unloaded`` on each handler, in order,
        with the server context passed as the only argument.

        .. warning::
            In practice this code may not run, since servers are often killed
            by a signal.

        N)r   on_server_unloadedrT   s      r'   rV   zApplication.on_server_unloaded   s6      	1 	1A  0000	1 	1r)   session_contextr   c                T   K   | j         D ]}|                    |           d{V  dS )a7   Invoked to execute code when a new session is created.

        This method calls ``on_session_created`` on each handler, in order,
        with the session context passed as the only argument.

        May return a ``Future`` which will delay session creation until the
        ``Future`` completes.

        N)r   on_session_createdr%   rW   r&   s      r'   rY   zApplication.on_session_created   sG        	8 	8A&&7777777777tr)   c                T   K   | j         D ]}|                    |           d{V  dS )a   Invoked to execute code when a session is destroyed.

        This method calls ``on_session_destroyed`` on each handler, in order,
        with the session context passed as the only argument.

        Afterwards, ``session_context.destroyed`` will be ``True``.

        N)r   on_session_destroyedrZ   s      r'   r\   z Application.on_session_destroyed   sG        	: 	:A((9999999999tr)   requestr   dict[str, Any]c                n    i }| j         D ]*}|                    |                    |                     +|S )a#   Processes incoming HTTP request returning a dictionary of
        additional data to add to the session_context.

        Args:
            request: HTTP request

        Returns:
            A dictionary of JSON serializable data to be included on
            the session context.
        )r   updateprocess_request)r%   r]   request_datar&   s       r'   ra   zApplication.process_request   sE     (* 	< 	<A 1 1' : :;;;;r)   )r    r   r   r   r!   r"   )r!   r*   )r!   r   r!   r/   )r!   r   )r5   r   r!   r"   )r!   r   )rG   r   r!   r"   )rQ   r   r!   r"   )rW   r   r!   r"   )r]   r   r!   r^   )__name__
__module____qualname____doc__r   __annotations__r(   propertyr    r   r3   r9   r$   rH   rF   rS   rV   rY   r\   ra   r<   r)   r'   r   r   I   s          59!8888$$$$MQ            H % % % X%    X G G G XG ! ! ! X!% % % %(      / / / /1 1 1 1           r)   r   c                  :    e Zd ZdZeedd                        ZdS )r   z A harness for server-specific information and tasks related to
    collections of Bokeh sessions.

    *This base class is probably not of interest to general users.*

    r!   list[ServerSession]c                    dS )zx ``SessionContext`` instances belonging to this application.

        *Subclasses must implement this method.*

        Nr<   r-   s    r'   sessionszServerContext.sessions  s	     	r)   N)r!   rk   )rd   re   rf   rg   ri   r   rm   r<   r)   r'   r   r   
  sH             ^ X  r)   r   )	metaclassc                      e Zd ZU dZded<   ded<   dd
Zeedd                        Zedd            Z	edd            Z
edd            ZdS )r   z A harness for server-specific information and tasks related to
    Bokeh sessions.

    *This base class is probably not of interest to general users.*

    r   _server_contextr   _idrQ   
session_idr!   r"   c                "    || _         || _        dS )r1   N)rp   rq   )r%   rQ   rr   s      r'   r(   zSessionContext.__init__)  s      .r)   r/   c                    dS )z If ``True``, the session has been discarded and cannot be used.

        A new session with the same ID could be created later but this instance
        will not come back to life.

        Nr<   r-   s    r'   	destroyedzSessionContext.destroyed2  s	     	r)   c                    | j         S )zF The unique ID for the session associated with this context.

        )rq   r-   s    r'   idzSessionContext.id=  s    
 xr)   c                    | j         S )z6 The server context for this session context

        )rp   r-   s    r'   rQ   zSessionContext.server_contextD  s    
 ##r)   func%Callable[[Document], Awaitable[None]]Awaitable[None]c                    dS )a   Runs a function with the document lock held, passing the
        document to the function.

        *Subclasses must implement this method.*

        Args:
            func (callable): function that takes a single parameter (the Document)
                and returns ``None`` or a ``Future``

        Returns:
            a ``Future`` containing the result of the function

        Nr<   )r%   ry   s     r'   with_locked_documentz#SessionContext.with_locked_documentM  s	     	r)   N)rQ   r   rr   r   r!   r"   rc   )r!   r   )r!   r   )ry   rz   r!   r{   )rd   re   rf   rg   rh   r(   ri   r   ru   rw   rQ   r}   r<   r)   r'   r   r     s           #"""GGG       ^ X    X $ $ $ X$    ^  r)   r   )$rg   
__future__r   logging	getLoggerrd   rL   abcr   r   typingr   r   r   r	   r
   
core.typesr   documentr   r   tornado.httputilr   typing_extensionsr   server.sessionr   handlers.handlerr   __all__r   rh   r   r   r   SessionDestroyedCallbackr<   r)   r'   <module>r      s  
 
 
 # " " " " " g!! ( ' ' ' ' ' ' '                                *222222++++++......)))))) r4x( ( ( ( (~ ~ ~ ~ ~ ~ ~ ~B    g    (> > > > >w > > > >@ $^$4d$:;   r)   