[Python-3000-checkins] r56128 - in python/branches/py3k-struni/Lib: httplib.py test/test_httplib.py

martin.v.loewis python-3000-checkins at python.org
Sat Jun 30 11:22:09 CEST 2007


Author: martin.v.loewis
Date: Sat Jun 30 11:22:09 2007
New Revision: 56128

Modified:
   python/branches/py3k-struni/Lib/httplib.py
   python/branches/py3k-struni/Lib/test/test_httplib.py
Log:
Fix test_httplib.


Modified: python/branches/py3k-struni/Lib/httplib.py
==============================================================================
--- python/branches/py3k-struni/Lib/httplib.py	(original)
+++ python/branches/py3k-struni/Lib/httplib.py	Sat Jun 30 11:22:09 2007
@@ -711,8 +711,8 @@
 
         Appends an extra \\r\\n to the buffer.
         """
-        self._buffer.extend(("", ""))
-        msg = "\r\n".join(self._buffer)
+        self._buffer.extend((b"", b""))
+        msg = b"\r\n".join(self._buffer)
         del self._buffer[:]
         self.send(msg)
 
@@ -758,9 +758,10 @@
         self._method = method
         if not 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:
             # Issue some standard headers for better HTTP/1.1 compliance
@@ -831,8 +832,8 @@
         if self.__state != _CS_REQ_STARTED:
             raise CannotSendHeader()
 
-        str = '%s: %s' % (header, value)
-        self._output(str)
+        header = '%s: %s' % (header, value)
+        self._output(header.encode('ascii'))
 
     def endheaders(self):
         """Indicate that the last header line has been sent to the server."""
@@ -846,7 +847,6 @@
 
     def request(self, method, url, body=None, headers={}):
         """Send a complete request to the server."""
-
         try:
             self._send_request(method, url, body, headers)
         except socket.error as v:
@@ -888,6 +888,7 @@
         self.endheaders()
 
         if body:
+            if isinstance(body, str): body = body.encode('ascii')
             self.send(body)
 
     def getresponse(self):

Modified: python/branches/py3k-struni/Lib/test/test_httplib.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_httplib.py	(original)
+++ python/branches/py3k-struni/Lib/test/test_httplib.py	Sat Jun 30 11:22:09 2007
@@ -11,7 +11,7 @@
     def __init__(self, text, fileclass=StringIO.StringIO):
         self.text = text
         self.fileclass = fileclass
-        self.data = ''
+        self.data = b''
 
     def sendall(self, data):
         self.data += data
@@ -54,7 +54,7 @@
                 kv = item.split(':')
                 if len(kv) > 1:
                     # item is a 'Key: Value' header string
-                    lcKey = kv[0].lower()
+                    lcKey = kv[0].decode('ascii').lower()
                     self.count.setdefault(lcKey, 0)
                     self.count[lcKey] += 1
                 list.append(self, item)


More information about the Python-3000-checkins mailing list