ó
®«Y]c           @   s¯   d  Z  d d l Z d d l 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 e j e j d Z d Z d d
 d	 „  ƒ  YZ d S(   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(   t   PyShell(   t   idleConf(   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   ScriptBindingc           B   s   e  Z d  d d d g f g Z d „  Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z	 e
 j ƒ  rr e	 Z d „  Z	 n  d „  Z d „  Z d „  Z RS(   t   runs   Check Modules   <<check-module>>s
   Run Modules   <<run-module>>c         C   sS   | |  _  |  j  j |  _ |  j  j |  _ t j ƒ  rO |  j  j j d |  j ƒ n  d  S(   Ns   <<run-module-event-2>>(   t   editwint   flistt   rootR   t	   isCocoaTkt
   text_framet   bindt   _run_module_event(   t   selfR   (    (    s&   lib/python2.7/idlelib/ScriptBinding.pyt   __init__2   s
    	c         C   s@   |  j  ƒ  } | s d S|  j | ƒ s) d S|  j | ƒ s< d Sd  S(   Nt   break(   t   getfilenamet   checksyntaxt   tabnanny(   R   t   eventt   filename(    (    s&   lib/python2.7/idlelib/ScriptBinding.pyt   check_module_event<   s    c         C   s¿   t  | d ƒ } y t j t j | j ƒ ƒ WnŒ t j k
 r~ } | j \ } \ } } |  j j	 | ƒ |  j
 d d | ƒ t St j k
 rº } |  j j	 | j ƒ  ƒ |  j
 d t ƒ t SXt S(   Nt   rs   Tabnanny Tokenizing Errors   Token Error: %ss   Tab/space error(   t   openR   t   process_tokenst   tokenizet   generate_tokenst   readlinet
   TokenErrort   argsR   t   gotolinet   errorboxt   Falset   NannyNagt
   get_linenot   indent_messaget   True(   R   R   t   ft   msgt   msgtxtt   linenot   startt   nag(    (    s&   lib/python2.7/idlelib/ScriptBinding.pyR   E   s    	c         C   s¨  |  j  j ƒ  |  _ } | j ƒ  } | j | j ƒ t | d ƒ  } | j ƒ  } Wd  QXd | k r t j	 d d | ƒ } t j	 d d | ƒ } n  | r² | d d k r² | d } n  |  j
 j } | j d d d	 ƒ zÂ y t | | d
 ƒ SWn§ t t t f k
 r‘} y\ | \ } \ }	 }
 } } |	 sK| | |
 | | f f | _ | | _ n  |  j | |
 | ƒ Wn d t | ƒ } n X|  j d d | ƒ t SXWd  | j | ƒ Xd  S(   NR   s   s   \r\ns   
s   \riÿÿÿÿt   ERRORs   1.0t   endt   execs   *** s   Syntax errors"   There's an error in your program:
(   R   t
   open_shellt   shellt   get_warning_streamt   set_warning_streamt   stderrR   t   readt   ret   subR   t   textt
   tag_removet   compilet   SyntaxErrort   OverflowErrort
   ValueErrorR   R   t   colorize_syntax_errort   strR   R    (   R   R   R/   t   saved_streamR%   t   sourceR6   t   errR&   t   errorfilenameR(   t   offsett   line(    (    s&   lib/python2.7/idlelib/ScriptBinding.pyR   V   s8    		c         C   s¼   |  j  j } d | d | d f } | j d | ƒ | j | ƒ } | ro | t k ro | j d | d | ƒ n  d | j | ƒ k r— | j d | ƒ n | j d | d ƒ | j | ƒ d  S(   Ns   0.0 + %d lines + %d charsi   R+   s
    wordstarts   
t   inserts   +1c(   R   R6   t   tag_addt   gett
   IDENTCHARSt   mark_sett   see(   R   R&   R(   RB   R6   t   post   char(    (    s&   lib/python2.7/idlelib/ScriptBinding.pyR<   v   s    c         C   sÂ   |  j  ƒ  } | s d S|  j | ƒ } | s/ d S|  j | ƒ sB d S|  j j } t j rs | j d t d | j	 ƒ n  t
 j j | ƒ } | j d j d | d | ƒ ƒ | j | ƒ | j | ƒ d S(   sY  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   t   with_cwdR   sz  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
            
t   dirname(   R   R   R   R/   t   interpR    t   use_subprocesst   restart_subprocessR    t   co_filenamet   ost   pathRM   t
   runcommandt   formatt   prepend_syspatht   runcode(   R   R   R   t   codeRN   RM   (    (    s&   lib/python2.7/idlelib/ScriptBinding.pyt   run_module_eventƒ   s"    		
c            s#   ˆ  j  j j d ‡  f d †  ƒ d S(   NiÈ   c              s   ˆ  j  j j d ƒ S(   Ns   <<run-module-event-2>>(   R   R
   t   event_generate(    (   R   (    s&   lib/python2.7/idlelib/ScriptBinding.pyt   <lambda>µ   t    R   (   R   R
   t   after(   R   R   (    (   R   s&   lib/python2.7/idlelib/ScriptBinding.pyRY   ³   s    c         C   s¯   |  j  j j } |  j  j ƒ  s« t j d d d d d ƒ} | r[ | r[ |  j  j j d ƒ q« |  j ƒ  } |  j  j	 j
 ƒ  | r¢ |  j  j j d ƒ |  j  j j } 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.

        t   maint   Generalt   autosavet   typet   boolN(   R   t   ioR   t	   get_savedR   t	   GetOptiont   savet   Nonet   ask_save_dialogR6   t	   focus_set(   R   R   R`   t   confirm(    (    s&   lib/python2.7/idlelib/ScriptBinding.pyR   ¸   s    	c      	   C   s?   d d
 d } t  j d d d | d t  j d	 |  j j ƒ } | S(   Ns   Source Must Be Saved
i   t    s   OK to Save?t   titles   Save Before Run or Checkt   messaget   defaultt   parents        (   t   tkMessageBoxt   askokcancelt   OKR   R6   (   R   R&   Rj   (    (    s&   lib/python2.7/idlelib/ScriptBinding.pyRh   Ó   s    	c         C   s0   t  j | | d |  j j ƒ|  j j j ƒ  d  S(   NRo   (   Rp   t	   showerrorR   R6   Ri   (   R   Rl   Rm   (    (    s&   lib/python2.7/idlelib/ScriptBinding.pyR   Û   s    N(   s   Check Modules   <<check-module>>(   s
   Run Modules   <<run-module>>(   t   __name__t
   __module__Rg   t   menudefsR   R   R   R   R<   RY   R   R	   R   R   Rh   R   (    (    (    s&   lib/python2.7/idlelib/ScriptBinding.pyR   +   s   	
				 		(		(    (   t   __doc__RR   R4   t   stringR   R   Rp   t   idlelibR    t   idlelib.configHandlerR   R   t   ascii_letterst   digitsRG   R#   R   (    (    (    s&   lib/python2.7/idlelib/ScriptBinding.pyt   <module>   s   
