3
f @ s d Z ddlZddlZddlZddljZddlmZ ddl m
Z
ddl mZ dZG dd dZ
ed kr|dd
lmZ eddd
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 @ sT e Zd Zdd Zdd Zdd Zdd Zd d
Zdd Zd
d Z dd Z
dd ZdS )
ScriptBindingc C s8 || _ | j j| _| j j| _tj r4| j jjd| j d S )Nz<>)editwinflistrootr isCocoaTk
text_frameZbind_run_module_event)selfr r
6/opt/alt/python36/lib64/python3.6/idlelib/runscript.py__init__# s
zScriptBinding.__init__c C s0 | j }|sdS | j|sdS | j|s,dS dS )Nbreak)getfilenamechecksyntaxtabnanny)r eventfilenamer
r
r check_module_event- s
z ScriptBinding.check_module_eventc C s t j|}ytjt j|j W n t jk
rn } z.|j\}\}}| jj | | j
dd| dS d }~X n> tjk
r } z | jj |j | j
dt
dS d }~X nX W d Q R X dS )NzTabnanny Tokenizing ErrorzToken Error: %sFzTab/space errorT)tokenizeopenr Zprocess_tokensgenerate_tokensreadline
TokenErrorargsr ZgotolineerrorboxZNannyNagZ
get_linenoindent_message)r r fmsgZmsgtxtlinenostartZnagr
r
r r 7 s
zScriptBinding.tabnannyc
C sZ | j j | _}|j }|j|j t|d}|j }W d Q R X d|krb|jdd}|jdd}|r~|d t dkr~|d }| j
}|j}|jddd zyt
||d S tttfk
rD } zzt|d
dp|pd} t|d
dpd}
t|ddpd}|dkr|
d7 }
d|
d |d f }|j|| | jdd| dS d }~X nX W d |j| X d S )Nrb
s
ZERRORz1.0endexecr zr! offsetr z0.0 + %d lines + %d charsSyntaxErrorz%-20sF)r Z
open_shellshellZget_warning_streamZset_warning_streamstderrr readreplaceordr textZ
tag_removecompiler+
OverflowError
ValueErrorgetattrZcolorize_syntax_errorr )
r r r- Zsaved_streamr sourcer r2 valuer r! r* posr
r
r r I s4
zScriptBinding.checksyntaxc s2 t j r$ jjjd fdd dS j|S d S )N c s j jjdS )Nz<>)r r
Zevent_generater
)r r
r o s z0ScriptBinding.run_module_event..r )r r r r
afterr )r r r
)r r run_module_eventg s
zScriptBinding.run_module_eventc C s | j }|sdS | j|}|s"dS | j|s0dS | jj}tjrT|jd| jj |d t
jj|}|j
dj||d |j| |j| dS )aX Run 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.
r F)Zwith_cwdr az if 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)r r r r- interpr Zuse_subprocessZrestart_subprocessr Z_filename_to_unicodeospathr> Z
runcommandformatZprepend_syspathZruncode)r r r coder? r> r
r
r r t s$
zScriptBinding._run_module_eventc C sx | j jj}| j j sttjddddd}|r>|r>| j jjd n6| j }| j jj |rp| j jjd | j jj}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.
mainZGeneralautosavebool)typeN)
r ior Z get_savedr Z GetOptionZsaveask_save_dialogr2 focus_set)r r rE confirmr
r
r r s
zScriptBinding.getfilenamec C s d }t jd|t j| jjd}|S )
NzSource Must Be Saved
zOK to Save?zSave Before Run or Check)titlemessagedefaultparentz zSource Must Be Saved
z%Source Must Be Saved
OK to Save?)tkMessageBoxZaskokcancelZOKr r2 )r r rK r
r
r rI s zScriptBinding.ask_save_dialogc C s$ t j||| jjd | jjj d S )N)rQ )rR Z showerrorr r2 rJ )r rN rO r
r
r r s zScriptBinding.errorboxN)__name__
__module____qualname__r r r r r= r r rI r r
r
r
r r ! s
)r __main__)rD z idlelib.idle_test.test_runscript ) verbosity)__doc__r@ r r Ztkinter.messageboxZ
messageboxrR Zidlelib.configr Zidlelibr r r r rS ZunittestrD r
r
r
r s
&