@@ -206,8 +206,8 @@ def __init__(
206
206
self .client_id = client_id
207
207
else :
208
208
# assign a unique client_id
209
- self .client_id = "cpy{0}{1}" . format (
210
- randint (0 , int (time .monotonic () * 100 ) % 1000 ), randint (0 , 99 )
209
+ self .client_id = (
210
+ f"cpy { randint (0 , int (time .monotonic () * 100 ) % 1000 )} { randint (0 , 99 )} "
211
211
)
212
212
# generated client_id's enforce spec.'s length rules
213
213
if len (self .client_id .encode ("utf-8" )) > 23 or not self .client_id :
@@ -261,13 +261,9 @@ def _get_connect_socket(self, host, port, *, timeout=1):
261
261
)
262
262
263
263
if self .logger is not None and port == MQTT_TLS_PORT :
264
- self .logger .info (
265
- "Establishing a SECURE SSL connection to {0}:{1}" .format (host , port )
266
- )
264
+ self .logger .info (f"Establishing a SECURE SSL connection to { host } :{ port } " )
267
265
elif self .logger is not None :
268
- self .logger .info (
269
- "Establishing an INSECURE connection to {0}:{1}" .format (host , port )
270
- )
266
+ self .logger .info (f"Establishing an INSECURE connection to { host } :{ port } " )
271
267
272
268
addr_info = self ._socket_pool .getaddrinfo (
273
269
host , port , 0 , self ._socket_pool .SOCK_STREAM
@@ -543,7 +539,7 @@ def disconnect(self):
543
539
self ._sock .send (MQTT_DISCONNECT )
544
540
except RuntimeError as e :
545
541
if self .logger is not None :
546
- self .logger .warning ("Unable to send DISCONNECT packet: {}" . format ( e ) )
542
+ self .logger .warning (f "Unable to send DISCONNECT packet: { e } " )
547
543
if self .logger is not None :
548
544
self .logger .debug ("Closing socket" )
549
545
self ._sock .close ()
@@ -598,7 +594,7 @@ def publish(self, topic, msg, retain=False, qos=0):
598
594
else :
599
595
raise MMQTTException ("Invalid message data type." )
600
596
if len (msg ) > MQTT_MSG_MAX_SZ :
601
- raise MMQTTException ("Message size larger than %d bytes." % MQTT_MSG_MAX_SZ )
597
+ raise MMQTTException (f "Message size larger than { MQTT_MSG_MAX_SZ } bytes." )
602
598
assert (
603
599
0 <= qos <= 1
604
600
), "Quality of Service Level 2 is unsupported by this library."
@@ -881,9 +877,7 @@ def _wait_for_msg(self, timeout=0.1):
881
877
self .logger .debug ("Got PINGRESP" )
882
878
sz = self ._sock_exact_recv (1 )[0 ]
883
879
if sz != 0x00 :
884
- raise MMQTTException (
885
- "Unexpected PINGRESP returned from broker: {}." .format (sz )
886
- )
880
+ raise MMQTTException (f"Unexpected PINGRESP returned from broker: { sz } ." )
887
881
return MQTT_PINGRESP
888
882
889
883
if res [0 ] & MQTT_PKT_TYPE_MASK != MQTT_PUBLISH :
0 commit comments