
   WG;$y                      S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
rSSKrSSKrSSKrSSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SS	KJr  SSKrSSKr\" \R2                  S
   S5      (       d6  S H  r\" \\5        \R2                  S\-   	 M     S\R2                  S
   l        Sr Sr\\l        \\ l        S5S jr" S6S jr#Sq$S r%\%" S5        \RL                  (       a  S r'O\RP                  " 5       r)\)4S jr'Sq*Sq+Sq,S7S jr-S r.S r/S r0S r1S r2S r3S rS r4S  r5S!r6S" r7S# r8 " S$ S%\Rr                  5      r: " S& S'\Rv                  5      r< " S( S)\<5      r= " S* S+\<5      r> " S, S-\R~                  5      r@ " S. S/5      rA\BS0:X  a  SS1KCJ-r-  \-" S2S3S49  \%" S5        g! \! a     Nf = f)8zidlelib.run

Simplified, pyshell.ModifiedInterpreter spawns a subprocess with
f'''{sys.executable} -c "__import__('idlelib.run').run.main()"'''
'.run' is needed because __import__ returns idlelib, not idlelib.run.
    N)autocomplete)calltip)
debugger_r)
debugobj_r)iomenu)rpc)stackviewerzidlelib.runfirstrun)simpledialog
messageboxfontdialog
filedialogcommondialogttkztkinter.Fz	127.0.0.1zCtrl-D (end-of-file)c                     SnUSU SU S3-  nUc  [         R                  " X#5      nUR                  5       nU(       a  USU-  -  nXQR                   SU  S3-  nU$ )zFormat warnings the IDLE way.z!
Warning (from warnings module):
z  File "z", line 
z    %s
: )	linecachegetlinestrip__name__)messagecategoryfilenamelinenoliness         "/usr/lib/python3.13/idlelib/run.pyidle_formatwarningr    3   su     	.A9XJixr	22A|  2::<D	Z$b		,,AH    c           	          Uc  [         R                  n UR                  [        XX#U5      5        g! [         a     gf = f)zmShow Idle-format warning after replacing warnings.showwarning.

