Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Undoing replacements

  • Loading branch information...
commit f24f12b790c71f4ac10a00f7e31bbd13ade20c82 1 parent 4a89bd2
Bernardo Heynemann authored
Showing with 5 additions and 0 deletions.
  1. +5 −0 mi7/core.py
5 mi7/core.py
View
@@ -116,6 +116,7 @@ def __init__(self, source_agent, method_name):
self.method_name = method_name
self.return_value = None
self.old_method = None
+ self.replacements = []
self.watch()
def watch(self):
@@ -132,6 +133,7 @@ def watch(self):
module = reduce(getattr, module_name.split('.')[1:], module)
if hasattr(module, self.method_name):
if getattr(module, self.method_name).__module__ == self.agent.target_module_name:
+ self.replacements.append((module, self.method_name, getattr(module, self.method_name)))
setattr(module, self.method_name, self.execute)
elif hasattr(module, self.agent.target.__name__):
setattr(module, self.agent.target.__name__, self.agent.target)
@@ -141,6 +143,9 @@ def get_lost(self):
'''Stop intercepting the target.'''
setattr(self.agent.target, self.method_name, self.old_method)
self.old_method = None
+ for replacement in self.replacements:
+ setattr(replacement[0], replacement[1], replacement[2])
+ self.replacements = []
def execute(self, *args, **kw):
'''Executes the interception.'''
Please sign in to comment.
Something went wrong with that request. Please try again.