mirror of
https://github.com/python/cpython.git
synced 2025-08-13 13:29:13 +00:00
Fixing Issue6557. urllib.urlopen will quote the space character within urls.
This commit is contained in:
parent
f492c36442
commit
b52c6f8c39
2 changed files with 15 additions and 0 deletions
|
@ -582,6 +582,17 @@ class Pathname_Tests(unittest.TestCase):
|
||||||
"url2pathname() failed; %s != %s" %
|
"url2pathname() failed; %s != %s" %
|
||||||
(expect, result))
|
(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.
|
# Just commented them out.
|
||||||
# Can't really tell why keep failing in windows and sparc.
|
# Can't really tell why keep failing in windows and sparc.
|
||||||
# Everywhere else they work ok, but on those machines, someteimes
|
# Everywhere else they work ok, but on those machines, someteimes
|
||||||
|
@ -676,6 +687,7 @@ def test_main():
|
||||||
UnquotingTests,
|
UnquotingTests,
|
||||||
urlencode_Tests,
|
urlencode_Tests,
|
||||||
Pathname_Tests,
|
Pathname_Tests,
|
||||||
|
URLopener_Tests,
|
||||||
#FTPWrapperTests,
|
#FTPWrapperTests,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -176,6 +176,9 @@ class URLopener:
|
||||||
def open(self, fullurl, data=None):
|
def open(self, fullurl, data=None):
|
||||||
"""Use URLopener().open(file) instead of open(file, 'r')."""
|
"""Use URLopener().open(file) instead of open(file, 'r')."""
|
||||||
fullurl = unwrap(toBytes(fullurl))
|
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:
|
if self.tempcache and fullurl in self.tempcache:
|
||||||
filename, headers = self.tempcache[fullurl]
|
filename, headers = self.tempcache[fullurl]
|
||||||
fp = open(filename, 'rb')
|
fp = open(filename, 'rb')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue