o =?h$@s dZddlZddlZddlZddlZddlZddejDZede d\Z Z ddl m Z ddlmZdd lmZd Zd Zd d d e fZd d d e fZejejd Zejejr^ejndZdeZGdddZeedkrddl m!Z!e!ddddSdS)zComplete either attribute names or file names. Either on demand or after a user-selected delay after a key character, pop up a list of candidates. NcCsg|]}|dvr|qS)>NoneTrueFalse.0srr;/opt/alt/python310/lib64/python3.10/idlelib/autocomplete.py sr )matchcase)r)autocomplete_w)idleConf) HyperParser)TFTN)FTTNF_.c@sneZdZdddZeddZddZddd Zd d Zd d Z dddZ ddZ ddZ ddZ ddZdS) AutoCompleteNcCs2||_|dur |j|_||_d|_d|_d|_dSN)editwintexttagsautocompletewindow_delayed_completion_id_delayed_completion_index)selfrrrrr __init__(s zAutoComplete.__init__cCstjdddddd|_dS)N extensionsr popupwaitintr)typedefault)rZ GetOptionr)clsrrr reload4s  zAutoComplete.reloadcCstj|j|jdS)N)r)rZAutoCompleteWindowrr)rrrr _make_autocomplete_window9sz&AutoComplete._make_autocomplete_windowcCs|jr |jd|_dSdSr)rZ hide_windowreventrrr _remove_autocomplete_window<s  z(AutoComplete._remove_autocomplete_windowcCs|tdS)zA(^space) Open completion list, even if a function call is needed.break)open_completionsFORCEr&rrr force_open_completions_eventAs z)AutoComplete.force_open_completions_eventcCsZt|dr|js|jddsdS|jr"|jr"|jdS|t }|r+dSdS)z5(tab) Complete word or open list if multiple options.mc_stateinsert linestartinsertNr)) hasattrr-rgetstriprZ is_activecompleter*TAB)rr'Zopenedrrr autocomplete_eventFs   zAutoComplete.autocomplete_eventcCsh|jd}|tvr2|dkrtnt}|jd|_|jdur%|j|j|j |j |j ||_dSdS)z7(./) Open completion list after pause with no movement.z insert-1crr/N) rr1TRIGGERSTRY_ATRY_Findexrr after_cancelZafterr_delayed_open_completions)rr'Zlastcharargsrrr try_open_completions_eventTs    z'AutoComplete.try_open_completions_eventcCs*d|_|jd|jkr||dSdS)z)Call open_completions if index unchanged.Nr/)rrr9rr*)rr<rrr r;_sz&AutoComplete._delayed_open_completionsc Cs&|\}}}}|jdur|j|jd|_t|jd}|jdd}t|}} |r{|r2|tkr{| t}|rT||ddt vrT|d8}|rT||ddt vsD||| } |} |rt||ddvrt|d8}|rt||ddvsf||| } np| r|r|t kr| t }|r||dt vst||ddkr|d8}|r||dt vst||ddks||| } |r||ddkr|dt||d|} | r|s| d d krdSnd } ndS|r| s| sdS|| |} | d sdS||_|j| dt| ||| S) aXFind the completions and create the AutoCompleteWindow. Return True if successful (no syntax error or so found). If complete is True, then if there's nothing to complete and no start of completion, won't open completions and return False. If mode is given, will open a completion list only in this mode. Nr/r.r z'"rz insert-%dc(rr)rrr:rrr1lenZ is_in_stringFILESr(SEPSZ is_in_codeATTRSID_CHARSordZ set_indexZget_expressionfindfetch_completionsr%rZ show_window) rr<Z evalfuncsr3ZwantwinmodeZhpZcurlineijZ comp_startZ comp_whatZ comp_listsrrr r*es^     ((     zAutoComplete.open_completionsc Csbz |jjjjj}Wnd}Y|r|dd||fiS|tkry|dkrOitjj tj }t d|}| t | d|vrGtt d|}nbdd|D}nZz ||}t|}| d|vrgt|j}nd d|D}Wn9ggfYS|tkr|dkrd }ztj|}t|}| d d|D}Wn tyggfYSw|s|}||fS) aOReturn a pair of lists of completions for something. The first list is a sublist of the second. Both are sorted. If there is a Python subprocess, get the comp. list there. Otherwise, either fetch_completions() is running in the subprocess itself or it was called in an IDLE EditorWindow before any script had been run. The subprocess environment is that of the most recently run script. If two unrelated modules are being edited some calltips in the current module may be inoperative if the module was not the last to run. NexecZget_the_completion_listrzdir()__all__cS g|] }|dddkr|qSNr rrrrrr r  z2AutoComplete.fetch_completions..cSrNrOrrrrr r rPrcSrN)Nr rrrrrr r rP)rZflistZpyshellZinterprpccltZ remotecallrD__main__ __builtins____dict__evalextendcompletion_kwdssortsorted get_entitydirrMrBospath expanduserlistdirOSError) rZwhatrIrQ namespaceZbiglZsmalllZentityZ expandedpathrrr rHsV           zAutoComplete.fetch_completionscCst|itjtjS)zBLookup name in a namespace spanning sys.modules and __main.dict__.)rUsysmodulesrRrT)rnamerrr rZszAutoComplete.get_entity)NNr)__name__ __module__ __qualname__r classmethodr$r%r(r,r5r=r;r*rHrZrrrr r&s     < :rrR)mainz#idlelib.idle_test.test_autocomplete) verbosity)"__doc__rRkeywordr\stringrbkwlistrWrVrXrDrBZidlelibrZidlelib.configrZidlelib.hyperparserrr+r4r7r8Z ascii_lettersZdigitsrEsepaltseprCr6rr$reZunittestrirrrr s6       ;