3 § f¡ã@s€dZddlZddlZddlZddljZddlmZddl m Z ddl m Z dZ Gdd„dƒZ ed kr|dd lmZed d d �dS)a‹Execute 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@sTeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dS)Ú ScriptBindingcCs8||_|jj|_|jj|_tjƒr4|jjjd|jƒdS)Nz<>)ÚeditwinÚflistÚrootrÚ isCocoaTkÚ text_frameZbindÚ_run_module_event)Úselfr©r ú6/opt/alt/python36/lib64/python3.6/idlelib/runscript.pyÚ__init__#s   zScriptBinding.__init__cCs0|jƒ}|sdS|j|ƒsdS|j|ƒs,dSdS)NÚbreak)Ú getfilenameÚ checksyntaxÚtabnanny)r ÚeventÚfilenamer r rÚcheck_module_event-s  z ScriptBinding.check_module_eventcCsºtj|ƒ�¦}ytjtj|jƒƒWnˆtjk 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)ÚtokenizeÚopenrZprocess_tokensÚgenerate_tokensÚreadlineÚ TokenErrorÚargsrZgotolineÚerrorboxZNannyNagZ get_linenoÚindent_message)r rÚfÚmsgZmsgtxtÚlinenoÚstartZnagr r rr7s    zScriptBinding.tabnannyc CsZ|jjƒ|_}|jƒ}|j|jƒt|dƒ�}|jƒ}WdQRXd|krb|jddƒ}|jddƒ}|r~|dt dƒkr~|d}|j }|j }|j dddƒz°y t ||d ƒStttfk �rD}zzt|d d ƒpÒ|pÒd } t|d d ƒpâd} t|dd ƒpòd} | dk�r| d7} d| d| df} |j|| ƒ|jdd| ƒdSd}~XnXWd|j|ƒXdS)NÚrbó s ó éZERRORz1.0ÚendÚexecr Úzr!Úoffsetrz0.0 + %d lines + %d charsÚ SyntaxErrorz%-20sFéÿÿÿÿ)rZ open_shellÚshellZget_warning_streamZset_warning_streamÚstderrrÚreadÚreplaceÚordrÚtextZ tag_removeÚcompiler+Ú OverflowErrorÚ ValueErrorÚgetattrZcolorize_syntax_errorr) r rr-Z saved_streamrÚsourcerr2Úvaluer r!r*Úposr r rrIs4       zScriptBinding.checksyntaxcs2tjƒr$ˆjjjd‡fdd„ƒdSˆj|ƒSdS)NéÈcsˆjjjdƒS)Nz<>)rr Zevent_generater )r r rÚosz0ScriptBinding.run_module_event..r)rr rr Úafterr )r rr )r rÚrun_module_eventgs  zScriptBinding.run_module_eventcCsŒ|jƒ}|sdS|j|ƒ}|s"dS|j|ƒs0dS|jj}tjrT|jd|jj |ƒd�t 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 )rÚdirname)rrrr-ÚinterprZuse_subprocessZrestart_subprocessrZ_filename_to_unicodeÚosÚpathr>Z runcommandÚformatZprepend_syspathZruncode)r rrÚcoder?r>r r rr ts$       zScriptBinding._run_module_eventcCsx|jjj}|jjƒsttjddddd�}|r>|r>|jjjdƒn6|jƒ}|jjj ƒ|rp|jjjdƒ|jjj}nd}|S)a±Get 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. ÚmainZGeneralÚautosaveÚbool)ÚtypeN) rÚiorZ get_savedrZ GetOptionZsaveÚask_save_dialogr2Ú focus_set)r rrEÚconfirmr r rr�s     zScriptBinding.getfilenamecCs d }tjd|tj|jjd�}|S) NzSource Must Be Saved éú z OK to Save?zSave Before Run or Check)ÚtitleÚmessageÚdefaultÚparentz zSource Must Be Saved z%Source Must Be Saved OK to Save?)Ú tkMessageBoxZ askokcancelZOKrr2)r r rKr r rrI¸s  zScriptBinding.ask_save_dialogcCs$tj|||jjd�|jjjƒdS)N)rQ)rRZ showerrorrr2rJ)r rNrOr r rrÀszScriptBinding.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    &