
    f9              	          d Z ddlZddlmZ ddlmZmZmZ ddlmZm	Z	 ddl
mZ ddl
mZ ddlmZ ddlmZ ddlZddlZddlZ e       Zd	d
dedefdZd	d
dedededefdZddededefdZd Z G d de      Z G d de      Zy)zfprompt-toolkit utilities

Everything in this module is a private API,
not to be used outside IPython.
    N)wcwidth)provisionalcompletercursor_to_position_deduplicate_completions)	Completer
Completion)Lexer)PygmentsLexer)patch_stdout   	min_elidestringreturnc                   | j                  dd      } | j                  dd      } t        |       |k  r| S | j                  d      }| j                  t        j                        }|d   dk(  r|j                          t        |      dkD  r&d	j                  |d
   |d   dd |d   dd |d         S t        |      dkD  rNdt        j                  z   dz   t        j                  z   dz   j                  |d
   |d   dd |d   dd |d         S | S )a  
    If a string is long enough, and has at least 3 dots,
    replace the middle part with ellipses.

    If a string naming a file is long enough, and has at least 3 slashes,
    replace the middle part with ellipses.

    If three consecutive dots, or two consecutive dots are encountered these are
    replaced by the equivalents HORIZONTAL ELLIPSIS or TWO DOT LEADER unicode
    equivalents
    z...   …z..u   ‥.    u   {}.{}…{}.{}r      Nz{}u   {}…{})replacelensplitosseppopformat)r   r   object_parts
file_partss       S/var/www/cvtools/html/venv/lib/python3.12/site-packages/IPython/terminal/ptutils.py_elide_pointr#      s$    ^^E";<F^^D!56F
6{Y<<$Lbff%J"~
<1299OOBQRS!	
 	
 
Z1	rvv ==FMUUqM:a=!,jnRS.A:b>
 	
 M    typedr   c                    t        |       |k  r| S t        |      dz
  }|dk  r| S | j                  |      r$t        |       t        |      kD  r| dd  d| |d  S | S )zT
    Elide the middle of a long string if the beginning has already been typed.
    r      Nr   )r   
startswith)r   r%   r   cut_how_muchs       r"   _elide_typedr*   A   sq    
 6{Yu:a<LaCKU$;!*4VLM5J4KLLMr$   c                 4    t        t        | |      ||      S )Nr   )r*   r#   )r   r%   r   s      r"   _elider,   O   s    Vy1$ $r$   c                 ^    | j                  d      rt        |      |kD  r||   dk(  r| d d S | S )N=r   )endswithr   )textbodyoffsets      r"   (_adjust_completion_text_based_on_contextr3   V   s5    }}Sc$i&0T&\S5HCRyr$   c                   >    e Zd ZdZddZed        Zd Zed        Z	y)IPythonPTCompleterz8Adaptor to provide IPython completions to prompt_toolkitNc                 >    ||t        d      || _        || _        y )Nz/Please pass shell=an InteractiveShell instance.)	TypeError_ipy_completershell)selfipy_completerr9   s      r"   __init__zIPythonPTCompleter.__init___   s'    =]2MNN+
r$   c                 ^    | j                   r| j                   S | j                  j                  S )N)r8   r9   r   )r:   s    r"   r;   z IPythonPTCompleter.ipy_completere   s'    &&&::'''r$   c              #   L  K   |j                   j                         sy t               5  t               5  |j                  }|j
                  }|j                  }|j                  }t        |||      }	 | j                  |||| j                        E d {    d d d        d d d        y 7 # t        $ rU}	 t        j                         \  }	}
}t        j                  |	|
|       n# t         $ r t#        d       Y nw xY wY d }~ld }~ww xY w# 1 sw Y   uxY w# 1 sw Y   y xY ww)Nz"Unrecoverable Error in completions)current_linestripr   r   r0   cursor_position_rowcursor_position_colcursor_positionr   _get_completionsr;   	Exceptionsysexc_info	tracebackprint_exceptionAttributeErrorprint)r:   documentcomplete_eventr1   
cursor_row
cursor_colrC   r2   eexc_type	exc_valueexc_tbs               r"   get_completionsz"IPythonPTCompleter.get_completionsl   s    $$**,
 ^ 	@13 	@==D!55J!55J&66O'j*EF@00vPTPbPbccc	@ 	@ 	@ d @@25,,./Hi--h	6J% @>?@	@	@ 	@ 	@ 	@s   &D$D>D2!B+B)B+D 	D$)B++	D	5/C%$D%C<	9D;C<	<D?DD		DD	DD!D$c              #   t  K   t        |dd      }t        | |j                  | |            }|D ]  }|j                  st	        j
                  d|j                        }t        |d         dk(  rn||j                  z   dkD  r\| |j                  dz
     }t	        j
                  d||z         }	t        |dd       dk(  r t        |	|j                  |z
  dz
         |j                  }
