o
    ÈQEcûõ  ã                
   @   s,  d dl Z edkre jd e jd< zd dlT W n ey(   ede jd edƒ‚w e jdkrKzd dl	Z	dZ
e	 d	¡ e
¡ W n eeefyJ   Y nw d d
lmZ edk rteƒ at ¡  d dlmZ etƒ ejdde td edƒ‚d dlmZ d dlZd dlZd dlZd dlZd dlmZ d dlZd dlZd dl Z d dl!m"Z" d dl#Z#d dl$Z$d dl%Z%d dl&Z&d dl'm(Z( d dl)m*Z* d dl+m,Z, d dl-m.Z. d dl-m/Z/ d dl0m1Z1m2Z2 d dl3m4Z4 d dl5m6Z6 d dl-m7Z7 d dl-m8Z8 d dlm9Z9m:Z:m;Z; d dl<m=Z= da>d Z?d Z@z
d!ZAeAeB_AeAeC_AW n
 eDy   Y nw e jaE	d@d"d#„ZFdaGd$d%„ ZHeHd&ƒ dejIfd'd(„ZJeJe_IG d)d*„ d*e1ƒZKG d+d,„ d,e4ƒZLG d-d.„ d.e(ƒZMG d/d0„ d0e=ƒZNG d1d2„ d2e,ƒZOG d3d4„ d4e8jPƒZQd5d6„ ZRG d7d8„ d8eƒZSG d9d:„ d:e6ƒZTd;d<„ ZUd=ZVd>d?„ ZWedkreWƒ  eHdƒ dS )Aé    NÚ__main__zidlelib.pyshell)Ú*zJ** IDLE can't import Tkinter.
Your Python may not be configured for Tk. **©Úfileé   Úwin32Zshcore)Ú
messageboxg      !@©Úfix_scalingzIdle Cannot Startz"Idle requires tcl/tk 8.5+, not %s.©Úparent)ÚInteractiveInterpreter)Úpython_version)ÚTextWrapper)ÚColorDelegator)ÚidleConf)Ú	Delegator©Údebugger)Ú
debugger_r)ÚEditorWindowÚfixwordbreaks)ÚFileList)ÚOutputWindow)Úreplace)Úrpc)Úidle_formatwarningÚStdInputFileÚStdOutputFile)ÚUndoDelegatorFz	127.0.0.1zCtrl-D (end-of-file)c              	   C   sN   |du rt }z| t| ||||d¡ | d¡ W dS  ttfy&   Y dS w )a   Show Idle-format warning (after replacing warnings.showwarning).

    The differences are the formatter called, the file=None replacement,
    which can be None, the capture of the consequence AttributeError,
    and the output of a hard-coded prompt.
    N)Úlinez>>> )Úwarning_streamÚwriter   ÚAttributeErrorÚOSError)ÚmessageÚcategoryÚfilenameÚlinenor   r    © r)   úLib\idlelib\pyshell.pyÚidle_showwarningR   s   
ÿÿr+   c                 C   s:   | rt du rtja tt_dS dS t durt t_da dS dS )z>Replace warning.showwarning with idle_showwarning, or reverse.N)Ú_warnings_showwarningÚwarningsÚshowwarningr+   )Zcapturer)   r)   r*   Úcapture_warningse   s   
þþr/   Tc                 C   sX   t j}i }t|ƒD ]}|dd… |dd…  dkr | |¡||< q	|| ƒ | |¡ dS )ao  Extend linecache.checkcache to preserve the <pyshell#...> entries

    Rather than repeating the linecache code, patch it to save the
    <pyshell#...> entries, call the original linecache.checkcache()
    (skipping them), and then restore the saved entries.

    orig_checkcache is bound at definition time to the original
    method, allowing it to be patched.
    Nr   éÿÿÿÿú<>)Ú	linecacheÚcacheÚlistÚpopÚupdate)r'   Zorig_checkcacher3   ÚsaveÚkeyr)   r)   r*   Úextended_linecache_checkcachet   s   €r9   c                   @   sv   e Zd ZdZdd„ Zg d¢Zddd„Zdd	„ Zddd„Zddd„Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd
S )ÚPyShellEditorWindowz6Regular text edit window in IDLE, supports breakpointsc                 G   s–   g | _ tj| g|¢R Ž  | j d| j¡ | j d| j¡ | j d| jj¡ t	j
 tjd¡| _| jj| fdd„}| j |¡ | jjrE|  ¡  |  ¡  d S )Nú<<set-breakpoint-here>>ú<<clear-breakpoint-here>>z<<open-python-shell>>zbreakpoints.lstc                 S   s   |  ¡  | ƒ  d S ©N)Úrestore_file_breaks)Zold_hookÚselfr)   r)   r*   Úfilename_changed_hook™   ó   
z;PyShellEditorWindow.__init__.<locals>.filename_changed_hook)Úbreakpointsr   Ú__init__ÚtextÚbindÚset_breakpoint_hereÚclear_breakpoint_hereÚflistÚ
open_shellÚosÚpathÚjoinr   ZuserdirÚbreakpointPathÚioZfilename_change_hookZset_filename_change_hookr'   r>   Úcolor_breakpoint_text)r?   Úargsr@   r)   r)   r*   rC   Ž   s   ÿ
ÿzPyShellEditorWindow.__init__))ZCutz<<cut>>Úrmenu_check_cut)ÚCopyz<<copy>>Úrmenu_check_copy)ZPastez	<<paste>>Úrmenu_check_paste)NNN)zSet Breakpointr;   N)zClear Breakpointr<   NTc                 C   sD   | j du rdS |rt ¡ }t |d¡}ndddœ}| j d|¡ dS )z,Turn colorizing of breakpoint text on or offNÚbreakÚ )Ú
foregroundÚ
backgroundÚBREAK)rN   r   ÚCurrentThemeÚGetHighlightrD   Z
tag_config)r?   ZcolorÚthemeZcfgr)   r)   r*   rO   «   s   

z)PyShellEditorWindow.color_breakpoint_textc                 C   s„   | j }| jj}| dd| d|d  ¡ z| j |¡ W n ty+   | j |¡ Y nw z| jj	j
j}| ||¡ W d S    Y d S )NrY   z%d.0r   )rD   rN   r'   Útag_addrB   ÚindexÚ
ValueErrorÚappendrH   ÚpyshellÚinterpr   rF   )r?   r(   rD   r'   Údebugr)   r)   r*   Úset_breakpoint·   s   ÿz"PyShellEditorWindow.set_breakpointNc                 C   s>   | j }| jj}|s| ¡  d S tt| d¡ƒƒ}|  |¡ d S )NÚinsert)rD   rN   r'   ÚbellÚintÚfloatr^   rd   )r?   ÚeventrD   r'   r(   r)   r)   r*   rF   Å   s   z'PyShellEditorWindow.set_breakpoint_herec                 C   s„   | j }| jj}|s| ¡  d S tt| d¡ƒƒ}z| j |¡ W n   Y | 	ddd¡ z| j
jjj}| ||¡ W d S    Y d S )Nre   rY   úinsert linestartzinsert lineend +1char)rD   rN   r'   rf   rg   rh   r^   rB   ÚremoveÚ
tag_removerH   ra   rb   r   rG   )r?   ri   rD   r'   r(   rc   r)   r)   r*   rG   Î   s$   ÿz)PyShellEditorWindow.clear_breakpoint_herec                 C   sf   | j r1| j}| jj}|s| ¡  d S g | _ | ddt¡ z| jjj	j
}| |¡ W d S    Y d S d S )NrY   ú1.0)rB   rD   rN   r'   rf   rl   ZENDrH   ra   rb   r   Úclear_file_breaks)r?   rD   r'   rc   r)   r)   r*   rn   á   s   ôz%PyShellEditorWindow.clear_file_breaksc              
   C   sZ  | j }| jj}zt| jdƒ}| ¡ }W d  ƒ n1 sw   Y  W n ty.   g }Y nw zKt| jdƒ:}|D ]}| |d ¡sG| |¡ q9|  	¡  | j }|rg| |d t
