]> granicus.if.org Git - python/commitdiff
Fix Issue1327971: HTTPResponse should expose a proper fileno attribute
authorSenthil Kumaran <orsenthil@gmail.com>
Tue, 21 Sep 2010 01:38:15 +0000 (01:38 +0000)
committerSenthil Kumaran <orsenthil@gmail.com>
Tue, 21 Sep 2010 01:38:15 +0000 (01:38 +0000)
Lib/httplib.py
Lib/test/test_httplib.py
Lib/test/test_urllib2net.py

index b1452f439c3f8c47da046aa600fac2432c877368..2f0356e61cef27a8a4dfe271c979955db4f9de76 100644 (file)
@@ -639,6 +639,9 @@ class HTTPResponse:
             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()
index 1fb810e816abf4ca4b641b2b3def6da52f89b7e2..435a9fc8b81b93340efb977fe195182554248b35 100644 (file)
@@ -285,6 +285,13 @@ class BasicTest(TestCase):
         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):
index 76572b052b775da84d61524bc64318865a38c25f..56e952d1478228e5e84561991a7d479f187537dd 100644 (file)
@@ -161,6 +161,17 @@ class OtherNetworkTests(unittest.TestCase):
         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