ó
æNXc           @@ s¯   d  Z  d d l m Z m Z d d l m Z d d l m Z d d l m	 Z	 d d l
 m Z d d l m Z e d	 d
 d d d d g ƒ Z d „  Z d d „ Z d d „ Z d S(   s   Token-related utilitiesi    (   t   absolute_importt   print_function(   t
   namedtuple(   t   StringIO(   t	   iskeywordi   (   t	   tokenize2(   t   cast_unicode_py2t   Tokent   tokent   textt   startt   endt   linec         c@ s?   y# x t  j |  ƒ D] } | Vq WWn t  j k
 r: d SXd S(   s(   wrap generate_tokens to catch EOF errorsN(   R   t   generate_tokenst
   TokenError(   t   readlineR   (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/tokenutil.pyR      s
    c         C@ s\   d } |  j  t ƒ } x: | D], } | t | ƒ } | | k rB Pn  | } q Wd } | | f S(   s»  Return the line in a cell at a given cursor position
    
    Used for calling line-based APIs that don't support multi-line input, yet.
    
    Parameters
    ----------
    
    cell: text
        multiline block of text
    cursor_pos: integer
        the cursor position
    
    Returns
    -------
    
    (line, offset): (text, integer)
        The line with the current cursor, and the character offset of the start of the line.
    i    t    (   t
   splitlinest   Truet   len(   t   cellt
   cursor_post   offsett   linesR   t   next_offset(    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/tokenutil.pyt   line_at_cursor   s    
c         C@ s   t  |  ƒ }  g  } g  } d } g  } xÕt t |  ƒ j ƒ D]¾} t | Œ  } | j d } | j d }	 | d k r| | d n | }
 | | |
 k r– Pn  | j t j	 k rt
 | j ƒ r| r| r| d j t j k r| d j d k rd | d | j f | d <q¦| j | j ƒ nˆ | j t j k r¦| j d k rU| rU| j d ƒ n  | j d k r~| r~| j | d ƒ q¦| j d k r¦| r¦| j d ƒ q¦n  | |	 | k rºPn  | j | ƒ | j t j t j f k r: | t | j ƒ 7} q: q: W| r
| d S| r| d Sd	 Sd
 S(   s‹  Get the token at a given cursor
    
    Used for introspection.
    
    Function calls are prioritized, so the token for the callable will be returned
    if the cursor is anywhere inside the call.
    
    Parameters
    ----------
    
    cell : unicode
        A block of Python code
    cursor_pos : int
        The location of the cursor in the block where the token should be found
    i    i   iÿÿÿÿt   .s   %s.%st   =t   (t   )R   N(   R   R   R   R   R   R
   R   R   R   t   NAMER   R	   t   OPt   appendt   popt   NEWLINEt   NLR   R   (   R   R   t   namest   tokensR   t
   call_namest   tupt   tokt	   start_colt   end_colt   boundary(    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/tokenutil.pyt   token_at_cursor8   sB    "5N(   t   __doc__t
   __future__R    R   t   collectionsR   t   ioR   t   keywordR   R   R   t	   py3compatR   R   R   R   R,   (    (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/tokenutil.pyt   <module>   s   		