Skip to content

Commit

Permalink
feat: Add support for Python 3.11 (#314)
Browse files Browse the repository at this point in the history
* ci: Enable 3.11 in CI

ci: remove old pythons to speed up

use b64 encoded = commands

fixes for startls

* no need for ssl context for client

* fix missing method on < 3.11
  • Loading branch information
maxking committed Nov 25, 2022
1 parent da4b11e commit 827f232
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit-testing-and-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
fail-fast: false
matrix:
os: [ "macos-10.15", "ubuntu-18.04", "ubuntu-20.04", "windows-latest" ]
python-version: [ "3.6", "3.7", "3.8", "3.9", "3.10", "pypy3.6" ]
python-version: [ "3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "pypy3.6" ]
runs-on: ${{ matrix.os }}
timeout-minutes: 15 # Slowest so far is pypy3 on MacOS, taking almost 7m
steps:
Expand Down
5 changes: 3 additions & 2 deletions aiosmtpd/smtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,11 +899,12 @@ async def smtp_STARTTLS(self, arg: str):
self.tls_context,
waiter,
server_side=True)

# Reconfigure transport layer. Keep a reference to the original
# transport so that we can close it explicitly when the connection is
# lost. XXX BaseTransport.set_protocol() was added in Python 3.5.3 :(
# lost.
self._original_transport = self.transport
self._original_transport._protocol = self._tls_protocol
self._original_transport.set_protocol(self._tls_protocol)
# Reconfigure the protocol layer. Why is the app transport a protected
# property, if it MUST be used externally?
self.transport = self._tls_protocol._app_transport
Expand Down
13 changes: 7 additions & 6 deletions aiosmtpd/tests/test_smtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
BCRLF = b"\r\n"
MAIL_LOG = logging.getLogger("mail.log")
MAIL_LOG.setLevel(logging.DEBUG)
B64EQUALS = b64encode(b"=").decode()

# fh = logging.FileHandler("~smtp.log")
# fh.setFormatter(logging.Formatter("{asctime} - {levelname} - {message}", style="{"))
Expand Down Expand Up @@ -985,7 +986,7 @@ def test_auth_loginteract_warning(self, client):
resp = client.docmd("AUTH WITH_UNDERSCORE")
assert resp == (334, b"challenge")
with warnings.catch_warnings(record=True) as w:
assert client.docmd("=") == S.S235_AUTH_SUCCESS
assert client.docmd(B64EQUALS) == S.S235_AUTH_SUCCESS
assert len(w) > 0
assert str(w[0].message) == "AUTH interaction logging is enabled!"
assert str(w[1].message) == "Sensitive information might be leaked!"
Expand Down Expand Up @@ -1099,7 +1100,7 @@ def test_plain1_bad_password(self, do_auth_plain1):
assert resp == S.S535_AUTH_INVALID

def test_plain1_empty(self, do_auth_plain1):
resp = do_auth_plain1("=")
resp = do_auth_plain1(B64EQUALS)
assert resp == S.S501_AUTH_CANTSPLIT

def test_plain1_good_credentials(
Expand Down Expand Up @@ -1161,7 +1162,7 @@ def test_plain2_bad_credentials(self, client_auth_plain2):
assert resp == S.S535_AUTH_INVALID

def test_plain2_no_credentials(self, client_auth_plain2):
resp = client_auth_plain2.docmd("=")
resp = client_auth_plain2.docmd(B64EQUALS)
assert resp == S.S501_AUTH_CANTSPLIT

def test_plain2_abort(self, client_auth_plain2):
Expand Down Expand Up @@ -1230,17 +1231,17 @@ def test_login3_bad_password(self, do_auth_login3):
assert resp == S.S535_AUTH_INVALID

def test_login3_empty_credentials(self, do_auth_login3):
resp = do_auth_login3("=")
resp = do_auth_login3(B64EQUALS)
assert resp == S.S334_AUTH_PASSWORD
resp = do_auth_login3("=")
resp = do_auth_login3(B64EQUALS)
assert resp == S.S535_AUTH_INVALID

def test_login3_abort_username(self, do_auth_login3):
resp = do_auth_login3("*")
assert resp == S.S501_AUTH_ABORTED

def test_login3_abort_password(self, do_auth_login3):
resp = do_auth_login3("=")
resp = do_auth_login3(B64EQUALS)
assert resp == S.S334_AUTH_PASSWORD
resp = do_auth_login3("*")
assert resp == S.S501_AUTH_ABORTED
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ classifiers =
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: Implementation :: CPython
Programming Language :: Python :: Implementation :: PyPy
Topic :: Communications :: Email :: Mail Transport Agents
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ envdir =
py38: {toxworkdir}/3.8
py39: {toxworkdir}/3.9
py310: {toxworkdir}/3.10
py311: {toxworkdir}/3.11
pypy3: {toxworkdir}/pypy3
py: {toxworkdir}/py
commands =
Expand Down

0 comments on commit 827f232

Please sign in to comment.