Skip to content
Browse files
fix: drop six dependency (#1452)
Fixes #1446 馃
  • Loading branch information
parthea committed Jul 23, 2021
1 parent 777eb76 commit 9f7b4109b370e89c29db6c58c6bd2e09002c8d42
@@ -1,7 +1,5 @@
"""Retain apiclient as an alias for googleapiclient."""

from six import iteritems

import googleapiclient

from googleapiclient import channel
@@ -32,5 +30,5 @@

import sys

for module_name, module in iteritems(_SUBMODULES):
for module_name, module in _SUBMODULES.items():
sys.modules["apiclient.%s" % module_name] = module
@@ -17,10 +17,7 @@
import functools
import inspect
import logging
import warnings

import six
from six.moves import urllib
import urllib

logger = logging.getLogger(__name__)
@@ -135,7 +132,7 @@ def positional_wrapper(*args, **kwargs):

return positional_wrapper

if isinstance(max_positional_args, six.integer_types):
if isinstance(max_positional_args, int):
return positional_decorator
args, _, _, defaults = inspect.getargspec(max_positional_args)
@@ -156,7 +153,7 @@ def parse_unique_urlencoded(content):
urlencoded_params = urllib.parse.parse_qs(content)
params = {}
for key, value in six.iteritems(urlencoded_params):
for key, value in urlencoded_params.items():
if len(value) != 1:
msg = "URL-encoded content contains a repeated value:" "%s -> %s" % (
@@ -76,7 +76,6 @@

from googleapiclient import errors
from googleapiclient import _helpers as util
import six

# The unix time epoch starts at midnight 1970.
@@ -104,7 +103,7 @@

def _upper_header_keys(headers):
new_headers = {}
for k, v in six.iteritems(headers):
for k, v in headers.items():
new_headers[k.upper()] = v
return new_headers

@@ -244,7 +243,7 @@ def update(self, resp):
resp: dict, The response from a watch() method.
for json_name, param_name in six.iteritems(CHANNEL_PARAMS):
for json_name, param_name in CHANNEL_PARAMS.items():
value = resp.get(json_name)
if value is not None:
setattr(self, param_name, value)
@@ -17,31 +17,26 @@
A client library for Google's discovery based APIs.
from __future__ import absolute_import
import six

__author__ = " (Joe Gregorio)"
__all__ = ["build", "build_from_document", "fix_method_name", "key2param"]

from six.moves import http_client
from six.moves.urllib.parse import urljoin

# Standard library imports
import copy
from collections import OrderedDict

from email.generator import BytesGenerator
except ImportError:
from email.generator import Generator as BytesGenerator
from email.generator import BytesGenerator
from email.mime.multipart import MIMEMultipart
from email.mime.nonmultipart import MIMENonMultipart
import http.client as http_client
import io
import json
import keyword
import logging
import mimetypes
import os
import re
import urllib

# Third-party imports
import httplib2
@@ -506,7 +501,7 @@ def build_from_document(

if client_options is None:
client_options = google.api_core.client_options.ClientOptions()
if isinstance(client_options, six.moves.collections_abc.Mapping):
if isinstance(client_options,
client_options = google.api_core.client_options.from_dict(client_options)

if http is not None:
@@ -519,9 +514,9 @@ def build_from_document(
if option is not None:
raise ValueError("Arguments http and {} are mutually exclusive".format(name))

if isinstance(service, six.string_types):
if isinstance(service, str):
service = json.loads(service)
elif isinstance(service, six.binary_type):
elif isinstance(service, bytes):
service = json.loads(service.decode("utf-8"))

if "rootUrl" not in service and isinstance(http, (HttpMock, HttpMockSequence)):
@@ -534,7 +529,7 @@ def build_from_document(
raise InvalidJsonError()

# If an API Endpoint is provided on client options, use that as the base URL
base = urljoin(service["rootUrl"], service["servicePath"])
base = urllib.parse.urljoin(service["rootUrl"], service["servicePath"])
if client_options.api_endpoint:
base = client_options.api_endpoint

@@ -630,7 +625,7 @@ def build_from_document(
if "mtlsRootUrl" in service and (
not client_options or not client_options.api_endpoint
mtls_endpoint = urljoin(service["mtlsRootUrl"], service["servicePath"])
mtls_endpoint = urllib.parse.urljoin(service["mtlsRootUrl"], service["servicePath"])
use_mtls_endpoint = os.getenv(GOOGLE_API_USE_MTLS_ENDPOINT, "auto")

if not use_mtls_endpoint in ("never", "auto", "always"):
@@ -759,7 +754,7 @@ def _fix_up_parameters(method_desc, root_desc, http_method, schema):
parameters = method_desc.setdefault("parameters", {})

# Add in the parameters common to all methods.
for name, description in six.iteritems(root_desc.get("parameters", {})):
for name, description in root_desc.get("parameters", {}).items():
parameters[name] = description

# Add in undocumented query parameters.
@@ -875,7 +870,7 @@ def _urljoin(base, url):
# exception here is the case of media uploads, where url will be an
# absolute url.
if url.startswith("http://") or url.startswith("https://"):
return urljoin(base, url)
return urllib.parse.urljoin(base, url)
new_base = base if base.endswith("/") else base + "/"
new_url = url[1:] if url.startswith("/") else url
return new_base + new_url
@@ -943,7 +938,7 @@ def set_parameters(self, method_desc):
parameters = method_desc.get("parameters", {})
sorted_parameters = OrderedDict(sorted(parameters.items()))
for arg, desc in six.iteritems(sorted_parameters):
for arg, desc in sorted_parameters.items():
param = key2param(arg)
self.argmap[param] = arg

@@ -997,9 +992,9 @@ def createMethod(methodName, methodDesc, rootDesc, schema):
def method(self, **kwargs):
# Don't bother with doc string, it will be over-written by createMethod.

for name in six.iterkeys(kwargs):
for name in kwargs:
if name not in parameters.argmap:
raise TypeError('Got an unexpected keyword argument "%s"' % name)
raise TypeError('Got an unexpected keyword argument {}'.format(name))

# Remove args that have a value of None.
keys = list(kwargs.keys())
@@ -1016,9 +1011,9 @@ def method(self, **kwargs):
raise TypeError('Missing required parameter "%s"' % name)

for name, regex in six.iteritems(parameters.pattern_params):
for name, regex in parameters.pattern_params.items():
if name in kwargs:
if isinstance(kwargs[name], six.string_types):
if isinstance(kwargs[name], str):
pvalues = [kwargs[name]]
pvalues = kwargs[name]
@@ -1029,13 +1024,13 @@ def method(self, **kwargs):
% (name, pvalue, regex)

for name, enums in six.iteritems(parameters.enum_params):
for name, enums in parameters.enum_params.items():
if name in kwargs:
# We need to handle the case of a repeated enum
# name differently, since we want to handle both
# arg='value' and arg=['value1', 'value2']
if name in parameters.repeated_params and not isinstance(
kwargs[name], six.string_types
kwargs[name], str
values = kwargs[name]
@@ -1049,7 +1044,7 @@ def method(self, **kwargs):

actual_query_params = {}
actual_path_params = {}
for key, value in six.iteritems(kwargs):
for key, value in kwargs.items():
to_type = parameters.param_types.get(key, "string")
# For repeated parameters we cast each member of the list.
if key in parameters.repeated_params and type(value) == type([]):
@@ -1086,7 +1081,7 @@ def method(self, **kwargs):

if media_filename:
# Ensure we end up with a valid MediaUpload object.
if isinstance(media_filename, six.string_types):
if isinstance(media_filename, str):
if media_mime_type is None:
"media_mime_type argument not specified: trying to auto-detect for %s",
@@ -1144,7 +1139,7 @@ def method(self, **kwargs):
# encode the body: note that we can't use `as_string`, because
# it plays games with `From ` lines.
fp = six.BytesIO()
fp = io.BytesIO()
g = _BytesGenerator(fp, mangle_from_=False)
g.flatten(msgRoot, unixfrom=False)
body = fp.getvalue()
@@ -1218,7 +1213,7 @@ def method(self, **kwargs):
enumDesc = paramdesc.get("enumDescriptions", [])
if enum and enumDesc:
docs.append(" Allowed values\n")
for (name, desc) in, enumDesc):
for (name, desc) in zip(enum, enumDesc):
docs.append(" %s - %s\n" % (name, desc))
if "response" in methodDesc:
if methodName.endswith("_media"):
@@ -1415,7 +1410,7 @@ def new_batch_http_request(callback=None):

# Add basic methods to Resource
if "methods" in resourceDesc:
for methodName, methodDesc in six.iteritems(resourceDesc["methods"]):
for methodName, methodDesc in resourceDesc["methods"].items():
fixedMethodName, method = createMethod(
methodName, methodDesc, rootDesc, schema
@@ -1463,7 +1458,7 @@ def methodResource(self):

return (methodName, methodResource)

for methodName, methodDesc in six.iteritems(resourceDesc["resources"]):
for methodName, methodDesc in resourceDesc["resources"].items():
fixedMethodName, method = createResourceMethod(methodName, methodDesc)
fixedMethodName, method.__get__(self, self.__class__)
@@ -1475,7 +1470,7 @@ def _add_next_methods(self, resourceDesc, schema):
# type either the method's request (query parameters) or request body.
if "methods" not in resourceDesc:
for methodName, methodDesc in six.iteritems(resourceDesc["methods"]):
for methodName, methodDesc in resourceDesc["methods"].items():
nextPageTokenName = _findPageTokenName(
_methodProperties(methodDesc, schema, "response")

0 comments on commit 9f7b410

Please sign in to comment.