Skip to content
Myr

Support bytestring URLs on Python 3.x

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Joe Alcorn · committed by Joe Alcorn · parent a718a81 · Browse files · 3 files+14 added−6 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+14 added−6 removed

  • other:+14 added−6 removed

3 files+14 added−6 removed

modified:requests/models.py+7 added-6 removed
324 unmodified lines
325326 def prepare_url(self, url, params):327 """Prepares the given HTTP URL."""328 #: Accept objects that have string representations.329 #: We're unable to blindy call unicode/str functions330 #: as this will include the bytestring indicator (b'')331 #: on python 3.x.332 #: https://github.com/kennethreitz/requests/pull/2238333 try:330 url = unicode(url)331 except NameError:332 # We're on Python 3.333 url = str(url)334 except UnicodeDecodeError:335 pass334 url = url.decode('utf8')335 except AttributeError:336 url = unicode(url) if is_py2 else str(url)337338 # Don't do any URL preparation for non-HTTP schemes like `mailto`,339 # `data` etc to work around exceptions from `url_parse`, which340 # handles RFC 3986 only.
479 unmodified lines
modified:AUTHORS.rst+1 added
153 unmodified lines
154- Константин Подшумок (`@podshumok <https://github.com/podshumok>`_)155- Ben Bass (`@codedstructure <https://github.com/codedstructure>`_)156- Jonathan Wong <evolutionace@gmail.com> (`@ContinuousFunction <https://github.com/ContinuousFunction>`_)157- Martin Jul (`@mjul <https://github.com/mjul>`_)158- Joe Alcorn (`@buttscicles <https://github.com/buttscicles>`_)
modified:test_requests.py+6 added
589 unmodified lines
590591 assert resp.json()['headers'][592 'Dummy-Auth-Test'] == 'dummy-auth-test-ok'593594 def test_prepare_request_with_bytestring_url(self):595 req = requests.Request('GET', b'https://httpbin.org/')596 s = requests.Session()597 prep = s.prepare_request(req)598 assert prep.url == "https://httpbin.org/"599600 def test_links(self):601 r = requests.Response()602 r.headers = {603 'cache-control': 'public, max-age=60, s-maxage=60',
899 unmodified lines