Format: application/x-python-code
⬇ Download File (3.6 KB)
   1  o
   2  
   3  ��h��@s�dZddlmZddlmZddlmZddlZddlmZddl	m
   4  Z
   5  mZedgd	��Zd
   6  d�Z
   7  	ddee
   8  efd
   9  d�Zddd�Zddedefdd�ZdS)zToken-related utilities�)�
  10  namedtuple)�StringIO)�	iskeywordN)�	TokenInfo)�List�Optional�Token)�token�text�start�end�lineccs6�zt�|�D]}|VqWdStjyYdSw)z'wrap generate_tkens to catch EOF errorsN)�tokenize�generate_tokens�
  11  TokenError)�readliner	�r�Mc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/utils/tokenutil.pyrs���r�extra_errors_to_catchc	
  12  #s��gd�}|dust|t�sJ�||pg}g}zt�|�D]
  13  }|�|�|VqWdStjyu�z=t�fdd�|D��ri|rW|djd|djdf}|}|dj	}nd}}d}t�
  14  tjd|||�Vn�WYd��dSd��ww)N)zunterminated string literalzinvalid non-printable characterz!after line continuation characterc3s�|]
  15  }|�jdvVqdS)rN)�args)�.0�error��excrr�	<genexpr>,s�z/generate_tokens_catch_errors.<locals>.<genexpr>�����r)�r�)�
  16  isinstance�listrr�appendr�anyrrr
  17  r�
  18  ERRORTOKEN)	rrZdefault_errors_to_catchZerrors_to_catch�tokensr	rrr
  19  rrr�generate_tokens_catch_errorss.�
  20  ����r$cCsXd}|�d�}|D]}|t|�}|�d�s|d7}||kr#||fS|}q	d}||fS)a�Return the line in a cell at a given cursor position
  21  
  22      Used for calling line-based APIs that don't support multi-line input, yet.
  23  
  24      Parameters
  25      ----------
  26      cell : str
  27          multiline block of text
  28      cursor_pos : integer
  29          the cursor position
  30  
  31      Returns
  32      -------
  33      (line, offset): (string, integer)
  34          The line with the current cursor, and the character offset of the start of the line.
  35      rT�
  36  rr)�
  37  splitlines�len�endswith)�cell�
  38  cursor_pos�offset�linesr
  39  �next_offsetrrr�line_at_cursor:s
  40  
  41  �r.r)r*cCs�g}g}g}ddi}tt|�j�D]�}t|�}|j\}}	|j\}
  42  }|
  43  d|vrI|j�d�}t||d�D]\}
  44  }|
  45  |vrH||
  46  dt	|�||
  47  <q4||}|	dkrU|dn|}||	|kr_nn|j
  48  tjkr�t
  49  |j�s�|r�|r�|dj
  50  tjkr�|djdkr�d|d|jf|d<n4|�|j�n-|j
  51  tjkr�|jdkr�|r�|�d�|jdkr�|r�|�|d�n|jd	kr�|r�|�d�|�|�||
  52  ||kr�nq|r�|dS|r�|dSd
  53  S)avGet the token at a given cursor
  54  
  55      Used for introspection.
  56  
  57      Function calls are prioritized, so the token for the callable will be returned
  58      if the cursor is anywhere inside the call.
  59  
  60      Parameters
  61      ----------
  62      cell : str
  63          A block of Python code
  64      cursor_pos : int
  65          The location of the cursor in the block where the token should be found
  66      rrTr�.z%s.%s�=�(�)r)rrrrrrr
  67  r&�	enumerater'r	r�NAMErr
  68  �OPr �pop)r)r*�namesr#Z
  69  call_names�offsets�tup�tok�
  70  start_lineZ	start_col�end_lineZend_colr,�linenor
  71  r+�boundaryrrr�token_at_cursor\sL
  72  
  73  �&
  74  
  75  
  76  �r?)N)r)�__doc__�collectionsr�ior�keywordrrr�typingrrrr�strr$r.�intr?rrrr�<module>s�
  77  
  78  �
  79  "