
    h                          " S  S5      r g)c                   J    \ rS rSrSrS rS rS rS r\r	S r
SS	 jrS
 rSrg)MonkeyPatcher   zb
Cover up attributes with new objects. Neat for monkey-patching things for
unit-testing purposes.
c                 P    / U l         / U l        U H  nU R                  " U6   M     g N)_patchesToApply
_originalsaddPatch)selfpatchespatchs      \/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/python/monkey.py__init__MonkeyPatcher.__init__   s)    ! EMM5!     c                 >    U R                   R                  XU45        g)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	   MonkeyPatcher.addPatch   s     	##S$67r   c                 D    U R                    H  u  p4nX44X4:X  d  M    g   g)zK
Has the C{name} attribute of C{obj} already been patched by this
patcher?
TF)r   )r
   r   r   onvs         r   _alreadyPatchedMonkeyPatcher._alreadyPatched   s*    
 GA!v#$ ' r   c           	          U R                    HN  u  pnU R                  X5      (       d&  U R                  R                  X[	        X5      45        [        XU5        MP     g)zn
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   MonkeyPatcher.patch)   sP    
 !% 4 4Cu''22&&733E'FGCu% !5r   c                     U R                   (       a=  U R                   R                  5       u  pn[        XU5        U R                   (       a  M<  gg)z5
Restore all original values to any patched objects.
N)r   popr    r   s       r   restoreMonkeyPatcher.restore5   s7     oo#224CuCu% ooor   Nc                 $    U R                  5         g r   )r$   )r
   excTypeexcValueexcTracebacks       r   __exit__MonkeyPatcher.__exit__=   s    r   c                 ~    U R                  5          U" U0 UD6U R                  5         $ ! U R                  5         f = f)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   runWithPatchesMonkeyPatcher.runWithPatches@   s0    
 	

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