mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Fix Issue1327971: HTTPResponse should expose a proper fileno attribute
This commit is contained in:
parent
a6166dac94
commit
d389cb5bcf
3 changed files with 21 additions and 0 deletions
|
@ -639,6 +639,9 @@ class HTTPResponse:
|
||||||
amt -= len(chunk)
|
amt -= len(chunk)
|
||||||
return ''.join(s)
|
return ''.join(s)
|
||||||
|
|
||||||
|
def fileno(self):
|
||||||
|
return self.fp.fileno()
|
||||||
|
|
||||||
def getheader(self, name, default=None):
|
def getheader(self, name, default=None):
|
||||||
if self.msg is None:
|
if self.msg is None:
|
||||||
raise ResponseNotReady()
|
raise ResponseNotReady()
|
||||||
|
|
|
@ -285,6 +285,13 @@ class BasicTest(TestCase):
|
||||||
self.assertEqual("Basic realm=\"example\"",
|
self.assertEqual("Basic realm=\"example\"",
|
||||||
resp.getheader("www-authenticate"))
|
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):
|
class OfflineTest(TestCase):
|
||||||
def test_responses(self):
|
def test_responses(self):
|
||||||
|
|
|
@ -161,6 +161,17 @@ class OtherNetworkTests(unittest.TestCase):
|
||||||
self.assertEqual(res.geturl(),
|
self.assertEqual(res.geturl(),
|
||||||
"http://docs.python.org/glossary.html")
|
"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):
|
def _test_urls(self, urls, handlers, retry=True):
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue