-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathresponse.py
More file actions
60 lines (41 loc) · 1.84 KB
/
Copy pathresponse.py
File metadata and controls
60 lines (41 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from __future__ import annotations
from typing import Any
class Response:
def __init__(self, exception: Exception | None = None, backend: Any = None) -> None:
self.backend = backend
self.set_exception(exception)
self.from_addr: str | None = None
self.to_addrs: list[str] | None = None
self._finished: bool = False
def set_exception(self, exc: Exception | None) -> None:
self._exc = exc
def raise_if_needed(self) -> None:
if self._exc:
raise self._exc
@property
def error(self) -> Exception | None:
return self._exc
@property
def success(self) -> bool:
return self._finished
class SMTPResponse(Response):
def __init__(self, exception: Exception | None = None, backend: Any = None) -> None:
super(SMTPResponse, self).__init__(exception=exception, backend=backend)
self.responses: list[list] = []
self.esmtp_opts: list[str] | None = None
self.rcpt_options: list[str] | None = None
self.status_code: int | None = None
self.status_text: bytes | None = None
self.last_command: str | None = None
self.refused_recipients: dict[str, tuple[int, bytes]] = {}
def set_status(self, command: str, code: int, text: bytes, **kwargs: Any) -> None:
self.responses.append([command, code, text, kwargs])
self.status_code = code
self.status_text = text
self.last_command = command
@property
def success(self) -> bool:
return self._finished and self.status_code is not None and self.status_code == 250
def __repr__(self) -> str:
return "<emails.backend.SMTPResponse status_code=%s status_text=%s>" % (self.status_code.__repr__(),
self.status_text.__repr__())