[Python-checkins] r84932 - in python/branches/release27-maint/Lib: httplib.py test/test_httplib.py test/test_urllib2net.py

senthil.kumaran python-checkins at python.org
Tue Sep 21 03:38:16 CEST 2010


Author: senthil.kumaran
Date: Tue Sep 21 03:38:15 2010
New Revision: 84932

Log:
Fix Issue1327971: HTTPResponse should expose a proper fileno attribute



Modified:
   python/branches/release27-maint/Lib/httplib.py
   python/branches/release27-maint/Lib/test/test_httplib.py
   python/branches/release27-maint/Lib/test/test_urllib2net.py

Modified: python/branches/release27-maint/Lib/httplib.py
==============================================================================
--- python/branches/release27-maint/Lib/httplib.py	(original)
+++ python/branches/release27-maint/Lib/httplib.py	Tue Sep 21 03:38:15 2010
@@ -639,6 +639,9 @@
             amt -= len(chunk)
         return ''.join(s)
 
+    def fileno(self):
+        return self.fp.fileno()
+
     def getheader(self, name, default=None):
         if self.msg is None:
             raise ResponseNotReady()

Modified: python/branches/release27-maint/Lib/test/test_httplib.py
==============================================================================
--- python/branches/release27-maint/Lib/test/test_httplib.py	(original)
+++ python/branches/release27-maint/Lib/test/test_httplib.py	Tue Sep 21 03:38:15 2010
@@ -285,6 +285,13 @@
         self.assertEqual("Basic realm=\"example\"",
                          resp.getheader("www-authenticate"))
 
+    def test_filenoattr(self):
+        # Just test the fileno attribute in the HTTPResponse Object.
+        body = "HTTP/1.1 200 Ok\r\n\r\nText"
+        sock = FakeSocket(body)
+        resp = httplib.HTTPResponse(sock)
+        self.assertTrue(hasattr(resp,'fileno'),
+                'HTTPResponse should expose a fileno attribute')
 
 class OfflineTest(TestCase):
     def test_responses(self):

Modified: python/branches/release27-maint/Lib/test/test_urllib2net.py
==============================================================================
--- python/branches/release27-maint/Lib/test/test_urllib2net.py	(original)
+++ python/branches/release27-maint/Lib/test/test_urllib2net.py	Tue Sep 21 03:38:15 2010
@@ -161,6 +161,17 @@
         self.assertEqual(res.geturl(),
                 "http://docs.python.org/glossary.html")
 
+    def test_fileno(self):
+        req = urllib2.Request("http://www.python.org")
+        opener = urllib2.build_opener()
+        res = opener.open(req)
+        try:
+            res.fileno()
+        except AttributeError:
+            self.fail("HTTPResponse object should return a valid fileno")
+        finally:
+            res.close()
+
     def _test_urls(self, urls, handlers, retry=True):
         import time
         import logging


More information about the Python-checkins mailing list