Skip to content

Commit 83438b0

Browse files
committed
Add type stubs for email module and backend components
1 parent 906bd5d commit 83438b0

25 files changed

Lines changed: 595 additions & 0 deletions

emails/__init__.pyi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import Any, Optional, Union, Tuple, List, Dict, Callable
2+
from .message import Message as Message, html as html
3+
from .utils import MessageID as MessageID
4+
5+
__title__: str
6+
__version__: str
7+
__author__: str
8+
__license__: str
9+
__copyright__: str
10+
USER_AGENT: str

emails/backend/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from .factory import ObjectFactory as ObjectFactory
2+
from .smtp import SMTPBackend as SMTPBackend

emails/backend/factory.pyi

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from typing import Any, Dict, Type, TypeVar
2+
3+
T = TypeVar('T')
4+
5+
def simple_dict2str(d: Dict[str, Any]) -> str: ...
6+
7+
class ObjectFactory:
8+
cls: Type[Any]
9+
pool: Dict[str, Any]
10+
def __init__(self, cls: Type[Any]) -> None: ...
11+
def __getitem__(self, k: Dict[str, Any]) -> Any: ...
12+
def invalidate(self, k: Dict[str, Any]) -> Any: ...

emails/backend/response.pyi

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from typing import Any, Optional, List, Dict, Tuple
2+
3+
class Response:
4+
backend: Any
5+
_exc: Optional[Exception]
6+
from_addr: Optional[str]
7+
to_addrs: Optional[List[str]]
8+
_finished: bool
9+
def __init__(self, exception: Optional[Exception] = ..., backend: Any = ...) -> None: ...
10+
def set_exception(self, exc: Exception) -> None: ...
11+
def raise_if_needed(self) -> None: ...
12+
@property
13+
def error(self) -> Optional[Exception]: ...
14+
@property
15+
def success(self) -> bool: ...
16+
17+
class SMTPResponse(Response):
18+
responses: List[Any]
19+
esmtp_opts: Optional[List[str]]
20+
rcpt_options: Optional[List[str]]
21+
status_code: Optional[int]
22+
status_text: Optional[str]
23+
last_command: Optional[str]
24+
refused_recipient: Dict[str, Any]
25+
refused_recipients: Dict[str, Any]
26+
def __init__(self, exception: Optional[Exception] = ..., backend: Any = ...) -> None: ...
27+
def set_status(self, command: str, code: int, text: str, **kwargs: Any) -> None: ...

emails/backend/smtp/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .backend import SMTPBackend as SMTPBackend

emails/backend/smtp/backend.pyi

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from typing import Any, Optional, Dict, List, Type, Callable
2+
from ..response import SMTPResponse
3+
from .client import SMTPClientWithResponse, SMTPClientWithResponse_SSL
4+
5+
class SMTPBackend:
6+
DEFAULT_SOCKET_TIMEOUT: int
7+
connection_cls: Type[SMTPClientWithResponse]
8+
connection_ssl_cls: Type[SMTPClientWithResponse_SSL]
9+
response_cls: Type[SMTPResponse]
10+
smtp_cls: Type[Any]
11+
ssl: bool
12+
tls: Optional[bool]
13+
smtp_cls_kwargs: Dict[str, Any]
14+
host: Optional[str]
15+
port: Optional[int]
16+
fail_silently: bool
17+
mail_options: List[str]
18+
_client: Optional[Any]
19+
20+
def __init__(self, ssl: bool = ..., fail_silently: bool = ..., mail_options: Optional[List[str]] = ..., **kwargs: Any) -> None: ...
21+
def get_client(self) -> Any: ...
22+
def close(self) -> None: ...
23+
def make_response(self, exception: Optional[Exception] = ...) -> SMTPResponse: ...
24+
def retry_on_disconnect(self, func: Callable[..., Any]) -> Callable[..., Any]: ...
25+
def _send(self, **kwargs: Any) -> Any: ...

emails/backend/smtp/client.pyi

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from typing import Any, Union, Sequence
2+
from smtplib import SMTP, SMTP_SSL
3+
4+
class SMTPClientWithResponse(SMTP):
5+
parent: Any
6+
make_response: Any
7+
tls: bool
8+
ssl: bool
9+
debug: int
10+
# user: str
11+
# password: str
12+
_initialized: bool
13+
initialized: bool
14+
def __init__(self, parent: Any, **kwargs: Any) -> None: ...
15+
def initialize(self) -> None: ...
16+
def quit(self) -> Any: ...
17+
def _rset(self) -> None: ...
18+
def sendmail(self, from_addr: str, to_addrs: Union[str, Sequence[str]], msg: Any, mail_options: Sequence[str] = ..., rcpt_options: Sequence[str] = ...) -> Any: ...
19+
20+
class SMTPClientWithResponse_SSL(SMTP_SSL):
21+
parent: Any
22+
make_response: Any
23+
tls: bool
24+
ssl: bool
25+
debug: int
26+
# user: str
27+
# password: str
28+
_initialized: bool
29+
initialized: bool
30+
def __init__(self, parent: Any, **kwargs: Any) -> None: ...
31+
def initialize(self) -> None: ...
32+
def quit(self) -> Any: ...
33+
def _rset(self) -> None: ...
34+
def sendmail(self, from_addr: str, to_addrs: Union[str, Sequence[str]], msg: Any, mail_options: Sequence[str] = ..., rcpt_options: Sequence[str] = ...) -> Any: ...

emails/django/__init__.pyi

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from typing import Any, Optional, List, Union, Dict
2+
from ..message import MessageTransformerMixin, MessageSignMixin, MessageBuildMixin, BaseMessage
3+
4+
class DjangoMessageMixin:
5+
_recipients: Optional[List[str]]
6+
_from_email: Optional[str]
7+
@property
8+
def encoding(self) -> str: ...
9+
def recipients(self) -> List[str]: ...
10+
@property
11+
def from_email(self) -> str: ...
12+
def _set_emails(self, mail_to: Optional[Union[str, List[str]]] = ..., set_mail_to: bool = ..., mail_from: Optional[str] = ..., set_mail_from: bool = ..., to: Optional[Union[str, List[str]]] = ...) -> None: ...
13+
def send(self, mail_to: Optional[Union[str, List[str]]] = ..., set_mail_to: bool = ..., mail_from: Optional[str] = ..., set_mail_from: bool = ..., context: Optional[Dict[str, Any]] = ..., connection: Optional[Any] = ..., to: Optional[Union[str, List[str]]] = ...) -> Any: ...
14+
15+
class DjangoMessage(DjangoMessageMixin, MessageTransformerMixin, MessageSignMixin, MessageBuildMixin, BaseMessage): ...
16+
17+
Message = DjangoMessage

emails/django_.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .django import *

emails/exc.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from .packages.dkim import DKIMException as DKIMException
2+
3+
class HTTPLoaderError(Exception): ...
4+
class BadHeaderError(ValueError): ...
5+
class IncompleteMessage(ValueError): ...

0 commit comments

Comments
 (0)