merge conflict and fixes for python3
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 · parent 253cba3 · Browse files · 3 files·+56 added−4 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+56 added−4 removed
- tests:+50 added−2 removed
- other:+6 added−2 removed
Provenance
- Commit
9f55f50- Tree
7f644c4- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
253cba3
3 files changed+56 added−4 removed
modified:requests/models.py+5 added-2 removed
233 unmodified lines234 235 # Facilitate non-RFC2616-compliant 'location' headers236 # (e.g. '/path/to/resource' instead of 'http://domain.tld/path/to/resource')237 if not urlparse(url).netloc:238- url = urljoin(r.url, url)238+ url = urljoin(r.url,239+ # Compliant with RFC3986, we percent240+ # encode the url.241+ requote_uri(url))242 243 # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4244 if r.status_code is codes.see_other:245 method = 'GET'437 unmodified lines683 fp.read(2) # throw away crlf684 while 1:685 #XXX correct line size? (httplib has 64kb, seems insane)686 pending_bytes = fp.readline(40).strip()684- if pending_bytes == '':687+ if not len(pending_bytes):688 # No content, like a HEAD request. Break out.689 break690 pending_bytes = int(pending_bytes, 16)691 if pending_bytes == 0:118 unmodified linesmodified:tests/test_requests_ext.py+50 added-2 removed
6 unmodified lines7 8 import unittest9 10 import requests11+from requests.compat import is_py2, is_py312 13 try:14 import omnijson as json15 except ImportError:29 unmodified lines45 s.get('https://kennethreitz.com', verify=False)46 47 48 def test_binary_post(self):49+ '''We need to be careful how we build the utf-8 string since50+ unicode literals are a syntax error in python351+ '''52+53+ if is_py2:54+ # Blasphemy!55+ utf8_string = eval("u'Smörgås'.encode('utf-8')")56+ elif is_py3:48- utf8_string = (u'Smörgås').encode('utf-8')57+ utf8_string = 'Smörgås'.encode('utf-8')58+ else:59+ raise EnvironmentError('Flesh out this test for your environment.')60 requests.post('http://www.google.com/', data=utf8_string)61 62 63+64 def test_unicode_error(self):53- url = u'http://blip.fm/~1abvfu'65+ url = 'http://blip.fm/~1abvfu'66 requests.get(url)67 68 69 def test_chunked_head_redirect(self):70 url = "http://t.co/NFrx0zLG"71 r = requests.head(url, allow_redirects=True)72 self.assertEqual(r.status_code, 200)73 74+ def test_unicode_redirect(self):75+ '''This url redirects to a location that has a nonstandard76+ character in it, that breaks requests in python2.777+78+ After some research, the cause was identified as an unintended79+ sideeffect of overriding of str with unicode.80+81+ In the case that the redirected url is actually a malformed82+ "bytes" object, i.e. a string with character c where83+ ord(c) > 127,84+ then unicode(url) breaks.85+ '''86+ r = requests.get('http://www.marketwire.com/mw/release.' +87+ 'do?id=1628202&sourceType=3')88+ assert r.ok89+90+ def test_unicode_url_outright(self):91+ '''This url visits in my browser'''92+ r = requests.get('http://www.marketwire.com/press-release/' +93+ 'jp-morgan-behauptet-sich-der-spitze-euro' +94+ 'p%C3%A4ischer-anleihe-analysten-laut-umf' +95+ 'rageergebnissen-1628202.htm')96+ assert r.ok97+98+ def test_redirect_encoding(self):99+ '''This url redirects to100+ http://www.dealipedia.com/deal_view_investment.php?r=20012'''101+102+ r = requests.get('http://feedproxy.google.com/~r/Dealipedia' +103+ 'News/~3/BQtUJRJeZlo/deal_view_investment.' +104+ 'php')105+ assert r.ok106+107+108+109+110 if __name__ == '__main__':111 unittest.main()112 modified:AUTHORS.rst+1 added
84 unmodified lines85 - Adam Tauber86 - Honza Javorek87 - Brendan Maguire <maguire.brendan@gmail.com>88 - Chris Dary89+- Danver Braganza <danverbraganza@gmail.com>