SF 698520: Iterator for urllib.URLOpener
Contributed by Brett Cannon.
diff --git a/Doc/lib/liburllib.tex b/Doc/lib/liburllib.tex
index 9b1ef31..20e2796 100644
--- a/Doc/lib/liburllib.tex
+++ b/Doc/lib/liburllib.tex
@@ -27,7 +27,8 @@
is raised. If all went well, a file-like object is returned. This
supports the following methods: \method{read()}, \method{readline()},
\method{readlines()}, \method{fileno()}, \method{close()},
-\method{info()} and \method{geturl()}.
+\method{info()} and \method{geturl()}. It also has proper support for
+the iterator protocol.
Except for the \method{info()} and \method{geturl()} methods,
these methods have the same interface as for
diff --git a/Lib/urllib.py b/Lib/urllib.py
index 24667ec..f486aee 100644
--- a/Lib/urllib.py
+++ b/Lib/urllib.py
@@ -780,6 +780,10 @@
self.readline = self.fp.readline
if hasattr(self.fp, "readlines"): self.readlines = self.fp.readlines
if hasattr(self.fp, "fileno"): self.fileno = self.fp.fileno
+ if hasattr(self.fp, "__iter__"):
+ self.__iter__ = self.fp.__iter__
+ if hasattr(self.fp, "next"):
+ self.next = self.fp.next
def __repr__(self):
return '<%s at %s whose fp = %s>' % (self.__class__.__name__,
diff --git a/Misc/NEWS b/Misc/NEWS
index a83e282..ebccbec 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -46,6 +46,9 @@
Library
-------
+- The urllib module now offers support for the iterator protocol.
+ SF patch 698520 contributed by Brett Cannon.
+
- New module timeit provides a simple framework for timing the
execution speed of expressions and statements.