(original) (raw)

changeset: 77985:e6bb919b2623 parent: 77983:34e705fa4da4 parent: 77984:01c8d800efd2 user: Senthil Kumaran senthil@uthcode.com date: Sat Jul 07 17:15:52 2012 -0700 files: Lib/test/test_urllib.py Lib/urllib/request.py Misc/NEWS description: Fix issue14826 - make urllib.request.Request quoted url consistent with URLOpener open method. Patch contributed by Stephen Thorne. diff -r 34e705fa4da4 -r e6bb919b2623 Lib/test/test_urllib.py --- a/Lib/test/test_urllib.py Sat Jul 07 14:29:58 2012 -0700 +++ b/Lib/test/test_urllib.py Sat Jul 07 17:15:52 2012 -0700 @@ -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 -r 34e705fa4da4 -r e6bb919b2623 Lib/urllib/request.py --- a/Lib/urllib/request.py Sat Jul 07 14:29:58 2012 -0700 +++ b/Lib/urllib/request.py Sat Jul 07 17:15:52 2012 -0700 @@ -263,7 +263,8 @@ origin_req_host=None, unverifiable=False, method=None): # unwrap('') --> '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 -r 34e705fa4da4 -r e6bb919b2623 Misc/NEWS --- a/Misc/NEWS Sat Jul 07 14:29:58 2012 -0700 +++ b/Misc/NEWS Sat Jul 07 17:15:52 2012 -0700 @@ -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"/senthil@uthcode.com