Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Remove six. #1346

Merged
merged 6 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions google/auth/_cloud_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import os
import subprocess

import six

from google.auth import _helpers
from google.auth import environment_vars
from google.auth import exceptions
Expand Down Expand Up @@ -152,4 +150,4 @@ def get_auth_access_token(account=None):
new_exc = exceptions.UserAccessTokenError(
"Failed to obtain access token", caught_exc
)
six.raise_from(new_exc, caught_exc)
raise new_exc from caught_exc
11 changes: 3 additions & 8 deletions google/auth/_credentials_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@
import abc
import inspect

import six

from google.auth import credentials


@six.add_metaclass(abc.ABCMeta)
class Credentials(credentials.Credentials):
class Credentials(credentials.Credentials, metaclass=abc.ABCMeta):
"""Async inherited credentials class from google.auth.credentials.
The added functionality is the before_request call which requires
async/await syntax.
Expand Down Expand Up @@ -84,8 +81,7 @@ class AnonymousCredentials(credentials.AnonymousCredentials, Credentials):
"""


@six.add_metaclass(abc.ABCMeta)
class ReadOnlyScoped(credentials.ReadOnlyScoped):
class ReadOnlyScoped(credentials.ReadOnlyScoped, metaclass=abc.ABCMeta):
"""Interface for credentials whose scopes can be queried.

OAuth 2.0-based credentials allow limiting access using scopes as described
Expand Down Expand Up @@ -171,6 +167,5 @@ def with_scopes_if_required(credentials, scopes):
return credentials


@six.add_metaclass(abc.ABCMeta)
class Signing(credentials.Signing):
class Signing(credentials.Signing, metaclass=abc.ABCMeta):
"""Interface for credentials that can cryptographically sign messages."""
12 changes: 5 additions & 7 deletions google/auth/_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import os
import warnings

import six

from google.auth import environment_vars
from google.auth import exceptions
import google.auth.transport._http_client
Expand Down Expand Up @@ -124,7 +122,7 @@ def load_credentials_from_file(
new_exc = exceptions.DefaultCredentialsError(
"File {} is not a valid json file.".format(filename), caught_exc
)
six.raise_from(new_exc, caught_exc)
raise new_exc from caught_exc
return _load_credentials_from_info(
filename, info, scopes, default_scopes, quota_project_id, request
)
Expand Down Expand Up @@ -440,7 +438,7 @@ def _get_authorized_user_credentials(filename, info, scopes=None):
except ValueError as caught_exc:
msg = "Failed to load authorized user credentials from {}".format(filename)
new_exc = exceptions.DefaultCredentialsError(msg, caught_exc)
six.raise_from(new_exc, caught_exc)
raise new_exc from caught_exc
return credentials, None


Expand All @@ -454,7 +452,7 @@ def _get_service_account_credentials(filename, info, scopes=None, default_scopes
except ValueError as caught_exc:
msg = "Failed to load service account credentials from {}".format(filename)
new_exc = exceptions.DefaultCredentialsError(msg, caught_exc)
six.raise_from(new_exc, caught_exc)
raise new_exc from caught_exc
return credentials, info.get("project_id")


Expand Down Expand Up @@ -500,7 +498,7 @@ def _get_impersonated_service_account_credentials(filename, info, scopes):
filename
)
new_exc = exceptions.DefaultCredentialsError(msg, caught_exc)
six.raise_from(new_exc, caught_exc)
raise new_exc from caught_exc
return credentials, None


Expand All @@ -514,7 +512,7 @@ def _get_gdch_service_account_credentials(filename, info):
except ValueError as caught_exc:
msg = "Failed to load GDCH service account credentials from {}".format(filename)
new_exc = exceptions.DefaultCredentialsError(msg, caught_exc)
six.raise_from(new_exc, caught_exc)
raise new_exc from caught_exc
return credentials, info.get("project")


Expand Down
8 changes: 3 additions & 5 deletions google/auth/_default_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import json
import os

import six

from google.auth import _default
from google.auth import environment_vars
from google.auth import exceptions
Expand Down Expand Up @@ -63,7 +61,7 @@ def load_credentials_from_file(filename, scopes=None, quota_project_id=None):
new_exc = exceptions.DefaultCredentialsError(
"File {} is not a valid json file.".format(filename), caught_exc
)
six.raise_from(new_exc, caught_exc)
raise new_exc from caught_exc

# The type key should indicate that the file is either a service account
# credentials file or an authorized user credentials file.
Expand All @@ -79,7 +77,7 @@ def load_credentials_from_file(filename, scopes=None, quota_project_id=None):
except ValueError as caught_exc:
msg = "Failed to load authorized user credentials from {}".format(filename)
new_exc = exceptions.DefaultCredentialsError(msg, caught_exc)
six.raise_from(new_exc, caught_exc)
raise new_exc from caught_exc
if quota_project_id:
credentials = credentials.with_quota_project(quota_project_id)
if not credentials.quota_project_id:
Expand All @@ -96,7 +94,7 @@ def load_credentials_from_file(filename, scopes=None, quota_project_id=None):
except ValueError as caught_exc:
msg = "Failed to load service account credentials from {}".format(filename)
new_exc = exceptions.DefaultCredentialsError(msg, caught_exc)
six.raise_from(new_exc, caught_exc)
raise new_exc from caught_exc
return credentials, info.get("project_id")

else:
Expand Down
4 changes: 1 addition & 3 deletions google/auth/_exponential_backoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import random
import time

import six

# The default amount of retry attempts
_DEFAULT_RETRY_TOTAL_ATTEMPTS = 3

Expand All @@ -38,7 +36,7 @@
"""


