1- from __future__ import absolute_import
2-
31import sys
42import platform
53import base64
64import gzip
75import os
86import socket
97import json
10- from six import BytesIO
11- from six . moves . urllib .parse import parse_qs , urlencode , urlparse
8+ from io import BytesIO
9+ from urllib .parse import parse_qs , urlencode , urlparse
1210
1311from createsend .utils import VerifiedHTTPSConnection , json_to_py , get_faker
1412
@@ -26,7 +24,7 @@ def __str__(self):
2624 # self.data should contain Code, Message and optionally ResultData
2725 extra = ("\n Extra result data: %s" % self .data .ResultData ) if hasattr (
2826 self .data , 'ResultData' ) else ""
29- return "The CreateSend API responded with the following error - %s: %s%s" % ( self .data .Code , self .data .Message , extra )
27+ return f "The CreateSend API responded with the following error - { self .data .Code } : { self .data .Message } { extra } "
3028
3129
3230class ClientError (Exception ):
@@ -59,7 +57,7 @@ class ExpiredOAuthToken(Unauthorized):
5957 pass
6058
6159
62- class CreateSendBase ( object ) :
60+ class CreateSendBase :
6361 auth_details = None
6462 timeout = socket ._GLOBAL_DEFAULT_TIMEOUT # passed to VerifiedHTTPSConnection
6563
@@ -77,7 +75,7 @@ def authorize_url(self, client_id, redirect_uri, scope, state=None):
7775 ]
7876 if state :
7977 params .append (('state' , state ))
80- return "%s?%s" % ( CreateSend .oauth_uri , urlencode (params ))
78+ return f" { CreateSend .oauth_uri } ? { urlencode (params )} "
8179
8280 def exchange_token (self , client_id , client_secret , redirect_uri , code ):
8381 """Exchange a provided OAuth code for an OAuth access token, 'expires in'
@@ -95,7 +93,7 @@ def exchange_token(self, client_id, client_secret, redirect_uri, code):
9593 r = json_to_py (response )
9694 if hasattr (r , 'error' ) and hasattr (r , 'error_description' ):
9795 err = "Error exchanging code for access token: "
98- err += "%s - %s" % ( r .error , r .error_description )
96+ err += f" { r .error } - { r .error_description } "
9997 raise Exception (err )
10098 access_token , expires_in , refresh_token = r .access_token , r .expires_in , r .refresh_token
10199 return [access_token , expires_in , refresh_token ]
@@ -156,7 +154,7 @@ def make_request(self, method, path, params={}, body="", username=None,
156154 overridden (e.g. when using the apikey route with username and password)."""
157155 if username and password :
158156 headers ['Authorization' ] = "Basic %s" % base64 .b64encode (
159- ("%s:%s" % ( username , password ) ).encode ()).decode ()
157+ (f" { username } : { password } " ).encode ()).decode ()
160158 elif self .auth_details :
161159 if 'api_key' in self .auth_details and self .auth_details ['api_key' ]:
162160 headers ['Authorization' ] = "Basic %s" % base64 .b64encode (
@@ -171,7 +169,7 @@ def make_request(self, method, path, params={}, body="", username=None,
171169 if self .fake_web :
172170 # Check that the actual url which would be requested matches
173171 # self.faker.url.
174- actual_url = "https://%s%s" % (parsed_base_uri .netloc ,
172+ actual_url = "https://{}{}" . format (parsed_base_uri .netloc ,
175173 self .build_url (parsed_base_uri , path , params ))
176174 self .faker .actual_url = actual_url
177175
@@ -186,7 +184,7 @@ def same_urls(url_a, url_b):
186184 a .fragment == b .fragment
187185 )
188186 if not same_urls (self .faker .url , actual_url ):
189- raise Exception ("Faker's expected URL (%s ) doesn't match actual URL (%s)" % (
187+ raise Exception ("Faker's expected URL ({} ) doesn't match actual URL ({})" . format (
190188 self .faker .url , actual_url ))
191189
192190 self .faker .actual_body = body
@@ -195,7 +193,7 @@ def same_bodies(body_a, body_b):
195193 return json .loads (body_a ) == json .loads (body_b )
196194 if self .faker .body is not None :
197195 if not same_bodies (self .faker .body , body ):
198- raise Exception ("Faker's expected body (%s ) doesn't match actual body (%s)" % (
196+ raise Exception ("Faker's expected body ({} ) doesn't match actual body ({})" . format (
199197 self .faker .body , body ))
200198
201199 data = self .faker .open () if self .faker else ''
@@ -265,7 +263,7 @@ class CreateSend(CreateSendBase):
265263 user_agent = default_user_agent
266264
267265 def __init__ (self , auth = None ):
268- super (CreateSend , self ).__init__ (auth )
266+ super ().__init__ (auth )
269267
270268 def clients (self ):
271269 """Gets your clients."""
0 commit comments