Kaydet (Commit) 29e2c64e authored tarafından Raymond Hettinger's avatar Raymond Hettinger

Issue #4608: urllib.request.urlopen does not return an iterable object

...@@ -110,8 +110,9 @@ class urlopen_FileTests(unittest.TestCase): ...@@ -110,8 +110,9 @@ class urlopen_FileTests(unittest.TestCase):
# Test iterator # Test iterator
# Don't need to count number of iterations since test would fail the # Don't need to count number of iterations since test would fail the
# instant it returned anything beyond the first line from the # instant it returned anything beyond the first line from the
# comparison # comparison.
for line in self.returned_obj.__iter__(): # Use the iterator in the usual implicit way to test for ticket #4608.
for line in self.returned_obj:
self.assertEqual(line, self.text) self.assertEqual(line, self.text)
class ProxyTests(unittest.TestCase): class ProxyTests(unittest.TestCase):
......
...@@ -23,10 +23,14 @@ class addbase(object): ...@@ -23,10 +23,14 @@ class addbase(object):
self.fileno = self.fp.fileno self.fileno = self.fp.fileno
else: else:
self.fileno = lambda: None self.fileno = lambda: None
if hasattr(self.fp, "__iter__"):
self.__iter__ = self.fp.__iter__ def __iter__(self):
if hasattr(self.fp, "__next__"): # Assigning `__iter__` to the instance doesn't work as intended
self.__next__ = self.fp.__next__ # because the iter builtin does something like `cls.__iter__(obj)`
# and thus fails to find the _bound_ method `obj.__iter__`.
# Returning just `self.fp` works for built-in file objects but
# might not work for general file-like objects.
return iter(self.fp)
def __repr__(self): def __repr__(self):
return '<%s at %r whose fp = %r>' % (self.__class__.__name__, return '<%s at %r whose fp = %r>' % (self.__class__.__name__,
......
...@@ -325,6 +325,7 @@ Lele Gaifax ...@@ -325,6 +325,7 @@ Lele Gaifax
Santiago Gala Santiago Gala
Yitzchak Gale Yitzchak Gale
Quentin Gallet-Gilles Quentin Gallet-Gilles
Riccardo Attilio Galli
Raymund Galvin Raymund Galvin
Nitin Ganatra Nitin Ganatra
Fred Gansevles Fred Gansevles
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment