B
    ZM	                 @   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)releasezhttp://www.statsmodels.org/c             C   s   t }|r|d7 }n|d7 }| dkr&|S t| tkrT|d7 }|td| i7 }|d7 }nRyB| }|j}|j}|dsxtdS |d	7 }||d
 | d 7 }W n   tdS |S )zn
    Parse inputs and return a correctly formatted URL or an error 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typestrr   __name__
__module__
startswith
ValueError)argstableZurlfuncZ	func_nameZfunc_module r   4lib/python3.7/site-packages/statsmodels/tools/web.py_generate_url   s*    


r   c             C   s6   |dkrt n|}t| |}t|tr(|t| dS )a  
    Opens a browser and displays online documentation

    Parameters
    ----------
    arg, optional : string or statsmodels function
        Either a string to search the documentation or a function
    stable, optional : 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
    >>> sm.webdoc()  # Documention site
    >>> sm.webdoc('glm')  # Search for glm in docs
    >>> sm.webdoc(sm.OLS, stable=False)  # Go to generated help for OLS, devel

    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.
    N)r   r   
isinstancer   
webbrowseropen)r   r   Zurl_or_errorr   r   r   webdoc,   s    


r   )NN)	__doc__r   Zstatsmodels.compat.pythonr   Zstatsmodels.versionr   r   r   r   r   r   r   r   <module>   s   