
    "eE                        d dl Z edk(  re j                  d   e j                  d<   	 d dl e j                  dk(  r(	 d dl	Z	dZ
 e	j                  d	      j                  e
       d d
lm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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l)m*Z*m+Z+ d dl,m-Z- d dl.m/Z/ d dl&m0Z0 d dl&m1Z1 d dl2m3Z3m4Z4m5Z5 d dl6m7Z7 da8dZ9d Z:	 dZ;e;e<_;        e;e=_;        e j                  a?	 d5dZ@daAd ZB eBd       dej                  fd ZDeDe_C         G d! d"e*      ZE G d# d$e-      ZF G d% d&e!      ZG G d' d(e7      ZH G d) d*e%      ZI G d+ d,e1j                        ZKd- ZL G d. d/e      ZM G d0 d1e/      ZNd2 ZOd3ZPd4 ZQedk(  r eQ         eBd       y# e$ r  ede j                          ed      w xY w# eeef$ r Y w xY w# e>$ r Y w xY w)6    N__main__zidlelib.pyshell)*zJ** IDLE can't import Tkinter.
Your Python may not be configured for Tk. **file   win32shcore)
messagebox)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           	          |t         }	 |j                  t        | ||||             |j                  d       y# t        t        f$ r Y yw xY 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   s         !lib/python3.12/idlelib/pyshell.pyidle_showwarningr)   I   sW     |

%8V$@ 	A

6G$ s   0; AAc                     | r't          t        j                  a t        t        _        yyt         t         t        _        da yy)z>Replace warning.showwarning with idle_showwarning, or reverse.N)_warnings_showwarningwarningsshowwarningr)   )captures    r(   capture_warningsr/   \   sA      ($,$8$8!#3H  ) !,#8H $(! -    Tc                     t         j                  }i }t        |      D ]%  }|dd |dd z   dk(  s|j                  |      ||<   '  ||        |j	                  |       y)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&   orig_checkcacher5   savekeys        r(   extended_linecache_checkcacher<   k   se     OOEDE{ 'r7SX%		#DI' H	LLr0   c                   `    e Zd ZdZd Zg dZddZd ZddZddZ	d	 Z
d
 Zd Zd Zd Zd Zy)PyShellEditorWindowz6Regular text edit window in IDLE, supports breakpointsc                 r   g | _         t        j                  | g|  | j                  j	                  d| j
                         | j                  j	                  d| j                         | j                  j	                  d| j                  j                         t        j                  j                  t        j                  d      | _        | j                  j                   | fd}| j                  j#                  |       | j                  j$                  r| j'                          | j)                          y )N<<set-breakpoint>><<clear-breakpoint>>z<<open-python-shell>>zbreakpoints.lstc                 2    |j                           |         y N)restore_file_breaks)old_hookselfs     r(   filename_changed_hookz;PyShellEditorWindow.__init__.<locals>.filename_changed_hook   s    $$&Jr0   )breakpointsr   __init__textbindset_breakpoint_eventclear_breakpoint_eventflist
open_shellospathjoinr   userdirbreakpointPathiofilename_change_hookset_filename_change_hookr&   rD   color_breakpoint_text)rF   argsrG   s      r(   rI   zPyShellEditorWindow.__init__   s    d*T*		+T-F-FG		-t/J/JK		.

0E0EF !ggll  "35 ,077+G+G'+	 	(()>?77$$&""$r0   ))Cutz<<cut>>rmenu_check_cut)Copyz<<copy>>rmenu_check_copy)Pastez	<<paste>>rmenu_check_paste)NNN)zSet Breakpointr@   N)zClear BreakpointrA   Nc                     | j                   y|r+t        j                         }t        j                  |d      }nddd}| j                  j                  d|       y)z,Turn colorizing of breakpoint text on or offNbreak )
foreground
backgroundBREAK)rU   r   CurrentThemeGetHighlightrJ   
tag_config)rF   colorthemecfgs       r(   rX   z)PyShellEditorWindow.color_breakpoint_text   sO    77?))+E''w7C!#26C		Wc*r0   c                    | j                   }| j                  j                  }|j                  dd|z  d|dz   z         	 | j                  j                  |       	 | j                  j                  j                  j                  }|j                  ||       y # t        $ r | j                  j                  |       Y dw xY w#  Y y xY w)Nre   z%d.0r   )rJ   rU   r&   tag_addrH   index
ValueErrorappendrN   pyshellinterpr   set_breakpoint)rF   r'   rJ   r&   debugs        r(   rs   z"PyShellEditorWindow.set_breakpoint   s    yy77##Wfvov/BC	,""6*	JJ&&--66E  62	  	,##F+	,
	s    B <C $C ?C CNc                     | j                   }| j                  j                  }|s|j                          y t	        t        |j                  d                  }| j                  |       y )Ninsert)rJ   rU   r&   bellintfloatrn   rs   )rF   eventrJ   r&   r'   s        r(   rL   z(PyShellEditorWindow.set_breakpoint_event   sO    yy77##IIKU4::h/01F#r0   c                    | j                   }| j                  j                  }|s|j                          y t	        t        |j                  d                  }	 | j                  j                  |       |j                  ddd       	 | j                  j                  j                  j                  }|j                  ||       y #  Y UxY w#  Y y xY w)Nrv   re   insert linestartzinsert lineend +1char)rJ   rU   r&   rw   rx   ry   rn   rH   remove
tag_removerN   rq   rr   r   clear_breakpoint)rF   rz   rJ   r&   r'   rt   s         r(   rM   z*PyShellEditorWindow.clear_breakpoint_event   s    yy77##IIKU4::h/01	##F+ 	!3/	1	JJ&&--66E""8V4		s   C 	<C C
Cc                 J   | j                   r| j                  }| j                  j                  }|s|j	                          y g | _         |j                  ddt               	 | j                  j                  j                  j                  }|j                  |       y y #  Y y xY w)Nre   1.0)rH   rJ   rU   r&   rw   r~   ENDrN   rq   rr   r   clear_file_breaks)rF   rJ   r&   rt   s       r(   r   z%PyShellEditorWindow.clear_file_breaks   s    99Dww''H		!DOOGUC0

**11::''1 s   !;B B"c                    | j                   }| j                  j                  }	 t        | j                        5 }|j                         }ddd       	 t        | j                  d      5 }D ](  }|j                  |dz         r|j                  |       * | j                          | j                   }|r#|j                  |dz   t        |      z   dz          ddd       y# 1 sw Y   xY w# t        $ r g }Y w xY w# 1 sw Y   yxY w# t        $ re}t        | j                  dd      sDd| j                  _        t        j                  dd	t        |      z  | j                   
       Y d}~yY d}~yd}~ww xY w)z#Save breakpoints when file is savedNw=
breakpoint_error_displayedFTz
IDLE Errorz$Unable to update breakpoint list:
%s)titler$   parent)rH   rU   r&   openrT   	readlinesr#   
startswithr!   update_breakpointsstrgetattrrootr   r
   	showerrorrJ   )rF   breaksr&   fplinesnew_filer   errs           r(   store_file_breaksz%PyShellEditorWindow.store_file_breaks   s`   $ !!77##	d))* 'b'	&d))3/ H8! -D??8c>: t,- '')))NN8c>CK#?$#FGH H' ' 	E	H H  	&499&BEJ7;		4$$<Cc(#99& & K	&sf   C- C!
C- D
 )C>AC>D
 !C*&C- -C;:C;>DD
 D
 
	E8AE33E8c                    | j                   j                          | j                  y | j                  j                  }|y t        j
                  j                  | j                        r}t        | j                        5 }|j                         }d d d        D ]I  }|j                  |dz         st        |t        |      dz   d        }|D ]  }| j                  |        K y y # 1 sw Y   YxY w)Nr   r   )rJ   r8   rU   r&   rP   rQ   isfilerT   r   r   r   evallenrs   )rF   r&   r   r   r   breakpoint_linenumbersbreakpoint_linenumbers          r(   rD   z'PyShellEditorWindow.restore_file_breaks  s    		77?77##77>>$--.d))* 'b' C??8c>2-1$s8}Q7G2H-I*1G C-++,ABCC /' 's   ?C((C1c                 n    | j                   }|j                  d      }| j                  |      }|| _        y)z3Retrieves all the breakpoints in the current windowre   N)rJ   
