From 27651eb27066fa602837e060085aed76077ad9bc Mon Sep 17 00:00:00 2001 From: Ivan Vazquez Date: Thu, 19 Feb 2015 13:23:50 -0700 Subject: [PATCH 1/3] Fix python 2->3 string issues. --- gcloud/exceptions.py | 4 ++++ gcloud/storage/connection.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/gcloud/exceptions.py b/gcloud/exceptions.py index 78f641118031..423b6648e29a 100644 --- a/gcloud/exceptions.py +++ b/gcloud/exceptions.py @@ -18,6 +18,7 @@ """ import json +import six _HTTP_CODE_TO_EXCEPTION = {} # populated at end of module @@ -171,6 +172,9 @@ def make_exception(response, content, use_json=True): :rtype: instance of :class:`GCloudError`, or a concrete subclass. :returns: Exception specific to the error response. """ + if six.PY3 and isinstance(content, bytes): + content = content.decode('utf-8') + message = content errors = () diff --git a/gcloud/storage/connection.py b/gcloud/storage/connection.py index fabb1edfb94d..a0779fa9b990 100644 --- a/gcloud/storage/connection.py +++ b/gcloud/storage/connection.py @@ -15,6 +15,7 @@ """Create / interact with gcloud storage connections.""" import json +import six from six.moves.urllib.parse import urlencode # pylint: disable=F0401 @@ -235,6 +236,9 @@ def api_request(self, method, path, query_params=None, if not 200 <= response.status < 300: raise make_exception(response, content) + if six.PY3 and isinstance(content, bytes): + content = content.decode('utf-8') + if content and expect_json: content_type = response.get('content-type', '') if not content_type.startswith('application/json'): From e1284cb8dcb2fb7c3647cfcd2adfd41fa9fad7db Mon Sep 17 00:00:00 2001 From: Ivan Vazquez Date: Thu, 19 Feb 2015 15:46:05 -0700 Subject: [PATCH 2/3] Handle more py3 string issues. --- gcloud/exceptions.py | 2 +- gcloud/storage/connection.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gcloud/exceptions.py b/gcloud/exceptions.py index 423b6648e29a..2452fcc379e5 100644 --- a/gcloud/exceptions.py +++ b/gcloud/exceptions.py @@ -173,7 +173,7 @@ def make_exception(response, content, use_json=True): :returns: Exception specific to the error response. """ if six.PY3 and isinstance(content, bytes): - content = content.decode('utf-8') + content = content.decode('utf-8') # pragma: NO COVER Py3K message = content errors = () diff --git a/gcloud/storage/connection.py b/gcloud/storage/connection.py index a0779fa9b990..0a34d91b1093 100644 --- a/gcloud/storage/connection.py +++ b/gcloud/storage/connection.py @@ -237,7 +237,7 @@ def api_request(self, method, path, query_params=None, raise make_exception(response, content) if six.PY3 and isinstance(content, bytes): - content = content.decode('utf-8') + content = content.decode('utf-8') # pragma: NO COVER Py3K if content and expect_json: content_type = response.get('content-type', '') From 59fff739bf7e02be225d311d27c8c5735587d910 Mon Sep 17 00:00:00 2001 From: Ivan Vazquez Date: Thu, 19 Feb 2015 16:02:08 -0700 Subject: [PATCH 3/3] Fixed lint problems. --- gcloud/exceptions.py | 2 +- gcloud/storage/connection.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gcloud/exceptions.py b/gcloud/exceptions.py index 2452fcc379e5..3f3842c22a19 100644 --- a/gcloud/exceptions.py +++ b/gcloud/exceptions.py @@ -173,7 +173,7 @@ def make_exception(response, content, use_json=True): :returns: Exception specific to the error response. """ if six.PY3 and isinstance(content, bytes): - content = content.decode('utf-8') # pragma: NO COVER Py3K + content = content.decode('utf-8') # pragma: NO COVER Py3K message = content errors = () diff --git a/gcloud/storage/connection.py b/gcloud/storage/connection.py index 0a34d91b1093..58f6369bb884 100644 --- a/gcloud/storage/connection.py +++ b/gcloud/storage/connection.py @@ -237,7 +237,7 @@ def api_request(self, method, path, query_params=None, raise make_exception(response, content) if six.PY3 and isinstance(content, bytes): - content = content.decode('utf-8') # pragma: NO COVER Py3K + content = content.decode('utf-8') # pragma: NO COVER Py3K if content and expect_json: content_type = response.get('content-type', '')