13
13
from . import _auth
14
14
15
15
from .charset import charset_by_name , charset_by_id
16
- from .constants import CLIENT , COMMAND , CR , FIELD_TYPE , SERVER_STATUS
16
+ from .constants import CLIENT , COMMAND , CR , ER , FIELD_TYPE , SERVER_STATUS
17
17
from . import converters
18
18
from .cursors import Cursor
19
19
from .optionfile import Parser
@@ -441,7 +441,10 @@ def get_autocommit(self):
441
441
def _read_ok_packet (self ):
442
442
pkt = self ._read_packet ()
443
443
if not pkt .is_ok_packet ():
444
- raise err .OperationalError (2014 , "Command Out of Sync" )
444
+ raise err .OperationalError (
445
+ CR .CR_COMMANDS_OUT_OF_SYNC ,
446
+ "Command Out of Sync" ,
447
+ )
445
448
ok = OKPacketWrapper (pkt )
446
449
self .server_status = ok .server_status
447
450
return ok
@@ -654,7 +657,8 @@ def connect(self, sock=None):
654
657
655
658
if isinstance (e , (OSError , IOError , socket .error )):
656
659
exc = err .OperationalError (
657
- 2003 , "Can't connect to MySQL server on %r (%s)" % (self .host , e )
660
+ CR .CR_CONN_HOST_ERROR ,
661
+ "Can't connect to MySQL server on %r (%s)" % (self .host , e ),
658
662
)
659
663
# Keep original exception and traceback to investigate error.
660
664
exc .original_exception = e
@@ -945,7 +949,7 @@ def _process_auth(self, plugin_name, auth_packet):
945
949
except AttributeError :
946
950
if plugin_name != b"dialog" :
947
951
raise err .OperationalError (
948
- 2059 ,
952
+ CR . CR_AUTH_PLUGIN_CANNOT_LOAD ,
949
953
"Authentication plugin '%s'"
950
954
" not loaded: - %r missing authenticate method"
951
955
% (plugin_name , type (handler )),
@@ -983,21 +987,21 @@ def _process_auth(self, plugin_name, auth_packet):
983
987
self .write_packet (resp + b"\0 " )
984
988
except AttributeError :
985
989
raise err .OperationalError (
986
- 2059 ,
990
+ CR . CR_AUTH_PLUGIN_CANNOT_LOAD ,
987
991
"Authentication plugin '%s'"
988
992
" not loaded: - %r missing prompt method"
989
993
% (plugin_name , handler ),
990
994
)
991
995
except TypeError :
992
996
raise err .OperationalError (
993
- 2061 ,
997
+ CR . CR_AUTH_PLUGIN_ERR ,
994
998
"Authentication plugin '%s'"
995
999
" %r didn't respond with string. Returned '%r' to prompt %r"
996
1000
% (plugin_name , handler , resp , prompt ),
997
1001
)
998
1002
else :
999
1003
raise err .OperationalError (
1000
- 2059 ,
1004
+ CR . CR_AUTH_PLUGIN_CANNOT_LOAD ,
1001
1005
"Authentication plugin '%s' not configured" % (plugin_name ,),
1002
1006
)
1003
1007
pkt = self ._read_packet ()
@@ -1007,7 +1011,8 @@ def _process_auth(self, plugin_name, auth_packet):
1007
1011
return pkt
1008
1012
else :
1009
1013
raise err .OperationalError (
1010
- 2059 , "Authentication plugin '%s' not configured" % plugin_name
1014
+ CR .CR_AUTH_PLUGIN_CANNOT_LOAD ,
1015
+ "Authentication plugin '%s' not configured" % plugin_name ,
1011
1016
)
1012
1017
1013
1018
self .write_packet (data )
@@ -1024,7 +1029,7 @@ def _get_auth_plugin_handler(self, plugin_name):
1024
1029
handler = plugin_class (self )
1025
1030
except TypeError :
1026
1031
raise err .OperationalError (
1027
- 2059 ,
1032
+ CR . CR_AUTH_PLUGIN_CANNOT_LOAD ,
1028
1033
"Authentication plugin '%s'"
1029
1034
" not loaded: - %r cannot be constructed with connection object"
1030
1035
% (plugin_name , plugin_class ),
@@ -1211,7 +1216,10 @@ def _read_load_local_packet(self, first_packet):
1211
1216
if (
1212
1217
not ok_packet .is_ok_packet ()
1213
1218
): # pragma: no cover - upstream induced protocol error
1214
- raise err .OperationalError (2014 , "Commands Out of Sync" )
1219
+ raise err .OperationalError (
1220
+ CR .CR_COMMANDS_OUT_OF_SYNC ,
1221
+ "Commands Out of Sync" ,
1222
+ )
1215
1223
self ._read_ok_packet (ok_packet )
1216
1224
1217
1225
def _check_packet_is_eof (self , packet ):
@@ -1357,7 +1365,10 @@ def send_data(self):
1357
1365
break
1358
1366
conn .write_packet (chunk )
1359
1367
except IOError :
1360
- raise err .OperationalError (1017 , f"Can't find file '{ self .filename } '" )
1368
+ raise err .OperationalError (
1369
+ ER .FILE_NOT_FOUND ,
1370
+ f"Can't find file '{ self .filename } '" ,
1371
+ )
1361
1372
finally :
1362
1373
# send the empty packet to signify we are done sending data
1363
1374
conn .write_packet (b"" )
0 commit comments