[Python-3000-checkins] r56446 - in python/branches/py3k-struni/Lib: asyncore.py test/test_asyncore.py
guido.van.rossum
python-3000-checkins at python.org
Wed Jul 18 22:57:45 CEST 2007
Author: guido.van.rossum
Date: Wed Jul 18 22:57:44 2007
New Revision: 56446
Modified:
python/branches/py3k-struni/Lib/asyncore.py
python/branches/py3k-struni/Lib/test/test_asyncore.py
Log:
Fix test_asyncore after merge. It needs to use bytes.
Modified: python/branches/py3k-struni/Lib/asyncore.py
==============================================================================
--- python/branches/py3k-struni/Lib/asyncore.py (original)
+++ python/branches/py3k-struni/Lib/asyncore.py Wed Jul 18 22:57:44 2007
@@ -344,14 +344,14 @@
# a closed connection is indicated by signaling
# a read condition, and having recv() return 0.
self.handle_close()
- return ''
+ return b''
else:
return data
except socket.error as why:
# winsock sometimes throws ENOTCONN
if why[0] in [ECONNRESET, ENOTCONN, ESHUTDOWN]:
self.handle_close()
- return ''
+ return b''
else:
raise
@@ -447,7 +447,7 @@
def __init__(self, sock=None, map=None):
dispatcher.__init__(self, sock, map)
- self.out_buffer = ''
+ self.out_buffer = b''
def initiate_send(self):
num_sent = 0
@@ -461,6 +461,7 @@
return (not self.connected) or len(self.out_buffer)
def send(self, data):
+ assert isinstance(data, bytes)
if self.debug:
self.log_info('sending %s' % repr(data))
self.out_buffer = self.out_buffer + data
Modified: python/branches/py3k-struni/Lib/test/test_asyncore.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_asyncore.py (original)
+++ python/branches/py3k-struni/Lib/test/test_asyncore.py Wed Jul 18 22:57:44 2007
@@ -9,7 +9,7 @@
from test import test_support
from test.test_support import TESTFN, run_unittest, unlink
-from StringIO import StringIO
+from io import StringIO, BytesIO
HOST = "127.0.0.1"
PORT = 54329
@@ -66,9 +66,10 @@
n = 200
while n > 0:
data = conn.recv(10)
+ assert isinstance(data, bytes)
# keep everything except for the newline terminator
- buf.write(data.replace('\n', ''))
- if '\n' in data:
+ buf.write(data.replace(b'\n', b''))
+ if b'\n' in data:
break
n -= 1
time.sleep(0.01)
@@ -338,16 +339,16 @@
def test_send(self):
self.evt = threading.Event()
- cap = StringIO()
- threading.Thread(target=capture_server, args=(self.evt,cap)).start()
+ cap = BytesIO()
+ threading.Thread(target=capture_server, args=(self.evt, cap)).start()
time.sleep(1) # Give server time to initialize
- data = "Suppose there isn't a 16-ton weight?"*5
+ data = b"Suppose there isn't a 16-ton weight?"*5
d = dispatcherwithsend_noread()
d.create_socket(socket.AF_INET, socket.SOCK_STREAM)
d.connect((HOST, PORT))
d.send(data)
- d.send('\n')
+ d.send(b'\n')
n = 1000
while d.out_buffer and n > 0:
@@ -366,7 +367,7 @@
class FileWrapperTest(unittest.TestCase):
def setUp(self):
self.d = "It's not dead, it's sleeping!"
- file(TESTFN, 'w').write(self.d)
+ open(TESTFN, 'w').write(self.d)
def tearDown(self):
unlink(TESTFN)
@@ -377,8 +378,8 @@
self.assertEqual(w.fd, fd)
self.assertEqual(w.fileno(), fd)
- self.assertEqual(w.recv(13), "It's not dead")
- self.assertEqual(w.read(6), ", it's")
+ self.assertEqual(w.recv(13), b"It's not dead")
+ self.assertEqual(w.read(6), b", it's")
w.close()
self.assertRaises(OSError, w.read, 1)
@@ -391,7 +392,7 @@
w.write(d1)
w.send(d2)
w.close()
- self.assertEqual(file(TESTFN).read(), self.d + d1 + d2)
+ self.assertEqual(open(TESTFN).read(), self.d + d1 + d2)
def test_main():
More information about the Python-3000-checkins
mailing list