class ExponentialBackoff(six.Iterator):
class ExponentialBackoff:
"""An exponential backoff iterator. This can be used in a for loop to
perform requests with exponential backoff.

Expand Down
17 changes: 6 additions & 11 deletions google/auth/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
import calendar
import datetime
import sys

import six
from six.moves import urllib
import urllib

from google.auth import exceptions

Expand Down Expand Up @@ -89,9 +87,6 @@ def datetime_to_secs(value):
def to_bytes(value, encoding="utf-8"):
"""Converts a string value to bytes, if necessary.

Unfortunately, ``six.b`` is insufficient for this task since in
Python 2 because it does not modify ``unicode`` objects.

Args:
value (Union[str, bytes]): The value to be converted.
encoding (str): The encoding to use to convert unicode to bytes.
Expand All @@ -104,8 +99,8 @@ def to_bytes(value, encoding="utf-8"):
Raises:
google.auth.exceptions.InvalidValue: If the value could not be converted to bytes.
"""
result = value.encode(encoding) if isinstance(value, six.text_type) else value
if isinstance(result, six.binary_type):
result = value.encode(encoding) if isinstance(value, str) else value
if isinstance(result, bytes):
return result
else:
raise exceptions.InvalidValue(
Expand All @@ -126,8 +121,8 @@ def from_bytes(value):
Raises:
google.auth.exceptions.InvalidValue: If the value could not be converted to unicode.
"""
result = value.decode("utf-8") if isinstance(value, six.binary_type) else value
if isinstance(result, six.text_type):
result = value.decode("utf-8") if isinstance(value, bytes) else value
if isinstance(result, str):
return result
else:
raise exceptions.InvalidValue(
Expand Down Expand Up @@ -171,7 +166,7 @@ def update_query(url, params, remove=None):
query_params.update(params)
# Remove any values specified in remove.
query_params = {
key: value for key, value in six.iteritems(query_params) if key not in remove
key: value for key, value in query_params.items() if key not in remove
}
# Re-encoded the query string.
new_query = urllib.parse.urlencode(query_params, doseq=True)
Expand Down
6 changes: 2 additions & 4 deletions google/auth/_oauth2client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

from __future__ import absolute_import

import six

from google.auth import _helpers
import google.auth.app_engine
import google.auth.compute_engine
Expand All @@ -34,7 +32,7 @@
import oauth2client.contrib.gce # type: ignore
import oauth2client.service_account # type: ignore
except ImportError as caught_exc:
six.raise_from(ImportError("oauth2client is not installed."), caught_exc)
raise ImportError("oauth2client is not installed.") from caught_exc

try:
import oauth2client.contrib.appengine # type: ignore
Expand Down Expand Up @@ -166,4 +164,4 @@ def convert(credentials):
return _CLASS_CONVERSION_MAP[credentials_class](credentials)
except KeyError as caught_exc:
new_exc = ValueError(_CONVERT_ERROR_TMPL.format(credentials_class))
six.raise_from(new_exc, caught_exc)
raise new_exc from caught_exc
4 changes: 1 addition & 3 deletions google/auth/_service_account_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import io
import json

import six

from google.auth import crypt
from google.auth import exceptions

Expand Down Expand Up @@ -46,7 +44,7 @@ def from_dict(data, require=None, use_rsa_signer=True):
"""
keys_needed = set(require if require is not None else [])

missing = keys_needed.difference(six.iterkeys(data))
missing = keys_needed.difference(data.keys())

if missing:
raise exceptions.MalformedError(
Expand Down
7 changes: 3 additions & 4 deletions google/auth/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@

import hashlib
import hmac
import http.client as http_client
import json
import os
import posixpath
import re

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

from google.auth import _helpers
from google.auth import environment_vars
Expand Down
10 changes: 4 additions & 6 deletions google/auth/compute_engine/_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
"""

import datetime
import http.client as http_client
import json
import logging
import os

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

from google.auth import _helpers
from google.auth import environment_vars
Expand Down Expand Up @@ -185,7 +183,7 @@ def get(
google.auth.exceptions.TransportError: if an error occurred while
retrieving metadata.
"""
base_url = urlparse.urljoin(root, path)
base_url = urljoin(root, path)
query_params = {} if params is None else params

headers_to_use = _METADATA_HEADERS.copy()
Expand Down Expand Up @@ -228,7 +226,7 @@ def get(
"Received invalid JSON from the Google Compute Engine "
"metadata service: {:.20}".format(content)
)
six.raise_from(new_exc, caught_exc)
raise new_exc from caught_exc
else:
return content
else:
Expand Down
6 changes: 2 additions & 4 deletions google/auth/compute_engine/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

import datetime

import six

from google.auth import _helpers
from google.auth import credentials
from google.auth import exceptions
Expand Down Expand Up @@ -118,7 +116,7 @@ def refresh(self, request):
)
except exceptions.TransportError as caught_exc:
new_exc = exceptions.RefreshError(caught_exc)
six.raise_from(new_exc, caught_exc)
raise new_exc from caught_exc

@property
def service_account_email(self):
Expand Down Expand Up @@ -386,7 +384,7 @@ def _call_metadata_identity_endpoint(self, request):
)
except exceptions.TransportError as caught_exc:
new_exc = exceptions.RefreshError(caught_exc)
six.raise_from(new_exc, caught_exc)
raise new_exc from caught_exc

_, payload, _, _ = jwt._unverified_decode(id_token)
return id_token, datetime.datetime.utcfromtimestamp(payload["exp"])
Expand Down
11 changes: 3 additions & 8 deletions google/auth/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@
import abc
import os

import six

from google.auth import _helpers, environment_vars
from google.auth import exceptions
from google.auth import metrics


@six.add_metaclass(abc.ABCMeta)
class Credentials(object):
class Credentials(metaclass=abc.ABCMeta):
"""Base class for all credentials.

All credentials have a :attr:`token` that is used for authentication and
Expand Down Expand Up @@ -232,8 +229,7 @@ def before_request(self, request, method, url, headers):
"""Anonymous credentials do nothing to the request."""


@six.add_metaclass(abc.ABCMeta)
class ReadOnlyScoped(object):
class ReadOnlyScoped(metaclass=abc.ABCMeta):
"""Interface for credentials whose scopes can be queried.

OAuth 2.0-based credentials allow limiting access using scopes as described
Expand Down Expand Up @@ -374,8 +370,7 @@ def with_scopes_if_required(credentials, scopes, default_scopes=None):
return credentials


@six.add_metaclass(abc.ABCMeta)
class Signing(object):
class Signing(metaclass=abc.ABCMeta):
"""Interface for credentials that can cryptographically sign messages."""

@abc.abstractmethod
Expand Down
4 changes: 1 addition & 3 deletions google/auth/crypt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
version is at least 1.4.0.
"""

import six

from google.auth.crypt import base
from google.auth.crypt import rsa

Expand Down Expand Up @@ -90,7 +88,7 @@ class to use for verification. This can be used to select different
Returns:
bool: True if the signature is valid, otherwise False.
"""
if isinstance(certs, (six.text_type, six.binary_type)):
if isinstance(certs, (str, bytes)):
certs = [certs]

for cert in certs:
Expand Down
Loading