@s~ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlmZddlmZmZyddlTWn2ek reddejejdYnXddljZddlmZmZdd lmZdd l m!Z!dd l"m#Z#dd l$m%Z%dd l&m'Z'ddl(m)Z)ddl(m*Z*ddl(m+Z+ddl(m,Z,ddl(m-Z-dZ.dZ/eja0ddl1Z1dddZ2ddddZ3da4ddZ5e5dde j6ddZ7e7e _6GdddeZ8Gdd d eZ9Gd!d"d"e!Z:Gd#d$d$e#Z;Gd%d&d&e*j<Z=Gd'd(d(eZ>Gd)d*d*e%Z?Gd+d,d,e j@ZAGd-d.d.eAZBGd/d0d0eAZCd1ZDd2d3ZEeFd4krpejGd4ejGd*>> )warning_streamwriter AttributeErrorOSError)rrrrrrrrridle_showwarning@s   r%cCsL|r*tdkrHtjatt_qHntdk rHtt_dandS)z>Replace warning.showwarning with idle_showwarning, or reverse.N)_warnings_showwarningwarnings showwarningr%)Zcapturerrrcapture_warningsSs    r)TcCs{tj}i}xNt|D]@}|dd|dddkr|j||| entries Rather than repeating the linecache code, patch it to save the entries, call the original linecache.checkcache() (skipping them), and then restore the saved entries. orig_checkcache is bound at definition time to the original method, allowing it to be patched. Nrz<>)rcachelistpopupdate)rZorig_checkcacher+savekeyrrrextended_linecache_checkcachebs $ r1c@seZdZdZddZd'd(d)d*d+d,gZdddZddZd ddZd ddZ ddZ ddZ dd Z d!d"Z d#d$Zd%d&Zd S)-PyShellEditorWindowz6Regular text edit window in IDLE, supports breakpointscGsg|_tj|||jjd|j|jjd|j|jjd|jjt j j t j d|_|jj|dd}|jj||jjr|jn|jdS)Nz<>z<>z<>zbreakpoints.lstcSs|j|dS)N)restore_file_breaks)Zold_hookselfrrrfilename_changed_hooks z;PyShellEditorWindow.__init__..filename_changed_hook) breakpointsr__init__textbindset_breakpoint_hereclear_breakpoint_hereflist open_shellospathjoinrZ GetUserCfgDirbreakpointPathioZfilename_change_hookZset_filename_change_hookrr3color_breakpoint_text)r4argsr5rrrr7|s     zPyShellEditorWindow.__init__Cut<>rmenu_check_cutCopy<>rmenu_check_copyPaste <>rmenu_check_pasteNSet Breakpoint<>Clear Breakpoint<>TcCsn|jdkrdS|rCtjddd}tj|d}nidd6dd6}|jjd |dS) z,Turn colorizing of breakpoint text on or offNmainThemenamebreak foreground backgroundBREAK)rBr GetOption GetHighlightr8Z tag_config)r4ZcolorthemeZcfgrrrrCsz)PyShellEditorWindow.color_breakpoint_textcCs|j}|jj}|jdd|d|dy|jj|}Wn"tk rn|jj|YnXy&|jj j j }|j ||WnYnXdS)NrYz%d.0r) r8rBrtag_addr6index ValueErrorappendr<pyshellinterpdebuggerr:)r4rr8ridebugrrrset_breakpoints   z"PyShellEditorWindow.set_breakpointcCsU|j}|jj}|s)|jdStt|jd}|j|dS)Ninsert)r8rBrbellintfloatr^rf)r4eventr8rrrrrr:s   z'PyShellEditorWindow.set_breakpoint_herecCs|j}|jj}|s)|jdStt|jd}y|jj|WnYnX|j dddy&|j j j j }|j||WnYnXdS)NrgrYzinsert linestartzinsert lineend +1char)r8rBrrhrirjr^r6remove tag_remover<rarbrcr;)r4rkr8rrrerrrr;s"    z)PyShellEditorWindow.clear_breakpoint_herec Cs|jr|j}|jj}|s2|jdSg|_|jddty#|jjj j }|j |WqYqXndS)NrYz1.0) r6r8rBrrhrmZENDr<rarbrcclear_file_breaks)r4r8rrerrrrns     z%PyShellEditorWindow.clear_file_breakscCsb|j}|jj}y+t|jd}|j}WdQXWntk rZg}YnXyt|jdv}x1|D])}|j|dsz|j|qzqzW|j |j}|r|j|dt |dnWdQXWnrtk r]}zRt |j ddsKd|j _ tjd d d d t |d |jnWYdd}~XnXdS)z#Save breakpoints when file is savedrNw= breakpoint_error_displayedFTtitlez IDLE Errorrz$Unable to update breakpoint list: %sparent)r6rBropenrA readlinesr$ startswithr"update_breakpointsstrgetattrrootrs tkMessageBox showerrorr8)r4ZbreaksrfplinesZnew_filererrrrrstore_file_breakss.       ,  z%PyShellEditorWindow.store_file_breaksc Cs|jj|jdkr dS|jj}|dkr<dStjj|jrt|jd}|j }WdQXxe|D]Z}|j |drt |t |dd}x|D]}|j |qWqqWndS)Nrorqr)r8r.rBrr>r?isfilerArvrwrxevallenrf)r4rrrrZbreakpoint_linenumbersZbreakpoint_linenumberrrrr3s      z'PyShellEditorWindow.restore_file_breakscCs4|j}|jd}|j|}||_dS)z3Retrieves all the breakpoints in the current windowrYN)r8Z tag_rangesranges_to_linenumbersr6)r4r8rangesZlinenumber_listrrrrys z&PyShellEditorWindow.update_breakpointscCsg}xtdt|dD]f}tt||j}tt||dj}x'||kr|j||d7}q^WqW|S)Nrr)rangerrirjstringr`)r4rrr^rendrrrrs z)PyShellEditorWindow.ranges_to_linenumberscCs|jtj|dS)z7Extend base method - clear breaks when module is closedN)rnr_close)r4rrrr0s zPyShellEditorWindow._close)rErFzrmenu_check_cut)rHrIrJ)rKrLzrmenu_check_paste)NNN)rNrON)rPrQN)r __module__ __qualname____doc__r7Z rmenu_specsrCrfr:r;rnrr3ryrrrrrrr2ys$       *   r2c@s1eZdZdZeZdZdddZdS)PyShellFileListz8Extend base class: IDLE supports a shell and breakpointsNcCsQ|jr|jjjn.t||_|jrJ|jjsJdSn|jS)N)ratopwakeupPyShellbegin)r4rkrrrr=?s  zPyShellFileList.open_shell)rrrrr2rrar=rrrrr6s rc@sFeZdZdZddZddZddZdd Zd S) ModifiedColorDelegatorz8Extend base class: colorizer for the shell window itselfcCstj||jdS)N)r r7 LoadTagDefs)r4rrrr7Ms zModifiedColorDelegator.__init__cCs7|jddd|jdddtj|dS)NZTODOz1.0iomarkZSYNC)rmr]r recolorize_main)r4rrrrQsz&ModifiedColorDelegator.recolorize_maincCstj|tjddd}|jjiidd6dd6d6tj|dd6tj|dd6tj|d d 6dS) NrRrSrTrXrWstdinstdoutstderrconsole)r rrrZtagdefsr.r[)r4r\rrrrVs  z"ModifiedColorDelegator.LoadTagDefscCs+x$|jD]}|j|ddq WdS)Nrr)rrm)r4tagrrr removecolors`sz#ModifiedColorDelegator.removecolorsN)rrrrr7rrrrrrrrJs    rc@s4eZdZdZdddZdddZdS)ModifiedUndoDelegatorz;Extend base class: forbid insert/delete before the I/O markNc Cs\y-|jj|ddr,|jjdSWntk rAYnXtj||||dS)NModifiedInterpretercCsf||_tjdj}tj|d|d|_d|_d|_t |_ |j j j |_dS)N__main__localsF) tkconsolesysmodules__dict__rr7save_warnings_filters restartingsubprocess_arglistPORTportcompilecompilerflagsoriginal_compiler_flags)r4rrrrrr7s     zModifiedInterpreter.__init__NcCs:|jdkr!|j|_ntj|j|_dS)N)rbuild_subprocess_arglist subprocessPopen rpcsubproc)r4rrrspawn_subprocesssz$ModifiedInterpreter.spawn_subprocesscCs|jdkstdddtjD}tjddddd d d }td krnd |f}n d|f}tjg|d|t|jgS)Nrz/Socket should have been assigned a port number.cSsg|]}d|qS)z-Wr).0rrrr s z@ModifiedInterpreter.build_subprocess_arglist..rRGeneralzdelete-exitfuncdefaultFtypeboolzidlelib.PyShellz&__import__('idlelib.run').run.main(%r)z__import__('run').main(%r)z-c) rAssertionErrorr warnoptionsrrZr executablerz)r4rpZ del_exitfZcommandrrrrs   z,ModifiedInterpreter.build_subprocess_arglistcCst|jf}xktdD]O}tj|yt||_PWqtk rj}zWYdd}~XqXqW|jdS|jj j d|_t dkr|jj j t jt jdn|j|jj jdy|jjWn6t jk r*}z|jdSWYdd}~XnX|jjd|j|jjd|jj|jjd|jj|jjd|jj|jjd |jj|jjd t|jjd ||jd d |j|jS)Nrr rrrrr<rrbwith_cwdT)HOSTrrtimeZsleeprrpccltr$display_port_binding_errorlistening_sockZ getsocknamerZ setsockoptsocketZ SOL_SOCKETZ SO_REUSEADDRrZ settimeoutaccepttimeoutdisplay_no_subprocess_errorregisterrrrrr<r transfer_pathpoll_subprocess)r4Zaddrrdrrrrstart_subprocesss>      z$ModifiedInterpreter.start_subprocessFcCs|jr|jSd|_|j}|rMytj|jWqMYqMXn|jj|j|j}|j}d|_|j y|jj Wn6t j k r}z|j dSWYdd}~XnX|jd||j|jjdd|r |jd|jnt|jddd }|j|d ||jjd d|jjd d |j|rtj|j}|jn|j|jj_d|_|jS) NTFrrzend-1crrrrqz RESTART restartleft)rr getdebuggerrZclose_subprocess_debuggercloseterminate_subprocessr executingrrrrrr stop_readliner8rr" showpromptriwidthmark_set mark_gravityZrestart_subprocess_debuggerload_breakpointsrrrr)r4rrerZ was_executingrZhalfbarZguirrrrestart_subprocesssJ                z&ModifiedInterpreter.restart_subprocesscCs|jjddfidS)NexecZinterrupt_the_server)rZ remotecall)r4rrrZ__request_interruptsz'ModifiedInterpreter.__request_interruptcCstjd|jjdS)Ntarget) threadingZThread'_ModifiedInterpreter__request_interruptstart)r4rrrinterrupt_subprocesssz(ModifiedInterpreter.interrupt_subprocesscCs|jdk r(|jjj|jny|jjjWntk rPYnXy|jjWntk rvYnX|jd|j_ d|_dS)NF) _afteridrr8Z after_cancelrrrr#rr)r4rrrkill_subprocesss    z#ModifiedInterpreter.kill_subprocesscCsXy|jjWntk r)dSYn+Xy|jjWntk rSdSYnXdS)z"Make sure subprocess is terminatedN)rkillr$wait)r4rrrrs   z(ModifiedInterpreter.terminate_subprocesscCsC|r"dg}|jtjn tj}|jd|fdS)NrVzRif 1: import sys as _sys _sys.path = %r del _sys )extendrr? runcommand)r4rr?rrrr!s   z!ModifiedInterpreter.transfer_pathcCs|j}|dkrdSy|j|jdd}Wn;tttfk rr|jjr^dSd}|jYnX|rp|jj d|_|\}}|jj }|dkr|dk rGt t |d|qGnl|dkr |jj drG|jqGn>|dkrGd}t ||dtjt ||d|ny|jjWqptk rlYqpXn|jjs|jjj|jj|j|_ndS) Nrg?ZOKrZ EXCEPTIONz<>ERRORz/PyShell.ModifiedInterpreter: Subprocess ERROR: )rZ pollresponse active_seqrr$KeyboardInterruptrclosingr resetoutputrprintreprgetvarremote_stack_viewerr __stderr__ endexecutingr#r8after pollintervalrr)r4ZcltresponseZhowZwhatrerrmsgrrrr0s@              z#ModifiedInterpreter.poll_subprocesscCs ||_dS)N)rc)r4rcrrr setdebuggerXszModifiedInterpreter.setdebuggercCs|jS)N)rc)r4rrrr[szModifiedInterpreter.getdebuggercCs|jjjd|jdS)aInitiate the remote stack viewer from a separate thread. This method is called from the subprocess, and by returning from this method we allow the subprocess to unblock. After a bit the shell requests the subprocess to open the remote stack viewer which returns a static object looking at the last exception. It is queried through the RPC mechanism. i,N)rr8rr)r4rrropen_remote_stack_viewer^s z,ModifiedInterpreter.open_remote_stack_viewerc Csddlm}|jjdddi}|dkrK|jjjdS|j|j|}ddlm }m }t |jj}t j ddd }t j|d d }||d |d d} | jjdddd|| jd|} | jdS)Nr)RemoteObjectBrowserrZ stackviewerr<)ScrolledCanvasTreeNoderRrSrTZnormalrXZbgZhighlightthicknessexpandrZfillZboth)zflist)idlelibrr remotequeuerr|rhZStubObjectTreeItemZidlelib.TreeWidgetrrZToplevelrrZr[ZframeZpackZcanvasr) r4rZoiditemrrrr\rXZscZnoderrrrks z'ModifiedInterpreter.remote_stack_viewerrcCs#|j|}|j||dS)z1Like runsource() but assumes complete exec sourceN) stuffsourceexecfile)r4sourcerrrr execsource~szModifiedInterpreter.execsourcecCs|dkr3tj|}|j}WdQXnyt||d}WnXttfk r|jjtdd|jj t j |||jj YnX|j |dS)zExecute an existing fileNrzB*** Error in script or command! Traceback (most recent call last):r)tokenizervreadr OverflowError SyntaxErrorrrrrrshowsyntaxerrorrruncode)r4rr rcoderrrr s    zModifiedInterpreter.execfilec Cs|j|}d|_tjdd|_tjdddtt|tsYt zt j |||SWd|jdk r|jtjddrrrr)gidsplitrrr+)r4r rrrrrr s  #zModifiedInterpreter.stuffsourcecCs|jd|fdS)z>Prepend sys.path with file's directory if not already includeda(if 1: _filename = %r import sys as _sys from os.path import dirname as _dirname _dir = _dirname(_filename) if not _dir in _sys.path: _sys.path.insert(0, _dir) del _filename, _sys, _dirname, _dir N)r)r4rrrrprepend_syspathsz#ModifiedInterpreter.prepend_syspathc Cs|j}|j}|jdddtj\}}}t|ddpU|pUd}t|ddpmd}t|d dpd } | d kr|d7}n|dkrd | d} nd |d| df} |j|| |j|jd ||j dS)zOverride Interactive Interpreter method: Use Colorizing Color the offending position instead of printing it and pointing at it with a caret. rz1.0rmsgrVzrroffsetrziomark + %d charsz&iomark linestart + %d lines + %d charszSyntaxError: %s N) rr8rmrexc_infor{Zcolorize_syntax_errorrr"r) r4rrr8rvaluetbr!rr"posrrrrs"      z#ModifiedInterpreter.showsyntaxerrorcCsJ|jj|jtj||jjdrF|jjndS)z1Extend base class method to reset output properlyz<>N)rrchecklinecacher showtracebackropen_stack_viewer)r4rrrr(s    z!ModifiedInterpreter.showtracebackcCsXtj}xHt|jD]4}|dd|dddkr||=qqWdS)Nrz<>r*)rr+r,keys)r4cr0rrrr's $z"ModifiedInterpreter.checklinecachecCsV|jjr|jdS|jrB|jjdd|fint||jdS)z*Run the code without invoking the debuggerrrrr)rrdisplay_executing_dialogrr rr)r4rrrrrs   zModifiedInterpreter.runcommandcCs|jjr|jjn|j|jdk rW|jtjddd?Z(d@dAZ)dBdCZ*dDdEZ+ddFdGZ,ddHdIZ-ddJdKZ.dLdMZ/dNdOZ0fdPdQZ1fdRdSZ2fdTdUZ3S)\rzPython z Shellr_Fileedit_Editre_Debugoptions_Optionswindows_Windowhelp_Helpr)HistoryNc Cstr9|j}|dddkr9|jddq9nt||_|dkrt}t||jt|}nt j ||ddd|_ d|_ d|_ |j}|jdd|jd |j|jd |j|jd |j|jd |j|jd |j|jd|j|jd|jtr~|jd|j|jd|jntj|_tj|_tj|_ ddl!m"}t#|d|j$|_t%|d|j$|_t%|d|j$|_t%|d|j$|_&ts?|jt_|jt_|jt_nyddl'}|j(|_)Wntj*t_YnX|j+|j|_,d|_-dS)NrrshellShe_llTZwrapcharz<>z<>z<>z<>z<>z<>z<>z<>z<>) IOBindingrrrr2)zshellr>).r0 menu_specsrgrrbTkr withdrawrr r7ZusetabsZ indentwidthZcontext_use_ps1r8Z configurer9enter_callbacklinefeed_callbackcancel_callback eof_callbackr)toggle_debuggertoggle_jit_stack_viewerview_restart_mark restart_shellrr save_stdoutr save_stderrr save_stdinrrAPseudoInputFileencodingPseudoOutputFilerpydocZ plainpagerZpagerrr<historyr)r4r<Zmsr|r8rArTrrrr7[s\                zPyShell.__init__cCstjddS)NZ shell_onlyT)rZ GetExtensions)r4rrrget_standard_extension_namessz$PyShell.get_standard_extension_namesFcCs |adS)N)r!)r4streamrrrset_warning_streamszPyShell.set_warning_streamcCstS)N)r!)r4rrrget_warning_streamszPyShell.get_warning_streamcCs`|jr0tjddd|j|jdS|jj}|rR|jn |jdS)NzDon't debug nowz*You can only toggle the debugger when idler-rU) rr}r~r8set_debugger_indicatorrbrclose_debugger open_debugger)r4rkdbrrrrJs     zPyShell.toggle_debuggercCs%|jj}|jd| dS)Nz<>)rbrZsetvar)r4r]rrrrZszPyShell.set_debugger_indicatorcCsdS)Nr)r4rkrrrrKszPyShell.toggle_jit_stack_viewercCs|jj}|r|jjd|j|jjrQtj|jjn|j|jj ddt _ |j n|j dS)Nz [DEBUG OFF] z>>> )rbrrrrrZclose_remote_debuggerrrr"rps1rrZ)r4r]rrrr[s     zPyShell.close_debuggercCsq|jjr'tj|jj|}ntj|}|jj||jdt_|j |j dS)Nz[DEBUG ON] >>> ) rbrrZstart_remote_debuggerrrrrr^rrZ)r4Zdbg_guirrrr\s     zPyShell.open_debuggercCs|jd|_dS)zHelper for ModifiedInterpreterrN)rr)r4rrrr.s zPyShell.beginexecutingcCs d|_d|_|jdS)zHelper for ModifiedInterpreterrN)rr1r)r4rrrrs  zPyShell.endexecutingcCsf|jr=tjddddd|j}|dkr=dSn|jd|_d|_tj|S) zExtend EditorWindow.close()zKill?z6The program is still running! Do you want to kill it?rokruFZcancelT) rr}Z askokcancelr8rr1rrr)r4rrrrrs      z PyShell.closecCs||jtr |jjn|jt_|jt_|j t_ d|_d|_ d|j _ d|_tj|dS)zEExtend EditorWindow._close(), shut down debugger and execution serverN)r[r0rbrrNrrrOrrPrrr<rarUrr)r4rrrrs        zPyShell._closecCsdS)z8Override EditorWindow method: never remove the colorizerTr)r4rrrrispythonsourceszPyShell.ispythonsourcecCs|jS)N) shell_title)r4rrr short_titleszPyShell.short_titlez@Type "copyright", "credits" or "license()" for more information.cCs|jjdd|jtrOd}|jj}|sm|jdSndddd}tjt _|j d t j t j |j |f|jd dl}d|_d S) NrrgrVFz==== No Subprocess ==== z9WARNING: Running IDLE without a Subprocess is deprecated z;and will be removed in a later version. See Help/IDLE Help zfor details. zPython %s on %s %s %srT)r8rrr0rbrrr displayhookrr"versionplatform COPYRIGHTrtkinterZ _default_root)r4ZnosubZclientrgrrrrs"        z PyShell.begincCs'|js dSd|_|jjdS)NT)reading_stop_readline_flagrquit)r4rrrrs  zPyShell.stop_readlinec Cs|j}zd|_|jjWd||_X|jrFd|_dS|jjdd}t|dkrvd}n|j|jrd|_t st qn|j rd|_ d}n|S)NrFrVrzend-1crrr) rhrmainlooprir8getrrr1r0r endoffile)r4r/rrrrreadline%s(             zPyShell.readlinecCsdS)NTr)r4rrrisatty<szPyShell.isattyc Csy |jjdddrdSWnYnX|jp:|jse|j|jjd|jdSd|_d|_ |jr|jj r|jj r|jj q|jj n|jr|jjndS)Nz sel.firstz!=zsel.lastzKeyboardInterrupt rUrr)r8rrrhrrbr"rrmr1rrrrrrj)r4rkrrrrH?s&     zPyShell.cancel_callbackcCs|jr|j rdS|jjdddoD|jjdddsKdS|jsk|j|jnd|_d|_|jj dS)Nrz==rgzend-1crrrU) rrhr8rrrr1rmrrj)r4rkrrrrIUs      zPyShell.eof_callbackcCs@|jr/|jjdd|jjdn |j|dS)NrgrrrU)rhr8rgseenewline_and_indent_event)r4rkrrrrGds   zPyShell.linefeed_callbackc Cs|jr|j rdSyN|jjdd}|rd|jjdddrd|j||dSnWnYnX|jjdddr|jjd d}|r|jjdd|d r|j|jj|d |d |dS|jjd d}|rL|jjd d |d rL|j|jj|d |d |dS|jjdd}|r|jj|d ddr|j|jj|d d |n|j|jjdd |dS|jjdddr|jjddn|jjdd}|r8|j r8|jj ddn|jjdddra|j |dS|jjdd|jr|jj dd|jj dn |j ||jjd dd|jj|jr|jjn |jdS)Nz sel.firstzsel.lastz<=rrUrgrziomark linestartrrrzinsert lineendz>=rzinsert linestartzend-1czend-1c linestartrr)rrhr8rlrrecallZ tag_prevrangeZ tag_nextrangerrrrqrgrpr]Zupdate_idletasksrrjrunit)r4rkselprevnextindicesrrrrrFmsX "'"'&      zPyShell.enter_callbackc Cstjdd|}tjdd|}|jd}|jjzL|jjddd|jjdd |jjd d}|jj d r|j ||jjd d}n|jj d|d j t |d krtjd|d jd }tjd|jd }xd|d dD]O}|j|rm||t |d}n|jj dd|jq;WnWd|jjd|jjXdS)Nz^\s*\nrVz\n\s*$rrrtz1.0rrgzend-1czinsert linestart:rrz ^([ \t]*))resubrr8Zundo_block_startrmrrlrstripendswithrqrgrrsearchgrouprxrpZundo_block_stop)r4rrkrprefixZorig_base_indentZnew_base_indentrrrrrrs*  (zPyShell.recallcCs|jjdd}t|}x.|dkrQ||ddkrQ|d}q$W|dkr||ddkr|d}nx.|dkr||ddkr|d}qW|d|}|jj|}dS)Nrzend-1crrz rr)r8rlrrbr)r4rrdrrrrrss #  #z PyShell.runitc Csu|jjr|jjSy tjWn%tjddd|jdSYnXddlm }||j |j }dS)NzNo stack tracez@There is no stack trace yet. (sys.last_traceback is not defined)r-r) StackBrowser) rbrrrlast_tracebackr}r~r8Zidlelib.StackViewerrr|r<)r4rkrZsvrrrr)s      zPyShell.open_stack_viewercCs$|jjd|jjddS)Nrr)r8rp)r4rkrrrrLszPyShell.view_restart_markcCs|jjdddS)z&Callback for Run/Restart Shell Cntl-F6rTN)rbr)r4rkrrrrMszPyShell.restart_shellc Csl|jyttj}Wnd}YnX|jj||jjdd|j|j j dS)NrVrgzend-1c) rrzrr^rr"r8rset_line_and_columnrBZ reset_undo)r4rrrrrs   zPyShell.showpromptcCs|jjdd}|jr1|jj|n|jjddkr_|jjddn|jjdd|jdS)Nrzend-1czend-2crr)r8rlrUZstorergrr)r4r rrrrs zPyShell.resetoutputc Cst|tryt|ryt|dkryx*t|D]\}}|dkr:Pq:q:Wtd|||ddnyB|jjddtj |||d}|jjddWn YnX|j rd|_ t st qn|S) Nu￿zUCS-2rz%Non-BMP character not supported in Tkrrightrr) rrzrmax enumerateUnicodeEncodeErrorr8rr r"r1r0r)r4rrrr@countrrrr"s"-     z PyShell.writec sFy |jjdddrdSWntk r8dSYnXtjS)Nz sel.firstrrdisabled)r8rrsuperrG)r4) __class__rrrGs   zPyShell.rmenu_check_cutcs)|jjdddrdStjS)Nrgrrr)r8rrrM)r4)rrrrMszPyShell.rmenu_check_paste)zfiler2)r3r4)zdebugr5)r6r7)r8r9)zhelpr;)4rrrrrarr rr rCZidlelib.IdleHistoryr<r7rVrhrr1rmrrirXrYrJrZrKr[r\r.rrrr`rbrfrrrnrorHrIrGrFrrrsr)rLrMrrr"rGrMrr)rrrEsd  :                ?   rc@sOeZdZdddZeddZeddZdd ZdS) PseudoFileNcCs||_||_||_dS)N)r=r _encoding)r4r=rrRrrrr7%s  zPseudoFile.__init__cCs|jS)N)r)r4rrrrR*szPseudoFile.encodingcCs d|jS)Nz<%s>)r)r4rrrrT.szPseudoFile.namecCsdS)NTr)r4rrrro2szPseudoFile.isatty)rrrr7propertyrRrTrorrrrr#s rc@s(eZdZddZddZdS)rScCsdS)NTr)r4rrrwritable8szPseudoOutputFile.writablecCs}|jrtdnt|tk rgt|tsUtdt|jntj|}n|jj ||j S)Nzwrite to closed filezmust be str, not ) closedr_rrzr TypeErrorr__str__r=r"r)r4rrrrr";s zPseudoOutputFile.writeN)rrrrr"rrrrrS6s  rSc@sUeZdZdddZddZd ddZdd d Zd d ZdS)rQNcCs#tj||||d|_dS)NrV)rr7 _line_buffer)r4r=rrRrrrr7HszPseudoInputFile.__init__cCsdS)NTr)r4rrrreadableLszPseudoInputFile.readablercCs|jrtdn|dkr-d}n+t|tsXtdt|jn|j}d|_|dkrx|jj }|sPn||7}qyWn_x9t ||kr|jj }|sPn||7}qW||d|_|d|}|S)Nzread from closed filerzmust be int, not rVrr*) rr_rrirrrrr=rnr)r4sizeresultrrrrrOs,      zPseudoInputFile.readcCs|jrtdn|dkr-d}n+t|tsXtdt|jn|jpm|jj }|dkrt |}n|j dd|}|dkr|d}n||d|_|d|S)Nzread from closed filerzmust be int, not rrrr*) rr_rrirrrrr=rnrfind)r4rrZeolrrrrnfs      zPseudoInputFile.readlinecCs|jjdS)N)r=r)r4rrrrvszPseudoInputFile.closer*r*)rrrr7rrrnrrrrrrQFs  rQa USAGE: idle [-deins] [-t title] [file]* idle [-dns] [-t title] (-c cmd | -r file) [arg]* idle [-dns] [-t title] - [arg]* -h print this help message and exit -n run IDLE without a subprocess (DEPRECATED, see Help/IDLE Help for details) The following options will override the IDLE 'settings' configuration: -e open an edit window -i open a shell window The following options imply -i and will open a shell: -c cmd run the command in a shell, or -r file run script from file -d enable the debugger -s run $IDLESTARTUP or $PYTHONSTARTUP before anything else -t title set title of shell window A default edit window will be bypassed when -c, -r, or - are used. [arg]* are passed to the command (-c) or script (-r) in sys.argv[1:]. Examples: idle Open an edit window or shell depending on IDLE's configuration. idle foo.py foobar.py Edit the files, also open a shell if configured to start with shell. idle -est "Baz" foo.py Run $IDLESTARTUP or $PYTHONSTARTUP, edit foo.py, and open a shell window with the title "Baz". idle -c "import sys; print(sys.argv)" "foo" Open a shell window and run the command, passing "-c" in sys.argv[0] and "foo" in sys.argv[1]. idle -d -s -r foo.py "Hello World" Open a shell window, run a startup script, enable the debugger, and run foo.py, passing "foo.py" in sys.argv[0] and "Hello World" in sys.argv[1]. echo "import sys; print(sys.argv)" | idle - "foobar" Open a shell window, run the script piped in, passing '' in sys.argv[0] and "foobar" in sys.argv[1]. cstddad}d}d}d}d}d}y)tjtjddd\}}WnRtjk r}z/td|tfdtjtj dWYdd}~XnXxE|D]=\} } | dkr| }d}n| d krd}d}n| d krd}n| d kr9tj j ttj n| d krNd}n| d krvtddtjdan| dkr| }t j j|rntd|tj d}n| dkrd}d}n| dkr| t_d}qqW|r(|ddkr(tjj}d}nx=tttj D]&} t j jtj | tj | W|r|ddkrdg|ddt_n|rdg|t_n|r|g|t_n|rTd}g} x'|D]} | jt j j| qWxy| D]=}t j j|}|tj krtj jd|qqWn1t j}|tj krtj jd|ntjddddd}|p|}|p| }tddat j jt j jtdt dkr t j jd}tj!d |nft"d!krt"d"kr>d#nd$fd%d&d/D}d*d&|D}tj#d|nt$ttj%t&ta't(j)tt'|r!|p|s!x=|ddD]+} t'j*| dkr|j+| qqW|st'j,qq!n|ret'j-}|s=dSt(j.rnt'j/rn|j0j1qnn t'j2}|r|j3n|rt j4j5d+pt j4j5d,} | rt j j| r|j6j7| qn|s|rD|j6j8d-tjf|r|j6j9|qy|ry|j6j:||j6j7|qyn5|ryt(j;t}|ry|j6j8d.|qynxt'j<rtj=q|Wtj>tddS)0NTFrz c:deihnr:st:z Error: %s %srrz-cz-dz-ez-hz-iz-nz: Warning: running IDLE without a subprocess is deprecated.z-rzNo script file: z-sz-tr-rVrRrzeditor-on-startuprrZ classNameZIdleZIconsZWindowszidle.icorg!@g333333!@z.pngz.gifcs/g|]%}tjjd|fqS)z idle_%d%s)r>r?r@)rr)exticondirrrrs zmain..r 0cSsg|]}td|qS)r)Z PhotoImage)riconfilerrrr s Z IDLESTARTUPZ PYTHONSTARTUPzbif 1: import sys as _sys _sys.argv = %r del _sys z print('%s'))rrr)?r)r0getoptrargvrr usage_msgrexitrr"r>r?rrrarrrrabspathr`dirnamerggetcwdrrZrDr|r@__file__rZ wm_iconbitmapZ TkVersionZ wm_iconphotor rErr<rZsetupApprvrlnewr=ZisAquaTkdictrlowerrar\environrlrbr rrr ZtkVersionWarningZ inversedictrkZdestroy)Z enable_shellZ enable_editrecmdZscriptZstartupZoptsrDr!oardZpathxrdirZ edit_startrZ iconfilesZiconsr=Ztkversionwarningr)rrrrRs )                         $      !             rRrF)Hrr>os.pathryrrrrrr tracebacktypesrBrrrrerrrg ImportErrorrrrZtkinter.messageboxZ messageboxr}Zidlelib.EditorWindowrr Zidlelib.FileListr Zidlelib.ColorDelegatorr Zidlelib.UndoDelegatorr Zidlelib.OutputWindowr Zidlelib.configHandlerrrrrrrrrrr!r'r r%r&r) checkcacher1r2rrrZ RPCClientrrr TextIOBaserrSrQrrRrrrrrrs~                     h