mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
SF patch# 1764815 by Paul Colomiets.
Fix for test_socketserver. Use io.BytesIO instead of io.StringIO, and adjust tests.
This commit is contained in:
parent
ad8d30092c
commit
15863ea07a
2 changed files with 6 additions and 6 deletions
|
@ -574,10 +574,10 @@ class DatagramRequestHandler(BaseRequestHandler):
|
||||||
"""Define self.rfile and self.wfile for datagram sockets."""
|
"""Define self.rfile and self.wfile for datagram sockets."""
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
from io import StringIO
|
from io import BytesIO
|
||||||
self.packet, self.socket = self.request
|
self.packet, self.socket = self.request
|
||||||
self.rfile = StringIO(self.packet)
|
self.rfile = BytesIO(self.packet)
|
||||||
self.wfile = StringIO()
|
self.wfile = BytesIO()
|
||||||
|
|
||||||
def finish(self):
|
def finish(self):
|
||||||
self.socket.sendto(self.wfile.getvalue(), self.client_address)
|
self.socket.sendto(self.wfile.getvalue(), self.client_address)
|
||||||
|
|
|
@ -38,7 +38,7 @@ class MyMixinServer:
|
||||||
self.server_close()
|
self.server_close()
|
||||||
raise
|
raise
|
||||||
|
|
||||||
teststring = "hello world\n"
|
teststring = b"hello world\n"
|
||||||
|
|
||||||
def receive(sock, n, timeout=20):
|
def receive(sock, n, timeout=20):
|
||||||
r, w, x = select.select([sock], [], [], timeout)
|
r, w, x = select.select([sock], [], [], timeout)
|
||||||
|
@ -51,7 +51,7 @@ def testdgram(proto, addr):
|
||||||
s = socket.socket(proto, socket.SOCK_DGRAM)
|
s = socket.socket(proto, socket.SOCK_DGRAM)
|
||||||
s.sendto(teststring, addr)
|
s.sendto(teststring, addr)
|
||||||
buf = data = receive(s, 100)
|
buf = data = receive(s, 100)
|
||||||
while data and '\n' not in buf:
|
while data and b'\n' not in buf:
|
||||||
data = receive(s, 100)
|
data = receive(s, 100)
|
||||||
buf += data
|
buf += data
|
||||||
verify(buf == teststring)
|
verify(buf == teststring)
|
||||||
|
@ -62,7 +62,7 @@ def teststream(proto, addr):
|
||||||
s.connect(addr)
|
s.connect(addr)
|
||||||
s.sendall(teststring)
|
s.sendall(teststring)
|
||||||
buf = data = receive(s, 100)
|
buf = data = receive(s, 100)
|
||||||
while data and '\n' not in buf:
|
while data and b'\n' not in buf:
|
||||||
data = receive(s, 100)
|
data = receive(s, 100)
|
||||||
buf += data
|
buf += data
|
||||||
verify(buf == teststring)
|
verify(buf == teststring)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue