a
    ze#                     @   s   d dl Z d dlZd dlZd dlZd dlZd\ZZd dlmZ d dl	m
Z
 d dlmZ dZdZdddefZdddefZejej d	 Zej ejrejnd
 Zde ZG dd dZe  edkrd dlmZ eddd dS )    N)r      )autocomplete_w)idleConf)HyperParser)TFTN)FTTNF_ .c                   @   sn   e Zd ZdddZedd Zdd Zddd	Zd
d Zdd Z	dddZ
dd Zdd Zdd Zdd ZdS )AutoCompleteNc                 C   s,   || _ |d ur|j| _d | _d | _d | _d S N)editwintextautocompletewindow_delayed_completion_id_delayed_completion_index)selfr    r   */usr/lib/python3.9/idlelib/autocomplete.py__init__"   s    zAutoComplete.__init__c                 C   s   t jdddddd| _d S )N
extensionsr	   	popupwaitintr   )typedefault)r   Z	GetOptionr   )clsr   r   r   reload-   s    
zAutoComplete.reloadc                 C   s   t | jS r
   )r   ZAutoCompleteWindowr   )r   r   r   r   _make_autocomplete_window2   s    z&AutoComplete._make_autocomplete_windowc                 C   s   | j r| j   d | _ d S r
   )r   Zhide_windowr   eventr   r   r   _remove_autocomplete_window5   s    
z(AutoComplete._remove_autocomplete_windowc                 C   s   |  t dS )Nbreak)open_completionsFORCEr   r   r   r   force_open_completions_event:   s    
z)AutoComplete.force_open_completions_eventc                 C   s^   t |dr|js"| jdd s&d S | jrD| j rD| j  dS | t	}|rVdS d S d S )Nmc_stateinsert linestartinsertr   )
hasattrr#   r   getstripr   Z	is_activecompleter    TAB)r   r   Zopenedr   r   r   autocomplete_event?   s    

zAutoComplete.autocomplete_eventc                 C   sd   | j d}|tv r`|dkr tnt}| j d| _| jd urJ| j | j | j 	| j
| j|| _d S )Nz	insert-1cr   r%   )r   r'   TRIGGERSTRY_ATRY_Findexr   r   after_cancelZafterr   _delayed_open_completions)r   r   Zlastcharargsr   r   r   try_open_completions_eventM   s    

z'AutoComplete.try_open_completions_eventc                 C   s&   d | _ | jd| jkr"| | d S )Nr%   )r   r   r/   r   r    )r   r2   r   r   r   r1   X   s    z&AutoComplete._delayed_open_completionsc                 C   s  |\}}}}| j d ur*| j| j  d | _ t| jd}| jdd}t| }}	| r|rd|tkr| 	  t}|r||d  dt
 vr|d8 }qp|||	 }
|}	|r||d  dvr|d8 }q|||	 }n| r|r|tkr| 	  t}|r*||d  tv s t||d  dkr*|d8 }q|||	 }
|r||d  dkr|dt||d    | }|r|s|dd	krd S nd
}nd S |r|s|
sd S | ||}|d sd S |  | _| j|dt|
 ||| S )Nr%   r$   r   z'"   r   z
insert-%dc(r   r   )r   r   r0   r   r   r'   lenZis_in_stringFILESr   SEPSZ
is_in_codeATTRSID_CHARSordZ	set_indexZget_expressionfindfetch_completionsr   r   Zshow_window)r   r2   Z	evalfuncsr)   ZwantwinmodeZhpZcurlineijZ
comp_startZ	comp_whatZ
comp_listsr   r   r   r    ^   sX    


.


zAutoComplete.open_completionsc           
      C   s  z| j jjjj}W n   d }Y n0 |r<|dd||fi S |tkr|dkri tjj	tj	}t
d|}dd tjD }|| |  d|v rtt
d|}ndd	 |D }nVz@| |}t|}|  d|v rt|j}nd
d	 |D }W n   g g f Y S 0 nf|tkrr|dkr$d}z0tj|}	t|	}|  dd	 |D }W n typ   g g f Y S 0 |s||}||fS d S )NexecZget_the_completion_listr   zdir()c                 s   s   | ]}|d vr|V  qdS )>   NoneTrueFalseNr   .0sr   r   r   	<genexpr>   s   z1AutoComplete.fetch_completions.<locals>.<genexpr>__all__c                 S   s    g | ]}|d d dkr|qS Nr   r   r   rF   r   r   r   
<listcomp>       z2AutoComplete.fetch_completions.<locals>.<listcomp>c                 S   s    g | ]}|d d dkr|qS rK   r   rF   r   r   r   rL      rM   r   c                 S   s    g | ]}|d d dkr|qS )Nr   r   r   rF   r   r   r   rL      rM   )r   flistZpyshellZinterprpccltZ
remotecallr:   __main____builtins____dict__evalkeywordkwlistextendsortsorted
get_entitydirrJ   r8   ospath
expanduserlistdirOSError)
r   Zwhatr?   rO   	namespaceZbiglkwdsZsmalllZentityZexpandedpathr   r   r   r>      sT    








zAutoComplete.fetch_completionsc                 C   s   t |i tjtjS r
   )rS   sysmodulesrP   rR   )r   namer   r   r   rY      s    zAutoComplete.get_entity)N)N)N)__name__
__module____qualname__r   classmethodr   r   r   r"   r+   r3   r1   r    r>   rY   r   r   r   r   r	       s   



<<r	   rP   )mainz#idlelib.idle_test.test_autocomplete   )	verbosity)rP   rT   r[   stringrb   r:   r8   Zidlelibr   Zidlelib.configr   Zidlelib.hyperparserr   r!   r*   r-   r.   ascii_lettersdigitsr;   sepaltsepr9   r,   r	   r   re   Zunittestri   r   r   r   r   <module>   s*   
 <