ó
¤ –Qc           @   s   d  Z  d d l Z d d l Z d d l Z d d l m Z m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ	 d e f d	 „  ƒ  YZ
 d
 „  Z d S(   s,   
PEP-302 importers for frozen applications.
iÿÿÿÿN(   t   ArchiveReadErrort   ZlibArchivet   BuiltinImporterc           B   sA   e  Z d  Z d d „ Z d d „ Z d „  Z d „  Z d „  Z RS(   s·   
    PEP-302 wrapper of the built-in modules for sys.meta_path.

    This wrapper ensures that import machinery will not look for built-in
    modules in the bundled ZIP archive.
    c         C   s6   t  j ƒ  d  } | t j k r( |  } n  t  j ƒ  | S(   N(   t   impt   acquire_lockt   Nonet   syst   builtin_module_namest   release_lock(   t   selft   fullnamet   patht   module_loader(    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyt   find_module#   s    
	
c         C   s   t  j ƒ  y4 t j j | ƒ } | d  k r= t  j | ƒ } n  Wn@ t k
 r€ | t j k rp t j j | ƒ n  t  j	 ƒ  ‚  n Xt  j	 ƒ  | S(   N(
   R   R   R   t   modulest   getR   t   init_builtint	   Exceptiont   popR   (   R	   R
   R   t   module(    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyt   load_module.   s    


c         C   s'   | t  j k r t St d | ƒ ‚ d S(   sP   
        Return always False since built-in modules are never packages.
        s   No module named N(   R   R   t   Falset   ImportError(   R	   R
   (    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyt
   is_packageG   s    c         C   s'   | t  j k r d St d | ƒ ‚ d S(   s4   
        Return None for a built-in module.
        s   No module named N(   R   R   R   R   (   R	   R
   (    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyt   get_codeQ   s    c         C   s'   | t  j k r d St d | ƒ ‚ d S(   s4   
        Return None for a built-in module.
        s   No module named N(   R   R   R   R   (   R	   R
   (    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyt
   get_source[   s    N(	   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   (    (    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyR      s   	
	
t   FrozenImporterc           B   s\   e  Z d  Z d „  Z d	 d „ Z d	 d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(
   sÁ  
    Load bytecode of Python modules from the executable created by PyInstaller.

    Python bytecode is zipped and appended to the executable.

    NOTE: PYZ format cannot be replaced by zipimport module.

    The problem is that we have no control over zipimport; for instance,
    it doesn't work if the zip file is embedded into a PKG appended
    to an executable, like we create in one-file.

    This is PEP-302 finder and loader class for the ``sys.meta_path`` hook.
    A PEP-302 finder requires method find_module() to return loader
    class with method load_module(). Both these methods are implemented
    in one class.


    To use this class just call

        FrozenImporter.install()
    c         C   s   xŠ t  j D] } yO t | ƒ |  _ |  j j ƒ  t  j j | ƒ t |  j j j ƒ  ƒ |  _ d SWq
 t	 k
 ru q
 q
 t
 k
 rˆ q
 q
 Xq
 Wt d ƒ ‚ d S(   sY   
        Load, unzip and initialize the Zip archive bundled with the executable.
        Ns   Can't load frozen modules.(   R   R   R   t   _pyz_archivet
   checkmagict   removet   sett   toct   keyst   IOErrorR    R   (   R	   t   pyz_filepath(    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyt   __init__|   s    	c         C   s6   t  j ƒ  d } | |  j k r( |  } n  t  j ƒ  | S(   sª  
        PEP-302 finder.find_module() method for the ``sys.meta_path`` hook.

        fullname     fully qualified name of the module
        path         None for a top-level module, or package.__path__ for submodules or subpackages.

        Return a loader object if the module was found, or None if it wasn't. If find_module() raises
        an exception, it will be propagated to the caller, aborting the import.
        N(   R   R   R   R"   R   (   R	   R
   R   R   (    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyR   ž   s    
	
c         B   sŠ  e  j ƒ  d } y)e j j | ƒ } | d k r8|  j j | ƒ \ } } e  j | ƒ } e j	 } | rš e
 j e
 j | | j d e
 j ƒ ƒ d ƒ | _ n( e
 j | | j d e
 j ƒ d ƒ | _ | rã e
 j | j ƒ g | _ n  |  | _ | rþ | | _ n | j d d ƒ d | _ | e j | <| | j f d Un  Wn@ e k
 r{| e j k rke j j | ƒ n  e  j ƒ  ‚  n Xe  j ƒ  | S(   s  
        PEP-302 loader.load_module() method for the ``sys.meta_path`` hook.

        Return the loaded module (instance of imp.new_module()) or raises
        an exception, preferably ImportError if an existing exception
        is not being propagated.
        t   .s   __init__.pycs   .pyci   i    N(   R   R   R   R   R   R   R   t   extractt
   new_modulet   prefixt   pyi_os_patht   os_path_joint   replacet   os_sept   __file__t   os_path_dirnamet   __path__t
   __loader__t   __package__t   rsplitt   __dict__R   R   R   (   R	   R
   R   R   t   is_pkgt   bytecodet   abspath(    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyR   ·   s8    	

	$			

c         C   sj   | |  j  k rV y  |  j j | ƒ \ } } | SWqf t k
 rR t d | ƒ ‚ qf Xn t d | ƒ ‚ d S(   sP   
        Return always False since built-in modules are never packages.
        s+   Loader FrozenImporter cannot handle module N(   R"   R   R(   R   R   (   R	   R
   R6   R7   (    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyR   $  s    c         C   sj   | |  j  k rV y  |  j j | ƒ \ } } | SWqf t k
 rR t d | ƒ ‚ qf Xn t d | ƒ ‚ d S(   s|   
        Get the code object associated with the module.

        ImportError should be raised if module not found.
        s+   Loader FrozenImporter cannot handle module N(   R"   R   R(   R   R   (   R	   R
   R6   R7   (    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyR   1  s    c         C   s'   | |  j  k r d St d | ƒ ‚ d S(   s¡   
        Method should return the source code for the module as a string.
        But frozen modules does not contain source code.

        Return None.
        s   No module named N(   R"   R   R   (   R	   R
   (    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyR   @  s    c         C   s)   t  | d ƒ } | j ƒ  } | j ƒ  | S(   s  
        This returns the data as a string, or raise IOError if the "file"
        wasn't found. The data is always returned as if "binary" mode was used.

        The 'path' argument is a path that can be constructed by munging
        module.__file__ (or pkg.__path__ items)
        t   rb(   t   opent   readt   close(   R	   R   t   fpt   content(    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyt   get_dataM  s    	
c         C   sq   t  j } |  j | ƒ rH t j t j | | j d t j ƒ ƒ d ƒ } n% t j | | j d t j ƒ d ƒ } | S(   sÂ   
        This method should return the value that __file__ would be set to
        if the named module was loaded. If the module is not found, then
        ImportError should be raised.
        R'   s   __init__.pycs   .pyc(   R   R*   R   R+   R,   R-   R.   (   R	   R
   R8   t   filename(    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyt   get_filename\  s    	!	N(   R   R   R   R&   R   R   R   R   R   R   R?   RA   (    (    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyR   f   s   	"m				t   CExtensionImporterc           B   s\   e  Z d  Z d „  Z d	 d „ Z d	 d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(
   sË   
    PEP-302 hook for sys.meta_path to load Python C extension modules.

    C extension modules are present on the sys.prefix as filenames:

        full.module.name.pyd
        full.module.name.so
    c         C   ss   xK t  j ƒ  D]= \ } } } | t  j k r | | | f |  _ | |  _ Pq q Wt j t j ƒ } t	 | ƒ |  _
 d  S(   N(   R   t   get_suffixest   C_EXTENSIONt   _c_ext_tuplet   _suffixR+   t
   os_listdirR   R*   R!   t   _file_cache(   R	   t   extt   modet   typt   files(    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyR&   w  s    	c         C   s=   t  j ƒ  d  } | |  j |  j k r/ |  } n  t  j ƒ  | S(   N(   R   R   R   RF   RH   R   (   R	   R
   R   R   (    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyR   ƒ  s    
	
c         C   sî   t  j ƒ  y“ t j j | ƒ } | d  k rœ t j t j | |  j	 ƒ } t
 | d ƒ } t  j | | | |  j ƒ } t | d ƒ rŒ | | _ qœ | | j d <n  Wn@ t k
 rß | t j k rÏ t j j | ƒ n  t  j ƒ  ‚  n Xt  j ƒ  | S(   NR9   t   __setattr__R/   (   R   R   R   R   R   R   R+   R,   R*   RF   R:   R   RE   t   hasattrR/   R5   R   R   R   (   R	   R
   R   R   R@   R=   (    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyR   Ž  s"    


c         C   s   t  S(   sS   
        Return always False since C extension modules are never packages.
        (   R   (   R	   R
   (    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyR   ±  s    c         C   s.   | |  j  |  j k r d St d | ƒ ‚ d S(   s7   
        Return None for a C extension module.
        s   No module named N(   RF   RH   R   R   (   R	   R
   (    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyR   ·  s    c         C   s.   | |  j  |  j k r d St d | ƒ ‚ d S(   s7   
        Return None for a C extension module.
        s   No module named N(   RF   RH   R   R   (   R	   R
   (    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyR   Á  s    c         C   s)   t  | d ƒ } | j ƒ  } | j ƒ  | S(   s  
        This returns the data as a string, or raise IOError if the "file"
        wasn't found. The data is always returned as if "binary" mode was used.

        The 'path' argument is a path that can be constructed by munging
        module.__file__ (or pkg.__path__ items)
        R9   (   R:   R;   R<   (   R	   R   R=   R>   (    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyR?   Ë  s    	
c         C   sD   | |  j  |  j k r0 t j t j | |  j  ƒ St d | ƒ ‚ d S(   sÂ   
        This method should return the value that __file__ would be set to
        if the named module was loaded. If the module is not found, then
        ImportError should be raised.
        s   No module named N(   RF   RH   R+   R,   R   R*   R   (   R	   R
   (    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyRA   Ú  s    N(   R   R   R   R&   R   R   R   R   R   R   R?   RA   (    (    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyRB   n  s   	#		
	
	c           C   s=   t  j j t ƒ  ƒ t  j j t ƒ  ƒ t  j j t ƒ  ƒ d S(   s  
    Install FrozenImporter class and other classes into the import machinery.

    This class method (static method) installs the FrozenImporter class into
    the import machinery of the running process. The importer is added
    to sys.meta_path. It could be added to sys.path_hooks but sys.meta_path
    is processed by Python before looking at sys.path!

    The order of processing import hooks in sys.meta_path:

    1. built-in modules
    2. modules from the bundled ZIP archive
    3. C extension modules
    N(   R   t	   meta_patht   appendR   R   RB   (    (    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyt   installè  s    (   R   R   R   R+   t   pyi_archiveR    R   t   objectR   R   RB   RQ   (    (    (    sc   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_importers.pyt   <module>   s   Jÿ 	z