]> granicus.if.org Git - python/commitdiff
SF 698520: Iterator for urllib.URLOpener
authorRaymond Hettinger <python@rcn.com>
Sun, 9 Mar 2003 05:33:33 +0000 (05:33 +0000)
committerRaymond Hettinger <python@rcn.com>
Sun, 9 Mar 2003 05:33:33 +0000 (05:33 +0000)
Contributed by Brett Cannon.

Doc/lib/liburllib.tex
Lib/urllib.py
Misc/NEWS

index 9b1ef31cda677ae7f0b6eefd13dc44981ac3f5a6..20e2796afc91681855ff3680faf02a78170c46c9 100644 (file)
@@ -27,7 +27,8 @@ if the server returns an error code, the \exception{IOError} exception
 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
index 24667ec058c318376812412280c02485f971b678..f486aeeb165bcda99bf7f5fcfad6da761366086e 100644 (file)
@@ -780,6 +780,10 @@ class addbase:
         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__,
index a83e28287f2a4c448500d7d0ddc718e98bd92b4b..ebccbecaf93d532baa78bf576ed613b70af3b729 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -46,6 +46,9 @@ Extension modules
 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.