ó
&9_[c           @@ 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   (    (    s6   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: str
        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(    (    s6   lib/python2.7/site-packages/IPython/utils/tokenutil.pyt   line_at_cursor   s    
c         C@ s‰  t  |  ƒ }  g  } g  } g  } i d d 6} x7t t |  ƒ j ƒ D] } t | Œ  } | j \ } }	 | j \ }
 } |
 d | k rò | j j t	 ƒ } x\ t
 t | d |
 d ƒ | ƒ D]7 \ } } | | k r´ | | d t | ƒ | | <q´ q´ Wn  | | } |	 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 rë| rë| j d ƒ n  | j d k r| r| j | d ƒ q<| j d	 k r<| r<| j d ƒ q<n  | j | ƒ | |
 | | k rA PqA qA W| rs| 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   iÿÿÿÿt   .s   %s.%st   =t   (t   )R   N(   R   R   R   R   R   R
   R   R   R   R   t   zipt   rangeR   R   R   t   NAMER   R	   t   OPt   appendt   pop(   R   R   t   namest   tokenst
   call_namest   offsetst   tupt   tokt
   start_linet	   start_colt   end_linet   end_colR   t   linenoR   R   t   boundary(    (    s6   lib/python2.7/site-packages/IPython/utils/tokenutil.pyt   token_at_cursor8   sJ    -&
"5N(   t   __doc__t
   __future__R    R   t   collectionsR   t   ioR   t   keywordR   R   R   t	   py3compatR   R   R   R   R0   (    (    (    s6   lib/python2.7/site-packages/IPython/utils/tokenutil.pyt   <module>   s   		