From 5eea4a3767797af6a0b994723a4280382328ce03 Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Mon, 26 May 2014 00:18:14 +0200 Subject: [PATCH 1/3] faq: mention that PyPy 2.2 works too The FAQ says that PyPy 1.9 is supported. On my Debian Unstable, I can install PyPy 2.2.1 and the tests work with that version too. --- docs/community/faq.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/community/faq.rst b/docs/community/faq.rst index 4e792eca..ed98fa85 100644 --- a/docs/community/faq.rst +++ b/docs/community/faq.rst @@ -60,6 +60,7 @@ supported: * Python 3.2 * Python 3.3 * PyPy 1.9 +* PyPy 2.2 What are "hostname doesn't match" errors? ----------------------------------------- From f4d1bbb7c549e1e276e61fa6390f9b5ce761c0ae Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Mon, 26 May 2014 00:23:21 +0200 Subject: [PATCH 2/3] faq: add Python 3.4 to list of supported Python versions No code changes were necessary for this. --- docs/community/faq.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/community/faq.rst b/docs/community/faq.rst index ed98fa85..5b3ecb81 100644 --- a/docs/community/faq.rst +++ b/docs/community/faq.rst @@ -59,6 +59,7 @@ supported: * Python 3.1 * Python 3.2 * Python 3.3 +* Python 3.4 * PyPy 1.9 * PyPy 2.2 From c8916a08deb8be25d2be38c646fab9b2ab1fb8f7 Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Mon, 26 May 2014 00:31:10 +0200 Subject: [PATCH 3/3] test: restore Python 3.2 compatibility The tests were broken because they used the u'...' Unicode literal syntax which disappeared in Python 3.0 to 3.2. We can work around this by conditionally defining a "u" function which will produce a Unicode literal on Python 2.x. This is basically the same approach as taken by the six library often used for writing cross-version compatible code. --- test_requests.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/test_requests.py b/test_requests.py index a92b22c6..4871dc51 100755 --- a/test_requests.py +++ b/test_requests.py @@ -16,7 +16,7 @@ import pytest from requests.adapters import HTTPAdapter from requests.auth import HTTPDigestAuth from requests.compat import ( - Morsel, cookielib, getproxies, str, urljoin, urlparse) + Morsel, cookielib, getproxies, str, urljoin, urlparse, is_py3) from requests.cookies import cookiejar_from_dict, morsel_to_cookie from requests.exceptions import InvalidURL, MissingSchema from requests.models import PreparedRequest, Response @@ -30,6 +30,14 @@ try: except ImportError: import io as StringIO +if is_py3: + def u(s): + return s +else: + def u(s): + return s.decode('unicode-escape') + + HTTPBIN = os.environ.get('HTTPBIN_URL', 'http://httpbin.org/') # Issue #1483: Make sure the URL always has a trailing slash HTTPBIN = HTTPBIN.rstrip('/') + '/' @@ -409,7 +417,7 @@ class RequestsTestCase(unittest.TestCase): url = httpbin('post') with open('requirements.txt') as f: pytest.raises(ValueError, "requests.post(url, data='[{\"some\": \"data\"}]', files={'some': f})") - pytest.raises(ValueError, "requests.post(url, data=u'[{\"some\": \"data\"}]', files={'some': f})") + pytest.raises(ValueError, "requests.post(url, data=u('[{\"some\": \"data\"}]'), files={'some': f})") def test_request_ok_set(self): r = requests.get(httpbin('status', '404')) @@ -456,12 +464,12 @@ class RequestsTestCase(unittest.TestCase): def test_unicode_multipart_post(self): r = requests.post(httpbin('post'), - data={'stuff': u'ëlïxr'}, + data={'stuff': u('ëlïxr')}, files={'file': ('test_requests.py', open(__file__, 'rb'))}) assert r.status_code == 200 r = requests.post(httpbin('post'), - data={'stuff': u'ëlïxr'.encode('utf-8')}, + data={'stuff': u('ëlïxr').encode('utf-8')}, files={'file': ('test_requests.py', open(__file__, 'rb'))}) assert r.status_code == 200 @@ -488,7 +496,7 @@ class RequestsTestCase(unittest.TestCase): def test_unicode_method_name(self): files = {'file': open('test_requests.py', 'rb')} - r = requests.request(method=u'POST', url=httpbin('post'), files=files) + r = requests.request(method=u('POST'), url=httpbin('post'), files=files) assert r.status_code == 200 def test_custom_content_type(self): @@ -865,7 +873,7 @@ class RequestsTestCase(unittest.TestCase): assert r.url == url def test_header_keys_are_native(self): - headers = {u'unicode': 'blah', 'byte'.encode('ascii'): 'blah'} + headers = {u('unicode'): 'blah', 'byte'.encode('ascii'): 'blah'} r = requests.Request('GET', httpbin('get'), headers=headers) p = r.prepare()