B
    @\
                 @   s   d Z ddlmZmZmZmZ ddlZe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G dd deZdS )a  
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.

    )absolute_importdivisionprint_functionunicode_literalsN   )get_svgscreate_webdriverterminate_webdriver   )set_single_plot_width_height)decode_utf8   )FileOutputSubcommand)SVGc            	       st   e Zd ZdZdZdZdZed de	de
dddfd	e	d
e
dddffe  Z fddZdd Zdd Z  ZS )r   zA Subcommand to output applications as standalone SVG files.

    svgz8Create standalone SVG files for one or more applicationsz--heightZHEIGHTzJThe desired height of the exported layout obj only if it's a Plot instanceN)metavartypehelpdefaultz--widthZWIDTHzIThe desired width of the exported layout obj only if it's a Plot instancec                s.   t  | _ztt| | W dt| j X dS )z


        N)r   driversuperr   invoker	   )selfargs)	__class__ <lib/python3.7/site-packages/bokeh/command/subcommands/svg.pyr   x   s    z
SVG.invokec       	   
   C   s   |  ||}xt|D ]\}}|dkr4tt| nd|dkrB|}n,|d}|d| d| ||d  }tj|ddd}|t| W dQ R X | 	||| qW dS )	z


        -r   z.svgNz_{}wzutf-8)encoding)
file_contents	enumerateprintr   findformatioopenwriteZafter_write_file)	r   r   filenamedoccontentsir   idxfr   r   r   
write_file   s    
"zSVG.write_filec             C   s    t ||j|jd t|| jdS )z


        )widthheight)r   )r   r/   r0   r   r   )r   r   r)   r   r   r   r       s    zSVG.file_contents)__name__
__module____qualname____doc__name	extensionr   r   Z	files_argdictintZ
other_argsr   r   r.   r    __classcell__r   r   )r   r   r   W   s&   


r   )r4   Z
__future__r   r   r   r   ZloggingZ	getLoggerr1   logr%   Z	io.exportr   r   r	   utilr   Zutil.stringr   Zfile_outputr   __all__r   r   r   r   r   <module>0   s   