tag_rangesranges_to_linenumbersrH   )rF   rJ   rangeslinenumber_lists       r(   r   z&PyShellEditorWindow.update_breakpoints"  s1    yy)44V<*r0   c                    g }t        dt        |      d      D ]i  }t        t        ||   j                              }t        t        ||dz      j                              }||k  sN|j                  |       |dz  }||k  rk |S )Nr      r   )ranger   rx   ry   stringrp   )rF   r   r   rn   r'   ends         r(   r   z)PyShellEditorWindow.ranges_to_linenumbers)  s    1c&k1- 	Eve}3345FeF57O2234C3,V$! 3,	 r0   c                 N    | j                          t        j                  |        y)z7Extend base method - clear breaks when module is closedN)r   r   _closerF   s    r(   r   zPyShellEditorWindow._close:  s     D!r0   )TrC   )__name__
__module____qualname____doc__rI   rmenu_specsrX   rs   rL   rM   r   r   rD   r   r   r    r0   r(   r>   r>      sE    <%(K
+$&(&TC"+""r0   r>   c                        e Zd ZdZeZdZddZy)PyShellFileListz8Extend base class: IDLE supports a shell and breakpointsNc                     | j                   r0| j                   j                  j                          | j                   S t        |       | _         | j                   r| j                   j	                         sy | j                   S rC   )rq   topwakeupPyShellbeginrF   rz   s     r(   rO   zPyShellFileList.open_shellI  s\    <<LL##% ||	 #4=DL||||))+||r0   rC   )r   r   r   r   r>   r   rq   rO   r   r0   r(   r   r   @  s    > 'LGr0   r   c                       e Zd ZdZd Zd Zy)ModifiedColorDelegatorz8Extend base class: colorizer for the shell window itselfc                 z    | j                  ddd       | j                  ddd       t        j                  |        y )NTODOr   iomarkSYNC)r~   rm   r   recolorize_mainr   s    r(   r   z&ModifiedColorDelegator.recolorize_mainV  s0    x0VUH-&&t,r0   c                 L    | j                   D ]  }| j                  |dd        y )Nr   r   )tagdefsr~   )rF   tags     r(   removecolorsz#ModifiedColorDelegator.removecolors[  s%    << 	2COOC51	2r0   N)r   r   r   r   r   r   r   r0   r(   r   r   T  s    >-
2r0   r   c                   2     e Zd ZdZddZddZ fdZ xZS )ModifiedUndoDelegatorz;Extend base class: forbid insert/delete before the I/O markc                     	 | j                   j                  |dd      r| j                   j                          y 	 t	        j
                  | |||       y # t        $ r Y $w xY wN<r   )delegatecomparerw   TclErrorr   rv   rF   rn   charstagss       r(   rv   zModifiedUndoDelegator.insertc  s_    	}}$$UC:""$ ;
 	T5%6  		s   7A 	A A c                     	 | j                   j                  |dd      r| j                   j                          y 	 t	        j
                  | ||       y # t        $ r Y #w xY wr   )r   r   rw   r   r   delete)rF   index1index2s      r(   r   zModifiedUndoDelegator.deletel  s]    	}}$$VS(;""$ <
 	T662  		s   7A 	AAc                     | j                   j                  fd| j                   _        	 t        |   |       | j                   _        y # | j                   _        w xY w)Nc                      | |d      S Nstdinr   )rn   r   orig_inserts     r(   <lambda>z2ModifiedUndoDelegator.undo_event.<locals>.<lambda>|  s    UE7!C r0   )r   rv   super
undo_event)rF   rz   r   	__class__s     @r(   r   z ModifiedUndoDelegator.undo_eventu  sN    
 mm**C 		/Gu%#.DMM ;DMM s   A A"rC   )r   r   r   r   rv   r   r   __classcell__r   s   @r(   r   r   a  s    A73/ /r0   r   c                       e Zd ZdZddZy)UserInputTaggingDelegatorz.Delegator used to tag user input with "stdin".Nc                 F    |d}| j                   j                  |||       y r   )r   rv   r   s       r(   rv   z UserInputTaggingDelegator.insert  s"    <DUE40r0   rC   )r   r   r   r   rv   r   r0   r(   r   r     s
    81r0   r   c                       e Zd Zd Zy)MyRPCClientc                     t         )z0Override the base class - just re-raise EOFError)EOFErrorr   s    r(   
handle_EOFzMyRPCClient.handle_EOF  s    r0   N)r   r   r   r   r   r0   r(   r   r     s    r0   r   c                     d|xs d d}| t        |      k\  r,t        | t        |      z
  d      \  }}||z   dz   | |dz   S |dd S )zReturn 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: Shellz =r   r   N)r   divmod)widthr&   r   divmods        r(   restart_liner     sf     +G,B
/CC5#c(?Q/Ss7C-c#gY//3Bxr0   c                       e Zd Zd ZdZdZdZd Zd Zd Z	d dZ
d Zd Zd	 Zd
 Zd!dZdZd ZdZd Zd Zd Zd ZdZd Zd"dZd Zd Zd Zd"dZd Zd Zd Z d Z!d Z"d Z#d Z$d Z%y)#ModifiedInterpreterc                     || _         t        j                  d   j                  }t	        j
                  | |       d| _        d | _        t        | _	        | j                  j                  j                  | _        y )Nr   )localsF)	tkconsolesysmodules__dict__r   rI   
