@@ -528,7 +528,9 @@ def escape_string(self, s):
528
528
529
529
def _quote_bytes (self , s ):
530
530
if self .server_status & SERVER_STATUS .SERVER_STATUS_NO_BACKSLASH_ESCAPES :
531
- return "'%s'" % (s .replace (b"'" , b"''" ).decode ("ascii" , "surrogateescape" ),)
531
+ return "'{}'" .format (
532
+ s .replace (b"'" , b"''" ).decode ("ascii" , "surrogateescape" )
533
+ )
532
534
return converters .escape_bytes (s )
533
535
534
536
def cursor (self , cursor = None ):
@@ -621,7 +623,7 @@ def connect(self, sock=None):
621
623
(self .host , self .port ), self .connect_timeout , ** kwargs
622
624
)
623
625
break
624
- except ( OSError , IOError ) as e :
626
+ except OSError as e :
625
627
if e .errno == errno .EINTR :
626
628
continue
627
629
raise
@@ -662,7 +664,7 @@ def connect(self, sock=None):
662
664
if isinstance (e , (OSError , IOError )):
663
665
exc = err .OperationalError (
664
666
CR .CR_CONN_HOST_ERROR ,
665
- "Can't connect to MySQL server on %r (%s)" % ( self .host , e ) ,
667
+ f "Can't connect to MySQL server on { self .host !r } ( { e } )" ,
666
668
)
667
669
# Keep original exception and traceback to investigate error.
668
670
exc .original_exception = e
@@ -739,13 +741,13 @@ def _read_bytes(self, num_bytes):
739
741
try :
740
742
data = self ._rfile .read (num_bytes )
741
743
break
742
- except ( IOError , OSError ) as e :
744
+ except OSError as e :
743
745
if e .errno == errno .EINTR :
744
746
continue
745
747
self ._force_close ()
746
748
raise err .OperationalError (
747
749
CR .CR_SERVER_LOST ,
748
- "Lost connection to MySQL server during query (%s)" % ( e ,) ,
<
67E6
tr class="diff-line-row">
750
+ f "Lost connection to MySQL server during query ({ e } )" ,
749
751
)
750
752
except BaseException :
751
753
# Don't convert unknown exception to MySQLError.
@@ -762,10 +764,10 @@ def _write_bytes(self, data):
762
764
self ._sock .settimeout (self ._write_timeout )
763
765
try :
764
766
self ._sock .sendall (data )
765
- except IOError as e :
767
+ except OSError as e :
766
768
self ._force_close ()
767
769
raise err .OperationalError (
768
- CR .CR_SERVER_GONE_ERROR , "MySQL server has gone away (%r)" % ( e ,)
770
+ CR .CR_SERVER_GONE_ERROR , f "MySQL server has gone away ({ e !r } )"
769
771
)
770
772
771
773
def _read_query_result (self , unbuffered = False ):
@@ -1006,7 +1008,7 @@ def _process_auth(self, plugin_name, auth_packet):
1006
1008
else :
1007
1009
raise err .OperationalError (
1008
1010
CR .CR_AUTH_PLUGIN_CANNOT_LOAD ,
1009
- "Authentication plugin '%s ' not configured" % ( plugin_name ,) ,
1011
+ f "Authentication plugin '{ plugin_name } ' not configured" ,
1010
1012
)
1011
1013
pkt = self ._read_packet ()
1012
1014
pkt .check_error ()
@@ -1382,7 +1384,7 @@ def send_data(self):
1382
1384
if not chunk :
1383
1385
break
1384
1386
conn .write_packet (chunk )
1385
- except IOError :
1387
+ except OSError :
1386
1388
raise err .OperationalError (
1387
1389
ER .FILE_NOT_FOUND ,
1388
1390
f"Can't find file '{ self .filename } '" ,
0 commit comments