
    fX                     `    d Z ddlmZ ddlmZ ddlmZ ddlZ edg d      Zd Z	dd	Z
dd
Zy)zToken-related utilities    )
namedtuple)StringIO)	iskeywordNToken)tokentextstartendlinec              #   |   K   	 t        j                  |       D ]  }|  y# t         j                  $ r Y yw xY ww)z(wrap generate_tokens to catch EOF errorsN)tokenizegenerate_tokens
TokenError)readliner   s     R/var/www/cvtools/html/venv/lib/python3.12/site-packages/IPython/utils/tokenutil.pyr   r      sA     --h7 	EK	 s   <# <9<9<c                     d}| j                  d      }|D ]2  }|t        |      z   }|j                  d      s|dz  }||kD  r ||fS |}4 d}||fS )a  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): (string, integer)
        The line with the current cursor, and the character offset of the start of the line.
    r   T
    )
splitlineslenendswith)cell
cursor_posoffsetlinesr   next_offsets         r   line_at_cursorr      s{    " FOOD!E s4y(}}T" 1K# &>  &>    c                 .   g }g }g }ddi}t        t        |       j                        D ]  }t        | }|j                  \  }}	|j
                  \  }
}|
dz   |vrN|j                  j                  d      }t        ||dz         D ]!  \  }}||vs||dz
     t        |      z   ||<   # ||   }|	dk(  r|dz   n|}||	z   |k\  r nD|j                  t        j                  k(  rt        |j                        sj|rL|rJ|d   j                  t        j                  k(  r*|d   j                  dk(  r|d   d|j                  |d<   n|j!                  |j                         n|j                  t        j                  k(  rj|j                  dk(  r|r|j#                  d       |j                  dk(  r|r|j!                  |d          n"|j                  dk(  r|r|j#                  d       |j!                  |       ||
   |z   |kD  s n |r|d   S |r|d   S y	)
az  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
    r   r   T.=()r   )r   r   r   r   r	   r
   r   r   	enumerater   r   r   NAMEr   r   OPappendpop)r   r   namestokens
call_namesoffsetstuptok
start_line	start_colend_lineend_colr   linenor   r   boundarys                    r   token_at_cursorr7   9   s     EFJ!fGx~667 )Sk !$		
IGG'a<w&HH''-E )%a @ D(&-fQh&7#d)&CGFOD $%.!^:>I) 99%i.AF2J$4$4$Cr
[^H^',Ry#((;b	SXX&YY(++%xx35		"xx35!!%),SZr"c8w&3S)V "~	Ryr   )r   )__doc__collectionsr   ior   keywordr   r   r   r   r   r7    r   r   <module>r=      s6    
 #    	7EFBDr   