restartingsubprocess_arglistPORTportcompilecompilerflagsoriginal_compiler_flags)rF   r   r   s      r(   rI   zModifiedInterpreter.__init__  s[    "Z(11''V<"&	'+||'<'<'B'B$r0   Nc                     | j                   | j                         | _         t        j                  | j                         | _        y rC   )r   build_subprocess_arglist
subprocessPopen
rpcsubprocr   s    r(   spawn_subprocessz$ModifiedInterpreter.spawn_subprocess  s7    ""*&*&C&C&ED#$**4+B+BCr0   c                    | j                   dk7  sJ d       t        j                  D cg c]  }d|z   	 }}t        j                  ddddd	      }d
|d}t        j
                  g|z   d|t        | j                         gz   S c c}w )Nr   z/Socket should have been assigned a port number.z-WmainGeneralzdelete-exitfuncFbool)defaulttypez#__import__('idlelib.run').run.main()-c)r   r   warnoptionsr   	GetOption
executabler   )rF   sr   	del_exitfcommands        r(   r   z,ModifiedInterpreter.build_subprocess_arglist  s    		1 	?=	?"/!TAX// &&vy:K/46C	7	}AF!#tWc$))n&EEE 0s   Bc                 D   t         | j                  f}t        d      D ])  }t        j                  |       	 t        |      | _         n | j                          y | j                  j                  j                         d   | _        t        dk7  rC| j                  j                  j                  t        j                  t        j                  d       | j!                          | j                  j                  j#                  d       	 | j                  j%                          | j                  j+                  d| j,                         | j                  j+                  d| j,                  j.                         | j                  j+                  d| j,                  j0                         | j                  j+                  d| j,                  j2                         | j                  j+                  d	| j,                  j4                         | j                  j+                  d
t6               | j                  j+                  d|        | j9                  d       | j;                          | j                  S # t        $ r Y aw xY w# t&        $ r | j)                          Y y w xY w)N   r   r   
   consoler   stdoutstderrrN   r4   rr   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  rN   r4   transfer_pathpoll_subprocess)rF   addris      r(   start_subprocessz$ModifiedInterpreter.start_subprocess  s   dii q 		AJJqM)$/			 ++-KK..::<Q?	19
 KK&&11&2C2C+1+>+>C 	""--b1	KK  	Y7Wdnn&:&:;Xt~~'<'<=Xt~~'<'<=Wdnn&:&:;[)4Xt,D){{C  *  	,,.	s#   I3	J 3	J ?J JJc                 (   | j                   r| j                  S d| _         | j                         }|r 	 t        j                  | j                         | j                  j                          | j                          | j                  }|j                  }d|_        | j                          	 | j                  j                          | j                  |       |j                          |j                  j!                  dd       |j#                  d       |j#                  t%        |j&                  |             |j                  j)                  dd       |j                  j+                  dd       |s|j-                          |r/t        j.                  | j                         |j1                          | j2                  | j4                  j6                  _        d| _         | j                  S #  Y xY w# t        $ r | j                          Y y w xY w)	NTFr  r   end-1cr   restartleft)r   r  getdebuggerr   close_subprocess_debuggercloseterminate_subprocessr   	executingr  r'  r(  r)  r+  stop_readlinerJ   r   r!   r   r   mark_setmark_gravity
showpromptrestart_subprocess_debuggerload_breakpointsr   r   r   r   )rF   r  r&   rt   r  was_executings         r(   restart_subprocessz&ModifiedInterpreter.restart_subprocess  s   ??;;  "44T[[A 	!!#..))!	KK  	H-Hh/dl7==(;<i2!!)V4 224;;?""$&*&B&B#{{A  	,,.	s   G- ,G5 -G25HHc                 @    | j                   j                  dddi        y )Nexecinterrupt_the_serverr   )r  
remotecallr   s    r(   __request_interruptz'ModifiedInterpreter.__request_interrupt  s    v'=r2Fr0   c                 `    t        j                  | j                        j                          y )N)target)	threadingThread'_ModifiedInterpreter__request_interruptstartr   s    r(   interrupt_subprocessz(ModifiedInterpreter.interrupt_subprocess  s     8 89??Ar0   c                    | j                   /| j                  j                  j                  | j                          	 | j                  j
                  j                          	 | j                  j                          | j                          d| j                  _	        d | _        y # t        $ r Y Ow xY w# t        $ r Y Cw xY w)NF)
_afteridr   rJ   after_cancelr  r   r6  r"   r7  r8  r   s    r(   kill_subprocessz#ModifiedInterpreter.kill_subprocess  s    ==$NN,,T]];	KK&&,,.	KK 	!!##(   		  		s#   $B% "B4 %	B10B14	C ?C c                     	 | j                   j                          	 | j                   j                          y# t        $ r Y yw xY w# t        $ r Y yw xY w)z"Make sure subprocess is terminatedN)r  killwaitr#   r   s    r(   r7  z(ModifiedInterpreter.terminate_subprocess+  sQ    		OO  "
$$&   		s    A 8 	AA	AAc                     |r#dg}|j                  t        j                         nt        j                  }| j                  dj	                  |             y )Nrb   zTif 1:
        import sys as _sys
        _sys.path = {!r}
        del _sys
        
)extendr   rQ   
runcommandformat)rF   r  rQ   s      r(   r+  z!ModifiedInterpreter.transfer_path8  sA    4DKK!88D  fTl		r0   c                 x   | j                   }|y 	 |j                  | j                  d      }|r| j                  j                          d | _        |\  }}| j                  j                  }|dk(  r|yt        t        |      |       nb|dk(  r,| j                  j                  d      rB| j                          n1|dk(  r,d}t        ||t        j                          t        |||       	 | j                  j#                          | j                  j                  sJ| j                  j&                  j)                  | j                  j*                  | j,                        | _        y y # t        t        t
        f$ r. | j                  j                  rY y d }| j                          Y {w xY w# t$        $ r Y w xY w)	Ng?)rS  OKr   	EXCEPTION<<toggle-jit-stack-viewer>>ERRORz/pyshell.ModifiedInterpreter: Subprocess ERROR:
)r  pollresponse
active_seqr   r#   KeyboardInterruptr   closingr@  resetoutputr  printreprgetvarremote_stack_viewerr   
__stderr__endexecutingr"   rJ   afterpollintervalr,  rN  )rF   cltresponsehowwhatr  errmsgs          r(   r,  z#ModifiedInterpreter.poll_subprocessG  sy   kk;	&''d'CH NN&&("DO ICnn,,Gd{#$t*73#>>(()FG,,.Kfd8fd1++- ~~%% NN//55++T-A-ACDM &9 '#45 	& ~~%%H##%	&2 " s)   E( -F- (*F*F*)F*-	F98F9c                     || _         y rC   r   )rF   r   s     r(   setdebuggerzModifiedInterpreter.setdebuggero  s	     r0   c                     | j                   S rC   r   r   s    r(   r4  zModifiedInterpreter.getdebuggerr  s    }}r0   c                 d    | j                   j                  j                  d| j                         y)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   rJ   rh  re  r   s    r(   open_remote_stack_viewerz,ModifiedInterpreter.open_remote_stack_vieweru  s'     	!!#t'?'?@r0   c                    ddl m} | j                  j                  dddi       }|%| j                  j
                  j                          y |j                  | j                  |      }ddlm	}m
} t        | j                  j
                        }t        j                         }t        j                  |d      d   } |||d	      }	|	j                  j!                  d
d        ||	j"                  d |      }
|
j%                          y )Nr   )
debugobj_rrB  stackviewer)rN   )ScrolledCanvasTreeNodenormalrd   )bghighlightthicknessr   both)expandfill)idlelibru  r  remotequeuer   r   rw   StubObjectTreeItemidlelib.treerw  rx  Toplevelr   rf   rg   framepackcanvasr}  )rF   ru  oiditemrw  rx  r   rj   rd   scnodes              r(   re  z'ModifiedInterpreter.remote_stack_viewer  s    &kk%%fmZL;NN$$&,,T[[#>9t~~**+%%'**5(;LI
CJ1E
QV,		4.r0   r   c                 J    | j                  |      }| j                  ||       y)z1Like runsource() but assumes complete exec sourceN)stuffsourceexecfilerF   sourcer&   s      r(   
execsourcezModifiedInterpreter.execsource  s     ##F+h'r0   c                    |]t        j                  |      5 }|j                         }t        r)dt        j
                  j                  |       d|z   dz   }ddd       	 t        ||d      }| j                  |       y# 1 sw Y   )xY w# t        t        f$ rn | j                  j                          t        d| j                  j                         t        j                   | |       | j                  j#                          Y yw xY w)zExecute an existing fileNz__file__ = r'''z'''
z
del __file__rB  zB*** Error in script or command!
Traceback (most recent call last):r   )tokenizer   readuse_subprocessrP   rQ   abspathr   runcodeOverflowErrorSyntaxErrorr   ra  rb  r  r   showsyntaxerrorr<  )rF   r&   r  r   codes        r(   r  zModifiedInterpreter.execfile  s    >x( ;B! /0I/J%P &')9:F;

	68V4D LL; ; {+ 	(NN&&( 6~~,,. #224BNN%%'	(s   A B !B  B	A:D	D	c                 v    | j                  |      }t        |t              sJ t        j                  | ||      S )zBExtend base class method: Stuff the source in the line cache first)r  
isinstancer   r   	runsourcer  s      r(   r  zModifiedInterpreter.runsource  s6    ##F+&#&& &//fhGGr0   c                     d| j                   z  }| j                   dz   | _         |j                  d      }t        |      dz   d||ft        j                  |<   |S )z"Stuff source in the filename cachez<pyshell#%d>r   r   r   )gidsplitr   r4   r5   )rF   r  r&   r   s       r(   r  zModifiedInterpreter.stuffsource  sQ    !DHH,88a<T"$'KM1eX$E	!r0   c                 D    | j                  dj                  |             y)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)rV  rW  rF   r&   s     r(   prepend_syspathz#ModifiedInterpreter.prepend_syspath  s      &"	$r0   c                    | j                   }|j                  }|j                  ddd       t        j                         \  }}}t        |dd      xs |xs d}t        |dd      xs d}t        |d	d      xs d
}	|	d
k(  r|dz  }|dk(  r	d|	dz
  z  }
nd|dz
  |	dz
  fz  }
|j                  ||
       |j                          | j                  d|z         |j                          y)zOverride Interactive Interpreter method: Use Colorizing

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

        r\  r   r   msgrb   z<no detail available>r'   r   offsetr   ziomark + %d charsz&iomark linestart + %d lines + %d charszSyntaxError: %s
N)
r   rJ   r~   r   exc_infor   colorize_syntax_errorra  r!   r<  )rF   r&   r   rJ   r
  valuetbr  r'   r  poss              r(   r  z#ModifiedInterpreter.showsyntaxerror  s     NN	~~.,,.eReUB'K5K4K"-2"-2Q;aKFQ;%2C:!8VAX&'C''c2

&,-r0   c                     | j                   j                          | j                          t        j                  |        | j                   j                  d      r| j                   j                          yy)z1Extend base class method to reset output properlyr[  N)r   ra  checklinecacher   showtracebackrd  open_stack_viewerr   s    r(   r  z!ModifiedInterpreter.showtraceback  sU    ""$,,T2>>  !>?NN,,. @r0   c                 h    t         j                  }t        |      D ]  }|dd |dd z   dk7  s||=  y)z%Remove keys other than '<pyshell#n>'.Nr   r2   r3   )r4   r5   r6   )rF   r5   r;   s      r(   r  z"ModifiedInterpreter.checklinecache  s>    ; 	C2AwRS!T)#J	r0   c                     | j                   j                  r| j                          y| j                  r | j                  j	                  dd|fi        yt        || j                         y)z*Run the code without invoking the debuggerr   rB  r  r   )r   r8  display_executing_dialogr  r  rB  r   )rF   r  s     r(   rV  zModifiedInterpreter.runcommand  sY     >>##))+;;KK##FIwC  t{{#r0   c                    | j                   j                  r| j                          | j                          | j                  }	 | j                   j                          |s1| j                  %| j                  j                  dd|fi       | _        n6|r |j                  || j                         nt        || j                         t$        s	 | j                   j+                          yy# t        $ rY | j                   j                  s?t        j                  ddd| j                   j                         r | j#                          n Y  t$        rLt'        d| j                   j(                  	       | j#                          | j                   j+                          nY| j                   j,                  r3d
| j                   _        t'        d| j                   j(                  	       n| j#                          Y 3xY w# t.        $ r Y yw xY w# t$        s+	 | j                   j+                          w # t.        $ r Y w w xY ww xY w)Override base class methodNrB  r  zExit?zDo you want to exit altogether?yesr	  r   z IDLE internal error in runcode()r   Fr_  )r   r8  r@  r  r   beginexecutingr  
asyncqueuer^  runr   rB  
SystemExitr`  r
   askyesnorJ   r  r  rb  r  rg  canceledr"   )rF   r  r   s      r(   r  zModifiedInterpreter.runcode   s   >>####%==&	NN))+ 7"&++"8"89=#ET4;;/T4;;'4 "NN//1 "3  	>>))&&5!>>..	0
 &&( )	)8>>002""$++->>**.3DNN+-DNN4I4IJ&&(
 &  "NN//1%  "s]   BC* G= *AG:	H B,G:7H =	H	H	H?H/.H?/	H;8H?:H;;H?c                 L    | j                   j                  j                  |      S )r  )r   r  r!   )rF   r  s     r(   r!   zModifiedInterpreter.write.  s    ~~$$**1--r0   c                 \    t        j                  dd| j                  j                         y )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   rJ   r   s    r(   r  z.ModifiedInterpreter.display_port_binding_error2  s'     / >>&&	(r0   c                 \    t        j                  dd| j                  j                         y )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  r  r   s    r(   r)  z/ModifiedInterpreter.display_no_subprocess_error=  s(    )J >>&&	(r0   c                 \    t        j                  dd| j                  j                         y )NzAlready executingzYThe Python Shell window is already executing a command; please wait until it is finished.r  r  r   s    r(   r  z,ModifiedInterpreter.display_executing_dialogE  s%    0>>&&		(r0   )Frb   )FrC   )&r   r   r   rI   rN  r  r  r  r   r/  r@  rJ  rL  rP  r7  r+  r^  r,  r   rp  r4  rs  re  r  r  r  r  r  r  r  r  r  rV  r  r!   r  r)  r  r   r0   r(   r   r     s    C HFJD

F)V*XGB J$CL H!" C(
(H
$4/
,\.	(((r0   r   c            	       P    e Zd ZddlmZ d e       z   ZeZe	Z
g dZej                  dgz   Zd e e ej"                  d e                  z   Zej'                  ed       [d	Zd
ZddlmZ ddlmZ d9dZ fdZ fdZd Zd Zd Zd9dZ d	Z!d	Z"d	Z#d	Z$d	Z%d	Z&d Z'd Z(d9dZ)d Z*d9dZ+d Z,d Z-d Z.d Z/d Z0d Z1d Z2d  Z3d! Z4d"Z5d# Z6d$ Z7d% Z8d& Z9d9d'Z:d( Z;d) Z<d* Z=d+ Z> e?j                  d,      ZAd- ZBd9d.ZCd9d/ZDd9d0ZEd1 ZFd2 ZGd3 ZHd:d4ZI fd5ZJ fd6ZKd9d7ZLd8 ZM xZNS );r   r   )SqueezerzIDLE Shell ))r   _File)edit_Edit)rt   _Debug)options_Options)window_Window)help_Help)Squeeze<<squeeze-current-text>>r   c                     | d   dk7  S )Nr   r\   r   )
rmenu_items    r(   r   zPyShell.<lambda>e  s    :a=F2 r0   )zCopy with prompts<<copy-with-prompts>>r]   Fr   )History)ShellSidebarc                    t         r)| j                  }|d   d   dk7  r|j                  dd       t        |       | _        |0t               }t        |       |j                          t        |      }d | _	        t        j                  | |d d        d| _        d| _        t        t        d      rt        j                   nd| _        | j"                  j%                  d	      d
   | _        | j"                  | _        | j*                  }|j-                  d       |j/                  d| j0                         |j/                  d| j2                         |j/                  d| j4                         |j/                  d| j6                         |j/                  d| j8                         |j/                  d| j:                         |j/                  d| j<                         |j/                  d| j>                         t         r8|j/                  d| j@                         |j/                  d| jB                         | jE                  |       | _#        |j/                  d| jH                         t        jJ                  | _&        t        jN                  | _(        t        jR                  | _*        ddl+m,} t[        | d|j\                  |j^                        | _)        ta        | d|j\                  |j^                        | _%        ta        | d|j\                  d      | _'        ta        | d|j\                  |j^                        | _1        t         s?| jJ                  t        _%        | jN                  t        _'        | jR                  t        _)        	 dd l2}|jf                  |_4        | jm                  | j*                        | _7        d| _8        | js                  |       | _	        | jt                  jv                  j                  | j*                  _        | jt                  jy                  t{                      y #  t        jj                  t        _'         xY w)Nr   r   shell)r  She_llF   ps1z>>>
