]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix test_smtplib by munging asynchat some more.
authorThomas Wouters <thomas@python.org>
Fri, 31 Aug 2007 00:20:14 +0000 (00:20 +0000)
committerThomas Wouters <thomas@python.org>
Fri, 31 Aug 2007 00:20:14 +0000 (00:20 +0000)
Lib/asynchat.py
Lib/test/test_smtplib.py

index 94436561618d426b68d5126328ba8a9522690ecb..0e2457f8ece6192367c7c944aba069365cbabedc 100644 (file)
@@ -46,6 +46,7 @@ method) up to the terminator, and then control will be returned to
 you - by calling your self.found_terminator() method.
 """
 
+import sys
 import socket
 import asyncore
 from collections import deque
@@ -91,6 +92,8 @@ class async_chat (asyncore.dispatcher):
             self.handle_error()
             return
 
+        if isinstance(data, str):
+            data = data.encode('ascii')
         self.ac_in_buffer = self.ac_in_buffer + bytes(data)
 
         # Continue to search for self.terminator in self.ac_in_buffer,
@@ -126,6 +129,8 @@ class async_chat (asyncore.dispatcher):
                 # 3) end of buffer does not match any prefix:
                 #    collect data
                 terminator_len = len(terminator)
+                if isinstance(terminator, str):
+                    terminator = terminator.encode('ascii')
                 index = self.ac_in_buffer.find(terminator)
                 if index != -1:
                     # we found the terminator
@@ -195,11 +200,15 @@ class async_chat (asyncore.dispatcher):
                         self.close()
                     return
                 elif isinstance(p, str) or isinstance(p, bytes):
+                    if isinstance(p, str):
+                        p = p.encode('ascii')
                     self.producer_fifo.pop()
-                    self.ac_out_buffer = self.ac_out_buffer + bytes(p)
+                    self.ac_out_buffer = self.ac_out_buffer + p
                     return
                 data = p.more()
                 if data:
+                    if isinstance(data, str):
+                        data = data.encode('ascii')
                     self.ac_out_buffer = self.ac_out_buffer + bytes(data)
                     return
                 else:
index e0dcc86cada9f5bd78cf22dcf5cd74c5b623f8b8..00c3ad412a553ae601b093511ff9fcbf89b1109f 100644 (file)
@@ -405,8 +405,8 @@ class SMTPSimTests(TestCase):
             self.assertEqual(smtp.vrfy(email), expected_known)
 
         u = 'nobody@nowhere.com'
-        expected_unknown = (550, bytes('No such user: %s'
-                                       % smtplib.quoteaddr(u)))
+        expected_unknown = (550, ('No such user: %s'
+                                       % smtplib.quoteaddr(u)).encode('ascii'))
         self.assertEqual(smtp.vrfy(u), expected_unknown)
         smtp.quit()