|ƒ d ¡ W d  ƒ W dS W d  ƒ W dS 1 ssw   Y  W dS  ty¬ } z&t| jddƒs¡d| j_tjd	d
t
|ƒ | jd W Y d}~dS W Y d}~dS d}~ww )z#Save breakpoints when file is savedÚrNÚwú=Ú
Úbreakpoint_error_displayedFTz
IDLE Errorz$Unable to update breakpoint list:
%s)Útitler%   r   )rB   rN   r'   ÚopenrM   Ú	readlinesr$   Ú
startswithr"   Úupdate_breakpointsÚstrÚgetattrÚrootrs   r   Ú	showerrorrD   )r?   Zbreaksr'   ÚfpÚlinesZnew_filer    Úerrr)   r)   r*   Ústore_file_breaksð   sF   
ÿ€ÿ
€ù&úÿýþ€ÿz%PyShellEditorWindow.store_file_breaksc                 C   sº   | j  ¡  | jd u rd S | jj}|d u rd S tj | j¡rYt| jdƒ}| 	¡ }W d   ƒ n1 s2w   Y  |D ]!}| 
|d ¡rXt|t|ƒd d … ƒ}|D ]}|  |¡ qPq9d S d S )Nro   rq   r   )rD   r6   rN   r'   rJ   rK   ÚisfilerM   ru   rv   rw   ÚevalÚlenrd   )r?   r'   r}   r~   r    Zbreakpoint_linenumbersZbreakpoint_linenumberr)   r)   r*   r>     s$   


ÿ€ùz'PyShellEditorWindow.restore_file_breaksc                 C   s$   | j }| d¡}|  |¡}|| _dS )z3Retrieves all the breakpoints in the current windowrY   N)rD   Z
tag_rangesÚranges_to_linenumbersrB   )r?   rD   ÚrangesZlinenumber_listr)   r)   r*   rx   +  s   


z&PyShellEditorWindow.update_breakpointsc                 C   sh   g }t dt|ƒdƒD ]'}tt|| jƒƒ}tt||d  jƒƒ}||k r1| |¡ |d7 }||k s$q
|S )Nr   é   r   )Úrangerƒ   rg   rh   Ústringr`   )r?   r…   r~   r^   r(   Úendr)   r)   r*   r„   2  s   
þ€z)PyShellEditorWindow.ranges_to_linenumbersc                 C   s   |   ¡  t | ¡ dS )z7Extend base method - clear breaks when module is closedN)rn   r   Ú_close©r?   r)   r)   r*   rŠ   C  s   zPyShellEditorWindow._close)Tr=   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rC   Úrmenu_specsrO   rd   rF   rG   rn   r€   r>   rx   r„   rŠ   r)   r)   r)   r*   r:   ‹   s    
	

	*r:   c                   @   s"   e Zd ZdZeZdZddd„ZdS )ÚPyShellFileListz8Extend base class: IDLE supports a shell and breakpointsNc                 C   s<   | j r| j j ¡  | j S t| ƒ| _ | j r| j  ¡ sd S | j S r=   )ra   ÚtopÚwakeupÚPyShellÚbegin©r?   ri   r)   r)   r*   rI   R  s   
ü
zPyShellFileList.open_shellr=   )rŒ   r   rŽ   r   r:   r   ra   rI   r)   r)   r)   r*   r‘   I  s
    r‘   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚModifiedColorDelegatorz8Extend base class: colorizer for the shell window itselfc                 C   s*   |   ddd¡ |  ddd¡ t | ¡ d S )NZTODOrm   ÚiomarkZSYNC)rl   r]   r   Úrecolorize_mainr‹   r)   r)   r*   r™   _  s   z&ModifiedColorDelegator.recolorize_mainc                 C   s   | j D ]	}|  |dd¡ qd S )Nr˜   r‰   )Ztagdefsrl   )r?   Útagr)   r)   r*   Úremovecolorsd  s   
ÿz#ModifiedColorDelegator.removecolorsN)rŒ   r   rŽ   r   r™   r›   r)   r)   r)   r*   r—   ]  s    r—   c                       s4   e Zd ZdZd	dd„Zd	dd„Z‡ fdd„Z‡  ZS )
ÚModifiedUndoDelegatorz;Extend base class: forbid insert/delete before the I/O markNc                 C   sL   z| j  |dd¡r| j  ¡  W d S W n	 ty   Y nw t | |||¡ d S ©Nú<r˜   )ÚdelegateÚcomparerf   ÚTclErrorr   re   ©r?   r^   ÚcharsÚtagsr)   r)   r*   re   l  s   
þÿzModifiedUndoDelegator.insertc                 C   sJ   z| j  |dd¡r| j  ¡  W d S W n	 ty   Y nw t | ||¡ d S r   )rŸ   r    rf   r¡   r   Údelete)r?   Zindex1Úindex2r)   r)   r*   r¥   u  s   
þÿzModifiedUndoDelegator.deletec                    s>   | j j‰ ‡ fdd„| j _ztƒ  |¡ W ˆ | j _d S ˆ | j _w )Nc                    s   ˆ | |dƒS ©NÚstdinr)   )r^   r£   ©Zorig_insertr)   r*   Ú<lambda>…  ó    z2ModifiedUndoDelegator.undo_event.<locals>.<lambda>)rŸ   re   ÚsuperÚ
undo_eventr–   ©Ú	__class__r©   r*   r­   ~  s   
ÿz ModifiedUndoDelegator.undo_eventr=   )rŒ   r   rŽ   r   re   r¥   r­   Ú__classcell__r)   r)   r®   r*   rœ   j  s
    

		rœ   c                   @   s   e Zd ZdZddd„ZdS )ÚUserInputTaggingDelegatorz.Delegator used to tag user input with "stdin".Nc                 C   s    |d u rd}| j  |||¡ d S r§   )rŸ   re   r¢   r)   r)   r*   re   Ž  s   z UserInputTaggingDelegator.insertr=   )rŒ   r   rŽ   r   re   r)   r)   r)   r*   r±   Œ  s    r±   c                   @   s   e Zd Zdd„ ZdS )ÚMyRPCClientc                 C   s   t ‚)z0Override the base class - just re-raise EOFError)ÚEOFErrorr‹   r)   r)   r*   Ú
handle_EOF–  ó   zMyRPCClient.handle_EOFN)rŒ   r   rŽ   r´   r)   r)   r)   r*   r²   ”  s    r²   c                 C   sZ   d|pd› d}| t |ƒkr't| t |ƒ dƒ\}}|| d › |› |d › S |dd… S )z¹Return width long restart line formatted with filename.

    Fill line with balanced '='s, with any extras and at least one at
    the beginning.  Do not end with a trailing space.
    z= RESTART: ZShellz =r†   rq   Néþÿÿÿ)rƒ   Údivmod)Úwidthr'   rš   ZdivÚmodr)   r)   r*   Úrestart_lineš  s
   rº   c                   @   s  e Zd Zdd„ ZdZdZdZ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@dd„ZdZdd„ ZdZdd„ Zdd„ Zdd„ Zd d!„ Zd"Zd#d$„ ZdAd%d&„Zd'd(„ Zd)d*„ Zd+d,„ ZdAd-d.„Zd/d0„ Zd1d2„ Zd3d4„ Z d5d6„ Z!d7d8„ Z"d9d:„ Z#d;d<„ Z$d=d>„ Z%dS )BÚModifiedInterpreterc                 C   sB   || _ tjd j}tj| |d d| _d | _t| _	| j
jj| _d S )Nr   )ÚlocalsF)Ú	tkconsoleÚsysÚmodulesÚ__dict__r   rC   Ú
restartingÚsubprocess_arglistÚPORTÚportÚcompileÚcompilerÚflagsÚoriginal_compiler_flags)r?   r½   r¼   r)   r)   r*   rC   ª  s   zModifiedInterpreter.__init__Nc                 C   s&   | j d u r
|  ¡ | _ t | j ¡| _d S r=   )rÂ   Úbuild_subprocess_arglistÚ
subprocessÚPopenÚ
rpcsubprocr‹   r)   r)   r*   Úspawn_subprocess·  s   

z$ModifiedInterpreter.spawn_subprocessc                 C   s\   | j dks	J dƒ‚dd„ tjD ƒ}tjddddd	d
}d|f }tjg| d|t| j ƒg S )Nr   z/Socket should have been assigned a port number.c                 S   s   g | ]}d | ‘qS )z-Wr)   )Ú.0Úsr)   r)   r*   Ú
<listcomp>¿  s    z@ModifiedInterpreter.build_subprocess_arglist.<locals>.<listcomp>ÚmainÚGeneralzdelete-exitfuncFÚbool)ÚdefaultÚtypez&__import__('idlelib.run').run.main(%r)ú-c)rÄ   r¾   Úwarnoptionsr   Ú	GetOptionÚ
executablery   )r?   rp   Z	del_exitfZcommandr)   r)   r*   rÉ   ¼  s   ÿ
ÿ
z,ModifiedInterpreter.build_subprocess_arglistc              	   C   sP  t | jf}tdƒD ]}t |¡ zt|ƒ| _W  n ty!   Y q	w |  ¡  d S | jj	 
¡ d | _tdkr@| jj	 tjtjd¡ |  ¡  | jj	 d¡ z| j ¡  W n ty`   |  ¡  Y d S w | j d| j¡ | j d| jj¡ | j d| jj¡ | j d| jj¡ | j d	| jj¡ | j d
t¡ | j d| ¡ | jdd |  ¡  | jS )Né   r   r   é
   Úconsoler¨   ÚstdoutÚstderrrH   r2   rb   T©Úwith_cwd)ÚHOSTrÄ   r‡   ÚtimeÚsleepr²   Úrpccltr$   Údisplay_port_binding_errorÚlistening_sockZgetsocknamerÃ   Z
