Skip to content

Commit

Permalink
Add support for Python 3.10 (aio-libs#5927)
Browse files Browse the repository at this point in the history
Co-authored-by: Sviatoslav Sydorenko <webknjaz@redhat.com>
  • Loading branch information
Hanaasagi and webknjaz authored Oct 8, 2021
1 parent f362679 commit 84babeb
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
needs: lint
strategy:
matrix:
pyver: [3.7, 3.8, 3.9]
pyver: [3.7, 3.8, 3.9, '3.10']
no-extensions: ['', 'Y']
os: [ubuntu, macos, windows]
exclude:
Expand Down
1 change: 1 addition & 0 deletions CHANGES/5927.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for Python 3.10 to Github Actions CI/CD workflows and fix the related deprecation warnings -- :user:`Hanaasagi`.
4 changes: 3 additions & 1 deletion aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,9 +876,11 @@ def _make_ssl_context(verified: bool) -> SSLContext:
if verified:
return ssl.create_default_context()
else:
sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
sslcontext = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
sslcontext.options |= ssl.OP_NO_SSLv2
sslcontext.options |= ssl.OP_NO_SSLv3
sslcontext.check_hostname = False
sslcontext.verify_mode = ssl.CERT_NONE
try:
sslcontext.options |= ssl.OP_NO_COMPRESSION
except AttributeError as attr_err:
Expand Down
1 change: 1 addition & 0 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
__all__ = ("BasicAuth", "ChainMapProxy", "ETag")

PY_38 = sys.version_info >= (3, 8)
PY_310 = sys.version_info >= (3, 10)

COOKIE_MAX_LENGTH = 4096

Expand Down
6 changes: 4 additions & 2 deletions aiohttp/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,10 @@ def get_app(self) -> Application:
raise RuntimeError("Did you forget to define get_application()?")

def setUp(self) -> None:
if PY_38:
self.loop = asyncio.get_event_loop()
try:
self.loop = asyncio.get_running_loop()
except RuntimeError:
self.loop = asyncio.get_event_loop_policy().get_event_loop()

self.loop.run_until_complete(self.setUpAsync())

Expand Down
6 changes: 3 additions & 3 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pyparsing==2.4.7
# via
# -r requirements/lint.txt
# packaging
pytest==6.2.2
pytest==6.2.5
# via
# -r requirements/lint.txt
# -r requirements/test.txt
Expand Down Expand Up @@ -230,7 +230,7 @@ requests==2.25.1
# sphinx
setuptools-git==1.2
# via -r requirements/test.txt
six==1.15.0
six==1.16.0
# via
# -r requirements/lint.txt
# cryptography
Expand Down Expand Up @@ -313,7 +313,7 @@ yarl==1.6.3
# via -r requirements/base.txt

# The following packages are considered to be unsafe in a requirements file:
setuptools==51.3.1
setuptools==57.4.0
# via
# blockdiag
# gunicorn
Expand Down
2 changes: 1 addition & 1 deletion requirements/lint.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ flake8-pyi==20.10.0
isort==5.9.3
mypy==0.910; implementation_name=="cpython"
pre-commit==2.15.0
pytest==6.2.2
pytest==6.2.5
types-chardet==0.1.3
4 changes: 2 additions & 2 deletions requirements/lint.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ pyflakes==2.3.0
# flake8-pyi
pyparsing==2.4.7
# via packaging
pytest==6.2.2
pytest==6.2.5
# via -r requirements/lint.in
pyyaml==5.4.1
# via pre-commit
regex==2020.11.13
# via black
six==1.15.0
six==1.16.0
# via virtualenv
toml==0.10.2
# via
Expand Down
2 changes: 1 addition & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ freezegun==1.1.0
mypy==0.910; implementation_name=="cpython"
mypy-extensions==0.4.3; implementation_name=="cpython"
proxy.py==2.3.1
pytest==6.2.2
pytest==6.2.5
pytest-cov==3.0.0
pytest-mock==3.6.1
re-assert==1.1.0
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def tls_certificate(tls_certificate_authority: Any) -> Any:

@pytest.fixture
def ssl_ctx(tls_certificate: Any) -> ssl.SSLContext:
ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
tls_certificate.configure_cert(ssl_ctx)
return ssl_ctx

Expand Down
2 changes: 1 addition & 1 deletion tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -2348,7 +2348,7 @@ def create(url: URL, srv: Any):
cert = tls_certificate_authority.issue_cert(
url.host, "localhost", "127.0.0.1"
)
ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
cert.configure_cert(ssl_ctx)
kwargs["ssl"] = ssl_ctx
return aiohttp_server(app, **kwargs)
Expand Down
14 changes: 9 additions & 5 deletions tests/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ async def go(app):

def create_mocked_conn(conn_closing_result: Optional[Any] = None, **kwargs: Any):
assert "loop" not in kwargs
loop = asyncio.get_event_loop()
try:
loop = asyncio.get_running_loop()
except RuntimeError:
loop = asyncio.get_event_loop_policy().get_event_loop()

proto = mock.Mock(**kwargs)
proto.closed = loop.create_future()
proto.closed.set_result(conn_closing_result)
Expand Down Expand Up @@ -1267,7 +1271,7 @@ async def test___get_ssl_context1(loop: Any) -> None:


async def test___get_ssl_context2(loop: Any) -> None:
ctx = ssl.SSLContext()
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
conn = aiohttp.TCPConnector()
req = mock.Mock()
req.is_ssl.return_value = True
Expand All @@ -1276,7 +1280,7 @@ async def test___get_ssl_context2(loop: Any) -> None:


async def test___get_ssl_context3(loop: Any) -> None:
ctx = ssl.SSLContext()
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
conn = aiohttp.TCPConnector(ssl=ctx)
req = mock.Mock()
req.is_ssl.return_value = True
Expand All @@ -1285,7 +1289,7 @@ async def test___get_ssl_context3(loop: Any) -> None:


async def test___get_ssl_context4(loop: Any) -> None:
ctx = ssl.SSLContext()
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
conn = aiohttp.TCPConnector(ssl=ctx)
req = mock.Mock()
req.is_ssl.return_value = True
Expand All @@ -1294,7 +1298,7 @@ async def test___get_ssl_context4(loop: Any) -> None:


async def test___get_ssl_context5(loop: Any) -> None:
ctx = ssl.SSLContext()
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
conn = aiohttp.TCPConnector(ssl=ctx)
req = mock.Mock()
req.is_ssl.return_value = True
Expand Down
6 changes: 3 additions & 3 deletions tests/test_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ async def test_on_startup_hook(self) -> None:
self.assertTrue(self.on_startup_called)

def test_default_loop(self) -> None:
self.assertIs(self.loop, asyncio.get_event_loop())
self.assertIs(self.loop, asyncio.get_event_loop_policy().get_event_loop())


def test_default_loop(loop: Any) -> None:
assert asyncio.get_event_loop() is loop
assert asyncio.get_event_loop_policy().get_event_loop() is loop


@pytest.mark.xfail(not PY_38, reason="ThreadedChildWatcher is only available in 3.8+")
Expand All @@ -53,7 +53,7 @@ def test_setup_loop_non_main_thread() -> None:
def target() -> None:
try:
with loop_context() as loop:
assert asyncio.get_event_loop() is loop
assert asyncio.get_event_loop_policy().get_event_loop() is loop
loop.run_until_complete(test_subprocess_co(loop))
except Exception as exc:
nonlocal child_exc
Expand Down
17 changes: 16 additions & 1 deletion tests/test_proxy_functional.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# type: ignore
import asyncio
import functools
import os
import pathlib
import platform
from re import match as match_regex
from typing import Any
from unittest import mock
Expand All @@ -13,7 +15,18 @@

import aiohttp
from aiohttp import web
from aiohttp.client_exceptions import ClientConnectionError
from aiohttp.client_exceptions import ClientConnectionError, ClientProxyConnectionError
from aiohttp.helpers import PY_310

secure_proxy_xfail_under_py310_except_macos = functools.partial(
pytest.mark.xfail,
PY_310 and platform.system() != "Darwin",
reason=(
"The secure proxy fixture does not seem to work "
"under Python 3.10 on Linux or Windows. "
"See https://github.com/abhinavsingh/proxy.py/issues/622."
),
)

ASYNCIO_SUPPORTS_TLS_IN_TLS = hasattr(
asyncio.sslproto._SSLProtocolTransport,
Expand Down Expand Up @@ -113,6 +126,7 @@ def _pretend_asyncio_supports_tls_in_tls(
)


@secure_proxy_xfail_under_py310_except_macos(raises=ClientProxyConnectionError)
@pytest.mark.parametrize("web_server_endpoint_type", ("http", "https"))
@pytest.mark.usefixtures("_pretend_asyncio_supports_tls_in_tls", "loop")
async def test_secure_https_proxy_absolute_path(
Expand All @@ -139,6 +153,7 @@ async def test_secure_https_proxy_absolute_path(
await conn.close()


@secure_proxy_xfail_under_py310_except_macos(raises=AssertionError)
@pytest.mark.parametrize("web_server_endpoint_type", ("https",))
@pytest.mark.usefixtures("loop")
async def test_https_proxy_unsupported_tls_in_tls(
Expand Down
6 changes: 3 additions & 3 deletions tests/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def test__create_ssl_context_without_certs_and_ciphers(
worker,
tls_certificate_pem_path,
) -> None:
worker.cfg.ssl_version = ssl.PROTOCOL_SSLv23
worker.cfg.ssl_version = ssl.PROTOCOL_TLS_CLIENT
worker.cfg.cert_reqs = ssl.CERT_OPTIONAL
worker.cfg.certfile = tls_certificate_pem_path
worker.cfg.keyfile = tls_certificate_pem_path
Expand All @@ -264,7 +264,7 @@ def test__create_ssl_context_with_ciphers(
worker,
tls_certificate_pem_path,
) -> None:
worker.cfg.ssl_version = ssl.PROTOCOL_SSLv23
worker.cfg.ssl_version = ssl.PROTOCOL_TLS_CLIENT
worker.cfg.cert_reqs = ssl.CERT_OPTIONAL
worker.cfg.certfile = tls_certificate_pem_path
worker.cfg.keyfile = tls_certificate_pem_path
Expand All @@ -279,7 +279,7 @@ def test__create_ssl_context_with_ca_certs(
tls_ca_certificate_pem_path,
tls_certificate_pem_path,
) -> None:
worker.cfg.ssl_version = ssl.PROTOCOL_SSLv23
worker.cfg.ssl_version = ssl.PROTOCOL_TLS_CLIENT
worker.cfg.cert_reqs = ssl.CERT_OPTIONAL
worker.cfg.certfile = tls_certificate_pem_path
worker.cfg.keyfile = tls_certificate_pem_path
Expand Down

0 comments on commit 84babeb

Please sign in to comment.