diff options
| -rw-r--r-- | eventlet/patcher.py | 13 | ||||
| -rw-r--r-- | tests/isolated/patcher_python3_http_client_regression.py | 6 | ||||
| -rw-r--r-- | tests/patcher_test.py | 5 |
3 files changed, 24 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 diff --git a/tests/isolated/patcher_python3_http_client_regression.py b/tests/isolated/patcher_python3_http_client_regression.py new file mode 100644 index 0000000..ec416ad --- /dev/null +++ b/tests/isolated/patcher_python3_http_client_regression.py @@ -0,0 +1,6 @@ +if __name__ == '__main__': + import http.client + original_id = id(http.client) + import eventlet.green.http.client # noqa + assert id(http.client) == original_id + print('pass') diff --git a/tests/patcher_test.py b/tests/patcher_test.py index 5aae0ac..a3a3cd5 100644 --- a/tests/patcher_test.py +++ b/tests/patcher_test.py @@ -528,3 +528,8 @@ def test_socketserver_selectors(): def test_blocking_select_methods_are_deleted(): tests.run_isolated('patcher_blocking_select_methods_are_deleted.py') + + +if six.PY3: + def test_http_client_regression(): + tests.run_isolated('patcher_python3_http_client_regression.py') |
