Your IP : 216.73.216.213
B
:��]� � @ s$ d dl mZmZ G dd� de�ZdS )� )�division�absolute_importc @ 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 | _x|D ]}| j|� qW d S )N)�_patchesToApply�
_originals�addPatch)�selfZpatches�patch� r
�H/opt/alt/python37/lib64/python3.7/site-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. x(| j D ]\}}}||f||fkrdS qW dS )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 sJ xD| j D ]:\}}}| �||�s6| j�||t||�f� t|||� qW dS )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�setattr)r r r r r
r
r r . s zMonkeyPatcher.patchc C s, x&| j r&| j �� \}}}t|||� qW dS )zE
Restore all original values to any patched objects.
N)r �popr )r r r r r
r
r �restore9 s zMonkeyPatcher.restorec O s"