3  f@sdZddlZddlZddlZddljZddlmZddl m Z ddl m Z dZ GdddZ ed kr|dd lmZed d d dS)aExecute code from an editor. Check module: do a full syntax check of the current module. Also run the tabnanny to catch any inconsistent tabs. Run module: also execute the module's code in the __main__ namespace. The window must have been saved previously. The module is added to sys.modules, and is also added to the __main__ namespace. TODO: Specify command line arguments in a dialog box. N)idleConf)macosx)pyshella/Error: Inconsistent indentation detected! 1) Your indentation is outright incorrect (easy to fix), OR 2) Your indentation mixes tabs and spaces. To fix case 2, change all tabs to spaces by using Edit->Select All followed by Format->Untabify Region and specify the number of columns used by each tab. c@sTeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ dS) ScriptBindingcCs8||_|jj|_|jj|_tjr4|jjjd|jdS)Nz<>)editwinflistrootr isCocoaTk text_frameZbind_run_module_event)selfrr 6/opt/alt/python36/lib64/python3.6/idlelib/runscript.py__init__#s   zScriptBinding.__init__cCs0|j}|sdS|j|sdS|j|s,dSdS)Nbreak) getfilename checksyntaxtabnanny)r eventfilenamer r rcheck_module_event-s  z ScriptBinding.check_module_eventcCstj|}ytjtj|jWntjk rn}z.|j\}\}}|jj ||j dd|dSd}~Xn>tj k r}z |jj |j |j dt dSd}~XnXWdQRXdS)NzTabnanny Tokenizing ErrorzToken Error: %sFzTab/space errorT)tokenizeopenrZprocess_tokensgenerate_tokensreadline TokenErrorargsrZgotolineerrorboxZNannyNagZ get_linenoindent_message)r rfmsgZmsgtxtlinenostartZnagr r rr7s    zScriptBinding.tabnannyc CsZ|jj|_}|j}|j|jt|d}|j}WdQRXd|krb|jdd}|jdd}|r~|dt dkr~|d}|j }|j }|j dddzy t ||d Stttfk rD}zzt|d d p|pd } t|d d pd} t|dd pd} | dkr| d7} d| d| df} |j|| |jdd| dSd}~XnXWd|j|XdS)Nrb s  ZERRORz1.0endexecr zr!offsetrz0.0 + %d lines + %d chars SyntaxErrorz%-20sF)rZ open_shellshellZget_warning_streamZset_warning_streamstderrrreadreplaceordrtextZ tag_removecompiler+ OverflowError ValueErrorgetattrZcolorize_syntax_errorr) r rr-Z saved_streamrsourcerr2valuer r!r*posr r rrIs4       zScriptBinding.checksyntaxcs2tjr$jjjdfdddSj|SdS)NcsjjjdS)Nz<>)rr Zevent_generater )r r rosz0ScriptBinding.run_module_event..r)rr rr afterr )r rr )r rrun_module_eventgs  zScriptBinding.run_module_eventcCs|j}|sdS|j|}|s"dS|j|s0dS|jj}tjrT|jd|jj |dt j j |}|j dj||d|j||j|dS)aXRun the module after setting up the environment. First check the syntax. If OK, make sure the shell is active and then transfer the arguments, set the run environment's working directory to the directory of the module being executed and also add that directory to its sys.path if not already included. rF)Zwith_cwdrazif 1: __file__ = {filename!r} import sys as _sys from os.path import basename as _basename if (not _sys.argv or _basename(_sys.argv[0]) != _basename(__file__)): _sys.argv = [__file__] import os as _os _os.chdir({dirname!r}) del _sys, _basename, _os )rdirname)rrrr-interprZuse_subprocessZrestart_subprocessrZ_filename_to_unicodeospathr>Z runcommandformatZprepend_syspathZruncode)r rrcoder?r>r r rr ts$       zScriptBinding._run_module_eventcCsx|jjj}|jjsttjddddd}|r>|r>|jjjdn6|j}|jjj |rp|jjjd|jjj}nd}|S)aGet source filename. If not saved, offer to save (or create) file The debugger requires a source file. Make sure there is one, and that the current version of the source buffer has been saved. If the user declines to save or cancels the Save As dialog, return None. If the user has configured IDLE for Autosave, the file will be silently saved if it already exists and is dirty. mainZGeneralautosavebool)typeN) riorZ get_savedrZ GetOptionZsaveask_save_dialogr2 focus_set)r rrEconfirmr r rrs     zScriptBinding.getfilenamecCs d }tjd|tj|jjd}|S) NzSource Must Be Saved  z OK to Save?zSave Before Run or Check)titlemessagedefaultparentz zSource Must Be Saved z%Source Must Be Saved OK to Save?) tkMessageBoxZ askokcancelZOKrr2)r r rKr r rrIs  zScriptBinding.ask_save_dialogcCs$tj|||jjd|jjjdS)N)rQ)rRZ showerrorrr2rJ)r rNrOr r rrszScriptBinding.errorboxN) __name__ __module__ __qualname__rrrrr=r rrIrr r r rr!s   )r__main__)rDz idlelib.idle_test.test_runscript) verbosity)__doc__r@rrZtkinter.messageboxZ messageboxrRZidlelib.configrZidlelibrrrrrSZunittestrDr r r r s    &