r   r2   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_specsrv   r   rr   Tkr   withdrawr   shell_sidebarr   rI   usetabsindentwidthhasattrr   r  sys_ps1r  prompt_last_linepromptrJ   	configurerK   enter_callbacklinefeed_callbackcancel_callbackeof_callbackr  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  r  r   encodingerrorsr   r  pydoc
plainpagerpagerrf  r  historyri  r  perr   insertfilterr   )rF   rN   msr   rJ   r  r  s          r(   rI   zPyShell.__init__s  s*   B!uQx7"		!01)$/=4D$MMO#D)E!dE46")#u"5sww7 $ 2 24 8 <llyyF#		*D,?,?@		0$2H2HI		+T-A-AB		#T%6%67		)4+A+AB		')=)=>		/1M1MN		)4+J+JKII($*@*@AII)4+=+=>d+		,11	3 ::::))"!$"(//6==B
#D($*OOV]]D#D($*OO5GI$T9%+__fmmECJCJ

CI	**EK
 ||DII.!..t4
  88<<..		79:	CJs   P* *Qc                 p    t         |           | j                  | j                  j                          y y rC   )r   	ResetFontr  update_fontrF   r   s    r(   r  zPyShell.ResetFont  s1    )**, *r0   c                    t         |           t        j                         }d d dt        j                  |d      t        j                  |d      t        j                  |d      d}|j                         D ]"  \  }} | j                  j                  |fi | $ | j                  | j                  j                          y y )N)rd   rc   r  r  ry  )r   r  r  r  )
