[Python-checkins] r64649 - in python/trunk: Doc/library/urllib.rst Lib/test/test_urllib.py Lib/test/test_urllibnet.py Lib/urllib.py Misc/NEWS

brett.cannon python-checkins at python.org
Wed Jul 2 03:57:09 CEST 2008


Author: brett.cannon
Date: Wed Jul  2 03:57:08 2008
New Revision: 64649

Log:
Handle urllib's renaming for Python 3.0:

* Deprecate urllib.urlopen() in favor of urllib2.urlopen() for 3.0.
* Update docs to mention split/rename of the module and deprecation of
  urlopen().

Changes to lib2to3 are in a separate commit. Work is for issue #2885.


Modified:
   python/trunk/Doc/library/urllib.rst
   python/trunk/Lib/test/test_urllib.py
   python/trunk/Lib/test/test_urllibnet.py
   python/trunk/Lib/urllib.py
   python/trunk/Misc/NEWS

Modified: python/trunk/Doc/library/urllib.rst
==============================================================================
--- python/trunk/Doc/library/urllib.rst	(original)
+++ python/trunk/Doc/library/urllib.rst	Wed Jul  2 03:57:08 2008
@@ -4,6 +4,13 @@
 .. module:: urllib
    :synopsis: Open an arbitrary network resource by URL (requires sockets).
 
+.. note::
+    The :mod:`urllib` module has been split into parts and renamed in
+    Python 3.0 to :mod:`urllib.request`, :mod:`urllib.parse`,
+    and :mod:`urllib.error`. The :term:`2to3` tool will automatically adapt
+    imports when converting your sources to 3.0.
+    Also note that the :func:`urllib.urlopen` function has been removed in
+    Python 3.0 in favor of :func:`urllib2.urlopen`.
 
 .. index::
    single: WWW
@@ -116,6 +123,10 @@
    .. versionchanged:: 2.6
       Added :meth:`getcode` to returned object and support for the
       :envvar:`no_proxy` environment variable.
+      
+   .. deprecated:: 2.6
+      The :func:`urlopen` function has been removed in Python 3.0 in favor
+      of :func:`urllib2.urlopen`.
 
 
 .. function:: urlretrieve(url[, filename[, reporthook[, data]]])

Modified: python/trunk/Lib/test/test_urllib.py
==============================================================================
--- python/trunk/Lib/test/test_urllib.py	(original)
+++ python/trunk/Lib/test/test_urllib.py	Wed Jul  2 03:57:08 2008
@@ -640,16 +640,20 @@
 
 
 def test_main():
-    test_support.run_unittest(
-        urlopen_FileTests,
-        urlopen_HttpTests,
-        urlretrieve_FileTests,
-        QuotingTests,
-        UnquotingTests,
-        urlencode_Tests,
-        Pathname_Tests,
-        #FTPWrapperTests,
-    )
+    import warnings
+    with test_support.catch_warning(record=False):
+        warnings.filterwarnings('ignore', ".*urllib\.urlopen.*Python 3.0",
+                                DeprecationWarning)
+        test_support.run_unittest(
+            urlopen_FileTests,
+            urlopen_HttpTests,
+            urlretrieve_FileTests,
+            QuotingTests,
+            UnquotingTests,
+            urlencode_Tests,
+            Pathname_Tests,
+            #FTPWrapperTests,
+        )
 
 
 

Modified: python/trunk/Lib/test/test_urllibnet.py
==============================================================================
--- python/trunk/Lib/test/test_urllibnet.py	(original)
+++ python/trunk/Lib/test/test_urllibnet.py	Wed Jul  2 03:57:08 2008
@@ -182,9 +182,13 @@
 
 def test_main():
     test_support.requires('network')
-    test_support.run_unittest(URLTimeoutTest,
-                              urlopenNetworkTests,
-                              urlretrieveNetworkTests)
+    from warnings import filterwarnings
+    with test_support.catch_warning(record=False):
+        filterwarnings('ignore', '.*urllib\.urlopen.*Python 3.0',
+                        DeprecationWarning)
+        test_support.run_unittest(URLTimeoutTest,
+                                  urlopenNetworkTests,
+                                  urlretrieveNetworkTests)
 
 if __name__ == "__main__":
     test_main()

Modified: python/trunk/Lib/urllib.py
==============================================================================
--- python/trunk/Lib/urllib.py	(original)
+++ python/trunk/Lib/urllib.py	Wed Jul  2 03:57:08 2008
@@ -28,6 +28,7 @@
 import time
 import sys
 from urlparse import urljoin as basejoin
+import warnings
 
 __all__ = ["urlopen", "URLopener", "FancyURLopener", "urlretrieve",
            "urlcleanup", "quote", "quote_plus", "unquote", "unquote_plus",
@@ -69,7 +70,11 @@
 # Shortcut for basic usage
 _urlopener = None
 def urlopen(url, data=None, proxies=None):
-    """urlopen(url [, data]) -> open file-like object"""
+    """Create a file-like object for the specified URL to read from."""
+    from warnings import warnpy3k
+    warnings.warnpy3k("urllib.urlopen() has been removed in Python 3.0 in "
+                        "favor of urllib2.urlopen()", stacklevel=2)
+
     global _urlopener
     if proxies is not None:
         opener = FancyURLopener(proxies=proxies)

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Wed Jul  2 03:57:08 2008
@@ -29,11 +29,24 @@
   would not cause a syntax error.  This was regression from 2.4 caused by the
   switch to the new compiler.
 
+
+Library
+-------
+
+- Issue #2885 (partial): The urllib.urlopen() function has been deprecated for
+  removal in Python 3.0 in favor of urllib2.urlopen().
+
+- Issue #2885 (partial): lib2to3 has been updated to handle the renaming of the
+  urllib module in Python 3.0 to urllib.request, urllib.parse, and
+  urllib.error.
+
+
 Build
 -----
 
 - Issue #3215: Build sqlite3 as sqlite3.dll, not sqlite3.pyd.
 
+
 What's New in Python 2.6 beta 1?
 ================================
 


More information about the Python-checkins mailing list