ó
[³XMc           @   s   d  e  f d „  ƒ  YZ d S(   t   MonkeyPatcherc           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sn   
    Cover up attributes with new objects. Neat for monkey-patching things for
    unit-testing purposes.
    c         G   s4   g  |  _  g  |  _ x | D] } |  j | Œ  q Wd  S(   N(   t   _patchesToApplyt
   _originalst   addPatch(   t   selft   patchest   patch(    (    s9   /usr/lib/python2.7/dist-packages/twisted/python/monkey.pyt   __init__   s    		c         C   s   |  j  j | | | f ƒ d S(   sæ   
        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   t   append(   R   t   objt   namet   value(    (    s9   /usr/lib/python2.7/dist-packages/twisted/python/monkey.pyR      s    c         C   s=   x6 |  j  D]+ \ } } } | | f | | f k r
 t Sq
 Wt S(   sc   
        Has the C{name} attribute of C{obj} already been patched by this
        patcher?
        (   R   t   Truet   False(   R   R	   R
   t   ot   nt   v(    (    s9   /usr/lib/python2.7/dist-packages/twisted/python/monkey.pyt   _alreadyPatched!   s    c         C   sh   xa |  j  D]V \ } } } |  j | | ƒ sP |  j j | | t | | ƒ f ƒ n  t | | | ƒ q
 Wd S(   s†   
        Apply all of the patches that have been specified with L{addPatch}.
        Reverse this operation using L{restore}.
        N(   R   R   R   R   t   getattrt   setattr(   R   R	   R
   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/python/monkey.pyR   ,   s    %c         C   s<   x5 |  j  r7 |  j  j ƒ  \ } } } t | | | ƒ q Wd S(   sE   
        Restore all original values to any patched objects.
        N(   R   t   popR   (   R   R	   R
   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/python/monkey.pyt   restore7   s    c         O   s-   |  j  ƒ  z | | | Ž  SWd |  j ƒ  Xd S(   s“   
        Apply each patch already specified. Then run the function f with the
        given args and kwargs. Restore everything when done.
        N(   R   R   (   R   t   ft   argst   kw(    (    s9   /usr/lib/python2.7/dist-packages/twisted/python/monkey.pyt   runWithPatches@   s    
(	   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/python/monkey.pyR       s   	
	
				N(   t   objectR    (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/python/monkey.pyt   <module>   s    