
    Mh                     $   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mZ ddlZddlZddlZ e            Zd
edefdZd
edededefdZd
ededefdZd Z G d de          Z G d de          Z dS )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)get_ipythonstringreturnc                   |                      dd          } |                      dd          } t          |           |k     r| S |                     d          }|                     t          j                  }|d         dk    r|                                 t          |          dk    r@d	                    |d
         |d         dd         |d         dd         |d                   S t          |          dk    r`dt          j        z   dz   t          j        z   dz                       |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   	min_elideobject_parts
file_partss       X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/IPython/terminal/ptutils.py_elide_pointr"      sU    ^^E";<<F^^D!566F
6{{Y<<$$Lbf%%J"~
<1299OOBQBRSS!	
 
 	
 
Z1		rv ==FMUUqM:a=!,jnRSS.A:b>
 
 	
 M    typedr   c                    t          |           |k     r| S t          |          dz
  }|dk     r| S |                     |          r7t          |           t          |          k    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)   E   s    
 6{{Yu::a<La MCKKU$;$;!*LLVLMM5JLLLMr#   c                 D    t          t          | |          ||          S )Nr   )r)   r"   )r   r$   r   s      r!   _elider,   T   s.    Vy111$ $ $ $r#   c                     |                      d          r)t          |          |k    r||         dk    r
| d d         S | S )N=r   )endswithr   )textbodyoffsets      r!   (_adjust_completion_text_based_on_contextr3   [   sG    }}S c$ii&00T&\S5H5HCRCyr#   c                   <    e Zd ZdZddZed             Zd Zd ZdS )IPythonPTCompleterz8Adaptor to provide IPython completions to prompt_toolkitNc                 H    ||t          d          || _        || _        d S )Nz/Please pass shell=an InteractiveShell instance.)	TypeError_ipy_completershell)selfipy_completerr9   s      r!   __init__zIPythonPTCompleter.__init__d   s.    =]2MNNN+


r#   c                 6    | j         r| j         S | j        j        S )N)r8   r9   r   )r:   s    r!   r;   z IPythonPTCompleter.ipy_completerj   s!     	(&&:''r#   c              #   H  K   |j                                         sd S t                      5  t                      5  |j        }|j        }|j        }|j        }t          |||          }	 | 	                    |||| j
                  E d {V  ne# t          $ rX}	 t          j                    \  }	}
}t          j        |	|
|           n# t           $ r t#          d           Y nw xY wY d }~nd }~ww xY wd d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )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_completionsq   s     $**,, 	F
 ^^ 	@ 	@133 	@ 	@=D!5J!5J&6O'j*EEF@00vPTPbcccccccccc @ @ @@25,../Hi-h	6JJJJ% @ @ @>?????@	@	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@s|   D.C?*#BC?
C0-CC+C#	 C+"C#	#C+&C?+C00C?3D?D	DD	DDDc              #   |  K   t          |dd          }t          ||                    ||                    }|D ]}|j        st	          j        d|j                  }t          |d                   dk    rp||j        z   dk    rb||j        dz
           }	t	          j        d|	|z             }
t          |dd                   dk    rt          |
|j        |z
  dz
            V  |j        }t          |j        ||          }| j
        dn| j
        j        }|j        d	k    rQt          ||j        |z
  t          |d
z   ||j        |j                 |          |j        |j        z             V  <t          ||j        |z
  t          |||j        |j                 |          |j                  V  dS )zT
        Private equivalent of get_completions() use only for unit_testing.
        debugFNFCr   r   )start_positionN   functionz()r+   )rX   displaydisplay_meta)getattrr   completionsr0   unicodedata	normalizer   startr   r3   r9   r   typer,   end	signature)r:   r1   r2   rC   ipycrV   r^   cr0   char_before
fixed_textdisplay_textadjusted_textr   s                 r!   rD   z#IPythonPTCompleter._get_completions   s,      gu--.$""4002 2 4	 4	A6 (77D
 tAw1$$"QW,q00"&qw{"3K!,!6{T1"3 "3J tAaCy))Q..(AGfDTWXDXYYYYYY  6LDf M #j0dj6JIv## !#$7V#3"$t+QWqu_-"+  
 "#!+!5	 	 	 	 	 	 	 !!#$7V#3"$QWqu_-"+  
 "#	 	 	 	 	 	 	W4	 4	r#   )NN)	__name__
__module____qualname____doc__r<   propertyr;   rT   rD    r#   r!   r5   r5   b   sj        BB    ( ( X(@ @ @,; ; ; ; ;r#   r5   c                       e Zd ZdZd Zd ZdS )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| _        d S )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9(55 "!+..!!+..'(9:: 122!!+..!!+.."1:..
 
r#   c                 p   |j                                         }| j        }|                    d          s|                    d          r| j        }nP|                    d          r;| j                                        D ]!\  }}|                    d|z             r|} n"|                    |          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#<#< 	$EE__T"" 	 -3355  q??4%<00 EE !!(+++r#   N)rk   rl   rm   rn   r<   r   rp   r#   r!   rr   rr      s<         
 
 
, , , , ,r#   rr   )!rn   r_   r   IPython.core.completerr   r   r   prompt_toolkit.completionr   r   prompt_toolkit.lexersr	   r
   prompt_toolkit.patch_stdoutr   IPython.core.getipythonr   pygments.lexerslexersr{   r   rF   rH   object_completion_sentinelstrr"   intr)   r,   r3   r5   rr   rp   r#   r!   <module>r      s                       < ; ; ; ; ; ; ; ' ' ' ' ' ' / / / / / / 4 4 4 4 4 4 / / / / / / * ) ) ) ) ) 				 



    vxx # #s # # # #L S      $3 $s $# $ $ $ $  ` ` ` ` ` ` ` `F!, !, !, !, !,U !, !, !, !, !,r#   