Here's a patch, produced by sixer (you can install it, I maintain it in Sid) using:
sixer -w all googlecloudapis/apitools/base/py/base_api.py As you can see, it contains some of six.moves stuff to make it Py3 compatible. Without it, python3-google-api-tools will not work. Cheers, Thomas Goirand (zigo)
Description: Python 3 support Author: Thomas Goirand <[email protected]> Bug-Debian: https://bugs.debian.org/838638 Forwarded: no Last-Update: 2016-09-23 --- python-googlecloudapis-0.9.30+debian1.orig/googlecloudapis/apitools/base/py/base_api.py +++ python-googlecloudapis-0.9.30+debian1/googlecloudapis/apitools/base/py/base_api.py @@ -1,16 +1,15 @@ """Base class for api services.""" import contextlib -import httplib import logging import pprint import types -import urllib -import urlparse - from protorpc import message_types from protorpc import messages +import six +from six.moves import http_client +from six.moves import urllib from googlecloudapis.apitools.base.py import credentials_lib from googlecloudapis.apitools.base.py import encoding @@ -126,12 +125,12 @@ class _UrlBuilder(object): """Convenient container for url data.""" def __init__(self, base_url, relative_path=None, query_params=None): - components = urlparse.urlsplit(urlparse.urljoin( + components = urllib.parse.urlsplit(urllib.parse.urljoin( base_url, relative_path or '')) if components.fragment: raise exceptions.ConfigurationValueError( 'Unexpected url fragment: %s' % components.fragment) - self.query_params = urlparse.parse_qs(components.query or '') + self.query_params = urllib.parse.parse_qs(components.query or '') if query_params is not None: self.query_params.update(query_params) self.__scheme = components.scheme @@ -140,20 +139,20 @@ class _UrlBuilder(object): @classmethod def FromUrl(cls, url): - urlparts = urlparse.urlsplit(url) - query_params = urlparse.parse_qs(urlparts.query) - base_url = urlparse.urlunsplit(( + urlparts = urllib.parse.urlsplit(url) + query_params = urllib.parse.parse_qs(urlparts.query) + base_url = urllib.parse.urlunsplit(( urlparts.scheme, urlparts.netloc, '', None, None)) relative_path = urlparts.path return cls(base_url, relative_path=relative_path, query_params=query_params) @property def base_url(self): - return urlparse.urlunsplit((self.__scheme, self.__netloc, '', '', '')) + return urllib.parse.urlunsplit((self.__scheme, self.__netloc, '', '', '')) @base_url.setter def base_url(self, value): - components = urlparse.urlsplit(value) + components = urllib.parse.urlsplit(value) if components.path or components.query or components.fragment: raise exceptions.ConfigurationValueError('Invalid base url: %s' % value) self.__scheme = components.scheme @@ -165,14 +164,14 @@ class _UrlBuilder(object): # non-ASCII, we may silently fail to encode correctly. We should # figure out who is responsible for owning the object -> str # conversion. - return urllib.urlencode(self.query_params, doseq=True) + return urllib.parse.urlencode(self.query_params, doseq=True) @property def url(self): if '{' in self.relative_path or '}' in self.relative_path: raise exceptions.ConfigurationValueError( 'Cannot create url with relative path %s' % self.relative_path) - return urlparse.urlunsplit(( + return urllib.parse.urlunsplit(( self.__scheme, self.__netloc, self.relative_path, self.query, '')) @@ -319,7 +318,7 @@ class BaseApiClient(object): @num_retries.setter def num_retries(self, value): - util.Typecheck(value, (int, long)) + util.Typecheck(value, six.integer_types) if value < 0: raise exceptions.InvalidDataError( 'Cannot have negative value for num_retries') @@ -435,10 +434,10 @@ class BaseApiService(object): for field in self.__client.params_type.all_fields()) query_info.update( (param, getattr(request, param, None)) for param in query_params) - query_info = dict((k, v) for k, v in query_info.iteritems() + query_info = dict((k, v) for k, v in six.iteritems(query_info) if v is not None) - for k, v in query_info.iteritems(): - if isinstance(v, unicode): + for k, v in six.iteritems(query_info): + if isinstance(v, six.text_type): query_info[k] = v.encode('utf8') elif isinstance(v, str): query_info[k] = v.decode('utf8') @@ -464,9 +463,9 @@ class BaseApiService(object): def __ProcessHttpResponse(self, method_config, http_response): """Process the given http response.""" - if http_response.status_code not in (httplib.OK, httplib.NO_CONTENT): + if http_response.status_code not in (http_client.OK, http_client.NO_CONTENT): raise exceptions.HttpError.FromResponse(http_response) - if http_response.status_code == httplib.NO_CONTENT: + if http_response.status_code == http_client.NO_CONTENT: # TODO(user): Find out why _replace doesn't seem to work here. http_response = http_wrapper.Response( info=http_response.info, content='{}',
