B
    Z[                 @   s   d Z ddlmZmZ ddlZddlZddlZddlmZm	Z	 ddl
mZ ddlmZmZ ddlmZ d	Zd
ZdddZdd Zdd ZG dd deZdd ZdadS )zUtility for calling pandoc    )print_functionabsolute_importN)TextIOWrapperBytesIO)check_version)
cast_byteswhich   )ConversionExceptionz1.12.1z2.0.0utf-8c       	      C   sh   dd|d|g}|r| | t  tj|tjtjd}|t| |\}}tt||d	 }|
dS )aG  Convert an input string using pandoc.

    Pandoc converts an input string `from` a format `to` a target format.

    Parameters
    ----------
    source : string
      Input string, assumed to be valid format `from`.
    fmt : string
      The name of the input format (markdown, etc.)
    to : string
      The name of the output format (html, etc.)

    Returns
    -------
    out : unicode
      Output as returned by pandoc.

    Raises
    ------
    PandocMissing
      If pandoc is not installed.
    
    Any error messages generated by pandoc are printed to stderr.

    pandocz-fz-t)stdinstdoutreplace
)extendcheck_pandoc_version
subprocessPopenPIPEZcommunicater   r   r   readrstrip)	sourceZfmttoZ
extra_argsencodingcmdpout_ r   5lib/python3.7/site-packages/nbconvert/utils/pandoc.pyr      s    
r   c              C   sh   t dkrdtdst tddg} |  }td}x,|d dd	 D ]}|
|rL|a P qLW t S )a{  Gets the Pandoc version if Pandoc is installed.
    
    If the minimal version is not met, it will probe Pandoc for its version, cache it and return that value.
    If the minimal version is met, it will return the cached version and stop probing Pandoc 
    (unless :func:`clean_cache()` is called).

    Raises
    ------
    PandocMissing
      If pandoc is unavailable.
    Nr   z-vz^\d+(\.\d+){1,}$r   asciir   )	__versionr   PandocMissingr   Zcheck_output
splitlinesrecompiledecodesplitmatch)r   Z	out_linesZversion_patterntokr   r   r    get_pandoc_version=   s    

r+   c              C   s`   t  } | dkr"tjdtdd dS t| ttd}|s\tjd|  dt  d	t  d
 tdd |S )zReturns True if pandoc's version meets at least minimal version.

    Raises
    ------
    PandocMissing
      If pandoc is unavailable.
    NzSorry, we cannot determine the version of pandoc.
Please consider reporting this issue and include theoutput of pandoc --version.
Continuing...   )
stacklevelF)Zmax_vz5You are using an unsupported version of pandoc (%s).
z#Your version must be at least (%s) zbut less than (%s).
zERefer to http://pandoc.org/installing.html.
Continuing with doubts...)r+   warningswarnRuntimeWarningr   _minimal_version_maximal_version)vokr   r   r    r   Y   s    

r   c                   s    e Zd ZdZ fddZ  ZS )r#   z(Exception raised when Pandoc is missing.c                s   t t| d d S )Nz]Pandoc wasn't found.
Please check that pandoc is installed:
http://pandoc.org/installing.html)superr#   __init__)selfargskwargs)	__class__r   r    r6   v   s    
zPandocMissing.__init__)__name__
__module____qualname____doc__r6   __classcell__r   r   )r:   r    r#   t   s   r#   c               C   s   d a d S )N)r"   r   r   r   r    clean_cache~   s    r@   )Nr   )r>   Z
__future__r   r   r   r.   r%   ior   r   Znbconvert.utils.versionr   Zipython_genutils.py3compatr   r   
exceptionsr
   r1   r2   r   r+   r   r#   r@   r"   r   r   r   r    <module>   s    
)
