ó
è¾bc           @   sZ  d  Z  d d l m Z e d d d ƒ[ d d l Z d d l Z d d l Z d d l Z d d l Z d d d	 g Z e	 d
 ƒ Z
 e	 e ƒ Z d d d „  ƒ  YZ d d d „  ƒ  YZ e r¾ d pÁ d Z d e Z d „  Z d a a d „  Z d „  Z d „  Z d	 e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d d d „  ƒ  YZ d „  Z d „  Z d S(   s  
Import utilities

Exported classes:
    ImportManager   Manage the import process

    Importer        Base class for replacing standard import functions
    BuiltinImporter Emulate the import mechanism for builtin and frozen modules

    DynLoadSuffixImporter
iÿÿÿÿ(   t   warnpy3ks1   the imputil module has been removed in Python 3.0t
   stackleveli   Nt   ImportManagert   Importert   BuiltinImportert    c           B   sq   e  Z d  Z e e ƒ d „ Z d „  Z d „  Z d	 Z	 d	 d „ Z
 d	 d	 d	 d „ Z d „  Z d „  Z d „  Z RS(
   s   Manage the import process.c         C   sE   t  | t ƒ r t | ƒ } n  | d |  _ | |  _ |  j | d <d S(   s8   Install this ImportManager into the specified namespace.t
   __import__N(   t
   isinstancet   _ModuleTypet   varst   previous_importert	   namespacet   _import_hook(   t   selfR   (    (    s   /usr/lib/python2.7/imputil.pyt   install!   s
    	c         C   s   |  j  |  j d <d S(   s&   Restore the previous import mechanism.R   N(   R
   R   (   R   (    (    s   /usr/lib/python2.7/imputil.pyt	   uninstall1   s    c         C   s,   t  | d ƒ s t ‚ |  j j | | ƒ d  S(   Nt   __call__(   t   hasattrt   AssertionErrort   fs_impt
   add_suffix(   R   t   suffixt
   importFunc(    (    s   /usr/lib/python2.7/imputil.pyR   5   s    c         C   sž   t  s t ƒ  n  | d  k r7 |  j p( t } | ƒ  } n  | |  _ xG t j ƒ  D]9 } | d t j k rM |  j	 | d t
 | ƒ j ƒ qM qM W|  j	 d t ƒ d  S(   Ni   i    s   .py(   t   _os_statt   _os_bootstrapt   Nonet   clsFilesystemImportert   _FilesystemImporterR   t   impt   get_suffixest   C_EXTENSIONR   t   DynLoadSuffixImportert   import_filet   py_suffix_importer(   R   R   t   clst   desc(    (    s   /usr/lib/python2.7/imputil.pyt   __init__@   s    
	c   
      C   sS  | j  d ƒ } |  j | ƒ } | rI | j j | | | ƒ } | rI | Sn  y t j | d } Wn: t k
 rš |  j | d ƒ } | s› t d | ‚ q› n Xt	 | ƒ d k rÐ | s· | S| j
 j d ƒ sÐ | Sn  | j
 j d ƒ }	 |	 rÿ |	 j | | d | ƒ St	 | ƒ d k rBt | | d ƒ rB| r;t | | d ƒ S| Sn  t d | ‚ d S(	   s5   Python calls this hook to locate and import a module.t   .i    s   No module named i   t	   __ispkg__t   __importer__i   N(   t   splitt   _determine_import_contextR'   t
   _do_importt   syst   modulest   KeyErrort   _import_top_modulet   ImportErrort   lent   __dict__t   gett   _finish_importR   t   getattr(
   R   t   fqnamet   globalst   localst   fromlistt   partst   parentt   modulet
   top_modulet   importer(    (    s   /usr/lib/python2.7/imputil.pyR   V   s2    %c         C   s¤   | s | j  d ƒ r d S| d } | d rU t j | } | | j k sQ t ‚ | S| j d ƒ } | d k rt d S| |  } t j | } | j | k s  t ‚ | S(   sJ  Returns the context in which a module should be imported.

        The context could be a loaded (package) module and the imported module
        will be looked for within that package. The context could also be None,
        meaning there is no context -- the module should be looked for as a
        "top-level" module.
        R'   t   __name__R&   R%   iÿÿÿÿN(   R2   R   R+   R,   R1   R   t   rfindR>   (   R   R6   t   parent_fqnameR:   t   i(    (    s   /usr/lib/python2.7/imputil.pyR)   •   s    	


c         C   sX   xQ t  j D]F } t | t ƒ r7 |  j j | | ƒ } n | j | ƒ } | r
 | Sq
 Wd  S(   N(   R+   t   pathR   t   _StringTypeR   t   import_from_dirt
   import_topR   (   R   t   namet   itemR;   (    (    s   /usr/lib/python2.7/imputil.pyR.   ¼   s    c         C   s(   | j  j d ƒ } | s n  t d ‚ d S(   s*   Python calls this hook to reload a module.R'   s   reload not yet implementedN(   R1   R2   t   SystemError(   R   R;   R=   (    (    s   /usr/lib/python2.7/imputil.pyt   _reload_hookÈ   s    N(   R>   t
   __module__t   __doc__R	   t   __builtin__R   R   R   R   R   R$   R   R)   R.   RI   (    (    (    s   /usr/lib/python2.7/imputil.pyR      s   			?	'	c           B   sV   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   s3   Base class for replacing standard import functions.c         C   s   |  j  d | | ƒ S(   s   Import a top-level module.N(   t   _import_oneR   (   R   RF   (    (    s   /usr/lib/python2.7/imputil.pyRE   Ü   s    c         C   s<   |  j  | | ƒ } | s | S| j r8 |  j | | ƒ n  | S(   N(   t
   _load_tailR&   t   _import_fromlist(   R   t   topR9   R8   t   bottom(    (    s   /usr/lib/python2.7/imputil.pyR3   ä   s    	c         C   sw   y t  j | SWn t k
 r" n X|  j | | | ƒ } | d k rH d S|  j | | ƒ } | rs t | | | ƒ n  | S(   s   Import a single module.N(   R+   R,   R-   t   get_codeR   t   _process_resultt   setattr(   R   R:   t   modnameR5   t   resultR;   (    (    s   /usr/lib/python2.7/imputil.pyRM     s    c         B   sÆ   | \ } } } e  | e ƒ } | r- | } n e j | ƒ } |  | _ | | _ | j j | ƒ | e j	 | <| s¬ y | | j UWq¬ | e j	 k r¢ e j	 | =n  ‚  q¬ Xn  e j	 | } | | _
 | S(   N(   R   R   R   t
   new_moduleR'   R&   R1   t   updateR+   R,   R>   (   R   RV   R5   t   ispkgt   codet   valuest	   is_moduleR;   (    (    s   /usr/lib/python2.7/imputil.pyRS     s&    			
	c         C   sS   xL | D]D } d | j  | f } |  j | | | ƒ } | s t d | ‚ q q W| S(   sˆ   Import the rest of the modules, down from the top-level module.

        Returns the last module in the dotted list of modules.
        s   %s.%ss   No module named (   R>   RM   R/   (   R   t   mR9   t   partR5   (    (    s   /usr/lib/python2.7/imputil.pyRN   A  s    c         C   s¦   d | k r4 t  | ƒ t  | j j d g  ƒ ƒ } n  xk | D]c } | d k r; t | | ƒ r; d | j | f } |  j | | | ƒ } | sž t d | ‚ qž q; q; Wd S(   s*   Import any sub-modules in the "from" list.t   *t   __all__s   %s.%ss   cannot import name N(   t   listR1   R2   R   R>   RM   R/   (   R   t   packageR8   t   subt   subnamet   submod(    (    s   /usr/lib/python2.7/imputil.pyRO   M  s    	c         C   sQ   | d } | j  d | } |  j | | | ƒ } | s: d S|  j | | d | ƒ S(   s¨   Attempt to import the module relative to parent.

        This method is used when the import context specifies that <self>
        imported the parent module.
        i    R%   i   N(   R>   RM   R   R3   (   R   R:   R9   R8   t   top_namet
   top_fqnameR<   (    (    s   /usr/lib/python2.7/imputil.pyR*   _  s    
c         C   s   t  d ‚ d S(   s£  Find and retrieve the code for the given module.

        parent specifies a parent module to define a context for importing. It
        may be None, indicating no particular context for the search.

        modname specifies a single module (not dotted) within the parent.

        fqname specifies the fully-qualified module name. This is a
        (potentially) dotted name from the "root" of the module namespace
        down to the modname.
        If there is no parent, then modname==fqname.

        This method should return None, or a 3-tuple.

        * If the module was not found, then None should be returned.

        * The first item of the 2- or 3-tuple should be the integer 0 or 1,
            specifying whether the module that was found is a package or not.

        * The second item is the code object for the module (it will be
            executed within the new module's namespace). This item can also
            be a fully-loaded module object (e.g. loaded from a shared lib).

        * The third item is a dictionary of name/value pairs that will be
            inserted into new module before the code object is executed. This
            is provided in case the module's code expects certain values (such
            as where the module was found). When the second item is a module
            object, then these names/values will be inserted *after* the module
            has been loaded/initialized.
        s   get_code not implementedN(   t   RuntimeError(   R   R:   RU   R5   (    (    s   /usr/lib/python2.7/imputil.pyRR   r  s    (   R>   RJ   RK   RE   R3   RM   RS   RN   RO   R*   RR   (    (    (    s   /usr/lib/python2.7/imputil.pyR   Ù   s   		#		%			t   ct   os   .pyc         C   sé   t  |  d ƒ j ƒ  } | r8 | d d k r8 | d } n  t j | |  d ƒ } y t  |  t d ƒ } Wn t k
 rw nn X| j d ƒ | j t j d | ƒ ƒ t	 j
 | | ƒ | j ƒ  | j d d ƒ | j t j ƒ  ƒ | j ƒ  | S(	   sN  Compile (and cache) a Python source file.

    The file specified by <pathname> is compiled to a code object and
    returned.

    Presuming the appropriate privileges exist, the bytecodes will be
    saved back to the filesystem for future imports. The source file's
    modification timestamp must be provided as a Long value.
    t   rUiÿÿÿÿs   
t   exect   wbs       s   <Ii    (   t   opent   readRL   t   compilet   _suffix_chart   IOErrort   writet   structt   packt   marshalt   dumpt   flusht   seekR   t	   get_magict   close(   t   pathnamet	   timestampt
   codestringRZ   t   f(    (    s   /usr/lib/python2.7/imputil.pyt   _compileŸ  s     


c          C   s×   t  j }  d } d |  k r4 d } d d l m } nx d |  k rY d } d d l m } nS d |  k r~ d } d d l m } n. d |  k r£ d } d d l m } n	 t d	 ‚ | d k rÇ | d
 „ } n  | a	 | a
 d S(   sI   Set up 'os' module replacement functions for use during import bootstrap.t   posixt   /iÿÿÿÿ(   t   statt   nts   \t   dost   os2s   no os specific module foundc         S   sF   |  d k r | S|  d } | d k s2 | | k r: |  | S|  | | S(   NR   iÿÿÿÿR‚   (    (   t   at   bt   sept   lastchar(    (    s   /usr/lib/python2.7/imputil.pyt   joinÕ  s    
N(   R+   t   builtin_module_namesR   R   Rƒ   R„   R…   R†   R/   R   t   _os_path_join(   t   namesR‹   R‰   Rƒ   (    (    s   /usr/lib/python2.7/imputil.pyR   ¿  s&    			c         C   s6   y t  |  ƒ } Wn t k
 r$ d SX| j d @d k S(   s&   Local replacement for os.path.isdir().i ð  i @  N(   R   t   OSErrorR   t   st_mode(   R|   t   s(    (    s   /usr/lib/python2.7/imputil.pyt   _os_path_isdirã  s
    c         C   s2   y t  |  ƒ } Wn t k
 r$ d SXt | j ƒ S(   s,   Return the file modification time as a Long.N(   R   R   R   t   longt   st_mtime(   R|   R‘   (    (    s   /usr/lib/python2.7/imputil.pyt
   _timestampë  s
    c           B   s   e  Z d  „  Z RS(   c         C   sr   | r
 d  St j | ƒ r% t j } n t j | ƒ r@ t j } n d  St j | d  | d d | f ƒ } d | i  f S(   NR   i    (   R   R   t
   is_builtint	   C_BUILTINt	   is_frozent	   PY_FROZENt   load_module(   R   R:   RU   R5   t   typeR;   (    (    s   /usr/lib/python2.7/imputil.pyRR   ù  s    !(   R>   RJ   RR   (    (    (    s   /usr/lib/python2.7/imputil.pyR   ø  s   R   c           B   s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s   g  |  _  d  S(   N(   t   suffixes(   R   (    (    s   /usr/lib/python2.7/imputil.pyR$     s    c         C   s/   t  | d ƒ s t ‚ |  j j | | f ƒ d  S(   NR   (   R   R   Rœ   t   append(   R   R   R   (    (    s   /usr/lib/python2.7/imputil.pyR     s    c         C   s5   |  j  t | | ƒ | ƒ } | r1 |  j | | ƒ Sd  S(   N(   t   _import_pathnameR   RS   R   (   R   t   dirR5   RV   (    (    s   /usr/lib/python2.7/imputil.pyRD     s    c         C   sg   | s t  ‚ x< | j D]1 } |  j t | | ƒ | ƒ } | d  k	 r | Sq W|  j t | j | ƒ | ƒ S(   N(   R   t   __path__Rž   R   R   t
   __pkgdir__(   R   R:   RU   R5   t   submodule_pathRZ   (    (    s   /usr/lib/python2.7/imputil.pyRR     s    c   	      C   s¿   t  | ƒ rc |  j t | d ƒ | ƒ } | r_ | d } | | d <| g | d <d | d | f Sd  SxU |  j D]J \ } } | | } y t | ƒ } Wn t k
 r¦ qm X| | | | ƒ Sqm Wd  S(   NR$   i   R¡   R    i   (   R’   Rž   R   R   Rœ   R   R   (	   R   R|   R5   RV   R[   R   R   t   filenamet   finfo(    (    s   /usr/lib/python2.7/imputil.pyRž   ,  s"    	


(   R>   RJ   R$   R   RD   RR   Rž   (    (    (    s   /usr/lib/python2.7/imputil.pyR     s
   				c   	      C   s÷   |  d  t  } t | d ƒ } t | ƒ } d  } | d  k	 r¿ | | k r¿ t | d ƒ } | j d ƒ t j ƒ  k r² t j	 d | j d ƒ ƒ d } | | k r² t
 j | ƒ } q² n  | j ƒ  n  | d  k rã |  } t | | ƒ } n  d | i | d 6f S(   Niýÿÿÿi   t   rbi   s   <Ii    t   __file__(   t   _suffixR“   R•   R   Rn   Ro   R   Rz   Rt   t   unpackRv   t   loadR{   R€   (	   R£   R¤   R5   t   filet   t_pyt   t_pycRZ   R   t   t(    (    s   /usr/lib/python2.7/imputil.pyR!   F  s    R   c           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   | |  _  d  S(   N(   R#   (   R   R#   (    (    s   /usr/lib/python2.7/imputil.pyR$   Z  s    c         C   sG   t  | |  j d ƒ } t j | | | |  j ƒ } | | _ d | i  f S(   Ni   i    (   Rn   R#   R   Rš   R¦   (   R   R£   R¤   R5   t   fpR;   (    (    s   /usr/lib/python2.7/imputil.pyR    ]  s    	(   R>   RJ   R$   R    (    (    (    s   /usr/lib/python2.7/imputil.pyR   Y  s   	c          C   s^   t  j j ƒ  }  |  j ƒ  x> |  D]6 \ } } | rM | G| j j d d ƒ GHq  | Gd GHq  Wd  S(   NR'   s   -- no importers   -- non-existent module(   R+   R,   t   itemst   sortR1   R2   (   R¯   RF   R;   (    (    s   /usr/lib/python2.7/imputil.pyt   _print_importersf  s    
c           C   s'   t  ƒ  j ƒ  t j j d t ƒ  ƒ d  S(   Ni    (   R   R   R+   RB   t   insertR   (    (    (    s   /usr/lib/python2.7/imputil.pyt   _test_revampo  s    (    (    (    (   RK   t   warningsR    R   R+   RL   Rt   Rv   R`   R›   RC   R   R   R   t	   __debug__Rq   R§   R€   R   R   R   R   R’   R•   R   R   R!   R   R±   R³   (    (    (    s   /usr/lib/python2.7/imputil.pyt   <module>   s4   »Á
	
	$		6			