ó
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
 Z
 d d l m Z d	 Z d e f d „  ƒ  YZ d S(
   uˆ   Provide a Bokeh Application Handler to build up documents by running
the code from Python script (``.py``) files.

This handler is configured with the filename of a Python module. When a
Bokeh application calls ``modify_doc``, the contents of the module are run to
process a new Document for a session. When the script code is executed, the
Document being modified will be available as ``curdoc``, and any optionally
provided ``args`` will be available as ``sys.argv``.

As an example, consider the following Python module ``myapp.py``

.. code-block:: python

    # myapp.py

    import sys

    from bokeh.io import cudoc
    from bokeh.plotting import figure

    p = figure(x_range=(10, 10), y_range=(10, 10), title=sys.argv[1])

    curdoc().add_root(p)

The a ``ScriptHandler`` configured with this script will modify new Bokeh
Documents by adding an empty plot with a title taken from ``args``.

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNi   (   t   CodeHandleru   ScriptHandlert   ScriptHandlerc           B` s#   e  Z d  Z d Z d Z d „  Z RS(   uD    Modify Bokeh documents by executing code from Python scripts.

    uG   %s: call to %s() ignored when running scripts with the 'bokeh' command.u   Scriptc         O` s¤   d | k r t  d ƒ ‚ n  | d } t j r_ t | d d d ƒ } | j ƒ  | d <Wd QXn( t | d ƒ  } | j ƒ  | d <Wd QXt t |  ƒ j | | Ž  d S(   ua   

        Keywords:
            filename (str) : a path to a Python source (".py") file

        u   filenameu%   Must pass a filename to ScriptHandleru   rt   encodingu   utf-8u   sourceN(   t
   ValueErrort   sixt   PY3t   opent   readt   superR   t   __init__(   t   selft   argst   kwargst   filenamet   f(    (    s@   lib/python2.7/site-packages/bokeh/application/handlers/script.pyR   Q   s    
		(   t   __name__t
   __module__t   __doc__t   _logger_textt   _originR   (    (    (    s@   lib/python2.7/site-packages/bokeh/application/handlers/script.pyR   H   s   (   u   ScriptHandler(   R   t
   __future__R    R   R   R   t   loggingt	   getLoggerR   t   logR   t   codeR   t   __all__R   (    (    (    s@   lib/python2.7/site-packages/bokeh/application/handlers/script.pyt   <module>"   s   "	