Files
typeshed/stdlib/email/parser.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

40 lines
1.9 KiB
Python

from _typeshed import SupportsRead
from collections.abc import Callable
from email._policybase import _MessageT
from email.feedparser import BytesFeedParser as BytesFeedParser, FeedParser as FeedParser
from email.message import Message
from email.policy import Policy
from io import _WrappedBuffer
from typing import Generic, overload
__all__ = ["Parser", "HeaderParser", "BytesParser", "BytesHeaderParser", "FeedParser", "BytesFeedParser"]
class Parser(Generic[_MessageT]):
@overload
def __init__(self: Parser[Message[str, str]], _class: None = None) -> None: ...
@overload
def __init__(self, _class: None = None, *, policy: Policy[_MessageT]) -> None: ...
@overload
def __init__(self, _class: Callable[[], _MessageT] | None, *, policy: Policy[_MessageT] = ...) -> None: ...
def parse(self, fp: SupportsRead[str], headersonly: bool = False) -> _MessageT: ...
def parsestr(self, text: str, headersonly: bool = False) -> _MessageT: ...
class HeaderParser(Parser[_MessageT]):
def parse(self, fp: SupportsRead[str], headersonly: bool = True) -> _MessageT: ...
def parsestr(self, text: str, headersonly: bool = True) -> _MessageT: ...
class BytesParser(Generic[_MessageT]):
parser: Parser[_MessageT]
@overload
def __init__(self: BytesParser[Message[str, str]], _class: None = None) -> None: ...
@overload
def __init__(self, _class: None = None, *, policy: Policy[_MessageT]) -> None: ...
@overload
def __init__(self, _class: Callable[[], _MessageT], *, policy: Policy[_MessageT] = ...) -> None: ...
def parse(self, fp: _WrappedBuffer, headersonly: bool = False) -> _MessageT: ...
def parsebytes(self, text: bytes | bytearray, headersonly: bool = False) -> _MessageT: ...
class BytesHeaderParser(BytesParser[_MessageT]):
def parse(self, fp: _WrappedBuffer, headersonly: bool = True) -> _MessageT: ...
def parsebytes(self, text: bytes | bytearray, headersonly: bool = True) -> _MessageT: ...