Skip to content
Myr

Merge branch 'keytype' of git://github.com/Lukasa/requests into 2.0

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 22701d1, 7de6b1e · Browse files · 3 files+43 added−16 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+43 added−16 removed

  • other:+43 added−16 removed

3 files+43 added−16 removed

modified:requests/models.py+2 added-3 removed
23 unmodified lines
24 ChunkedEncodingError)25from .utils import (26 guess_filename, get_auth_from_url, requote_uri,27 stream_decode_response_unicode, to_key_val_list, parse_header_links,28 iter_slices, guess_json_utf, super_len)28 iter_slices, guess_json_utf, super_len, to_native_string)29from .compat import (30 cookielib, urlunparse, urlsplit, urlencode, str, bytes, StringIO,31 is_py2, chardet, json, builtin_str, basestring, IncompleteRead)32
327 unmodified lines
360 def prepare_headers(self, headers):361 """Prepares the given HTTP headers."""362363 if headers:364 headers = dict((name.encode('ascii'), value) for name, value in headers.items())365 self.headers = CaseInsensitiveDict(headers)364 self.headers = CaseInsensitiveDict((to_native_string(name), value) for name, value in headers.items())365 else:366 self.headers = CaseInsensitiveDict()367368 def prepare_body(self, data, files):
356 unmodified lines
modified:requests/utils.py+25 added-6 removed
19 unmodified lines
2021from . import __version__22from . import certs23from .compat import parse_http_list as _parse_list_header24from .compat import quote, urlparse, bytes, str, OrderedDict, urlunparse25from .compat import getproxies, proxy_bypass24from .compat import (quote, urlparse, bytes, str, OrderedDict, urlunparse,25 is_py2, is_py3, builtin_str, getproxies, proxy_bypass)26from .cookies import RequestsCookieJar, cookiejar_from_dict27from .structures import CaseInsensitiveDict2829_hush_pyflakes = (RequestsCookieJar,)
362 unmodified lines
392 # First check whether no_proxy is defined. If it is, check that the URL393 # we're getting isn't in the no_proxy list.394 no_proxy = get_proxy('no_proxy')395 netloc = urlparse(url).netloc396 396397 if no_proxy:398 # We need to check whether we match here. We need to see if we match399 # the end of the netloc, both with and without the port.400 no_proxy = no_proxy.split(',')401 401402 for host in no_proxy:403 if netloc.endswith(host) or netloc.split(':')[0].endswith(host):404 # The URL does match something in no_proxy, so we don't want405 # to apply the proxies on this URL.406 return {}407 407408 # If the system proxy settings indicate that this URL should be bypassed,409 # don't proxy.410 if proxy_bypass(netloc):411 return {}
1 unmodified line
413 # If we get here, we either didn't have no_proxy set or we're not going414 # anywhere that no_proxy applies to, and the system settings don't require415 # bypassing the proxy for the current URL.416 return getproxies()417 417418419def default_user_agent():420 """Return a string representing the default user agent."""421 _implementation = platform.python_implementation()422
122 unmodified lines
545 parsed = urlparse(url)546 return (parsed.username, parsed.password)547 else:548 return ('', '')549550551def to_native_string(string, encoding='ascii'):552 """553 Given a string object, regardless of type, returns a representation of that554 string in the native string type, encoding and decoding where necessary.555 This assumes ASCII unless told otherwise.556 """557 out = None558559 if isinstance(string, builtin_str):560 out = string561 else:562 if is_py2:563 out = string.encode(encoding)564 else:565 out = string.decode(encoding)566567 return out
modified:test_requests.py+16 added-7 removed
179 unmodified lines
180 # Make sure the cookie was sent181 assert r.json()['cookies']['foo'] == 'bar'182 # Make sure the session cj is still the custom one183 assert s.cookies is cj184 184185 def test_requests_in_history_are_not_overridden(self):186 resp = requests.get(httpbin('redirect/3'))187 urls = [r.url for r in resp.history]188 req_urls = [r.request.url for r in resp.history]189 self.assertEquals(urls, req_urls)190 190191 def test_user_agent_transfers(self):192193 heads = {194 'User-agent': 'Mozilla/5.0 (github.com/kennethreitz/requests)'
49 unmodified lines
244 r = requests.get(url, auth=wrong_auth)245 self.assertEqual(r.status_code, 401)246247 s = requests.session()248 248249 # Should use netrc and work.250 r = s.get(url)251 self.assertEqual(r.status_code, 200)252
302 unmodified lines
555 s.headers.update({'ACCEPT': 'BOGUS'})556 s.headers.update({'accept': 'application/json'})557 r = s.get(httpbin('get'))558 headers = r.request.headers559 # ASCII encode because of key comparison changes in py3559 self.assertEqual(561 headers['accept'.encode('ascii')],560 headers['accept'],561 'application/json'562 )563 self.assertEqual(565 headers['Accept'.encode('ascii')],564 headers['Accept'],565 'application/json'566 )567 self.assertEqual(569 headers['ACCEPT'.encode('ascii')],568 headers['ACCEPT'],569 'application/json'570 )571572 def test_uppercase_scheme_redirect(self):
63 unmodified lines
636 )637 r = requests.Request('GET', url).prepare()638 self.assertEqual(r.url, url)639640 def test_header_keys_are_native(self):641 headers = {u'unicode': 'blah', 'byte'.encode('ascii'): 'blah'}642 r = requests.Request('GET', httpbin('get'), headers=headers)643 p = r.prepare()644645 # This is testing that they are builtin strings. A bit weird, but there646 # we go.647 self.assertTrue('unicode' in p.headers.keys())648 self.assertTrue('byte' in p.headers.keys())649650651class TestCaseInsensitiveDict(unittest.TestCase):652653 def test_mapping_init(self):654 cid = CaseInsensitiveDict({'Foo': 'foo','BAr': 'bar'})
142 unmodified lines