diff options
Diffstat (limited to 'eventlet/patcher.py')
| -rw-r--r-- | eventlet/patcher.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/eventlet/patcher.py b/eventlet/patcher.py index 2b75272..cdbda33 100644 --- a/eventlet/patcher.py +++ b/eventlet/patcher.py @@ -80,6 +80,14 @@ def inject(module_name, new_globals, *additional_modules): # state of all the modules we're going to mess with, and lock saver = SysModulesSaver([name for name, m in additional_modules]) saver.save(module_name) + if '.' in module_name: + parent_name, attribute_name = module_name.rsplit('.', 1) + parent_module = sys.modules.get(parent_name) + if parent_module: + not_set = object() + old_attribute_in_parent = getattr(parent_module, attribute_name, not_set) + else: + parent_module = None # Cover the target modules so that when you import the module it # sees only the patched versions @@ -102,6 +110,11 @@ def inject(module_name, new_globals, *additional_modules): sys.modules[patched_name] = module finally: saver.restore() # Put the original modules back + if parent_module and not old_attribute_in_parent is not_set: + new_attribute = getattr(parent_module, attribute_name) + if new_attribute is not old_attribute_in_parent: + setattr(parent_module, attribute_name, old_attribute_in_parent) + return module |
