11# coding: utf-8
22
3- from __future__ import absolute_import , unicode_literals
4-
53from datetime import datetime , timedelta
64import json
75import random
1210from cryptography .hazmat .primitives import serialization
1311from cryptography .hazmat .primitives .asymmetric .rsa import RSAPrivateKey
1412import jwt
15- from six import binary_type , string_types , raise_from , text_type
1613
1714from ..config import API
1815from ..exception import BoxOAuthException
1916from .oauth2 import OAuth2
2017from ..object .user import User
21- from ..util .compat import NoneType
2218
2319
2420class 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__ )
0 commit comments