a
    IfQ                      @   s   d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl	m
Z
 ddl	mZ ddlmZ ddl	mZ d	ZG d
d dZedkrddlmZ eddd dS )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)
messagebox)idleConf)macosx)pyshell)	CustomRun)outwina/  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                   @   sZ   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZddddZdd Z	dd Z
dd ZdS )ScriptBindingc                 C   s*   || _ | j j| _| j j| _g | _d| _d S )Ng        )editwinflistrootcli_argsperf)selfr	    r   "lib/python3.9/idlelib/runscript.py__init__&   s
    

zScriptBinding.__init__c                 C   sN   t | jtjr| jj  dS |  }|s.dS | |s<dS | |sJdS dS )Nbreak)	
isinstancer	   r   OutputWindowtextbellgetfilenamechecksyntaxtabnanny)r   eventfilenamer   r   r   check_module_event0   s    

z ScriptBinding.check_module_eventc                 C   s   t |}ztt |j W n t jy } zD|j\}\}}| j	| | 
dd|  W Y d }~W d    dS d }~0  tjy } z6| j	|  | 
dt W Y d }~W d    dS d }~0 0 W d    n1 s0    Y  dS )NzTabnanny Tokenizing ErrorzToken Error: %sFzTab/space errorT)tokenizeopenr   Zprocess_tokensgenerate_tokensreadline
TokenErrorargsr	   ZgotolineerrorboxZNannyNagZ
get_linenoindent_message)r   r   fmsgZmsgtxtlinenostartZnagr   r   r   r   =   s    "BzScriptBinding.tabnannyc              
   C   s  | j   | _}| }||j t|d}| }W d    n1 sL0    Y  d|v rv|dd}|dd}|r|d t	dkr|d }| j
}|j}|ddd zzt||d	W W || S  tttfy| } zt|d
dp|pd}	t|ddpd}
t|ddpd}|dkr*|
d7 }
d|
d |d f }||| | dd|	  W Y d }~W || dS d }~0 0 W || n|| 0 d S )Nrb   s   
   
ZERRORz1.0endexecr&    z<no detail available>r'      offsetr   z0.0 + %d lines + %d charsSyntaxErrorz%-20sF)r
   Z
open_shellshellZget_warning_streamZset_warning_streamstderrr   readreplaceordr	   r   Z
tag_removecompiler2   OverflowError
ValueErrorgetattrZcolorize_syntax_errorr#   )r   r   r3   Zsaved_streamr%   sourcer	   r   valuer&   r'   r1   posr   r   r   r   O   s<    &


zScriptBinding.checksyntaxc                 C   s   | j |ddS )NT	customize)run_module_event)r   r   r   r   r   run_custom_eventm   s    zScriptBinding.run_custom_eventFr?   c             	   C   s.  t  rt | j dk rdS t| jtjr<| jj	
  dS |  }|sLdS | |}|s^dS | |sldS |rd| j  d}t| jj	|| jdj}|sdS |r|ng df\| _}| jj}tjr|r|jd|d tj|}	|g}
| jr|
| j7 }
|d	|d
|
d|	d || || dS )ay  Run the module after setting up the environment.

        First check the syntax.  Next get customization.  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.
        g?r   z
Customize z Run)r   TF)Zwith_cwdr   zif 1:
            __file__ = zi
            import sys as _sys
            from os.path import basename as _basename
            argv = z
            if (not _sys.argv or
                _basename(_sys.argv[0]) != _basename(__file__) or
                len(argv) > 1):
                _sys.argv = argv
            import os as _os
            _os.chdir(z:)
            del _sys, argv, _basename, _os
            
)r   Z	isCocoaTktimeperf_counterr   r   r	   r   r   r   r   r   r   r   Zshort_titler   r3   r   resultinterpr   Zuse_subprocessZrestart_subprocessospathdirnameZ
runcommandZprepend_syspathZruncode)r   r   r@   r   codetitleZrun_argsZrestartrF   rI   argvr   r   r   rA   p   sP    	








zScriptBinding.run_module_eventc                 C   sx   | j jj}| j  sttjddddd}|r>|r>| j jd n6|  }| j j	  |rp| j jd | j jj}nd}|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.

        mainZGeneralautosavebool)typeN)
r	   ior   Z	get_savedr   Z	GetOptionZsaveask_save_dialogr   	focus_set)r   r   rN   confirmr   r   r   r      s    

zScriptBinding.getfilenamec                 C   s    d}t jd|t j| jjd}|S )Nz%Source Must Be Saved
     OK to Save?zSave Before Run or Check)rK   messagedefaultparent)r   ZaskokcancelZOKr	   r   )r   r&   rT   r   r   r   rR      s    zScriptBinding.ask_save_dialogc                 C   s.   t j||| jjd | jj  t | _d S )N)rW   )r   Z	showerrorr	   r   rS   rC   rD   r   )r   rK   rU   r   r   r   r#      s    zScriptBinding.errorboxN)__name__
__module____qualname__r   r   r   r   rB   rA   r   rR   r#   r   r   r   r   r   $   s   
9r   __main__)rM   z idlelib.idle_test.test_runscript   )	verbosity)__doc__rG   r   rC   r   Ztkinterr   Zidlelib.configr   Zidlelibr   r   Zidlelib.queryr   r   r$   r   rX   ZunittestrM   r   r   r   r   <module>   s     0