r   ResetColorizerr   rf   rg   itemsrJ   tag_configurer  update_colors)rF   rj   
tag_colorsr   tag_colors_configr   s        r(   r  zPyShell.ResetColorizer  s     %%'"&d;))%:))%:**5(;	

 '1&6&6&8 	>"C"#DII##C=+<=	> ),,. *r0   c                 F    t        j                   | j                  d       y)Nr   )insert_tagsra   )r   rJ   r   s     r(   replace_eventzPyShell.replace_event  s    		w7r0   c                 .    t        j                  d      S )NT)
shell_only)r   GetExtensionsr   s    r(   get_standard_extension_namesz$PyShell.get_standard_extension_names  s    %%66r0   c                 n   | j                   j                  ||      }t        t        t	        |            t        t	        |                  }|D cg c]'  }| j
                  j                  j                  |      ) }}dj                  d t        ||j                               D              dz   S c c}w )z6Return text between first and last with prompts added.r   c              3   8   K   | ]  \  }}||n| d|   y w)N r   ).0r  r   s      r(   	<genexpr>z*PyShell.get_prompt_text.<locals>.<genexpr>  s0      
 ND6(!D6(::
s   )
rJ   getr   rx   ry   r  line_promptsrR   zip
splitlines)rF   firstlastrJ   lineno_ranger'   promptss          r(   get_prompt_textzPyShell.get_prompt_text  s    yy}}UD)ed '
 ++//7
 
 yy 
 #GT__-> ?
 
  		
s   ,B2c                     | j                   }|j                  d      }|y|j                  d      }|d   dk7  r|j                  d      }|j                          | j                  ||      }|j	                  |       y)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.lastr2   0zsel.last+1line linestart)rJ   rn   clipboard_clearr"  clipboard_append)rF   rz   rJ   selfirstsellastprompt_texts         r(   r  z"PyShell.copy_with_prompts_callback  sz     yy::34**Z(2;#jj!;<G**8W=k*r0   c                     |a y rC   r    )rF   streams     r(   set_warning_streamzPyShell.set_warning_stream
  s    r0   c                     t         S rC   r,  r   s    r(   get_warning_streamzPyShell.get_warning_stream  s    r0   c                     | j                   r3t        j                  dd| j                         | j	                          y| j
                  j                         }|r| j                          y | j                          y )NzDon't debug nowz*You can only toggle the debugger when idler  ra   )	r8  r
   r   rJ   set_debugger_indicatorrr   r4  close_debuggeropen_debugger)rF   rz   dbs      r(   r  zPyShell.toggle_debugger  sb    >>  !2<yy" '')((*B##%""$r0   c                 `    | j                   j                         }| j                  d|         y )Nr  )rr   r4  setvarrF   r5  s     r(   r2  zPyShell.set_debugger_indicator  s'    [[$$&)2v:6r0   c                      y rC   r   r   s     r(   r  zPyShell.toggle_jit_stack_viewer#  s    r0   c                    | j                   j                         }|r| j                   j                  d        |j                          | j                   j                  r)t        j                  | j                   j                         | j                          | j                  j                  d       | j                  | _        | j                          | j                          y )Nz[DEBUG OFF]
)rr   r4  rp  r6  r  r   close_remote_debuggerra  r  r!   r  r  r<  r2  r8  s     r(   r3  zPyShell.close_debugger&  s    [[$$&KK##D)HHJ{{!!001C1CDLL/,,DKOO##%r0   c                 n   | j                   j                  r+t        j                  | j                   j                  |       }nt	        j
                  |       }| j                   j                  |       |j                          d| j                  z   | _	        | j                          | j                          y )Nz[DEBUG ON]
)rr   r  r   start_remote_debuggerr   Debuggerrp  r>  r  r  r<  r2  )rF   dbg_guis     r(   r4  zPyShell.open_debugger3  s    ;; 66t{{7I7I;?AG ''-G(  "$t||3##%r0   c                 J    | j                   rdnd}| j                  dd|       y )Ndisabledry  rt   z*tack*iewer)r8  update_menu_state)rF   states     r(   debug_menu_postcommandzPyShell.debug_menu_postcommand?  s!    "nn
(wu=r0   c                 2    | j                          d| _        y)Helper for ModifiedInterpreterTN)ra  r8  r   s    r(   r  zPyShell.beginexecutingC  s    r0   c                 @    d| _         d| _        | j                          y)rF  FN)r8  r  r<  r   s    r(   rg  zPyShell.endexecutingH  s    r0   c                     | j                   r(t        j                  ddd| j                        }|du ry| j	                          d| _        d| _        t        j                  |       S )zExtend EditorWindow.close()zKill?z7Your program is still running!
 Do you want to kill it?okr  FcancelT)	r8  r
   askokcancelrJ   r9  r  r`  r   r6  )rF   rk  s     r(   r6  zPyShell.closeN  sa    >>!--Jyy	"H
 5 !!$''r0   c                 X   | j                          t        r| j                  j                          | j                  t
        _        | j                  t
        _        | j                  t
        _
        d| _        d| _        d| j                  _        d| _        t        j                   |        y)zEExtend EditorWindow._close(), shut down debugger and execution serverN)r3  r  rr   rP  r  r   r  r  r  r  r   r  rN   rq   r  r   r   r   s    r(   r   zPyShell._close]  su    KK'')%%
%%
OO	!

D!r0   c                      y)z8Override EditorWindow method: never remove the colorizerTr   r  s     r(   ispythonsourcezPyShell.ispythonsourcem  s    r0   c                     | j                   S rC   )shell_titler   s    r(   short_titlezPyShell.short_titleq  s    r0   zHType "help", "copyright", "credits" or "license()" for more information.c           
         | j                   j                  dd       | j                          t        r/d}| j                  j                         }|s,| j                          yd}t        j                  t        _        | j                  dt        j                  dt        j                  d| j                  d|       | j                   j                          | j                          d	d l}d
|_        d |_        y
)Nr   rv   rb   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 z on r   r   T)rJ   r:  ra  r  rr   r/  r6  r   displayhookr   r!   versionplatform	COPYRIGHTfocus_forcer<  tkinter_support_default_root_default_root)rF   nosubclientrX  s       r(   r   zPyShell.beginw  s    		8X.E[[113F

'E "ooCO

KKt~~uF 	G		(,% $r0   c                 `    | j                   sy d| _        | j                  j                          y NT)reading_stop_readline_flagr   quitr   s    r(   r9  zPyShell.stop_readline  s!    ||#' r0   c                    | j                   }	 d| _         | j                  j                          || _         | j                  rd| _        y| j                  j                  dd      }t        |      dk(  rd}| j                          | j                  rd| _        t        st        | j                  r	d| _        d}|S # || _         w xY w)NTFrb   r   r1  r   r   )r_  r   mainloopr`  rJ   r  r   ra  r  r  r_  	endoffile)rF   r:   r   s      r(   readlinezPyShell.readline  s    ||	 DLHHDL##',D$yy}}Xx0t9>D==!DM!''>>"DND  DLs   !B< <	Cc                      yr^  r   r   s    r(   isattyzPyShell.isatty  s    r0   c                 D   	 | j                   j                  ddd      ry 	 | j                  sH| j                  s<| j	                          | j
                  j                  d       | j                          yd| _        d| _	        | j                  re| j
                  j                  rO| j
                  j                         r| j
                  j                          n| j
                  j                          | j                  r| j                  j                          y#  Y xY w)N	sel.firstz!=r$  zKeyboardInterrupt
ra   FT)rJ   r   r8  r_  ra  rr   r!   r<  rd  r  r  r4  r@  rL  r   ra  r   s     r(   r  zPyShell.cancel_callback  s    	yy  dJ? @ $,,KK34OONNt{{11{{&&(..0002<<HHMMO!	s   D Dc                 V   | j                   r| j                  sy | j                  j                  ddd      r| j                  j                  ddd      sy | j                   s!| j	                          | j                          yd| _        d| _        | j                  j                          y)Nr   z==rv   r1  FTra   )
r8  r_  rJ   r   ra  r6  r  rd  r   ra  r   s     r(   r  zPyShell.eof_callback  s    >>$,,		!!(D(;		!!(D(;~~JJL
  "DM!DNHHMMOr0   c                     | j                   r8| j                  j                  dd       | j                  j                  d       y| j	                  |       y)Nrv   r   ra   )r_  rJ   rv   seenewline_and_indent_eventr   s     r(   r  zPyShell.linefeed_callback  sE    <<IIXt,IIMM(#  ))%0r0   c                 r	   | j                   r| j                  sy 	 | j                  j                  dd      }|r0| j                  j	                  ddd      r| j                  ||       y| j                  j	                  ddd      r| j                  j                  d	d      }|r#| j                  j	                  dd|d
         rd| j                  j                  d      vr| j                  j                  dd      }|r-| j                  j	                  |d
   d|d         r
|d
   |d
   f}| j                  j                  dd      }|rI| j                  j	                  |d   d|d
         r&|d   | j                  j                  |d   dz         f}| j                  | j                  j                  |d   |d
         |       y| j                  j                  d	d      }|r| j                  j	                  dd|d         r| j                  j                  dd      }|rI| j                  j	                  |d   d|d
         r&|d   | j                  j                  |d   dz         f}| j                  | j                  j                  |d   |d
         |       y| j                  j                  dd      }|rP| j                  j	                  |d   dd      r0| j                  | j                  j                  |d
   d      |       y| j                  | j                  j                  dd      |       y| j                  j	                  ddd      r| j                  j                  dd       | j                  j                  dd      }|r,|j                         s| j                  j                  dd       | j                  j	                  ddd      r| j                  |       y| j                  j                  dd       | j                  r8| j                  j                  dd       | j                  j                  d       n| j                  |       | j                  j!                          | j                  r| j"                  j%                          y| j'                          y#  Y MxY w)Nri  r$  z<=r   ra   rv   r   iomark linestartr   r   r  z>=r   z+1czinsert lineendr|   r1  zend-1c linestartr   )r8  r_  rJ   r  r   recalltag_prevrange	tag_namestag_nextrangern   r:  stripr   rm  rv   rl  update_idletasksr   ra  runit)	rF   rz   selprev	prev_cons	next_consnextindicesr  s	            r(   r  zPyShell.enter_callback  s   >>$,,	))--Z8C99$$Zx@KKU+" 99Xs,>?
 99**7H=DII%%hT!W=TYY%8%8%BB II33IxH	!2!29Q<tAw!O%aL$q'2D II33IxH	!2!29Q<d1g!N GTYY__Yq\E5I%JKDDIIMM$q'47;UC99**7H=D		))*:D$q'J II33I?OP	!2!29Q<d1g!N GTYY__Yq\E5I%JKDDIIMM$q'47;UCii--i9KLGyy  T3EFDIIMM'!*6FGO  DIIMM*<>NOQVW 99XsH5IIx2 IIMM(H-QWWYIIXx0 99Xs,>?))%0		8X.<<IIXt,IIMM(#))%0		""$<<HHMMO  JJLE	s   AR1 1R6c                    t        j                  dd|      }t        j                  dd|      }|j                  d      }| j                  j	                          	 | j                  j                  ddd       | j                  j                  dd	       | j                  j                  d
