σ
§]c           @@ 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   Z d   Z d e _ d e f d     YZ d   Z d a d S(   s   Utility for calling pandoci    (   t   print_functiont   absolute_importN(   t   TextIOWrappert   BytesIO(   t   check_version(   t
   cast_bytest   whichi   (   t   ConversionExceptions   1.12.1s   3.0.0s   utf-8c   	      C@ s   d d | d | g } | r+ | j  |  n  t   t j | d t j d t j } | j t |  |   \ } } t t |  | d  j	   } | j
 d  S(   sG  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.

    t   pandocs   -fs   -tt   stdint   stdoutt   replaces   
(   t   extendt   check_pandoc_versiont
   subprocesst   Popent   PIPEt   communicateR   R   R   t   readt   rstrip(	   t   sourcet   fmtt   tot
   extra_argst   encodingt   cmdt   pt   outt   _(    (    s5   lib/python2.7/site-packages/nbconvert/utils/pandoc.pyR      s    !c          C@ s   t  d k r t d  s$ t    n  t j d d g  }  |  j   } t j d  } x@ | d j	 d d  j
   D] } | j |  rq | a  Pqq qq Wn  t  S(   s{  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.
    R   s   -vs   ^\d+(\.\d+){1,}$i    t   asciiR   N(   t	   __versiont   NoneR   t   PandocMissingR   t   check_outputt
   splitlinest   ret   compilet   decodet   splitt   match(   R   t	   out_linest   version_patternt   tok(    (    s5   lib/python2.7/site-packages/nbconvert/utils/pandoc.pyt   get_pandoc_version>   s    #c          C@ s   t  j d	 k	 r t  j St   }  |  d	 k rE t j d t d d t St |  t	 d t
 } | t  _ | s t j d |  d t	 d t
 d t d d n  | S(
   s   Returns True if pandoc's version meets at least minimal version.

    Raises
    ------
    PandocMissing
      If pandoc is unavailable.
    s   Sorry, we cannot determine the version of pandoc.
Please consider reporting this issue and include theoutput of pandoc --version.
Continuing...t
   stackleveli   t   max_vs5   You are using an unsupported version of pandoc (%s).
s#   Your version must be at least (%s) s   but less than (%s).
sE   Refer to http://pandoc.org/installing.html.
Continuing with doubts...N(   R   t   _cachedR   R+   t   warningst   warnt   RuntimeWarningt   FalseR   t   _minimal_versiont   _maximal_version(   t   vt   ok(    (    s5   lib/python2.7/site-packages/nbconvert/utils/pandoc.pyR   Z   s    			R    c           B@ s   e  Z d  Z d   Z RS(   s(   Exception raised when Pandoc is missing.c         O@ s"   t  t |   j d d d  d  S(   Ns   Pandoc wasn't found.
s'   Please check that pandoc is installed:
s!   http://pandoc.org/installing.html(   t   superR    t   __init__(   t   selft   argst   kwargs(    (    s5   lib/python2.7/site-packages/nbconvert/utils/pandoc.pyR8   ~   s    (   t   __name__t
   __module__t   __doc__R8   (    (    (    s5   lib/python2.7/site-packages/nbconvert/utils/pandoc.pyR    |   s   c           C@ s
   d  a d  S(   N(   R   R   (    (    (    s5   lib/python2.7/site-packages/nbconvert/utils/pandoc.pyt   clean_cache   s    (   R>   t
   __future__R    R   R   R/   R#   t   ioR   R   t   nbconvert.utils.versionR   t   ipython_genutils.py3compatR   R   t
   exceptionsR   R3   R4   R   R   R+   R   R.   R    R?   R   (    (    (    s5   lib/python2.7/site-packages/nbconvert/utils/pandoc.pyt   <module>   s"   )			
	