setsockoptÚsocketZ
SOL_SOCKETZSO_REUSEADDRrÍ   Z
settimeoutÚacceptÚTimeoutErrorÚdisplay_no_subprocess_errorÚregisterr½   r¨   rÝ   rÞ   rH   r2   Útransfer_pathÚpoll_subprocess)r?   ZaddrÚir)   r)   r*   Ústart_subprocessÈ  sD   


ÿÿþz$ModifiedInterpreter.start_subprocessFrV   c                 C   s&  | j r| jS d| _ |  ¡ }|rzt | j¡ W n   Y | j ¡  |  ¡  | j}|j}d|_|  	¡  z| j 
¡  W n tyG   |  ¡  Y d S w | j|d | ¡  |j dd¡ | d¡ | t|j|ƒ¡ |j dd¡ |j dd¡ |s{| ¡  |r‡t | j¡ | ¡  | j| jj_d| _ | jS )	NTFrß   r˜   úend-1crr   ÚrestartÚleft)rÁ   rä   Úgetdebuggerr   Zclose_subprocess_debuggerÚcloseÚterminate_subprocessr½   Ú	executingrÍ   rè   ré   rê   rì   Ústop_readlinerD   r¥   r"   rº   r¸   Úmark_setÚmark_gravityÚ
showpromptZrestart_subprocess_debuggerÚload_breakpointsrÈ   rÅ   rÆ   rÇ   )r?   rà   r'   rc   rÜ   Zwas_executingr)   r)   r*   Úrestart_subprocessó  sH   
þ
z&ModifiedInterpreter.restart_subprocessc                 C   s   | j  dddi ¡ d S )NÚexecZinterrupt_the_serverr)   )rä   Z
remotecallr‹   r)   r)   r*   Z__request_interrupt  ó   z'ModifiedInterpreter.__request_interruptc                 C   s   t j| jd ¡  d S )N)Útarget)Ú	threadingZThreadÚ'_ModifiedInterpreter__request_interruptÚstartr‹   r)   r)   r*   Úinterrupt_subprocess"  rþ   z(ModifiedInterpreter.interrupt_subprocessc                 C   sz   | j d ur| jj | j ¡ z| jj ¡  W n	 ty   Y nw z| j ¡  W n	 ty/   Y nw |  ¡  d| j_	d | _d S )NF)
Ú_afteridr½   rD   Zafter_cancelrä   ræ   rô   r#   rõ   rö   r‹   r)   r)   r*   Úkill_subprocess%  s   
ÿÿ
z#ModifiedInterpreter.kill_subprocessc                 C   sJ   z| j  ¡  W n
 ty   Y dS w z| j  ¡  W dS  ty$   Y dS w )z"Make sure subprocess is terminatedN)rÌ   Úkillr$   Úwaitr‹   r)   r)   r*   rõ   4  s   þÿz(ModifiedInterpreter.terminate_subprocessc                 C   s2   |rdg}|  tj¡ ntj}|  d|f ¡ d S )NrV   zRif 1:
        import sys as _sys
        _sys.path = %r
        del _sys
        
)Úextendr¾   rK   Ú
runcommand)r?   rà   rK   r)   r)   r*   rì   A  s   
üz!ModifiedInterpreter.transfer_pathc              
   C   s2  | j }|d u r	d S z
|j| jdd}W n tttfy,   | jjr$Y d S d }|  ¡  Y nw |r…| j 	¡  d | _|\}}| jj
}|dkrP|d urOtt|ƒ|d n$|dkr_| j d¡r^|  ¡  n|dkrtd}t||tjd t|||d z| j ¡  W n	 ty„   Y nw | jjs—| jj | jj| j¡| _d S d S )	Ngš™™™™™©?)r  ZOKr   Z	EXCEPTIONú<<toggle-jit-stack-viewer>>ÚERRORz/pyshell.ModifiedInterpreter: Subprocess ERROR:
)rä   ZpollresponseÚ
active_seqr³   r$   ÚKeyboardInterruptr½   Úclosingrü   ÚresetoutputrÜ   ÚprintÚreprÚgetvarÚremote_stack_viewerr¾   Ú
__stderr__Úendexecutingr#   rD   ÚafterÚpollintervalrí   r  )r?   ZcltÚresponseZhowZwhatrÜ   Úerrmsgr)   r)   r*   rí   P  sL   ú
€€ÿ

ÿÿz#ModifiedInterpreter.poll_subprocessc                 C   s
   || _ d S r=   r   )r?   r   r)   r)   r*   Úsetdebuggerx  s   
