o
     JAfûõ  ã                
   @   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)   ú&/usr/lib/python3.10/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+   )Úcapturer)   r)   r*   Úcapture_warningse   s   
þþr0   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_checkcacher4   ÚsaveÚkeyr)   r)   r*   Úextended_linecache_checkcachet   s   €r:   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@   ÚargsrA   r)   r)   r*   rD   Ž   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)rO   r   ÚCurrentThemeÚGetHighlightrE   Z
tag_config)r@   ZcolorÚthemeZcfgr)   r)   r*   rP   «   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 )NrZ   z%d.0r   )rE   rO   r'   Útag_addrC   ÚindexÚ
ValueErrorÚappendrI   ÚpyshellÚinterpr   rG   )r@   r(   rE   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)rE   rO   r'   ÚbellÚintÚfloatr_   re   )r@   ÚeventrE   r'   r(   r)   r)   r*   rG   Å   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 )Nrf   rZ   úinsert linestartzinsert lineend +1char)rE   rO   r'   rg   rh   ri   r_   rC   ÚremoveÚ
tag_removerI   rb   rc   r   rH   )r@   rj   rE   r'   r(   rd   r)   r)   r*   rH   Î   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 )NrZ   ú1.0)rC   rE   rO   r'   rg   rm   ZENDrI   rb   rc   r   Úclear_file_breaks)r@   rE   r'   rd   r)   r)   r*   ro   á   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   )rC   rO   r'   ÚopenrN   Ú	readlinesr$   Ú
startswithr"   Úupdate_breakpointsÚstrÚgetattrÚrootrt   r   Ú	showerrorrE   )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 )Nrp   rr   r   )rE   r7   rO   r'   rK   rL   ÚisfilerN   rv   rw   rx   ÚevalÚlenre   )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 windowrZ   N)rE   Z
tag_rangesÚranges_to_linenumbersrC   )r@   rE   ÚrangesZlinenumber_listr)   r)   r*   ry   +  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„   rh   ri   Ústringra   )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)ro   r   Ú_close©r@   r)   r)   r*   r‹   C  s   zPyShellEditorWindow._close)Tr>   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rD   Úrmenu_specsrP   re   rG   rH   ro   r   r?   ry   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>   )rb   ÚtopÚwakeupÚPyShellÚbegin©r@   rj   r)   r)   r*   rJ   R  s   
ü
zPyShellFileList.open_shellr>   )r   rŽ   r   r   r;   r   rb   rJ   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TODOrn   ÚiomarkZSYNC)rm   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tagdefsrm   )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Úcomparerg   ÚTclErrorr   rf   ©r@   r_   ÚcharsÚtagsr)   r)   r*   rf   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¡   rg   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    rf   ÚsuperÚ
undo_eventr—   ©Ú	__class__rª   r*   r®   ~  s   
ÿz ModifiedUndoDelegator.undo_eventr>   )r   rŽ   r   r   rf   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    rf   r£   r)   r)   r*   rf   Ž  s   z UserInputTaggingDelegator.insertr>   )r   rŽ   r   r   rf   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‡   rr   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   rD   Ú
restartingÚsubprocess_arglistÚPORTÚportÚcompileÚcompilerÚflagsÚoriginal_compiler_flags)r@   r¾   r½   r)   r)   r*   rD   ª  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Ú
executablerz   )r@   rq   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ÚstderrrI   r3   rc   T©Úwith_cwd)ÚHOSTrÅ   rˆ   ÚtimeÚsleepr³   Úrpccltr$   Údisplay_port_binding_errorÚlistening_sockÚgetsocknamerÄ   Ú
setsockoptÚsocketÚ
SOL_SOCKETÚSO_REUSEADDRrÎ   Ú
settimeoutÚacceptÚTimeoutErrorÚdisplay_no_subprocess_errorÚregisterr¾   r©   rÞ   rß   rI   r3   Útransfer_pathÚpoll_subprocess)r@   ÚaddrÚir)   r)   r*   Ústart_subprocessÈ  sD   


