U
    KvfÁ  ã                   @   s>   d Z ddlZddlmZ ddlmZ dZdd„ Zd
dd	„ZdS )zj
Provides a function to open the system browser to either search or go directly
to a function's reference
é    N)Ú	urlencode)Ú__version__zhttps://www.statsmodels.org/c                 C   s¶   t }|r|d7 }n|d7 }| dkr&|S t| tƒrR|d7 }|td| iƒ7 }|d7 }n`zB| } | j}| j}| d¡svtdƒ‚|d	7 }||d
 | d 7 }W n tk
r°   tdƒ‚Y nX |S )zw
    Parse inputs and return a correctly formatted URL or raises ValueError
    if the input is not understandable
    zstable/zdevel/Nzsearch.html?Úqz &check_keywords=yes&area=defaultzstatsmodels.z!Function must be from statsmodelsz
generated/Ú.z.htmlzInput not understood)	ÚBASE_URLÚ
isinstanceÚstrr   Ú__name__Ú
__module__Ú
startswithÚ
ValueErrorÚAttributeError)ÚfuncÚstableÚurlÚ	func_nameZfunc_module© r   ú9/tmp/pip-unpacked-wheel-2v6byqio/statsmodels/tools/web.pyÚ_generate_url   s*    



r   c                 C   s(   dt krt n|}t| |ƒ}t |¡ dS )ay  
    Opens a browser and displays online documentation

    Parameters
    ----------
    func : {str, callable}
        Either a string to search the documentation or a function
    stable : bool
        Flag indicating whether to use the stable documentation (True) or
        the development documentation (False).  If not provided, opens
        the stable documentation if the current version of statsmodels is a
        release

    Examples
    --------
    >>> import statsmodels.api as sm

    Documentation site

    >>> sm.webdoc()

    Search for glm in docs

    >>> sm.webdoc('glm')

    Go to current generated help for OLS

    >>> sm.webdoc(sm.OLS, stable=False)

    Notes
    -----
    By default, open stable documentation if the current version of
    statsmodels is a release.  Otherwise opens the development documentation.

    Uses the default system browser.
    ÚdevN)r   r   Ú
webbrowserÚopen)r   r   Zurl_or_errorr   r   r   Úwebdoc,   s    %

r   )NN)	Ú__doc__r   Úurllib.parser   Zstatsmodelsr   r   r   r   r   r   r   r   Ú<module>   s   