Merge
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
|
||||
|
||||
__select = __import__('select')
|
||||
error = __select.error
|
||||
from eventlet.api import getcurrent
|
||||
@@ -21,6 +23,12 @@ def get_fileno(obj):
|
||||
return rv
|
||||
|
||||
def select(read_list, write_list, error_list, timeout=None):
|
||||
# error checking like this is required by the stdlib unit tests
|
||||
if timeout is not None:
|
||||
try:
|
||||
timeout = float(timeout)
|
||||
except ValueError:
|
||||
raise TypeError("Expected number for timeout")
|
||||
hub = get_hub()
|
||||
t = None
|
||||
current = getcurrent()
|
||||
|
@@ -6,6 +6,7 @@ _fileobject = __socket._fileobject
|
||||
from eventlet.hubs import get_hub
|
||||
from eventlet.greenio import GreenSocket as socket
|
||||
from eventlet.greenio import SSL as _SSL # for exceptions
|
||||
import sys
|
||||
import warnings
|
||||
|
||||
def fromfd(*args):
|
||||
@@ -18,8 +19,13 @@ def socketpair(*args):
|
||||
def gethostbyname(name):
|
||||
if getattr(get_hub(), 'uses_twisted_reactor', None):
|
||||
globals()['gethostbyname'] = _gethostbyname_twisted
|
||||
elif sys.platform.startswith('darwin'):
|
||||
# the thread primitives on Darwin have some bugs that make
|
||||
# it undesirable to use tpool for hostname lookups
|
||||
globals()['gethostbyname'] = __socket.gethostbyname
|
||||
else:
|
||||
globals()['gethostbyname'] = _gethostbyname_tpool
|
||||
|
||||
return globals()['gethostbyname'](name)
|
||||
|
||||
def _gethostbyname_twisted(name):
|
||||
|
@@ -73,4 +73,4 @@ def get_hub():
|
||||
except AttributeError:
|
||||
use_hub()
|
||||
hub = _threadlocal.hub = _threadlocal.Hub()
|
||||
return hub
|
||||
return hub
|
||||
|
@@ -13,28 +13,30 @@ def inject(module_name, new_globals, *additional_modules):
|
||||
|
||||
## Remove the old module from sys.modules and reimport it while the specified modules are in place
|
||||
old_module = sys.modules.pop(module_name, None)
|
||||
module = __import__(module_name, {}, {}, module_name.split('.')[:-1])
|
||||
try:
|
||||
module = __import__(module_name, {}, {}, module_name.split('.')[:-1])
|
||||
|
||||
if new_globals is not None:
|
||||
## Update the given globals dictionary with everything from this new module
|
||||
for name in dir(module):
|
||||
if name not in __exclude:
|
||||
new_globals[name] = getattr(module, name)
|
||||
if new_globals is not None:
|
||||
## Update the given globals dictionary with everything from this new module
|
||||
for name in dir(module):
|
||||
if name not in __exclude:
|
||||
new_globals[name] = getattr(module, name)
|
||||
|
||||
## Keep a reference to the new module to prevent it from dying
|
||||
sys.modules['__patched_module_' + module_name] = module
|
||||
## Put the original module back
|
||||
if old_module is not None:
|
||||
sys.modules[module_name] = old_module
|
||||
else:
|
||||
del sys.modules[module_name]
|
||||
## Keep a reference to the new module to prevent it from dying
|
||||
sys.modules['__patched_module_' + module_name] = module
|
||||
finally:
|
||||
## Put the original module back
|
||||
if old_module is not None:
|
||||
sys.modules[module_name] = old_module
|
||||
elif module_name in sys.modules:
|
||||
del sys.modules[module_name]
|
||||
|
||||
## Put all the saved modules back
|
||||
for name, mod in additional_modules:
|
||||
if saved[name] is not None:
|
||||
sys.modules[name] = saved[name]
|
||||
else:
|
||||
del sys.modules[name]
|
||||
## Put all the saved modules back
|
||||
for name, mod in additional_modules:
|
||||
if saved[name] is not None:
|
||||
sys.modules[name] = saved[name]
|
||||
else:
|
||||
del sys.modules[name]
|
||||
|
||||
return module
|
||||
|
||||
@@ -63,4 +65,4 @@ def patch_function(func, *additional_modules):
|
||||
else:
|
||||
del sys.modules[name]
|
||||
return patched
|
||||
|
||||
|
||||
|
@@ -15,5 +15,8 @@ patcher.inject('test.test_socket',
|
||||
('thread', thread),
|
||||
('threading', threading))
|
||||
|
||||
# TODO: fix
|
||||
TCPTimeoutTest.testInterruptedTimeout = lambda *a: None
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
test_main()
|
||||
|
Reference in New Issue
Block a user