Skip to content

Commit 9b3397f

Browse files
authored
chore: Remove six library and __future__ imports (#646)
Closes: SDK-1876
1 parent 546d9ec commit 9b3397f

File tree

227 files changed

+87
-737
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+87
-737
lines changed

boxsdk/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# coding: utf-8
22

3-
from __future__ import unicode_literals, absolute_import
4-
53
from .auth import JWTAuth, OAuth2
64
from .client import * # pylint:disable=wildcard-import,redefined-builtin
75
from .exception import * # pylint:disable=wildcard-import

boxsdk/auth/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# coding: utf-8
22

3-
from __future__ import unicode_literals
4-
53
from .cooperatively_managed_oauth2 import CooperativelyManagedOAuth2
64
from .developer_token_auth import DeveloperTokenAuth
75
try:

boxsdk/auth/cooperatively_managed_oauth2.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# coding: utf-8
22

3-
from __future__ import unicode_literals
43
from .oauth2 import OAuth2
54

65

boxsdk/auth/developer_token_auth.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# coding: utf-8
22

3-
from __future__ import unicode_literals, absolute_import
4-
5-
from six.moves import input # pylint:disable=redefined-builtin
6-
73
from .oauth2 import OAuth2
84

95

boxsdk/auth/jwt_auth.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# coding: utf-8
22

3-
from __future__ import absolute_import, unicode_literals
4-
53
from datetime import datetime, timedelta
64
import json
75
import random
@@ -12,13 +10,11 @@
1210
from cryptography.hazmat.primitives import serialization
1311
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey
1412
import jwt
15-
from six import binary_type, string_types, raise_from, text_type
1613

1714
from ..config import API
1815
from ..exception import BoxOAuthException
1916
from .oauth2 import OAuth2
2017
from ..object.user import User
21-
from ..util.compat import NoneType
2218

2319

2420
class JWTAuth(OAuth2):
@@ -254,7 +250,7 @@ def _auth_with_jwt(self, sub, sub_type):
254250
if attempt_number >= API.MAX_RETRY_ATTEMPTS:
255251
raise ex
256252

257-
if (code == 429 or code >= 500):
253+
if code == 429 or code >= 500:
258254
jwt_time = None
259255
elif box_datetime is not None and self._was_exp_claim_rejected_due_to_clock_skew(network_response):
260256
jwt_time = box_datetime
@@ -365,8 +361,8 @@ def _normalize_user_id(cls, user):
365361
return None
366362
if isinstance(user, User):
367363
return user.object_id
368-
if isinstance(user, string_types):
369-
return text_type(user)
364+
if isinstance(user, str):
365+
return str(user)
370366
raise TypeError("Got unsupported type {0!r} for user.".format(user.__class__.__name__))
371367

372368
def authenticate_instance(self, enterprise=None):
@@ -423,15 +419,15 @@ def _normalize_rsa_private_key(cls, file_sys_path, data, passphrase=None):
423419
data = key_file.read()
424420
if hasattr(data, 'read') and callable(data.read):
425421
data = data.read()
426-
if isinstance(data, text_type):
422+
if isinstance(data, str):
427423
try:
428424
data = data.encode('ascii')
429-
except UnicodeError:
430-
raise_from(
431-
TypeError("rsa_private_key_data must contain binary data (bytes/str), not a text/unicode string"),
432-
None,
433-
)
434-
if isinstance(data, binary_type):
425+
except UnicodeError as unicode_error:
426+
raise TypeError(
427+
"rsa_private_key_data must contain binary data (bytes/str), not a text/unicode string"
428+
) from unicode_error
429+
430+
if isinstance(data, bytes):
435431
passphrase = cls._normalize_rsa_private_key_passphrase(passphrase)
436432
return serialization.load_pem_private_key(
437433
data,
@@ -450,15 +446,15 @@ def _normalize_rsa_private_key(cls, file_sys_path, data, passphrase=None):
450446

451447
@staticmethod
452448
def _normalize_rsa_private_key_passphrase(passphrase):
453-
if isinstance(passphrase, text_type):
449+
if isinstance(passphrase, str):
454450
try:
455451
return passphrase.encode('ascii')
456-
except UnicodeError:
457-
raise_from(
458-
TypeError("rsa_private_key_passphrase must contain binary data (bytes/str), not a text/unicode string"),
459-
None,
460-
)
461-
if not isinstance(passphrase, (binary_type, NoneType)):
452+
except UnicodeError as unicode_error:
453+
raise TypeError(
454+
"rsa_private_key_passphrase must contain binary data (bytes/str), not a text/unicode string"
455+
) from unicode_error
456+
457+
if not isinstance(passphrase, (bytes, type(None))):
462458
raise TypeError(
463459
"rsa_private_key_passphrase must contain binary data (bytes/str), got {0!r}"
464460
.format(passphrase.__class__.__name__)

boxsdk/auth/oauth2.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
# coding: utf-8
22

3-
from __future__ import unicode_literals
4-
53
from contextlib import contextmanager
64
from logging import getLogger
75
import random
86
import string # pylint:disable=deprecated-module
9-
import sys
107
from threading import Lock
11-
12-
# pylint:disable=import-error,no-name-in-module
13-
from six.moves.urllib.parse import urlencode, urlunsplit
14-
# pylint:enable=import-error,no-name-in-module
15-
import six
8+
from urllib.parse import urlunsplit, urlencode
169

1710
from ..config import API
1811
from ..exception import BoxOAuthException, BoxAPIException
@@ -489,19 +482,19 @@ def closing(self, **close_kwargs):
489482
# pylint:disable=broad-except
490483
try:
491484
yield self
492-
except Exception:
493-
exc_infos.append(sys.exc_info())
494-
except BaseException:
495-
exc_infos.append(sys.exc_info())
485+
except Exception as exception:
486+
exc_infos.append(exception)
487+
except BaseException as base_exception:
488+
exc_infos.append(base_exception)
496489
close_kwargs['revoke'] = False
497490

498491
try:
499492
self.close(**close_kwargs)
500-
except Exception:
501-
exc_infos.append(sys.exc_info())
493+
except Exception as exception:
494+
exc_infos.append(exception)
502495

503496
if exc_infos:
504-
six.reraise(*exc_infos[0])
497+
raise exc_infos[0]
505498

506499
def _check_closed(self):
507500
if self.closed:

boxsdk/auth/redis_managed_jwt_auth.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# coding: utf-8
22

3-
from __future__ import unicode_literals, absolute_import
4-
53
from .jwt_auth import JWTAuth
64
from .redis_managed_oauth2 import RedisManagedOAuth2Mixin
75

boxsdk/auth/redis_managed_oauth2.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# coding: utf-8
22

3-
from __future__ import unicode_literals
4-
53
from uuid import uuid4
64

75
from redis import StrictRedis

boxsdk/auth/remote_managed_oauth2.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# coding: utf-8
22

3-
from __future__ import unicode_literals
43
from .oauth2 import OAuth2
54

65

boxsdk/client/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# coding: utf-8
22

3-
from __future__ import unicode_literals, absolute_import
4-
53
from .client import Client
64
from .developer_token_client import DeveloperTokenClient
75
from .development_client import DevelopmentClient

0 commit comments

Comments
 (0)