zModifiedInterpreter.setdebuggerc                 C   ó   | j S r=   r   r‹   r)   r)   r*   ró   {  ó   zModifiedInterpreter.getdebuggerc                 C   s   | j j d| j¡ dS )a’  Initiate the remote stack viewer from a separate thread.

        This method is called from the subprocess, and by returning from this
        method we allow the subprocess to unblock.  After a bit the shell
        requests the subprocess to open the remote stack viewer which returns a
        static object looking at the last exception.  It is queried through
        the RPC mechanism.

        i,  N)r½   rD   r  r  r‹   r)   r)   r*   Úopen_remote_stack_viewer~  s   
z,ModifiedInterpreter.open_remote_stack_viewerc                 C   s°   ddl m} | j dddi ¡}|d u r| jj ¡  d S | | j|¡}ddlm	}m
} t| jjƒ}t ¡ }t |d¡d }|||dd	}	|	jjd
dd ||	jd |ƒ}
|
 ¡  d S )Nr   )Ú
debugobj_rrý   Zstackviewer)rH   )ÚScrolledCanvasÚTreeNodeÚnormalrX   )ÚbgZhighlightthicknessr   Zboth)ÚexpandÚfill)Úidlelibr  rä   Úremotequeuer½   r{   rf   ZStubObjectTreeItemZidlelib.treer  r   ZToplevelr   rZ   r[   ÚframeZpackZcanvasr#  )r?   r  ZoidÚitemr  r   r’   r\   rX   ZscZnoder)   r)   r*   r  ‹  s   z'ModifiedInterpreter.remote_stack_viewerr   c                 C   s   |   |¡}|  ||¡ dS )z1Like runsource() but assumes complete exec sourceN)ÚstuffsourceÚexecfile©r?   Úsourcer'   r)   r)   r*   Ú
execsourcež  s   
zModifiedInterpreter.execsourcec              	   C   sÂ   |du r-t  |¡}| ¡ }trdtj |¡› d| d }W d  ƒ n1 s(w   Y  zt||dƒ}W n$ tt	fyY   | j
 ¡  td| j
jd t | |¡ | j
 ¡  Y dS w |  |¡ dS )zExecute an existing fileNz__file__ = r'''z'''
z
del __file__rý   zB*** Error in script or command!
Traceback (most recent call last):r   )Útokenizeru   ÚreadÚuse_subprocessrJ   rK   ÚabspathrÅ   ÚOverflowErrorÚSyntaxErrorr½   r  r  rÞ   r   Úshowsyntaxerrorrú   Úruncode)r?   r'   r,  r}   Úcoder)   r)   r*   r*  £  s,   ÿÿ€ý
þúzModifiedInterpreter.execfilec                 C   s&   |   |¡}t|tƒsJ ‚t | ||¡S )zBExtend base class method: Stuff the source in the line cache first)r)  Ú
isinstancery   r   Ú	runsourcer+  r)   r)   r*   r8  ·  s   
zModifiedInterpreter.runsourcec                 C   s>   d| j  }| j d | _ | d¡}t|ƒd d||ftj|< |S )z"Stuff source in the filename cachez<pyshell#%d>r   rr   r   )ÚgidÚsplitrƒ   r2   r3   )r?   r,  r'   r~   r)   r)   r*   r)  À  s
   

zModifiedInterpreter.stuffsourcec                 C   s   |   d|f ¡ dS )z>Prepend sys.path with file's directory if not already includeda(  if 1:
            _filename = %r
            import sys as _sys
            from os.path import dirname as _dirname
            _dir = _dirname(_filename)
            if not _dir in _sys.path:
                _sys.path.insert(0, _dir)
            del _filename, _sys, _dirname, _dir
            
N)r	  ©r?   r'   r)   r)   r*   Úprepend_syspathÈ  s   
øz#ModifiedInterpreter.prepend_syspathc                 C   sÄ   | j }|j}| ddd¡ t ¡ \}}}t|ddƒp|pd}t|ddƒp%d}t|d	dƒp-d
}	|	d
kr6|d7 }|dkrAd|	d  }
n
d|d |	d f }
| ||
¡ | ¡  |  d| ¡ | 	¡  dS )z§Override Interactive Interpreter method: Use Colorizing

        Color the offending position instead of printing it and pointing at it
        with a caret.

        r  rm   r‰   ÚmsgrV   z<no detail available>r(   r   Úoffsetr   ziomark + %d charsz&iomark linestart + %d lines + %d charszSyntaxError: %s
N)
r½   rD   rl   r¾   Úexc_inforz   Zcolorize_syntax_errorr  r"   rú   )r?   r'   r½   rD   rÕ   ÚvalueÚtbr=  r(   r>  Úposr)   r)   r*   r4  Ô  s$   ÿz#ModifiedInterpreter.showsyntaxerrorc                 C   s:   | j  ¡  |  ¡  t | ¡ | j  d¡r| j  ¡  dS dS )z1Extend base class method to reset output properlyr
  N)r½   r  Úchecklinecacher   Úshowtracebackr  Úopen_stack_viewerr‹   r)   r)   r*   rD  î  s   

ÿz!ModifiedInterpreter.showtracebackc                 C   s>   t j}t| ¡ ƒD ]}|d d… |dd …  dkr||= q	d S )Nr   r0   r1   )r2   r3   r4   Úkeys)r?   Úcr8   r)   r)   r*   rC  ö  s   €þz"ModifiedInterpreter.checklinecachec                 C   sB   | j jr
|  ¡  dS | jr| j dd|fi ¡ dS t|| jƒ dS )z*Run the code without invoking the debuggerr   rý   r5  r   )r½   rö   Údisplay_executing_dialogrä   r&  rý   r¼   )r?   r6  r)   r)   r*   r	  ü  s   ÿzModifiedInterpreter.runcommandc                 C   sd  | j jr|  ¡  |  ¡  | j}zŽz*| j  ¡  |s)| jdur)| j dd|fi ¡| _n|r3| 	|| j
¡ nt|| j
ƒ W nK tyY   | j jsVtjddd| j jdrQ‚ |  ¡  n‚ Y n-   trptd| j jd	 |  ¡  | j  ¡  n| j jrd
| j _td| j jd	 n|  ¡  Y W tsœz| j  ¡  W dS  ty›   Y dS w dS ts±z| j  ¡  W w  ty°   Y w w w )úOverride base class methodNrý   r5  zExit?zDo you want to exit altogether?Zyes©rÔ   r   z IDLE internal error in runcode()r   Fr  )r½   rö   rü   rC  r   Úbeginexecutingrä   Z
asyncqueuer  Úrunr¼   rý   Ú
SystemExitr  r   ZaskyesnorD   rD  r0  r  rÞ   r  Úcanceledr#   )r?   r6  r   r)   r)   r*   r5    sf   

ÿ€ü
þÿ€ÿýÿýzModifiedInterpreter.runcodec                 C   s   | j j |¡S )rI  )r½   rÞ   r"   )r?   rÏ   r)   r)   r*   r"   6  s   zModifiedInterpreter.writec                 C   ó   t jdd| jjd d S )NzPort Binding ErroraA  IDLE can't bind to a TCP/IP port, which is necessary to communicate with its Python execution server.  This might be because no networking is installed on this computer.  Run IDLE with the -n command line switch to start without a subprocess and refer to Help/IDLE Help 'Running without a subprocess' for further details.r   ©r   r|   r½   rD   r‹   r)   r)   r*   rå   :  s
   
øz.ModifiedInterpreter.display_port_binding_errorc                 C   rO  )NzSubprocess Connection Errorz¢IDLE's subprocess didn't make connection.
See the 'Startup failure' section of the IDLE doc, online at
https://docs.python.org/3/library/idle.html#startup-failurer   rP  r‹   r)   r)   r*   rê   E  s
   
