U
    /e                  	   @  sN  d Z ddlmZ ddlZeeZddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZmZ ddlmZ ddlmZ ddlmZmZ ddlmZ dZ dZ!d6ddddddddddZ"dddddd d!d"Z#ddd#d$d%d&Z$ddd'd(d)d*d+Z%ddd'dd,d-d.Z&d7dd/d0ddd1d2d3d4d5Z'dS )8z

    )annotationsN)abspath)Tuple)warn)Template   )FILE)PathLike)	LayoutDOM)	ResourcesResourcesLike)settings)Theme   )Statecurstate)default_filenamez
Bokeh Plot)saver
   zPathLike | NonezResourcesLike | Nonez
str | NonezTemplate | NonezState | Nonestr)objfilename	resourcestitletemplatestatereturnc                 C  sD   |dkrt  }|jj}t||||\}}}t| ||||| t|S )a   Save an HTML file with the data for the current document.

    Will fall back to the default output state (or an explicitly provided
    :class:`State` object) for ``filename``, ``resources``, or ``title`` if they
    are not provided. If the filename is not given and not provided via output state,
    it is derived from the script name (e.g. ``/foo/myplot.py`` will create
    ``/foo/myplot.html``)

    Args:
        obj (LayoutDOM object) : a Layout (Row/Column), Plot or Widget object to display

        filename (PathLike, e.g. str, Path, optional) : filename to save document under (default: None)
            If None, use the default state configuration.

        resources (Resources or ResourcesMode, optional) : A Resources config to use (default: None)
            If None, use the default state configuration, if there is one.
            otherwise use ``resources.INLINE``.

        title (str, optional) : a title for the HTML document (default: None)
            If None, use the default state title value, if there is one.
            Otherwise, use "Bokeh Plot"

        template (Template, optional) : HTML document template (default: FILE)
            A Jinja2 Template, see bokeh.core.templates.FILE for the required template
            parameters

        state (State, optional) :
            A :class:`State` object. If None, then the current default
            implicit state is used. (default: None).

    Returns:
        str: the filename where the HTML file is saved.

    N)r   documenttheme_get_save_args_save_helperr   )r   r   r   r   r   r   r    r    3/tmp/pip-unpacked-wheel-f5fndrjf/bokeh/io/saving.pyr   7   s    %r   r   zTuple[PathLike, Resources, str])r   r   r   r   r   c                 C  s0   t | |\}}t| ||}t| ||}|||fS )

    )_get_save_filename_get_save_resources_get_save_title)r   r   r   r   Zis_default_filenamer    r    r!   r   m   s    r   zTuple[PathLike, bool])r   r   r   c                 C  s6   |d k	r|dfS | j r*t s*| j jdfS tddfS )NFhtmlT)filer   Zignore_filenamer   r   )r   r   r    r    r!   r#   z   s
    r#   boolr   )r   r   suppress_warningr   c                 C  sH   |d k	r t |tr|S t|dS | jr.| jjS |s:td tt dS )N)modezosave() called but no resources were supplied and output_file(...) was never called, defaulting to resources.CDN)
isinstancer   r'   r   r   r   )r   r   r)   r    r    r!   r$      s    

r$   )r   r   r)   r   c                 C  s*   |d k	r|S | j r| j jS |s&td tS )Nzosave() called but no title was supplied and output_file(...) was never called, using default title 'Bokeh Plot')r'   r   r   DEFAULT_TITLE)r   r   r)   r    r    r!   r%      s    r%   r	   zResources | NonezTheme | NoneNone)r   r   r   r   r   r   r   c           	   	   C  sJ   ddl m} || |||pt|d}t|ddd}|| W 5 Q R X dS )r"   r   )	file_html)r   r   r   wzutf-8)r*   encodingN)embedr.   r   openwrite)	r   r   r   r   r   r   r.   r&   fr    r    r!   r      s    r   )NNNNN)N)(__doc__
__future__r   logging	getLogger__name__logos.pathr   typingr   warningsr   Zjinja2r   Zcore.templatesr   Z
core.typesr	   Zmodels.layoutsr
   r   r   r   r   Zthemesr   r   r   r   utilr   r,   __all__r   r   r#   r$   r%   r   r    r    r    r!   <module>   s8   
      6	 