B N8c?X@s@dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl mZddl mZddl mZddl mZddl mZddl mZdd l mZddlZddlZeejd d sx"d D]Zeeeejd e=qWdejd _dZdAddZdBddZdaddZ e de!Z"e"fddZ#da$da%da&dCddZ'ddZ(ddZ)dd Z*d!d"Z+d#d$Z,d%d&Z-d'd(Z.d)d*Z/d+Z0d,d-Z1d.d/Z2Gd0d1d1ej3Z4Gd2d3d3ej5Z6Gd4d5d5e6Z7Gd6d7d7e6Z8Gd8d9d9ej9Z:Gd:d;d;e;Zm'Z'e'd>d?d@e ddS)Dz 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.1cCsVd}|d||f7}|dkr(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/python37/lib64/python3.7/idlelib/run.pyidle_formatwarning*s  rcCsB|dkrtj}y|t|||||Wntk r<YnXdS)zuShow Idle-format warning after replacing warnings.showwarning. The only difference is the formatter called. N)sysstderrwriterOSError)rrrrfilerrrridle_showwarning_subproc7srcCs0|rtdkr,tjatt_ntdk r,tt_dadS)zFReplace warning.showwarning with idle_showwarning_subproc, or reverse.N)_warnings_showwarningwarnings showwarningr)Zcapturerrrcapture_warningsGsr!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_eventsWsr%c Cs|ay$ttjdkstttjd}WntdtjddStddgtjdd<t j t dt |ffd }d|_ |x2ytry tWntk rwYnXytjjdd d }Wntjk rd}YnX|r |\}\}}}|||}tj||fntWqtk r4tr.dawYqtk rRtd Yqt\} } } yttj|dfWn&tj| | | tjdtYnXwYqXqWdS) 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)targetnameargsg?)blockZtimeoutF) no_exitfunclenrargvAssertionErrorintprint __stderr__r! threadingZThread manage_socket LOCALHOSTZdaemonstartexit_nowexitKeyboardInterruptrZ request_queuegetqueueZEmptyZresponse_queueZputr%quitting SystemExitexc_infoprint_exception traceback) Z del_exitfuncZportZ sockthreadrequestseqmethodr+kwargsZrettypevaluetbrrrmaines^      rIc CsxtdD]b}t|yt|t}PWq tk rj}z$td|jddtj d|}Wdd}~XYq Xq Wtdtj dt ||da dS| dS)NzIDLE Subprocess: OSError: r&z, retrying....)rz8IDLE Subprocess: Connection to IDLE GUI failed, exiting.T) rangetimesleep MyRPCServer MyHandlerrr2r+rr3show_socket_errorr8Zhandle_request)addressiZservererrZ socket_errorrrrr5s    r5c 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.messageboxrTZTk fix_scalingZwithdrawerrnostrerrorZdestroy)rSrQrWrTrootrrrrPs (rPcsdddl}|ttjt\}}}}|\t_t_t_t fdd|||dS)Nrc st||j}|j}|dk rNt|krNt|||jtddn8|dk r|jst|krt|||jtdd|rt |}tddd}t ||tj |dt ||}x|D]}t|ddqWdS)NzF The above exception was the direct cause of the following exception: )rzE 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__rF __traceback__r2__suppress_context__rA extract_tbcleanup_traceback print_listformat_exception_only) typexcrHcontextcauseZtbeexcludelinesr)efile print_excseenrrrns,       z"print_exception..print_exc) r checkcache flush_stdoutrrr? last_type last_valuelast_tracebackset)r rgvalrHexcinfor)rmrnrorr@sr@c Cs|dd}x2|r>x"|D]}|dd|rPqWP|d=qWx2|rrx"|D]}|dd|rLPqLWP|d=qBWt|dkr|dd|dd<tdtjdtjdj}xbtt|D]R}||\}}}} |dkrd}| s| d r| d d ||fi} |||| f||<qWdS) zARemove excluded traces from beginning/end of tb; get cached linesNrr'z** IDLE Internal Exception: )rexec?z -toplevel-z tdt|dYnX|dksPtd|tS)Nz.setrecursionlimit() takes no keyword argumentsz0setrecursionlimit() takes exactly one argument (z given)rz/recursion limit must be greater or equal than 1) TypeError ValueErrorr. __wrapped__RECURSIONLIMIT_DELTA)r+rElimit)setrecursionlimitrrr@s z:install_recursionlimit_wrappers..setrecursionlimitz# This IDLE wrapper adds z7 to prevent possible uninterruptible loops.cs tS)N)rrr)getrecursionlimitrrrUsz:install_recursionlimit_wrappers..getrecursionlimitz( This IDLE wrapper subtracts z# to compensate for the z" IDLE adds when setting the limit.N) functoolswrapsrrrrrrr)rrrinstall_recursionlimit_wrappers<srcCsFttjddrBttjddrBtjjt_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_wrappersds   rc@seZdZddZdS)rNcCsyWntk rYntk r:datYntj}td|dtd|dtdt j |dtd||dtdt ||dt j |dtd|dtd |ddatYnXd S) zrOverride RPCServer method for IDLE Interrupt the MainThread and exit server if link is dropped. Tz) ----------------------------------------)rzUnhandled server exception!z Thread: %szClient Address: z Request: z# *** Unrecoverable, server exiting!z(----------------------------------------N)r>EOFErrorr8threadinterrupt_mainrr3r2r4Zcurrent_threadr*reprrArnr=)selfrBZclient_addressZerfrrr handle_errorus&      zMyRPCServer.handle_errorN)r __module__ __qualname__rrrrrrNssrNc@sBeZdZdddZeddZeddZed d Zd d Zd S) StdioFileutf-8strictcCs||_||_||_||_dS)N)shelltags _encoding_errors)rrrencodingerrorsrrr__init__szStdioFile.__init__cCs|jS)N)r)rrrrrszStdioFile.encodingcCs|jS)N)r)rrrrrszStdioFile.errorscCs d|jS)Nz<%s>)r)rrrrr*szStdioFile.namecCsdS)NTr)rrrrisattyszStdioFile.isattyN)rr) rrrrpropertyrrr*rrrrrrs     rc@seZdZddZddZdS) StdOutputFilecCsdS)NTr)rrrrwritableszStdOutputFile.writablecCs<|jrtdt||j|j|j|j}|j||j S)Nzwrite to closed file) closedrstrencoderrdecoderrr)rrrrrrszStdOutputFile.writeN)rrrrrrrrrrsrc@s4eZdZdZddZd ddZd ddZd d Zd S) StdInputFiler(cCsdS)NTr)rrrrreadableszStdInputFile.readabler'cCs|jrtd|dkrd}nt|ts8tdt|j|j}d|_|dkrlxb|j }|s^P||7}qNWnDx(t ||kr|j }|sP||7}qnW||d|_|d|}|S)Nzread from closed filer'zmust be int, not r(r) rr isinstancer1rrFr _line_bufferrreadliner.)rrresultrrrrreads,     zStdInputFile.readcCs|jrtd|dkrd}nt|ts8tdt|j|jpF|j }|dkrXt |}| dd|}|dkrv|d}||d|_|d|S)Nzread from closed filer'zmust be int, not r r&) rrrr1rrFrrrrr.find)rrrZeolrrrrs zStdInputFile.readlinecCs|jdS)N)rclose)rrrrrszStdInputFile.closeN)r')r')rrrrrrrrrrrrrs   rc@s,eZdZddZddZddZddZd S) rOcCst|}|d||d|_t|jdtjtjt_ t |jdtjtjt_ t |jdtjdt_ t jt_ddl}|j|_tj |_t|d |_t jj|dd d dS) zOverride base methodrxconsolestdinstdoutrbackslashreplacerNinterpg?)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)rLrM)rrrrexithookszMyHandler.exithookcCsdatdS)zEOverride SocketIO method - terminate wait on callback and exit threadTN)r=rr)rrrrEOFhook szMyHandler.EOFhookcCsdatdS)zinterrupt awakened threadTN)r=rr)rrrrdecode_interrupthookszMyHandler.decode_interrupthookN)rrrrrrrrrrrrOsrOc@sNeZdZddZddZddZddZd d Zd d Zd dZ dddZ dS)rcCs&||_tj|_t|_t|_dS)N)r{__main____dict__localsrZCalltiprZ AutoComplete)rr{rrrrs zExecutive.__init__c Csy&d|_dazt||jWddaXWntk r}z<|jrp|jd}t|tdtfspt dt |t j dWdd}~XYnJt |_trtt|jjd}|r|jjYnXtdS)NTFrz SystemExit: )rz<>) usr_exc_info interruptablerxrr>r+rrFr1r2rrrr?r=r9r@r{rZgetvarrZopen_remote_stack_viewerrq)rcodeeZobZjitrrrruncodes(  & zExecutive.runcodecCstr tdS)N)rrr)rrrrinterrupt_the_server8szExecutive.interrupt_the_servercCst|j|S)N)rZstart_debuggerr{)rZ gui_adap_oidrrrstart_the_debugger<szExecutive.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_debugger?szExecutive.stop_the_debuggercCs |j|S)N)rZ fetch_tip)rr*rrrget_the_calltipCszExecutive.get_the_calltipcCs|j||S)N)rZfetch_completions)rZwhatmoderrrget_the_completion_listFsz!Executive.get_the_completion_listNcCsr|jr|j\}}}ndSd}|dk r0|j|}x|rN|jjddkrN|j}q2W|t_|t_t ||}t |S)Nr)rrun) rr{rtb_frame f_globalstb_nextrrrrsrZ StackTreeItemrZremote_object_tree_item)rZ flist_oidrgrvrHZflistitemrrrrIs   zExecutive.stackviewer)N) rrrrrrrrrrrrrrrrsrr)rIzidlelib.idle_test.test_run) verbosity)N)NN)F)?rrior r<rrrLrA_threadrr4rZidlelibrrrrrrrrrWhasattrmodulesmoddelattrr r6rrrr!ZTclr$r%r8r=rrIr5rPr@rdrqr9rXrrrrZ RPCServerrN TextIOBaserrrrrOobjectrrZunittestrrrrst               M$ (! 1-C