łň
B3IHc           @   s;  d  d k  Z  e  i i   Z d e d <d e d <d e d <e d <d	 e d
 <e d e Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d d e i
 d d  Z d d  Z d   Z d   Z d  d k Z d  d k Z d  d k Z d   Z d d  Z d e e d  Z e e d  Z d e e d  Z d S(   i˙˙˙˙Ns   Mark Hammondt   authors-   (c) Mark Hammond (See PythonWin distribution)t	   copyrightt   scriptutilst   titlet	   titleFullsU   Changes:
    - may 2003: www.stani.be to make it platform and PythonWin independent.
t   descriptiont   doci    c         B   s  d d  k  } Hd } d } d  } yŔ|  og e i i |   \ } }	 | oD | e i j o e i i d |  n e i   } e i |  q n | oJ e	 |  e
 i j o | i e i   d  } n d | } d }  }	 nX e |  d  }
 |
 i   } |
 i   e	 |  e
 i j o | i e i   d  } n e | i d d  d |  d	  } | oo d d  k } d d  k } | i   } | | d
 <| i d e   |  } | i |  } | i d d  i   n	 | | Ud } WnS e j
 o } | } d } n4 e j
 o | i   d } n | i   n Xy e i i   Wn e  j
 o n X| o d |	 | f GHn
 d |	 GH| o e i |  n d  S(   Ni˙˙˙˙i    t   replaces   __name__="__main__"
%ss   <source>t   rs   
s   
t   exect
   codeObjects   exec codeObject in mainDictt   cumt   timei   s!   Script '%s' returned exit code %ss)   Exception raised while running script  %s(!   t	   tracebackt   Nonet   ost   patht   splitt   syst   insertt   getcwdt   chdirt   typet   typest   UnicodeTypet   encodet   getdefaultencodingt   opent   readt   closet   compileR   t   profilet   pstatst   Profilet   runctxt   localst   Statst
   sort_statst   print_statst
   SystemExitt   KeyboardInterruptt	   print_exct   stdoutt   flusht   AttributeError(   t   fileNamet   sourcet   mainDictt	   profilingR   t   bWorkedt   exitCodet   osPathR   t   baset   fR
   R   R    t   proft   statst   code(    (    s   C:\py\_spe\sm\scriptutils.pyt   run   sd     

"




	c         B   sE  d d  k  } d d  k } d d  k } d d  k } H| i i |   \ } } | i i |  \ } } d  }	 xě | i i	   D] \ }
 } e
 | d  o | i } | i i |  \ } } | i |  d j o
 d } n | | } | i i |  | i i |   j o |
 } Pqqw qw We |   \ } }	 |	 o' |	 | i j o | i i d |	  n | i i |  o d } d } n d	 } d } y | | i j o | i i |  n e d
 | d d  } | p | i } n | | U| o e | i |  n d | d | d GHWn. e j
 o" } d | d | d | GHn Xd  S(   Ni˙˙˙˙t   __file__s   .pyos   .pycs   .pyi    i   t   reloadt   imports   import s   <auto import>R	   s   Successfully s   ed module "t   "s
   Failed to s	    module "s   " (%s)(   s   .pyos   .pyc(   R   t   stringR   t   __main__R   R   t   splitextR   t   modulest   itemst   hasattrR:   t   lowert   abspatht   GetPackageModuleNameR   t   has_keyt   appendR   t   __dict__R;   t	   Exception(   t   pathNameR/   R   R>   R   R?   R   t   modNamet   modExtt   newPatht   keyt   modt   fnameR4   t   extt   bNeedReloadt   whatt   codeObjt   message(    (    s   C:\py\_spe\sm\scriptutils.pyt	   importModL   sH    0 	

%
  c   	      C   sk  d d k  } d d k } | i i |   \ } } | } | i i |  d } g  } d } t |  pü xů t |  d j oŰ | i i |  \ } } | i |  t |  oĽ t	 i
 i |  o | i i | i i | d   pD | i i | i i | d   p" | i i | i i | d   o, | i   | i | d  d | | f Sqh qh W| } n | | f S(	   sÁ   Given a filename, return (module name, new path).
       eg - given "c:\c\my.py", return ("b.c.my",None) if "c:" is on sys.path.
       If no package found, will return ("my", "c:\c")
    i˙˙˙˙Ni    i   s   __init__.pys   __init__.pycs   __init__.pyot   .(   R   R>   R   R   R@   R   t   IsOnPythonPatht   lenRH   R   RA   RG   t   existst   joint   reverse(	   R-   R   R>   R   RQ   t   origPatht   modBitst   newPathReturnt   modBit(    (    s   C:\py\_spe\sm\scriptutils.pyRF   t   s&      """
'
c         C   sj   d d k  } d d k } xK | i D]@ } y | o d Sn Wq" t j
 o } d | | f GHq" Xq" Wd S(   sU   Given a path only, see if it is on the Pythonpath.  Assumes path is a full path spec.i˙˙˙˙Ni   s.   Warning: The sys.path entry '%s' is invalid
%si    (   R   R   R   RJ   (   R   R   R   t   syspatht   details(    (    s   C:\py\_spe\sm\scriptutils.pyRY      s    
 c         C   s	   |  GHd  S(   N(    (   t   x(    (    s   C:\py\_spe\sm\scriptutils.pyt   smPrintStatusŁ   s    i   c         C   s   d |  | | f GHd  S(   Ns)   -> fileName = "%s", lineno = %s, col = %s(    (   R-   t   linenot   col(    (    s   C:\py\_spe\sm\scriptutils.pyt   smJumpToPositionŚ   s    c   	      C   s<  d } | | d  | p] y t  |   } Wn( t j
 o } d |  | f GHd Sn Xz | i   } Wd | i   Xn | i d d  d } yU t | |  d  } t |  d | d	 | o& | d
 t i i	 |   d  d Sn WnR t
 j
 o  t | |  d | d	 | n( t i   t | d | d	 | n Xd S(   sď    This code looks for the current window, and gets Python to check it
    without actually executing any code (ie, by compiling only)

    status: function to set statusbar, otherwise print
    jump: function(fileName, lineno, col = 1)
    t   checks   ing module...s   Can't open file '%s' - %sNs   
s   
R	   t   statust   jumps7   Python and the TabNanny successfully checked the file 't   'i   (   R   t   IOErrorR   R   R   R   t   RunTabNannyR   R   t   basenamet   SyntaxErrort   _HandlePythonFailureR   R)   (	   RK   R.   Rj   Rk   RT   R5   Rc   R8   RU   (    (    s   C:\py\_spe\sm\scriptutils.pyt	   CheckFileŞ   s.    	
c   
      C   s  y d d  k  } d d  k } Wn t j
 o } | GHn X| i   } t i t i f } | t _ t _ z | i |   Wd  | \ t _ t _ X| i   } | oo y> t	 i
 |  d }	 t |	  }	 | d |	  | |  |	  Wn& t t t f j
 o d GH| GHn Xd Sn d S(   Ni˙˙˙˙i   s%   The TabNanny found trouble at line %ds/   The tab nanny complained, but I cant see where!i    (   t	   cStringIOt   tabnannyRJ   t   StringIOR   t   stderrR*   Ri   t   getvalueR>   R   t   intt
   IndexErrort	   TypeErrort
   ValueError(
   t   filenameRj   Rk   Rs   Rt   RV   t   newoutt   old_outt   dataRf   (    (    s   C:\py\_spe\sm\scriptutils.pyRn   Ę   s,    

c         C   sć   t  i   \ } } } | t j o yR | \ } \ } }	 }
 } | p | d j o | o
 | } n | | |	 |
  Wn% t t f j
 o t |  } n X| d |  d |  n' t i   | d |  d t |   d  } d  S(   Ns   <string>s   <source>s
   Failed to s    - syntax error - %ss    - (   s   <string>s   <source>(	   R   t   exc_infoRp   Rz   R{   t   strR   R)   R   (   RT   t   syntaxErrorPathNameRj   Rk   t   typRc   t   tbt   msgR-   t   lineRg   t   text(    (    s   C:\py\_spe\sm\scriptutils.pyRq   ĺ   s    

(   t   smt   INFOt   copyt   __doc__R>   R   R   R   R?   R   RI   R9   RW   RF   RY   R   Re   Rh   Rr   Rn   Rq   (    (    (    s   C:\py\_spe\sm\scriptutils.pys   <module>   s&   


08(		$	 