smtplib improvements (#2419)

* Mark SMTP attibutes with class defaults with "= ..."
* Add SMTP.command_encoding
* Annotate SMTP.__exit__()
* Add SMTP.auth() et al.
* Add LMTP_PORT constant
This commit is contained in:
Sebastian Rittau
2018-08-28 05:22:19 +02:00
committed by Jelle Zijlstra
parent c3cf369c6f
commit bbe9b94b00

View File

@@ -1,9 +1,10 @@
from email.message import Message as _Message
from socket import socket
from ssl import SSLContext
from types import TracebackType
from typing import (
Any, AnyStr, Dict, Generic, List, Optional, Sequence, Tuple, Union,
Pattern)
Pattern, Type, Callable, Protocol, overload)
import sys
_Reply = Tuple[int, bytes]
@@ -47,24 +48,32 @@ class SMTPAuthenticationError(SMTPResponseException): ...
def quoteaddr(addrstring: str) -> str: ...
def quotedata(data: str) -> str: ...
class _AuthObject(Protocol):
@overload
def __call__(self, challenge: None = ...) -> Optional[str]: ...
@overload
def __call__(self, challenge: bytes) -> str: ...
class SMTP:
debuglevel: int
debuglevel: int = ...
# Type of file should match what socket.makefile() returns
file: Any
helo_resp: Optional[bytes]
ehlo_msg: str
ehlo_resp: Optional[bytes]
does_esmtp: int
default_port: int
file: Any = ...
helo_resp: Optional[bytes] = ...
ehlo_msg: str = ...
ehlo_resp: Optional[bytes] = ...
does_esmtp: int = ...
default_port: int = ...
timeout: float
esmtp_features: Dict[str, str]
command_encoding: str
source_address: Optional[_SourceAddress]
local_hostname: str
def __init__(self, host: str = ..., port: int = ...,
local_hostname: Optional[str] = ..., timeout: float = ...,
source_address: Optional[_SourceAddress] = ...) -> None: ...
def __enter__(self) -> SMTP: ...
def __exit__(self, *args) -> None: ...
def __exit__(self, exc_type: Optional[Type[Exception]], exc_value: Optional[Exception],
tb: Optional[TracebackType]) -> None: ...
def set_debuglevel(self, debuglevel: int) -> None: ...
sock: Optional[socket]
def connect(self, host: str = ..., port: int = ...,
@@ -87,6 +96,15 @@ class SMTP:
def expn(self, address: str) -> _Reply: ...
def ehlo_or_helo_if_needed(self) -> None: ...
if sys.version_info >= (3, 5):
user: str
password: str
def auth(self, mechanism: str, authobject: _AuthObject, *, initial_response_ok: bool = ...) -> _Reply: ...
@overload
def auth_cram_md5(self, challenge: None = ...) -> None: ...
@overload
def auth_cram_md5(self, challenge: bytes) -> str: ...
def auth_plain(self, challenge: Optional[bytes] = ...) -> str: ...
def auth_login(self, challenge: Optional[bytes] = ...) -> str: ...
def login(self, user: str, password: str, *,
initial_response_ok: bool = ...) -> _Reply: ...
else:
@@ -114,6 +132,8 @@ class SMTP_SSL(SMTP):
source_address: Optional[_SourceAddress] = ...,
context: Optional[SSLContext] = ...) -> None: ...
LMTP_PORT: int
class LMTP(SMTP):
def __init__(self, host: str = ..., port: int = ...,
local_hostname: Optional[str] = ...,