ûz/ModifiedInterpreter.display_no_subprocess_errorc                 C   rO  )NzAlready executingzYThe Python Shell window is already executing a command; please wait until it is finished.r   rP  r‹   r)   r)   r*   rH  M  s
   
üz,ModifiedInterpreter.display_executing_dialog)FrV   )Fr=   )&rŒ   r   rŽ   rC   r  rä   rÌ   rÍ   rÉ   rï   rü   r  r  r  rõ   rì   r  rí   r   r  ró   r  r  r9  r-  r*  r8  r)  r<  r4  rD  rC  r	  r5  r"   rå   rê   rH  r)   r)   r)   r*   r»   ¨  sH    	
+,
&
	
.r»   c                       s&  e Zd ZddlmZ deƒ  ZeZe	Z
g d¢Zejdg Zdeee dd„ e¡ƒƒ Ze ed	¡ [d
ZdZddlmZ ddlmZ dfdd„Z‡ fdd„Z‡ fdd„Zdd„ Zdd„ Zdd„ Zdfdd„Z d
Z!d
Z"d
Z#d
Z$d
Z%d
Z&dd„ Z'dd „ Z(dfd!d"„Z)d#d$„ Z*dfd%d&„Z+d'd(„ Z,d)d*„ Z-d+d,„ Z.d-d.„ Z/d/d0„ Z0d1d2„ Z1d3d4„ Z2d5d6„ Z3d7d8„ Z4d9Z5d:d;„ Z6d<d=„ Z7d>d?„ Z8d@dA„ Z9dfdBdC„Z:dDdE„ Z;dFdG„ Z<dHdI„ Z=dJdK„ Z>e? @dL¡ZAdMdN„ ZBdfdOdP„ZCdfdQdR„ZDdfdSdT„ZEdUdV„ ZFdWdX„ ZGdYdZ„ ZHdgd\d]„ZI‡ fd^d_„ZJ‡ fd`da„ZKdfdbdc„ZLddde„ ZM‡  ZNS )hr”   r   )ÚSqueezerzIDLE Shell ))r   Z_File)ZeditZ_Edit)rc   Z_Debug)ÚoptionsZ_Options)ZwindowZ_Window)ÚhelpZ_Help)ZSqueezeú<<squeeze-current-text>>r   c                 C   s   | d dkS )Nr   rR   r)   )Z
rmenu_itemr)   r)   r*   rª   m  r«   zPyShell.<lambda>)zCopy with promptsú<<copy-with-prompts>>rS   Fr¨   )ÚHistory)ÚShellSidebarNc                 C   sX  t r| j}|d d dkr| dd¡ t| ƒ| _|d u r+tƒ }t|ƒ | ¡  t|ƒ}d | _	t
 | |d d ¡ d| _d| _ttdƒrDtjnd| _| j d	¡d
 | _| j| _| j}|jdd | d| j¡ | d| j¡ | d| j¡ | d| j¡ | d| j¡ | d| j¡ | d| j¡ | d| j¡ t r¥| d| j ¡ | d| j!¡ |  "| ¡| _#| d| j$¡ tj%| _&tj'| _(tj)| _*ddl+m,} t-| d|j.|j/ƒ| _)t0| d|j.|j/ƒ| _%t0| d|j.dƒ| _'t0| d|j.|j/ƒ| _1t sù| j%t_%| j't_'| j)t_)z
dd l2}|j3|_4W n   tj5t_'‚ |  6| j¡| _7d| _8|  9| ¡| _	| j:j;j| j_| j: <t=ƒ ¡ d S )Nr†   r   Úshell)rX  ZShe_llFé   Úps1z>>>
rr   r0   Úchar)Úwrapz<<newline-and-indent>>z<<plain-newline-and-indent>>z<<interrupt-execution>>z<<end-of-file>>z<<open-stack-viewer>>ú<<toggle-debugger>>r
  rU  z<<view-restart>>z<<restart-shell>>rT  )Úiomenur¨   rÝ   rÞ   ÚbackslashreplacerÜ   é2   )>r0  Ú
menu_specsre   r»   rb   ÚTkr   Úwithdrawr‘   Úshell_sidebarr   rC   ZusetabsZindentwidthÚhasattrr¾   rZ  Úsys_ps1r:  Zprompt_last_lineÚpromptrD   Z	configurerE   Úenter_callbackÚlinefeed_callbackÚcancel_callbackÚeof_callbackrE  Útoggle_debuggerÚtoggle_jit_stack_viewerÚcopy_with_prompts_callbackÚview_restart_markÚrestart_shellrQ  ÚsqueezerÚsqueeze_current_text_eventrÝ   Úsave_stdoutrÞ   Úsave_stderrr¨   Ú
save_stdinr%  r^  r   ÚencodingÚerrorsr   rÜ   ÚpydocZ
plainpagerZpagerr  rV  Úhistoryr  rW  Úperr’   Zinsertfilterr±   )r?   rH   Úmsr{   rD   r^  rx  r)   r)   r*   rC   {  s‚   
ÿÿÿÿÿzPyShell.__init__c                    s&   t ƒ  ¡  | jd ur| j ¡  d S d S r=   )r¬   Ú	ResetFontrd  Zupdate_fontr‹   r®   r)   r*   r|  É  s   

ÿzPyShell.ResetFontc                    s€   t ƒ  ¡  t ¡ }d d dœt |d¡t |d¡t |d¡dœ}| ¡ D ]\}}| jj|fi |¤Ž q#| jd ur>| j 	¡  d S d S )N)rX   rW   rÝ   rÞ   r!  )r¨   rÝ   rÞ   rÜ   )
r¬   ÚResetColorizerr   rZ   r[   ÚitemsrD   Ztag_configurerd  Zupdate_colors)r?   r\   Z
tag_colorsrš   Ztag_colors_configr®   r)   r*   r}  Ï  s   



ü
ÿzPyShell.ResetColorizerc                 C   s   t j | jdd dS )Nr¨   )Zinsert_tagsrU   )r   rD   r–   r)   r)   r*   Úreplace_eventß  s   zPyShell.replace_eventc                 C   s   t jddS )NT)Z
shell_only)r   ZGetExtensionsr‹   r)   r)   r*   Úget_standard_extension_namesã  s   z$PyShell.get_standard_extension_namesc                    s\   ˆ j  ||¡}ttt|ƒƒtt|ƒƒƒ}‡ fdd„|D ƒ}d dd„ t|| ¡ ƒD ƒ¡d S )z6Return text between first and last with prompts added.c                    s   g | ]	}ˆ j j |¡‘qS r)   )rd  Zline_promptsÚget)rÎ   r(   r‹   r)   r*   rÐ   í  s    ÿÿz+PyShell.get_prompt_text.<locals>.<listcomp>rr   c                 s   s.    | ]\}}|d u r|n|› d|› V  qd S )Nú r)   )rÎ   rg  r    r)   r)   r*   Ú	<genexpr>ñ  s
   € ÿ
ÿz*PyShell.get_prompt_text.<locals>.<genexpr>)rD   r  r‡   rg   rh   rL   ÚzipÚ
splitlines)r?   ÚfirstZlastrD   Zlineno_rangeZpromptsr)   r‹   r*   Úget_prompt_textæ  s   

þ
þ
þýzPyShell.get_prompt_textc                 C   s^   | j }| d¡}|du rdS | d¡}|d dkr| d¡}| ¡  |  ||¡}| |¡ dS )a  Copy selected lines to the clipboard, with prompts.

        This makes the copied text useful for doc-tests and interactive
        shell code examples.

        This always copies entire lines, even if only part of the first
        and/or last lines is selected.
        zsel.first linestartNúsel.lastr0   Ú0zsel.last+1line linestart)rD   r^   Zclipboard_clearr‡  Zclipboard_append)r?   ri   rD   ZselfirstZsellastZprompt_textr)   r)   r*   rn  ÷  s   	


z"PyShell.copy_with_prompts_callbackc                 C   s   |a d S r=   ©r!   )r?   Ústreamr)   r)   r*   Úset_warning_stream  s   zPyShell.set_warning_streamc                 C   s   t S r=   rŠ  r‹   r)   r)   r*   Úget_warning_stream  ó   zPyShell.get_warning_streamc                 C   sJ   | j rtjdd| jd |  ¡  dS | j ¡ }|r|  ¡  d S |  ¡  d S )NzDon't debug nowz*You can only toggle the debugger when idler   rU   )	rö   r   r|   rD   Úset_debugger_indicatorrb   ró   Úclose_debuggerÚopen_debugger)r?   ri   Údbr)   r)   r*   rl    s   þ
zPyShell.toggle_debuggerc                 C   s   | j  ¡ }|  d|  ¡ d S )Nr]  )rb   ró   Zsetvar©r?   r’  r)   r)   r*   r  '  s   
zPyShell.set_debugger_indicatorc                 C   s   d S r=   r)   r–   r)   r)   r*   rm  +  rŽ  zPyShell.toggle_jit_stack_viewerc                 C   sh   | j  ¡ }|r.| j  d ¡ | ¡  | j jrt | j j¡ |  ¡  | j 	d¡ | j
| _|  ¡  |  ¡  d S )Nz[DEBUG OFF]
)rb   ró   r  rô   rä   r   Zclose_remote_debuggerr  rÜ   r"   rf  rg  rú   r  r“  r)   r)   r*   r  .  s   
zPyShell.close_debuggerc                 C   sX   | j jrt | j j| ¡}nt | ¡}| j  |¡ | ¡  d| j | _	|  
¡  |  ¡  d S )Nz[DEBUG ON]
)rb   rä   r   Zstart_remote_debuggerr   ZDebuggerr  rû   rf  rg  rú   r  )r?   Zdbg_guir)   r)   r*   r‘  ;  s   
ÿ
zPyShell.open_debuggerc                 C   s    | j rdnd}|  dd|¡ d S )NÚdisabledr!  rc   z*tack*iewer)rö   Zupdate_menu_state)r?   Ústater)   r)   r*   Údebug_menu_postcommandG  s   zPyShell.debug_menu_postcommandc                 C   s   |   ¡  d| _dS )úHelper for ModifiedInterpreterTN)r  rö   r‹   r)   r)   r*   rK  K  rA   zPyShell.beginexecutingc                 C   s   d| _ d| _|  ¡  dS )r—  FN)rö   rN  rú   r‹   r)   r)   r*   r  P  s   zPyShell.endexecutingc                 C   sD   | j rtjddd| jd}|du rdS |  ¡  d| _d| _t | ¡S )zExtend EditorWindow.close()zKill?z7Your program is still running!
 Do you want to kill it?ÚokrJ  FÚcancelT)	rö   r   ZaskokcancelrD   r÷   rN  r  r   rô   )r?   r  r)   r)   r*   rô   V  s   ü
zPyShell.closec                 C   sV   |   ¡  tr| j ¡  | jt_| jt_| j	t_
d| _d| _d| j_d| _t | ¡ dS )zEExtend EditorWindow._close(), shut down debugger and execution serverN)r  r0  rb   r  rs  r¾   rÝ   rt  rÞ   ru  r¨   rÜ   rH   ra   ry  r   rŠ   r‹   r)   r)   r*   rŠ   e  s   
zPyShell._closec                 C   ó   dS )z8Override EditorWindow method: never remove the colorizerTr)   r;  r)   r)   r*   Úispythonsourceu  rµ   zPyShell.ispythonsourcec                 C   r  r=   )Úshell_titler‹   r)   r)   r*   Úshort_titley  r  zPyShell.short_titlezHType "help", "copyright", "credits" or "license()" for more information.c                 C   sŒ   | j  dd¡ |  ¡  trd}| j ¡ }|s|  ¡  dS nd}tjt	_|  
dt	jt	j| j|f ¡ | j  ¡  |  ¡  dd l}d|_d |_dS )	Nr˜   re   rV   Fz›==== No Subprocess ====

WARNING: Running IDLE without a Subprocess is deprecated
and will be removed in a later version. See Help/IDLE Help
for details.

zPython %s on %s
%s
%sr   T)rD   rø   r  r0  rb   rï   rô   r   Údisplayhookr¾   r"   ÚversionÚplatformÚ	COPYRIGHTZfocus_forcerú   ÚtkinterZ_support_default_rootZ_default_root)r?   ZnosubZclientr¢  r)   r)   r*   r•     s(   
þÿ
zPyShell.beginc                 C   s   | j sd S d| _| j ¡  d S ©NT)ÚreadingÚ_stop_readline_flagr’   Úquitr‹   r)   r)   r*   r÷   ™  s   zPyShell.stop_readlinec                 C   sˆ   | j }zd| _ | j ¡  W || _ n|| _ w | jrd| _dS | j dd¡}t|ƒdkr,d}|  ¡  | jr:d| _t	s:t
‚| jrBd| _d}|S )NTFrV   r˜   rð   r   rr   )r¤  r’   Úmainloopr¥  rD   r  rƒ   r  rN  r0  r  Ú	endoffile)r?   r7   r    r)   r)   r*   ÚreadlineŸ  s(   zPyShell.readlinec                 C   rš  r£  r)   r‹   r)   r)   r*   Úisatty¶  rŽ  zPyShell.isattyc                 C   sž   z| j  ddd¡rW d S W n   Y | js(| js(|  ¡  | j d¡ |  ¡  dS d| _d| _	| jrE| jj
rE| j ¡ r@| j ¡  n| j ¡  | jrM| j ¡  dS )Nú	sel.firstz!=rˆ  zKeyboardInterrupt
rU   FT)rD   r    rö   r¤  r  rb   r"   rú   r¨  rN  rä   ró   rü   r  r’   r¦  r–   r)   r)   r*   rj  ¹  s(   ÿ


zPyShell.cancel_callbackc                 C   sh   | j r| jsd S | j ddd¡r| j ddd¡sd S | j s'|  ¡  |  ¡  dS d| _d| _| j 	¡  dS )Nr˜   z==re   rð   FTrU   )
rö   r¤  rD   r    r  rô   rN  r¨  r’   r¦  r–   r)   r)   r*   rk  Ï  s   ÿý
zPyShell.eof_callbackc                 C   s2   | j r| j dd¡ | j d¡ dS |  |¡ dS )Nre   rr   rU   )r¤  rD   re   ÚseeÚnewline_and_indent_eventr–   r)   r)   r*   ri  Þ  s   
ÿzPyShell.linefeed_callbackc           	      C   s   | j r| jsd S z| j dd¡}|r#| j ddd¡r#|  ||¡ W dS W n   Y | j ddd¡r| j d	d¡}|rž| j dd|d
 ¡ržd| j d¡vrž| j dd¡}|rj| j |d
 d|d ¡rj|d
 |d
 f}| j dd¡}|r| j |d d|d
 ¡r|d | j 	|d d ¡f}|  | j |d |d
 ¡|¡ dS | j d	d¡}|rå| j dd|d ¡rå| j dd¡}|rÔ| j |d d|d
 ¡rÔ|d | j 	|d d ¡f}|  | j |d |d
 ¡|¡ dS | j dd¡}|r	| j |d dd¡r	|  | j |d
 d¡|¡ dS |  | j dd¡|¡ dS | j ddd¡r&| j 
dd¡ | j dd¡}|r<| ¡ s<| j dd¡ | j ddd¡rL|  |¡ dS | j 
dd¡ | jre| j dd¡ | j d¡ n|  |¡ | j ¡  | jrz| j ¡  dS |  ¡  dS )Nr«  rˆ  z<=r˜   rU   re   rž   úiomark linestartr¨   r   rÜ   z>=r   z+1czinsert lineendrj   rð   zend-1c linestartrr   )rö   r¤  rD   r  r    ÚrecallZtag_prevrangeZ	tag_namesZtag_nextranger^   rø   Ústripr¥   r­  re   r¬  Zupdate_idletasksr’   r¦  Úrunit)	r?   ri   ÚselÚprevZ	prev_consZ	next_consÚnextÚindicesrÏ   r)   r)   r*   rh  ç  sx   €ÿþÿÿ



ÿzPyShell.enter_callbackc              	   C   sl  t  dd|¡}t  dd|¡}| d¡}| j ¡  z‘| j ddd¡ | j dd	¡ | j d
d¡}| ¡  	d¡rB|  
|¡ | j d
d¡}| j d|d  ¡ | j¡ t|ƒdkrŽt  d|d ¡ d¡}t  d|¡ d¡}|dd … D ],}| |¡r€||t|ƒd …  }| j dd| ¡  | j¡ qoW | j d¡ | j ¡  d S W | j d¡ | j ¡  d S | j d¡ | j ¡  w )Nz^\s*\nrV   z\n\s*$rr   r²  rm   r‰   re   rð   rj   ú:r   r   z	^([ \t]*))ÚreÚsubr:  rD   Zundo_block_startrl   rø   r  ÚrstripÚendswithr­  re   r°  Úuser_input_insert_tagsrƒ   ÚsearchÚgrouprw   r¬  Zundo_block_stop)r?   rÏ   ri   r~   ÚprefixZorig_base_indentZnew_base_indentr    r)   r)   r*   r¯  6  s>   


ÿ
ÿù
øÿzPyShell.recallz[ \t]*(\n[ \t]*)?\Zc                 C   sj   | j  d¡}| j  dd¡}| j d|¡}| j |¡}|s3| j  |¡dkr,| j  | j|¡ | j	 
¡  d S d S )Núend-2cr˜   rð   rV   rr   )rD   r^   r  Ú_last_newline_rer¸  rb   r8  rl   r»  rd  Úupdate_sidebar)r?   Zindex_beforer    Zinput_is_completer)   r)   r*   r±  S  s   ýzPyShell.runitc                 C   sZ   | j jr	| j  ¡ S ztj W n   tjdd| jd Y d S ddlm	} || j
| jƒ d S )NzNo stack tracez@There is no stack trace yet.
(sys.last_traceback is not defined)r   r   )ÚStackBrowser)rb   rä   r  r¾   Úlast_tracebackr   r|   rD   Zidlelib.stackviewerrÂ  r{   rH   )r?   ri   rÂ  r)   r)   r*   rE  _  s   

ýzPyShell.open_stack_viewerc                 C   s   | j  d¡ | j  d¡ d S )Nr˜   rñ   )rD   r¬  r–   r)   r)   r*   ro  m  s   zPyShell.view_restart_markc                 C   s   | j jdd dS )z&Callback for Run/Restart Shell Cntl-F6Trß   N)rb   rü   r–   r)   r)   r*   rp  q  s   zPyShell.restart_shellc                 C   s|   |   ¡  | j}| jr| | j¡r|d t| jƒ … }| j dd¡ | j |¡ | j	 
¡  | j dd¡ |  ¡  | j ¡  d S )NrÜ   z	iomark-1cre   rð   )r  rg  rf  rº  rƒ   rD   r]   rÜ   r"   rd  rÁ  rø   Úset_line_and_columnrN   Z
reset_undo)r?   rg  r)   r)   r*   rú   u  s   
zPyShell.showpromptc                 C   sP   | j jj}t|ddd}d | |¡¡}| d¡s|d7 }| jj 	d|d¡ d S )Né   T)r¸   ÚtabsizeZexpand_tabsrr   r®  rÞ   )
rb   r½   r¸   r   rL   r\  rº  rz  Zbottomre   )r?   r=  r¸   ÚwrapperZwrapped_msgr)   r)   r*   Úshow_warningƒ  s   

zPyShell.show_warningc                 C   sb   | j  dd¡}| jr| j |¡ | j  d¡dkr| j  dd¡ | j  dd¡ |  ¡  | j ¡  d S )Nr˜   rð   r¿  rr   )	rD   r  ry  Ústorere   rø   rÄ  ZctipZremove_calltip_window)r?   r,  r)   r)   r*   r  ‹  s   zPyShell.resetoutputr)   c                 C   sR   z| j  dd¡ t | ||d¡}| j  dd¡ W n   ‚ | jr'd| _ts't‚|S )Nr˜   Úrightrò   F)rD   rù   r   r"   rN  r0  r  )r?   rÏ   r¤   Úcountr)   r)   r*   r"   •  s   zPyShell.writec                    s:   z| j  ddd¡rW dS W n
 ty   Y dS w tƒ  ¡ S )Nr«  rž   r˜   r”  )rD   r    r¡   r¬   rQ   r‹   r®   r)   r*   rQ   £  s   ÿÿ
zPyShell.rmenu_check_cutc                    s   | j  ddd¡r
dS tƒ  ¡ S )Nre   rž   r˜   r”  )rD   r    r¬   rT   r‹   r®   r)   r*   rT   «  s   
zPyShell.rmenu_check_pastec                 C   s   | j  ¡  | j ¡  d S r=   )rq  Zsqueeze_current_textrd  rÁ  r–   r)   r)   r*   rr  °  s   
z"PyShell.squeeze_current_text_eventc                 C   s   | j  ¡  d S r=   )rd  rÁ  )r?   r^   rD   r¤   r)   r)   r*   Úon_squeezed_expand´  s   zPyShell.on_squeezed_expandr=   )r)   )OrŒ   r   rŽ   Zidlelib.squeezerrQ  r   rœ  r—   r   rœ   r   ra  r   r   rƒ   r4   Ú	itertoolsÚ	takewhileZ_idxre   Zallow_line_numbersr»  Zidlelib.historyrV  Zidlelib.sidebarrW  rC   r|  r}  r  r€  r‡  rn  r¤  rö   rN  r¨  r  r¥  rŒ  r  rl  r  rm  r  r‘  r–  rK  r  rô   rŠ   r›  r  r¡  r•   r÷   r©  rª  rj  rk  ri  rh  r¯  r·  rÅ   rÀ  r±  rE  ro  rp  rú   rÈ  r  r"   rQ   rT   rr  rÌ  r°   r)   r)   r®   r*   r”   U  sŠ    

ÿ

ÿ
N


ÿ
	O






r”   c              
   C   s6   | j dkrdD ]}|  |dd|  |d¡ ¡ qdS dS )z6Make paste replace selection on x11.  See issue #5124.Zx11)ZTextZEntryZSpinboxz	<<Paste>>z%catch {%W delete sel.first sel.last}
N)Z_windowingsystemZ
bind_class)r{   Úclsr)   r)   r*   Úfix_x11_paste¸  s   

ÿýþrÐ  a¢  
USAGE: idle  [-deins] [-t title] [file]*
       idle  [-dns] [-t title] (-c cmd | -r file) [arg]*
       idle  [-dns] [-t title] - [arg]*

  -h         print this help message and exit
  -n         run IDLE without a subprocess (DEPRECATED,
             see Help/IDLE Help for details)

The following options will override the IDLE 'settings' configuration:

  -e         open an edit window
  -i         open a shell window

The following options imply -i and will open a shell:

  -c cmd     run the command in a shell, or
  -r file    run script from file

  -d         enable the debugger
  -s         run $IDLESTARTUP or $PYTHONSTARTUP before anything else
  -t title   set title of shell window

A default edit window will be bypassed when -c, -r, or - are used.

[arg]* are passed to the command (-c) or script (-r) in sys.argv[1:].

Examples:

idle
        Open an edit window or shell depending on IDLE's configuration.

idle foo.py foobar.py
        Edit the files, also open a shell if configured to start with shell.

idle -est "Baz" foo.py
        Run $IDLESTARTUP or $PYTHONSTARTUP, edit foo.py, and open a shell
        window with the title "Baz".

idle -c "import sys; print(sys.argv)" "foo"
        Open a shell window and run the command, passing "-c" in sys.argv[0]
        and "foo" in sys.argv[1].

idle -d -s -r foo.py "Hello World"
        Open a shell window, run a startup script, enable the debugger, and
        run foo.py, passing "foo.py" in sys.argv[0] and "Hello World" in
        sys.argv[1].

echo "import sys; print(sys.argv)" | idle - "foobar"
        Open a shell window, run the script piped in, passing '' in sys.argv[0]
        and "foobar" in sys.argv[1].
c               
      sJ  dd l } ddlm} ddlm} ddlm} tdƒ dad}d}d}d }d }d}	z|   tj	dd … d¡\}
}W n# | j
yZ } ztd	|tf tjd
 t d¡ W Y d }~nd }~ww |
D ]d\}}|dkri|}d}|dkrqd}d}|dkrwd}|dkr…tj t¡ t ¡  |dkr‹d}|dkr˜tdtjd
 da|dkr°|}tj |¡r¥n	td|ƒ t ¡  d}|dkr¸d}	d}|dkrÁ|t_d}q]|rÑ|d dkrÑtj ¡ }d}tttjƒƒD ]}tj tj| ¡tj|< qØ|rú|d dkrúdg|dd …  t_	nU|rdg| t_	nK|r|g| t_	nA|r>d}g }|D ]}| tj |¡¡ q|D ]}tj |¡}|tjvr;tj d|¡ q&nt ¡ }|tjvrOtj d|¡ tj ddddd}|p\|}|pb| }trl|slt!ƒ  t"dda#t# $¡  dd l%m&} |t#ƒ tj 'tj t(¡d!¡‰|ƒ d"kržtj 'ˆd#¡}t#j)|d$ n-| *¡ sËt+d%kr­d&‰ d'}nd(‰ d)}‡ ‡fd*d+„|D ƒ}d,d+„ |D ƒ}t#j,dg|¢R Ž  t-t#ƒ t.t#ƒ t/t#ƒa0| 1t#t0¡ |r|s|s|d d … D ]}t0 2|¡d u rû| 3|¡ qì|st0 4¡  |rt0 5¡ }|sd S | *¡ rt0j6r|j7 8¡  nt0j9}|r)| :¡  |	rItj; <d-¡p8tj; <d.¡}|rItj |¡rI|j= >|¡ |sO|rs|j= ?d/tj	f ¡ |rc|j= @|¡ n,|rr|j= A|¡ |j= >|¡ n|r| Bt#¡}|rƒ| C|¡ | D¡ }|r| C|¡ t0jEr›t# F¡  t0jEs“t# G¡  tdƒ d S )0Nr   )Úsystem)Útesting)ÚmacosxTFr   zc:deihnr:st:zError: %s
%sr   r†   rÖ   z-dz-ez-hz-iz-nz: Warning: running IDLE without a subprocess is deprecated.z-rzNo script file: z-sz-tú-rV   rÑ   rÒ   zeditor-on-startuprÓ   )rÕ   ZIdle)Z	classNamer	   ZIconsZWindowszidle.ico)rÔ   g333333!@z.png)é   é    é0   é   z.gif)rÕ  rÖ  r×  c                    s"   g | ]}t j ˆd |ˆ f ¡‘qS )z	idle_%d%s)rJ   rK   rL   )rÎ   Úsize©ÚextZicondirr)   r*   rÐ   b  s    ÿzmain.<locals>.<listcomp>c                 S   s   g | ]}t t|d ‘qS ))Zmasterr   )Z
PhotoImager{   )rÎ   Úiconfiler)   r)   r*   rÐ   d  s    ÿZIDLESTARTUPZPYTHONSTARTUPzbif 1:
            import sys as _sys
            _sys.argv = %r
            del _sys
            
)HÚgetoptr   rÑ  r%  rÒ  rÓ  r/   r0  r¾   ÚargvÚerrorr  Ú	usage_msgrÞ   ÚexitrÝ   r"   rJ   rK   r   r”   rœ  r¨   r/  r‡   rƒ   r1  r`   Údirnamere   Úgetcwdr   rØ   ZNoDefaultRootrb  r{   rc  Úidlelib.runr
   rL   Ú__file__Zwm_iconbitmapZisAquaTkÚ	TkVersionZwm_iconphotor   rÐ  r‘   rH   ZsetupAppru   rk   ÚnewrI   Údictr’   Úlowerra   r‘  Úenvironr  rb   r*  r	  r-  r<  ZtkVersionWarningrÈ  ZpreferTabsPreferenceWarningZinversedictr§  Zdestroy)rÝ  rÑ  rÒ  rÓ  Zenable_shellZenable_editrc   ÚcmdZscriptZstartupZoptsrP   r=  ÚoÚarî   Zpathxr'   ÚdirZ
