mirror of
https://github.com/python/cpython.git
synced 2025-08-29 21:25:01 +00:00
Issue #4608: urllib.request.urlopen does not return an iterable object
This commit is contained in:
commit
29e2c64edd
3 changed files with 12 additions and 6 deletions
|
@ -23,10 +23,14 @@ class addbase(object):
|
|||
self.fileno = self.fp.fileno
|
||||
else:
|
||||
self.fileno = lambda: None
|
||||
if hasattr(self.fp, "__iter__"):
|
||||
self.__iter__ = self.fp.__iter__
|
||||
if hasattr(self.fp, "__next__"):
|
||||
self.__next__ = self.fp.__next__
|
||||
|
||||
def __iter__(self):
|
||||
# Assigning `__iter__` to the instance doesn't work as intended
|
||||
# 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):
|
||||
return '<%s at %r whose fp = %r>' % (self.__class__.__name__,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue