@@ -90,7 +90,7 @@ def __init__(self, ishttps,
9090 if (server_context .startswith ("/" )):
9191 self .__serverContext = server_context
9292 else :
93- self .__serverContext = "/" + server_context
93+ self .__serverContext = f"/ { server_context } "
9494 else :
9595 self .__serverContext = ""
9696 self .__tapContext = self .__create_context (tap_context )
@@ -108,9 +108,9 @@ def __init__(self, ishttps,
108108 def __create_context (self , context ):
109109 if (context is not None and context != "" ):
110110 if (str (context ).startswith ("/" )):
111- return self .__serverContext + str ( context )
111+ return f" { self .__serverContext } { context } "
112112 else :
113- return self .__serverContext + "/" + str ( context )
113+ return f" { self .__serverContext } / { context } "
114114 else :
115115 return self .__serverContext
116116
@@ -132,14 +132,14 @@ def __interna_init(self):
132132 self .__currentReason = ""
133133
134134 def __get_tap_context (self , subContext ):
135- return self .__tapContext + "/" + subContext
135+ return f" { self .__tapContext } / { subContext } "
136136
137137 def __get_data_context (self , encodedData = None ):
138138 if self .__dataContext is None :
139139 raise ValueError ("data_context must be specified at TAP object " +
140140 "creation for this action to be performed" )
141141 if encodedData is not None :
142- return self .__dataContext + "?" + str ( encodedData )
142+ return f" { self .__dataContext } ? { encodedData } "
143143 else :
144144 return self .__dataContext
145145
@@ -149,10 +149,10 @@ def __get_datalink_context(self, subContext, encodedData=None):
149149 "object creation for this action to be " +
150150 "performed" )
151151 if encodedData is not None :
152- return self .__datalinkContext + "/" + subContext + "?" + \
153- encodedData
152+ return f" { self .__datalinkContext } / { subContext } ? { encodedData } "
153+
154154 else :
155- return self .__datalinkContext + "/" + subContext
155+ return f" { self .__datalinkContext } / { subContext } "
156156
157157 def __get_upload_context (self ):
158158 if self .__uploadContext is None :
@@ -169,7 +169,7 @@ def __get_table_edit_context(self):
169169 return self .__tableEditContext
170170
171171 def __get_server_context (self , subContext ):
172- return self .__serverContext + "/" + subContext
172+ return f" { self .__serverContext } / { subContext } "
173173
174174 def execute_tapget (self , subcontext , verbose = False ):
175175 """Executes a TAP GET request
@@ -238,8 +238,8 @@ def execute_datalinkget(self, subcontext, query, verbose=False):
238238 def __execute_get (self , context , verbose = False ):
239239 conn = self .__get_connection (verbose )
240240 if verbose :
241- print ("host = " + str ( conn .host ) + ":" + str ( conn .port ) )
242- print ("context = " + context )
241+ print (f "host = { conn .host } : { conn .port } " )
242+ print (f "context = { context } " )
243243 conn .request ("GET" , context , None , self .__getHeaders )
244244 response = conn .getresponse ()
245245 self .__currentReason = response .reason
@@ -396,9 +396,9 @@ def __execute_post(self, context, data,
396396 verbose = False ):
397397 conn = self .__get_connection (verbose )
398398 if verbose :
399- print ("host = " + str ( conn .host ) + ":" + str ( conn .port ) )
400- print ("context = " + context )
401- print ("Content-type = " + str ( content_type ) )
399+ print (f "host = { conn .host } : { conn .port } " )
400+ print (f "context = { context } " )
401+ print (f "Content-type = { content_type } " )
402402 self .__postHeaders ["Content-type" ] = content_type
403403 conn .request ("POST" , context , data , self .__postHeaders )
404404 response = conn .getresponse ()
@@ -614,8 +614,7 @@ def get_host_url(self):
614614 -------
615615 A string composed of: 'host:port/server_context'
616616 """
617- return str (self .__connHost ) + ":" + str (self .__connPort ) \
618- + str (self .__get_tap_context ("" ))
617+ return f'{ self .__connHost } :{ self .__connPort } { self .__get_tap_context ("" )} '
619618
620619 def get_host_url_secure (self ):
621620 """Returns the host+portSsl+serverContext
@@ -624,8 +623,7 @@ def get_host_url_secure(self):
624623 -------
625624 A string composed of: 'host:portSsl/server_context'
626625 """
627- return str (self .__connHost ) + ":" + str (self .__connPortSsl ) \
628- + str (self .__get_tap_context ("" ))
626+ return f'{ self .__connHost } :{ self .__connPortSsl } { self .__get_tap_context ("" )} '
629627
630628 def check_launch_response_status (self , response , debug ,
631629 expected_response_status ,
@@ -654,8 +652,7 @@ def check_launch_response_status(self, response, debug,
654652 isError = False
655653 if response .status != expected_response_status :
656654 if debug :
657- print ("ERROR: " + str (response .status ) + ": " +
658- str (response .reason ))
655+ print (f"ERROR: { response .status } : { response .reason } " )
659656 isError = True
660657 if isError and raise_exception :
661658 errMsg = taputils .get_http_response_error (response )
@@ -687,37 +684,33 @@ def encode_multipart(self, fields, files):
687684 The suitable content-type and the body for the request
688685 """
689686 timeMillis = int (round (time .time () * 1000 ))
690- boundary = '===%s ===' % str ( timeMillis )
687+ boundary = f '==={ timeMillis } ==='
691688 CRLF = '\r \n '
692689 multiparItems = []
693690 for key in fields :
694- multiparItems .append ('--' + boundary + CRLF )
691+ multiparItems .append (f '--{ boundary } { CRLF } ' )
695692 multiparItems .append (
696- 'Content-Disposition: form-data; name="%s"%s' % ( key , CRLF ) )
693+ f 'Content-Disposition: form-data; name="{ key } " { CRLF } ' )
697694 multiparItems .append (CRLF )
698- multiparItems .append (fields [key ]+ CRLF )
695+ multiparItems .append (f' { fields [key ]} { CRLF } ' )
699696 for (key , filename , value ) in files :
700- multiparItems .append ('--' + boundary + CRLF )
697+ multiparItems .append (f '--{ boundary } { CRLF } ' )
701698 multiparItems .append (
702- 'Content-Disposition: form-data; name="%s"; filename="%s"%s' %
703- (key , filename , CRLF ))
699+ f'Content-Disposition: form-data; name="{ key } "; filename="{ filename } "{ CRLF } ' )
704700 multiparItems .append (
705- 'Content-Type: %s%s' %
706- (mimetypes .guess_extension (filename ), CRLF ))
701+ f'Content-Type: { mimetypes .guess_extension (filename )} { CRLF } ' )
707702 multiparItems .append (CRLF )
708703 multiparItems .append (value )
709704 multiparItems .append (CRLF )
710- multiparItems .append ('--' + boundary + '--' + CRLF )
705+ multiparItems .append (f '--{ boundary } -- { CRLF } ' )
711706 multiparItems .append (CRLF )
712707 body = utils .util_create_string_from_buffer (multiparItems )
713- contentType = 'multipart/form-data; boundary=%s' % boundary
708+ contentType = f 'multipart/form-data; boundary={ boundary } '
714709 return contentType , body .encode ('utf-8' )
715710
716711 def __str__ (self ):
717- return "\t Host: " + str (self .__connHost ) + "\n \t Use HTTPS: " \
718- + str (self .__isHttps ) \
719- + "\n \t Port: " + str (self .__connPort ) + "\n \t SSL Port: " \
720- + str (self .__connPortSsl )
712+ return f"\t Host: { self .__connHost } \n \t Use HTTPS: { self .__isHttps } " \
713+ f"\n \t Port: { self .__connPort } \n \t SSL Port: { self .__connPortSsl } "
721714
722715
723716class ConnectionHandler (object ):
0 commit comments