Ñò
mÈKc           @   s’  d  Z  d d k l Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k	 Z	 e
 e i d ƒ o
 d Z n d Z e e i i d ƒ ƒ Z e e i i d ƒ ƒ Z e e i i d	 ƒ ƒ Z e e i i d
 ƒ ƒ Z e e g Z e e i ƒ Z h  Z d „  Z h  Z d „  Z d f  d „  ƒ  YZ d f  d „  ƒ  YZ d „  Z e d j o, y e ƒ  Z Wn e j
 o d GHn Xn d S(   s3   Find modules used by a script, using introspection.iÿÿÿÿ(   t
   generatorsNt   newlinest   Ut   rt
   LOAD_CONSTt   IMPORT_NAMEt
   STORE_NAMEt   STORE_GLOBALc         C   s-   t  i |  g  ƒ } | i | ƒ | t  |  <d  S(   N(   t   packagePathMapt   gett   append(   t   packagenamet   patht   paths(    (    s"   /usr/lib/python2.6/modulefinder.pyt   AddPackagePath#   s    c         C   s   | t  |  <d  S(   N(   t   replacePackageMap(   t   oldnamet   newname(    (    s"   /usr/lib/python2.6/modulefinder.pyt   ReplacePackage/   s    t   Modulec           B   s    e  Z d d d  „ Z d „  Z RS(   c         C   s:   | |  _  | |  _ | |  _ d  |  _ h  |  _ h  |  _ d  S(   N(   t   __name__t   __file__t   __path__t   Nonet   __code__t   globalnamest   starimports(   t   selft   namet   fileR   (    (    s"   /usr/lib/python2.6/modulefinder.pyt   __init__5   s    					c         C   sn   d |  i  f } |  i d  j	 o | d |  i f } n |  i d  j	 o | d |  i f } n | d } | S(   Ns	   Module(%rs   , %rt   )(   R   R   R   R   (   R   t   s(    (    s"   /usr/lib/python2.6/modulefinder.pyt   __repr__B   s    
N(   R   t
   __module__R   R   R!   (    (    (    s"   /usr/lib/python2.6/modulefinder.pyR   3   s   t   ModuleFinderc           B   s  e  Z d d  g  g  d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d d d d „ Z	 d d	 „ Z
 d
 „  Z d „  Z d  d „ Z d „  Z d „  Z d „  Z d „  Z d d „ Z e i d „ Z e i d „ Z d „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z RS(   i    c         C   sf   | d  j o t i } n | |  _ h  |  _ h  |  _ | |  _ d |  _ | |  _ | |  _ g  |  _	 d  S(   Ni    (
   R   t   sysR   t   modulest
   badmodulest   debugt   indentt   excludest   replace_pathst   processed_paths(   R   R   R'   R)   R*   (    (    s"   /usr/lib/python2.6/modulefinder.pyR   M   s    							c         G   sV   | |  i  j oB x t |  i ƒ D]
 } d Gq  W| Gx | D] } t | ƒ Gq9 WHn d  S(   Ns      (   R'   t   rangeR(   t   repr(   R   t   levelt   strt   argst   it   arg(    (    s"   /usr/lib/python2.6/modulefinder.pyt   msgY   s      c         G   s?   | d } | |  i  j o! |  i d |  _ |  i | Œ  n d  S(   Ni    i   (   R'   R(   R3   (   R   R0   R.   (    (    s"   /usr/lib/python2.6/modulefinder.pyt   msginb   s    
c         G   s?   | d } | |  i  j o! |  i d |  _ |  i | Œ  n d  S(   Ni    i   (   R'   R(   R3   (   R   R0   R.   (    (    s"   /usr/lib/python2.6/modulefinder.pyt   msgouth   s    
c         C   sN   |  i  d d | ƒ t | t ƒ } d d t i f } |  i d | | | ƒ d  S(   Ni   t
   run_scriptt    R   t   __main__(   R3   t   opent	   READ_MODEt   impt	   PY_SOURCEt   load_module(   R   t   pathnamet   fpt   stuff(    (    s"   /usr/lib/python2.6/modulefinder.pyR6   n   s    c         C   sk   t  i i | ƒ \ } } t  i i | ƒ \ } } t | t ƒ } | d t i f } |  i | | | | ƒ d  S(   NR   (	   t   osR   t   splitt   splitextR9   R:   R;   R<   R=   (   R   R>   t   dirR   t   extR?   R@   (    (    s"   /usr/lib/python2.6/modulefinder.pyt	   load_filet   s
    iÿÿÿÿc   	      C   s‰   |  i  d d | | | | ƒ |  i | d | ƒ} |  i | | ƒ \ } } |  i | | ƒ } | p | S| i o |  i | | ƒ n d  S(   Ni   t   import_hookR.   (   R3   t   determine_parentt   find_head_packaget	   load_tailR   t   ensure_fromlistR   (	   R   R   t   callert   fromlistR.   t   parentt   qt   tailt   m(    (    s"   /usr/lib/python2.6/modulefinder.pyRG   {   s    
c         C   sÒ  |  i  d d | | ƒ | p | d j o |  i d d ƒ d  S| i } | d j oÃ | i o | d 8} n | d j o9 |  i | } | | j p t ‚ |  i d d | ƒ | S| i d ƒ | j  o t d ‚ n d i	 | i
 d ƒ |  ƒ } |  i | } |  i d d | ƒ | S| i o9 |  i | } | | j p t ‚ |  i d d | ƒ | Sd | j oU | i d ƒ } | |  } |  i | } | i | j p t ‚ |  i d d | ƒ | S|  i d d ƒ d  S(	   Ni   RH   i    s   determine_parent -> Nonei   s   determine_parent ->t   .s   relative importpath too deep(   R4   R5   R   R   R   R%   t   AssertionErrort   countt   ImportErrort   joinRB   t   rfind(   R   RL   R.   t   pnameRN   R1   (    (    s"   /usr/lib/python2.6/modulefinder.pyRH   †   sB    	


c         C   s9  |  i  d d | | ƒ d | j o+ | i d ƒ } | |  } | | d } n | } d } | o d | i | f } n | } |  i | | | ƒ } | o$ |  i d d | | f ƒ | | f S| oP | } d  } |  i | | | ƒ } | o$ |  i d d | | f ƒ | | f Sn |  i d d | ƒ t d	 | ‚ d  S(
   Ni   RI   RR   i   R7   s   %s.%ss   find_head_package ->s"   raise ImportError: No module nameds   No module named (   R4   t   findR   t   import_moduleR5   R   RU   (   R   RN   R   R1   t   headRP   t   qnameRO   (    (    s"   /usr/lib/python2.6/modulefinder.pyRI   ©   s.    
c         C   sÚ   |  i  d d | | ƒ | } x¤ | oœ | i d ƒ } | d j  o t | ƒ } n | |  | | d } } d | i | f } |  i | | | ƒ } | p$ |  i d d | ƒ t d | ‚ q q W|  i d d	 | ƒ | S(
   Ni   RJ   RR   i    i   s   %s.%ss"   raise ImportError: No module nameds   No module named s   load_tail ->(   R4   RY   t   lenR   RZ   R5   RU   (   R   RO   RP   RQ   R1   R[   t   mname(    (    s"   /usr/lib/python2.6/modulefinder.pyRJ   Ä   s      c         C   sË   |  i  d d | | | ƒ x« | D]£ } | d j o< | p1 |  i | ƒ } | o |  i | | d ƒ qk qÃ q  t | | ƒ pD d | i | f } |  i | | | ƒ } | p t d | ‚ qÃ q  q  Wd  S(   Ni   RK   t   *i   s   %s.%ss   No module named (   R3   t   find_all_submodulesRK   t   hasattrR   RZ   RU   (   R   RQ   RM   t	   recursivet   subt   allt   subnamet   submod(    (    s"   /usr/lib/python2.6/modulefinder.pyRK   Ó   s     c         C   s  | i  p d  Sh  } g  } x% t i ƒ  D] } | i | d ƒ q( WxË | i  D]À } y t i | ƒ } Wn, t i j
 o |  i d d | ƒ qM n Xxu | D]m } d  } x< | D]4 }	 t	 |	 ƒ }
 | |
 |	 j o | |
  } Pq¯ q¯ W| o | d j o | | | <qœ qœ WqM W| i
 ƒ  S(   Ni    i   s   can't list directoryR   (   R   R;   t   get_suffixesR
   RA   t   listdirt   errorR3   R   R]   t   keys(   R   RQ   R%   t   suffixest   tripleRD   t   namesR   t   modt   sufft   n(    (    s"   /usr/lib/python2.6/modulefinder.pyR`   á   s4    
 
   	c         C   se  |  i  d d | | | ƒ y |  i | } Wn t j
 o n X|  i d d | ƒ | S| |  i j o |  i d d ƒ d  S| o% | i d  j o |  i d d ƒ d  Sy, |  i | | o | i | ƒ \ } } } Wn' t j
 o |  i d d d  ƒ d  SXz |  i	 | | | | ƒ } Wd  | o | i
 ƒ  n X| o t | | | ƒ n |  i d d | ƒ | S(   Ni   RZ   s   import_module ->s   import_module -> None(   R4   R%   t   KeyErrorR5   R&   R   R   t   find_moduleRU   R=   t   closet   setattr(   R   t   partnamet   fqnameRN   RQ   R?   R>   R@   (    (    s"   /usr/lib/python2.6/modulefinder.pyRZ   ü   s6    	# c   
      C   s  | \ } } } |  i  d d | | o d | ƒ | t i j o* |  i | | ƒ } |  i d d | ƒ | S| t i j o  t | i ƒ  d | d ƒ }	 nw | t i j o` | i d ƒ t i	 ƒ  j o$ |  i d d | ƒ t
 d	 | ‚ n | i d ƒ t i | ƒ }	 n d  }	 |  i | ƒ } | | _ |	 o: |  i o |  i |	 ƒ }	 n |	 | _ |  i |	 | ƒ n |  i d d | ƒ | S(
   Ni   R=   R?   s   load_module ->s   
t   execi   s#   raise ImportError: Bad magic numbers   Bad magic number in %s(   R4   R;   t   PKG_DIRECTORYt   load_packageR5   R<   t   compilet   readt   PY_COMPILEDt	   get_magicRU   t   marshalt   loadR   t
   add_moduleR   R*   t   replace_paths_in_codeR   t	   scan_code(
   R   Rv   R?   R>   t	   file_infot   suffixt   modet   typeRQ   t   co(    (    s"   /usr/lib/python2.6/modulefinder.pyR=     s0      	
	c         C   sU   | |  i  j o h  |  i  | <n | o d |  i  | | i <n d |  i  | d <d  S(   Ni   t   -(   R&   R   (   R   R   RL   (    (    s"   /usr/lib/python2.6/modulefinder.pyt   _add_badmodule5  s
    c         C   s6  | |  i  j o |  i | | ƒ d  Sy |  i | | d | ƒWn> t j
 o2 } |  i d d t | ƒ ƒ |  i | | ƒ n´ X| o« x¨ | D]œ } | |  i  j o |  i | | ƒ qŽ n y  |  i | | | g d | ƒWqŽ t j
 o@ } |  i d d t | ƒ ƒ | d | } |  i | | ƒ qŽ XqŽ Wn d  S(   NR.   i   s   ImportError:RR   (   R&   R‰   RG   RU   R3   R/   (   R   R   RL   RM   R.   R3   Rc   t   fullname(    (    s"   /usr/lib/python2.6/modulefinder.pyt   _safe_import_hook=  s(      c   
      c   s  | i  } | i } | i } xå | oÝ | d } | t j o< | d | d d !ƒ \ } d | | f f V| d } q n | t j oT | d t j oC | d | d  ƒ \ } }	 d | | | |	 f f V| d } q n | t j o | d } q | d } q Wd  S(	   Ni    s   <Hi   i   t   stores   <xHxHi   t   import(   t   co_codet   co_namest	   co_constst	   STORE_OPSR   R   t   HAVE_ARGUMENT(
   R   R‡   t   unpackt   codeRm   t   constst   ct   opargt   oparg_1t   oparg_2(    (    s"   /usr/lib/python2.6/modulefinder.pyt   scan_opcodesT  s&    			 


c         c   su  | i  } | i } | i } t t t } xE| o=| d } | t j o< | d | d d !ƒ \ } d | | f f V| d } q, n | d  d d … | j o§ | d | d  ƒ \ }	 }
 } | |	 } | d j o d	 | |
 | | f f VnG | d j o d
 | |
 | | f f Vn d | | |
 | | f f V| d } q, n | t j o | d } q, | d } q, Wd  S(   Ni    s   <Hi   i   RŒ   i	   s   <xHxHxHiÿÿÿÿR   t   absolute_importt   relative_import(   RŽ   R   R   R   R   R‘   R’   (   R   R‡   R“   R”   Rm   R•   t   LOAD_LOAD_AND_IMPORTR–   R—   R˜   R™   t   oparg_3R.   (    (    s"   /usr/lib/python2.6/modulefinder.pyt   scan_opcodes_25l  s2    			 



c      	   C   s­  | i  } t i d j o |  i } n
 |  i } x9| | ƒ D]+\ } } | d j o | \ } d | i | <q< | d j oj| \ } } d }	 | d  j	 oM d | j o
 d }	 n g  }
 | D] } | d j o |
 | q½ q½ ~
 } n | d j o
 d } n d	 } |  i | | | d
 | ƒ|	 o½ d  } | i o! |  i	 i
 | i d | ƒ } n | d  j o |  i	 i
 | ƒ } n | d  j	 oK | i i | i ƒ | i i | i ƒ | i d  j o d | i | <qÞqâd | i | <qgq< | d j oh | \ } } } | o |  i | | | d
 | ƒqg|  i | d
 | ƒ} |  i | i d  | d
 d ƒq< t | ƒ ‚ q< Wx; | i D]0 } t | t | ƒ ƒ o |  i | | ƒ ququWd  S(   Ni   i   RŒ   i   R   R›   i    R_   iÿÿÿÿR.   RR   Rœ   (   i   i   (   s   imports   absolute_import(   RŽ   R$   t   version_infoRŸ   Rš   R   R   R‹   R   R%   R	   R   t   updateR   R   RH   t   RuntimeErrorR   t
   isinstanceR†   R‚   (   R   R‡   RQ   R”   t   scannert   whatR0   R   RM   t	   have_start   _[1]t   fR.   t   mmRN   R–   (    (    s"   /usr/lib/python2.6/modulefinder.pyR‚   ‹  sV    		 	
6 

! 
 c         C   sÁ   |  i  d d | | ƒ t i | ƒ } | o
 | } n |  i | ƒ } | | _ | g | _ | i t i | g  ƒ | _ |  i d | i ƒ \ } } } |  i | | | | ƒ |  i	 d d | ƒ | S(   Ni   Ry   R   s   load_package ->(
   R4   R   R	   R€   R   R   R   Rr   R=   R5   (   R   Rv   R>   R   RQ   R?   t   bufR@   (    (    s"   /usr/lib/python2.6/modulefinder.pyRy   Á  s    
	c         C   s7   | |  i  j o |  i  | St | ƒ |  i  | <} | S(   N(   R%   R   (   R   Rv   RQ   (    (    s"   /usr/lib/python2.6/modulefinder.pyR€   Ò  s    c         C   s¬   | d  j	 o | i d | } n | } | |  i j o  |  i d d | ƒ t | ‚ n | d  j o7 | t i j o d  d  d d t i f f S|  i	 } n t i
 | | ƒ S(   NRR   i   s   find_module -> ExcludedR7   (   R   R   R)   R5   RU   R$   t   builtin_module_namesR;   t	   C_BUILTINR   Rr   (   R   R   R   RN   RŠ   (    (    s"   /usr/lib/python2.6/modulefinder.pyRr   Ø  s    c         C   sC  Hd d GHd d GH|  i  i ƒ  } | i ƒ  xH | D]@ } |  i  | } | i o d Gn d Gd | G| i p d GHq3 W|  i ƒ  \ } } | oR Hd	 GHxI | D]= } |  i | i ƒ  } | i ƒ  d
 G| Gd Gd i | ƒ GHq Wn | oV Hd Gd GHxI | D]= } |  i | i ƒ  } | i ƒ  d
 G| Gd Gd i | ƒ GHqú Wn d S(   s’   Print a report to stdout, listing the found modules with their
        paths, as well as modules that are missing, or seem to be missing.
        s
     %-25s %st   Namet   Files   ----t   PRQ   s   %-25sR7   s   Missing modules:t   ?s   imported froms   , s7   Submodules thay appear to be missing, but could also bes#   global names in the parent package:N(   R­   R®   (   s   ----s   ----(   R%   Rj   t   sortR   R   t   any_missing_maybeR&   RV   (   R   Rj   t   keyRQ   t   missingt   maybeR   t   mods(    (    s"   /usr/lib/python2.6/modulefinder.pyt   reporté  s<    		
 
 
" 
c         C   s   |  i  ƒ  \ } } | | S(   s½   Return a list of modules that appear to be missing. Use
        any_missing_maybe() if you want to know which modules are
        certain to be missing, and which *may* be missing.
        (   R²   (   R   R´   Rµ   (    (    s"   /usr/lib/python2.6/modulefinder.pyt   any_missing  s    c         C   s.  g  } g  } x|  i  D]ö } | |  i j o q n | i d ƒ } | d j  o | i | ƒ q n | | d } | |  } |  i i | ƒ } | d j	 oe | |  i  | j o | i | ƒ q| | i j o q| i o | i | ƒ q| i | ƒ q | i | ƒ q W| i	 ƒ  | i	 ƒ  | | f S(   s®  Return two lists, one with modules that are certainly missing
        and one with modules that *may* be missing. The latter names could
        either be submodules *or* just global names in the package.

        The reason it can't always be determined is that it's impossible to
        tell which names are imported when "from module import *" is done
        with an extension module, short of actually importing it.
        RR   i    i   N(
   R&   R)   RW   R
   R%   R	   R   R   R   R±   (   R   R´   Rµ   R   R1   Re   t   pkgnamet   pkg(    (    s"   /usr/lib/python2.6/modulefinder.pyR²     s2    	
 



c         C   s‹  t  i i | i ƒ } } x@ |  i D]5 \ } } | i | ƒ o | | t | ƒ } Pq# q# W|  i of | |  i j oV | | j o |  i	 d d | | f ƒ n |  i	 d d | f ƒ |  i i
 | ƒ n t | i ƒ } xO t t | ƒ ƒ D]; } t | | t | ƒ ƒ o |  i | | ƒ | | <qî qî Wt i | i | i | i | i | i t | ƒ | i | i | | i | i | i | i | i ƒ S(   Ni   s   co_filename %r changed to %rs    co_filename %r remains unchanged(    RA   R   t   normpatht   co_filenameR*   t
   startswithR]   R'   R+   R5   R
   t   listR   R,   R£   R†   R   t   typest   CodeTypet   co_argcountt
   co_nlocalst   co_stacksizet   co_flagsRŽ   t   tupleR   t   co_varnamest   co_namet   co_firstlinenot	   co_lnotabt   co_freevarst   co_cellvars(   R   R‡   t   new_filenamet   original_filenameR¨   R   R•   R1   (    (    s"   /usr/lib/python2.6/modulefinder.pyR   D  s.    
 	 N(   R   R"   R   R   R3   R4   R5   R6   RF   RG   RH   RI   RJ   RK   R`   RZ   R=   R‰   R‹   t   structR“   Rš   RŸ   R‚   Ry   R€   Rr   R·   R¸   R²   R   (    (    (    s"   /usr/lib/python2.6/modulefinder.pyR#   K   s4   						#							6			%		.c          C   s8  d d  k  }  y# |  i  t i d d ƒ \ } } Wn |  i j
 o } | GHd  SXd } d } g  } g  } x¢ | D]š \ } }	 | d j o | d } n | d j o
 d } n | d j o | |	 i t i ƒ } n | d j o
 d } n | d	 j o | i |	 ƒ qo qo W| p
 d
 }
 n | d }
 t i } t i i	 |
 ƒ | d <| | } | d j o) d GHx! | D] } d Gt
 | ƒ GHqkWn t | | | ƒ } x€ | d D]t } | d j o d } q¥n | o@ | d d j o | i | d  d  d g ƒ q| i | ƒ q¥| i | ƒ q¥W| i |
 ƒ | i ƒ  | S(   Niÿÿÿÿi   s   dmp:qx:i    s   -ds   -ms   -ps   -qs   -xs   hello.pys   path:s      iþÿÿÿs   .*R_   (   t   getoptR$   t   argvRi   RB   RA   t   pathsepR
   R   t   dirnameR-   R#   RG   R   RF   R6   R·   (   RÏ   t   optsR0   R3   R'   t   domodst   addpatht   excludet   ot   at   scriptR   t   itemt   mfR2   (    (    s"   /usr/lib/python2.6/modulefinder.pyt   test`  s^    # 





  
R8   s   
[interrupt](    t   __doc__t
   __future__R    t   disR;   R~   RA   R$   R¿   RÎ   Ra   t
   __stdout__R:   t   chrt   opnamet   indexR   R   R   R   R‘   R’   R   R   R   R   R   R#   RÜ   R   RÛ   t   KeyboardInterrupt(    (    (    s"   /usr/lib/python2.6/modulefinder.pyt   <module>   s>   
		ÿ ÿ 	;