summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSenthil Kumaran <orsenthil@gmail.com>2009-08-15 17:49:55 (GMT)
committerSenthil Kumaran <orsenthil@gmail.com>2009-08-15 17:49:55 (GMT)
commitb52c6f8c3906b10446dbe81b29bcdb0a9b8e785a (patch)
treee3bbbfbdb1fab9fd110b9c683e207adb1e3d49bd /Lib
parentf492c364427eb0224fa242ae938cc3cc98f7fe51 (diff)
downloadcpython-b52c6f8c3906b10446dbe81b29bcdb0a9b8e785a.zip
cpython-b52c6f8c3906b10446dbe81b29bcdb0a9b8e785a.tar.gz
cpython-b52c6f8c3906b10446dbe81b29bcdb0a9b8e785a.tar.bz2
Fixing Issue6557. urllib.urlopen will quote the space character within urls.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_urllib.py12
-rw-r--r--Lib/urllib.py3
2 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index c8410d1..0870b53 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -582,6 +582,17 @@ class Pathname_Tests(unittest.TestCase):
"url2pathname() failed; %s != %s" %
(expect, result))
+class URLopener_Tests(unittest.TestCase):
+ """Testcase to test the open method of URLopener class."""
+ def test_quoted_open(self):
+ class DummyURLopener(urllib.URLopener):
+ def open_spam(self, url):
+ return url
+
+ self.assertEqual(DummyURLopener().open(
+ 'spam://example/ /'),'//example/%20/')
+
+
# Just commented them out.
# Can't really tell why keep failing in windows and sparc.
# Everywhere else they work ok, but on those machines, someteimes
@@ -676,6 +687,7 @@ def test_main():
UnquotingTests,
urlencode_Tests,
Pathname_Tests,
+ URLopener_Tests,
#FTPWrapperTests,
)
diff --git a/Lib/urllib.py b/Lib/urllib.py
index 541cec8..f69ec63 100644
--- a/Lib/urllib.py
+++ b/Lib/urllib.py
@@ -176,6 +176,9 @@ class URLopener:
def open(self, fullurl, data=None):
"""Use URLopener().open(file) instead of open(file, 'r')."""
fullurl = unwrap(toBytes(fullurl))
+ # percent encode url. fixing lame server errors like space within url
+ # parts
+ fullurl = quote(fullurl, safe="%/:=&?~#+!$,;'@()*[]")
if self.tempcache and fullurl in self.tempcache:
filename, headers = self.tempcache[fullurl]
fp = open(filename, 'rb')