Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 74e68c7

Browse files
committed
Fix test_smtplib by munging asynchat some more.
1 parent 828f04a commit 74e68c7

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

Lib/asynchat.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
you - by calling your self.found_terminator() method.
4747
"""
4848

49+
import sys
4950
import socket
5051
import asyncore
5152
from collections import deque
@@ -91,6 +92,8 @@ def handle_read (self):
9192
self.handle_error()
9293
return
9394

95+
if isinstance(data, str):
96+
data = data.encode('ascii')
9497
self.ac_in_buffer = self.ac_in_buffer + bytes(data)
9598

9699
# Continue to search for self.terminator in self.ac_in_buffer,
@@ -126,6 +129,8 @@ def handle_read (self):
126129
# 3) end of buffer does not match any prefix:
127130
# collect data
128131
terminator_len = len(terminator)
132+
if isinstance(terminator, str):
133+
terminator = terminator.encode('ascii')
129134
index = self.ac_in_buffer.find(terminator)
130135
if index != -1:
131136
# we found the terminator
@@ -195,11 +200,15 @@ def refill_buffer (self):
195200
self.close()
196201
return
197202
elif isinstance(p, str) or isinstance(p, bytes):
203+
if isinstance(p, str):
204+
p = p.encode('ascii')
198205
self.producer_fifo.pop()
199-
self.ac_out_buffer = self.ac_out_buffer + bytes(p)
206+
self.ac_out_buffer = self.ac_out_buffer + p
200207
return
201208
data = p.more()
202209
if data:
210+
if isinstance(data, str):
211+
data = data.encode('ascii')
203212
self.ac_out_buffer = self.ac_out_buffer + bytes(data)
204213
return
205214
else:

Lib/test/test_smtplib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,8 @@ def testVRFY(self):
405405
self.assertEqual(smtp.vrfy(email), expected_known)
406406

407407
408-
expected_unknown = (550, bytes('No such user: %s'
409-
% smtplib.quoteaddr(u)))
408+
expected_unknown = (550, ('No such user: %s'
409+
% smtplib.quoteaddr(u)).encode('ascii'))
410410
self.assertEqual(smtp.vrfy(u), expected_unknown)
411411
smtp.quit()
412412

0 commit comments

Comments
 (0)