Skip to content

Commit 3a43132

Browse files
committed
Bugfix: Explicitly specify SMTP parameter for Pythone versions 3.5+ (fixes #21).
1 parent 908f070 commit 3a43132

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pytest_localserver/smtp.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
import asyncore
1111
import email
1212
import smtpd
13+
import sys
1314
import threading
1415

1516

17+
PY35_OR_NEWER = sys.version_info[:2] >= (3, 5)
18+
1619
class Server (smtpd.SMTPServer, threading.Thread):
1720

1821
"""
@@ -32,7 +35,12 @@ class Server (smtpd.SMTPServer, threading.Thread):
3235
WAIT_BETWEEN_CHECKS = 0.001
3336

3437
def __init__(self, host='localhost', port=0):
35-
smtpd.SMTPServer.__init__(self, (host, port), None)
38+
# Workaround for deprecated signature in Python 3.6
39+
if PY35_OR_NEWER:
40+
smtpd.SMTPServer.__init__(self, (host, port), None, decode_data=True)
41+
else:
42+
smtpd.SMTPServer.__init__(self, (host, port), None)
43+
3644
if self._localaddr[1] == 0:
3745
self.addr = self.socket.getsockname()
3846

0 commit comments

Comments
 (0)