cpython: d4aeeddf72e3 (original) (raw)
Mercurial > cpython
changeset 70997:d4aeeddf72e3
Issue #4608: urllib.request.urlopen does not return an iterable object [#4608]
Raymond Hettinger python@rcn.com | |
---|---|
date | Sun, 26 Jun 2011 14:30:25 +0200 |
parents | b879bad40154(current diff)c0a68b948f5d(diff) |
children | fcf242243d46 |
files | Lib/test/test_urllib.py Lib/urllib/response.py Misc/ACKS |
diffstat | 3 files changed, 12 insertions(+), 6 deletions(-)[+] [-] Lib/test/test_urllib.py 5 Lib/urllib/response.py 12 Misc/ACKS 1 |
line wrap: on
line diff
--- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -110,8 +110,9 @@ class urlopen_FileTests(unittest.TestCas # Test iterator # Don't need to count number of iterations since test would fail the # instant it returned anything beyond the first line from the
# comparison[](#l1.7)
for line in self.returned_obj.__iter__():[](#l1.8)
# comparison.[](#l1.9)
# Use the iterator in the usual implicit way to test for ticket #4608.[](#l1.10)
for line in self.returned_obj:[](#l1.11) self.assertEqual(line, self.text)[](#l1.12)
class ProxyTests(unittest.TestCase):
--- a/Lib/urllib/response.py +++ b/Lib/urllib/response.py @@ -23,10 +23,14 @@ class addbase(object): self.fileno = self.fp.fileno else: self.fileno = lambda: None
if hasattr(self.fp, "__iter__"):[](#l2.7)
self.__iter__ = self.fp.__iter__[](#l2.8)
if hasattr(self.fp, "__next__"):[](#l2.9)
self.__next__ = self.fp.__next__[](#l2.10)
- def iter(self):
# Assigning `__iter__` to the instance doesn't work as intended[](#l2.13)
# because the iter builtin does something like `cls.__iter__(obj)`[](#l2.14)
# and thus fails to find the _bound_ method `obj.__iter__`.[](#l2.15)
# Returning just `self.fp` works for built-in file objects but[](#l2.16)
# might not work for general file-like objects.[](#l2.17)
return iter(self.fp)[](#l2.18)
def repr(self): return '<%s at %r whose fp = %r>' % (self.class.name,
--- a/Misc/ACKS +++ b/Misc/ACKS @@ -325,6 +325,7 @@ Lele Gaifax Santiago Gala Yitzchak Gale Quentin Gallet-Gilles +Riccardo Attilio Galli Raymund Galvin Nitin Ganatra Fred Gansevles