B
    @\                 @   sF   d Z ddlmZmZmZmZ ddlZeeZ	dZ
G dd deZdS )a   Provide a base class for Bokeh Application handler classes.

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.

Below is an example outline of a custom handler that might modify documents
based off information in some database:

.. code-block:: python

    class DatabaseHandler(Handler):
        """ A Bokeh Application handler to initialize Documents from a database

        """

        def modify_document(self, doc):

            # do some data base lookup here to generate 'plot'

            # add the plot to the document (i.e modify the document)
            doc.add_root(plot)

            # and return it
            return doc

    )absolute_importdivisionprint_functionunicode_literalsN)Handlerc               @   st   e Zd ZdZdd Zedd Zedd Zedd	 Zd
d Z	dd Z
dd Zdd Zdd Zdd Zdd ZdS )r   zW Provide a mechanism for Bokeh applications to build up new Bokeh
    Documents.


    c             O   s   d| _ d | _d | _d | _d S )NF)_failed_error_error_detail_static)selfargskwargs r   Alib/python3.7/site-packages/bokeh/application/handlers/handler.py__init__N   s    zHandler.__init__c             C   s   | j S )zE If the handler fails, may contain a related error message.

        )r   )r   r   r   r   errorV   s    zHandler.errorc             C   s   | j S )zJ If the handler fails, may contain a traceback or other details.

        )r	   )r   r   r   r   error_detail]   s    zHandler.error_detailc             C   s   | j S )z; ``True`` if the handler failed to modify the doc

        )r   )r   r   r   r   failedd   s    zHandler.failedc             C   s   t ddS )a   Modify an application document in a specified manner.

        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 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.

        *Subclasses must implement this method*

        Args:
            doc (Document) : A Bokeh Document to update in-place

        Returns:
            Document

        zimplement modify_document()N)NotImplementedError)r   docr   r   r   modify_documentm   s    zHandler.modify_documentc             C   s   dS )a.   Execute code when the server is first started.

        Subclasses may implement this method to provide for any one-time
        initialization that is necessary after the server starts, but
        before any sessions are created.

        Args:
            server_context (ServerContext) :

        Nr   )r   server_contextr   r   r   on_server_loaded   s    zHandler.on_server_loadedc             C   s   dS )a   Execute code when the server cleanly exits. (Before stopping the
        server's ``IOLoop``.)

        Subclasses may implement this method to provide for any one-time
        tear down that is necessary before the server exits.

        Args:
            server_context (ServerContext) :

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

        Nr   )r   r   r   r   r   on_server_unloaded   s    zHandler.on_server_unloadedc             C   s   dS )a#   Execute code when a new session is created.

        Subclasses may implement this method to provide for any per-session
        initialization that is necessary before ``modify_doc`` is called for
        the session.

        Args:
            session_context (SessionContext) :

        Nr   )r   session_contextr   r   r   on_session_created   s    zHandler.on_session_createdc             C   s   dS )a    Execute code when a session is destroyed.

        Subclasses may implement this method to provide for any per-session
        tear-down that is necessary when sessions are destroyed.

        Args:
            session_context (SessionContext) :

        Nr   )r   r   r   r   r   on_session_destroyed   s    
zHandler.on_session_destroyedc             C   s   | j r
dS | jS dS )zI Return a path to app-specific static resources, if applicable.

        N)r   r
   )r   r   r   r   static_path   s    zHandler.static_pathc             C   s   dS )aR   Returns a default URL path, if applicable.

        Handlers subclasses may optionally implement this method, to inform
        the Bokeh application what URL it should be installed at.

        If multiple handlers specify ``url_path`` the Application will use the
        value from the first handler in its list of handlers.

        Nr   )r   r   r   r   url_path   s    
zHandler.url_pathN)__name__
__module____qualname____doc__r   propertyr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   G   s   		r   )r"   Z
__future__r   r   r   r   ZloggingZ	getLoggerr   log__all__objectr   r   r   r   r   <module>#   s
   
