Ñò
ÎÑAHc        	   @   sÖ   d  Z  d d k l Z d e i d Z e i Z d Z d Z d d k	 Z	 d d k
 Z
 d d k Z d d d d d „ Z d	 „  Z d
 „  Z d „  Z d d „ Z h  a d „  Z d „  Z e	 i Z d d d g d „ Z d S(   s  
A module to change reload() so that it acts recursively.
To enable it type:
    >>> import __builtin__, deep_reload
    >>> __builtin__.reload = deep_reload.reload
You can then disable it with:
    >>> __builtin__.reload = deep_reload.original_reload
    
Alternatively, you can add a dreload builtin alongside normal reload with:
    >>> __builtin__.dreload = deep_reload.reload
    
This code is almost entirely based on knee.py from the standard library.

$Id: deep_reload.py 958 2005-12-27 23:17:51Z fperez $iÿÿÿÿ(   t   Releases   %s <%s>t   Nathans   0.5s   21 August 2001Nc   	      C   sa   t  | ƒ } t | |  ƒ \ } } t | | ƒ } | p | St | d ƒ o t | | ƒ n | S(   Nt   __path__(   t   determine_parentt   find_head_packaget	   load_tailt   hasattrt   ensure_fromlist(	   t   namet   globalst   localst   fromlistt   levelt   parentt   qt   tailt   m(    (    sK   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/deep_reload.pyt   deep_import_hook#   s    c         C   s´   |  p |  i  d ƒ o d  S|  d } |  i  d ƒ o) t i | } |  | i j p t ‚ | Sd | j oB | i d ƒ } | |  } t i | } | i | j p t ‚ | Sd  S(   Nt   __name__R   t   .(   t   has_keyt   Nonet   syst   modulest   __dict__t   AssertionErrort   rfindR   (   R	   t   pnameR   t   i(    (    sK   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/deep_reload.pyR   /   s    

c         C   sØ   d | j o+ | i  d ƒ } | |  } | | d } n | } d } |  o d |  i | f } n | } t | | |  ƒ } | o | | f S|  o4 | } d  }  t | | |  ƒ } | o | | f Sn t d | ‚ d  S(   NR   i   t    s   %s.%ss   No module named (   t   findR   t   import_moduleR   t   ImportError(   R   R   R   t   headR   t   qnameR   (    (    sK   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/deep_reload.pyR   ?   s&    
  c         C   s‘   |  } x„ | o| | i  d ƒ } | d j  o t | ƒ } n | |  | | d } } | i } t | | | ƒ } | p t d | ‚ q	 q	 W| S(   NR   i    i   s   No module named (   R   t   lenR   R   R    (   R   R   R   R   R!   t   mname(    (    sK   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/deep_reload.pyR   X   s      	i    c         C   sÆ   x¿ | D]· } | d j oE | p7 y |  i  } Wn t j
 o qX Xt |  | d ƒ q q n | d j oR t |  | ƒ oA d |  i | f } t | | |  ƒ } | p t d | ‚ q¾ q q Wd  S(   Nt   *i   s   %s.%ss   No module named (   t   __all__t   AttributeErrorR   R   R   R   R    (   R   R   t	   recursivet   subt   allt   subnamet   submod(    (    sK   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/deep_reload.pyR   k   s     c         C   sà   t  i | ƒ o) y t i | SWq9 t j
 o q9 Xn d G| GHd t  | <y) t i |  | o | i ƒ \ } } } Wn t j
 o d  SXz t i
 | | | | ƒ } Wd  | o | i ƒ  n X| o t | |  | ƒ n | S(   Nt	   Reloadingi   (   t	   found_nowR   R   R   t   KeyErrort   impt   find_moduleR   R    R   t   load_modulet   closet   setattr(   t   partnamet   fqnameR   t   fpt   pathnamet   stuffR   (    (    sK   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/deep_reload.pyR      s&    		
	  c         C   se   |  i  } d | j o t | | d  ƒ S| i d ƒ } | |  } t i | } t | | d | | ƒ S(   NR   i   (   R   R   R   R   R   R   (   t   moduleR   R   R   R   (    (    sK   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/deep_reload.pyt   deep_reload_hook›   s    	
R   t   __builtin__t   __main__c         C   sT   x | D] } d t  | <q Wt i } t t _ z t |  ƒ } Wd | t _ h  a  X| S(   s
  Recursively reload all modules used in the given module.  Optionally
    takes a list of modules to exclude from reloading.  The default exclude
    list contains sys, __main__, and __builtin__, to prevent, e.g., resetting 
    display, exception, and io hooks.
    i   N(   R.   R<   t
   __import__R   R;   (   R:   t   excludeR   t   original_importt   ret(    (    sK   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/deep_reload.pyt   reload¨   s     			(   t   __doc__t   IPythonR    t   authorst
   __author__t   licenset   __license__t   __version__t   __date__R<   R0   R   R   R   R   R   R   R   R.   R   R;   RB   t   original_reload(    (    (    sK   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/deep_reload.pyt   <module>   s$   							
	