Merge pull request #1363 from dave-shawley/master
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Fix for #1362
authored by Kenneth Reitz · committed by Kenneth Reitz · parents eacb91a, 6e76ab7 · Browse files · 3 files·+25 added−7 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+25 added−7 removed
- other:+25 added−7 removed
Provenance
- Commit
5943afa- Tree
139e1c9- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
eacb91a- Parent 2
6e76ab7
3 files changed+25 added−7 removed
modified:requests/models.py+15 added-7 removed
16 unmodified lines17 18 from .auth import HTTPBasicAuth19 from .cookies import cookiejar_from_dict, get_cookie_header20 from .packages.urllib3.filepost import encode_multipart_formdata21+from .packages.urllib3.util import parse_url22 from .exceptions import HTTPError, RequestException, MissingSchema, InvalidURL23 from .utils import (24 guess_filename, get_auth_from_url, requote_uri,25 stream_decode_response_unicode, to_key_val_list, parse_header_links,258 unmodified lines284 except UnicodeDecodeError:285 pass286 287 # Support for unicode domain names and paths.287- scheme, netloc, path, _params, query, fragment = urlparse(url)288+ scheme, auth, host, port, path, query, fragment = parse_url(url)289 290 if not scheme:291 raise MissingSchema("Invalid URL %r: No schema supplied" % url)292 292- if not netloc:293- raise InvalidURL("Invalid URL %t: No netloc supplied" % url)293+ if not host:294+ raise InvalidURL("Invalid URL %t: No host supplied" % url)295 296+ # Only want to apply IDNA to the hostname297 try:296- netloc = netloc.encode('idna').decode('utf-8')298+ host = host.encode('idna').decode('utf-8')299 except UnicodeError:300 raise InvalidURL('URL has an invalid label.')301 302+ # Carefully reconstruct the network location303+ netloc = auth or ''304+ if netloc:305+ netloc += '@'306+ netloc += host307+ if port:308+ netloc += ':' + str(port)309+310 # Bare domains aren't valid URLs.311 if not path:312 path = '/'313 3 unmodified lines317 if isinstance(netloc, str):318 netloc = netloc.encode('utf-8')319 if isinstance(path, str):320 path = path.encode('utf-8')311- if isinstance(_params, str):312- _params = _params.encode('utf-8')321 if isinstance(query, str):322 query = query.encode('utf-8')323 if isinstance(fragment, str):324 fragment = fragment.encode('utf-8')4 unmodified lines329 query = '%s&%s' % (query, enc_params)330 else:331 query = enc_params332 325- url = requote_uri(urlunparse([scheme, netloc, path, _params, query, fragment]))333+ url = requote_uri(urlunparse([scheme, netloc, path, None, query, fragment]))334 self.url = url335 336 def prepare_headers(self, headers):337 """Prepares the given HTTP headers."""349 unmodified linesmodified:AUTHORS.rst+1 added
125 unmodified lines126 - Bryce Boe <bbzbryce@gmail.com> @bboe127 - Colin Dunklau <colin.dunklau@gmail.com> @cdunklau128 - Hugo Osvaldo Barrera <hugo@osvaldobarrera.com.ar> @hobarrera129 - Łukasz Langa <lukasz@langa.pl> @llanga130+- Dave Shawley <daveshawley@gmail.com>modified:test_requests.py+9 added
519 unmodified lines520 s2.mount('https://', HTTPAdapter())521 self.assertTrue('http://' in s2.adapters)522 self.assertTrue('https://' in s2.adapters)523 524+ def test_long_authinfo_in_url(self):525+ url = 'http://{0}:{1}@{2}:9000/path?query#frag'.format(526+ 'E8A3BE87-9E3F-4620-8858-95478E385B5B',527+ 'EA770032-DA4D-4D84-8CE9-29C6D910BF1E',528+ 'exactly-------------sixty-----------three------------characters',529+ )530+ r = requests.Request('GET', url).prepare()531+ self.assertEqual(r.url, url)532 533+534 class TestCaseInsensitiveDict(unittest.TestCase):535 536 def test_mapping_init(self):537 cid = CaseInsensitiveDict({'Foo': 'foo','BAr': 'bar'})142 unmodified lines