ó
[³XMc           @   s»   d  Z  d d l Z d d l Z d d l Z d d l Z d d l m Z m Z e j ƒ  a d d d „  ƒ  YZ	 i  Z
 d „  Z d „  Z d e f d	 „  ƒ  YZ d
 „  Z d „  Z d d „ Z d S(   s&   
*Real* reloading support for Python.
iÿÿÿÿN(   t   logt   reflectt	   Sensitivec           B   s/   e  Z d  Z e Z d „  Z d „  Z d „  Z RS(   sÐ   
    A utility mixin that's sensitive to rebuilds.

    This is a mixin for classes (usually those which represent collections of
    callbacks) to make sure that their code is up-to-date before running.
    c         C   s   |  j  t  k  } | S(   N(   t   lastRebuild(   t   selft   yn(    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/rebuild.pyt   needRebuildUpdate    s    c         C   s   t  j  ƒ  |  _ d  S(   N(   t   timeR   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/rebuild.pyt   rebuildUpToDate$   s    c         C   s½   t  | ƒ } | t j k r% t | ƒ S| t j k rl | j d k rV t | j | j	 ƒ St | j | j	 ƒ SnM | t j
 k r t | d d ƒ | S| t j k r¨ t | ƒ St j d ƒ | Sd S(   s¡   
        Get the latest version of an object.

        This can handle just about anything callable; instances, functions,
        methods, and classes.
        t   nothings   warning returning anObject!N(   t   typet   typest   FunctionTypet   latestFunctiont
   MethodTypet   im_selft   Nonet   getattrt   im_classt   __name__t   InstanceTypet	   ClassTypet   latestClassR    t   msg(   R   t   anObjectt   t(    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/rebuild.pyt   latestVersionOf'   s    

(   R   t
   __module__t   __doc__R   R   R   R   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/rebuild.pyR      s
   		c         C   s>   t  |  j ƒ } t j | ƒ } | d k r. |  St | |  j ƒ S(   s/   
    Get the latest version of a function.
    N(   t   idt   func_globalst   _modDictIDMapt   getR   R   R   (   t   oldFunct   dictIDt   module(    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/rebuild.pyR   B   s
    c         C   s¹   t  j |  j ƒ } t | |  j ƒ } g  | j D] } t | ƒ ^ q. } y t | ƒ | _ | SWnU t k
 r´ | j d k r€ | St | d t	 ƒ } | | j t | ƒ t
 | j ƒ ƒ SXd S(   s,   
    Get the latest version of a class.
    t   __builtin__t   __metaclass__N(   R   t   namedModuleR   R   R   t	   __bases__R   t   tuplet	   TypeErrorR
   t   dictt   __dict__(   t   oldClassR#   t   newClasst   baset   newBasest   ctor(    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/rebuild.pyR   O   s    "t   RebuildErrorc           B   s   e  Z d  Z RS(   sT   
    Exception raised when trying to rebuild a class whereas it's not possible.
    (   R   R   R   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/rebuild.pyR1   c   s   c         C   sR   y t  |  j ƒ |  _ Wn5 t k
 rM t |  j d ƒ rG t d ƒ ‚ qN ‚  n Xd S(   s,   
    Updates an instance to be current.
    t	   __slots__s2   Can't rebuild class with __slots__ on Python < 2.6N(   R   t	   __class__R)   t   hasattrR1   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/rebuild.pyt   updateInstancei   s    c         C   s[   | d k r t  d ƒ ‚ n  t |  ƒ t j d t j |  j ƒ | f ƒ t |  | ƒ } | S(   s<   
    A getattr method to cause a class to be refreshed.
    t   __del__s   Without this, Python segfaults.s#   (rebuilding stale %s instance (%s))(   t   AttributeErrorR5   R    R   R   t   qualR3   R   (   R   t   namet   result(    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/rebuild.pyt   __getattr__v   s    
#i   c         C   s+  t  j  ƒ  a t |  d ƒ r6 |  j s6 t d ƒ ‚ q6 n  | rY t j d t |  j ƒ ƒ n  d d l	 m
 } t | _ |  j } |  t t | ƒ <i  } i  } i  } i  } | rÆ t j d t |  j ƒ ƒ n  x+| j ƒ  D]\ } }	 t |	 ƒ t j k r<|	 j |  j k rðd | |	 <| r9t j j d ƒ t j j ƒ  q9qðqÓ t |	 ƒ t j k r™|	 j |  j k rðd | |	 <| r–t j j d	 ƒ t j j ƒ  q–qðqÓ t |	 t ƒ rÓ |	 j |  j k rðd | |	 <| rít j j d
 ƒ t j j ƒ  qíqðqÓ qÓ W| j | ƒ | j | ƒ | j }
 | j ƒ  } | j ƒ  } | j ƒ  } | rkt j d ƒ t j d t |  j ƒ ƒ n  t |  ƒ t j  ƒ  | r¢t j d t |  j ƒ ƒ n  x” | D]Œ } t! |  | j ƒ | k rät j d t" j# | ƒ ƒ q©| r
