diff options
author | Daniel Kahn Gillmor <dkg@fifthhorseman.net> | 2024-01-30 15:40:58 -0500 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2024-04-06 16:16:00 +0800 |
commit | 793fafd0a98d3d428e07802eacfa0b359f6c9063 (patch) | |
tree | 3a7d5521e4abe73c2b2d9666994232f827d8be93 /imap-dl | |
parent | 3f69d1912f91c6b1b51381de51f9a79f43f908ad (diff) | |
download | mailscripts-793fafd0a98d3d428e07802eacfa0b359f6c9063.tar.gz |
email-print-mime-structure, imap-dl: clean up types with mypy 1.9.0
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
Diffstat (limited to 'imap-dl')
-rwxr-xr-x | imap-dl | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -2,7 +2,7 @@ # PYTHON_ARGCOMPLETE_OK # -*- coding: utf-8 -*- -# Copyright (C) 2019-2020 Daniel Kahn Gillmor +# Copyright (C) 2019-2024 Daniel Kahn Gillmor # Copyright (C) 2020 Red Hat, Inc. # # This program is free software: you can redistribute it and/or modify @@ -52,14 +52,17 @@ import statistics import configparser from typing import Dict, List, Optional, Tuple, Union +from types import ModuleType +argcomplete:Optional[ModuleType] try: - import argcomplete #type: ignore + import argcomplete except ImportError: argcomplete = None +gssapi:Optional[ModuleType] try: - import gssapi # type: ignore + import gssapi except ModuleNotFoundError: gssapi = None @@ -96,15 +99,16 @@ def auth_builtin(username:str, imap:imaplib.IMAP4, except Exception as e: raise Exception(f'login failed with {e} as user {username} on {server}') -if gssapi: +if gssapi is not None: # imaplib auth methods need to be in the form of callables, and they all # requre both additional parameters and storage beyond what the function # interface provides. class GSSAPI_handler(): - gss_vc:gssapi.SecurityContext username:str def __init__(self, server:str, username:str) -> None: + if gssapi is None: + raise Exception("Impossible state -- gssapi module is not loaded") name = gssapi.Name(f'imap@{server}', gssapi.NameType.hostbased_service) self.gss_vc = gssapi.SecurityContext(usage="initiate", name=name) |