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   sP   	 |d u rt }z|t| ||||d |d W d S  ttfy'   Y d S w )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 N)_warnings_showwarningwarningsshowwarningr+   )capturer)   r)   r*   capture_warningse   s   
r1   Tc                 C   sZ   	 t j}i }t|D ]}|d d |dd   dkr!||||< q
||  || d S Nr   z<>)	linecachecachelistpopupdate)r'   Zorig_checkcacher5   savekeyr)   r)   r*   extended_linecache_checkcachet   s   	r;   c                   @   st   e 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 )PyShellEditorWindowc                 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 r,   )restore_file_breaks)Zold_hookselfr)   r)   r*   filename_changed_hook   s   
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*   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   sF   	 | j d u rd S |rt }t|d}nddd}| jd| d S )N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   s\  	 | 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 sH|| q:| 	  | j }|rh||d t
| d  W d    W d S W d    W d S 1 stw   Y  W d S  ty } z&t| jddsd| j_tjdd	t
| | jd
 W Y d }~d S W Y d }~d S d }~ww )Nr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   sH   

&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   r8   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 )NrY   )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 r,   )rn   r   _closer@   r)   r)   r*   r   C  s   zPyShellEditorWindow._close)Tr,   )__name__
__module____qualname__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	 eZdZdddZdS )PyShellFileListNc                 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   ra   rI   r)   r)   r)   r*   r   I  s
    r   c                   @   s   e Zd Z	 dd Zdd ZdS )ModifiedColorDelegatorc                 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   ]  s    r   c                       s2   e Zd Z	 dddZdddZ fddZ  ZS )	ModifiedUndoDelegatorNc                 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   re   r   r   __classcell__r)   r)   r   r*   r   j  s
    

		r   c                   @   s   e Zd Z	 dddZdS )UserInputTaggingDelegatorNc                 C   s    |d u rd}| j ||| d S r   )r   re   r   r)   r)   r*   re     s   z UserInputTaggingDelegator.insertr,   )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 r,   )EOFErrorr   r)   r)   r*   
handle_EOF     zMyRPCClient.handle_EOFN)r   r   r   r   r)   r)   r)   r*   r     s    r   c                 C   s\   	 d|pd d}| t |kr(t| t | d\}}|| d  | |d  S |d d S )Nz= RESTART: ZShellz =r   rq   )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   sJ   dd t jD }tjdddddd}d	|f }t jg| d
|t| jg S )Nc                 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   warnoptionsr   	GetOption
executablery   r   )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   r4   rb   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   rH   r4   transfer_pathpoll_subprocess)r@   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{|  |rt| 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)	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   rD   Zafter_cancelr   r   r   r#   r   r   r   r)   r)   r*   kill_subprocess%  s   

z#ModifiedInterpreter.kill_subprocessc                 C   sL   	 z| j   W n
 ty   Y d S w z| j   W d S  ty%   Y d S w r,   )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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 )Ni,  )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[   frame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 r,   )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yZ   | j
  td| j
jd t| | | j
  Y d S w | | d S )Nz__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'   r5  r}   coder)   r)   r*   r3    s.   
zModifiedInterpreter.execfilec                 C   s   	 |  |}t| ||S r,   )r2  r   	runsourcer4  r)   r)   r*   r@    s   
zModifiedInterpreter.runsourcec                 C   s@   	 d| j  }| j d | _ |d}t|d d||ftj|< |S )Nz<pyshell#%d>r   rr   r   )gidsplitr   r4   r5   )r@   r5  r'   r~   r)   r)   r*   r2    s   

zModifiedInterpreter.stuffsourcec                 C   s   	 |  d|f  d S )Na(  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
            
)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r7|d7 }|dkrBd|	d  }
n
d|d |	d f }
|||
 |  | d|  |	  d S )Nr  rm   r   msgrV   z<no detail available>r(   r   offsetr   ziomark + %d charsz&iomark linestart + %d lines + %d charszSyntaxError: %s
)
r   rD   rl   r   exc_inforz   Zcolorize_syntax_errorr  r"   r   )r@   r'   r   rD   r   valuetbrE  r(   rF  posr)   r)   r*   r=    s&   z#ModifiedInterpreter.showsyntaxerrorc                 C   s<   	 | j   |   t|  | j dr| j   d S d S )Nr  )r   r  checklinecacher   showtracebackr  open_stack_viewerr   r)   r)   r*   rL    s   

