Skip to content

Commit baa35c2

Browse files
committed
Remove to_bytes calls from signers.py
All inputs are known str — use .encode() directly instead of the Python 2 compatibility wrapper. signers.py no longer imports anything from utils.
1 parent 1fcb40a commit baa35c2

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

emails/signers.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from .packages import dkim
1010
from .packages.dkim import DKIMException, UnparsableKeyError
1111
from .packages.dkim.crypto import parse_pem_private_key
12-
from .utils import to_bytes
1312

1413

1514
class DKIMSigner:
@@ -38,8 +37,8 @@ def __init__(self, selector: str, domain: str, key: str | bytes | IO[bytes] | No
3837
raise DKIMException(exc)
3938

4039
self._sign_params.update({'privkey': privkey_parsed,
41-
'domain': to_bytes(domain),
42-
'selector': to_bytes(selector)})
40+
'domain': domain.encode(),
41+
'selector': selector.encode()})
4342

4443
def get_sign_string(self, message: bytes) -> bytes | None:
4544
try:
@@ -76,9 +75,7 @@ def sign_message(self, msg: MIMEMultipart) -> MIMEMultipart:
7675
# but py3 smtplib requires str to send DATA command (#
7776
# so we have to convert msg.as_string
7877

79-
msg_bytes = to_bytes(msg.as_string())
80-
assert msg_bytes is not None
81-
dkim_header = self.get_sign_header(msg_bytes)
78+
dkim_header = self.get_sign_header(msg.as_string().encode())
8279
if dkim_header:
8380
msg._headers.insert(0, dkim_header) # type: ignore[attr-defined]
8481
return msg
@@ -92,9 +89,7 @@ def sign_message_string(self, message_string: str) -> str:
9289
# but py3 smtplib requires str to send DATA command
9390
# so we have to convert message_string
9491

95-
msg_bytes = to_bytes(message_string)
96-
assert msg_bytes is not None
97-
s = self.get_sign_string(msg_bytes)
92+
s = self.get_sign_string(message_string.encode())
9893
if s:
9994
return s.decode() + message_string
10095
return message_string

0 commit comments

Comments
 (0)