B
    v9a=%                 @   s   d dl Z d dlZd dlZd dlZedd\ZZd dlmZ d dl	m
Z
 d dlmZ ejej d ZejZejrxeej7 ZG dd	 d	Ze  ed
krd dlmZ eddd dS )    N      )autocomplete_w)idleConf)HyperParser_c               @   sv   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 Z
dd Zdd ZdddZdd Zdd ZdS )AutoCompleteNc             C   s,   || _ |d k	r(|j| _d | _d | _d | _d S )N)editwintextautocompletewindow_delayed_completion_id_delayed_completion_index)selfr	    r   "/usr/lib/python3.7/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 )N)r   ZAutoCompleteWindowr
   )r   r   r   r   _make_autocomplete_window.   s    z&AutoComplete._make_autocomplete_windowc             C   s   | j r| j   d | _ d S )N)r   Zhide_window)r   eventr   r   r   _remove_autocomplete_window1   s    
z(AutoComplete._remove_autocomplete_windowc             C   s   |  ddd dS )NTFbreak)open_completions)r   r   r   r   r   force_open_completions_event6   s    z)AutoComplete.force_open_completions_eventc             C   sB   | j d}|dkr&| dddt n|tkr>| dddt d S )Nz	insert-1c.F)r
   get_open_completions_laterCOMPLETE_ATTRIBUTESSEPSCOMPLETE_FILES)r   r   Zlastcharr   r   r   try_open_completions_event=   s    

z'AutoComplete.try_open_completions_eventc             C   sb   t |dr|js"| jdd s&d S | jrD| j rD| j  dS | ddd}|rZdS d S d S )Nmc_statezinsert linestartinsertr   FT)	hasattrr&   r
   r    stripr   Z	is_activecompleter   )r   r   Zopenedr   r   r   autocomplete_eventJ   s    
zAutoComplete.autocomplete_eventc             G   sD   | j d| _| jd k	r&| j | j | j j| j| jf| | _d S )Nr'   )r
   indexr   r   after_cancelZafterr   _delayed_open_completions)r   argsr   r   r   r!   [   s
    
z$AutoComplete._open_completions_laterc             G   s&   d | _ | jd| jkr"| j|  d S )Nr'   )r   r
   r,   r   r   )r   r/   r   r   r   r.   c   s    z&AutoComplete._delayed_open_completionsc             C   s  | j d k	r| j| j  d | _ t| jd}| jdd}t| }}| r|rX|tkr| 	  t}x$|r||d  dt
 kr|d8 }qfW ||| }	|}x |r||d  dkr|d8 }qW ||| }
n| r|r|tkr| 	  t}x:|r(||d  tkst||d  dkr(|d8 }qW ||| }	|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'   zinsert linestartr   z'"   r   z
insert-%dc( r   )r   r
   r-   r   r	   r    lenZis_in_stringr$   r   r#   Z
is_in_coder"   ID_CHARSordZ	set_indexZget_expressionfindfetch_completionsr   r   Zshow_window)r   Z	evalfuncsr*   ZuserWantsWinmodeZhpZcurlineijZ
comp_startZ	comp_whatZ
comp_listsr   r   r   r   h   sN    
0

zAutoComplete.open_completionsc       	      C   s`  y| j jjjj}W n   d }Y nX |r<|dd||fi S |tkr|dkrtjj	tj	}t
d|}|  d|krtt
d|}qdd |D }nPy@| |}t|}|  d|krt|j}ndd |D }W n   g g fS nd|tkrJ|dk rd	}y0tj|}t|}|  d
d |D }W n tk
rH   g g fS X |sT|}||fS d S )NexecZget_the_completion_listr3   zdir()__all__c             S   s    g | ]}|d d dkr|qS )Nr   r   r   ).0sr   r   r   
<listcomp>   s    z2AutoComplete.fetch_completions.<locals>.<listcomp>c             S   s    g | ]}|d d dkr|qS )Nr   r   r   )r>   r?   r   r   r   r@      s    r   c             S   s    g | ]}|d d dkr|qS )Nr   r   r   )r>   r?   r   r   r   r@      s    )r	   flistZpyshellZinterprpccltZ
remotecallr"   __main____builtins____dict__evalsortsorted
get_entitydirr=   r$   ospath
expanduserlistdirOSError)	r   Zwhatr9   rB   	namespaceZbiglZsmalllZentityZexpandedpathr   r   r   r8      sL    







zAutoComplete.fetch_completionsc             C   s   t |tjtjS )N)rF   sysmodulesrC   rE   )r   namer   r   r   rI      s    zAutoComplete.get_entity)N)N)N)__name__
__module____qualname__r   classmethodr   r   r   r   r%   r+   r!   r.   r   r8   rI   r   r   r   r   r      s   


@9r   rC   )mainz#idlelib.idle_test.test_autocomplete   )	verbosity)rC   rK   stringrQ   ranger"   r$   Zidlelibr   Zidlelib.configr   Zidlelib.hyperparserr   Zascii_lettersdigitsr5   sepr#   altsepr   r   rT   ZunittestrX   r   r   r   r   <module>   s"   
 K