z!ModifiedInterpreter.showtracebackc                 C   s>   t j}t| D ]}|d d |dd   dkr||= q	d S r2   )r4   r5   r6   keys)r@   cr:   r)   r)   r*   rK    s   z"ModifiedInterpreter.checklinecachec                 C   sD   	 | j jr|   dS | jr| jdd|fi  dS t|| j dS )Nr   r  r>  r   )r   r   display_executing_dialogr   r.  r  r   )r@   r?  r)   r)   r*   r    s   zModifiedInterpreter.runcommandc                 C   sf  	 | j jr	|   |   | j}zz*| j   |s*| jd ur*| jdd|fi | _n|r4|	|| j
 nt|| j
 W nK tyZ   | j jsWtjddd| j jdrR |   n Y n-   trqtd| j jd |   | j   n| j jrd	| j _td
| j jd n|   Y W tsz| j   W d S  ty   Y d S w d S tsz| j   W w  ty   Y w w w )Nr  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  rK  r   beginexecutingr   Z
asyncqueuer  runr   r  
SystemExitr  r   ZaskyesnorD   rL  r9  r  r   r  canceledr#   )r@   r?  r   r)   r)   r*   r>    sh   


zModifiedInterpreter.runcodec                 C   s   	 | j j|S r,   )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   rV  )NzSubprocess Connection ErrorzIDLE'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   rW  r   r)   r)   r*   r   E  s
   
z/ModifiedInterpreter.display_no_subprocess_errorc                 C   rV  )NzAlready executingzYThe Python Shell window is already executing a command; please wait until it is finished.r   rW  r   r)   r)   r*   rP  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  rA  r6  r3  r@  r2  rD  r=  rL  rK  r  r>  r"   r   r   rP  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)r_  ZShe_llF   ps1z>>>
rr   r3   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   )>r9  
menu_specsre   r   rb   Tkr   withdrawr   shell_sidebarr   rC   ZusetabsZindentwidthhasattrr   ra  sys_ps1rB  Zprompt_last_linepromptrD   Z	configurerE   enter_callbacklinefeed_callbackcancel_callbackeof_callbackrM  toggle_debuggertoggle_jit_stack_viewercopy_with_prompts_callbackview_restart_markrestart_shellrX  squeezersqueeze_current_text_eventr   save_stdoutr   save_stderrr   
save_stdinr-  re  r   encodingerrorsr   r   pydocZ
plainpagerZpagerr  r]  historyr  r^  perr   Zinsertfilterr   )r@   rH   msr{   rD   re  r  r)   r)   r*   rC   {  s   
zPyShell.__init__c                    s&   t    | jd ur| j  d S d S r,   )r   	ResetFontrk  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_configurerk  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 )Nc                    s   g | ]	} j j|qS r)   )rk  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   rn  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 )Nzsel.first linestartsel.lastr3   0zsel.last+1line linestart)rD   r^   Zclipboard_clearr  Zclipboard_append)r@   ri   rD   ZselfirstZsellastZprompt_textr)   r)   r*   ru    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*   rs    s   
zPyShell.toggle_debuggerc                 C   s   | j  }| d|   d S )Nrd  )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*   rt  +  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"   rm  rn  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   rm  rn  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 NT)r  r   r   r)   r)   r*   rR  K  s   
zPyShell.beginexecutingc                 C   s   	 d| _ d| _|   d S r
  )r   rU  r   r   r)   r)   r*   r  P  s   zPyShell.endexecutingc                 C   sF   	 | j rtjddd| jd}|du rdS |   d| _d| _t| S )NzKill?z7Your program is still running!
 Do you want to kill it?okrQ  FcancelT)	r   r   ZaskokcancelrD   r   rU  r  r   r   )r@   r  r)   r)   r*   r   V  s   
