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