ϪfGddZy)c@eZdZdZdZdZdZdZeZdZ d dZ d Z y) MonkeyPatcherzn Cover up attributes with new objects. Neat for monkey-patching things for unit-testing purposes. cLg|_g|_|D]}|j|yN)_patchesToApply _originalsaddPatch)selfpatchespatchs 7/usr/lib/python3/dist-packages/twisted/python/monkey.py__init__zMonkeyPatcher.__init__ s0! "E DMM5 ! "c@|jj|||fy)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)rappendr objnamevalues r rzMonkeyPatcher.addPatchs ##S$$67rcD|jD]\}}}||f||fk(syy)zc Has the C{name} attribute of C{obj} already been patched by this patcher? TF)r)r rronvs r _alreadyPatchedzMonkeyPatcher._alreadyPatcheds5  GAq!1v#t$ rc |jD]M\}}}|j||s(|jj||t ||ft |||Oy)z Apply all of the patches that have been specified with L{addPatch}. Reverse this operation using L{restore}. N)rrrrgetattrsetattrrs r r zMonkeyPatcher.patch)s\ !% 4 4 & Cu''T2&&T733E'FG Cu % &rc|jr9|jj\}}}t||||jr8yy)zE Restore all original values to any patched objects. N)rpoprrs r restorezMonkeyPatcher.restore5s9oo#224 Cu Cu %oorNc$|jyr)r)r excTypeexcValue excTracebacks r __exit__zMonkeyPatcher.__exit__=s  rc~|j ||i||jS#|jwxYw)z Apply each patch already specified. Then run the function f with the given args and kwargs. Restore everything when done. )r r)r fargskws r runWithPatcheszMonkeyPatcher.runWithPatches@s0  d>b> LLNDLLNs*<)NNN) __name__ __module__ __qualname____doc__r rrr __enter__rr$r)rr rrs1 "8&I& rrN)rr/rr r0sBBr