ó
è¾bc           @   s—  d  Z  d d l Z d d l Z d d l m Z y d d l m Z Wn! e k
 re d d l m Z n Xd d g Z d e f d „  ƒ  YZ	 d	 e f d
 „  ƒ  YZ
 d d d d d d „ Z d d d d d d „ Z d „  Z e d „ Z e d „ Z d e f d „  ƒ  YZ e d „ Z d d e d „ Z d „  Z d „  Z d d d „ Z e d k r“e e j ƒ d k  rue j d IJq“e j d =e e j d ƒ n  d S(   sZ  runpy.py - locating and running Python code using the module namespace

Provides support for locating and running Python scripts using the Python
module namespace instead of the native filesystem.

This allows Python code to play nicely with non-filesystem based PEP 302
importers when locating support scripts as well as when importing modules.
iÿÿÿÿN(   t	   read_code(   t
   get_loadert
   run_modulet   run_patht   _TempModulec           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sC   Temporarily replace a module in sys.modules with an empty namespacec         C   s(   | |  _  t j | ƒ |  _ g  |  _ d  S(   N(   t   mod_namet   impt
   new_modulet   modulet   _saved_module(   t   selfR   (    (    s   /usr/lib/python2.7/runpy.pyt   __init__   s    	c         C   sL   |  j  } y |  j j t j | ƒ Wn t k
 r7 n X|  j t j | <|  S(   N(   R   R	   t   appendt   syst   modulest   KeyErrorR   (   R
   R   (    (    s   /usr/lib/python2.7/runpy.pyt	   __enter__   s    	c         G   s=   |  j  r# |  j  d t j |  j <n t j |  j =g  |  _  d  S(   Ni    (   R	   R   R   R   (   R
   t   args(    (    s   /usr/lib/python2.7/runpy.pyt   __exit__(   s    	(   t   __name__t
   __module__t   __doc__R   R   R   (    (    (    s   /usr/lib/python2.7/runpy.pyR      s   			t   _ModifiedArgv0c           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   s    | |  _  t ƒ  |  _ |  _ d  S(   N(   t   valuet   objectt   _saved_valuet	   _sentinel(   R
   R   (    (    s   /usr/lib/python2.7/runpy.pyR   0   s    	c         C   sE   |  j  |  j k	 r! t d ƒ ‚ n  t j d |  _  |  j t j d <d  S(   Ns   Already preserving saved valuei    (   R   R   t   RuntimeErrorR   t   argvR   (   R
   (    (    s   /usr/lib/python2.7/runpy.pyR   4   s    c         G   s    |  j  |  _ |  j t j d <d  S(   Ni    (   R   R   R   R   R   (   R
   R   (    (    s   /usr/lib/python2.7/runpy.pyR   :   s    (   R   R   R   R   R   (    (    (    s   /usr/lib/python2.7/runpy.pyR   /   s   		c      	   B   sJ   | d k	 r | j | ƒ n  | j d | d | d | d | ƒ |  | U| S(   s)   Helper to run code in nominated namespaceR   t   __file__t
   __loader__t   __package__N(   t   Nonet   update(   t   codet   run_globalst   init_globalsR   t	   mod_fnamet
   mod_loadert   pkg_name(    (    s   /usr/lib/python2.7/runpy.pyt	   _run_code>   s    c         C   sZ   t  | ƒ B } t | ƒ - | j j } t |  | | | | | | ƒ Wd QXWd QX| j ƒ  S(   s5   Helper to run code in new namespace with sys modifiedN(   R   R   R   t   __dict__R(   t   copy(   R"   R$   R   R%   R&   R'   t   temp_modulet   mod_globals(    (    s   /usr/lib/python2.7/runpy.pyt   _run_module_codeK   s     c         C   s=   x6 d D]. } t  |  | d  ƒ } | d  k	 r | | ƒ Sq Wd  S(   Nt   get_filenamet   _get_filename(   R.   R/   (   t   getattrR    (   t   loaderR   t   attrt   meth(    (    s   /usr/lib/python2.7/runpy.pyR/   \   s
    c         C   sd  y> t  |  ƒ } | d  k r. | d |  ƒ ‚ n  | j |  ƒ } Wn% t k
 re } | t | ƒ ƒ ‚ n X| rë |  d k s‡ |  j d ƒ r– | d ƒ ‚ n  t |  ƒ y |  d } t | ƒ SWqë t k
 rç } | d d | |  f ƒ ‚ që Xn  y | j |  ƒ } Wn% t k
 r%} | t | ƒ ƒ ‚ n X| d  k rE| d |  ƒ ‚ n  t	 | |  ƒ } |  | | | f S(   Ns   No module named %st   __main__s	   .__main__s%   Cannot use package as __main__ modules   %s; %r is a package and cannot s   be directly executeds   No code object available for %s(
   R   R    t
   is_packaget   ImportErrort   formatt   endswitht
   __import__t   _get_module_detailst   get_codeR/   (   R   t   errorR1   t   ispkgt   et   pkg_main_nameR"   t   filename(    (    s   /usr/lib/python2.7/runpy.pyR:   d   s2    

c         C   sc   d } y t  | ƒ SWnH t k
 r^ } | t | ƒ k rX |  d | t j d f ƒ ‚ n  ‚  n Xd  S(   NR4   s   can't find %r module in %ri    (   R:   R6   t   strR   t   path(   R<   t	   main_namet   exc(    (    s   /usr/lib/python2.7/runpy.pyt   _get_main_module_details€   s    t   _Errorc           B   s   e  Z d  Z RS(   sB   Error that _run_module_as_main() should report without a traceback(   R   R   R   (    (    (    s   /usr/lib/python2.7/runpy.pyRF   Œ   s   c   	      C   s×   yL | s |  d k r3 t  |  t ƒ \ }  } } } n t t ƒ \ }  } } } Wn3 t k
 r } d t j | f } t j | ƒ n X|  j d ƒ d } t j d j } | r» | t j	 d <n  t
 | | d d | | | ƒ S(   s¯  Runs the designated module in the __main__ namespace

       Note that the executed module will have full access to the
       __main__ namespace. If this is not desirable, the run_module()
       function should be used to run the module code in a fresh namespace.

       At the very least, these variables in __main__ will be overwritten:
           __name__
           __file__
           __loader__
           __package__
    R4   s   %s: %st   .i    N(   R:   RF   RE   R   t
   executablet   exitt
   rpartitionR   R)   R   R(   R    (	   R   t
   alter_argvR1   R"   t   fnameRD   t   msgR'   t   main_globals(    (    s   /usr/lib/python2.7/runpy.pyt   _run_module_as_main“   s    c         C   s   t  |  ƒ \ }  } } } | d k r- |  } n  |  j d ƒ d } | r_ t | | | | | | ƒ St | i  | | | | | ƒ Sd S(   sn   Execute a module's code without importing it

       Returns the resulting top level namespace dictionary
    RG   i    N(   R:   R    RJ   R-   R(   (   R   R$   t   run_namet	   alter_sysR1   R"   RL   R'   (    (    s   /usr/lib/python2.7/runpy.pyR   °   s    	c         C   s¤   t  j } y | |  } Wn† t k
 rŸ d | |  <x^ t  j D]+ } y | |  ƒ } PWq; t k
 re q; Xq; Wy t j |  ƒ } Wn t k
 r‘ d SX| | |  <n X| S(   s5   Python version of PyImport_GetImporter C API functionN(   R   t   path_importer_cacheR   R    t
   path_hooksR6   R   t   NullImporter(   t	   path_namet   cachet   importert   hook(    (    s   /usr/lib/python2.7/runpy.pyt   _get_importerÅ   s"    	
c      	   C   sg   t  |  d ƒ  } t | ƒ } Wd  QX| d  k rc t  |  d ƒ  } t | j ƒ  |  d ƒ } Wd  QXn  | S(   Nt   rbt   rUt   exec(   t   openR    R    t   compilet   read(   RL   t   fR"   (    (    s   /usr/lib/python2.7/runpy.pyt   _get_code_from_fileá   s    !c         C   s<  | d k r d } n  t |  ƒ } t | t j ƒ rR t |  ƒ } t | | | |  ƒ St j j	 d |  ƒ z§ d } t j
 | } t j
 | =z t ƒ  \ } } } }	 Wd | t j
 | <Xd }
 t | ƒ H } t |  ƒ 3 | j j } t | | | | |	 | |
 ƒ j ƒ  SWd QXWd QXWd y t j j |  ƒ Wn t k
 r6n XXd S(   s_  Execute code located at the specified filesystem location

       Returns the resulting top level namespace dictionary

       The file path may refer directly to a Python script (i.e.
       one that could be directly executed with execfile) or else
       it may refer to a zipfile or directory containing a top
       level __main__.py script.
    s
   <run_path>i    R4   Nt    (   R    RY   t
   isinstanceR   RT   Ra   R-   R   RB   t   insertR   RE   R   R   R   R)   R(   R*   t   removet
   ValueError(   RU   R$   RP   RW   R"   RC   t
   saved_mainR   R1   RL   R'   R+   R,   (    (    s   /usr/lib/python2.7/runpy.pyR   ë   s0    
	
&R4   i   s!   No module specified for executioni    (   R   R   R   t   pkgutilR    R   R6   t   __all__R   R   R   R    R(   R-   R/   R:   RE   t	   ExceptionRF   t   TrueRO   t   FalseR   RY   Ra   R   R   t   lenR   t   stderr(    (    (    s   /usr/lib/python2.7/runpy.pyt   <module>   s>   			
1
