Merge branch 'mgiuca-uri-cleanup-nonpath' into develop
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kenneth Reitz · committed by Kenneth Reitz · parents 9e2f5dd, 690426a · Browse files · 4 files·+45 added−11 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+45 added−11 removed
- other:+45 added−11 removed
Provenance
- Commit
b887ea3- Tree
d97ff5f- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
9e2f5dd- Parent 2
690426a
4 files changed+45 added−11 removed
modified:requests/models.py+17 added-7 removed
24 unmodified lines25 ConnectionError, HTTPError, RequestException, Timeout, TooManyRedirects,26 URLRequired, SSLError)27 from .utils import (28 get_encoding_from_headers, stream_decode_response_unicode,29- stream_decompress, guess_filename, requote_path, dict_from_string)29+ stream_decompress, guess_filename, requote_uri, dict_from_string)30 31 from .compat import urlparse, urlunparse, urljoin, urlsplit, urlencode, quote, unquote, str, bytes, SimpleCookie, is_py3, is_py232 33 # Import chardet if it is available.286 unmodified lines320 if not path:321 path = '/'322 323 if is_py2:324+ if isinstance(scheme, str):325+ scheme = scheme.encode('utf-8')326+ if isinstance(netloc, str):327+ netloc = netloc.encode('utf-8')328 if isinstance(path, str):329 path = path.encode('utf-8')330+ if isinstance(params, str):331+ params = params.encode('utf-8')332+ if isinstance(query, str):333+ query = query.encode('utf-8')334+ if isinstance(fragment, str):335+ fragment = fragment.encode('utf-8')336 327- path = requote_path(path)328-337 url = (urlunparse([ scheme, netloc, path, params, query, fragment ]))338 339 if self._enc_params:340 if urlparse(url).query:333- return '%s&%s' % (url, self._enc_params)341+ url = '%s&%s' % (url, self._enc_params)342 else:335- return '%s?%s' % (url, self._enc_params)336- else:337- return url343+ url = '%s?%s' % (url, self._enc_params)344 345+ url = requote_uri(url)346+347+ return url348+349 @property350 def path_url(self):351 """Build the path URL to use."""352 451 unmodified linesmodified:requests/utils.py+4 added-4 removed
417 unmodified lines418 else:419 parts[i] = '%' + parts[i]420 return ''.join(parts)421 422-def requote_path(path):423- """Re-quote the given URL path component.422+def requote_uri(uri):423+ """Re-quote the given URI.424 425- This function passes the given path through an unquote/quote cycle to425+ This function passes the given URI through an unquote/quote cycle to426 ensure that it is fully and consistently quoted.427 """428 # Unquote only the unreserved characters429 # Then quote only illegal characters (do not quote reserved, unreserved,430 # or '%')431- return quote(unquote_unreserved(path), safe="!#$%&'()*+,/:;=?@[]~")431+ return quote(unquote_unreserved(uri), safe="!#$%&'()*+,/:;=?@[]~")432 return "/".join(parts)modified:AUTHORS.rst+1 added
79 unmodified lines80 - David Kemp81 - Brendon Crawford82 - Denis (Telofy)83 - Cory Benfield (Lukasa)84+- Matt Giucamodified:test_requests.py+23 added
158 unmodified lines159 url = httpbin('get/' + path_unreserved_escaped)160 response = get(url)161 self.assertEqual(response.url, httpbin('get/' + path_unreserved))162 163+ # Re-run all of the same tests on the query part of the URI164+ query_fully_escaped = '%3Ca%25b%23c%2Fd%3E=%C3%98%20%C3%A5'165+ url = httpbin('get/?' + query_fully_escaped)166+ response = get(url)167+ self.assertEqual(response.url, httpbin('get/?' + query_fully_escaped))168 169+ query = u'<a%25b%23c%2Fd%3E=\u00d8 %C3%A5'170+ url = httpbin('get/?' + query)171+ response = get(url)172+ self.assertEqual(response.url, httpbin('get/?' + query_fully_escaped))173+174+ # The legal characters in query happens to be the same as in path175+ query_reserved = '!$&\'()*+,/:=@-._~'176+ url = httpbin('get/?' + query_reserved)177+ response = get(url)178+ self.assertEqual(response.url, httpbin('get/?' + query_reserved))179+180+ query_unreserved = 'ABCDwxyz=1234-._~'181+ query_unreserved_escaped = '%41%42%43%44%77%78%79%7A=%31%32%33%34%2D%2E%5F%7E'182+ url = httpbin('get/?' + query_unreserved_escaped)183+ response = get(url)184+ self.assertEqual(response.url, httpbin('get/?' + query_unreserved))185+186+187 def test_user_agent_transfers(self):188 """Issue XX"""189 190 heads = {613 unmodified lines