d      }|j                         j                  d      r-| j                  |       | j                  j                  d
d      }| j                  j                  d|d   j                         | j                         t        |      dkD  rt        j                  d|d         j!                  d      }t        j                  d|      j!                  d      }|dd  D ]\  }|j#                  |      r||t        |      d  z   }| j                  j                  dd|j                         z   | j                         ^ | j                  j%                  d       | j                  j'                          y # | j                  j%                  d       | j                  j'                          w xY w)Nz^\s*\nrb   z\n\s*$r   rw  r   r   rv   r1  r|   :r   r   z	^([ \t]*))resubr  rJ   undo_block_startr~   r:  r  rstripendswithrm  rv   rt  user_input_insert_tagsr   searchgroupr   rl  undo_block_stop)rF   r  rz   r   prefixorig_base_indentnew_base_indentr   s           r(   rp  zPyShell.recall.  s   FF9b!$FF9b!$		""$	(II  u5IIx2YY]]#5x@F}}'',--e4'98DIIXuQx~~'7!88:5zA~#%99\58#D#J#J1#M #%99\6#B#H#H#K!!"I BD'78.c:J6K6L1MMII$$Xtdkkm/C%)%@%@B	B IIMM(#II%%' IIMM(#II%%'s   FH) )7I z[ \t]*(\n[ \t]*)?\Zc                    | j                   j                  d      }| j                   j                  dd      }| j                  j	                  d|      }| j
                  j                  |      }|s_| j                   j                  |      dk(  r&| j                   j                  | j                  |       | j                  j                          y y )Nend-2cr   r1  rb   r   )rJ   rn   r  _last_newline_rer  rr   r  r~   r  r  update_sidebar)rF   index_beforer   input_is_completes       r(   rv  zPyShell.runitK  s    yyx0yy}}Xx0 $$((T2 KK11$7 yy}}\*d2		$$T%@%@,O--/ !r0   c                    | j                   j                  r| j                   j                         S ddlm} 	  || j
                  t        j                  | j                         y #  t        j                  dd| j                         Y y xY w)Nr   )StackBrowserzNo stack tracez:There is no stack trace yet.
