[Python-checkins] r85475 - in python/branches/py3k: Doc/library/urllib.request.rst Lib/test/test_urllib2.py Lib/urllib/request.py Misc/NEWS

senthil.kumaran python-checkins at python.org
Thu Oct 14 13:57:35 CEST 2010


Author: senthil.kumaran
Date: Thu Oct 14 13:57:35 2010
New Revision: 85475

Log:
Issue10063 - file:// scheme will stop accessing remote hosts via ftp protocol



Modified:
   python/branches/py3k/Doc/library/urllib.request.rst
   python/branches/py3k/Lib/test/test_urllib2.py
   python/branches/py3k/Lib/urllib/request.py
   python/branches/py3k/Misc/NEWS

Modified: python/branches/py3k/Doc/library/urllib.request.rst
==============================================================================
--- python/branches/py3k/Doc/library/urllib.request.rst	(original)
+++ python/branches/py3k/Doc/library/urllib.request.rst	Thu Oct 14 13:57:35 2010
@@ -1004,8 +1004,12 @@
 .. method:: FileHandler.file_open(req)
 
    Open the file locally, if there is no host name, or the host name is
-   ``'localhost'``. Change the protocol to ``ftp`` otherwise, and retry opening it
-   using :attr:`parent`.
+   ``'localhost'``.
+
+   This method is applicable only for local hostnames. When a remote hostname
+   is given, an :exc:`URLError` is raised.
+
+.. versionchanged:: 3.2
 
 
 .. _ftp-handler-objects:

Modified: python/branches/py3k/Lib/test/test_urllib2.py
==============================================================================
--- python/branches/py3k/Lib/test/test_urllib2.py	(original)
+++ python/branches/py3k/Lib/test/test_urllib2.py	Thu Oct 14 13:57:35 2010
@@ -731,11 +731,11 @@
         # file:///blah.txt (a file)
         # file://ftp.example.com/blah.txt (an ftp URL)
         for url, ftp in [
-            ("file://ftp.example.com//foo.txt", True),
+            ("file://ftp.example.com//foo.txt", False),
             ("file://ftp.example.com///foo.txt", False),
 # XXXX bug: fails with OSError, should be URLError
             ("file://ftp.example.com/foo.txt", False),
-            ("file://somehost//foo/something.txt", True),
+            ("file://somehost//foo/something.txt", False),
             ("file://localhost//foo/something.txt", False),
             ]:
             req = Request(url)

Modified: python/branches/py3k/Lib/urllib/request.py
==============================================================================
--- python/branches/py3k/Lib/urllib/request.py	(original)
+++ python/branches/py3k/Lib/urllib/request.py	Thu Oct 14 13:57:35 2010
@@ -1228,8 +1228,8 @@
         url = req.selector
         if url[:2] == '//' and url[2:3] != '/' and (req.host and
                 req.host != 'localhost'):
-            req.type = 'ftp'
-            return self.parent.open(req)
+            if not req.host is self.get_names():
+                raise URLError("file:// scheme is supported only on localhost")
         else:
             return self.open_local_file(req)
 
@@ -1712,7 +1712,7 @@
         if not isinstance(url, str):
             raise URLError('file error', 'proxy support for file protocol currently not implemented')
         if url[:2] == '//' and url[2:3] != '/' and url[2:12].lower() != 'localhost/':
-            return self.open_ftp(url)
+            raise ValueError("file:// scheme is supported only on localhost")
         else:
             return self.open_local_file(url)
 

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Thu Oct 14 13:57:35 2010
@@ -18,6 +18,12 @@
 Library
 -------
 
+- Issue #Issue10063: file:// scheme will stop accessing remote hosts via ftp
+  protocol. file:// urls had fallback to access remote hosts via ftp. This was
+  not correct, change is made to raise a URLError when a remote host is tried
+  to access via file:// scheme.
+
+
 - Issue #1710703: Write structures for an empty ZIP archive when a ZipFile is
   created in modes 'a' or 'w' and then closed without adding any files. Raise
   BadZipfile (rather than IOError) when opening small non-ZIP files.


More information about the Python-checkins mailing list