a XC?h6R@sldZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl mZddl mZddl mZddl mZddl mZddl mZdd l mZddlZddlZeejd d sd D]Zeeeejd e=qdejd _dZzdZee_ee_Wne y2Yn0dBddZ!dCddZ"da#ddZ$e$de%Z&e&fddZ'da(da)da*dDddZ+ddZ,ddZ-d d!Z.d"d#Z/d$d%Z0d&d'Zd(d)Z1d*d+Z2d,Z3d-d.Z4d/d0Z5Gd1d2d2ej6Z7Gd3d4d4ej8Z9Gd5d6d6e9Z:Gd7d8d8e9Z;Gd9d:d:ej<Z=Gd;d<d<Z>e?d=kr`dd>l@m+Z+e+d?d@dAe$ddS)Ez 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}|dur(t||}|}|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__)messagecategoryfilenamelinenolinesr0/opt/alt/python39/lib64/python3.9/idlelib/run.pyidle_formatwarning2s  rcCs@|durtj}z|t|||||Wnty:Yn0dS)zuShow Idle-format warning after replacing warnings.showwarning. The only difference is the formatter called. N)sysstderrwriterOSError)rrrrfilerrrridle_showwarning_subproc?s  rcCs0|rtdur,tjatt_ntdur,tt_dadS)zFReplace warning.showwarning with idle_showwarning_subproc, or reverse.N)_warnings_showwarningwarnings showwarningr)Zcapturerrrcapture_warningsOsr!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|az$ttjdksJttjd}WntdtjdYdS0tddgtjdd<tj t dt |ffd }d|_ | ztrz tWntyYWqYn0ztjjdd d }Wntjyd}Yn0|r|\}\}}}||i|}tj||fntWqty8tr0daYqYqtyTtd Yqt\} } } zttj|dfWn&tj| | | tjdtYn0YqYq0qdS) 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,kwargsZrettypevaluetbrrrmainms`      rJc CstdD]h}t|zt|t}WqWqtyn}z,td|jddtj d|}WYd}~qd}~00qtdtj 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 rQcsdddl}|ttjt\}}}}|\t_t_t_t fdd|||dS)Nrc st||j}|j}|durNt|vrNt|||jtddn8|dur|jst|vrt|||jtdd|rt |}tddd}t ||tj |dt ||}|D]}t|ddqdS)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_listformat_exception_only) typexcrIcontextcauseZtbeexcludelinesrZefile print_excseenrrros4     z"print_exception..print_exc) r checkcache flush_stdoutrrr@ last_type last_valuelast_tracebackset)r rhvalrIexcinforrnrrAsrAc Cs|dd}|r:|D]}|dd|rq2qq:|d=q |rh|D]}|dd|rBq`qBqh|d=q:t|dkr|dd|dd<tdtjdtjdj}tt|D]R}||\}}}} |dkrd}| s| d r| d d ||fi} |||| f||<qdS) zARemove excluded traces from beginning/end of tb; get cached linesNrr'z** IDLE Internal Exception: r(exec?z -toplevel-z srcs|ttjfddtdtdttjfddtdtdtd tttt_t_d S) z9Install wrappers to always add 30 to the recursion limit.cs\|r tdz |\}Wn&ty<tdt|dYn0|dksNtd|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)setrecursionlimitrrrHs  z:install_recursionlimit_wrappers..setrecursionlimitz# This IDLE wrapper adds z7 to prevent possible uninterruptible loops.cs tSN)rrr)getrecursionlimitrrr]sz:install_recursionlimit_wrappers..getrecursionlimitz( This IDLE wrapper subtracts z# to compensate for the z" IDLE adds when setting the limit.N) functoolswrapsrrrrrrr)rrrinstall_recursionlimit_wrappersDs    rcCsFttjddrBttjddrBtjjt_tjjt_tttdS)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_wrappersls    rc@seZdZddZdS)rOcCszWntyYnty6datYnvtj}tt dddt j d|d|d |dt jd|d tt d d|ddatYn0d 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+rBror>)selfrCZclient_addressZerfrrr handle_error}s8   zMyRPCServer.handle_errorN)r __module__ __qualname__rrrrrrO{srOc@sBeZdZdddZeddZeddZed d Zd d Zd S) StdioFileutf-8strictcCs||_||_||_||_dSr)shelltags _encoding_errors)rrrencodingerrorsrrr__init__szStdioFile.__init__cCs|jSr)rrrrrrszStdioFile.encodingcCs|jSr)rrrrrrszStdioFile.errorscCs d|jS)Nz<%s>)rrrrrr+szStdioFile.namecCsdSNTrrrrrisattyszStdioFile.isattyN)rr) rrrrpropertyrrr+rrrrrrs    rc@seZdZddZddZdS) StdOutputFilecCsdSrrrrrrwritableszStdOutputFile.writablecCs<|jrtdt||j|j|j|j}|j||j S)Nzwrite to closed file) closedrstrencoderrdecoderrr)rrrrrrszStdOutputFile.writeN)rrrrrrrrrrsrc@s4eZdZdZddZd ddZd ddZd d Zd S) StdInputFiler)cCsdSrrrrrrreadableszStdInputFile.readabler'cCs|jrtd|durd}nt|ts8tdt|j|j}d|_|dkrf|j }r||7}qLn@t ||kr|j }|sq||7}qf||d|_|d|}|S)Nread from closed filer'must be int, not r)r) rr isinstancer2rrGr _line_bufferrreadliner0)rrresultrrrrreads$      zStdInputFile.readcCs|jrtd|durd}nt|ts8tdt|j|jpF|j }|dkrXt |}| dd|}|dkrv|d}||d|_|d|S)Nrr'rr r&) rrrr2rrGrrrrr0find)rrrZeolrrrrs zStdInputFile.readlinecCs|jdSr)rcloserrrrrszStdInputFile.closeN)r')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 methodryconsolestdinstdoutrbackslashreplacerNinterpr-)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)rMrNrrrrexithookszMyHandler.exithookcCsdatdS)zEOverride SocketIO method - terminate wait on callback and exit threadTNr>rrrrrrEOFhookszMyHandler.EOFhookcCsdatdS)zinterrupt awakened threadTNrrrrrdecode_interrupthookszMyHandler.decode_interrupthookN)rrrrrrrrrrrrPsrPc@sNeZdZddZddZddZddZd d Zd d Zd dZ dddZ dS)rcCs8||_tjdur.tj|_t|_t |_ni|_dS)NF) r|idlelibZtesting__main____dict__localsrZCalltiprZ AutoComplete)rr|rrrr%s    zExecutive.__init__c Csz*d|_dazt||jWdanda0Wnty}zD|jrr|jd}t|tdtfsrt dt |t j dWYd}~nd}~0t |_trtt jt jurtn.zt j|jWnt |_tYn0|jjd}|r|jjYn0tdS)NTFrz SystemExit: r(z<>) user_exc_info interruptableryrr?r,rrGr2r3rrrr@r>r: excepthook__excepthook__rAr|rZgetvarrZopen_remote_stack_viewerrr)rcodeeZobZjitrrrruncode.s4 *    zExecutive.runcodecCstr tdSr)rrrrrrrinterrupt_the_serverOszExecutive.interrupt_the_servercCst|j|Sr)rZstart_debuggerr|)rZ gui_adap_oidrrrstart_the_debuggerSszExecutive.start_the_debuggercCs|j|dS)zDUnregister the Idb Adapter. Link objects and Idb then subject to GCN)r|Z unregister)rZ idb_adap_oidrrrstop_the_debuggerVszExecutive.stop_the_debuggercCs |j|Sr)rZ fetch_tip)rr+rrrget_the_calltipZszExecutive.get_the_calltipcCs|j||Sr)rZfetch_completions)rZwhatmoderrrget_the_completion_list]sz!Executive.get_the_completion_listNcCsn|jr|j\}}}ndSd}|dur0|j|}|rL|jjddvrL|j}q0|t_|t_t ||}t |S)Nr)rrun) rr|rtb_frame f_globalstb_nextrrsrtrZ StackTreeItemrZremote_object_tree_item)rZ flist_oidrhrwrIZflistitemrrrr`s  zExecutive.stackviewer)N) rrrrrrrrrrrrrrrr#s !rr)rJzidlelib.idle_test.test_run) verbosity)N)NN)F)Arrior r=rrrMrB_threadrr5rrrrrrrrrrrXhasattrmodulesmoddelattrr r7eofr:quit NameErrorrrrr!ZTclr$r%r9r>rrJr6rQrArerrrYrrrrZ RPCServerrO TextIOBaserrrrrPrrZunittestrrrrs               M$ (( /-M