(sys.last_exc is not defined)r  )rr   r  re  idlelib.stackviewerr  r   r   last_excrN   r
   r   rJ   )rF   rz   r  s      r(   r  zPyShell.open_stack_viewerW  sp    ;;;;22444	"CLL$**= 	"  !10yy" s   ,A% %$Bc                 p    | j                   j                  d       | j                   j                  d       y )Nr   r2  )rJ   rl  r   s     r(   r  zPyShell.view_restart_marke  s"    		h		i r0   c                 <    | j                   j                  d       y)z&Callback for Run/Restart Shell Cntl-F6Tr  N)rr   r@  r   s     r(   r  zPyShell.restart_shelli  s    &&&5r0   c                    | j                          | j                  }| j                  r4|j                  | j                        r|d t	        | j                          }| j
                  j                  dd       | j                  j                  |       | j                  j                          | j
                  j                  dd       | j                          | j                  j                          y )Nr  z	iomark-1crv   r1  )ra  r  r  r  r   rJ   rm   r  r!   r  r  r:  set_line_and_columnrU   
reset_undo)rF   r  s     r(   r<  zPyShell.showpromptm  s    <<FOODLL9/c$,,//0F		)[16"))+		8X.  "r0   c                    | j                   j                  j                  }t        |dd      }dj	                  |j                  |            }|j                  d      s|dz  }| j                  j                  j                  d|d       y )N   T)r   tabsizeexpand_tabsr   ro  r  )
rr   r   r   r   rR   r  r  r   bottomrv   )rF   r  r   wrapperwrapped_msgs        r(   show_warningzPyShell.show_warning{  so    %%++E1$GiiS 12##D)4K1;Ir0   c                    | j                   j                  dd      }| j                  r| j                  j                  |       | j                   j                  d      dk7  r| j                   j	                  dd       | j                   j                  dd       | j                          | j                  j                          y )Nr   r1  r  r   )	rJ   r  r  storerv   r:  r  ctipremove_calltip_window)rF   r  s     r(   ra  zPyShell.resetoutput  s    x2<<LLv&99=="d*IIXt,		8X.  "		'')r0   c                     	 | j                   j                  dd       t        j                  | ||d      }| j                   j                  dd       | j                  rd| _        t
        st        |S #   xY w)Nr   rightr3  F)rJ   r;  r   r!   r  r  r_  )rF   r  r   counts       r(   r!   zPyShell.write  sm    	II""8W5 &&tQh?EII""8V4 ==!DM!''	s   AA3 3A6c                 ~    	 | j                   j                  ddd      ry	 t        |          S # t        $ r Y yw xY w)Nri  r   r   rA  )rJ   r   r   r   r[   r  s    r(   r[   zPyShell.rmenu_check_cut  sJ    	yy  c8<! = w&((  		s   0 	<<c                 \    | j                   j                  ddd      ryt        |          S )Nrv   r   r   rA  )rJ   r   r   r_   r  s    r(   r_   zPyShell.rmenu_check_paste  s*    99Xc(3w(**r0   c                 l    | j                   j                          | j                  j                          y rC   )r  squeeze_current_textr  r  r   s     r(   r  z"PyShell.squeeze_current_text_event  s$    **,))+r0   c                 8    | j                   j                          y rC   )r  r  )rF   rn   rJ   r   s       r(   on_squeezed_expandzPyShell.on_squeezed_expand  s    ))+r0   rC   )r   )Or   r   r   idlelib.squeezerr  r   rP  r   r   r   r   r  r   r   r   r6   	itertools	takewhile_idxrv   allow_line_numbersr  idlelib.historyr  idlelib.sidebarr  rI   r  r  r  r  r"  r  r_  r8  r  rd  r`  r`  r.  r0  r  r2  r  r3  r4  rD  r  rg  r6  r   rN  rQ  rV  r   r9  re  rg  r  r  r  r  rp  r  r   r  rv  r  r  r  r<  r  ra  r!   r[   r_   r  r  r   r   s   @r(   r   r   M  s   )."22K ,N)MJ **/. K s4+	++2KA   D t 2 3 	$ (,L;\-/ 7"+( GIHIG %7&
&>
("   U 4.,M^(8 "rzz"89
0!6J*)+
,,r0   r   c           
      ~    | j                   dk(  r.dD ](  }| j                  |dd| j                  |d      z          * yy)z6Make paste replace selection on x11.  See issue #5124.x11)TextEntrySpinboxz	<<Paste>>z%catch {%W delete sel.first sel.last}
N)_windowingsystem
bind_class)r   clss     r(   fix_x11_paster    sL    %- 	;COO8[9:;	; &r0   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            	         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}		 | j                  t        j                  dd  d      \  }
}
D ]  \  }}|dk(  r|}d}|dk(  rd}d}|dk(  rd}|dk(  r7t        j                  j!                  t               t        j                          |dk(  rd}|dk(  rt        dt        j                         da|dk(  rD|}t"        j$                  j'                  |      rn t        d|       t        j                          d}|dk(  rd}	d}|dk(  s|t(        _        d} r(|d   dk(  r t        j,                  j/                         }d}t1        t3        t        j$                              D ]C  }t"        j$                  j5                  t        j$                  |         t        j$                  |<   E |r|d   dk(  rdg|dd  z   t        _	        n|rdg|z   t        _	        n|r|g|z   t        _	        n|rd}g }|D ]0  }|j7                  t"        j$                  j9                  |             2 |D ]T  }t"        j$                  j5                  |      }|t        j$                  vs5t        j$                  j;                  d|       V nFt#        j<                         }|t        j$                  vr t        j$                  j;                  d|       t?        j@                  dddd      }|xs |}|xs | }t        r|s
tC                tE        d       a#tF        jI                          dd!l%m&}  |tF               t"        j$                  jO                  t"        j$                  j9                  tP              d"      } |       d#k(  r7t"        j$                  jO                  |d$      }tF        jS                  |%       n|jU                         sxtV        d&k\  rd'}d(}nd)}d*}|D cg c]'  }t"        j$                  jO                  |d+||fz        ) }}|D cg c]  }tY        tF        |,       }}tG        jZ                  dg|  t]        tF               t_        tF               ta        tF              a1|je                  tF        tb               |rK|sI|sG|d d  D ])  }tb        jg                  |      |ji                  |       + |stb        jk                          |rRtb        jm                         }|sy |jU                         r;tb        jn                  r+|jp                  js                          ntb        jt                  }|r|jw                          |	r|t"        jx                  j{                  d-      xs t"        jx                  j{                  d.      }|r:t"        j$                  j'                  |      r|j|                  j                  |       |s|r|j|                  j                  d/j                  t        j                               |r|j|                  j                  |       n^|r\|j|                  j                  |       |j|                  j                  |       n%|r#|j                         }|r|j                  |       tb        j                  r%tF        j                          tb        j                  r%tF        j                          t        d       y # | j                  $ rE}t        d	| d
t         t        j                         t        j                  d       Y d }~d }~ww xY wc c}w c c}w )0Nr   )system)testing)macosxTFr   zc:deihnr:st:zError: r   r   r   r  z-dz-ez-hz-iz-nz: Warning: running IDLE without a subprocess is deprecated.z-rzNo script file: z-sz-t-rb   r  r  zeditor-on-startupr  )r
  Idle)	className)fix_scalingIconsWindowszidle.ico)r	  g333333!@z.png)       0      z.gif)r  r  r  z	idle_%d%s)masterr   IDLESTARTUPPYTHONSTARTUPzdif 1:
            import sys as _sys
            _sys.argv = {!r}
            del _sys
            
)IgetoptrU  r  r  r  r  r/   r  r   argverrorrb  	usage_msgr  exitr  r!   rP   rQ   r   r   rP  r   r  r   r   r  rp   dirnamerv   getcwdr   r  NoDefaultRootr  r   r  idlelib.runr  rR   __file__wm_iconbitmapisAquaTk	TkVersion
PhotoImagewm_iconphotor   r  r   rN   setupAppr   r}   newrO   dictr   lowerrq   r4  environr  rr   r  rV  rW  r  r  preferTabsPreferenceWarningr  inversedictrc  destroy)r  r  r  r  enable_shellenable_editrt   cmdscriptstartupoptsrY   r  oar.  pathxr&   dir
edit_startr  icondiriconfileextsizessize	iconfilesiconsr  prefer_tabs_preference_warnings                                 r(   r  r    s    TNLKE
CFG]]388AB<@
d   19CL9EL9K9JJY'HHJ9L9Nzz#"N9Fww~~f%(&1
L9GL9"#GL? @ Q3iinn3sxx=! 3ggoochhqk23Q34$qr(?	6D=	8d?	 	4HLL23	4 	(C''//#&C#((?3'	(
 iikchhHHOOAs###FI$7fFJ+K2{?L gDMMO' ggll277??84g>Gx977<<48,__C%EC E!&( WW\\';$+DE (	 ( "+, 4h7 , ,$'' $$D!E