ÿÿþz$ModifiedInterpreter.start_subprocessFrW   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-1crs   ÚrestartÚleft)rÂ   rå   Úgetdebuggerr   Zclose_subprocess_debuggerÚcloseÚterminate_subprocessr¾   Ú	executingrÎ   rî   rï   rð   rò   Ústop_readlinerE   r¦   r"   r»   r¹   Úmark_setÚmark_gravityÚ
showpromptZrestart_subprocess_debuggerÚload_breakpointsrÉ   rÆ   rÇ   rÈ   )r@   rá   r'   rd   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)Ú	threadingÚ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¾   rE   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 )NrW   zRif 1:
        import sys as _sys
        _sys.path = %r
        del _sys
        
)Úextendr¿   rL   Ú
runcommand)r@   rá   rL   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#   rE   ÚafterÚpollintervalró   r  )r@   ZcltÚresponseÚ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¾   rE   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)rI   )ÚScrolledCanvasÚTreeNodeÚnormalrY   )ÚbgZhighlightthicknessr   Zboth)ÚexpandÚfill)Úidlelibr'  rå   Úremotequeuer¾   r|   rg   ZStubObjectTreeItemZidlelib.treer(  r)  ZToplevelr   r[   r\   ÚframeÚpackZcanvasr,  )r@   r'  ZoidÚitemr(  r)  r“   r]   rY   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   )Útokenizerv   ÚreadÚuse_subprocessrK   rL   ÚabspathrÆ   ÚOverflowErrorÚSyntaxErrorr¾   r  r  rß   r   Úshowsyntaxerrorr  Úruncode)r@   r'   r6  r~   Úcoder)   r)   r*   r4  £  s,   ÿÿ€ý
þúzModifiedInterpreter.execfilec                 C   s&   |   |¡}t|tƒsJ ‚t | ||¡S )zBExtend base class method: Stuff the source in the line cache first)r3  Ú
isinstancerz   r   Ú	runsourcer5  r)   r)   r*   rB  ·  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   rs   r   )ÚgidÚsplitr„   r3   r4   )r@   r6  r'   r   r)   r)   r*   r3  À  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  rn   rŠ   ÚmsgrW   z<no detail available>r(   r   Úoffsetr   ziomark + %d charsz&iomark linestart + %d lines + %d charszSyntaxError: %s
N)
r¾   rE   rm   r¿   Úexc_infor{   Zcolorize_syntax_errorr  r"   r  )r@   r'   r¾   rE   rÖ   ÚvalueÚtbrG  r(   rH  Úposr)   r)   r*   r>  Ô  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*   rN  î  s   

ÿz!ModifiedInterpreter.showtracebackc                 C   s>   t j}t| ¡ ƒD ]}|d d… |dd …  dkr||= q	d S )Nr   r1   r2   )r3   r4   r5   Úkeys)r@   Úcr9   r)   r)   r*   rM  ö  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  r?  r   )r¾   rý   Údisplay_executing_dialogrå   r/  r  r½   )r@   r@  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  r?  zExit?zDo you want to exit altogether?Zyes©rÕ   r   z IDLE internal error in runcode()r   Fr  )r¾   rý   r  rM  r   Úbeginexecutingrå   Z
asyncqueuer  Úrunr½   r  Ú
SystemExitr  r   ZaskyesnorE   rN  r:  r  rß   r  Úcanceledr#   )r@   r@  r   r)   r)   r*   r?    sf   

ÿ€ü
þÿ€ÿýÿýzModifiedInterpreter.runcodec                 C   s   | j j |¡S )rS  )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¾   rE   rŒ   r)   r)   r*   ræ   :  s
   
øz.ModifiedInterpreter.display_port_binding_errorc                 C   rY  )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   rZ  rŒ   r)   r)   r*   rð   E  s
   
