[Python-checkins] cpython (merge 3.2 -> default): Fix issue14826 - make urllib.request.Request quoted url consistent with
senthil.kumaran
python-checkins at python.org
Sun Jul 8 02:15:06 CEST 2012
http://hg.python.org/cpython/rev/e6bb919b2623
changeset: 77985:e6bb919b2623
parent: 77983:34e705fa4da4
parent: 77984:01c8d800efd2
user: Senthil Kumaran <senthil at uthcode.com>
date: Sat Jul 07 17:15:52 2012 -0700
summary:
Fix issue14826 - make urllib.request.Request quoted url consistent with URLOpener open method.
Patch contributed by Stephen Thorne.
files:
Lib/test/test_urllib.py | 5 +++++
Lib/urllib/request.py | 3 ++-
Misc/NEWS | 5 +++++
3 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -1272,6 +1272,11 @@
request.method = 'HEAD'
self.assertEqual(request.get_method(), 'HEAD')
+ def test_quote_url(self):
+ Request = urllib.request.Request
+ request = Request("http://www.python.org/foo bar")
+ self.assertEqual(request.full_url, "http://www.python.org/foo%20bar")
+
def test_main():
support.run_unittest(
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -263,7 +263,8 @@
origin_req_host=None, unverifiable=False,
method=None):
# unwrap('<URL:type://host/path>') --> 'type://host/path'
- self.full_url = unwrap(url)
+ self.full_url = unwrap(to_bytes(url))
+ self.full_url = quote(self.full_url, safe="%/:=&?~#+!,ドル;'@()*[]|")
self.full_url, self.fragment = splittag(self.full_url)
self.data = data
self.headers = {}
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -23,6 +23,11 @@
Library
-------
+- Issue #14826: Quote urls in urllib.request.Request identically to how they
+ are quoted by urllib.request.URLopener. Allows urls to spaces in them to work
+ transparently with urllib.request.urlopen(...). Patch contributed by Stephen
+ Thorne.
+
- Issue #5931: wsgiref environ variable SERVER_SOFTWARE will specify an
implementation specific term like Cpython, Jython instead of generic "Python"
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list