Skip to content

Commit

Permalink
Add support for Python 3.10 (#5927) (#6081)
Browse files Browse the repository at this point in the history
Co-authored-by: Sviatoslav Sydorenko <webknjaz@redhat.com>
(cherry picked from commit 84babeb)

Co-authored-by: 秋葉 <ambiguous404@gmail.com>
  • Loading branch information
webknjaz and Hanaasagi authored Oct 16, 2021
1 parent cbb794c commit f8a11f5
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 21 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.6, 3.7, 3.8, 3.9]
pyver: [3.6, 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 @@ -913,9 +913,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 @@ -60,6 +60,7 @@
PY_36 = sys.version_info >= (3, 6)
PY_37 = sys.version_info >= (3, 7)
PY_38 = sys.version_info >= (3, 8)
PY_310 = sys.version_info >= (3, 10)

if not PY_37:
import idna_ssl # type: ignore[import]
Expand Down
6 changes: 4 additions & 2 deletions aiohttp/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,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
4 changes: 2 additions & 2 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,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 @@ -300,7 +300,7 @@ yarl==1.7.0
# 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.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ 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 tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def tls_certificate(tls_certificate_authority):

@pytest.fixture
def ssl_ctx(tls_certificate):
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 @@ -2340,7 +2340,7 @@ def create(url, srv):
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 @@ -84,7 +84,11 @@ async def go(app):


def create_mocked_conn(conn_closing_result=None, **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 @@ -1262,7 +1266,7 @@ async def test___get_ssl_context1(loop) -> None:


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


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


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


async def test___get_ssl_context5(loop) -> None:
ctx = ssl.SSLContext()
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
conn = aiohttp.TCPConnector(loop=loop, ssl=ctx)
req = mock.Mock()
req.is_ssl.return_value = True
Expand Down
4 changes: 2 additions & 2 deletions tests/test_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ 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) -> None:
assert asyncio.get_event_loop() is loop
assert asyncio.get_event_loop_policy().get_event_loop() is loop
18 changes: 16 additions & 2 deletions tests/test_proxy_functional.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import asyncio
import functools
import os
import pathlib
import platform
from re import match as match_regex
from unittest import mock
from uuid import uuid4
Expand All @@ -11,8 +13,18 @@

import aiohttp
from aiohttp import web
from aiohttp.client_exceptions import ClientConnectionError
from aiohttp.helpers import IS_MACOS, IS_WINDOWS, PY_37
from aiohttp.client_exceptions import ClientConnectionError, ClientProxyConnectionError
from aiohttp.helpers import IS_MACOS, IS_WINDOWS, PY_37, 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 +125,7 @@ def _pretend_asyncio_supports_tls_in_tls(
)


@secure_proxy_xfail_under_py310_except_macos(raises=ClientProxyConnectionError)
@pytest.mark.parametrize(
"web_server_endpoint_type",
(
Expand Down Expand Up @@ -152,6 +165,7 @@ async def test_secure_https_proxy_absolute_path(
await conn.close()


@secure_proxy_xfail_under_py310_except_macos(raises=AssertionError)
@pytest.mark.xfail(
not PY_37,
raises=RuntimeError,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,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 @@ -266,7 +266,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 @@ -281,7 +281,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 f8a11f5

Please sign in to comment.