summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBill Janssen <janssen@parc.com>2007-10-30 18:13:17 (GMT)
committerBill Janssen <janssen@parc.com>2007-10-30 18:13:17 (GMT)
commit1cd5bd2a2e600d0f29f9dcfbb9ea922cb1cd006f (patch)
treeafb72958d3818706cd3562ae5f7371f6a125ca8b /Lib
parent8cfe3a32763895b86eff1a7eb79f56774896645f (diff)
downloadcpython-1cd5bd2a2e600d0f29f9dcfbb9ea922cb1cd006f.zip
cpython-1cd5bd2a2e600d0f29f9dcfbb9ea922cb1cd006f.tar.gz
cpython-1cd5bd2a2e600d0f29f9dcfbb9ea922cb1cd006f.tar.bz2
make sure to write bytes instead of strings to underlying socket channel
Diffstat (limited to 'Lib')
-rw-r--r--Lib/BaseHTTPServer.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/Lib/BaseHTTPServer.py b/Lib/BaseHTTPServer.py
index 56e2169..f8a1138 100644
--- a/Lib/BaseHTTPServer.py
+++ b/Lib/BaseHTTPServer.py
@@ -356,11 +356,11 @@ class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler):
content = (self.error_message_format %
{'code': code, 'message': _quote_html(message), 'explain': explain})
self.send_response(code, message)
- self.send_header("Content-Type", "text/html")
+ self.send_header("Content-Type", "text/html;charset=utf-8")
self.send_header('Connection', 'close')
self.end_headers()
if self.command != 'HEAD' and code >= 200 and code not in (204, 304):
- self.wfile.write(content)
+ self.wfile.write(content.encode('UTF-8', 'replace'))
error_message_format = DEFAULT_ERROR_MESSAGE
@@ -378,8 +378,8 @@ class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler):
else:
message = ''
if self.request_version != 'HTTP/0.9':
- self.wfile.write("%s %d %s\r\n" %
- (self.protocol_version, code, message))
+ self.wfile.write(("%s %d %s\r\n" %
+ (self.protocol_version, code, message)).encode('ASCII', 'strict'))
# print (self.protocol_version, code, message)
self.send_header('Server', self.version_string())
self.send_header('Date', self.date_time_string())
@@ -387,7 +387,7 @@ class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler):
def send_header(self, keyword, value):
"""Send a MIME header."""
if self.request_version != 'HTTP/0.9':
- self.wfile.write("%s: %s\r\n" % (keyword, value))
+ self.wfile.write(("%s: %s\r\n" % (keyword, value)).encode('ASCII', 'strict'))
if keyword.lower() == 'connection':
if value.lower() == 'close':
@@ -398,7 +398,7 @@ class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler):
def end_headers(self):
"""Send the blank line ending the MIME headers."""
if self.request_version != 'HTTP/0.9':
- self.wfile.write("\r\n")
+ self.wfile.write(b"\r\n")
def log_request(self, code='-', size='-'):
"""Log an accepted request.