Fix subtle py3 bug in t.m.pop3 detected by higher coverage.

Before this, protocol error messages would send literal "b'error message'" to
the clients.
This commit is contained in:
Evilham 2019-07-23 16:01:40 +02:00
parent 6985b744c8
commit 6eb978caa1
2 changed files with 4 additions and 5 deletions

View File

@ -575,8 +575,9 @@ class POP3(basic.LineOnlyReceiver, policies.TimeoutMixin):
return self.processCommand(*line.split(b' '))
except (ValueError, AttributeError, POP3Error, TypeError) as e:
log.err()
self.failResponse('bad protocol or server: {}: {}'.format(
e.__class__.__name__, e))
self.failResponse(b': '.join([b'bad protocol or server',
e.__class__.__name__.encode('utf-8'),
b''.join(e.args)]))
def processCommand(self, command, *args):

View File

@ -599,9 +599,7 @@ class AnotherPOP3Tests(unittest.TestCase):
Sending a command with invalid UTF-8 characters
will raise a L{pop3.POP3Error}.
"""
error = str(b'not authenticated yet: cannot do \x81PASS')
if not isinstance(error, bytes):
error = error.encode("utf-8")
error = b'not authenticated yet: cannot do \x81PASS'
d = self.runTest(
[b'\x81PASS',
b'QUIT'],