Format: application/x-python-code
1 o
2
3 ��h9 � @ s d Z ddlZddlmZ ddlmZmZmZ ddlmZm Z ddl
4 mZ ddl
5 mZ ddl
6 mZ ddlmZ ddlZddlZddlZe� Zd d
7 �dedefd
8 d�Zd d
9 �dedededefdd�Zddededefdd�Zdd� ZG dd� de�ZG dd� de�ZdS )zfprompt-toolkit utilities
10
11 Everything in this module is a private API,
12 not to be used outside IPython.
13 � N)�wcwidth)�provisionalcompleter�cursor_to_position�_deduplicate_completions)� Completer�
14 Completion)�Lexer)�
15 PygmentsLexer)�patch_stdout� �� min_elide�string�returnc C s� | � dd�} | � dd�} t| �|k r| S | �d�}| �tj�}|d dkr)|�� t|�dkrGd �|d
16 |d dd� |d
17 dd� |d �S t|�dkrodtj d tj d �|d
18 |d dd� |d
19 dd� |d �S | S )a�
20 If a string is long enough, and has at least 3 dots,
21 replace the middle part with ellipses.
22
23 If a string naming a file is long enough, and has at least 3 slashes,
24 replace the middle part with ellipses.
25
26 If three consecutive dots, or two consecutive dots are encountered these are
27 replaced by the equivalents HORIZONTAL ELLIPSIS or TWO DOT LEADER unicode
28 equivalents
29 z...� …z..u ‥�.������ � u
30 {}.{}…{}.{}r � N�����z{}u {}…{})�replace�len�split�os�sep�pop�format)r r
31 Zobject_partsZ
32 file_parts� r �Nc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/terminal/ptutils.py�_elide_point s(
33 �(�r �typedr
34 c C sd t | �|k r| S t |�d }|dk r| S | �|�r0t | �t |�kr0| dd� � d| |d� � �S | S )zT
35 Elide the middle of a long string if the beginning has already been typed.
36 r � Nr )r �
37 startswith)r r! r
38 Zcut_how_muchr r r �_elide_typedA s r$ c C s t t| |d�||d�S )Nr )r$ r )r r! r
39 r r r �_elideO s
40 �r% c C s2 | � d�rt|�|kr|| dkr| d d� S | S )N�=r )�endswithr )�text�body�offsetr r r �(_adjust_completion_text_based_on_contextV s "r+ c @ s: e Zd ZdZddd�Zedd� �Zdd� Zed d
41 � �Z dS )�IPythonPTCompleterz8Adaptor to provide IPython completions to prompt_toolkitNc C s( |d u r|d u rt d��|| _|| _d S )Nz/Please pass shell=an InteractiveShell instance.)� TypeError�_ipy_completer�shell)�self�
42 ipy_completerr/ r r r �__init___ s
43 zIPythonPTCompleter.__init__c C s | j r| j S | jjS )N)r. r/ r )r0 r r r r1 e s z IPythonPTCompleter.ipy_completerc
44 c s � |j �� sd S t� �u t� �Y |j}|j}|j}|j}t|||�}z| � |||| j
45 �E d H W n0 ty` } z$zt�
46 � \} }
47 }t�| |
48 |� W n
49 tyU td� Y nw W Y d }~nd }~ww W d � n1 skw Y W d � d S W d � d S 1 s�w Y d S )Nz"Unrecoverable Error in completions)�current_line�stripr
50 r r( Zcursor_position_rowZcursor_position_col�cursor_positionr �_get_completionsr1 � Exception�sys�exc_info� traceback�print_exception�AttributeError�print)r0 �documentZcomplete_eventr) Z
51 cursor_rowZ
52 cursor_colr5 r* �e�exc_type� exc_value�exc_tbr r r �get_completionsl s, �
53 ����P�z"IPythonPTCompleter.get_completionsc c s0 � t |dd�}t| |�| |��}|D ]�}|jsqt�d|j�}t|d �dkrT||j dkrT| |jd }t�d|| �} t|dd� �dkrTt| |j| d d�V q|j}
54 t |j| |�}|j
55 dkrt||j| t|
56 d | |j|j� �|j
57 |j
58 d �V qt||j| t|
59 | |j|j� �|j
60 d �V qd
61 S )zT
62 Private equivalent of get_completions() use only for unit_testing.
63 �debugF�NFCr r )�start_position�functionz())rF �displayZdisplay_metaN)�getattrr �completionsr( �unicodedata� normalizer �startr r+ �typer% �end� signature)r) r* r5 ZipycrD rJ �cr( Zchar_beforeZ
64 fixed_textZdisplay_textZ
65 adjusted_textr r r r6 � s0 ���
66 8.�z#IPythonPTCompleter._get_completions)NN)
67 �__name__�
68 __module__�__qualname__�__doc__r2 �propertyr1 rC �staticmethodr6 r r r r r, ] s
69
70 r, c @ s e Zd ZdZdd� Zdd� ZdS )�IPythonPTLexerz3
71 Wrapper around PythonLexer and BashLexer.
72 c C s` t }t|j�| _t|j�| _t|j�t|j�t|j�t|j�t|j�t|j �t|j
73 �d�| _d S )N)�HTML�html�
74 javascript�js�perl�ruby�latex)�pygments_lexersr �Python3Lexer�python_lexer� BashLexer�shell_lexer� HtmlLexer�JavascriptLexer� PerlLexer� RubyLexer�TexLexer�magic_lexers)r0 �lr r r r2 � s �zIPythonPTLexer.__init__c C sj |j �� }| j}|�d�s|�d�r| j}n|�d�r0| j�� D ]\}}|�d| �r/|} nq |�|�S )N�!z%%bashz%%)r( �lstriprb r# rd rj �items�lex_document)r0 r>