Skip to content
Myr

Merge branch '400-header_expand-unicode' of https://github.com/acdha/requests 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 d39cdc4, 0a17bad · Browse files · 2 files+14 added−5 removed
This commit

State

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

Diff stats

2 files+14 added−5 removed

  • other:+14 added−5 removed

2 files+14 added−5 removed

modified:requests/utils.py+5 added-1 removed
144 unmodified lines
145 collector = []146147 if isinstance(headers, dict):148 headers = list(headers.items())149149 elif isinstance(headers, basestring):150 return headers151 elif isinstance(headers, unicode):152 # As discussed in https://github.com/kennethreitz/requests/issues/400153 # latin-1 is the most conservative encoding used on the web. Anyone154 # who needs more can encode to a byte-string before calling155 return headers.encode("latin-1")156157 for i, (value, params) in enumerate(headers):158159 _params = []
277 unmodified lines
modified:test_requests.py+9 added-4 removed
53 unmodified lines
545556class RequestsTestSuite(TestSetup, unittest.TestCase):57 """Requests test cases."""58 5859 def test_entry_points(self):6061 requests.session62 requests.session().get
47 unmodified lines
110111 r = get(httpbin('get') + '?test=true', params={'q': 'test'}, headers=heads)112 self.assertEqual(r.status_code, 200)113114 def test_session_with_unicode_headers(self):115 heads = { u'User-Agent': u'\u30cd\u30c3\u30c8\u30ef\u30fc\u30af' }116114 def test_unicode_headers(self):115 # Simply calling requests with a unicode instance should simply work116 # when the characters are all representable using latin-1:117 heads = { u'User-Agent': u'Requests Test Suite' }118 requests.get(url=httpbin('get'), headers=heads)119120 # Characters outside latin-1 should raise an exception:121 heads = { u'User-Agent': u'\u30cd\u30c3\u30c8\u30ef\u30fc\u30af' }122 self.assertRaises(UnicodeEncodeError, requests.get,123 url=httpbin('get'), headers=heads)124125 def test_session_with_escaped_url(self):126 # Test a URL that contains percent-escaped characters127 # This URL should not be modified (double-escaped)
681 unmodified lines