3 § fxCã@sÐddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl m Z ddl mZddl mZddl mZddl mZddl mZddlZx"d8D]Zee eƒejde=q²WdZd9dd„Zd:dd„Zdadd„Zedƒe jƒZefdd„Zdada da!d;dd„Z"dd„Z#d d!„Z$d"d#„Z%d$d%„Z&d&d'„Z'd(d)„Z(d*d+„Z)Gd,d-„d-ej*ƒZ+Gd.d/„d/ej,ƒZ-Gd0d1„d1e-ƒZ.Gd2d3„d3e-ƒZ/Gd4d5„d5ej0ƒZ1Gd6d7„d7e2ƒZ3edƒdS)<éN)Ú autocomplete)Úcalltip)Ú debugger_r)Ú debugobj_r)Úiomenu)Úrpc)Ú stackviewerÚ simpledialogÚ messageboxÚfontÚdialogÚ filedialogÚ commondialogÚttkztkinter.z 127.0.0.1cCsVd}|d||f7}|dkr(tj||ƒ}|jƒ}|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 )Ú linecacheÚgetlineÚstripÚ__name__)ÚmessageÚcategoryÚfilenameÚlinenoÚlineÚs©rú0/opt/alt/python36/lib64/python3.6/idlelib/run.pyÚidle_formatwarnings  rc CsB|dkrtj}y|jt|||||ƒƒWntk r<YnXdS)zuShow Idle-format warning after replacing warnings.showwarning. The only difference is the formatter called. N)ÚsysÚstderrÚwriterÚOSError)rrrrÚfilerrrrÚidle_showwarning_subproc,sr"cCs0|rtdkr,tjatt_ntdk r,tt_dadS)zFReplace warning.showwarning with idle_showwarning_subproc, or reverse.N)Ú_warnings_showwarningÚwarningsÚ showwarningr")ZcapturerrrÚcapture_warnings<sr&TcCs|jdƒdS)z–Process 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)ÚtclrrrÚhandle_tk_eventsLsr*Fc Cs¤|ayttjd ƒ}Wntdtjd�dStdƒdgtjdd…<tjt dt |ffd�}d|_ |j ƒ�x0yŽt r˜y tƒWntk r–wpYnXytjjdd d �}Wntjk rÆd}YnX|rö|\}\}}}|||Ž}tjj||fƒntƒWqptk �r t�rda wpYqptk �r>td ƒ‚Yqptjƒ\} } } ytƒtjj|dfƒWn&tj| | | tjd�tƒYnXwpYqpXqpWdS) 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.)r!NTÚZ SockThread)ÚtargetÚnameÚargsgš™™™™™©?)ÚblockZtimeoutFéÿÿÿÿ)Ú no_exitfuncÚintrÚargvÚprintÚ __stderr__r&Ú threadingZThreadÚ manage_socketÚ LOCALHOSTZdaemonÚstartÚexit_nowÚexitÚKeyboardInterruptrZ request_queueÚgetÚqueueZEmptyZresponse_queueZputr*ÚquittingÚ SystemExitÚexc_infoÚprint_exceptionÚ traceback) Z del_exitfuncZportZ sockthreadÚrequestÚseqÚmethodr/ÚkwargsZretÚtypeÚvalueÚtbrrrÚmainZs\      rLcCsœxŽtdƒD]b}tj|ƒyt|tƒ}PWq tk rj}z&td|jddtj d�|}WYdd}~Xq Xq Wtdtj d�t ||ƒda dS|j ƒdS)NézIDLE Subprocess: OSError: r+z, retrying....)r!z8IDLE Subprocess: Connection to IDLE GUI failed, exiting.T) ÚrangeÚtimeÚsleepÚ MyRPCServerÚ MyHandlerr r5r/rr6Úshow_socket_errorr;Zhandle_request)ÚaddressÚiZserverÚerrZ socket_errorrrrr8§s    r8c Cspddl}ddlm}|jƒ}t|ƒ|jƒd|d›d|d›d|j›d|j›d � }|d ||d �|jƒdS) z(Display socket error from manage_socket.rN)Ú showerrorz#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-failurezIDLE Subprocess Error)Úparent) ÚtkinterZtkinter.messageboxrWZTkÚ fix_scalingZwithdrawÚerrnoÚstrerrorZdestroy)rVrTrZrWÚrootÚmsgrrrrSºs *rScsdddl}|jƒtƒtj‰tjƒ\}}}}|\t_t_t_t ƒ‰‡‡‡fdd„‰ˆ|||ƒdS)Nrc sêˆjt|ƒƒ|j}|j}|dk rNt|ƒˆkrNˆt|ƒ||jƒtdˆd�n:|dk rˆ|j rˆt|ƒˆkrˆˆt|ƒ||jƒtdˆd�|r¾tj |ƒ}tdˆd�d }t ||ƒtj |ˆd�tj ||ƒ}x|D]}t|d ˆd �qÐWdS)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):úrun.pyúrpc.pyú threading.pyúqueue.pyú debugger_r.pyúbdb.pyr,)Úendr!)r`rarbrcrdre) ÚaddÚidÚ __context__Ú __cause__rIÚ __traceback__r5Ú__suppress_context__rDÚ extract_tbÚcleanup_tracebackÚ print_listÚformat_exception_only) ÚtypÚexcrKÚcontextÚcauseZtbeÚexcludeÚlinesr)ÚefileÚ print_excÚseenrrrxÑs.       z"print_exception..print_exc) rÚ checkcacheÚ flush_stdoutrrrBÚ last_typeÚ last_valueÚlast_tracebackÚset)rrqÚvalrKZexcinfor)rwrxryrrCÈsrCc Cs|dd…}x2|r>x"|D]}|ddj|ƒrPqWP|d=qWx2|rrx"|D]}|d dj|ƒrLPqLWP|d =qBWt|ƒdkr¢|dd…|dd…<tdtjd�tjdj}xftt|ƒƒD]V}||\}}}} |dkrÜd}| oê|j d ƒ�r|j d d ||fiƒ} |||| f||<q¼WdS)zARemove excluded traces from beginning/end of tb; get cached linesNrr+z** IDLE Internal Exception: )r!Úexecú?z -toplevel-z )rž)r˜rrrr.UszPseudoFile.namecCsdS)NTr)r˜rrrÚisattyYszPseudoFile.isatty)N)rršr›r¡Úpropertyr r.r¢rrrrrœJs   rœc@seZdZdd„Zdd„ZdS)ÚPseudoOutputFilecCsdS)NTr)r˜rrrÚwritable_szPseudoOutputFile.writablecCsP|jrtdƒ‚t|ƒtk r@t|tƒs6tdt|ƒjƒ‚tj|ƒ}|jj ||j ƒS)Nzwrite to closed filezmust be str, not ) ÚclosedÚ ValueErrorrIÚstrÚ isinstanceÚ TypeErrorrÚ__str__r�rrž)r˜rrrrrbs   zPseudoOutputFile.writeN)rršr›r¥rrrrrr¤]sr¤c@s:eZdZd dd„Zdd„Zddd„Zdd d „Zd d „ZdS)ÚPseudoInputFileNcCstj||||ƒd|_dS)Nr,)rœr¡Ú _line_buffer)r˜r�ržr rrrr¡oszPseudoInputFile.__init__cCsdS)NTr)r˜rrrÚreadablesszPseudoInputFile.readabler+cCs´|jrtdƒ‚|dkrd}nt|tƒs8tdt|ƒjƒ‚|j}d|_|dkrlxb|jj ƒ}|s^P||7}qNWnDx(t |ƒ|kr”|jj ƒ}|sŠP||7}qnW||d…|_|d|…}|S)Nzread from closed filer+zmust be int, not r,rr1) r¦r§r©r3rªrIrr­r�Úreadliner„)r˜r�ÚresultrrrrÚreadvs,     zPseudoInputFile.readcCs�|jrtdƒ‚|dkrd}nt|tƒs8tdt|ƒjƒ‚|jpF|jj ƒ}|dkrXt |ƒ}|j dd|ƒ}|dkrv|d}||d…|_|d|…S)Nzread from closed filer+zmust be int, not rr‘r1) r¦r§r©r3rªrIrr­r�r¯r„Úfind)r˜r�rZeolrrrr¯�s zPseudoInputFile.readlinecCs|jjƒdS)N)r�Úclose)r˜rrrr³�szPseudoInputFile.close)Nr1)r1r1)r1)rršr›r¡r®r±r¯r³rrrrr¬ms    r¬c@s,eZdZdd„Zdd„Zdd„Zdd„Zd S) rRcCs˜t|ƒ}|jd|ƒ|jdƒ|_t|jdtjƒt_t |jdtjƒt_ t |jdtjƒt_ t j t_ ddl}|j|_tj|_|jdƒ|_t jj|dd d �dS) zOverride base methodr�ÚconsoleÚstdinÚstdoutrrNÚinterpgš™™™™™©?)ZmyseqÚwait)Ú ExecutiveÚregisterÚget_remote_proxyr´r¬rr rrµr¤r¶rrÚ displayhookÚpydocZ plainpagerZpagerZ _keep_stdinr·Ú RPCHandlerZ getresponse)r˜Z executiver½rrrÚhandle£s      zMyHandler.handlecCstjdƒdS)z>override SocketIO method - wait for MainThread to shut us downé N)rOrP)r˜rrrÚexithook»szMyHandler.exithookcCsdatjƒdS)zEOverride SocketIO method - terminate wait on callback and exit threadTN)r@r•r–)r˜rrrÚEOFhook¿szMyHandler.EOFhookcCsdatjƒdS)zinterrupt awakened threadTN)r@r•r–)r˜rrrÚdecode_interrupthookÅszMyHandler.decode_interrupthookN)rršr›r¿rÁrÂrÃrrrrrR¡srRc@sNeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z ddd„Z dS)r¹cCs&||_tj|_tjƒ|_tjƒ|_dS)N)r…Ú__main__Ú__dict__ÚlocalsrZCalltiprZ AutoComplete)r˜r…rrrr¡Îs zExecutive.__init__cCsˆy&d|_dazt||jƒWddaXWnVtk r:YnJtjƒ|_trTtƒt ƒ|j j j dƒ}|rx|j j jƒYnXtƒdS)NTFz<>)Ú usr_exc_infoÚ interruptabler�rÆrArrBr@r<rCr…r´Zgetvarr·Zopen_remote_stack_viewerr{)r˜ÚcodeZjitrrrÚruncodeÔs"  zExecutive.runcodecCstr tjƒdS)N)rÈr•r–)r˜rrrÚinterrupt_the_serveríszExecutive.interrupt_the_servercCstj|j|ƒS)N)rZstart_debuggerr…)r˜Z gui_adap_oidrrrÚstart_the_debuggerñszExecutive.start_the_debuggercCs|jj|ƒdS)zDUnregister the Idb Adapter. Link objects and Idb then subject to GCN)r…Z unregister)r˜Z idb_adap_oidrrrÚstop_the_debuggerôszExecutive.stop_the_debuggercCs |jj|ƒS)N)rZ fetch_tip)r˜r.rrrÚget_the_calltipøszExecutive.get_the_calltipcCs|jj||ƒS)N)rZfetch_completions)r˜ZwhatÚmoderrrÚget_the_completion_listûsz!Executive.get_the_completion_listNcCsr|jr|j\}}}ndSd}|dk r0|jj|ƒ}x|rN|jjddkrN|j}q2W|t_|t_t j ||ƒ}t j |ƒS)NrrÚrun)rrÑ) rÇr…r»Útb_frameÚ f_globalsÚtb_nextrr|r}rZ StackTreeItemrZremote_object_tree_item)r˜Z flist_oidrqr€rKZflistÚitemrrrrþs   zExecutive.stackviewer)N) rršr›r¡rÊrËrÌrÍrÎrÐrrrrrr¹Ìsr¹)r r r r r rr)N)NN)F)4Úiorr?rrOrDÚ_threadr•r7r$rZZidlelibrrrrrrrrÄÚmodÚdelattrÚmodulesr9rr"r#r&ZTclr)r*r;r@rÈrLr8rSrCrnr{r<r[Z RPCServerrQÚ TextIOBaserœr¤r¬r¾rRÚobjectr¹rrrrÚs`             M$ !4+A