From: Senthil Kumaran Date: Tue, 21 Sep 2010 01:38:15 +0000 (+0000) Subject: Fix Issue1327971: HTTPResponse should expose a proper fileno attribute X-Git-Tag: v2.7.1rc1~260 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d389cb5bcf890c327154f79240aacc41c5174722;p=python Fix Issue1327971: HTTPResponse should expose a proper fileno attribute --- diff --git a/Lib/httplib.py b/Lib/httplib.py index b1452f439c..2f0356e61c 100644 --- a/Lib/httplib.py +++ b/Lib/httplib.py @@ -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() diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index 1fb810e816..435a9fc8b8 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -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): diff --git a/Lib/test/test_urllib2net.py b/Lib/test/test_urllib2net.py index 76572b052b..56e952d147 100644 --- a/Lib/test/test_urllib2net.py +++ b/Lib/test/test_urllib2net.py @@ -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