support old python - 3.9

This commit is contained in:
Balakrishnan Balasubramanian 2023-06-26 17:31:00 -04:00
parent 59abf24ce5
commit 5f56a1256b
5 changed files with 13 additions and 9 deletions

View File

@ -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

View File

@ -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]

View File

@ -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(

View File

@ -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":

View File

@ -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=}"