2929from .validation import validate_report , validate_transaction
3030
3131
32- _AIOHTTP_UA = "minFraud-API/%s %s" % (
33- __version__ ,
34- aiohttp .http .SERVER_SOFTWARE ,
35- )
32+ _AIOHTTP_UA = f"minFraud-API/{ __version__ } { aiohttp .http .SERVER_SOFTWARE } "
3633
37- _REQUEST_UA = "minFraud-API/%s %s" % (
38- __version__ ,
39- requests .utils .default_user_agent (),
40- )
34+ _REQUEST_UA = f"minFraud-API/{ __version__ } { requests .utils .default_user_agent ()} "
4135
4236
4337# pylint: disable=too-many-instance-attributes, missing-class-docstring
@@ -65,7 +59,7 @@ def __init__( # pylint: disable=too-many-arguments
6559 self ._license_key = license_key
6660 self ._timeout = timeout
6761
68- base_uri = u "https://{0:s }/minfraud/v2.0". format ( host )
62+ base_uri = f "https://{ host } /minfraud/v2.0"
6963 self ._score_uri = "/" .join ([base_uri , "score" ])
7064 self ._insights_uri = "/" .join ([base_uri , "insights" ])
7165 self ._factors_uri = "/" .join ([base_uri , "factors" ])
@@ -77,7 +71,7 @@ def _prepare_report(self, request: Dict[str, Any], validate: bool):
7771 try :
7872 validate_report (cleaned_request )
7973 except MultipleInvalid as ex :
80- raise InvalidRequestError ("Invalid report data: {0}" . format ( ex ) ) from ex
74+ raise InvalidRequestError (f "Invalid report data: { ex } " ) from ex
8175 return cleaned_request
8276
8377 def _prepare_transaction (self , request : Dict [str , Any ], validate : bool ):
@@ -86,9 +80,7 @@ def _prepare_transaction(self, request: Dict[str, Any], validate: bool):
8680 try :
8781 validate_transaction (cleaned_request )
8882 except MultipleInvalid as ex :
89- raise InvalidRequestError (
90- "Invalid transaction data: {0}" .format (ex )
91- ) from ex
83+ raise InvalidRequestError (f"Invalid transaction data: { ex } " ) from ex
9284 return cleaned_request
9385
9486 def _copy_and_clean (self , data : Any ) -> Any :
@@ -112,9 +104,7 @@ def _handle_success(
112104 decoded_body = json .loads (body )
113105 except ValueError as ex :
114106 raise MinFraudError (
115- "Received a 200 response"
116- " but could not decode the response as "
117- "JSON: {0}" .format (body ),
107+ f"Received a 200 response but could not decode the response as JSON: { body } " ,
118108 200 ,
119109 uri ,
120110 ) from ex
@@ -151,11 +141,11 @@ def _exception_for_4xx_status(
151141 """Returns exception for error responses with 4xx status codes."""
152142 if not body :
153143 return HTTPError (
154- "Received a {0 } error with no body" . format ( status ) , status , uri , body
144+ f "Received a { status } error with no body" , status , uri , body
155145 )
156146 if content_type .find ("json" ) == - 1 :
157147 return HTTPError (
158- "Received a {0 } with the following " " body: {1}" . format ( status , body ) ,
148+ f "Received a { status } with the following body: { body } " ,
159149 status ,
160150 uri ,
161151 body ,
@@ -164,10 +154,7 @@ def _exception_for_4xx_status(
164154 decoded_body = json .loads (body )
165155 except ValueError :
166156 return HTTPError (
167- "Received a {status:d} error but it did not include"
168- " the expected JSON body: {content}" .format (
169- status = status , content = body
170- ),
157+ f"Received a { status } error but it did not include the expected JSON body: { body } " ,
171158 status ,
172159 uri ,
173160 body ,
@@ -178,8 +165,7 @@ def _exception_for_4xx_status(
178165 decoded_body .get ("error" ), decoded_body .get ("code" ), status , uri
179166 )
180167 return HTTPError (
181- "Error response contains JSON but it does not specify code"
182- " or error keys: {0}" .format (body ),
168+ f"Error response contains JSON but it does not specify code or error keys: { body } " ,
183169 status ,
184170 uri ,
185171 body ,
@@ -217,7 +203,7 @@ def _exception_for_5xx_status(
217203 ) -> HTTPError :
218204 """Returns exception for error response with 5xx status codes."""
219205 return HTTPError (
220- u "Received a server error ({0 }) for " u"{1}" . format ( status , uri ) ,
206+ f "Received a server error ({ status } ) for { uri } " ,
221207 status ,
222208 uri ,
223209 body ,
@@ -231,7 +217,7 @@ def _exception_for_unexpected_status(
231217 ) -> HTTPError :
232218 """Returns exception for responses with unexpected status codes."""
233219 return HTTPError (
234- u "Received an unexpected HTTP status " u"({0 }) for {1}" . format ( status , uri ) ,
220+ f "Received an unexpected HTTP status ( { status } ) for { uri } " ,
235221 status ,
236222 uri ,
237223 body ,
0 commit comments