OOD% v G *::h'/KK)* 		  "??
 IIOO ::>>-0 3::>>/2 	x0LL!!(+
f ! &"		$
 LL##C(LL((0LL!!&)	 *0)K)K)M&)=>


 

LLNUy << uByk*<n(,s#   &[; ,]6];]
:]

])NN)Rr   r   r   rX  ImportErrorrb  rf  r  rU  ctypesPROCESS_SYSTEM_DPI_AWAREOleDLLSetProcessDpiAwarenessr"   r#   r
   r  r   r  r4   rP   os.pathr   r  r#  r  textwrapr   rH  r  r  r,   idlelib.colorizerr   idlelib.configr   idlelib.delegatorr   r  r   r   idlelib.editorr   r   idlelib.filelistr   idlelib.outwinr   r   r   r  r   r   r   idlelib.undor   r  r  r   eofr  ra  	NameErrorr    r)   r+   r/   
checkcacher<   r>   r   r   r   r   	RPCClientr   r   r   r   r  r  r  r   r0   r(   <module>r     s-   z%([[%<CKK!" <<7#$ h667OP  '   	  # 	         , # '   6 % '   G G & 	
 CDHDH  >B"  )  +/2;2F2F( 5	 {", {"|h (
2^ 
2/M /D1	 1#-- k(0 k(\`	,l `	,F;4	lnb zF  y4  	 9?B~~O
Q- 1 V  		s.   G 'G( <G7 "G%(G43G47G?>G?