ó
æNXc        	   @   su  d  Z  d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l m	 Z	 d d l
 m Z m Z d d l m Z m Z m Z e r¥ d d l m Z n d d l m Z d	 Z d
 Z d Z d Z d Z d Z d Z d Z d Z e e e e e e e e e g	 Z d e e j e ƒ f d „  ƒ  YZ d e f d „  ƒ  YZ  d e f d „  ƒ  YZ! d e f d „  ƒ  YZ" d e" f d „  ƒ  YZ# e! j$ d „  ƒ Z% d d „ Z' d „  Z( d „  Z) d  „  Z* d! „  Z+ d" „  Z, d# „  Z- d$ „  Z. i e( e 6e) e 6e* e 6e* e 6e+ e 6e, e 6e- e 6e. e 6Z/ e  j$ d% „  ƒ Z0 e j1 d& ƒ Z2 e j1 d' e j3 ƒ Z4 e ƒ  Z5 e ƒ  Z6 d( „  Z7 d) „  Z8 d* „  Z9 e  j$ d+ „  ƒ Z: e! j$ e; d, „ ƒ Z< d d- „ Z= e! j$ d. „  ƒ Z> e! j$ d/ „  ƒ Z? e! j$ d0 „  ƒ Z@ e! j$ d1 „  ƒ ZA d2 ZB e j1 d3 jC eB ƒ e j3 ƒ ZD d4 ZE e  j$ d5 „  ƒ ZF e j1 d6 jC eB ƒ e j3 ƒ ZG d7 ZH e  j$ d8 „  ƒ ZI d S(9   sÔ   Input transformer classes to support IPython special syntax.

