ó
±éRc           @  s¼   d  Z  d d l m Z d d l Z d d l m Z m Z d d l m Z m	 Z	 m
 Z
 d d l m Z m Z d d l m Z e j d ƒ Z d	 e f d
 „  ƒ  YZ d „  Z e ƒ  e j d <d S(   sö   reST directive for syntax-highlighting ipython interactive sessions.

XXX - See what improvements can be made based on the new (as of Sept 2009)
'pycon' lexer for the python console.  At the very least it will give better
highlighted tracebacks.
iÿÿÿÿ(   t   print_functionN(   t   Lexert   do_insertions(   t   PythonConsoleLexert   PythonLexert   PythonTracebackLexer(   t   Commentt   Generic(   t   highlightings   .*?
t   IPythonConsoleLexerc           B  sk   e  Z d  Z d Z d g Z d g Z e j d ƒ Z e j d ƒ Z	 e j d ƒ Z
 e j d ƒ Z d „  Z RS(	   sN  
    For IPython console output or doctests, such as:

    .. sourcecode:: ipython

      In [1]: a = 'foo'

      In [2]: a
      Out[2]: 'foo'

      In [3]: print a
      foo

      In [4]: 1 / 0

    Notes:

      - Tracebacks are not currently supported.

      - It assumes the default IPython prompts, not customized ones.
    s   IPython console sessiont   ipythons   text/x-ipython-consoles   (In \[[0-9]+\]: )|(   \.\.\.+:)s   (Out\[[0-9]+\]: )|(   \.\.\.+:)s      \.\.\.+:s   \-+c         c  s?  t  |  j �  } t |  j �  } d } g  } xÝt j | ƒ D]Ì} | j ƒ  } |  j j | ƒ } |  j j | j	 ƒ  ƒ }	 |  j
 j | ƒ }
 | j d ƒ r¿ | j t | ƒ d t | f g f ƒ q: | d  k	 r| j t | ƒ d t j | j ƒ  f g f ƒ | | | j ƒ  7} q: |	 d  k	 ra| j t | ƒ d t j |	 j ƒ  f g f ƒ | | |	 j ƒ  7} q: |
 d  k	 r²| j t | ƒ d t j |
 j ƒ  f g f ƒ | | |
 j ƒ  7} q: | rïx4 t | | j | ƒ ƒ D] } | Vd } g  } qÑWn  | j ƒ  t j | f Vq: W| r;x( t | | j | ƒ ƒ D] } | Vq)Wn  d  S(   Nt    t   #i    (   R   t   optionsR   t   line_ret   finditert   groupt   input_promptt   matcht   continue_promptt   rstript   output_promptt
   startswitht   appendt   lenR   t   NoneR   t   Promptt   endt   ErrorR   t   get_tokens_unprocessedt   startt   Output(   t   selft   textt   pylexert   tblexert   curcodet
   insertionsR   t   lineR   R   R   t   item(    (    sk   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/sphinxext/ipython_console_highlighting.pyR   =   sF    		(   t   __name__t
   __module__t   __doc__t   namet   aliasest	   mimetypest   ret   compileR   R   R   t   tb_startR   (    (    (    sk   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/sphinxext/ipython_console_highlighting.pyR	      s   		c         C  s   d S(   s   Setup as a sphinx extension.N(    (   t   app(    (    sk   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/sphinxext/ipython_console_highlighting.pyt   setuph   s    R
   (   R*   t
   __future__R    R.   t   pygments.lexerR   R   t   pygments.lexers.agileR   R   R   t   pygments.tokenR   R   t   sphinxR   R/   R   R	   R2   t   lexers(    (    (    sk   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/sphinxext/ipython_console_highlighting.pyt   <module>   s   J	