t j j d ƒ t j j ƒ  n  d | _$ | j j% ƒ  t& | _& |  j | _ q©W| rNd d l' } n  x‡ | D] } t! |  | j ƒ } | | k r–t j d t" j# | ƒ ƒ qUx; | j( | ƒ D]* } t! | d d ƒ | k r¦| | _* q¦q¦WqUW| rt j d ƒ t j d t |  j ƒ ƒ n  d } xÝt+ j, j ƒ  D]Ì\ } } | d } | |  k s| d k rRqn  t | d ƒ sgqn  t | d ƒ r|qn  d } x(| j j ƒ  D]\ } }	 y t- |	 ƒ Wn t. k
 rÂq’n X|
 |	 ƒ rdt |	 ƒ t j k r| r
t j j d ƒ t j j ƒ  n  t/ |	 ƒ } n2 | r?t j j d	 ƒ t j j ƒ  n  t0 |	 ƒ } d } t1 | | | ƒ q’t |	 ƒ t j k r’x- |	 j$ D] } |
 | ƒ rƒt/ |	 ƒ qƒqƒWq’q’W| r| r| d d k rt j j d ƒ t j j ƒ  qqWt2 | _ | r't j d ƒ t j d t |  j ƒ ƒ n  |  S(   sO   
    Reload a module and do as much as possible to replace its references.
    t   ALLOW_TWISTED_REBUILDs   I am not allowed to be rebuilt.s   Rebuilding %s...iÿÿÿÿ(   t
   componentss     (scanning %s): i   t   ct   ft   ot    s     (reload   %s)s     (cleaning %s): s)   WARNING: class %s not replaced by reload!t   xNs-   WARNING: new-class %s not replaced by reload!R3   s     (fixing   %s): i    t   __file__t
   __bundle__i
   t   .s      Rebuilt %s.(    (3   R   R   R4   R<   t   RuntimeErrorR    R   t   strR   t   twisted.pythonR=   t   Truet   ALLOW_DUPLICATESR+   R   R   t   itemsR
   R   R   R   t   logfilet   writet   flushR   R   t
   isinstancet   updatet   has_keyt   keyst   reloadt	   linecachet
   clearcacheR   R   R8   R'   t   clearR;   t   gct   get_referrersR   R3   t   syst   modulest   hasht	   ExceptionR   R   t   setattrt   False(   R#   t   doLogR=   t   dt
   newclassest   classest	   functionst   valuest   kt   vt   fromOldModulet   clazzRW   t   nclasst   gat   rt   modcountt   mkt   modt   changedt   nvR.   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/rebuild.pyt   rebuild‚   sÚ    			


	

		
	(    (   R   RY   R   R   RT   RH   R    R   R   R   R   R   R   R\   R1   R5   R;   Rq   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/rebuild.pyt   <module>   s   *				