3  fxC@sddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl m Z ddl mZddl mZddl mZddl mZddl mZddlZx"d8D]Zee eejde=qWdZd9ddZd:ddZdaddZede jZefddZdada da!d;ddZ"ddZ#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-Gd0d1d1e-Z.Gd2d3d3e-Z/Gd4d5d5ej0Z1Gd6d7d7e2Z3eddS)<N) autocomplete)calltip) debugger_r) debugobj_r)iomenu)rpc) stackviewer simpledialog messageboxfontdialog filedialog commondialogttkztkinter.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 ) linecachegetlinestrip__name__)messagecategoryfilenamelinenolinesr0/opt/alt/python36/lib64/python3.6/idlelib/run.pyidle_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)sysstderrwriterOSError)rrrrfilerrrridle_showwarning_subproc,sr"cCs0|rtdkr,tjatt_ntdk r,tt_dadS)zFReplace warning.showwarning with idle_showwarning_subproc, or reverse.N)_warnings_showwarningwarnings showwarningr")Zcapturerrrcapture_warnings<sr&TcCs|jddS)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_eventsLsr*Fc Cs|ay$ttjdkstttjd }WntdtjddStddgtjdd<t j t dt |ffd}d|_ |jx2ytry tWntk rwYnXytjjdd d }Wntjk rd}YnX|r |\}\}}}|||}tjj||fntWqtk r4tr.dawYqtk rRtd Yqtj\} } } yttjj|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.)r!NTZ SockThread)targetnameargsg?)blockZtimeoutF) no_exitfunclenrargvAssertionErrorintprint __stderr__r& threadingZThread manage_socket LOCALHOSTZdaemonstartexit_nowexitKeyboardInterruptrZ request_queuegetqueueZEmptyZresponse_queueZputr*quitting SystemExitexc_infoprint_exception traceback) Z del_exitfuncZportZ sockthreadrequestseqmethodr/kwargsZrettypevaluetbrrrmainZs^      rNcCsxtdD]b}tj|yt|t}PWq tk rj}z&td|jddtj d|}WYdd}~Xq Xq Wtdtj dt ||da dS|j dS)NzIDLE Subprocess: OSError: r+z, retrying....)r!z8IDLE Subprocess: Connection to IDLE GUI failed, exiting.T) rangetimesleep MyRPCServer MyHandlerr r7r/rr8show_socket_errorr=Zhandle_request)addressiZservererrZ socket_errorrrrr:s    r:c Cspddl}ddlm}|j}t||jd|dd|dd|jd|jd }|d ||d |jdS) 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.messageboxrYZTk fix_scalingZwithdrawerrnostrerrorZdestroy)rXrVr\rYrootmsgrrrrUs *rUcsdddl}|jttjtj\}}}}|\t_t_t_t fdd|||dS)Nrc sjt||j}|j}|dk rNt|krNt|||jtddn:|dk r|j rt|krt|||jtdd|rtj |}tddd }t ||tj |dtj ||}x|D]}t|d d qWdS)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.pyrpc.py threading.pyqueue.py debugger_r.pybdb.pyr,)endr!)rbrcrdrerfrg) addid __context__ __cause__rK __traceback__r7__suppress_context__rF extract_tbcleanup_traceback print_listformat_exception_only) typexcrMcontextcauseZtbeexcludelinesr)efile print_excseenrrrzs.       z"print_exception..print_exc) r checkcache flush_stdoutrrrD last_type last_valuelast_tracebackset)rrsvalrMZexcinfor)ryrzr{rrEsrEc Cs|dd}x2|r>x"|D]}|ddj|rPqWP|d=qWx2|rrx"|D]}|d dj|rLPqLWP|d =qBWt|dkr|dd|dd<tdtjdtjdj}xftt|D]V}||\}}}} |dkrd}| o|j d r|j d d ||fi} |||| f||<qWdS)zARemove excluded traces from beginning/end of tb; get cached linesNrr+z** IDLE Internal Exception: )r!exec?z -toplevel-z )rrrrr>s r>cCsrddl}t|jjdd}|dkrnxJ|jj|D]:}|jj||dd}t|d}|dkr0td ||d<q0WdS) zScale fonts on HiDPI displays.rNtkscalinggffffff?T)r`r.existssizeg?g) Z tkinter.fontfloatrZcallr namesZFontr6round)r`r\rr.r rrrrr]s r]c@seZdZddZdS)rSc CsyWntk rYntk r:datjYntj}tddd|dtd|dtdtj j |dtd||dtd t ||dt j |dtd |dtdd|ddatjYnXd S) zrOverride RPCServer method for IDLE Interrupt the MainThread and exit server if link is dropped. T -()r!zUnhandled server exception!z Thread: %szClient Address: z Request: z# *** Unrecoverable, server exiting!N)rCEOFErrorr=threadinterrupt_mainrr8r7r9Zcurrent_threadr.reprrFrzrB)selfrGZclient_addressZerfrrr handle_error+s&    zMyRPCServer.handle_errorN)r __module__ __qualname__rrrrrrS)srSc@s6eZdZd ddZeddZeddZdd ZdS) PseudoFileNcCs||_||_||_dS)N)shelltags _encoding)rrrencodingrrr__init__LszPseudoFile.__init__cCs|jS)N)r)rrrrrQszPseudoFile.encodingcCs d|jS)Nz<%s>)r)rrrrr.UszPseudoFile.namecCsdS)NTr)rrrrisattyYszPseudoFile.isatty)N)rrrrpropertyrr.rrrrrrJs   rc@seZdZddZddZdS)PseudoOutputFilecCsdS)NTr)rrrrwritable_szPseudoOutputFile.writablecCsP|jrtdt|tk r@t|ts6tdt|jtj|}|jj ||j S)Nzwrite to closed filezmust be str, not ) closed ValueErrorrKstr isinstance TypeErrorr__str__rrr)rrrrrrbs   zPseudoOutputFile.writeN)rrrrrrrrrr]src@s:eZdZd ddZddZdddZdd d Zd d ZdS)PseudoInputFileNcCstj||||d|_dS)Nr,)rr _line_buffer)rrrrrrrroszPseudoInputFile.__init__cCsdS)NTr)rrrrreadablesszPseudoInputFile.readabler+cCs|jrtd|dkrd}nt|ts8tdt|j|j}d|_|dkrlxb|jj }|s^P||7}qNWnDx(t ||kr|jj }|sP||7}qnW||d|_|d|}|S)Nzread from closed filer+zmust be int, not r,rr1) rrrr6rrKrrrreadliner3)rrresultrrrrreadvs,     zPseudoInputFile.readcCs|jrtd|dkrd}nt|ts8tdt|j|jpF|jj }|dkrXt |}|j dd|}|dkrv|d}||d|_|d|S)Nzread from closed filer+zmust be int, not rrr1) rrrr6rrKrrrrr3find)rrrZeolrrrrs zPseudoInputFile.readlinecCs|jjdS)N)rclose)rrrrrszPseudoInputFile.close)Nr1)r1r1)r1)rrrrrrrrrrrrrms    rc@s,eZdZddZddZddZddZd S) rTcCst|}|jd||jd|_t|jdtjt_t |jdtjt_ t |jdtjt_ t j t_ ddl}|j|_tj|_|jd|_t jj|dd d dS) zOverride base methodrconsolestdinstdoutrrNinterpg?)Zmyseqwait) Executiveregisterget_remote_proxyrrrrrrrrrr displayhookpydocZ plainpagerZpagerZ _keep_stdinr RPCHandlerZ getresponse)rZ executiverrrrhandles      zMyHandler.handlecCstjddS)z>override SocketIO method - wait for MainThread to shut us down N)rQrR)rrrrexithookszMyHandler.exithookcCsdatjdS)zEOverride SocketIO method - terminate wait on callback and exit threadTN)rBrr)rrrrEOFhookszMyHandler.EOFhookcCsdatjdS)zinterrupt awakened threadTN)rBrr)rrrrdecode_interrupthookszMyHandler.decode_interrupthookN)rrrrrrrrrrrrTsrTc@sNeZdZddZddZddZddZd d Zd d Zd dZ dddZ dS)rcCs&||_tj|_tj|_tj|_dS)N)r__main____dict__localsrZCalltiprZ AutoComplete)rrrrrrs zExecutive.__init__cCsy&d|_dazt||jWddaXWnVtk r:YnJtj|_trTtt |j j j d}|rx|j j jYnXtdS)NTFz<>) usr_exc_info interruptablerrrCrrDrBr>rErrZgetvarrZopen_remote_stack_viewerr})rcodeZjitrrrruncodes"  zExecutive.runcodecCstr tjdS)N)rrr)rrrrinterrupt_the_serverszExecutive.interrupt_the_servercCstj|j|S)N)rZstart_debuggerr)rZ gui_adap_oidrrrstart_the_debuggerszExecutive.start_the_debuggercCs|jj|dS)zDUnregister the Idb Adapter. Link objects and Idb then subject to GCN)rZ unregister)rZ idb_adap_oidrrrstop_the_debuggerszExecutive.stop_the_debuggercCs |jj|S)N)rZ fetch_tip)rr.rrrget_the_calltipszExecutive.get_the_calltipcCs|jj||S)N)rZfetch_completions)rZwhatmoderrrget_the_completion_listsz!Executive.get_the_completion_listNcCsr|jr|j\}}}ndSd}|dk r0|jj|}x|rN|jjddkrN|j}q2W|t_|t_t j ||}t j |S)Nrrrun)rr) rrrtb_frame f_globalstb_nextrr~rrZ StackTreeItemrZremote_object_tree_item)rZ flist_oidrsrrMZflistitemrrrrs   zExecutive.stackviewer)N) rrrrrrrrrrrrrrrrsr)r r r r r rr)N)NN)F)4iorrArrQrF_threadrr9r$r\Zidlelibrrrrrrrrmoddelattrmodulesr;rr"r#r&ZTclr)r*r=rBrrNr:rUrErpr}r>r]Z RPCServerrS TextIOBaserrrrrTobjectrrrrrs`             M$ !4+A