Commit 74e68c75 authored by Thomas Wouters's avatar Thomas Wouters

Fix test_smtplib by munging asynchat some more.

parent 828f04ac
...@@ -46,6 +46,7 @@ method) up to the terminator, and then control will be returned to ...@@ -46,6 +46,7 @@ method) up to the terminator, and then control will be returned to
you - by calling your self.found_terminator() method. you - by calling your self.found_terminator() method.
""" """
import sys
import socket import socket
import asyncore import asyncore
from collections import deque from collections import deque
...@@ -91,6 +92,8 @@ class async_chat (asyncore.dispatcher): ...@@ -91,6 +92,8 @@ class async_chat (asyncore.dispatcher):
self.handle_error() self.handle_error()
return return
if isinstance(data, str):
data = data.encode('ascii')
self.ac_in_buffer = self.ac_in_buffer + bytes(data) self.ac_in_buffer = self.ac_in_buffer + bytes(data)
# Continue to search for self.terminator in self.ac_in_buffer, # Continue to search for self.terminator in self.ac_in_buffer,
...@@ -126,6 +129,8 @@ class async_chat (asyncore.dispatcher): ...@@ -126,6 +129,8 @@ class async_chat (asyncore.dispatcher):
# 3) end of buffer does not match any prefix: # 3) end of buffer does not match any prefix:
# collect data # collect data
terminator_len = len(terminator) terminator_len = len(terminator)
if isinstance(terminator, str):
terminator = terminator.encode('ascii')
index = self.ac_in_buffer.find(terminator) index = self.ac_in_buffer.find(terminator)
if index != -1: if index != -1:
# we found the terminator # we found the terminator
...@@ -195,11 +200,15 @@ class async_chat (asyncore.dispatcher): ...@@ -195,11 +200,15 @@ class async_chat (asyncore.dispatcher):
self.close() self.close()
return return
elif isinstance(p, str) or isinstance(p, bytes): elif isinstance(p, str) or isinstance(p, bytes):
if isinstance(p, str):
p = p.encode('ascii')
self.producer_fifo.pop() self.producer_fifo.pop()
self.ac_out_buffer = self.ac_out_buffer + bytes(p) self.ac_out_buffer = self.ac_out_buffer + p
return return
data = p.more() data = p.more()
if data: if data:
if isinstance(data, str):
data = data.encode('ascii')
self.ac_out_buffer = self.ac_out_buffer + bytes(data) self.ac_out_buffer = self.ac_out_buffer + bytes(data)
return return
else: else:
......
...@@ -405,8 +405,8 @@ class SMTPSimTests(TestCase): ...@@ -405,8 +405,8 @@ class SMTPSimTests(TestCase):
self.assertEqual(smtp.vrfy(email), expected_known) self.assertEqual(smtp.vrfy(email), expected_known)
u = 'nobody@nowhere.com' u = 'nobody@nowhere.com'
expected_unknown = (550, bytes('No such user: %s' expected_unknown = (550, ('No such user: %s'
% smtplib.quoteaddr(u))) % smtplib.quoteaddr(u)).encode('ascii'))
self.assertEqual(smtp.vrfy(u), expected_unknown) self.assertEqual(smtp.vrfy(u), expected_unknown)
smtp.quit() smtp.quit()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment