Files
typeshed/stdlib/email/policy.pyi
T
Sebastian Rittau 0eb44e574c Clean up and fix email message types (#13532)
* Unify the `_MessageT` type var in `email._policybase`.
* Use explicit type arguments for `Message` type in `_MessageT` type var.
  In particular, change bound from `Message[str, str]` to `Message[Any, Any]`.
* Change `__init__()` overloads of `Parser` and `BytesParser` to accept
  `Message` objects that are not `Message[str, str]` if `_class` is not also given.
2025-05-05 11:59:51 -04:00

76 lines
2.7 KiB
Python

from collections.abc import Callable
from email._policybase import Compat32 as Compat32, Policy as Policy, _MessageFactory, _MessageT, compat32 as compat32
from email.contentmanager import ContentManager
from email.message import EmailMessage
from typing import Any, overload
from typing_extensions import Self
__all__ = ["Compat32", "compat32", "Policy", "EmailPolicy", "default", "strict", "SMTP", "HTTP"]
class EmailPolicy(Policy[_MessageT]):
utf8: bool
refold_source: str
header_factory: Callable[[str, Any], Any]
content_manager: ContentManager
@overload
def __init__(
self: EmailPolicy[EmailMessage],
*,
max_line_length: int | None = ...,
linesep: str = ...,
cte_type: str = ...,
raise_on_defect: bool = ...,
mangle_from_: bool = ...,
message_factory: None = None,
# Added in Python 3.9.20, 3.10.15, 3.11.10, 3.12.5
verify_generated_headers: bool = ...,
utf8: bool = ...,
refold_source: str = ...,
header_factory: Callable[[str, str], str] = ...,
content_manager: ContentManager = ...,
) -> None: ...
@overload
def __init__(
self,
*,
max_line_length: int | None = ...,
linesep: str = ...,
cte_type: str = ...,
raise_on_defect: bool = ...,
mangle_from_: bool = ...,
message_factory: _MessageFactory[_MessageT] | None = ...,
# Added in Python 3.9.20, 3.10.15, 3.11.10, 3.12.5
verify_generated_headers: bool = ...,
utf8: bool = ...,
refold_source: str = ...,
header_factory: Callable[[str, str], str] = ...,
content_manager: ContentManager = ...,
) -> None: ...
def header_source_parse(self, sourcelines: list[str]) -> tuple[str, str]: ...
def header_store_parse(self, name: str, value: Any) -> tuple[str, Any]: ...
def header_fetch_parse(self, name: str, value: str) -> Any: ...
def fold(self, name: str, value: str) -> Any: ...
def fold_binary(self, name: str, value: str) -> bytes: ...
def clone(
self,
*,
max_line_length: int | None = ...,
linesep: str = ...,
cte_type: str = ...,
raise_on_defect: bool = ...,
mangle_from_: bool = ...,
message_factory: _MessageFactory[_MessageT] | None = ...,
# Added in Python 3.9.20, 3.10.15, 3.11.10, 3.12.5
verify_generated_headers: bool = ...,
utf8: bool = ...,
refold_source: str = ...,
header_factory: Callable[[str, str], str] = ...,
content_manager: ContentManager = ...,
) -> Self: ...
default: EmailPolicy[EmailMessage]
SMTP: EmailPolicy[EmailMessage]
SMTPUTF8: EmailPolicy[EmailMessage]
HTTP: EmailPolicy[EmailMessage]
strict: EmailPolicy[EmailMessage]