
    BNe<                    8   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
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j        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'dS )+z
For internal use only.
    )annotationsN)	TYPE_CHECKINGAnyCallableDictIterableOptionalType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_codetextstrreturnboolc                6   g }t          j        dd|           } t          |           D ]p}|dv r|                    |           |dv rP|rK|dk    r|d         dk    s$|dk    r|d         d	k    s|d
k    r |d         dk    r|                                 m dS qdS )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)r   stackcs      x/home/feoh/.cache/pypoetry/virtualenvs/veilid-python-play-bIboZq2W-py3.11/lib/python3.11/site-packages/ptpython/utils.pyr   r   (   s    
 E 6*B55Dd^^  ::LLOOOO%ZZ 	#XX%)s"2"2SU2Y#%5%5SU2Y#%5%5IIKKK tt  5    documentr   localsdict[str, Any]globalsr   c                    dd l }	 |                    | j        d||g          S # t          $ r Y d S t          $ r Y d S t
          $ r Y d S t          $ r Y d S t          $ r Y d S w xY w)Nr   z
input-text)path
namespaces)jedir   r   
ValueErrorAttributeError
IndexErrorKeyError	Exception)r-   r.   r0   r4   s       r+   r   r   E   s     KKKM(   
 
 	

     tt    tt   tt   tt   tts%   % 
A#	A#	A#
	A#	A#"A#z[']{3}|["]{3}c                     d fd}d j         v s
 |            rdS d fd} |            s5 j        rt           j                  s j                             d          rdS  j        dd	         d
k    rdS dS )z@
    Determine whether this is a multiline Python document.
    r   r   c                     t                               j                  } d}| D ]}||}||k    rd}t          |          S )zU
        ``True`` if we're inside a multiline string at the end of the text.
        N)_multiline_string_delimsfindallr   r   )delimsopeningdelimr-   s      r+   ends_in_multiline_stringz>document_is_multiline_python.<locals>.ends_in_multiline_stringm   sW     *11(-@@ 	 	E'!!G}}r,   
Tc                 N     j                                         dd          dk    S )Nr   :)current_linerstrip)r-   s   r+   line_ends_with_colonz:document_is_multiline_python.<locals>.line_ends_with_colon}   s&    $++--bcc2c99r,   @r   N\F)r   r   )r   is_cursor_at_the_endr   text_before_cursor
startswith)r-   rA   rG   s   `  r+   r   r   h   s    
      x} 8 8 : :t: : : : : :
 	 ) &h&ABB	 =##C(( t 
	$RSS	)T	1	1t5r,   _T)boundhandlerc                :     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.)
    mouse_eventr   r   NotImplementedOrNonec                R    | j         t          j        k    r |           S t          S N)
event_typer   
MOUSE_DOWNNotImplemented)rQ   rO   s    r+   handle_if_mouse_downz*if_mousedown.<locals>.handle_if_mouse_down   s*    !^%>>>7;'''!!r,   )rQ   r   r   rR   )r   rM   )rO   rX   s   ` r+   if_mousedownrY      s4    " " " " " " ()))r,   _T_typeclsc                `     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.selfobjectr   r   c                    t          d          sJ t          t                              |                               S )Nr]   )hasattrr   r   r]   )r^   r[   s    r+   __repr__z ptrepr_to_repr.<locals>.__repr__   s<    sM*****$%6st7L7L%M%MNNNr,   )r^   r_   r   r   )ra   	TypeErrorrb   )r[   rb   s   ` r+   ptrepr_to_reprrd      s^     3&& 
^
 
 	
O O O O O O CLJr,   c                    |                      d          }t          |          fd|D             }d                    |          S )zG
    Remove common leading whitespace when all lines are indented.
    T)keependsc                >    g | ]}|t                    d          S rT   )len).0linecommon_prefixs     r+   
<listcomp>z!unindent_code.<locals>.<listcomp>   s,    :::DT#m$$&&':::r,   r   )
splitlines_common_whitespace_prefixjoin)r   linesrk   s     @r+   r   r      sR     OOTO**E .e44M ;:::E:::E775>>r,   stringsIterable[str]c                    d | D             } | sdS t          |           }t          |           }t          |          D ]!\  }}|||         k    s|dvr|d|         c S "|S )zl
    Return common prefix for a list of lines.
    This will ignore lines that contain whitespace only.
    c                `    g | ]+}|                                 t          |          d k    )|,S )r   )isspacerh   )ri   ss     r+   rl   z-_common_whitespace_prefix.<locals>.<listcomp>   s0    IIIQISVVq[[q[[[r,   r   z 	N)minmax	enumerate)rq   s1s2ir*   s        r+   rn   rn      s     JI'IIIG r \\\\bMM 	 	DAqBqEzzQe^^"1"v , 	r,   )r   r   r   r   )r-   r   r.   r/   r0   r/   r   r   )r-   r   r   r   )rO   rM   r   rM   )r[   rZ   r   rZ   )r   r   r   r   )rq   rr   r   r   )(__doc__
__future__r   r$   typingr   r   r   r   r   r	   r
   r   r   prompt_toolkit.documentr   prompt_toolkit.formatted_textr   #prompt_toolkit.formatted_text.utilsr   prompt_toolkit.mouse_eventsr   r   r4   r   r_   rR   __all__r   r   compiler<   r   rM   rY   typerZ   rd   r   rn    r,   r+   <module>r      s    # " " " " " 				
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 - , , , , , ; ; ; ; ; ; E E E E E E B B B B B B B B "      
 "     :   @ &2:&9:: ( ( ( (V WT:,"45666* * * *$ ')4
(
(
(   "        r,   