
    ړi                    ,   d Z ddlmZ ddlZddlmZmZmZmZm	Z	m
Z
 ddlmZ ddlmZ ddlmZ ddlmZmZ erdd	lmZ eZg d
ZddZ	 	 	 	 	 	 	 	 ddZ ej6                  d      ZddZ e	deegdf         ZddZ e	de       Z!ddZ"ddZ#ddZ$y)z
For internal use only.
    )annotationsN)TYPE_CHECKINGAnyCallableIterableTypeVarcast)Document)to_formatted_text)fragment_list_to_text)
MouseEventMouseEventType)Interpreter)has_unclosed_bracketsget_jedi_script_from_documentdocument_is_multiline_pythonunindent_codec                   g }t        j                  dd|       } t        |       D ]Z  }|dv r|j                  |       |dv s|r:|dk(  r|d   dk(  s|dk(  r|d   d	k(  s|d
k(  s@|d   dk(  sI|j	                          Z y y)z
    Starting at the end of the string. If we find an opening bracket
    for which we didn't had a closing one yet, return True.
    z('[^']*'|"[^"]*") z])}z[({[]{}()TF)resubreversedappendpop)textstackcs      5/tmp/pip-target-20744g9h/lib/python/ptpython/utils.pyr   r      s    
 E 66*B5Dd^ :LLO%Z#X%)s"2SU2Y#%5SU2Y#%5IIK       c                    dd l }	 |j                  | j                  d||g      S # t        $ r Y y t        $ r Y y t
        $ r Y y t        $ r Y y t        $ r Y y w xY w)Nr   z
input-text)path
namespaces)jedir   r"   
ValueErrorAttributeError
IndexErrorKeyError	Exception)documentlocalsglobalsr*   s       r%   r   r   <   sz     MM(   
 	

        s%   & 	AAAAAAz[']{3}|["]{3}c                     d
 fd}d j                   v s |       ryd
 fd} |       s< j                  rt         j                        s j                   j	                  d      ry j                  dd dk(  ryy	)z@
    Determine whether this is a multiline Python document.
    c                     t         j                  j                        } d}| D ]  }||}||k(  sd} t        |      S )zU
        ``True`` if we're inside a multiline string at the end of the text.
        N)_multiline_string_delimsfindallr"   bool)delimsopeningdelimr0   s      r%   ends_in_multiline_stringz>document_is_multiline_python.<locals>.ends_in_multiline_stringd   sP     *11(--@ 	E'!		
 G}r&   
Tc                 D     j                   j                         dd  dk(  S )Nr   :)current_linerstrip)r0   s   r%   line_ends_with_colonz:document_is_multiline_python.<locals>.line_ends_with_colont   s$    $$++-bc2c99r&   @r   N\F)returnr7   )r"   is_cursor_at_the_endr   text_before_cursor
startswith)r0   r;   rA   s   `  r%   r   r   _   su    
 x}} 8 ::
 	))%h&A&AB==##C( 
	$	$RS	)T	1r&   _T)boundc                0     d fd}t        t        |      S )z
    Decorator for mouse handlers.
    Only handle event when the user pressed mouse down.

    (When applied to a token list. Scroll events will bubble up and are handled
    by the Window.)
    c                Z    | j                   t        j                  k(  r |       S t        S )N)
event_typer   
MOUSE_DOWNNotImplemented)mouse_eventhandlers    r%   handle_if_mouse_downz*if_mousedown.<locals>.handle_if_mouse_down   s(    !!^%>%>>;''!!r&   )rO   r   rD   NotImplementedOrNone)r	   rH   )rP   rQ   s   ` r%   if_mousedownrS      s    " ())r&   _T_typec                P     t         d      st        d      d fd}| _         S )zT
    Generate a normal `__repr__` method for classes that have a `__pt_repr__`.
    __pt_repr__zP@ptrepr_to_repr can only be applied to classes that have a `__pt_repr__` method.c                f    t        d      sJ t        t        j                  |                   S )NrV   )hasattrr   r   rV   )selfclss    r%   __repr__z ptrepr_to_repr.<locals>.__repr__   s-    sM***$%6st7L%MNNr&   )rY   objectrD   str)rX   	TypeErrorr[   )rZ   r[   s   ` r%   ptrepr_to_reprr_      s3     3&^
 	
O CLJr&   c                    | j                  d      }t        |      }|D cg c]  }|t        |      d  }}dj                  |      S c c}w )zG
    Remove common leading whitespace when all lines are indented.
    T)keependsNr   )
splitlines_common_whitespace_prefixlenjoin)r"   linescommon_prefixlines       r%   r   r      sU     OOTO*E .e4M 5::DT#m$&':E:775> ;s   A
c                    | D cg c]$  }|j                         rt        |      dk(  r#|& } }| syt        |       }t        |       }t	        |      D ]  \  }}|||   k7  s|dvs|d| c S  |S c c}w )zl
    Return common prefix for a list of lines.
    This will ignore lines that contain whitespace only.
    r   r   z 	N)isspacerd   minmax	enumerate)stringsss1s2ir$   s         r%   rc   rc      s     "IQSVq[qIGI \\bM 	DAqBqEzQe^"1v	 	 Js   A1A1A1)r"   r]   rD   r7   )r0   r
   r1   dict[str, Any]r2   rs   rD   r   )r0   r
   rD   r7   )rP   rH   rD   rH   )rZ   rT   rD   rT   )r"   r]   rD   r]   )rn   zIterable[str]rD   r]   )%__doc__
__future__r   r   typingr   r   r   r   r   r	   prompt_toolkit.documentr
   prompt_toolkit.formatted_textr   #prompt_toolkit.formatted_text.utilsr   prompt_toolkit.mouse_eventsr   r   r*   r   r\   rR   __all__r   r   compiler5   r   rH   rS   typerT   r_   r   rc    r&   r%   <module>r      s    # 	 H H , ; E B 
 ": .9G@ &2::&9: (V T:,"456*$ )4
("r&   