Format: application/x-python-code
1 o
2
3 ��h� � @ s� d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddl m
4 Z
5 mZ edg d ��Zd
6 d� Z
7 ddee
8 e fd
9 d�Zddd�Zddedefdd�ZdS )zToken-related utilities� )�
10 namedtuple)�StringIO)� iskeywordN)� TokenInfo)�List�Optional�Token)�token�text�start�end�linec c s6 � zt �| �D ]}|V qW dS t jy Y dS w )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.pyr s ���r �extra_errors_to_catchc
12 # s� � g d�}|d u st |t�sJ �||pg }g }zt�| �D ]
13 }|�|� |V qW d S tjyu � z=t� fdd�|D ��ri|rW|d jd |d jd f}|}|d j }nd }}d}t�
14 tjd|||�V n� W Y d � � d S d � � ww )N)zunterminated string literalzinvalid non-printable characterz!after line continuation characterc 3 s � | ]
15 }|� j d v V qdS )r N)�args)�.0�error��excr r � <genexpr>, s � z/generate_tokens_catch_errors.<locals>.<genexpr>�����r )� r � )�
16 isinstance�listr r �appendr �anyr r r
17 r �
18 ERRORTOKEN) r r Zdefault_errors_to_catchZerrors_to_catch�tokensr r r r
19 r r r �generate_tokens_catch_errors s. �
20 ����r$ c C sX d}| � 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 r T�
36 r r )�
37 splitlines�len�endswith)�cell�
38 cursor_pos�offset�linesr
39 �next_offsetr r r �line_at_cursor: s
40
41 �r. r) r* c C s� g }g }g }ddi}t t| �j�D ]�}t|� }|j\}} |j\}
42 }|
43 d |vrI|j�d�}t||d �D ]\}
44 }|
45 |vrH||
46 d t |� ||
47 <