ó
mÜJ]c           @` sƒ   d  Z  d d l m Z m Z m Z m Z d d l Z e j e ƒ Z	 d d l
 m Z d d l m Z d Z d	 e f d
 „  ƒ  YZ d S(   uY   Provide a Bokeh Application Handler to build up documents by running
a specified Python function.

This Handler is not used by the Bokeh server command line tool, but is often
useful if users wish to embed the Bokeh server programmatically:

.. code-block:: python

    def make_doc(doc):

        # do work to modify the document, add plots, widgets, etc.

        return doc

    app = Application(FunctionHandler(make_doc))

    server = Server({'/bkapp': app}, io_loop=IOLoop.current())

    server.start()

For complete examples of this technique, see
:bokeh-tree:`examples/howto/server_embed`

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNi   (   t   _check_callbacki   (   t   Handleru   FunctionHandlert   FunctionHandlerc           B` s/   e  Z d  Z d „  Z e d „  ƒ Z d „  Z RS(   u>   A Handler that accepts a plain python function to use for modifying
    Bokeh Documents.

    For example, the following code configures a handler with a function that
    adds an empty plot to a Document:

    .. code-block:: python

        def add_empty_plot(doc):
            p = figure(x_range=(0,10), y_range=(0, 10))
            doc.add_root(p)
            return doc

        handler = FunctionHandler(add_empty_plot)

    This handler could be configured on an Application, and the Application
    would run this function every time a new session is created.

    c         C` s6   t  t |  ƒ j ƒ  t | d ƒ | |  _ t |  _ d S(   u§  

        Args:
            func (callable) : a function to modify and return a Bokeh Document.
                The function should have the form:

                .. code-block:: python

                    def func(doc):
                        # modify doc
                        return doc

                and it  should return the passed-in document after making any
                modifications in-place.

        u   docN(   u   doc(   t   superR   t   __init__R   t   _funct   Truet   _safe_to_fork(   t   selft   func(    (    sB   lib/python2.7/site-packages/bokeh/application/handlers/function.pyR   Y   s    	c         C` s   |  j  S(   u‹    Whether it is still safe for the Bokeh server to fork new workers.

        ``False`` if ``modify_doc`` has already been called.

        (   R   (   R   (    (    sB   lib/python2.7/site-packages/bokeh/application/handlers/function.pyt   safe_to_forks   s    c         C` s   |  j  | ƒ t |  _ d S(   u     Execute the configured ``func`` to modify the document.

        After this method is first executed, ``safe_to_fork`` will return
        ``False``.

        N(   R	   t   FalseR   (   R   t   doc(    (    sB   lib/python2.7/site-packages/bokeh/application/handlers/function.pyt   modify_document~   s    (   t   __name__t
   __module__t   __doc__R   t   propertyR   R   (    (    (    sB   lib/python2.7/site-packages/bokeh/application/handlers/function.pyR   D   s   	(   u   FunctionHandler(   R   t
   __future__R    R   R   R   t   loggingt	   getLoggerR   t   logt   util.callback_managerR   t   handlerR   t   __all__R   (    (    (    sB   lib/python2.7/site-packages/bokeh/application/handlers/function.pyt   <module>   s   "