
mJ]c           @` sc   d  Z  d d l m Z m Z m Z m Z d d l Z e j e  Z	 d Z
 d e f d     YZ d S(   u   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

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNu   Handlert   Handlerc           B` s   e  Z d  Z d   Z e d    Z e d    Z e d    Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z RS(   uW    Provide a mechanism for Bokeh applications to build up new Bokeh
    Documents.


    c         O` s(   t  |  _ d  |  _ d  |  _ d  |  _ d  S(   N(   t   Falset   _failedt   Nonet   _errort   _error_detailt   _static(   t   selft   argst   kwargs(    (    sA   lib/python2.7/site-packages/bokeh/application/handlers/handler.pyt   __init__N   s    			c         C` s   |  j  S(   uE    If the handler fails, may contain a related error message.

        (   R   (   R   (    (    sA   lib/python2.7/site-packages/bokeh/application/handlers/handler.pyt   errorV   s    c         C` s   |  j  S(   uJ    If the handler fails, may contain a traceback or other details.

        (   R	   (   R   (    (    sA   lib/python2.7/site-packages/bokeh/application/handlers/handler.pyt   error_detail]   s    c         C` s   |  j  S(   u;    ``True`` if the handler failed to modify the doc

        (   R   (   R   (    (    sA   lib/python2.7/site-packages/bokeh/application/handlers/handler.pyt   failedd   s    c         C` s   t  d   d S(   u   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

        u   implement modify_document()N(   t   NotImplementedError(   R   t   doc(    (    sA   lib/python2.7/site-packages/bokeh/application/handlers/handler.pyt   modify_documentm   s    c         C` s   d S(   u.   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) :

        N(    (   R   t   server_context(    (    sA   lib/python2.7/site-packages/bokeh/application/handlers/handler.pyt   on_server_loaded   s    c         C` s   d S(   u   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.

        N(    (   R   R   (    (    sA   lib/python2.7/site-packages/bokeh/application/handlers/handler.pyt   on_server_unloaded   s    c         C` s   d S(   u#   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) :

        N(    (   R   t   session_context(    (    sA   lib/python2.7/site-packages/bokeh/application/handlers/handler.pyt   on_session_created   s    c         C` s   d S(   u    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) :

        N(    (   R   R   (    (    sA   lib/python2.7/site-packages/bokeh/application/handlers/handler.pyt   on_session_destroyed   s    
c         C` s   |  j  r d S|  j Sd S(   uI    Return a path to app-specific static resources, if applicable.

        N(   R   R   R
   (   R   (    (    sA   lib/python2.7/site-packages/bokeh/application/handlers/handler.pyt   static_path   s    	c         C` s   d S(   uR   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.

        N(   R   (   R   (    (    sA   lib/python2.7/site-packages/bokeh/application/handlers/handler.pyt   url_path   s    
(   t   __name__t
   __module__t   __doc__R   t   propertyR   R   R   R   R   R   R   R   R   R   (    (    (    sA   lib/python2.7/site-packages/bokeh/application/handlers/handler.pyR   G   s   									(   u   Handler(   R   t
   __future__R    R   R   R   t   loggingt	   getLoggerR   t   logt   __all__t   objectR   (    (    (    sA   lib/python2.7/site-packages/bokeh/application/handlers/handler.pyt   <module>#   s
   "