diff options
author | Raymond Hettinger <python@rcn.com> | 2011-06-26 12:30:25 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2011-06-26 12:30:25 (GMT) |
commit | 29e2c64edd9696483d51a24a6f74ae74815b441d (patch) | |
tree | 10dbf63f1cba853fa2e27f5f035809a8282f84e8 /Lib/urllib/response.py | |
parent | 58ff0039a3df47e240eed9f721f759c9db508202 (diff) | |
parent | 038018aaa4c4d1c8df7952adaa4df14ec3333496 (diff) | |
download | cpython-29e2c64edd9696483d51a24a6f74ae74815b441d.zip cpython-29e2c64edd9696483d51a24a6f74ae74815b441d.tar.gz cpython-29e2c64edd9696483d51a24a6f74ae74815b441d.tar.bz2 |
Issue #4608: urllib.request.urlopen does not return an iterable object
Diffstat (limited to 'Lib/urllib/response.py')
-rw-r--r-- | Lib/urllib/response.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Lib/urllib/response.py b/Lib/urllib/response.py index bce2287..b43e575 100644 --- 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__"): - 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__, |