o
    ¹iX  ã                   @   s^   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d	„ Z	dd
d„Z
ddd„ZdS )zToken-related utilitiesé    )Ú
namedtuple)ÚStringIO)Ú	iskeywordNÚToken)ÚtokenÚtextÚstartÚendÚlinec                 c   s6    zt  | ¡D ]}|V  qW dS  t jy   Y dS w )z(wrap generate_tokens to catch EOF errorsN)ÚtokenizeÚgenerate_tokensÚ
TokenError)Úreadliner   © r   úR/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/IPython/utils/tokenutil.pyr      s   €ÿþr   c                 C   sX   d}|   d¡}|D ]}|t|ƒ }| d¡s|d7 }||kr# ||fS |}q	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_offsetr   r   r   Úline_at_cursor   s   

ýr   c                 C   s¶  g }g }g }ddi}t t| ƒjƒD ]»}t|Ž }|j\}}	|j\}
}|
d |vrI|j d¡}t||d ƒD ]\}}||vrH||d  t	|ƒ ||< q4|| }|	dkrU|d n|}||	 |kr_ nn|j
tjkrt|jƒs|r‰|r‰|d j
tjkr‰|d jdkr‰d|d |jf |d< n4| |j¡ n-|j
tjkr½|jdkr¢|r¢| d¡ |jdkr±|r±| |d ¡ n|jd	kr½|r½| d¡ | |¡ ||
 | |krÌ nq|rÓ|d S |rÙ|d S d
S )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éÿÿÿÿÚ.z%s.%sú=ú(ú)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   Úboundaryr   r   r   Útoken_at_cursor9   sL   

€&


þr3   )r   )Ú__doc__Úcollectionsr   Úior   Úkeywordr   r   r   r   r   r3   r   r   r   r   Ú<module>   s    
	!