U
    -eX                     @   sd   d Z ddlmZ ddlmZ ddlmZ ddlZedddd	d
dg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   s8   zt | D ]
}|V  qW n t jk
r2   Y dS X dS )z(wrap generate_tokens to catch EOF errorsN)tokenizegenerate_tokens
TokenError)readliner    r   X/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/IPython/utils/tokenutil.pyr      s
    r   c                 C   sR   d}|  d}|D ]2}|t| }|ds4|d7 }||kr@ qJ|}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 |kr|jd}t||d D ](\}}||krj||d  t	| ||< qj|| }|	dkr|d n|}||	 |kr q|j
tjkr0t|js0|r"|r"|d j
tjkr"|d jdkr"d|d |jf |d< n||j nh|j
tjkr|jdkrZ|rZ|d |jdkr||r|||d  n|jd	kr|r|d || ||
 | |kr" qq"|r|d S |r|d S 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   N)r   r   r   r   r   r	   r
   r   	enumerater   r   r   NAMEr   r   OPappendpop)r   r   namestokensZ
call_namesoffsetstuptok
start_lineZ	start_colend_lineZend_colr   linenor
   r   boundaryr   r   r   token_at_cursor9   sH    

.


r0   )r   )r   )__doc__collectionsr   ior   keywordr   r   r   r   r   r0   r   r   r   r   <module>   s   	
!