The only difference is the formatter called.
N)sysstderrwriter    OSError)r   r   r   r   filer   s         r   idle_showwarning_subprocr(   @   sD     |zz

%8T; 	< s   2 
??c                     U (       a(  [         c   [        R                  q [        [        l        gg[         b  [         [        l        Sq gg)zFReplace warning.showwarning with idle_showwarning_subproc, or reverse.N)_warnings_showwarningwarningsshowwarningr(   )captures    r   capture_warningsr.   P   sA      ($,$8$8!#;H  ) !,#8H $(! -r!   Tc                      g N r1   r!   r   handle_tk_eventsr2   b   s    r!   c                 &    U R                  S5        g)zProcess any tk events that are ready to be dispatched if tkinter
has been imported, a tcl interpreter has been created and tk has been
loaded.updateN)eval)tcls    r   r2   r2   g   s     	r!   c           	         U q  [        [        R                  5      S:  d   e[	        [        R                  S   5      n[        S5        S/[        R                  SS& [        R                  " [        S[        U44SS	9R                  5           [        (       a   [        5          [         R"                  R%                  SS
S9nU(       a1  Uu  nu  pEnU" U0 UD6n[         R*                  R-                  X745        O[/        5          M{  !   [        S[        R                  S9   g= f! [         a     M  f = f! [&        R(                   a    Sn Nf = f! [         a    [0        (       a  Sq M  [2         a    [        S5        e   [        R4                  " 5       u  pn
 [7        5         [         R*                  R-                  WS45         GM@  !   [8        R6                  " XU
[        R                  S9  [        5           N= f= f)a2  Start the Python execution server in a subprocess

In the Python subprocess, RPCServer is instantiated with handlerclass
MyHandler, which inherits register/unregister methods from RPCHandler via
the mix-in class SocketIO.

When the RPCServer 'server' is instantiated, the TCPServer initialization
creates an instance of run.MyHandler and calls its handle() method.
handle() instantiates a run.Executive object, passing it a reference to the
MyHandler object.  That reference is saved as attribute rpchandler of the
Executive instance.  The Executive methods have access to the reference and
can pass it on to entities that they command
(e.g. debugger_r.Debugger.start_debugger()).  The latter, in turn, can
call MyHandler(SocketIO) register/unregister methods via the reference to
register and unregister themselves.

   z/IDLE Subprocess: no IP port passed in sys.argv.r'   NT 
SockThread)targetnameargsdaemon皙?)blocktimeoutF)no_exitfunclenr#   argvintprint
__stderr__r.   	threadingThreadmanage_socket	LOCALHOSTstartexit_nowexitKeyboardInterruptr   request_queuegetqueueEmptyresponse_queueputr2   quitting
SystemExitexc_infoprint_exception	traceback)del_exitfuncportrequestseqmethodr?   kwargsrettypevaluetbs              r   mainrg   u   s   * K388}q ! 388B<  T$CHHQKM&%t,.  eg
$	xF++//dD/I
 .5++fFd-f-""&&z2 "' ?>>	# ) 
 ;;  ! 	x 	U#
	!llnOD!""&&T{3 ))$rOs}   ;D
 E 
D) 'D: 7E =
E 
D&)
D73E 6D77E :EE EE H0.H+G0H>HHc                 n   [        S5       H*  n[        R                  " U5         [        U [        5      n  O)   [        S[        R                  S9  [        WU 5        Sqg UR                  5         g ! [
         a8  n[        SUR                  S   -   S-   [        R                  S9  Un S nAM  S nAff = f)N   zIDLE Subprocess: OSError: r8   z, retrying....r:   z8IDLE Subprocess: Connection to IDLE GUI failed, exiting.T)rangetimesleepMyRPCServer	MyHandlerr&   rH   r?   r#   rI   show_socket_errorrO   handle_request)addressiservererrsocket_errors        r   rL   rL      s    1X

1	 )4F	  	 *03	@,0
  	.!<"#),9L	s   A22
B4<-B//B4c                     SSK nSSKJn  UR                  " 5       n[	        U5        UR                  5         U" SSUS    SUS    SU R                   S	U R                   S
3	US9  UR                  5         g)z(Display socket error from manage_socket.r   N)	showerrorzSubprocess Connection Errorz#IDLE's subprocess can't connect to :r8   z.
Fatal OSError #r   zz.
See the 'Startup failure' section of the IDLE doc, online at
https://docs.python.org/3/library/idle.html#startup-failure)parent)	tkintertkinter.messageboxrw   Tkfix_scalingwithdrawerrnostrerrordestroy)rt   rq   rz   rw   roots        r   ro   ro      sy    ,::<DMMO)1'!*Qwqzl K!ii[3<<. 9JJ  	LLNr!   c                 R   U [         [        4;   aq  [        R                  " 5       n[        R
                  " U5         [        R                  " XU5        SSS5        UR                  5       R                  S5      S   S-   /$ [        R                  " X5      $ ! , (       d  f       NJ= f)z,Return line composing the exception message.Nr   )AttributeError	NameErrorioStringIO
contextlibredirect_stderrr#   __excepthook__getvaluesplitr\   format_exception_only)typexcrf   rt   s       r   get_message_linesr      s{    
~y))kkm'',s, -$$T*2.566..s88	 -,s   B
B&c                  (  ^^^ SS K n U R                  " 5         [        5         [        R                  m[        R
                  " 5       =u  pp4Uu  [        l        [        l        [        l        U[        l	        [        5       mUUU4S jmT" XU5        g )Nr   c                 @  > TR                  [        U5      5        UR                  nUR                  nUb6  [        U5      T;  a'  T
" [	        U5      XDR
                  5        [        ST	S9  OIUbF  UR                  (       d5  [        U5      T;  a&  T
" [	        U5      X3R
                  5        [        ST	S9  U(       aB  [        R                  " U5      n[        ST	S9  Sn[        XV5        [        R                  " UT	S9  [        XU5      nU H  n[        UST	S9  M     g )NzF
The above exception was the direct cause of the following exception:
r:   zE
During handling of the above exception, another exception occurred:
z"Traceback (most recent call last):)zrun.pyzrpc.pyzthreading.pyzqueue.pyzdebugger_r.pyzbdb.pyr;   )endr'   )addid__context__	__cause__rd   __traceback__rH   __suppress_context__r\   
extract_tbcleanup_traceback
print_listr   )r   r   rf   contextcausetbeexcludelinesr   efile	print_excseens            r   r   "print_exception.<locals>.print_exc   s    C//E$!6d5k5*=*=> 28=?!**k%d7mW.C.CD 28=?&&r*C6UC2Gc+  51!#B/D$BU+ r!   )r   
checkcacheflush_stdoutr#   r$   rZ   	last_type
last_valuelast_tracebacklast_excset)r   r   valrf   excinfor   r   r   s        @@@r   r[   r[      sd    NJJE \\^+LCb8?5CM3>3#5CL5D,2 cr!   c                 V   U SS nU (       a4  U H!  nU S   S   R                  U5      (       d  M!    O   OU S	 U (       a  M4  U (       a4  U H!  nU S   S   R                  U5      (       d  M!    O   OU S	 U (       a  M4  [        U 5      S:X  a   USS U SS& [        S[        R                  S9  [
        R                  S   R                  n[        [        U 5      5       HJ  nX   u  pgpUS:X  a  SnU	(       d+  UR                  S	5      (       a  UR                  S
SXg40 5      n	XgX4X'   ML     g)zARemove excluded traces from beginning/end of tb; get cached linesNr   r9   z** IDLE Internal Exception: r:   exec?z
-toplevel-z	<pyshell#r   r   )countrE   rH   r#   r$   r   objecttable
rpchandlerrj   
startswith
remotecall)
rf   r   orig_tbrpcfiler   rr   fnlnnmr   s
             r   r   r     s    eG
G!uQx~~g&&  qE " G"vayw''  rF " 2w!|
1,3::>(33J3r7^59Bk22((i/1h<D  r!   c                      g)zXXX How to do this now?Nr1   r1   r!   r   r   r   7  s    r!   c                      [         (       a  SSKn U R                  5         [        S5        [        R
                  " S5        g)zExit subprocess, possibly after first clearing exit functions.

If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
functions registered with atexit will be removed before exiting.
(VPython support)

r   NF)rD   atexit_clearr.   r#   rP   )r   s    r   rP   rP   :  s(     {UHHQKr!   c                 *   SSK n[        U R                  R                  SS5      5      nUS:  ad  UR                  R                  U 5       HD  nUR                  R                  XSS9n[        US   5      nUS:  d  M3  [        S	U-  5      US'   MF     gg)
zScale fonts on HiDPI displays.r   Ntkscalinggffffff?T)r   r>   existssizeg      )	tkinter.fontfloatr   callr   namesFontrG   round)r   rz   r   r>   r   r   s         r   r}   r}   I  s    DGGLLy12G}LL&&t,D<<$$$$$GDtF|$Dax$U4Z0V	 - r!   c                     U R                   b  U R                   S-   OSnU[        R                  " [        R                  " U5      5      -   U l         g )Nz

r;   )__doc__textwrapfilldedent)funtexttems      r   fixdocr   U  s9    $'KK$;3;;Chood&;<<CKr!      c                    ^ ^ [         R                  " [        R                  5      U4S j5       m[	        TS[
         S35        [         R                  " [        R                  5      U 4S j5       m [	        T S[
         S[
         S35        [        R                  " [        R                  " 5       [
        -   5        T[        l        T [        l        g)	z9Install wrappers to always add 30 to the recursion limit.c                     > U(       a  [        S5      e U u  nUS:  d  [        S5      eTR                  U[        -   5      $ ! [         a    [        S[        U 5       S35      ef = f)Nz.setrecursionlimit() takes no keyword argumentsz0setrecursionlimit() takes exactly one argument (z given)r   z/recursion limit must be greater or equal than 1)	TypeError
ValueErrorrE   __wrapped__RECURSIONLIMIT_DELTA)r?   rb   limitsetrecursionlimits      r   r   :install_recursionlimit_wrappers.<locals>.setrecursionlimit_  s     @B B	=FE qyAC C !,,U5I-IJJ  	= )),T7< = =	=s   A #A%z#            This IDLE wrapper adds z7 to prevent possible
            uninterruptible loops.c                  2   > T R                  5       [        -
  $ r0   )r   r   )getrecursionlimits   r   r   :install_recursionlimit_wrappers.<locals>.getrecursionlimitt  s     ,,.1EEEr!   z(            This IDLE wrapper subtracts z# to compensate
            for the z" IDLE adds when setting the limit.N)	functoolswrapsr#   r   r   r   r   )r   r   s   @@r   install_recursionlimit_wrappersr   [  s     __S**+K ,K   #$$8#9 :#& ' __S**+F ,F  #))=(> ?)**LP Q
 #//14HHI-C-Cr!   c                  t   [        [        R                  SS5      (       a  [        [        R                  SS5      (       aw  [        R                  R                  [        l        [        R                  R                  [        l        [        R                  " [        R                  " 5       [
        -
  5        ggg)zUninstall the recursion limit wrappers from the sys module.

IDLE only uses this for tests. Users can import run and call
this to remove the wrapping.
r   N)getattrr#   r   r   r   r   r1   r!   r   !uninstall_recursionlimit_wrappersr     s     C))=$??C))=$?? # 5 5 A A # 5 5 A Ac3358LLM	 @ @r!   c                       \ rS rSrS rSrg)rm   i  c                     e ! [          a    e [         a    Sq[        R                  " 5          g  [
        R                  n[        [        R                  " SS S[        R                  " 5       R                   SU SU< S3	5      US9  [        R                  " SUS	9  [        [        R                  " S
S 35      US9  Sq[        R                  " 5          g= f)zbOverride RPCServer method for IDLE

Interrupt the MainThread and exit server if link is dropped.

Tz
            z(----------------------------------------zU
            Unhandled exception in user code execution server!'
            Thread: z"
            IDLE Client Address: z
            Request: r:   i)r   r'   a  
            *** Unrecoverable, server exiting!

            Users should never see this message; it is likely transient.
            If this recurs, report this with a copy of the message
            and an explanation of how to make it repeat.
            N)rY   EOFErrorrO   threadinterrupt_mainr#   rI   rH   r   r   rJ   current_threadr>   r\   r   rX   )selfr_   client_addresserfs       r   handle_errorMyRPCServer.handle_error  s    	$ 	 	$H!!#	$..C(// 'H --/445 6""0!1 2[ !#   c4(// ' H#   #$ H!!#s    +CB'Cr1   N)r   
__module____qualname____firstlineno__r   __static_attributes__r1   r!   r   rm   rm     s    !$r!   rm   c                   T    \ rS rSrS	S jr\S 5       r\S 5       r\S 5       rS r	Sr
g)
	StdioFilei  c                 Z    Xl         SS0U R                   l        X l        X0l        X@l        g )Nwidthr8   )shell_RPCProxy__attributestags	_encoding_errors)r   r   r   encodingerrorss        r   __init__StdioFile.__init__  s(    
 -4Q<

(	!r!   c                     U R                   $ r0   )r   r   s    r   r   StdioFile.encoding  s    ~~r!   c                     U R                   $ r0   )r   r  s    r   r  StdioFile.errors  s    ||r!   c                      SU R                   -  $ )Nz<%s>)r   r  s    r   r>   StdioFile.name  s    		!!r!   c                     gNTr1   r  s    r   isattyStdioFile.isatty      r!   )r   r   r   r   N)zutf-8strict)r   r   r   r   r  propertyr   r  r>   r  r   r1   r!   r   r   r     sH         " "r!   r   c                        \ rS rSrS rS rSrg)StdOutputFilei  c                     gr  r1   r  s    r   writableStdOutputFile.writable  r  r!   c                     U R                   (       a  [        S5      e[        R                  XR                  U R
                  5      R                  U R                  U R
                  5      nU R                  R                  XR                  5      $ )Nzwrite to closed file)
closedr   strencoder   r  decoder   r%   r   )r   r   s     r   r%   StdOutputFile.write  s[    ;;344JJq--5<<T]]DKKXzz99--r!   r1   N)r   r   r   r   r  r%   r   r1   r!   r   r  r    s    .r!   r  c                   8    \ rS rSrSrS rS	S jrS	S jrS rSr	g)
StdInputFilei  r;   c                     gr  r1   r  s    r   readableStdInputFile.readable  r  r!   c                 $   U R                   (       a  [        S5      eUc  SnO6[        U[        5      (       d!  [	        S[        U5      R                  -   5      eU R                  nSU l        US:  aJ  U R                  R                  5       =n(       a'  X#-  nU R                  R                  5       =n(       a  M'  U$ [        U5      U:  a7  U R                  R                  5       nU(       d  OX#-  n[        U5      U:  a  M7  X!S  U l        US U nU$ )Nread from closed filer9   must be int, not r;   r   )r  r   
isinstancerG   r   rd   r   _line_bufferr   readlinerE   )r   r   resultr   s       r   readStdInputFile.read  s    ;;455<DD#&&/$t*2E2EEFF""!8**--//$/ **--//$/  f+$zz**,U f+$ !'uDET]Fr!   c                    U R                   (       a  [        S5      eUc  SnO6[        U[        5      (       d!  [	        S[        U5      R                  -   5      eU R                  =(       d    U R                  R                  5       nUS:  a  [        U5      nUR                  SSU5      nUS:  a  US-   nX!S  U l        US U $ )Nr#  r9   r$  r   r   r8   )r  r   r%  rG   r   rd   r   r&  r   r'  rE   find)r   r   r   eols       r   r'  StdInputFile.readline  s    ;;455<DD#&&/$t*2E2EEFF  9DJJ$7$7$9!8t9Diia&!87D KET{r!   c                 8    U R                   R                  5         g r0   )r   closer  s    r   r0  StdInputFile.close  s    

r!   )r&  N)r9   )
r   r   r   r   r&  r   r)  r'  r0  r   r1   r!   r   r  r    s    L* r!   r  c                   ,    \ rS rSrS rS rS rS rSrg)rn   i  c                    [        U 5      nU R                  SU5        U R                  S5      U l        [	        U R                  S[
        R                  [
        R                  5      [        l	        [        U R                  S[
        R                  [
        R                  5      [        l        [        U R                  S[
        R                  S5      [        l        [        R                  [        l        SSKnUR                   Ul        [        R                  U l        ['        5         U R                  S	5      U l        [        R*                  R-                  U SS
S9  g)zOverride base methodr   consolestdinstdoutr$   backslashreplacer   NinterprA   )myseqwait)	Executiveregisterget_remote_proxyr4  r  r   r   r  r#   r5  r  r6  r$   r   displayhookpydoc
plainpagerpager_keep_stdinr   r8  
RPCHandlergetresponse)r   	executiver?  s      r   handleMyHandler.handle  s    dO	fi(,,Y7 w!'&--A	"4<<#)??FMMC
"4<<#)??4FH
 //&& 99')++H5""4t$"?r!   c                 0    [         R                  " S5        g)z>override SocketIO method - wait for MainThread to shut us down
   N)rk   rl   r  s    r   exithookMyHandler.exithook,  s    

2r!   c                 2    Sq [        R                  " 5         g)zEOverride SocketIO method - terminate wait on callback and exit threadTNrX   r   r   r  s    r   EOFhookMyHandler.EOFhook0       r!   c                 2    Sq [        R                  " 5         g)zinterrupt awakened threadTNrM  r  s    r   decode_interrupthookMyHandler.decode_interrupthook6  rP  r!   )rB  r4  r8  N)	r   r   r   r   rF  rJ  rN  rR  r   r1   r!   r   rn   rn     s    @4  r!   rn   c                   H    \ rS rSrS rS rS rS rS rS r	S r
SS
 jrSrg	)r;  i=  c                     Xl         [        R                  SL aJ  [        R                  U l        [        R                  " 5       U l        [        R                  " 5       U l        g 0 U l        g )NF)
r   idlelibtesting__main____dict__localsr   Calltipr   AutoComplete)r   r   s     r   r  Executive.__init__?  sF    $??e#"++DK"??,DL , 9 9 ;DDKr!   c                 h    S U l         Sq [        XR                  5        Sq [	        5         g ! Sqf = f! [
         ax  nUR                  (       a]  UR                  S   n[        U[        S 5      [        45      (       d)  [        S[        U5      -   [        R                  S9   S nAg  S nAg  S nAg S nAf  [        R                  " 5       U l         [        (       a
  [!        5         [        R"                  [        R$                  L a  ['        5         OJ [        R"                  " U R                   6   O+!   [        R                  " 5       U l         ['        5          O= fU R(                  R*                  R-                  S5      nU(       a&  U R(                  R.                  R1                  5          g  g = f)NTFr   zSystemExit: r:   z<<toggle-jit-stack-viewer>>)user_exc_infointerruptibler   rZ  r   rY   r?   r%  rd   rG   rH   r  r#   r$   rZ   rX   rP   
excepthookr   r[   r   r4  getvarr8  open_remote_stack_viewer)r   codeeobjits        r   runcodeExecutive.runcodeH  s1   	!%D M&T;;' %. N/ !& 	EvvVVAY!"tDz3&788.3r72D 9 
	B!$Dx~~!3!33!&NND$6$67&),D&#%//))001NOC&&??A s@   	6 / 6 36 
F1 A$B33A F1D21F12&EAF1c                 F    [         (       a  [        R                  " 5         g g r0   )r`  r   r   r  s    r   interrupt_the_serverExecutive.interrupt_the_serveri  s    =!!# r!   c                 D    [         R                  " U R                  U5      $ r0   )r   start_debuggerr   )r   gui_adap_oids     r   start_the_debuggerExecutive.start_the_debuggerm  s    ((,GGr!   c                 :    U R                   R                  U5        g)zDUnregister the Idb Adapter.  Link objects and Idb then subject to GCN)r   
unregister)r   idb_adap_oids     r   stop_the_debuggerExecutive.stop_the_debuggerp  s    ""<0r!   c                 8    U R                   R                  U5      $ r0   )r   	fetch_tip)r   r>   s     r   get_the_calltipExecutive.get_the_calltipt  s    ||%%d++r!   c                 8    U R                   R                  X5      $ r0   )r   fetch_completions)r   whatmodes      r   get_the_completion_list!Executive.get_the_completion_listw  s      224>>r!   Nc                    U R                   (       a  U R                   u  p#nOg S nUb  U R                  R                  U5      nU(       aO  UR                  R                  S   S;   a2  UR
                  nU(       a  UR                  R                  S   S;   a  M2  XCl        [        R                  " X55      n[        R                  " U5      $ )Nr   )r   run)r_  r   r=  tb_frame	f_globalstb_nextr   r	   StackTreeItemr   remote_object_tree_item)r   	flist_oid_r   rf   flistitems          r   r	   Executive.stackviewerz  s    ++JAB OO44Y?ER[[**:6.HB R[[**:6.H((411$77r!   )r   r   rZ  r   r_  r0   )r   r   r   r   r  rh  rk  rp  ru  ry  r  r	   r   r1   r!   r   r;  r;  =  s,    B$H1,?8r!   r;  rX  )rg   zidlelib.idle_test.test_run   )	verbosityr0   )NN)F)Dr   r   r   r   r   rT   r#   r   rk   r\   _threadr   rJ   r+   rV  r   r   r   r   r   r   r	   rX  rz   hasattrmodulesmoddelattrr
   rM   eofrP   quitr   r    r(   r*   r.   rW  r2   Tclr6   rO   rX   r`  rg   rL   ro   r   r[   r   r   r}   r   r   r   r   	RPCServerrm   
TextIOBaser   r  r  rC  rn   r;  r   unittestr1   r!   r   <module>r     s     	   
                 s{{=):66 	KK
S()	 +0CKK'		
 CDHDH
 >B  )  
?? ++-C   L\&"	9#J!>"	1=  %.PN#$#-- #$P 6	.I 	.,9 ,^*  * ZI8 I8X z	%3  }  		s   =F: :GG