Skip to content

Commit f729d74

Browse files
committed
Use a helper for to_bytes() and None input
1 parent 9cd348d commit f729d74

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

scrapy/mail.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,20 @@
3030
logger = logging.getLogger(__name__)
3131

3232

33+
def _to_bytes_or_none(text):
34+
if text is None:
35+
return None
36+
return to_bytes(text)
37+
38+
3339
class MailSender(object):
3440

3541
def __init__(self, smtphost='localhost', mailfrom='scrapy@localhost',
3642
smtpuser=None, smtppass=None, smtpport=25, smtptls=False, smtpssl=False, debug=False):
3743
self.smtphost = smtphost
3844
self.smtpport = smtpport
39-
self.smtpuser = to_bytes(smtpuser) if smtpuser is not None else None
40-
self.smtppass = to_bytes(smtppass) if smtppass is not None else None
45+
self.smtpuser = _to_bytes_or_none(smtpuser)
46+
self.smtppass = _to_bytes_or_none(smtppass)
4147
self.smtptls = smtptls
4248
self.smtpssl = smtpssl
4349
self.mailfrom = mailfrom

0 commit comments

Comments
 (0)