�`^c@s�dZddlZddlZddlZddlZddlZddlZddlmZddl m
Z
ddlmZejej
dZdZdd
d ��YZdS(s?Extension to execute code outside the Python shell window.
This adds the following commands:
- Check module does a full syntax check of the current module.
It also runs the tabnanny to catch any inconsistent tabs.
- Run module executes 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.
XXX GvR Redesign this interface (yet again) as follows:
- Present a dialog box for ``Run Module''
- Allow specify command line arguments in the dialog box
i�N(tPyShell(tidleConf(t
macosxSupportt_s/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.
t
ScriptBindingcBs�eZddddgfgZd�Zd�Zd�Zd�Zd �Zd
�Z e
j�rre Zd�Z nd�Z
d
�Zd�ZRS(trunsCheck Modules<<check-module>>s
Run Modules<<run-module>>cCsS||_|jj|_|jj|_tj�rO|jjjd|j�ndS(Ns<<run-module-event-2>>(teditwintflisttrootRt isCocoaTkt
text_frametbindt_run_module_event(tselfR((s+/sys/lib/python2.7/idlelib/ScriptBinding.pyt__init__2s
cCs@|j�}|sdS|j|�s)dS|j|�s<dSdS(Ntbreak(tgetfilenametchecksyntaxttabnanny(R
teventtfilename((s+/sys/lib/python2.7/idlelib/ScriptBinding.pytcheck_module_event<scCs�t|d�}ytjtj|j��Wn�tjk
r{}|\}\}}|jj|�|j dd|�t
Stjk
r�}|jj|j��|j dt
�t
SXtS(NtrsTabnanny Tokenizing ErrorsToken Error: %ssTab/space error(topenRtprocess_tokensttokenizetgenerate_tokenstreadlinet
TokenErrorRtgotolineterrorboxtFalsetNannyNagt
get_linenotindent_messagetTrue(R
Rtftmsgtmsgtxttlinenotstarttnag((s+/sys/lib/python2.7/idlelib/ScriptBinding.pyREs c
Cs�|jj�|_}|j�}|j|j�t|d��}|j�}WdQXd|kr�tj dd|�}tj dd|�}n|r�|ddkr�|d}n|j
j}|jddd �z�yt
||d
�SWn�tttfk
r�}y\|\}\} }
}}| sK|||
||ff|_||_n|j||
|�Wndt|�}nX|jdd
|�tSXWd|j|�XdS(NRs
s\r\ns
s\ri�tERRORs1.0tendtexecs*** sSyntax errors"There's an error in your program:
(Rt
open_shelltshelltget_warning_streamtset_warning_streamtstderrRtreadtretsubRttextt
tag_removetcompiletSyntaxErrort
OverflowErrort
ValueErrortargsRtcolorize_syntax_errortstrRR(
R
RR.tsaved_streamR$tsourceR5terrR%t
errorfilenameR'toffsettline((s+/sys/lib/python2.7/idlelib/ScriptBinding.pyRVs8
cCs�|jj}d|d|df}|jd|�|j|�}|ro|tkro|jd|d|�nd|j|�kr�|jd|�n|jd|d�|j|�dS(Ns0.0 + %d lines + %d charsiR*s
wordstarts
tinserts+1c(RR5ttag_addtgett
IDENTCHARStmark_settsee(R
R%R'RBR5tpostchar((s+/sys/lib/python2.7/idlelib/ScriptBinding.pyR<vscCs�|j�}|sdS|j|�}|s/dS|j|�sBdS|jj}tjrj|jdt�nt j
j|�}|jdj
d|d|��|j|�|j|�dS(sYRun 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.
Rtwith_cwdszif 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
Rtdirname(RRRR.tinterpRtuse_subprocesstrestart_subprocessRtostpathRMt
runcommandtformattprepend_syspathtruncode(R
RRtcodeRNRM((s+/sys/lib/python2.7/idlelib/ScriptBinding.pytrun_module_event�s"
cs#�jjjd�fd��dS(Ni�cs�jjjd�S(Ns<<run-module-event-2>>(RR
tevent_generate((R
(s+/sys/lib/python2.7/idlelib/ScriptBinding.pyt<lambda>�sR(RR
tafter(R
R((R
s+/sys/lib/python2.7/idlelib/ScriptBinding.pyRX�scCs�|jjj}|jj�s�tjddddd�}|r[|r[|jjjd�q�|j�}|jj j
�|r�|jjjd�|jjj}q�d}n|S(s�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.
tmaintGeneraltautosavettypetboolN(RtioRt get_savedRt GetOptiontsavetNonetask_save_dialogR5t focus_set(R
RR^tconfirm((s+/sys/lib/python2.7/idlelib/ScriptBinding.pyR�s c Cs?dd
d}tjddd|dtjd |jj�}|S(NsSource Must Be Saved
it sOK to Save?ttitlesSave Before Run or Checktmessagetdefaulttmasters (ttkMessageBoxtaskokcanceltOKRR5(R
R%Rh((s+/sys/lib/python2.7/idlelib/ScriptBinding.pyRf�s cCs0tj||d|jj�|jjj�dS(NRm(Rnt showerrorRR5Rg(R
RjRk((s+/sys/lib/python2.7/idlelib/ScriptBinding.pyR�sN(sCheck Modules<<check-module>>(s
Run Modules<<run-module>>(t__name__t
__module__RetmenudefsRRRRR<RXRR RRRfR(((s+/sys/lib/python2.7/idlelib/ScriptBinding.pyR+s
( ((t__doc__RQR3tstringRRRntidlelibRtidlelib.configHandlerRRt
ascii_letterstdigitsRGR"R(((s+/sys/lib/python2.7/idlelib/ScriptBinding.pyt<module>s
|