o =?hT@szdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddlZddlmZddlmZddlmZddlmZddlmZddlmZdd lmZddlZddlZeejd d sd D] Zeeeejd e=qrdejd _dZz dZee_ee _Wn e!yYnwdDddZ" dEddZ#da$ddZ%e%de&Z'e'fddZ(da)da*da+dFddZ,ddZ-ddZ.d d!Z/d"d#Z0d$d%Z1d&d'Z2d(d)Zd*d+Z3d,d-Z4d.Z5d/d0Z6d1d2Z7Gd3d4d4ej8Z9Gd5d6d6ej:Z;Gd7d8d8e;ZZ?Gd=d>d>Z@eAd?kr7dd@lBm,Z,e,dAdBdCe%ddS)Gz idlelib.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.runfirstrun)Z simpledialogZ messageboxfontZdialogZ filedialogZ commondialogZttkztkinter.Fz 127.0.0.1zCtrl-D (end-of-file)cCsVd}|d||f7}|durt||}|}|r |d|7}|d|j|f7}|S)zFormat warnings the IDLE way.z! Warning (from warnings module): z File "%s", line %s Nz %s z%s: %s ) linecachegetlinestrip__name__)messagecategoryfilenamelinenolinesr2/opt/alt/python310/lib64/python3.10/idlelib/run.pyidle_formatwarning3s  rcCs@|durtj}z|t|||||WdStyYdSw)zuShow Idle-format warning after replacing warnings.showwarning. The only difference is the formatter called. N)sysstderrwriterOSError)rrrrfilerrrridle_showwarning_subproc@s  rcCs:|rtdurtjatt_dSdStdurtt_dadSdS)zFReplace warning.showwarning with idle_showwarning_subproc, or reverse.N)_warnings_showwarningwarnings showwarningr)Zcapturerrrcapture_warningsPs r!TcCs|ddS)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)tclrrrhandle_tk_events`sr%c Cs|azttjdks Jttjd}Wn tdtjdYdStddgtjdd<tj t dt |ffd }d|_ |  zGtrTztWn tySYWq@wz tjjdd d }Wn tjyjd}Ynw|r|\}\}}}||i|}tj||fntWnDtytrdaYq@tytd t\} } } z ttj|dfWntj| | | tjdtYnYq@YqA) afStart 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.rNTZ SockThread)targetnameargs皙?)blockZtimeoutF) no_exitfunclenrargvintprint __stderr__r! threadingZThread manage_socket LOCALHOSTZdaemonstartexit_nowexitKeyboardInterruptrZ request_queuegetqueueZEmptyZresponse_queueZputr%quitting SystemExitexc_infoprint_exception traceback) Z del_exitfuncZportZ sockthreadrequestseqmethodr,kwargsZrettypevaluetbrrrmainnsl     rJc CstdD]1}t|zt|t}Wn2ty5}ztd|jddtj d|}WYd}~qd}~wwtdtj dt ||da dS| dS)NzIDLE Subprocess: OSError: r&z, retrying....r(z8IDLE Subprocess: Connection to IDLE GUI failed, exiting.T) rangetimesleep MyRPCServer MyHandlerrr3r,rr4show_socket_errorr9Zhandle_request)addressiZservererrZ socket_errorrrrr6s*     r6c Cslddl}ddlm}|}t|||dd|dd|dd|jd |jd |d |dS) z(Display socket error from manage_socket.rN) showerrorzSubprocess Connection Errorz#IDLE's subprocess can't connect to :r&z. Fatal OSError #z: zz. See the 'Startup failure' section of the IDLE doc, online at https://docs.python.org/3/library/idle.html#startup-failure)parent) tkinterZtkinter.messageboxrUZTk fix_scalingZwithdrawerrnostrerrorZdestroy)rTrRrXrUrootrrrrQs  rQcCsp|ttfvr2t}t|t|||Wdn1s!wY| dddgSt ||S)z,Return line composing the exception message.N ) AttributeError NameErrorioStringIO contextlibredirect_stderrr__excepthook__getvaluesplitrBformat_exception_only)typexcrIrTrrrget_message_liness   rkcsdddl}|ttjt\}}}}|\t_t_t_t fdd|||dS)Nrc st||j}|j}|dur't|vr't|||jtddn|durC|jsCt|vrCt|||jtdd|r^t |}tddd}t ||tj |dt |||}|D] }t|ddqfdS)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):)zrun.pyzrpc.pyz threading.pyzqueue.pyz debugger_r.pyzbdb.pyr))endr) addid __context__ __cause__rG __traceback__r3__suppress_context__rB extract_tbcleanup_traceback print_listrk) rirjrIcontextcauseZtbeexcludelinesrZefile print_excseenrrr{s4     z"print_exception..print_exc) r checkcache flush_stdoutrrr@ last_type last_valuelast_tracebackset)r rivalrIexcinforrzrrAsrAc Cs |dd}|r|D] }|dd|rnq n|d=|s|r6|D] }|dd|r/nq"n|d=|s t|dkrM|dd|dd<tdtjdtjdj}tt|D])}||\}}}} |dkrid}| sz| d rz| d d ||fi} |||| f||<qYdS) zARemove excluded traces from beginning/end of tb; get cached linesNrr'z** IDLE Internal Exception: r(exec?z -toplevel-z   rtcCdS)zXXX How to do this now?Nrrrrrr~.sr~cCs*tr ddl}|tdtddS)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) rNF)r/atexitZ_clearr!rr:)rrrrr:1s r:cCsrddl}t|jdd}|dkr5|j|D]}|jj||dd}t|d}|dkr4td ||d<qdSdS) zScale fonts on HiDPI displays.rNtkscalinggffffff?T)r\r+existssizeg) Z tkinter.fontfloatrZcallr namesZFontr2round)r\rXrr+r rrrrrY@s rYcCs2|jdur |jdnd}|tt||_dS)Nz r))__doc__textwrapZfilldedent)ZfuntextZtemrrrfixdocLsrcs|ttjfddtdtdttjfddtdtdtd tttt_t_d S) z9Install wrappers to always add 30 to the recursion limit.csX|rtdz|\}Wntytdt|dw|dks%td|tS)Nz.setrecursionlimit() takes no keyword argumentsz0setrecursionlimit() takes exactly one argument (z given)rz/recursion limit must be greater or equal than 1) TypeError ValueErrorr0 __wrapped__RECURSIONLIMIT_DELTA)r,rFlimit)setrecursionlimitrrrVs    z:install_recursionlimit_wrappers..setrecursionlimitz# This IDLE wrapper adds z7 to prevent possible uninterruptible loops.cs tSN)rrr)getrecursionlimitrrrks z:install_recursionlimit_wrappers..getrecursionlimitz( This IDLE wrapper subtracts z# to compensate for the z" IDLE adds when setting the limit.N) functoolswrapsrrrrrrr)rrrinstall_recursionlimit_wrappersRs    rcCsNttjddr#ttjddr%tjjt_tjjt_tttdSdSdS)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. rN)getattrrrrrrrrrr!uninstall_recursionlimit_wrapperszs    rc@seZdZddZdS)rOcCszty tydatYd Stj}tt dddt j d|d|d |dt jd|d tt d d|ddatYd S) zrOverride 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)rra *** 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)r?EOFErrorr9threadinterrupt_mainrr4r3rrr5Zcurrent_threadr+rBr{r>)selfrCZclient_addressZerfrrr handle_errors8  zMyRPCServer.handle_errorN)r __module__ __qualname__rrrrrrOs rOc@sBeZdZdddZeddZeddZed d Zd d Zd S) StdioFileutf-8strictcCs||_||_||_||_dSr)shelltags _encoding_errors)rrrencodingerrorsrrr__init__s zStdioFile.__init__cC|jSr)rrrrrrzStdioFile.encodingcCrr)rrrrrrrzStdioFile.errorscCs d|jS)Nz<%s>)rrrrrr+s zStdioFile.namecCrNTrrrrrisattyzStdioFile.isattyN)rr) rrrrpropertyrrr+rrrrrrs     rc@seZdZddZddZdS) StdOutputFilecCrrrrrrrwritablerzStdOutputFile.writablecCs<|jrtdt||j|j|j|j}|j||j S)Nzwrite to closed file) closedrstrencoderrdecoderrr)rrrrrrszStdOutputFile.writeN)rrrrrrrrrrs rc@s4eZdZdZddZd ddZd ddZd d Zd S) StdInputFiler)cCrrrrrrrreadablerzStdInputFile.readabler'cCs|jrtd|durd}nt|tstdt|j|j}d|_|dkr:|j }r8||7}|j }s-|St ||krR|j }|sHn ||7}t ||ks@||d|_|d|}|S)Nread from closed filer'must be int, not r)r) rr isinstancer2rrGr _line_bufferrreadliner0)rrresultrrrrreads*    zStdInputFile.readcCs|jrtd|durd}nt|tstdt|j|jp#|j }|dkr,t |}| dd|}|dkr;|d}||d|_|d|S)Nrr'rrr]r&) rrrr2rrGrrrrr0find)rrrZeolrrrrs  zStdInputFile.readlinecCs|jdSr)rcloserrrrrzStdInputFile.closeN)r')rrrrrrrrrrrrrs    rc@s,eZdZddZddZddZddZd S) rPcCst|}|d||d|_t|jdtjtjt_ t |jdtjtjt_ t |jdtjdt_ t jt_ddl}|j|_tj |_t|d |_t jj|dd d dS) zOverride base methodrconsolestdinstdoutrbackslashreplacerNinterpr-)Zmyseqwait) Executiveregisterget_remote_proxyrrrrrrrrrrr displayhookpydocZ plainpagerZpagerZ _keep_stdinrr RPCHandlerZ getresponse)rZ executiverrrrhandles&   zMyHandler.handlecCstddS)z>override SocketIO method - wait for MainThread to shut us down N)rMrNrrrrexithook szMyHandler.exithookcCdatdS)zEOverride SocketIO method - terminate wait on callback and exit threadTNr>rrrrrrEOFhook$ zMyHandler.EOFhookcCr)zinterrupt awakened threadTNrrrrrdecode_interrupthook*rzMyHandler.decode_interrupthookN)rrrrrrrrrrrrPs  rPc@sNeZdZddZddZddZddZd d Zd d Zd dZ dddZ dS)rcCs:||_tjdurtj|_t|_t |_dSi|_dS)NF) ridlelibZtesting__main____dict__localsrZCalltiprZ AutoComplete)rrrrrr3s    zExecutive.__init__c Cs0zd|_daz t||jWdandawWn}tyR}z1|jr@|jd}t|tdtfsGt dt |t j dWYd}~dSWYd}~dSWYd}~dSd}~wt |_tr_tt jt juritnzt j|jWn t |_tY|jjd}|r|jjYdSYdStdS)NTFrz SystemExit: r(z<>) user_exc_info interruptablerrr?r,rrGr2r3rrrr@r>r: excepthookrerArrZgetvarrZopen_remote_stack_viewerr~)rcodeeZobZjitrrrruncode<s< $    zExecutive.runcodecCstrtdSdSr)rrrrrrrinterrupt_the_server]s zExecutive.interrupt_the_servercCst|j|Sr)rZstart_debuggerr)rZ gui_adap_oidrrrstart_the_debuggerarzExecutive.start_the_debuggercCs|j|dS)zDUnregister the Idb Adapter. Link objects and Idb then subject to GCN)r unregister)rZ idb_adap_oidrrrstop_the_debuggerdszExecutive.stop_the_debuggercCs |j|Sr)rZ fetch_tip)rr+rrrget_the_calltiphs zExecutive.get_the_calltipcCs|j||Sr)rZfetch_completions)rZwhatmoderrrget_the_completion_listkrz!Executive.get_the_completion_listNcCs|jr |j\}}}ndSd}|dur|j|}|r/|jjddvr/|j}|r/|jjddvs"|t_|t_t ||}t |S)Nr)rrun) rrrtb_frame f_globalstb_nextrrrrZ StackTreeItemrZremote_object_tree_item)rZ flist_oidrirrIZflistitemrrrrns   zExecutive.stackviewerr) rrrrrrrrrrrrrrrr1s !rr)rJzidlelib.idle_test.test_run) verbosityr)NN)F)Crrcrrar r=rrrMrB_threadrr5rrrrrrrrrrrXhasattrmodulesmoddelattrr r7eofr:quitr`rrrr!ZTclr$r%r9r>rrJr6rQrkrArtr~rYrrrrZ RPCServerrO TextIOBaserrrrrPrrZunittestrrrrs                 M $ (( /- M