2727from requests .structures import CaseInsensitiveDict
2828from ibm_cloud_sdk_core .authenticators import Authenticator
2929from .version import __version__
30- from .utils import (
31- has_bad_first_or_last_char ,
32- remove_null_values ,
33- cleanup_values ,
34- read_external_sources ,
35- strip_extra_slashes
36- )
30+ from .utils import (has_bad_first_or_last_char , remove_null_values ,
31+ cleanup_values , read_external_sources , strip_extra_slashes )
3732from .detailed_response import DetailedResponse
3833from .api_exception import ApiException
3934from .token_manager import TokenManager
4237# import http.client as http_client
4338# http_client.HTTPConnection.debuglevel = 1
4439
40+
4541#pylint: disable=too-many-instance-attributes
4642#pylint: disable=too-many-locals
4743class BaseService :
@@ -95,8 +91,7 @@ def __init__(self,
9591 if not self .authenticator :
9692 raise ValueError ('authenticator must be provided' )
9793 if not isinstance (self .authenticator , Authenticator ):
98- raise ValueError (
99- 'authenticator should be of type Authenticator' )
94+ raise ValueError ('authenticator should be of type Authenticator' )
10095
10196 @staticmethod
10297 def _get_system_info () -> str :
@@ -131,11 +126,10 @@ def configure_service(self, service_name: str) -> None:
131126 if config .get ('URL' ):
132127 self .set_service_url (config .get ('URL' ))
133128 if config .get ('DISABLE_SSL' ):
134- self .set_disable_ssl_verification (
135- bool (config .get ('DISABLE_SSL' ))
136- )
129+ self .set_disable_ssl_verification (bool (config .get ('DISABLE_SSL' )))
137130 if config .get ('ENABLE_GZIP' ) is not None :
138- self .set_enable_gzip_compression (config .get ('ENABLE_GZIP' ) == 'True' )
131+ self .set_enable_gzip_compression (
132+ config .get ('ENABLE_GZIP' ) == 'True' )
139133
140134 def _set_user_agent_header (self , user_agent_string : str ) -> None :
141135 self .user_agent_header = {'User-Agent' : user_agent_string }
@@ -153,8 +147,10 @@ def set_http_config(self, http_config: dict) -> None:
153147 """
154148 if isinstance (http_config , dict ):
155149 self .http_config = http_config
156- if (self .authenticator and hasattr (self .authenticator , 'token_manager' ) and
157- isinstance (self .authenticator .token_manager , TokenManager )):
150+ if (self .authenticator
151+ and hasattr (self .authenticator , 'token_manager' )
152+ and isinstance (self .authenticator .token_manager ,
153+ TokenManager )):
158154 self .authenticator .token_manager .http_config = http_config
159155 else :
160156 raise TypeError ("http_config parameter must be a dictionary" )
@@ -201,7 +197,8 @@ def set_http_client(self, http_client: requests.sessions.Session) -> None:
201197 if isinstance (http_client , requests .sessions .Session ):
202198 self .http_client = http_client
203199 else :
204- raise TypeError ("http_client parameter must be a requests.sessions.Session" )
200+ raise TypeError (
201+ "http_client parameter must be a requests.sessions.Session" )
205202
206203 def get_authenticator (self ) -> Authenticator :
207204 """Get the authenticator currently used by the service.
@@ -246,7 +243,9 @@ def send(self, request: requests.Request, **kwargs) -> DetailedResponse:
246243 stream_response = kwargs .get ('stream' ) or False
247244
248245 try :
249- response = self .http_client .request (** request , cookies = self .jar , ** kwargs )
246+ response = self .http_client .request (** request ,
247+ cookies = self .jar ,
248+ ** kwargs )
250249
251250 if 200 <= response .status_code <= 299 :
252251 if response .status_code == 204 or request ['method' ] == 'HEAD' :
@@ -261,22 +260,18 @@ def send(self, request: requests.Request, **kwargs) -> DetailedResponse:
261260 result = response .json ()
262261 except :
263262 result = response
264- return DetailedResponse (response = result , headers = response .headers ,
263+ return DetailedResponse (response = result ,
264+ headers = response .headers ,
265265 status_code = response .status_code )
266266
267- raise ApiException (
268- response .status_code , http_response = response )
267+ raise ApiException (response .status_code , http_response = response )
269268 except requests .exceptions .SSLError :
270269 logging .exception (self .ERROR_MSG_DISABLE_SSL )
271270 raise
272- except ApiException as err :
273- logging .exception (err .message )
274- raise
275- except :
276- logging .exception ('Error in service call' )
277- raise
278271
279- def set_enable_gzip_compression (self , should_enable_compression : bool = False ) -> None :
272+ def set_enable_gzip_compression (self ,
273+ should_enable_compression : bool = False
274+ ) -> None :
280275 """Set value to enable gzip compression on request bodies"""
281276 self .enable_gzip_compression = should_enable_compression
282277
@@ -291,10 +286,10 @@ def prepare_request(self,
291286 headers : Optional [dict ] = None ,
292287 params : Optional [dict ] = None ,
293288 data : Optional [Union [str , dict ]] = None ,
294- files : Optional [Union [
295- Dict [ str , Tuple [str ]] ,
296- List [ Tuple [ str , Tuple [str , ...]]]
297- ]] = None ,
289+ files : Optional [Union [Dict [ str , Tuple [ str ]],
290+ List [ Tuple [str ,
291+ Tuple [str ,
292+ ...]]] ]] = None ,
298293 ** kwargs ) -> dict :
299294 """Build a dict that represents an HTTP service request.
300295
@@ -349,9 +344,9 @@ def prepare_request(self,
349344 self .authenticator .authenticate (request )
350345
351346 # Compress the request body if applicable
352- if (self .get_enable_gzip_compression () and
353- 'content-encoding' not in headers and
354- request ['data' ] is not None ):
347+ if (self .get_enable_gzip_compression ()
348+ and 'content-encoding' not in headers
349+ and request ['data' ] is not None ):
355350 headers ['content-encoding' ] = 'gzip'
356351 uncompressed_data = request ['data' ]
357352 request_body = gzip .compress (uncompressed_data )
@@ -371,7 +366,8 @@ def prepare_request(self,
371366 files = files .items ()
372367 # Next, fill in any missing filenames from file tuples.
373368 for part_name , file_tuple in files :
374- if file_tuple and len (file_tuple ) == 3 and file_tuple [0 ] is None :
369+ if file_tuple and len (
370+ file_tuple ) == 3 and file_tuple [0 ] is None :
375371 file = file_tuple [1 ]
376372 if file and hasattr (file , 'name' ):
377373 filename = basename (file .name )
0 commit comments