From 98720891356264fc4c9a4c4ad43152e002bda6f7 Mon Sep 17 00:00:00 2001 From: Naveed Date: Sun, 21 Feb 2016 18:06:04 +0400 Subject: [PATCH 1/2] Python 3 support --- .travis.yml | 5 ++++- chronos/__init__.py | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index c0f69e2..03b06ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,11 @@ env: - CHRONOSVERSION: 2.4.0 language: python -python: 2.7 +python: + - 2.7 + - 3.5 sudo: true +dist: trusty install: - pip install tox script: diff --git a/chronos/__init__.py b/chronos/__init__.py index b8099cc..617bea4 100755 --- a/chronos/__init__.py +++ b/chronos/__init__.py @@ -25,7 +25,12 @@ import httplib2 import json import logging -from urllib import quote + +# Python 3 changed the submodule for quote +try: + from urllib import quote +except ImportError: + from urllib.parse import quote class ChronosAPIError(Exception): @@ -152,9 +157,12 @@ def _check(self, resp, content): if content: try: payload = json.loads(content) - except ValueError: - self.logger.error("Response not valid json: %s" % content) - payload = content + except (TypeError, ValueError): + try: + payload = json.loads(content.decode('utf-8')) + except ValueError: + self.logger.error("Response not valid in json: %s" % content) + payload = content if payload is None and status != 204: raise ChronosAPIError("Request to Chronos API failed: status: %d, response: %s" % (status, content)) From 1fdf3ec3dcdb4b4c39714042c5de3cc73b6b643e Mon Sep 17 00:00:00 2001 From: Naveed ur Rahman Date: Wed, 24 Feb 2016 22:57:32 +0400 Subject: [PATCH 2/2] chronos version fix --- .travis.yml | 2 -- chronos/__init__.py | 11 ++++------- itests/install-chronos.sh | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 03b06ee..dfdedda 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,4 @@ env: - - CHRONOSVERSION: 2.3.4 - CHRONOSVERSION: 2.4.0 language: python @@ -7,7 +6,6 @@ python: - 2.7 - 3.5 sudo: true -dist: trusty install: - pip install tox script: diff --git a/chronos/__init__.py b/chronos/__init__.py index 617bea4..7527643 100755 --- a/chronos/__init__.py +++ b/chronos/__init__.py @@ -156,13 +156,10 @@ def _check(self, resp, content): if content: try: - payload = json.loads(content) - except (TypeError, ValueError): - try: - payload = json.loads(content.decode('utf-8')) - except ValueError: - self.logger.error("Response not valid in json: %s" % content) - payload = content + payload = json.loads(content.decode('utf-8')) + except ValueError: + self.logger.error("Response not valid json: %s" % content) + payload = content if payload is None and status != 204: raise ChronosAPIError("Request to Chronos API failed: status: %d, response: %s" % (status, content)) diff --git a/itests/install-chronos.sh b/itests/install-chronos.sh index 4a35fa5..a70766e 100755 --- a/itests/install-chronos.sh +++ b/itests/install-chronos.sh @@ -3,7 +3,7 @@ set -e # Default version of chronos to test against if not set by the user [[ -f /root/chronos-version ]] && source /root/chronos-version -CHRONOSVERSION="${CHRONOSVERSION:-2.3.4}" +CHRONOSVERSION="${CHRONOSVERSION:-2.4.0}" sudo apt-key adv --keyserver keyserver.ubuntu.com --recv E56151BF DISTRO=$(lsb_release -is | tr '[:upper:]' '[:lower:]')