diff options
author | Tim Burke <tim.burke@gmail.com> | 2021-10-08 03:18:04 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-08 13:18:04 +0300 |
commit | 15d3c2477510229e1b49c60fccfde5ffe94b2a76 (patch) | |
tree | 5b77b8bdc8518221e5bd043199b6d27ae3f72212 | |
parent | 690464aee772b62a54eedf5275843dce30318597 (diff) | |
download | eventlet-15d3c2477510229e1b49c60fccfde5ffe94b2a76.tar.gz |
Python 3.10 partial support
Everything below is specific to changes in Python 3.10.
https://github.com/eventlet/eventlet/pull/715
- Only wrap socket.timeout on Python < 3.10
socket.timeout is TimeoutError, which our is_timeout() helper func already knows.
fixes https://github.com/eventlet/eventlet/issues/687
- Working greenio._open
_pyio.open is now a staticmethod, so we've got to go down to
_pyio.open.__wrapped__ to get to the python function object.
- Test using eventlet.is_timeout rather than requiring an is_timeout attribute on errors.
TimeoutErrors (which are covered by is_timeout) can't necessarily have attributes added to them.
- Fix backdoor tests
Skip build info line at interpreter startup. Also, start printing the banner as we read it to aid in future debugging.
- Tolerate __builtins__ being a dict (rather than module) in is_timeout
(@tipabu) still not sure how this happens, but somehow it does in socket_test.test_error_is_timeout.
-rw-r--r-- | eventlet/greenio/base.py | 5 | ||||
-rw-r--r-- | eventlet/greenio/py3.py | 5 | ||||
-rw-r--r-- | eventlet/timeout.py | 9 | ||||
-rw-r--r-- | tests/__init__.py | 2 | ||||
-rw-r--r-- | tests/backdoor_test.py | 5 |
5 files changed, 20 insertions, 6 deletions
diff --git a/eventlet/greenio/base.py b/eventlet/greenio/base.py index 2eed869..51a7ae1 100644 --- a/eventlet/greenio/base.py +++ b/eventlet/greenio/base.py @@ -29,7 +29,10 @@ if six.PY2: _original_socket = eventlet.patcher.original('socket').socket -socket_timeout = eventlet.timeout.wrap_is_timeout(socket.timeout) +if sys.version_info >= (3, 10): + socket_timeout = socket.timeout # Really, TimeoutError +else: + socket_timeout = eventlet.timeout.wrap_is_timeout(socket.timeout) def socket_connect(descriptor, address): diff --git a/eventlet/greenio/py3.py b/eventlet/greenio/py3.py index 7a75b52..bc3dc94 100644 --- a/eventlet/greenio/py3.py +++ b/eventlet/greenio/py3.py @@ -191,9 +191,12 @@ _open_environment.update(dict( FileIO=GreenFileIO, os=_original_os, )) +if hasattr(_original_pyio, 'text_encoding'): + _open_environment['text_encoding'] = _original_pyio.text_encoding +_pyio_open = getattr(_original_pyio.open, '__wrapped__', _original_pyio.open) _open = FunctionType( - six.get_function_code(_original_pyio.open), + six.get_function_code(_pyio_open), _open_environment, ) diff --git a/eventlet/timeout.py b/eventlet/timeout.py index 6e1e08f..4ab893e 100644 --- a/eventlet/timeout.py +++ b/eventlet/timeout.py @@ -174,6 +174,11 @@ def wrap_is_timeout(base): return fun +if isinstance(__builtins__, dict): # seen when running tests on py310, but HOW?? + _timeout_err = __builtins__.get('TimeoutError', Timeout) +else: + _timeout_err = getattr(__builtins__, 'TimeoutError', Timeout) + + def is_timeout(obj): - py3err = getattr(__builtins__, 'TimeoutError', Timeout) - return bool(getattr(obj, 'is_timeout', False)) or isinstance(obj, py3err) + return bool(getattr(obj, 'is_timeout', False)) or isinstance(obj, _timeout_err) diff --git a/tests/__init__.py b/tests/__init__.py index c0b64fd..1883667 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -383,7 +383,7 @@ def run_isolated(path, prefix='tests/isolated/', **kwargs): def check_is_timeout(obj): value_text = getattr(obj, 'is_timeout', '(missing)') - assert obj.is_timeout, 'type={0} str={1} .is_timeout={2}'.format(type(obj), str(obj), value_text) + assert eventlet.is_timeout(obj), 'type={0} str={1} .is_timeout={2}'.format(type(obj), str(obj), value_text) @contextlib.contextmanager diff --git a/tests/backdoor_test.py b/tests/backdoor_test.py index 03a5692..1e09f09 100644 --- a/tests/backdoor_test.py +++ b/tests/backdoor_test.py @@ -1,5 +1,6 @@ import os import os.path +import sys import eventlet @@ -22,7 +23,9 @@ class BackdoorTest(tests.LimitedTestCase): def _run_test_on_client_and_server(self, client, server_thread): f = client.makefile('rw') assert 'Python' in f.readline() - f.readline() # build info + if sys.version_info < (3, 10): + # Starting in py310, build info is included in version line + f.readline() # build info f.readline() # help info assert 'InteractiveConsole' in f.readline() self.assertEqual('>>> ', f.read(4)) |