Fix test_httplib.

This commit is contained in:
Martin v. Löwis 2007-06-30 09:22:09 +00:00
parent 486364b821
commit dd5a86070c
2 changed files with 10 additions and 9 deletions

View file

@ -711,8 +711,8 @@ class HTTPConnection:
Appends an extra \\r\\n to the buffer. Appends an extra \\r\\n to the buffer.
""" """
self._buffer.extend(("", "")) self._buffer.extend((b"", b""))
msg = "\r\n".join(self._buffer) msg = b"\r\n".join(self._buffer)
del self._buffer[:] del self._buffer[:]
self.send(msg) self.send(msg)
@ -758,9 +758,10 @@ class HTTPConnection:
self._method = method self._method = method
if not url: if not url:
url = '/' url = '/'
str = '%s %s %s' % (method, url, self._http_vsn_str) request = '%s %s %s' % (method, url, self._http_vsn_str)
self._output(str) # Non-ASCII characters should have been eliminated earlier
self._output(request.encode('ascii'))
if self._http_vsn == 11: if self._http_vsn == 11:
# Issue some standard headers for better HTTP/1.1 compliance # Issue some standard headers for better HTTP/1.1 compliance
@ -831,8 +832,8 @@ class HTTPConnection:
if self.__state != _CS_REQ_STARTED: if self.__state != _CS_REQ_STARTED:
raise CannotSendHeader() raise CannotSendHeader()
str = '%s: %s' % (header, value) header = '%s: %s' % (header, value)
self._output(str) self._output(header.encode('ascii'))
def endheaders(self): def endheaders(self):
"""Indicate that the last header line has been sent to the server.""" """Indicate that the last header line has been sent to the server."""
@ -846,7 +847,6 @@ class HTTPConnection:
def request(self, method, url, body=None, headers={}): def request(self, method, url, body=None, headers={}):
"""Send a complete request to the server.""" """Send a complete request to the server."""
try: try:
self._send_request(method, url, body, headers) self._send_request(method, url, body, headers)
except socket.error as v: except socket.error as v:
@ -888,6 +888,7 @@ class HTTPConnection:
self.endheaders() self.endheaders()
if body: if body:
if isinstance(body, str): body = body.encode('ascii')
self.send(body) self.send(body)
def getresponse(self): def getresponse(self):

View file

@ -11,7 +11,7 @@ class FakeSocket:
def __init__(self, text, fileclass=StringIO.StringIO): def __init__(self, text, fileclass=StringIO.StringIO):
self.text = text self.text = text
self.fileclass = fileclass self.fileclass = fileclass
self.data = '' self.data = b''
def sendall(self, data): def sendall(self, data):
self.data += data self.data += data
@ -54,7 +54,7 @@ class HeaderTests(TestCase):
kv = item.split(':') kv = item.split(':')
if len(kv) > 1: if len(kv) > 1:
# item is a 'Key: Value' header string # item is a 'Key: Value' header string
lcKey = kv[0].lower() lcKey = kv[0].decode('ascii').lower()
self.count.setdefault(lcKey, 0) self.count.setdefault(lcKey, 0)
self.count[lcKey] += 1 self.count[lcKey] += 1
list.append(self, item) list.append(self, item)