B
    dH                 @   sv   d Z ddlZddlZddlZddlZddlmZ ddlmZ ej	de
dd dd
dZdddZdd ZdddZdS )zH
mpld3 Utilities
===============
Utility routines for the mpld3 package
    N)wraps   )urlsalwaysZmpld3)categorymoduleFc             C   s&   |rt d|  S tt d| S dS )zxCheck whether objid is valid as an HTML id attribute.

    If html5 == True, then use the more liberal html5 rules.
    z\sz^[a-zA-Z][a-zA-Z0-9\-\.\:\_]*$N)researchboolmatch)objidhtml5 r   X/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/mpld3/utils.py
html_id_ok   s    r    elTc             C   sJ   |sd}|sd}|t t  t t|  | }|rFt|sFtd |S )zGet a unique id for the objectr   z5"{0}" is not a valid html ID. This may cause problems)strosgetpididr   warningswarn)objsuffixprefixZwarn_on_invalidr   r   r   r   get_id   s     
r   c                s0   t   fdd}df |j |_|S )z*Decorator to mark functions as deprecated.c                 s    t jdtd  | |S )Nz7{0} is deprecated and will be removed.  Use {1} instead)r   )r   r   formatDeprecationWarning)argskwargs)funcnew_nameold_namer   r   new_func.   s    zdeprecated.<locals>.new_funcz(*%s is deprecated: use %s instead*

    )r   __doc__)r!   r#   r"   r$   r   )r!   r"   r#   r   
deprecated,   s    r&   c          
      s  | dkr@yddl m  W n  tk
r8   t } d}Y qDX d}nd}|dkrRtj}|dkr`tj}tj	|}tj	|}tj
|std|tj
|std||rVd} fd	d
}y|||g W n tk
rR   ddlm} tj| d}	x@||gD ]4}
tj|	tj	|
}tj
|r
t| q
W |||g Y nX nd}tj| |}tj| |}xj||f||fgD ]V\}
}yt|
| W n: tk
r   tj
|rt| t|
| Y nX qW || || fS )a  
    Write the mpld3 and d3 javascript libraries to the given file location.

    This utility is used by the IPython notebook tools to enable easy use
    of mpld3 with no web connection.

    Parameters
    ----------
    location : string (optioal)
        the directory in which the d3 and mpld3 javascript libraries will be
        written. If not specified, the IPython nbextensions directory will be
        used. If IPython doesn't support nbextensions (< 2.0),
        the current working directory will be used.
    d3_src : string (optional)
        the source location of the d3 library. If not specified, the standard
        path in mpld3.urls.D3_LOCAL will be used.
    mpld3_src : string (optional)
        the source location of the mpld3 library. If not specified, the
        standard path in mpld3.urls.MPLD3_LOCAL will be used.

    Returns
    -------
    d3_url, mpld3_url : string
        The URLs to be used for loading these js files.
    Nr   )install_nbextensionFTzd3 src not found at '{0}'zmpld3 src not found at '{0}'z/nbextensions/c                s:   ddl }|jd dkr.x| D ]} | qW n |  dS )z-Wrapper for IPython.html.install_nbextension.r   N   )IPythonversion_info)
extensionsr)   	extension)r'   r   r   _install_nbextensionp   s
    
z2write_ipynb_local_js.<locals>._install_nbextension)get_ipython_dirZnbextensionsz/files/)ZIPython.htmlr'   ImportErrorr   getcwdr   ZD3_LOCALZMPLD3_LOCALpathbasenameexists
ValueErrorr   IOErrorZIPython.utils.pathr.   joinremoveshutilcopyfile)locationZd3_srcZ	mpld3_srcZnbextensionZd3jsZmpld3jsr   r-   r.   ZnbextsrcdestZd3_destZ
mpld3_destr   )r'   r   write_ipynb_local_js9   sT    
	
r=   )F)r   r   T)NNN)r%   r   r   r8   r   	functoolsr   r   r   filterwarningsr   r   r   r&   r=   r   r   r   r   <module>   s   

