From bd6b89f76043251c20eeec5a846b262354ada8b2 Mon Sep 17 00:00:00 2001 From: Gilles Dartiguelongue Date: Fri, 26 Dec 2014 16:09:50 +0100 Subject: [PATCH 1/4] Add python 3.4 support --- CHANGES.rst | 2 +- ocs_sdk/apis/api_account.py | 9 ++++++--- ocs_sdk/tests/apis/__init__.py | 8 ++++++-- ocs_sdk/tests/apis/test_api.py | 2 +- ocs_sdk/tests/apis/test_api_metadata.py | 10 ++++++++-- setup.py | 2 ++ 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 26cdf24..12614eb 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,7 @@ ChangeLog 0.3.2 (unreleased) ------------------ -* No entry. +* Add python 3.4 support. 0.3.1 (2014-12-19) ------------------ diff --git a/ocs_sdk/apis/api_account.py b/ocs_sdk/apis/api_account.py index e9712b4..9451f01 100644 --- a/ocs_sdk/apis/api_account.py +++ b/ocs_sdk/apis/api_account.py @@ -9,7 +9,10 @@ # file except in compliance with the License. You may obtain a copy of the # License at http://opensource.org/licenses/BSD-2-Clause -from itertools import izip_longest +try: + from itertools import izip_longest as zip_longest +except ImportError: + from itertools import zip_longest import slumber @@ -63,8 +66,8 @@ def perm_matches(self, request_perm, effective_perm): effective_perm_parts = effective_perm.split(':') for (request_perm_part, - effective_perm_part) in izip_longest(request_perm_parts, - effective_perm_parts): + effective_perm_part) in zip_longest(request_perm_parts, + effective_perm_parts): if ( request_perm_part != effective_perm_part and diff --git a/ocs_sdk/tests/apis/__init__.py b/ocs_sdk/tests/apis/__init__.py index 7e889e5..f9cef93 100644 --- a/ocs_sdk/tests/apis/__init__.py +++ b/ocs_sdk/tests/apis/__init__.py @@ -9,7 +9,11 @@ # License at http://opensource.org/licenses/BSD-2-Clause import json -import urlparse + +try: + from urlparse import urljoin +except ImportError: + from urllib.parse import urljoin import httpretty @@ -31,7 +35,7 @@ def fake_endpoint(self, api, endpoint, method=httpretty.GET, httpretty.register_uri( method, - urlparse.urljoin(api.get_api_url(), endpoint), + urljoin(api.get_api_url(), endpoint), body=body, content_type='application/json', status=status diff --git a/ocs_sdk/tests/apis/test_api.py b/ocs_sdk/tests/apis/test_api.py index 21f3af8..8af1f52 100644 --- a/ocs_sdk/tests/apis/test_api.py +++ b/ocs_sdk/tests/apis/test_api.py @@ -31,7 +31,7 @@ def test_make_requests_session(self): ).make_requests_session() self.assertEqual(requests_session.headers.get('X-Auth-Token'), - '0xdeadbeef') + b'0xdeadbeef') self.assertEqual(requests_session.headers.get('User-Agent'), 'jamesb0nd') diff --git a/ocs_sdk/tests/apis/test_api_metadata.py b/ocs_sdk/tests/apis/test_api_metadata.py index 63eb542..adbca6e 100644 --- a/ocs_sdk/tests/apis/test_api_metadata.py +++ b/ocs_sdk/tests/apis/test_api_metadata.py @@ -9,9 +9,13 @@ import json import unittest -import urlparse import uuid +try: + from urlparse import parse_qs, urlparse +except ImportError: + from urllib.parse import parse_qs, urlparse + from ocs_sdk.apis import MetadataAPI from . import FakeAPITestCase @@ -45,7 +49,7 @@ def fake_route_conf(_, uri, headers): If no format is given, return a text/plain response with a "shell" format. """ - querystring = urlparse.parse_qs(urlparse.urlparse(uri).query) + querystring = parse_qs(urlparse(uri).query) if 'json' in querystring.get('format', []): return 200, headers, json.dumps(json_response) @@ -64,5 +68,7 @@ def test_get(self): self.assertEqual(self.api.get_metadata(), expected_response) shell_response = self.api.get_metadata(as_shell=True) + if not isinstance(shell_response, str): # py3 branch + shell_response = str(shell_response, 'utf-8') self.assertIn('id="%(id)s"' % expected_response, shell_response) self.assertIn('name="%(name)s"' % expected_response, shell_response) diff --git a/setup.py b/setup.py index 5c2028a..98ba718 100644 --- a/setup.py +++ b/setup.py @@ -67,6 +67,8 @@ def get_long_description(): 'Programming Language :: Python', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', 'Topic :: Software Development :: Libraries :: Python Modules', 'Topic :: Internet', 'Topic :: System :: Distributed Computing', From 59e8933c4237745fc032eb0acc1b60e259829090 Mon Sep 17 00:00:00 2001 From: Gilles Dartiguelongue Date: Fri, 26 Dec 2014 16:48:24 +0100 Subject: [PATCH 2/4] Add 3.4 to travis.yml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 257f7dd..5410544 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: python python: - "2.7" + - "3.4" install: - pip install -e . - pip install coveralls From a4a92289fd3d09ef086513b651306b2ba23be133 Mon Sep 17 00:00:00 2001 From: Gilles Dartiguelongue Date: Fri, 26 Dec 2014 16:49:32 +0100 Subject: [PATCH 3/4] Switch try/except to use of six --- ocs_sdk/apis/api_account.py | 6 +----- ocs_sdk/tests/apis/__init__.py | 6 +----- ocs_sdk/tests/apis/test_api_metadata.py | 6 ++---- setup.py | 1 + 4 files changed, 5 insertions(+), 14 deletions(-) diff --git a/ocs_sdk/apis/api_account.py b/ocs_sdk/apis/api_account.py index 9451f01..5c160d2 100644 --- a/ocs_sdk/apis/api_account.py +++ b/ocs_sdk/apis/api_account.py @@ -9,11 +9,7 @@ # file except in compliance with the License. You may obtain a copy of the # License at http://opensource.org/licenses/BSD-2-Clause -try: - from itertools import izip_longest as zip_longest -except ImportError: - from itertools import zip_longest - +from six.moves import zip_longest import slumber from . import API diff --git a/ocs_sdk/tests/apis/__init__.py b/ocs_sdk/tests/apis/__init__.py index f9cef93..51aed8c 100644 --- a/ocs_sdk/tests/apis/__init__.py +++ b/ocs_sdk/tests/apis/__init__.py @@ -10,12 +10,8 @@ import json -try: - from urlparse import urljoin -except ImportError: - from urllib.parse import urljoin - import httpretty +from six.moves.urllib.parse import urljoin class FakeAPITestCase(object): diff --git a/ocs_sdk/tests/apis/test_api_metadata.py b/ocs_sdk/tests/apis/test_api_metadata.py index adbca6e..ee438e1 100644 --- a/ocs_sdk/tests/apis/test_api_metadata.py +++ b/ocs_sdk/tests/apis/test_api_metadata.py @@ -11,10 +11,8 @@ import unittest import uuid -try: - from urlparse import parse_qs, urlparse -except ImportError: - from urllib.parse import parse_qs, urlparse +import six +from six.moves.urllib.parse import parse_qs, urlparse from ocs_sdk.apis import MetadataAPI diff --git a/setup.py b/setup.py index 98ba718..3a66c5c 100644 --- a/setup.py +++ b/setup.py @@ -49,6 +49,7 @@ def get_long_description(): install_requires=[ 'slumber >= 0.6.0', + 'six', ], packages=find_packages(), From 6f45fd3944c309ca93dd43a94772cbe35a1ab6d8 Mon Sep 17 00:00:00 2001 From: Gilles Dartiguelongue Date: Fri, 26 Dec 2014 16:49:52 +0100 Subject: [PATCH 4/4] Depend on a recent enough slumber revision claiming python3 support --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 3a66c5c..88cca4d 100644 --- a/setup.py +++ b/setup.py @@ -48,7 +48,7 @@ def get_long_description(): license='BSD', install_requires=[ - 'slumber >= 0.6.0', + 'slumber >= 0.6.2', 'six', ],