zPyShell.closec                 C   sX   	 |    tr| j  | jt_| jt_| j	t_
d | _d | _d | j_d | _t|  d S r,   )r  r9  rb   r  rz  r   r   r{  r   r|  r   r   rH   ra   r  r   r   r   r)   r)   r*   r   e  s   
zPyShell._closec                 C   s   	 dS r  r)   rC  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  r9  rb   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 r  )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  rU  r9  r  	endoffile)r@   r9   r    r)   r)   r*   readline  s(   zPyShell.readlinec                 C   s   dS 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  rU  r   r   r  r	  r   r  r   r)   r)   r*   rq    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   rU  r  r   r  r   r)   r)   r*   rr    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*   rp    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
 rd| 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*   ro    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rt 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subrB  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   r@  rl   r  rk  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*   rM  _  s   

zPyShell.open_stack_viewerc                 C   s   | j d | j d d S )Nr   r   )rD   r  r   r)   r)   r*   rv  m  s   zPyShell.view_restart_markc                 C   s   	 | j jdd d S )NTr   )rb   r  r   r)   r)   r*   rw  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  rn  rm  r  r   rD   r]   r   r"   rk  r  r   set_line_and_columnrN   Z
reset_undo)r@   rn  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   rc  r  r  Zbottomre   )r@   rE  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  r  storere   r   r  ZctipZremove_calltip_window)r@   r5  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"   rU  r9  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,   )rx  Zsqueeze_current_textrk  r  r   r)   r)   r*   ry    s   
z"PyShell.squeeze_current_text_eventc                 C   s   | j   d S r,   )rk  r  )r@   r^   rD   r   r)   r)   r*   on_squeezed_expand  s   zPyShell.on_squeezed_expandr,   )r)   )Or   r   r   Zidlelib.squeezerrX  r   r  r   r   r   r   rh  r   r   r   r6   	itertools	takewhileZ_idxre   Zallow_line_numbersr  Zidlelib.historyr]  Zidlelib.sidebarr^  rC   r  r  r  r  r  ru  r  r   rU  r  r  r  r  r  rs  r  rt  r  r  r  rR  r  r   r   r  r  r  r   r   r  r  rq  rr  rp  ro  r  r  r   r  r  rM  rv  rw  r   r  r  r"   rQ   rT   ry  r  r   r)   r)   r   r*   r   U  s    




N



	O






r   c              
   C   s8   	 | j dkrdD ]}| |dd| |d  qd S d S )NZx11)ZTextZEntryZSpinboxz	<<Paste>>z%catch {%W delete sel.first sel.last}
)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rtjt t  |dkrd}|dkrtdtjd
 da|dkr|}tj|rn	td| t  d}|dkrd}	d}|dkr|t_d}q]|r|d dkrtj }d}tttjD ]}tjtj| tj|< q|r|d dkrd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rtj'd#}t#j)|d$ n-|* st+d%krd& 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 ]}t02|d u r|3| q|st04  |rt05 }|sd S |* rt0j6r|j78  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rt#F  t0jEst#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  r1   r9  r   argverrorr  	usage_msgr   exitr   r"   rJ   rK   r   r   r  r   r8  r   r   r:  r`   dirnamere   getcwdr   r   ZNoDefaultRootri  r{   rj  idlelib.runr
   rL   __file__Zwm_iconbitmapZisAquaTk	TkVersionZwm_iconphotor   r  r   rH   ZsetupAppru   rk   newrI   dictr   lowerra   r  environr  rb   r3  r  r6  rD  ZtkVersionWarningr  ZpreferTabsPreferenceWarningZinversedictr  Zdestroy)r  r  r  r  Zenable_shellZenable_editrc   cmdZscriptZstartupZoptsrP   rE  oar   Zpathxr'   dirZ
edit_startr
   r  ZsizesZ	iconfilesZiconsr_  ZtkversionwarningZprefer_tabs_preference_warningr)   r  r*   r     s6  











r   )NN)Xr   r   r   r  ImportErrorr  r  rT  r  ZctypesZPROCESS_SYSTEM_DPI_AWAREZOleDLLZSetProcessDpiAwarenessr#   r$   r   r  ri  r{   rj  r  r
   r|   r?  r   r  r4   rJ   Zos.pathr   r  r   r   textwrapr   r  r   r7  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   r9  r   r   eofr  r  	NameErrorr!   r+   r-   r1   
checkcacher;   r<   r   r   r   r   Z	RPCClientr   r   r   r   r  r  r   r)   r)   r)   r*   <module>   s   



 ?"   0    g6 
6