o ¯btã@sGdd„dƒZdS)c@s@eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dS)Ú MonkeyPatcherzn Cover up attributes with new objects. Neat for monkey-patching things for unit-testing purposes. cGs$g|_g|_|D]}|j|ŽqdS)N)Ú_patchesToApplyÚ _originalsÚaddPatch)ÚselfÚpatchesÚpatch©rú7/usr/lib/python3/dist-packages/twisted/python/monkey.pyÚ__init__ s  ÿzMonkeyPatcher.__init__cCs|j |||f¡dS)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Úvaluerrr rszMonkeyPatcher.addPatchcCs,|jD]\}}}||f||fkrdSqdS)zc Has the C{name} attribute of C{obj} already been patched by this patcher? TF)r)rr rÚoÚnÚvrrr Ú_alreadyPatcheds ÿzMonkeyPatcher._alreadyPatchedcCsF|jD]\}}}| ||¡s|j ||t||ƒf¡t|||ƒqdS)z† Apply all of the patches that have been specified with L{addPatch}. Reverse this operation using L{restore}. N)rrrr ÚgetattrÚsetattrr rrr r)s  ýzMonkeyPatcher.patchcCs0|jr|j ¡\}}}t|||ƒ|jsdSdS)zE Restore all original values to any patched objects. N)rÚpoprr rrr Úrestore3s þzMonkeyPatcher.restorecOs,| ¡z ||i|¤ŽW| ¡S| ¡w)z“ Apply each patch already specified. Then run the function f with the given args and kwargs. Restore everything when done. )rr)rÚfÚargsÚkwrrr ÚrunWithPatches;szMonkeyPatcher.runWithPatchesN) Ú__name__Ú __module__Ú __qualname__Ú__doc__r rrrrrrrrr rs    rN)rrrrr Ús