This includes the machinery to recognise and transform ``%magic`` commands,
``!system`` commands, ``help?`` querying, prompt stripping, and so forth.
iÿÿÿÿN(   t   LineInfo(   t	   tokenize2(   t   cookie_comment_re(   t   with_metaclasst   PY3(   t   generate_tokenst
   untokenizet
   TokenError(   t   StringIOt   !s   !!t   ?s   ??t   %s   %%t   ,t   ;t   /t   InputTransformerc           B   sA   e  Z d  Z e j d „  ƒ Z e j d „  ƒ Z e d „  ƒ Z RS(   s6   Abstract base class for line-based input transformers.c         C   s   d S(   s9  Send a line of input to the transformer, returning the transformed
        input or None if the transformer is waiting for more input.
        
        Must be overridden by subclasses.

        Implementations may raise ``SyntaxError`` if the input is invalid. No
        other exceptions may be raised.
        N(    (   t   selft   line(    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt   push1   s    
c         C   s   d S(   s¥   Return, transformed any lines that the transformer has accumulated,
        and reset its internal state.
        
        Must be overridden by subclasses.
        N(    (   R   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt   reset=   s    c            s%   t  j ˆ  ƒ ‡ ‡  f d †  ƒ } | S(   s‡   Can be used by subclasses as a decorator, to return a factory that
        will allow instantiation with the decorated object.
        c             s   ˆ  ˆ |   S(   N(    (   t   kwargs(   t   clst   func(    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt   transformer_factoryK   s    (   t	   functoolst   wraps(   R   R   R   (    (   R   R   sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt   wrapF   s    !(	   t   __name__t
   __module__t   __doc__t   abct   abstractmethodR   R   t   classmethodR   (    (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyR   .   s   	t   StatelessInputTransformerc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   sD   Wrapper for a stateless input transformer implemented as a function.c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt   __init__S   s    c         C   s   d j  |  j ƒ S(   Ns%   StatelessInputTransformer(func={0!r})(   t   formatR   (   R   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt   __repr__V   s    c         C   s   |  j  | ƒ S(   sQ   Send a line of input to the transformer, returning the
        transformed input.(   R   (   R   R   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyR   Y   s    c         C   s   d S(   s!   No-op - exists for compatibility.N(    (   R   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyR   ^   s    (   R   R   R   R"   R$   R   R   (    (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyR!   Q   s
   			t   CoroutineInputTransformerc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s<   Wrapper for an input transformer implemented as a coroutine.c         K   s    | |   |  _  t |  j  ƒ d  S(   N(   t   corot   next(   R   R&   R   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyR"   d   s    c         C   s   d j  |  j ƒ S(   Ns%   CoroutineInputTransformer(coro={0!r})(   R#   R&   (   R   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyR$   i   s    c         C   s   |  j  j | ƒ S(   s—   Send a line of input to the transformer, returning the
        transformed input or None if the transformer is waiting for more
        input.
        (   R&   t   send(   R   R   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyR   l   s    c         C   s   |  j  j d ƒ S(   sr   Return, transformed any lines that the transformer has
        accumulated, and reset its internal state.
        N(   R&   R(   t   None(   R   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyR   s   s    (   R   R   R   R"   R$   R   R   (    (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyR%   b   s
   			t   TokenInputTransformerc           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sÆ   Wrapper for a token-based input transformer.
    
    func should accept a list of tokens (5-tuples, see tokenize docs), and
    return an iterable which can be passed to tokenize.untokenize().
    c         C   s)   | |  _  d |  _ t |  _ |  j ƒ  d  S(   Nt    (   R   t   current_linet   Falset	   line_usedt   reset_tokenizer(   R   R   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyR"      s    			c         C   s   t  |  j ƒ |  _ d  S(   N(   R   t   get_linet	   tokenizer(   R   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyR/   …   s    c         C   s"   |  j  r t ‚ n  t |  _  |  j S(   N(   R.   R   t   TrueR,   (   R   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyR0   ˆ   s    			c         C   sÜ   |  j  | d 7_  |  j  j ƒ  r, |  j ƒ  St |  _ g  } t } yo xh |  j D]] } | j | ƒ | d } | t j k s | r“ | t j	 k r“ PqN | t j
 k rN t } qN qN WWn t k
 rÎ |  j ƒ  d  SX|  j | ƒ S(   Ns   
i    (   R,   t   isspaceR   R-   R.   R1   t   appendR   t   NEWLINEt   NLt
   ERRORTOKENR2   R   R/   R)   t   output(   R   R   t   tokenst
   stop_at_NLt   intokt   t(    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyR   Ž   s$    
	
$
c         C   s/   d |  _  |  j ƒ  t |  j | ƒ ƒ j d ƒ S(   NR+   s   
(   R,   R/   R   R   t   rstrip(   R   R9   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyR8   ¦   s    	
c         C   s3   |  j  } d |  _  |  j ƒ  | r/ | j d ƒ Sd  S(   NR+   s   
(   R,   R/   R=   (   R   t   l(    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyR   «   s
    		
(	   R   R   R   R"   R/   R0   R   R8   R   (    (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyR*   y   s   					t   assemble_python_linesc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   t  t |  ƒ j d  ƒ d  S(   N(   t   superR?   R"   R)   (   R   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyR"   ³   s    c         C   s
   |  j  ƒ  S(   N(   R   (   R   R9   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyR8   ¶   s    (   R   R   R"   R8   (    (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyR?   ²   s   	c          c   s¤   d }  x— t  rŸ |  V}  |  s	 |  j ƒ  r/ q	 n  g  } xU |  d k	 rŒ |  j d ƒ r{ t |  ƒ r{ | j |  d  ƒ d V}  q8 | j |  ƒ Pq8 Wd j | ƒ }  q	 Wd S(   s4   Join lines following explicit line continuations (\)R+   s   \iÿÿÿÿN(   R2   R3   R)   t   endswitht   has_commentR4   t   join(   R   t   parts(    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt   assemble_logical_lines¹   s    	
c         C   sn   | d k r d n d |  k r$ d n d } d j  | |  g ƒ } | d	 k rY d | | f Sd | | | f Sd	 S(
   sU   Prepares a pinfo(2)/psearch call from a target name and the escape
    (i.e. ? or ??)s   ??t   pinfo2t   *t   psearcht   pinfot    s   %sget_ipython().magic(%r)s:   %sget_ipython().set_next_input(%r);get_ipython().magic(%r)N(   RC   R)   (   t   targett   esct   lspacet
   next_inputt   methodt   arg(    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt   _make_help_callÏ   s    c         C   s)   |  j  j ƒ  j t ƒ } d |  j | f S(   s   Translate lines escaped with: !s   %sget_ipython().system(%r)(   R   t   lstript	   ESC_SHELLt   pre(   t	   line_infot   cmd(    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt
   _tr_systemÝ   s    c         C   s$   |  j  j ƒ  d } d |  j | f S(   s    Translate lines escaped with: !!i   s   %sget_ipython().getoutput(%r)(   R   RR   RT   (   RU   RV   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt   _tr_system2â   s    c         C   s*   |  j  d s d St |  j |  j |  j ƒ S(   s"   Translate lines escaped with: ?/??i   s   get_ipython().show_usage()(   R   RQ   t   ifunRL   RT   (   RU   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt   _tr_helpç   s    c         C   sQ   d } |  j  j t ƒ r |  j  Sd j |  j |  j g ƒ j ƒ  } | |  j | f S(   s   Translate lines escaped with: %s   %sget_ipython().magic(%r)RJ   (   R   t
   startswitht
   ESC_MAGIC2RC   RY   t   the_restt   stripRT   (   RU   t   tplRV   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt	   _tr_magicï   s
    !c         C   s)   d |  j  |  j d j |  j j ƒ  ƒ f S(   s   Translate lines escaped with: ,s
   %s%s("%s")s   ", "(   RT   RY   RC   R]   t   split(   RU   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt	   _tr_quote÷   s    c         C   s   d |  j  |  j |  j f S(   s   Translate lines escaped with: ;s
   %s%s("%s")(   RT   RY   R]   (   RU   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt
   _tr_quote2ü   s    c         C   s)   d |  j  |  j d j |  j j ƒ  ƒ f S(   s   Translate lines escaped with: /s   %s%s(%s)s   , (   RT   RY   RC   R]   Ra   (   RU   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt	   _tr_paren  s    c         C   sG   |  s |  j  ƒ  r |  St |  ƒ } | j t k r6 |  St | j | ƒ S(   sM   Transform escaped commands - %magic, !system, ?help + various autocalls.
    (   R3   R    RL   t   tr(   R   t   lineinf(    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt   escaped_commands  s    s   \s*s  (%{0,2}
                              [a-zA-Z_*][\w*]*        # Variable name
                              (\.[a-zA-Z_*][\w*]*)*   # .etc.etc
                              )
                              (\?\??)$                # ? or ??
                              c         C   sŽ   t  |  ƒ j } t ƒ  } y, x% t | ƒ D] } | j | d ƒ q( WWnC t k
 r‰ } d | j d k ry | j t ƒ qŠ | j t ƒ n X| S(   s5   Helper for has_comment and ends_in_comment_or_string.i    s   multi-line string(	   R   t   readlinet   setR   t   addR   t   argst   _MULTILINE_STRINGt   _MULTILINE_STRUCTURE(   R   Rh   t   toktypesR<   t   e(    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt   _line_tokens)  s    	c         C   s   t  j t |  ƒ k S(   s;  Indicate whether an input line has (i.e. ends in, or is) a comment.

    This uses tokenize, so it can distinguish comments from # inside strings.

    Parameters
    ----------
    src : string
      A single line input string.

    Returns
    -------
    comment : bool
        True if source has a comment.
    (   R   t   COMMENTRp   (   t   src(    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyRB   8  s    c         C   s%   t  |  ƒ } t j | k p$ t | k S(   s  Indicates whether or not an input line ends in a comment or within
    a multiline string.
    
    Parameters
    ----------
    src : string
      A single line input string.

    Returns
    -------
    comment : bool
        True if source ends in a comment or multiline string.
    (   Rp   R   Rq   Rl   (   Rr   Rn   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt   ends_in_comment_or_stringI  s    c         C   s¤   t  j |  ƒ } | d k s' t |  ƒ r+ |  S| j d ƒ } | j d ƒ } t j |  ƒ j d ƒ } |  j ƒ  | j d ƒ k r‹ |  j d ƒ n d } t	 | | | | ƒ S(   s$   Translate lines with ?/?? at the endi   i   i    R
   N(
   t   _help_end_ret   searchR)   Rs   t   groupt   _initial_space_ret   matchR^   R=   RQ   (   R   t   mRK   RL   RM   RN   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt   help_end[  s    0c         c   s!  d } t  j d ƒ } d } xÿ t r| V} x | s> | V} q. W| j t ƒ sn x | d k	 rg | V} qQ Wq n  | j | ƒ rƒ q n  | } g  } d V} x= | d k	 rÕ | j ƒ  d k s¾ |  rÕ | j | ƒ d V} q™ W| j	 d ƒ \ } } } | j
 t ƒ } | | | d j | ƒ f } q Wd S(   s“   Captures & transforms cell magics.
    
    After a cell magic is started, this stores up any lines it gets until it is
    reset (sent None).
    s(   get_ipython().run_cell_magic(%r, %r, %r)s   %%\w+\?R+   RJ   u   
N(   t   ret   compileR2   R[   R\   R)   Rx   R^   R4   t	   partitionRR   RC   (   t   end_on_blank_lineR_   t   cellmagic_help_reR   t   firstt   bodyt
   magic_namet   _(    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt	   cellmagick  s.    		c         c   sö   | d k r |  } n  d } xÔ t rñ | V} | d k r= q n  | j d | d d ƒ\ } } | V} | d k rt q n  |  j d | d d ƒ\ } } | V} | s¥ | rÔ xF | d k	 rÐ |  j d | d d ƒV} q¨ Wq x | d k	 rí | V} q× Wq Wd S(   s  Remove matching input prompts from a block of input.
    
    Parameters
    ----------
    prompt_re : regular expression
        A regular expression matching any input prompt (including continuation)
    initial_re : regular expression, optional
        A regular expression matching only the initial prompt, but not continuation.
        If no initial expression is given, prompt_re will be used everywhere.
        Used mainly for plain Python prompts, where the continuation prompt
        ``...`` is a valid Python expression in Python 3, so shouldn't be stripped.
    
    If initial_re and prompt_re differ,
    only initial_re will be tested against the first line.
    If any prompt is found on the first two lines,
    prompts will be stripped from the rest of the block.
    R+   t   counti   N(   R)   R2   t   subnt   sub(   t	   prompt_ret
   initial_reR   t   outt   n1t   n2(    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt   _strip_prompts“  s$    		 c          C   s+   t  j d ƒ }  t  j d ƒ } t |  | ƒ S(   s:   Strip the >>>/... prompts of the Python interactive shell.s   ^(>>>|\.\.\.)( |$)s	   ^>>>( |$)(   R{   R|   R   (   Rˆ   R‰   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt   classic_promptÄ  s    c          C   s   t  j d ƒ }  t |  ƒ S(   s%   Strip IPython's In [1]:/...: prompts.s   ^(In \[\d+\]: |\s*\.{3,}: ?)(   R{   R|   R   (   Rˆ   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt
   ipy_promptÌ  s    c          c   s¼   t  j d ƒ }  d } x  t r· | V} | d k r7 q n  |  j | ƒ } | rš | j d ƒ } xV | d k	 r– | j | ƒ rŒ | t | ƒ } n  | V} q^ Wq x | d k	 r³ | V} q Wq Wd S(   s­   Remove leading indentation.
    
    If the first line starts with a spaces or tabs, the same whitespace will be
    removed from each following line until it is reset.
    s   ^[ \t]+R+   i    N(   R{   R|   R2   R)   Rx   Rv   R[   t   len(   t   space_reR   Ry   t   space(    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt   leading_indentÔ  s    	c          c   s   d }  xr t  rz |  V}  xD t d ƒ D]6 } |  d k r9 Pn  t j |  ƒ rR d V}  q# |  V}  q# Wx |  d k	 rv |  V}  q` Wq	 Wd S(   s˜   Remove encoding comment if found in first two lines
    
    If the first or second line has the `# coding: utf-8` comment,
    it will be removed.
    R+   i   N(   R2   t   rangeR)   R   Rx   (   R   t   i(    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt   strip_encoding_cookieð  s    	
sÎ   (?P<lhs>(\s*)
    ([\w\.]+)                # Initial identifier
    (\s*,\s*
        \*?[\w\.]+)*         # Further identifiers for unpacking
    \s*?,?                   # Trailing comma
    )
    \s*=\s*
s   {}!\s*(?P<cmd>.*)s    %s = get_ipython().getoutput(%r)c         C   s3   t  j |  ƒ } | d k r |  St | j d d ƒ S(   s<   Transform assignment from system commands (e.g. files = !ls)t   lhsRV   N(   t   assign_system_reRx   R)   t   assign_system_templateRv   (   R   Ry   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt   assign_from_system  s    s   {}%\s*(?P<cmd>.*)s   %s = get_ipython().magic(%r)c         C   s3   t  j |  ƒ } | d k r |  St | j d d ƒ S(   s;   Transform assignment from magic commands (e.g. a = %who_ls)R—   RV   N(   t   assign_magic_reRx   R)   t   assign_magic_templateRv   (   R   Ry   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt   assign_from_magic  s    (J   R   R   R   R{   t   IPython.core.splitinputR    t   IPython.utilsR   t   IPython.utils.openpyR   t   IPython.utils.py3compatR   R   t   IPython.utils.tokenize2R   R   R   t   ioR   RS   t
   ESC_SH_CAPt   ESC_HELPt	   ESC_HELP2t	   ESC_MAGICR\   t	   ESC_QUOTEt
   ESC_QUOTE2t	   ESC_PARENt   ESC_SEQUENCESt   ABCMetat   objectR   R!   R%   R*   R?   R   RE   R)   RQ   RW   RX   RZ   R`   Rb   Rc   Rd   Re   Rg   R|   Rw   t   VERBOSERt   Rl   Rm   Rp   RB   Rs   Rz   R-   R„   R   RŽ   R   R“   R–   t   _assign_patR#   R˜   R™   Rš   R›   Rœ   R   (    (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/inputtransformer.pyt   <module>   sŒ   		"#9							

					'1	