σ
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 m Z m Z d d l m Z d d l m Z d	 d
 l m Z d Z d e f d     YZ d S(   u©  
To generate standalone SVGs for a Bokeh application from a single
Python script, pass the script name to ``bokeh svg`` on the command
line:

.. code-block:: sh

    bokeh svg app_script.py

The generated SVGs will be saved in the current working directory with
the name ``app_script.svg``. If there are multiple SVGs within an application,
the subsequent ones will be named ``app_script_1.svg``, ``app_script_2.svg``,
etc.

It is also possible to run the same commmand with jupyter notebooks:

.. code-block:: sh

    bokeh svg app_notebook.ipynb

This will generate SVG files named ``app_notebook_{n}.svg`` just like
with a python script.

Applications can also be created from directories. The directory should
contain a ``main.py`` (and any other helper modules that are required) as
well as any additional assets (e.g., theme files). Pass the directory name
to ``bokeh svg`` to generate the SVG:

.. code-block:: sh

    bokeh svg app_dir

It is possible to generate SVG files for multiple applications at once:

.. code-block:: sh

    bokeh svg app_script.py app_dir

For all cases, it's required to explicitly add a Bokeh layout to
``bokeh.io.curdoc`` for it to appear in the output.

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNi   (   t   get_svgst   create_webdrivert   terminate_webdriveri   (   t   set_single_plot_width_height(   t   decode_utf8i   (   t   FileOutputSubcommandu   SVGt   SVGc           B` s   e  Z d  Z d Z d Z d Z e j d  d e d d d e	 d d	 d
 d  f d e d d d e	 d d d
 d  f f e j   Z d   Z d   Z d   Z RS(   uA    Subcommand to output applications as standalone SVG files.

    u   svgu8   Create standalone SVG files for one or more applicationsu   SVGu   --heightt   metavaru   HEIGHTt   typet   helpuJ   The desired height of the exported layout obj only if it's a Plot instancet   defaultu   --widthu   WIDTHuI   The desired width of the exported layout obj only if it's a Plot instancec         C` s;   t    |  _ z t t |   j |  Wd t |  j  Xd S(   u
   

        N(   R   t   drivert   superR
   t   invokeR   (   t   selft   args(    (    s<   lib/python2.7/site-packages/bokeh/command/subcommands/svg.pyR   x   s    c   	      C` sά   |  j  | |  } xΓ t |  D]΅ \ } } | d k rJ t t |   nw | d k r_ | } n. | j d  } | |  d j |  | | } t j | d d d  } | j t |   Wd QX|  j	 | | |  q Wd S(	   u
   

        u   -i    u   .svgu   _{}u   wt   encodingu   utf-8N(
   t   file_contentst	   enumeratet   printR   t   findt   formatt   iot   opent   writet   after_write_file(	   R   R   t   filenamet   doct   contentst   it   svgt   idxt   f(    (    s<   lib/python2.7/site-packages/bokeh/command/subcommands/svg.pyt
   write_file   s    	c         C` s/   t  | d | j d | j t | d |  j S(   u
   

        t   widtht   heightR   (   R   R&   R'   R   R   (   R   R   R   (    (    s<   lib/python2.7/site-packages/bokeh/command/subcommands/svg.pyR      s    N(   t   __name__t
   __module__t   __doc__t   namet	   extensionR   R	   t	   files_argt   dictt   intt   Nonet
   other_argsR   R   R%   R   (    (    (    s<   lib/python2.7/site-packages/bokeh/command/subcommands/svg.pyR
   W   s&   				
	(   u   SVG(   R*   t
   __future__R    R   R   R   t   loggingt	   getLoggerR(   t   logR   t	   io.exportR   R   R   t   utilR   t   util.stringR   t   file_outputR	   t   __all__R
   (    (    (    s<   lib/python2.7/site-packages/bokeh/command/subcommands/svg.pyt   <module>0   s   "