t        |j                  | |      }|j                  dk(  r[t        ||j                  |z
  t        |
dz   | |j                  |j                         |j                  |j                  z   	       =t        ||j                  |z
  t        |
| |j                  |j                         |j                  	        y
w)zT
        Private equivalent of get_completions() use only for unit_testing.
        debugFNFCr   r   )start_positionfunctionz())rX   displaydisplay_metaN)getattrr   completionsr0   unicodedata	normalizer   startr   r3   typer,   end	signature)r1   r2   rC   ipycrV   r]   cr0   char_before
fixed_textdisplay_textadjusted_texts               r"   rD   z#IPythonPTCompleter._get_completions   s    
 gu-.$""402 	ZA66((7D
 tAw1$"QWW,q0"&qww{"3K!,!6!6{T1"3J tAay)Q.(AGGfDTWXDXYY  66LDQVVTSYZMvv# qww?OY_`lmq`qswxyxx  AB  AF  AF  tG  ZH  WX  W]  W]  ^_  ^i  ^i  Wi  j  j qww?OY_`lostut{t{|}  }B  }B  pC  ZD  ST  SY  SY  Z  Z?	Zs   F6F8)NN)
__name__
__module____qualname____doc__r<   propertyr;   rT   staticmethodrD    r$   r"   r5   r5   ]   s:    B ( (@, &Z &Zr$   r5   c                       e Zd ZdZd Zd Zy)IPythonPTLexerz3
    Wrapper around PythonLexer and BashLexer.
    c           	         t         }t        |j                        | _        t        |j                        | _        t        |j                        t        |j                        t        |j                        t        |j                        t        |j                        t        |j                        t        |j                        d| _        y )N)HTMLhtml
javascriptjsperlrubylatex)pygments_lexersr
   Python3Lexerpython_lexer	BashLexershell_lexer	HtmlLexerJavascriptLexer	PerlLexer	RubyLexerTexLexermagic_lexers)r:   ls     r"   r<   zIPythonPTLexer.__init__   s    )!..9(5 "!++.!!++.'(9(9: 1 12!!++.!!++."1::.
r$   c                 d   |j                   j                         }| j                  }|j                  d      s|j                  d      r| j                  }nK|j                  d      r:| j
                  j                         D ]  \  }}|j                  d|z         s|} n |j                  |      S )N!z%%bashz%%)r0   lstripr}   r(   r   r   itemslex_document)r:   rL   r0   lexermagicr   s         r"   r   zIPythonPTLexer.lex_document   s    }}##%!!??34??8#<$$E__T" --335 q??4%<0E
 !!(++r$   N)rj   rk   rl   rm   r<   r   rp   r$   r"   rr   rr      s    
,r$   rr   )r   )rm   r^   r   IPython.core.completerr   r   r   prompt_toolkit.completionr   r   prompt_toolkit.lexersr	   r
   prompt_toolkit.patch_stdoutr   pygments.lexerslexersr{   r   rF   rH   object_completion_sentinelstrr#   intr*   r,   r3   r5   rr   rp   r$   r"   <module>r      s       < ' / 4 ) 	 
 x *, # #s #J :<  3 S c $# $S $ $LZ LZ\!,U !,r$   