ûz/ModifiedInterpreter.display_no_subprocess_errorc                 C   rY  )NzAlready executingzYThe Python Shell window is already executing a command; please wait until it is finished.r   rZ  rŒ   r)   r)   r*   rR  M  s
   
üz,ModifiedInterpreter.display_executing_dialog)FrW   )Fr>   )&r   rŽ   r   rD   r  rå   rÍ   rÎ   rÊ   rö   r  r	  r  r  rü   rò   r  ró   r   r#  rú   r&  r  rC  r7  r4  rB  r3  rF  r>  rN  rM  r  r?  r"   ræ   rð   rR  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)rd   Z_Debug)ÚoptionsZ_Options)ZwindowZ_Window)ÚhelpZ_Help)ZSqueezeú<<squeeze-current-text>>r   c                 C   s   | d dkS )Nr   rS   r)   )Z
rmenu_itemr)   r)   r*   r«   m  r¬   zPyShell.<lambda>)zCopy with promptsú<<copy-with-prompts>>rT   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)rb  ZShe_llFé   Úps1z>>>
rs   r1   Úchar)Úwrapz<<newline-and-indent>>z<<plain-newline-and-indent>>z<<interrupt-execution>>z<<end-of-file>>z<<open-stack-viewer>>ú<<toggle-debugger>>r  r_  z<<view-restart>>z<<restart-shell>>r^  )Úiomenur©   rÞ   rß   ÚbackslashreplacerÝ   é2   )>r:  Ú
menu_specsrf   r¼   rc   ÚTkr   Úwithdrawr’   Úshell_sidebarr   rD   ZusetabsZindentwidthÚhasattrr¿   rd  Úsys_ps1rD  Zprompt_last_lineÚpromptrE   Z	configurerF   Úenter_callbackÚlinefeed_callbackÚcancel_callbackÚeof_callbackrO  Útoggle_debuggerÚtoggle_jit_stack_viewerÚcopy_with_prompts_callbackÚview_restart_markÚrestart_shellr[  ÚsqueezerÚsqueeze_current_text_eventrÞ   Úsave_stdoutrß   Úsave_stderrr©   Ú
save_stdinr.  rh  r   ÚencodingÚerrorsr   rÝ   ÚpydocZ
plainpagerZpagerr  r`  Úhistoryr  ra  Úperr“   Zinsertfilterr²   )r@   rI   Úmsr|   rE   rh  r‚  r)   r)   r*   rD   {  s‚   
ÿÿÿÿÿzPyShell.__init__c                    s&   t ƒ  ¡  | jd ur| j ¡  d S d S r>   )r­   Ú	ResetFontrn  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)rY   rX   rÞ   rß   r*  )r©   rÞ   rß   rÝ   )
r­   ÚResetColorizerr   r[   r\   ÚitemsrE   Ztag_configurern  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_tagsrV   )r   rE   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)   )rn  Zline_promptsÚget)rÏ   r(   rŒ   r)   r*   rÑ   í  s    ÿÿz+PyShell.get_prompt_text.<locals>.<listcomp>rs   c                 s   s.    | ]\}}|d u r|n|› d|› V  qd S )Nú r)   )rÏ   rq  r    r)   r)   r*   Ú	<genexpr>ñ  s
   € ÿ
ÿz*PyShell.get_prompt_text.<locals>.<genexpr>)rE   r‹  rˆ   rh   ri   rM   ÚzipÚ
splitlines)r@   ÚfirstZlastrE   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.lastr1   Ú0zsel.last+1line linestart)rE   r_   Zclipboard_clearr‘  Zclipboard_append)r@   rj   rE   ZselfirstZsellastZprompt_textr)   r)   r*   rx  ÷  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   rV   )	rý   r   r}   rE   Úset_debugger_indicatorrc   rú   Úclose_debuggerÚopen_debugger)r@   rj   Údbr)   r)   r*   rv    s   þ
zPyShell.toggle_debuggerc                 C   s   | j  ¡ }|  d|  ¡ d S )Nrg  )rc   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*   rw  +  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]
)rc   rú   r#  rû   rå   r   Zclose_remote_debuggerr  rÝ   r"   rp  rq  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]
)rc   rå   r   Zstart_remote_debuggerr   ZDebuggerr#  r  rp  rq  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*  rd   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*   rU  K  rB   zPyShell.beginexecutingc                 C   s   d| _ d| _|  ¡  dS )r¡  FN)rý   rX  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?ÚokrT  FÚcancelT)	rý   r   ZaskokcancelrE   rþ   rX  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š  r:  rc   r  r}  r¿   rÞ   r~  rß   r  r©   rÝ   rI   rb   rƒ  r   r‹   rŒ   r)   r)   r*   r‹   e  s   
zPyShell._closec                 C   ó   dS )z8Override EditorWindow method: never remove the colorizerTr)   rE  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™   rf   rW   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)rE   rÿ   r  r:  rc   rö   rû   r   Údisplayhookr¿   r"   ÚversionÚplatformÚ	COPYRIGHTZfocus_forcer  ÚtkinterZ_support_default_rootZ_default_root)r@   ZnosubÚ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 )NTFrW   r™   r÷   r   rs   )r¯  r“   Úmainloopr°  rE   r‹  r„   r  rX  r:  r  Ú	endoffile)r@   r8   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
rV   FT)rE   r¡   rý   r¯  r  rc   r"   r  r³  rX  rå   rú   r  r  r“   r±  r—   r)   r)   r*   rt  ¹  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==rf   r÷   FTrV   )
rý   r¯  rE   r¡   r  rû   rX  r³  r“   r±  r—   r)   r)   r*   ru  Ï  s   ÿý
zPyShell.eof_callbackc                 C   s2   | j r| j dd¡ | j d¡ dS |  |¡ dS )Nrf   rs   rV   )r¯  rE   rf   ÚseeÚnewline_and_indent_eventr—   r)   r)   r*   rs  Þ  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™   rV   rf   rŸ   úiomark linestartr©   r   rÝ   z>=r   z+1czinsert lineendrk   r÷   zend-1c linestartrs   )rý   r¯  rE   r‹  r¡   ÚrecallZtag_prevrangeZ	tag_namesZtag_nextranger_   rÿ   Ústripr¦   r¸  rf   r·  Zupdate_idletasksr“   r±  Úrunit)	r@   rj   ÚselÚprevZ	prev_consZ	next_consÚnextÚindicesrÐ   r)   r)   r*   rr  ç  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*\nrW   z\n\s*$rs   r½  rn   rŠ   rf   r÷   rk   ú:r   r   z	^([ \t]*))ÚreÚsubrD  rE   Zundo_block_startrm   rÿ   r‹  ÚrstripÚendswithr¸  rf   r»  Úuser_input_insert_tagsr„   ÚsearchÚgrouprx   r·  Zundo_block_stop)r@   rÐ   rj   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÷   rW   rs   )rE   r_   r‹  Ú_last_newline_rerÃ  rc   rB  rm   rÆ  rn  Ú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)rc   rå   r  r¿   Úlast_tracebackr   r}   rE   Zidlelib.stackviewerrÍ  r|   rI   )r@   rj   rÍ  r)   r)   r*   rO  _  s   

ýzPyShell.open_stack_viewerc                 C   s   | j  d¡ | j  d¡ d S )Nr™   rø   )rE   r·  r—   r)   r)   r*   ry  m  s   zPyShell.view_restart_markc                 C   s   | j jdd dS )z&Callback for Run/Restart Shell Cntl-F6Trà   N)rc   r  r—   r)   r)   r*   rz  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-1crf   r÷   )r  rq  rp  rÅ  r„   rE   r^   rÝ   r"   rn  rÌ  rÿ   Úset_line_and_columnrO   Z
reset_undo)r@   rq  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_tabsrs   r¹  rß   )
rc   r¾   r¹   r   rM   rf  rÅ  r„  Zbottomrf   )r@   rG  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Ê  rs   )	rE   r‹  rƒ  Ústorerf   rÿ   rÏ  ZctipZremove_calltip_window)r@   r6  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)rE   r   r   r"   rX  r:  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ž  )rE   r¡   r¢   r­   rR   rŒ   r¯   r)   r*   rR   £  s   ÿÿ
zPyShell.rmenu_check_cutc                    s   | j  ddd¡r
dS tƒ  ¡ S )Nrf   rŸ   r™   rž  )rE   r¡   r­   rU   rŒ   r¯   r)   r*   rU   «  s   
zPyShell.rmenu_check_pastec                 C   s   | j  ¡  | j ¡  d S r>   )r{  Zsqueeze_current_textrn  rÌ  r—   r)   r)   r*   r|  °  s   
z"PyShell.squeeze_current_text_eventc                 C   s   | j  ¡  d S r>   )rn  rÌ  )r@   r_   rE   r¥   r)   r)   r*   Úon_squeezed_expand´  s   zPyShell.on_squeezed_expandr>   )r)   )Or   rŽ   r   Zidlelib.squeezerr[  r   r¦  r˜   r   r   r   rk  r   r‘   r„   r5   Ú	itertoolsÚ	takewhileZ_idxrf   Zallow_line_numbersrÆ  Zidlelib.historyr`  Zidlelib.sidebarra  rD   r†  r‡  r‰  rŠ  r‘  rx  r¯  rý   rX  r³  r  r°  r–  r—  rv  r™  rw  rš  r›  r   rU  r  rû   r‹   r¥  r§  r«  r–   rþ   r´  rµ  rt  ru  rs  rr  rº  rÂ  rÆ   rË  r¼  rO  ry  rz  r  rÓ  r  r"   rR   rU   r|  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ú-rW   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)rK   rL   rM   )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Þ  r0   r:  r¿   ÚargvÚerrorr  Ú	usage_msgrß   ÚexitrÞ   r"   rK   rL   r‚   r•   r¦  r©   r9  rˆ   r„   r;  ra   Údirnamerf   Úgetcwdr   rÙ   ZNoDefaultRootrl  r|   rm  Úidlelib.runr
   rM   Ú__file__Zwm_iconbitmapZisAquaTkÚ	TkVersionZwm_iconphotor   rÛ  r’   rI   ZsetupApprv   rl   ÚnewrJ   Údictr“   Úlowerrb   r›  Úenvironr‹  rc   r4  r  r7  rF  ZtkVersionWarningrÓ  ZpreferTabsPreferenceWarningZinversedictr²  Zdestroy)rè  rÜ  rÝ  rÞ  Zenable_shellZenable_editrd   ÚcmdZscriptZstartupZoptsrQ   rG  ÚoÚarõ   Zpathxr'   ÚdirZ
edit_startr
   rç  ZsizesZ	iconfilesZiconsrb  ZtkversionwarningZprefer_tabs_preference_warningr)   rå  r*   rÒ   ù  s6  €þÿ
€
€ýÿ



ÿÿ
€
€
ÿü€


ÿrÒ   )NN)Xr¿   r   rÀ   r¬  ÚImportErrorr  r  rW  rª  ZctypesZPROCESS_SYSTEM_DPI_AWAREZOleDLLZSetProcessDpiAwarenessr#   r$   r   rñ  rl  r|   rm  rï  r
   r}   r@  r   rØ  r3   rK   Zos.pathr   rÂ  rê   rË   Útextwrapr   r  rã   r8  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   r:  râ   rÄ   Úeofrì  r±  Ú	NameErrorr!   r+   r,   r0   Ú
checkcacher:   r;   r’   r˜   r   r²   Z	RPCClientr³   r»   r¼   r•   rÛ  rë  rÒ   r)   r)   r)   r*   Ú<module>   sÈ   ÿý
ÿþ
ÿ
ÿ
ÿ ?"   0    g6 
6