77"""
88
99import json
10+ from collections .abc import Sequence
1011from functools import partial
11- from typing import Any , Callable , cast , Dict , Optional , Sequence , Union
12+ from typing import Any , Callable , Dict , Optional , Union , cast
1213
1314import aiohttp
1415import aiohttp .http
1516import requests
1617import requests .utils
1718from requests .models import Response
1819
19- from .version import __version__
2020from .errors import (
21- MinFraudError ,
22- HTTPError ,
2321 AuthenticationError ,
22+ HTTPError ,
2423 InsufficientFundsError ,
2524 InvalidRequestError ,
25+ MinFraudError ,
2626 PermissionRequiredError ,
2727)
2828from .models import Factors , Insights , Score
2929from .request import prepare_report , prepare_transaction
30-
30+ from . version import __version__
3131
3232_AIOHTTP_UA = f"minFraud-API/{ __version__ } { aiohttp .http .SERVER_SOFTWARE } "
3333
@@ -85,7 +85,11 @@ def _handle_success(
8585 return model_class (** decoded_body ) # type: ignore
8686
8787 def _exception_for_error (
88- self , status : int , content_type : Optional [str ], raw_body : str , uri : str
88+ self ,
89+ status : int ,
90+ content_type : Optional [str ],
91+ raw_body : str ,
92+ uri : str ,
8993 ) -> Union [
9094 AuthenticationError ,
9195 InsufficientFundsError ,
@@ -94,15 +98,18 @@ def _exception_for_error(
9498 PermissionRequiredError ,
9599 ]:
96100 """Returns the exception for the error responses."""
97-
98101 if 400 <= status < 500 :
99102 return self ._exception_for_4xx_status (status , content_type , raw_body , uri )
100103 if 500 <= status < 600 :
101104 return self ._exception_for_5xx_status (status , raw_body , uri )
102105 return self ._exception_for_unexpected_status (status , raw_body , uri )
103106
104107 def _exception_for_4xx_status (
105- self , status : int , content_type : Optional [str ], raw_body : str , uri : str
108+ self ,
109+ status : int ,
110+ content_type : Optional [str ],
111+ raw_body : str ,
112+ uri : str ,
106113 ) -> Union [
107114 AuthenticationError ,
108115 InsufficientFundsError ,
@@ -113,7 +120,10 @@ def _exception_for_4xx_status(
113120 """Returns exception for error responses with 4xx status codes."""
114121 if not raw_body :
115122 return HTTPError (
116- f"Received a { status } error with no body" , status , uri , raw_body
123+ f"Received a { status } error with no body" ,
124+ status ,
125+ uri ,
126+ raw_body ,
117127 )
118128 if content_type is None or content_type .find ("json" ) == - 1 :
119129 return HTTPError (
@@ -135,7 +145,10 @@ def _exception_for_4xx_status(
135145
136146 if "code" in decoded_body and "error" in decoded_body :
137147 return self ._exception_for_web_service_error (
138- decoded_body .get ("error" ), decoded_body .get ("code" ), status , uri
148+ decoded_body .get ("error" ),
149+ decoded_body .get ("code" ),
150+ status ,
151+ uri ,
139152 )
140153 return HTTPError (
141154 "Error response contains JSON but it does not "
@@ -147,7 +160,10 @@ def _exception_for_4xx_status(
147160
148161 @staticmethod
149162 def _exception_for_web_service_error (
150- message : str , code : str , status : int , uri : str
163+ message : str ,
164+ code : str ,
165+ status : int ,
166+ uri : str ,
151167 ) -> Union [
152168 InvalidRequestError ,
153169 AuthenticationError ,
@@ -354,7 +370,9 @@ async def score(
354370 )
355371
356372 async def report (
357- self , report : Dict [str , Optional [str ]], validate : bool = True
373+ self ,
374+ report : Dict [str , Optional [str ]],
375+ validate : bool = True ,
358376 ) -> None :
359377 """Send a transaction report to the Report Transaction endpoint.
360378
@@ -403,7 +421,9 @@ async def _response_for(
403421 return self ._handle_success (raw_body , uri , model_class )
404422
405423 async def _do_request (
406- self , uri : str , data : Dict [str , Any ]
424+ self ,
425+ uri : str ,
426+ data : Dict [str , Any ],
407427 ) -> aiohttp .ClientResponse :
408428 session = await self ._session ()
409429 return await session .post (uri , json = data , proxy = self ._proxy )
@@ -651,7 +671,10 @@ def _response_for(
651671
652672 def _do_request (self , uri : str , data : Dict [str , Any ]) -> Response :
653673 return self ._session .post (
654- uri , json = data , timeout = self ._timeout , proxies = self ._proxies
674+ uri ,
675+ json = data ,
676+ timeout = self ._timeout ,
677+ proxies = self ._proxies ,
655678 )
656679
657680 def close (self ):
0 commit comments