ó
æNXc           @@  sç  d  Z  d d l m Z d Z d Z d d l Z d d l Z d d l Z d d l Td d l	 m
 Z
 m Z d d l Z d d l m Z e j d	 ƒ Z d d l Z e j d
 d d d d d d g Z [ e d d g 7Z e Z d
 e e <e d Z d e e <e d Z d e e <e d 7Z d e j d d ƒ f d „  ƒ  YZ d „  Z d „  Z d „  Z d Z d Z e e d e ƒ e e ƒ Z d Z d Z  d  Z! d! Z" d" Z# e e  e! e" e# ƒ Z$ d# Z% e d$ d% ƒ e e% ƒ Z& d& e% Z' e e& e' ƒ Z( e d' e( d( ƒ Z) e e) e( e$ ƒ Z* e j+ j, d k r&d) Z- n d* Z- d+ Z. d, Z/ d- Z0 d. Z1 e e- d/ e- d0 ƒ Z2 e e- d1 e- d2 ƒ Z3 e d3 d4 d5 d6 d7 d8 d9 d: ƒ Z4 d; Z5 e d< d= d> ƒ Z6 e e4 e5 e6 ƒ Z7 e e* e7 e3 e ƒ Z8 e e8 Z9 e e- d? e d@ d ƒ e- dA e dB d ƒ ƒ Z: e d e e2 ƒ Z; e e e; e* e7 e: e ƒ Z< dC „  Z= e> e= e9 e< e0 e1 f ƒ \ Z? Z@ ZA ZB i e= e. ƒ d@ 6e= e/ ƒ dB 6eA d/ 6eB d0 6eA dD 6eB dE 6eA dF 6eB dG 6eA dH 6eB dI 6eA dJ 6eB dK 6eA dL 6eB dM 6eA dN 6eB dO 6eA dP 6eB dQ 6eA dR 6eB dS 6d dT 6d dU 6d dV 6d dW 6ZD i  ZE x d} D] ZF eF eE eF <q2Wi  ZG x d~ D] ZF eF eG eF <qSWe j+ j, d k rx€ dh di dj dk dl dm g D]f ZH eH d0 ZI eB eD eI <eI eE eI <eH d/ ZJ eA eD eJ <eJ eE eJ <eH dB eG eH dB <eH d@ eG eH d@ <q’W[H [I [J d eD dl <d eD dm <n  [= dn ZK d eL f do „  ƒ  YZM dp eL f dq „  ƒ  YZN dr d ds „  ƒ  YZO dt „  ZP du „  ZQ dv „  ZR dw „  ZS dx „  ZT dy „  ZU dz „  ZV eW d{ k rãd| ZX x+ eT eY eX jZ ƒ  ƒ j[ ƒ D] Z\ e\ GHqÑWn  d S(€   sð  Patched version of standard library tokenize, to deal with various bugs.

Based on Python 3.2 code.

Patches:

- Gareth Rees' patch for Python issue #12691 (untokenizing)
  - Except we don't encode the output of untokenize
  - Python 2 compatible syntax, so that it can be byte-compiled at installation
- Newlines in comments and blank lines should be either NL or NEWLINE, depending
  on whether they are in a multi-line statement. Filed as Python issue #17061.
- Export generate_tokens & TokenError
- u and rb literals are allowed under Python 3.3 and above.

------------------------------------------------------------------------------
Tokenization help for Python programs.

tokenize(readline) is a generator that breaks a stream of bytes into
Python tokens.  It decodes the bytes according to PEP-0263 for
determining source file encoding.

It accepts a readline-like method which is called repeatedly to get the
next line of input (or b"" for EOF).  It generates 5-tuples with these
members:

    the token type (see token.py)
    the token (a string)
    the starting (row, column) indices of the token (a 2-tuple of ints)
    the ending (row, column) indices of the token (a 2-tuple of ints)
    the original line (string)

It is designed to match the working of the Python tokenizer exactly, except
that it produces COMMENT tokens for comments and gives type OP for all
operators.  Additionally, all token lists start with an ENCODING token
which tells you which encoding was used to decode the bytes stream.
i    (   t   absolute_imports   Ka-Ping Yee <ping@lfw.org>sp   GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, Skip Montanaro, Raymond Hettinger, Trent Nelson, Michael FoordN(   t   *(   t   lookupt   BOM_UTF8(   t   TextIOWrappers   coding[:=]\s*([-\w.]+)t   COMMENTt   tokenizet   detect_encodingt   NLt
   untokenizet   ENCODINGt	   TokenInfot   generate_tokenst
   TokenErrori   i   i   s   type string start end linec           B@  s   e  Z d  „  Z RS(   c         C@  s.   d |  j  t |  j  f } d |  j d | ƒ S(   Ns   %d (%s)s8   TokenInfo(type=%s, string=%r, start=%r, end=%r, line=%r)t   type(   R   t   tok_namet   _replace(   t   selft   annotated_type(    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/_tokenize_py3.pyt   __repr__D   s    (   t   __name__t
   __module__R   (    (    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/_tokenize_py3.pyR   C   s   c          G@  s   d d j  |  ƒ d S(   Nt   (t   |t   )(   t   join(   t   choices(    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/_tokenize_py3.pyt   groupI   s    c          G@  s   t  |  Œ  d S(   NR   (   R   (   R   (    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/_tokenize_py3.pyt   anyJ   s    c          G@  s   t  |  Œ  d S(   Nt   ?(   R   (   R   (    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/_tokenize_py3.pyt   maybeK   s    s   [ \f\t]*s	   #[^\r\n]*s   \\\r?\ns   \w+s   0[xX][0-9a-fA-F]+s
   0[bB][01]+s   0[oO][0-7]+s   (?:0+|[1-9][0-9]*)s   [eE][-+]?[0-9]+s   [0-9]+\.[0-9]*s   \.[0-9]+s   [0-9]+s
   [0-9]+[jJ]s   [jJ]s   (?:[bB][rR]?|[rR][bB]?|[uU])?s   (?:[bB]?[rR]?)?s   [^'\\]*(?:\\.[^'\\]*)*'s   [^"\\]*(?:\\.[^"\\]*)*"s%   [^'\\]*(?:(?:\\.|'(?!''))[^'\\]*)*'''s%   [^"\\]*(?:(?:\\.|"(?!""))[^"\\]*)*"""s   '''s   """s   '[^\n'\\]*(?:\\.[^\n'\\]*)*'s   "[^\n"\\]*(?:\\.[^\n"\\]*)*"s   \*\*=?s   >>=?s   <<=?s   !=s   //=?s   ->s   [+\-*/%&|^=<>]=?t   ~s   [][(){}]s   \r?\ns   \.\.\.s   [:;.,@]s   '[^\n'\\]*(?:\\.[^\n'\\]*)*t   's   "[^\n"\\]*(?:\\.[^\n"\\]*)*t   "c         C@  s   t  j |  t  j ƒ S(   N(   t   ret   compilet   UNICODE(   t   expr(    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/_tokenize_py3.pyt   _compile‰   s    s   r'''s   r"""s   b'''s   b"""s   R'''s   R"""s   B'''s   B"""s   br'''s   br"""s   bR'''s   bR"""s   Br'''s   Br"""s   BR'''s   BR"""t   rt   Rt   bt   Bs   r's   r"s   R's   R"s   b's   b"s   B's   B"s   br's   br"s   Br's   Br"s   bR's   bR"s   BR's   BR"t   rbt   rBt   Rbt   RBt   ut   Ui   c           B@  s   e  Z RS(    (   R   R   (    (    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/_tokenize_py3.pyR   ¼   s    t   StopTokenizingc           B@  s   e  Z RS(    (   R   R   (    (    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/_tokenize_py3.pyR1   ¾   s    t   Untokenizerc           B@  s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C@  s(   g  |  _  d |  _ d |  _ d |  _ d  S(   Ni   i    s   utf-8(   t   tokenst   prev_rowt   prev_colt   encoding(   R   (    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/_tokenize_py3.pyt   __init__Ã   s    			c         C@  sŒ   | \ } } | |  j  k s! t ‚ | |  j } | d k rQ |  j j d | ƒ n7 | |  j  k rˆ | t t t f k rˆ |  j j d ƒ n  d  S(   Ni    t    (   R4   t   AssertionErrorR5   R3   t   appendt   NEWLINER   t	   ENDMARKER(   R   t   tok_typet   startt   rowt   colt
   col_offset(    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/_tokenize_py3.pyt   add_whitespaceÉ   s    $c         C@  sã   t  | ƒ } xÄ | D]¼ } t | ƒ d k r? |  j | | ƒ Pn  | d  \ } } } } | t k rp | |  _ q n  |  j | | ƒ |  j j | ƒ | \ |  _ |  _	 | t
 t f k r |  j d 7_ d |  _	 q q Wd j |  j ƒ S(   Ni   i   i   i    t    (   t   itert   lent   compatR
   R6   RB   R3   R:   R4   R5   R;   R   R   (   R   R3   t   iterablet   tR=   t   tokenR>   t   end(    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/_tokenize_py3.pyR	   Ó   s     	c         C@  sJ  d d l  m } t } t } g  } |  j j } x| | g | ƒ D]} | d  \ }	 }
 |	 t k rr |
 |  _ qA n  |	 t t f k r‘ |
 d 7}
 n  |	 t	 k r¹ | r° d |
 }
 n  t
 } n t } |	 t k rÞ | j |
 ƒ qA nZ |	 t k rú | j ƒ  qA n> |	 t t f k rt
 } n# | r8| r8| | d ƒ t } n  | |
 ƒ qA Wd  S(   Ni    (   t   chaini   R8   iÿÿÿÿ(   t	   itertoolsRK   t   FalseR3   R:   R
   R6   t   NAMEt   NUMBERt   STRINGt   Truet   INDENTt   DEDENTt   popR;   R   (   R   RI   RG   RK   t	   startlinet
   prevstringt   indentst   toks_appendt   tokt   toknumt   tokval(    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/_tokenize_py3.pyRF   å   s:    		
		(   R   R   R7   RB   R	   RF   (    (    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/_tokenize_py3.pyR2   Á   s   		
	c         C@  s   t  ƒ  j |  ƒ S(   s¸  
    Convert ``tokens`` (an iterable) back into Python source code. Return
    a bytes object, encoded using the encoding specified by the last
    ENCODING token in ``tokens``, or UTF-8 if no ENCODING token is found.

    The result is guaranteed to tokenize back to match the input so that
    the conversion is lossless and round-trips are assured.  The
    guarantee applies only to the token type and token string as the
    spacing between tokens (column positions) may change.

    :func:`untokenize` has two modes. If the input tokens are sequences
    of length 2 (``type``, ``string``) then spaces are added as necessary to
    preserve the round-trip property.

    If the input tokens are sequences of length 4 or more (``type``,
    ``string``, ``start``, ``end``), as returned by :func:`tokenize`, then
    spaces are added so that each token appears in the result at the
    position indicated by ``start`` and ``end``, if possible.
    (   R2   R	   (   R3   (    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/_tokenize_py3.pyR	     s    c         C@  s^   |  d  j  ƒ  j d d ƒ } | d k s7 | j d ƒ r; d S| d k sV | j d ƒ rZ d S|  S(   s(   Imitates get_normal_name in tokenizer.c.i   t   _t   -s   utf-8s   utf-8-s   latin-1s
   iso-8859-1s   iso-latin-1s   latin-1-s   iso-8859-1-s   iso-latin-1-(   s   latin-1s
   iso-8859-1s   iso-latin-1(   s   latin-1-s   iso-8859-1-s   iso-latin-1-(   t   lowert   replacet
   startswith(   t   orig_enct   enc(    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/_tokenize_py3.pyt   _get_normal_name$  s    c         @  sÞ   t  ‰  d } d } ‡ f d †  } ‡  f d †  } | ƒ  } | j t ƒ ra t ‰  | d } d } n  | sq | g  f S| | ƒ } | r | | g f S| ƒ  } | s¬ | | g f S| | ƒ } | rÎ | | | g f S| | | g f S(   s  
    The detect_encoding() function is used to detect the encoding that should
    be used to decode a Python source file.  It requires one argment, readline,
    in the same way as the tokenize() generator.

    It will call readline a maximum of twice, and return the encoding used
    (as a string) and a list of any lines (left as bytes) it has read in.

    It detects the encoding from the presence of a utf-8 bom or an encoding
    cookie as specified in pep-0263.  If both a bom and a cookie are present,
    but disagree, a SyntaxError will be raised.  If the encoding cookie is an
    invalid charset, raise a SyntaxError.  Note that if a utf-8 bom is found,
    'utf-8-sig' is returned.

    If no encoding is specified, then the default of 'utf-8' will be returned.
    s   utf-8c           @  s$   y ˆ  ƒ  SWn t  k
 r d SXd  S(   NRC   (   t   StopIteration(    (   t   readline(    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/_tokenize_py3.pyt   read_or_stopC  s    c         @  sÂ   y |  j  d ƒ } Wn t k
 r2 t d ƒ ‚ n Xt j | ƒ } | sL d  St | d ƒ } y t | ƒ } Wn! t k
 r t d | ƒ ‚ n Xˆ  r¾ | d k r± t d ƒ ‚ n  | d 7} n  | S(   Ns   utf-8s'   invalid or missing encoding declarationi    s   unknown encoding: s   encoding problem: utf-8s   -sig(	   t   decodet   UnicodeDecodeErrort   SyntaxErrort	   cookie_ret   findallt   NoneRc   R   t   LookupError(   t   linet   line_stringt   matchesR6   t   codec(   t	   bom_found(    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/_tokenize_py3.pyt   find_cookieI  s"    i   s	   utf-8-sigN(   RM   Rl   R`   R   RQ   (   Re   R6   t   defaultRf   Rs   t   firstt   second(    (   Rr   Re   sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/_tokenize_py3.pyR   /  s,    	
	
	c         C@  sV   t  j |  d ƒ } t | j ƒ \ } } | j d ƒ t | | d t ƒ} d | _ | S(   sX   Open a file in read only mode using the encoding detected by
    detect_encoding().
    R+   i    t   line_bufferingR'   (   t   builtinst   openR   Re   t   seekR   RQ   t   mode(   t   filenamet   bufferR6   t   linest   text(    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/_tokenize_py3.pyRy   z  s    	c         C@  s_   d d l  m } m } t |  ƒ \ } } t |  d ƒ } | d ƒ } t | | | | ƒ j | ƒ S(   sÚ  
    The tokenize() generator requires one argment, readline, which
    must be a callable object which provides the same interface as the
    readline() method of built-in file objects.  Each call to the function
    should return one line of input as bytes.  Alternately, readline
    can be a callable function terminating with StopIteration:
        readline = open(myfile, 'rb').__next__  # Example of alternate readline

    The generator produces 5-tuples with these members: the token type; the
    token string; a 2-tuple (srow, scol) of ints specifying the row and
    column where the token begins in the source; a 2-tuple (erow, ecol) of
    ints specifying the row and column where the token ends in the source;
    and the line on which the token was found.  The line passed is the
    logical line; continuation lines are included.

    The first token sequence will always be an ENCODING token
    which tells you which encoding was used to decode the bytes stream.
    i    (   RK   t   repeatRC   (   RL   RK   R€   R   RD   t	   _tokenizet   __next__(   Re   RK   R€   R6   t   consumedt   rl_gent   empty(    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/_tokenize_py3.pyR   †  s
    c         c@  s¯  d } } } d } d \ } } d  } d g }	 | d  k	 rj | d k rP d } n  t t | d d  d ƒ Vn  xãt rOy |  ƒ  }
 Wn t k
 r™ d }
 n X| d  k	 r¸ |
 j | ƒ }
 n  | d 7} d t |
 ƒ } } | rÒ|
 só t d | ƒ ‚ n  | j |
 ƒ } | rY| j	 d ƒ } } t t
 | |
 |  | | | f | |
 ƒ Vd! \ } } d  } q-| r¸|
 d d	 k r¸|
 d
 d k r¸t t | |
 | | t |
 ƒ f | ƒ Vd } d  } qm q-| |
 } | |
 } qm n[| d k r	| r	|
 sïPn  d } xv | | k  rm|
 | d k r!| d 7} n? |
 | d k rF| t d t } n |
 | d k r_d } n P| d 7} qøW| | k r~Pn  |
 | d k rQ|
 | d k r|
 | j d ƒ } | t | ƒ } t t | | | f | | t | ƒ f |
 ƒ Vt t |
 | | | f | t |
 ƒ f |
 ƒ Vqm t t |
 | | | f | t |
 ƒ f |
 ƒ Vqm n  | |	 d k r˜|	 j | ƒ t t |
 |  | d f | | f |
 ƒ Vn  x’ | |	 d k  r| |	 k rÕt d d | | |
 f ƒ ‚ n  |	 d  }	 t t d | | f | | f |
 ƒ Vq›Wn$ |
 s't d | d f ƒ ‚ n  d } x| | k  rKt j |
 | ƒ } | r| j d ƒ \ } } | | f | | f | } } } |
 | | !|
 | } } | | k sÑ| d k rë| d k rë| d k rët t | | | |
 ƒ VqH| d k r#t | d k rt n t | | | |
 ƒ VqH| d k r_| j d ƒ sEt ‚ t t | | | |
 ƒ VqH| t k rét | } | j |
 | ƒ } | rÉ| j	 d ƒ } |
 | | !} t t
 | | | | f |
 ƒ Vq| | f } |
 | } |
 } PqH| t k s| d  t k s| d  t k rŒ| d d k rr| | f } t | pTt | d pTt | d } |
 | d } } |
 } Pqt t
 | | | |
 ƒ VqH| j ƒ  r²t t | | | |
 ƒ VqH| d k rÇd } qH| d k rà| d 7} n | d k rù| d 8} n  t t | | | |
 ƒ Vq0t t |
 | | | f | | d f |
 ƒ V| d 7} q0Wqm Wx5 |	 d D]) } t t d | d f | d f d ƒ Vq[Wt t  d | d f | d f d ƒ Vd  S("   Ni    t
   0123456789RC   s	   utf-8-sigs   utf-8i   s   EOF in multi-line stringiþÿÿÿs   \
iýÿÿÿs   \
R8   s   	s   s   #
t   #s   
iÿÿÿÿs3   unindent does not match any outer indentation levels
   <tokenize>s   EOF in multi-line statementt   .s   ...s   
i   i   s   \s   ([{s   )]}(   RC   i    (   i    i    (   i    i    (   RC   i    (!   Rl   R   R
   RQ   Rd   Rg   RE   R   t   matchRJ   RP   t
   ERRORTOKENt   tabsizet   rstripR   R;   R:   RR   t   IndentationErrorRS   t
   pseudoprogt   spanRO   R   t   endswithR9   t   triple_quotedt   endprogst   single_quotedt   isidentifierRN   t   OPR<   (   Re   R6   t   lnumt   parenlevt	   continuedt   numcharst   contstrt   needcontt   contlineRW   Rn   t   post   maxt   strstartt   endprogt   endmatchRJ   t   columnt   comment_tokent   nl_post   pseudomatchR>   t   spost   eposRI   t   initialt   indent(    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/_tokenize_py3.pyR   ¢  s    			

	&

 		$# *
* $
 
	'c         C@  s   t  |  d  ƒ S(   N(   R   Rl   (   Re   (    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/_tokenize_py3.pyR   9  s    t   __main__s4  def parseline(self, line):
            """Parse the line into a command name and a string containing
            the arguments.  Returns a tuple containing (command, args, line).
            'command' and 'args' may be None if the line couldn't be parsed.
            """
            line = line.strip()
            if not line:
                return None, None, line
            elif line[0] == '?':
                line = 'help ' + line[1:]
            elif line[0] == '!':
                if hasattr(self, 'do_shell'):
                    line = 'shell ' + line[1:]
                else:
                    return None, None, line
            i, n = 0, len(line)
            while i < n and line[i] in self.identchars: i = i+1
            cmd, arg = line[:i], line[i:].strip()
            return cmd, arg, line
    (   s   '''s   """s   r'''s   r"""s   R'''s   R"""s   b'''s   b"""s   B'''s   B"""s   br'''s   br"""s   Br'''s   Br"""s   bR'''s   bR"""s   BR'''s   BR"""(   R    R!   s   r's   r"s   R's   R"s   b's   b"s   B's   B"s   br's   br"s   Br's   Br"s   bR's   bR"s   BR's   BR"(    (]   t   __doc__t
   __future__R    t
   __author__t   __credits__Rx   R"   t   sysRI   t   codecsR   R   t   collectionst   ioR   R#   Rj   t   __all__t   N_TOKENSR   R   R   R
   t
   namedtupleR   R   R   R   t
   Whitespacet   Commentt   Ignoret   Namet	   Hexnumbert	   Binnumbert	   Octnumbert	   Decnumbert	   Intnumbert   Exponentt
   Pointfloatt   Expfloatt   Floatnumbert
   Imagnumbert   Numbert   version_infot   minort   StringPrefixt   Singlet   Doublet   Single3t   Double3t   Triplet   Stringt   Operatort   Brackett   Specialt   Funnyt
   PlainTokent   Tokent   ContStrt   PseudoExtrast   PseudoTokenR&   t   mapt	   tokenprogRŽ   t   single3progt   double3progRl   R’   R‘   RH   R“   t   _prefixt   _t2t   _t1R‹   t	   ExceptionR   R1   R2   R	   Rc   R   Ry   R   R   R   R   t   sRD   t
   splitlinesR‚   RY   (    (    (    sS   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/_tokenize_py3.pyt   <module>$   sø   






"			
	
	

	$   
   






	
L			K			—	"