summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-11-21 22:09:45 (GMT)
committerGuido van Rossum <guido@python.org>2007-11-21 22:09:45 (GMT)
commit8a392d7387c9992537b0e1f66de989e34bd4eb4e (patch)
tree689dd92ee0ca56b2464982cb07b398af03f81f19 /Lib
parentb08340053cb10af7290628ed624e4f7ec6be398b (diff)
downloadcpython-8a392d7387c9992537b0e1f66de989e34bd4eb4e.zip
cpython-8a392d7387c9992537b0e1f66de989e34bd4eb4e.tar.gz
cpython-8a392d7387c9992537b0e1f66de989e34bd4eb4e.tar.bz2
Convert the socket module to insist on bytes for input, and to return bytes
(not bytearray) on output. Discovered a bunch of places that were still depending on it accepting text strings.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/SimpleXMLRPCServer.py3
-rwxr-xr-xLib/smtplib.py10
-rw-r--r--Lib/test/test_ftplib.py2
-rw-r--r--Lib/test/test_poplib.py2
-rw-r--r--Lib/test/test_smtplib.py2
-rw-r--r--Lib/test/test_socket.py2
-rw-r--r--Lib/test/test_urllib2_localnet.py9
7 files changed, 17 insertions, 13 deletions
diff --git a/Lib/SimpleXMLRPCServer.py b/Lib/SimpleXMLRPCServer.py
index 5f6e9d0..f74ca54 100644
--- a/Lib/SimpleXMLRPCServer.py
+++ b/Lib/SimpleXMLRPCServer.py
@@ -464,7 +464,8 @@ class SimpleXMLRPCRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
self.end_headers()
else:
- # got a valid XML RPC response
+ # Got a valid XML RPC response; convert to bytes first
+ response = response.encode("utf-8")
self.send_response(200)
self.send_header("Content-type", "text/xml")
self.send_header("Content-length", str(len(response)))
diff --git a/Lib/smtplib.py b/Lib/smtplib.py
index e10e327..0b4cbf0 100755
--- a/Lib/smtplib.py
+++ b/Lib/smtplib.py
@@ -295,12 +295,14 @@ class SMTP:
if self.debuglevel > 0: print("connect:", msg, file=stderr)
return (code, msg)
- def send(self, str):
- """Send `str' to the server."""
- if self.debuglevel > 0: print('send:', repr(str), file=stderr)
+ def send(self, s):
+ """Send `s' to the server."""
+ if self.debuglevel > 0: print('send:', repr(s), file=stderr)
if self.sock:
+ if isinstance(s, str):
+ s = s.encode("ascii")
try:
- self.sock.sendall(str)
+ self.sock.sendall(s)
except socket.error:
self.close()
raise SMTPServerDisconnected('Server not connected')
diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py
index 62aae05..d782c53 100644
--- a/Lib/test/test_ftplib.py
+++ b/Lib/test/test_ftplib.py
@@ -18,7 +18,7 @@ def server(evt, ready):
except socket.timeout:
pass
else:
- conn.send("1 Hola mundo\n")
+ conn.send(b"1 Hola mundo\n")
conn.close()
finally:
serv.close()
diff --git a/Lib/test/test_poplib.py b/Lib/test/test_poplib.py
index ef8565c..983cf21 100644
--- a/Lib/test/test_poplib.py
+++ b/Lib/test/test_poplib.py
@@ -19,7 +19,7 @@ def server(ready, evt):
except socket.timeout:
pass
else:
- conn.send("+ Hola mundo\n")
+ conn.send(b"+ Hola mundo\n")
conn.close()
finally:
serv.close()
diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py
index 00c3ad4..4151d6b 100644
--- a/Lib/test/test_smtplib.py
+++ b/Lib/test/test_smtplib.py
@@ -50,7 +50,7 @@ class GeneralTests(TestCase):
def setUp(self):
self.evt = threading.Event()
- servargs = (self.evt, "220 Hola mundo\n")
+ servargs = (self.evt, b"220 Hola mundo\n")
threading.Thread(target=server, args=servargs).start()
# wait until server thread has assigned a port number
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index c01d998..97445a0 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -498,7 +498,7 @@ class GeneralModuleTests(unittest.TestCase):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
sock.close()
- self.assertRaises(socket.error, sock.send, "spam")
+ self.assertRaises(socket.error, sock.send, b"spam")
def testNewAttributes(self):
# testing .family, .type and .protocol
diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py
index dde9504..f0b5dea 100644
--- a/Lib/test/test_urllib2_localnet.py
+++ b/Lib/test/test_urllib2_localnet.py
@@ -139,7 +139,7 @@ class DigestAuthHandler:
# not.
#request_handler.send_header('Connection', 'close')
request_handler.end_headers()
- request_handler.wfile.write("Proxy Authentication Required.")
+ request_handler.wfile.write(b"Proxy Authentication Required.")
return False
def handle_request(self, request_handler):
@@ -210,9 +210,10 @@ class FakeProxyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
self.send_response(200, "OK")
self.send_header("Content-Type", "text/html")
self.end_headers()
- self.wfile.write("You've reached %s!<BR>" % self.path)
- self.wfile.write("Our apologies, but our server is down due to "
- "a sudden zombie invasion.")
+ self.wfile.write(bytes("You've reached %s!<BR>" % self.path,
+ "ascii"))
+ self.wfile.write(b"Our apologies, but our server is down due to "
+ b"a sudden zombie invasion.")
# Test cases