Daniel Diniz <[email protected]> added the comment:
IMHO, using a fileno property looks better than __getattr__. Setting an
attribute in init works too, unless fp changes during the object life
(then 3.x is broken IIUC).
It works OK as a property of either urllib.addinfourl or of
httplib.HTTPResponse (socket would work, but is this broken there or a
higher layer).
Tests and fixes for both solutions attached. As soon as one is chosen,
some docs on fileno would be nice, even for 3.x.
This (current) test in test_urllibnet.py passes, but I don't see how to
improve it, assuming it should fail/detect this bug (maybe self.urlopen
isn't testing urllib.urlopen correctly?):
def test_fileno(self):
if (sys.platform in ('win32',) or
not hasattr(os, 'fdopen')):
# On Windows, socket handles are not file descriptors; this
# test can't pass on Windows.
return
# Make sure fd returned by fileno is valid.
open_url = self.urlopen("http://www.python.org/")
fd = open_url.fileno()
FILE = os.fdopen(fd)
----------
keywords: +patch
stage: test needed -> patch review
Added file: http://bugs.python.org/file13030/httplib_fileno.diff
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue1327971>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com