/usr/lib/python3/dist-packages/twisted/python/__pycache__
Edit: /usr/lib/python3/dist-packages/twisted/python/__pycache__/monkey.cpython-310.pyc (2315B)
o
¯bt ã @ s G d d„ dƒZ dS )c @ s@ e Zd ZdZdd„ Zdd„ Zdd„ Zdd „ Zd
d„ Zdd
„ Z dS )Ú
MonkeyPatcherzn
Cover up attributes with new objects. Neat for monkey-patching things for
unit-testing purposes.
c G s$ g | _ g | _|D ]}| j|Ž qd S )N)Ú_patchesToApplyÚ
_originalsÚaddPatch)ÚselfÚpatchesÚpatch© r ú7/usr/lib/python3/dist-packages/twisted/python/monkey.pyÚ__init__
s
ÿzMonkeyPatcher.__init__c C s | 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Úvaluer r r r s zMonkeyPatcher.addPatchc C s, | j D ]\}}}||f||fkr dS qdS )zc
Has the C{name} attribute of C{obj} already been patched by this
patcher?
TF)r )r r
r ÚoÚnÚvr r r Ú_alreadyPatched s
ÿzMonkeyPatcher._alreadyPatchedc C sF | j D ]\}}}| ||¡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)r r r r ÚgetattrÚsetattrr r r r r ) s
ýzMonkeyPatcher.patchc C s0 | j r| j ¡ \}}}t|||ƒ | j sdS dS )zE
Restore all original values to any patched objects.
N)r Úpopr r r r r Úrestore3 s þzMonkeyPatcher.restorec O s, | ¡ 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.
)r r )r ÚfÚargsÚkwr r r ÚrunWithPatches; s zMonkeyPatcher.runWithPatchesN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
r r r r r r r r r r s
r N)r r r r r Ú
s