From 5f56a1256bec5ce2f5931873c9e5b4aa55d48d65 Mon Sep 17 00:00:00 2001 From: Balakrishnan Balasubramanian Date: Mon, 26 Jun 2023 17:31:00 -0400 Subject: [PATCH] support old python - 3.9 --- Makefile | 1 + mail4one/config.py | 8 ++++---- mail4one/pop3.py | 4 +++- mail4one/server.py | 5 +++-- mail4one/smtp.py | 4 ++-- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 5867514..d1d8772 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ docker-tests: docker run --pull=always -v `pwd`:/app -w /app --rm -it python:3.10-alpine sh runtests.sh docker run --pull=always -v `pwd`:/app -w /app --rm -it python:3.11 sh runtests.sh docker run --pull=always -v `pwd`:/app -w /app --rm -it python:3.10 sh runtests.sh + docker run --pull=always -v `pwd`:/app -w /app --rm -it python:3.9 sh runtests.sh requirements.txt: Pipfile.lock pipenv requirements > requirements.txt diff --git a/mail4one/config.py b/mail4one/config.py index 918bd85..1f97319 100644 --- a/mail4one/config.py +++ b/mail4one/config.py @@ -1,7 +1,7 @@ import json import re import logging -from typing import Callable +from typing import Callable, Union, Optional from jata import Jata, MutableDefault @@ -45,7 +45,7 @@ class ServerCfg(Jata): host: str = "default" port: int # disabled: bool = False - tls: TLSCfg | str = "default" + tls: Union[TLSCfg, str] = "default" class PopCfg(ServerCfg): @@ -72,9 +72,9 @@ class LogCfg(Jata): class Config(Jata): - default_tls: TLSCfg | None + default_tls: Optional[TLSCfg] = None default_host: str = "0.0.0.0" - logging: LogCfg | None = None + logging: Optional[LogCfg] = None mails_path: str matches: list[Match] diff --git a/mail4one/pop3.py b/mail4one/pop3.py index 8d21b21..5b993ae 100644 --- a/mail4one/pop3.py +++ b/mail4one/pop3.py @@ -13,6 +13,8 @@ from .pwhash import parse_hash, check_pass, PWInfo from asyncio import StreamReader, StreamWriter import random +from typing import Optional + from .poputils import ( InvalidCommand, parse_command, @@ -361,7 +363,7 @@ async def create_pop_server( port: int, mails_path: Path, users: list[User], - ssl_context: ssl.SSLContext | None = None, + ssl_context: Optional[ssl.SSLContext] = None, timeout_seconds: int = 60, ) -> asyncio.Server: logging.info( diff --git a/mail4one/server.py b/mail4one/server.py index 72704ba..05e26c9 100644 --- a/mail4one/server.py +++ b/mail4one/server.py @@ -13,6 +13,7 @@ from .version import VERSION from . import config from . import pwhash +from typing import Optional, Union def create_tls_context(certfile, keyfile) -> ssl.SSLContext: @@ -34,13 +35,13 @@ def setup_logging(cfg: config.LogCfg): async def a_main(cfg: config.Config) -> None: - default_tls_context: ssl.SSLContext | None = None + default_tls_context: Optional[ssl.SSLContext] = None if tls := cfg.default_tls: logging.info(f"Initializing default tls {tls.certfile=}, {tls.keyfile=}") default_tls_context = create_tls_context(tls.certfile, tls.keyfile) - def get_tls_context(tls: config.TLSCfg | str): + def get_tls_context(tls: Union[config.TLSCfg, str]): if tls == "default": return default_tls_context elif tls == "disable": diff --git a/mail4one/smtp.py b/mail4one/smtp.py index 25ba5d6..fad36ce 100644 --- a/mail4one/smtp.py +++ b/mail4one/smtp.py @@ -7,7 +7,7 @@ import uuid import shutil from functools import partial from pathlib import Path -from typing import Callable +from typing import Callable, Optional from . import config from email.message import Message import email.policy @@ -115,7 +115,7 @@ async def create_smtp_server( port: int, mails_path: Path, mbox_finder: Callable[[str], list[str]], - ssl_context: ssl.SSLContext | None = None, + ssl_context: Optional[ssl.SSLContext] = None, ) -> asyncio.Server: logging.info( f"Starting SMTP server {host=}, {port=}, {mails_path=!s}, {ssl_context != None=}"