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__)messagecategoryfilenamelinenolinesr./opt/alt/python37/lib/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|ayttjd}WntdtjddStddgtjdd<tjt dt |ffd}d|_ | x0yt ry tWntk rwpYnXytjjdd d }Wntjk rd}YnX|r|\}\}}}|||}tj||fntWqptk r trda wpYqptk r>td Yqpt\} } } yttj|dfWn&tj| | | tjdtYnXwpYqpXqpWdS) 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_exitfuncintrargvprint __stderr__r! threadingZThread manage_socket LOCALHOSTZdaemonstartexit_nowexitKeyboardInterruptrZ request_queuegetqueueZEmptyZresponse_queueZputr%quitting SystemExitexc_infoprint_exception traceback) Z del_exitfuncZportZ sockthreadrequestseqmethodr*kwargsZrettypevaluetbrrrmaines\      rFc CsxtdD]b}t|yt|t}PWq tk rj}z$td|jddtj d|}Wdd}~XYq Xq Wtdtj dt ||da dS| dS)NzIDLE Subprocess: OSError: z, retrying....)rz8IDLE Subprocess: Connection to IDLE GUI failed, exiting.T) rangetimesleep MyRPCServer MyHandlerrr/r*rr0show_socket_errorr5Zhandle_request)addressiZservererrZ socket_errorrrrr2s    r2c 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 :rHz. 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.messageboxrRZTk fix_scalingZwithdrawerrnostrerrorZdestroy)rQrOrUrRrootrrrrNs (rNcsdddl}|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__rC __traceback__r/__suppress_context__r> extract_tbcleanup_traceback print_listformat_exception_only) typexcrEcontextcauseZtbeexcludelinesr)efile print_excseenrrrls,       z"print_exception..print_exc) r checkcache flush_stdoutrrr< last_type last_valuelast_tracebackset)r revalrEexcinfor)rkrlrmrr=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 ValueErrorry __wrapped__RECURSIONLIMIT_DELTA)r*rBlimit)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)rLcCsyWntk 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;EOFErrorr5threadinterrupt_mainrr0r/r1Zcurrent_threadr)reprr>rlr:)selfr?Zclient_addressZerfrrr handle_errorus&      zMyRPCServer.handle_errorN)r __module__ __qualname__rrrrrrLssrLc@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 isinstancer-rrCr _line_bufferrreadlinery)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 rH) rrrr-rrCrrrrryfind)rrrZeolrrrrs zStdInputFile.readlinecCs|jdS)N)rclose)rrrrrszStdInputFile.closeN)r&)r&)rrrrrrrrrrrrrs   rc@s,eZdZddZddZddZddZd S) rMcCst|}|d||d|_t|jdtjtjt_ t |jdtjtjt_ t |jdtjdt_ t jt_ddl}|j|_tj |_t|d |_t jj|dd d dS) zOverride base methodrvconsolestdinstdoutrbackslashreplacerNinterpg?)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)rJrK)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)rrrrrrrrrrrrMsrMc@sNeZdZddZddZddZddZd d Zd d Zd dZ dddZ dS)rcCs&||_tj|_t|_t|_dS)N)rz__main____dict__localsrZCalltiprZ AutoComplete)rrzrrrrs 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 interruptablervrr;r*rrCr-r/rrrr<r:r6r=rzrZgetvarrZopen_remote_stack_viewerro)rcodeeZobZjitrrrruncodes(  & zExecutive.runcodecCstr tdS)N)rrr)rrrrinterrupt_the_server8szExecutive.interrupt_the_servercCst|j|S)N)rZstart_debuggerrz)rZ gui_adap_oidrrrstart_the_debugger<szExecutive.start_the_debuggercCs|j|dS)zDUnregister the Idb Adapter. Link objects and Idb then subject to GCN)rzZ 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) rrzrtb_frame f_globalstb_nextrrprqrZ StackTreeItemrZremote_object_tree_item)rZ flist_oidrertrEZflistitemrrrrIs   zExecutive.stackviewer)N) rrrrrrrrrrrrrrrrsrr)rFzidlelib.idle_test.test_run) verbosity)N)NN)F)?rrior r9rrrJr>_threadrr1rZidlelibrrrrrrrrrUhasattrmodulesmoddelattrr r3rrrr!ZTclr$r%r5r:rrFr2rNr=rbror6rVrrrrZ RPCServerrL TextIOBaserrrrrMobjectrrZunittestrrrrst               M$ (! 1-C