
    Ϫf                          G d  d      Z y)c                   @    e Zd ZdZd Zd Zd Zd ZeZd Z	d
dZ
d	 Zy)MonkeyPatcherzn
    Cover up attributes with new objects. Neat for monkey-patching things for
    unit-testing purposes.
    c                 L    g | _         g | _        |D ]  } | j                  |   y N)_patchesToApply
_originalsaddPatch)selfpatchespatchs      7/usr/lib/python3/dist-packages/twisted/python/monkey.py__init__zMonkeyPatcher.__init__   s0    !  	"EDMM5!	"    c                 @    | j                   j                  |||f       y)z
        Add a patch so that the attribute C{name} on C{obj} will be assigned to
        C{value} when C{patch} is called or during C{runWithPatches}.

        You can restore the original values with a call to restore().
        N)r   appendr	   objnamevalues       r   r   zMonkeyPatcher.addPatch   s     	##S$$67r   c                 D    | j                   D ]  \  }}}||f||fk(  s y y)zc
        Has the C{name} attribute of C{obj} already been patched by this
        patcher?
        TF)r   )r	   r   r   onvs         r   _alreadyPatchedzMonkeyPatcher._alreadyPatched   s5    
  	GAq!1v#t$	 r   c           	          | j                   D ]M  \  }}}| j                  ||      s(| j                  j                  ||t	        ||      f       t        |||       O y)z
        Apply all of the patches that have been specified with L{addPatch}.
        Reverse this operation using L{restore}.
        N)r   r   r   r   getattrsetattrr   s       r   r   zMonkeyPatcher.patch)   s\    
 !% 4 4 	&Cu''T2&&T733E'FGCu%	&r   c                     | j                   r9| j                   j                         \  }}}t        |||       | j                   r8yy)zE
        Restore all original values to any patched objects.
        N)r   popr   r   s       r   restorezMonkeyPatcher.restore5   s9     oo#224CuCu% oor   Nc                 $    | j                          y r   )r   )r	   excTypeexcValueexcTracebacks       r   __exit__zMonkeyPatcher.__exit__=   s    r   c                 ~    | j                          	  ||i || j                          S # | j                          w xY w)z
        Apply each patch already specified. Then run the function f with the
        given args and kwargs. Restore everything when done.
        )r   r   )r	   fargskws       r   runWithPatcheszMonkeyPatcher.runWithPatches@   s0    
 	

	d>b>LLNDLLNs   * <)NNN)__name__
__module____qualname____doc__r   r   r   r   	__enter__r   r$   r)    r   r   r   r      s1    
"8& I&	r   r   N)r   r/   r   r   <module>r0      s   B Br   