
    \d                         U d Z ddlZddlZddlZddlZddlmZ ddlmZ ddlm	Z	 ddl
mZmZ  ej                    a G d d          Zi Ze	eef         ed	<   d
 Zd Z G d de          Zd Zd ZddZdS )z&
*Real* reloading support for Python.
    N)reload)
ModuleType)Dict)logreflectc                   (    e Zd ZdZeZd Zd Zd ZdS )	Sensitivez
    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                 &    | j         t           k     }|S N)lastRebuild)selfyns     6lib/python3.11/site-packages/twisted/python/rebuild.pyneedRebuildUpdatezSensitive.needRebuildUpdate$   s    +	    c                 6    t          j                     | _        d S r   )timer   r   s    r   rebuildUpToDatezSensitive.rebuildUpToDate(   s    9;;r   c                     t          |          }|t          j        k    rt          |          S |t          j        k    r;|j        t          |j        |j                  S t          |j        |j                  S t          j
        d           |S )z
        Get the latest version of an object.

        This can handle just about anything callable; instances, functions,
        methods, and classes.
        Nzwarning returning anObject!)typetypesFunctionTypelatestFunction
MethodType__self__getattrim_class__name__r   msg)r   anObjectts      r   latestVersionOfzSensitive.latestVersionOf+   s     NN"""!(+++%""" (x0(2CDDDx0(2CDDDG1222Or   N)r   
__module____qualname____doc__r   r   r   r#    r   r   r	   r	      sR          K  ' ' '    r   r	   _modDictIDMapc                     t          | j                  }t                              |          }|| S t	          || j                  S )z/
    Get the latest version of a function.
    )id__globals__r(   getr   r   )oldFuncdictIDmodules      r   r   r   B   sD     #$$Fv&&F~67+,,,r   c                 h   t          j        | j                  }t          || j                  }d |j        D             }|j        dk    r|S 	 t          |          |_        |S # t          $ rC t          |          } ||j        t          |          t          |j
                            cY S w xY w)z,
    Get the latest version of a class.
    c                 ,    g | ]}t          |          S r'   )latestClass).0bases     r   
<listcomp>zlatestClass.<locals>.<listcomp>U   s     AAAdD!!AAAr   builtins)r   namedModuler$   r   r   	__bases__tuple	TypeErrorr   dict__dict__)oldClassr/   newClassnewBasesctors        r   r2   r2   O   s      !455Fvx011HAAh.@AAAHj((Q"8__ Q Q QH~~tH%uXX=N8O8OPPPPPQs   A$ $A
B10B1c                       e Zd ZdZdS )RebuildErrorzT
    Exception raised when trying to rebuild a class whereas it's not possible.
    N)r   r$   r%   r&   r'   r   r   rB   rB   d   s           r   rB   c                 8    t          | j                  | _        dS )z,
    Updates an instance to be current.
    N)r2   	__class__r   s    r   updateInstancerE   j   s     !00DNNNr   c                     |dk    rt          d          t          |            t          j        dt	          j        | j                   d| d           t          | |          }|S )z<
    A getattr method to cause a class to be refreshed.
    __del__zWithout this, Python segfaults.z(rebuilding stale z instance (z)))AttributeErrorrE   r   r    r   qualrD   r   )r   nameresults      r   __injectedgetattr__rL   q   sp     y>???4GRdn!=!=RR$RRRSSST4  FMr      c                    t          j                     at          | d          r| j        st	          d          |r*t          j        dt          | j                   d           ddl	m
} d|_        | j        }| t          t          |          <   i }i }i }i }|r*t          j        dt          | j                   d	           |                                D ]\  }}	t!          t#          |	          t$          j                  rS|	j        | j        u rDd
||	<   |r=t
          j                            d           t
          j                                         t1          |	t"                    rT|	j        | j        k    rDd
||	<   |r=t
          j                            d           t
          j                                         |                    |           |                    |           |j        }
|                                }|                                }|                                }|r>t          j        d           t          j        dt          | j                   d           t;          |            t=          j                     |r*t          j        dt          | j                   d	           |D ]}tA          | |j                  |u r+t          j        dtC          j"        |           d           D|r=t
          j                            d           t
          j                                         d|_#        |j        $                                 tJ          |_&        | j        |_        |rddl'}|D ]}tA          | |j                  }||u r:t          j        d(                    tC          j"        |                               U|)                    |          D ]}tA          |dd          |u r||_*        |r>t          j        d           t          j        dt          | j                   d	           d}tV          j,                                        D ].\  }}|d
z   }|| k    s|t          |d          s%t          |d          r6d}|j                                        D ]\  }}		 t[          |	           n# t\          $ r Y "w xY w |
|	          ra|r=t
          j                            d           t
          j                                         t_          |	          }d
}ta          |||           |rH|sF|dz  dk    r=t
          j                            d           t
          j                                         0d|_        |r>t          j        d           t          j        dt          | j                   d           | S )zO
    Reload a module and do as much as possible to replace its references.
    ALLOW_TWISTED_REBUILDzI am not allowed to be rebuilt.zRebuilding z...r   )
componentsTz  (scanning z): rM   fo z  (reload   )z  (cleaning zWARNING: class z not replaced by reload!xr'   Nz-WARNING: new-class {} not replaced by reload!rD   z  (fixing   __file__
__bundle__
   .Fz   Rebuilt )1r   r   hasattrrO   RuntimeErrorr   r    strr   twisted.pythonrP   ALLOW_DUPLICATESr<   r(   r*   items
issubclassr   r   r   r+   logfilewriteflush
isinstancer$   update__contains__keysr   	linecache
clearcacher   r   rI   r8   clearrL   __getattr__gcformatget_referrersrD   sysmoduleshash	Exceptionr   setattr)r/   doLogrP   d
newclassesclasses	functionsvalueskvfromOldModuleclazzrl   nclassgarmodcountmkmodchangednvs                        r   rebuildr   }   s   
 )++Kv.// B+ 	B@AAA 97c&/22777888 *)))))"&JA!M"Q%%JGIF :8s6?33888999		 ( (1d1ggu122 	(}// 	! (K%%c***K%%'''4   	(|v.. !
1 (K%%c***K%%'''
MM'
MM)'M""JllnnG  I 86s6?33666777 6NNN :8s6?33888999 
/ 
/65>**e33GSgl5&9&9SSSTTTT $!!#&&&!!### EON  """ 3E%E 			 % %VV_--<<G?FFL((     %%f-- % %1k400F::"$AK%  :8s6?33888999H;$$&&    Ca<&==CKsJ'' 	3%% 	 L&&(( 	$ 	$DAqQ   }Q $ (K%%c***K%%'''#A&&Q### 	  	 x"}&:&:Kc"""K"'J 75c&/22555666Ms   S
SS)rM   )r&   rh   ro   r   r   impr   r   typingr   r]   r   r   r   r	   r(   int__annotations__r   r2   rr   rB   rE   rL   r   r'   r   r   <module>r      sm         


                     ( ' ' ' ' ' ' 'dikk" " " " " " " "J (*tCO$ ) ) )
- 
- 
-Q Q Q*    9   1 1 1	 	 	} } } } } }r   