mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 20:54:28 +08:00
email: improve bytes handling (#9032)
This commit is contained in:
@@ -9,7 +9,7 @@ _ParamType: TypeAlias = Union[str, tuple[str | None, str | None, str]] # noqa:
|
||||
_ParamsType: TypeAlias = Union[str, None, tuple[str, str | None, str]] # noqa: Y047
|
||||
|
||||
def message_from_string(s: str, _class: Callable[[], Message] = ..., *, policy: Policy = ...) -> Message: ...
|
||||
def message_from_bytes(s: bytes, _class: Callable[[], Message] = ..., *, policy: Policy = ...) -> Message: ...
|
||||
def message_from_bytes(s: bytes | bytearray, _class: Callable[[], Message] = ..., *, policy: Policy = ...) -> Message: ...
|
||||
def message_from_file(fp: IO[str], _class: Callable[[], Message] = ..., *, policy: Policy = ...) -> Message: ...
|
||||
def message_from_binary_file(fp: IO[bytes], _class: Callable[[], Message] = ..., *, policy: Policy = ...) -> Message: ...
|
||||
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
__all__ = ["body_decode", "body_encode", "decode", "decodestring", "header_encode", "header_length"]
|
||||
|
||||
def header_length(bytearray: str | bytes) -> int: ...
|
||||
def header_encode(header_bytes: str | bytes, charset: str = ...) -> str: ...
|
||||
def body_encode(s: bytes, maxlinelen: int = ..., eol: str = ...) -> str: ...
|
||||
def decode(string: str | bytes) -> bytes: ...
|
||||
from _typeshed import ReadableBuffer
|
||||
|
||||
def header_length(bytearray: str | bytes | bytearray) -> int: ...
|
||||
def header_encode(header_bytes: str | ReadableBuffer, charset: str = ...) -> str: ...
|
||||
|
||||
# First argument should be a buffer that supports slicing and len().
|
||||
def body_encode(s: bytes | bytearray, maxlinelen: int = ..., eol: str = ...) -> str: ...
|
||||
def decode(string: str | ReadableBuffer) -> bytes: ...
|
||||
|
||||
body_decode = decode
|
||||
decodestring = decode
|
||||
|
||||
@@ -20,5 +20,5 @@ class BytesFeedParser(Generic[_MessageT]):
|
||||
def __init__(self: BytesFeedParser[Message], _factory: None = ..., *, policy: Policy = ...) -> None: ...
|
||||
@overload
|
||||
def __init__(self, _factory: Callable[[], _MessageT], *, policy: Policy = ...) -> None: ...
|
||||
def feed(self, data: bytes) -> None: ...
|
||||
def feed(self, data: bytes | bytearray) -> None: ...
|
||||
def close(self) -> _MessageT: ...
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from collections.abc import Iterable
|
||||
from email.charset import Charset
|
||||
from typing import Any
|
||||
|
||||
@@ -6,14 +7,14 @@ __all__ = ["Header", "decode_header", "make_header"]
|
||||
class Header:
|
||||
def __init__(
|
||||
self,
|
||||
s: bytes | str | None = ...,
|
||||
s: bytes | bytearray | str | None = ...,
|
||||
charset: Charset | str | None = ...,
|
||||
maxlinelen: int | None = ...,
|
||||
header_name: str | None = ...,
|
||||
continuation_ws: str = ...,
|
||||
errors: str = ...,
|
||||
) -> None: ...
|
||||
def append(self, s: bytes | str, charset: Charset | str | None = ..., errors: str = ...) -> None: ...
|
||||
def append(self, s: bytes | bytearray | str, charset: Charset | str | None = ..., errors: str = ...) -> None: ...
|
||||
def encode(self, splitchars: str = ..., maxlinelen: int | None = ..., linesep: str = ...) -> str: ...
|
||||
def __eq__(self, other: object) -> bool: ...
|
||||
def __ne__(self, __other: object) -> bool: ...
|
||||
@@ -23,7 +24,7 @@ class Header:
|
||||
# contains at least one encoded part.
|
||||
def decode_header(header: Header | str) -> list[tuple[Any, Any | None]]: ...
|
||||
def make_header(
|
||||
decoded_seq: list[tuple[bytes, str | None]],
|
||||
decoded_seq: Iterable[tuple[bytes | bytearray | str, str | None]],
|
||||
maxlinelen: int | None = ...,
|
||||
header_name: str | None = ...,
|
||||
continuation_ws: str = ...,
|
||||
|
||||
@@ -12,7 +12,7 @@ __all__ = ["Message", "EmailMessage"]
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
_PayloadType: TypeAlias = list[Message] | str | bytes
|
||||
_PayloadType: TypeAlias = list[Message] | str | bytes | bytearray
|
||||
_CharsetType: TypeAlias = Charset | str | None
|
||||
_HeaderType: TypeAlias = Any
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ __all__ = ["MIMEApplication"]
|
||||
class MIMEApplication(MIMENonMultipart):
|
||||
def __init__(
|
||||
self,
|
||||
_data: str | bytes,
|
||||
_data: str | bytes | bytearray,
|
||||
_subtype: str = ...,
|
||||
_encoder: Callable[[MIMEApplication], object] = ...,
|
||||
*,
|
||||
|
||||
@@ -8,7 +8,7 @@ __all__ = ["MIMEAudio"]
|
||||
class MIMEAudio(MIMENonMultipart):
|
||||
def __init__(
|
||||
self,
|
||||
_audiodata: str | bytes,
|
||||
_audiodata: str | bytes | bytearray,
|
||||
_subtype: str | None = ...,
|
||||
_encoder: Callable[[MIMEAudio], object] = ...,
|
||||
*,
|
||||
|
||||
@@ -8,7 +8,7 @@ __all__ = ["MIMEImage"]
|
||||
class MIMEImage(MIMENonMultipart):
|
||||
def __init__(
|
||||
self,
|
||||
_imagedata: str | bytes,
|
||||
_imagedata: str | bytes | bytearray,
|
||||
_subtype: str | None = ...,
|
||||
_encoder: Callable[[MIMEImage], object] = ...,
|
||||
*,
|
||||
|
||||
@@ -16,6 +16,6 @@ class HeaderParser(Parser): ...
|
||||
class BytesParser:
|
||||
def __init__(self, _class: Callable[[], Message] = ..., *, policy: Policy = ...) -> None: ...
|
||||
def parse(self, fp: BinaryIO, headersonly: bool = ...) -> Message: ...
|
||||
def parsebytes(self, text: bytes, headersonly: bool = ...) -> Message: ...
|
||||
def parsebytes(self, text: bytes | bytearray, headersonly: bool = ...) -> Message: ...
|
||||
|
||||
class BytesHeaderParser(BytesParser): ...
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from collections.abc import Iterable
|
||||
|
||||
__all__ = [
|
||||
"body_decode",
|
||||
"body_encode",
|
||||
@@ -13,11 +15,11 @@ __all__ = [
|
||||
|
||||
def header_check(octet: int) -> bool: ...
|
||||
def body_check(octet: int) -> bool: ...
|
||||
def header_length(bytearray: bytes) -> int: ...
|
||||
def body_length(bytearray: bytes) -> int: ...
|
||||
def unquote(s: str | bytes) -> str: ...
|
||||
def quote(c: str | bytes) -> str: ...
|
||||
def header_encode(header_bytes: bytes, charset: str = ...) -> str: ...
|
||||
def header_length(bytearray: Iterable[int]) -> int: ...
|
||||
def body_length(bytearray: Iterable[int]) -> int: ...
|
||||
def unquote(s: str | bytes | bytearray) -> str: ...
|
||||
def quote(c: str | bytes | bytearray) -> str: ...
|
||||
def header_encode(header_bytes: bytes | bytearray, charset: str = ...) -> str: ...
|
||||
def body_encode(body: str, maxlinelen: int = ..., eol: str = ...) -> str: ...
|
||||
def decode(encoded: str, eol: str = ...) -> str: ...
|
||||
def header_decode(s: str) -> str: ...
|
||||
|
||||
Reference in New Issue
Block a user