edit_startr
   rÜ  ZsizesZ	iconfilesZiconsrX  ZtkversionwarningZprefer_tabs_preference_warningr)   rÚ  r*   rÑ   ù  s6  €þÿ
€
€ýÿ



ÿÿ
€
€
ÿü€


ÿrÑ   )NN)Xr¾   rŒ   r¿   r¢  ÚImportErrorr  r  rM  r   ZctypesZPROCESS_SYSTEM_DPI_AWAREZOleDLLZSetProcessDpiAwarenessr#   r$   r   ræ  rb  r{   rc  rä  r
   r|   r6  r   rÍ  r2   rJ   Úos.pathr   r·  rç   rÊ   Útextwrapr   r   râ   r.  r-   Zidlelib.colorizerr   Zidlelib.configr   Zidlelib.delegatorr   r%  r   r   Zidlelib.editorr   r   Zidlelib.filelistr   Zidlelib.outwinr   r   r   r   r   r   Zidlelib.undor   r0  rá   rÃ   Úeofrá  r¦  Ú	NameErrorr!   r+   r,   r/   Ú
checkcacher9   r:   r‘   r—   rœ   r±   Z	RPCClientr²   rº   r»   r”   rÐ  rà  rÑ   r)   r)   r)   r*   Ú<module>   sÈ   ÿý
ÿþ
ÿ
ÿ
ÿ ?"   0    g6 
6