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,7 @@ 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 (CR . CR_COMMANDS_OUT_OF_SYNC , "Command Out of Sync" )
445
445
ok = OKPacketWrapper (pkt )
446
446
self .server_status = ok .server_status
447
447
return ok
@@ -654,7 +654,7 @@ def connect(self, sock=None):
654
654
655
655
if isinstance (e , (OSError , IOError , socket .error )):
656
656
exc = err .OperationalError (
657
- 2003 , "Can't connect to MySQL server on %r (%s)" % (self .host , e )
657
+ CR . CR_CONN_HOST_ERROR , "Can't connect to MySQL server on %r (%s)" % (self .host , e )
658
658
)
659
659
# Keep original exception and traceback to investigate error.
660
660
exc .original_exception = e
@@ -945,7 +945,7 @@ def _process_auth(self, plugin_name, auth_packet):
945
945
except AttributeError :
946
946
if plugin_name != b"dialog" :
947
947
raise err .OperationalError (
948
- 2059 ,
948
+ CR . CR_AUTH_PLUGIN_CANNOT_LOAD ,
949
949
"Authentication plugin '%s'"
950
950
" not loaded: - %r missing authenticate method"
951
951
% (plugin_name , type (handler )),
@@ -983,21 +983,21 @@ def _process_auth(self, plugin_name, auth_packet):
983
983
self .write_packet (resp + b"\0 " )
984
984
except AttributeError :
985
985
raise err .OperationalError (
986
- 2059 ,
986
+ CR . CR_AUTH_PLUGIN_CANNOT_LOAD ,
987
987
"Authentication plugin '%s'"
988
988
" not loaded: - %r missing prompt method"
989
989
% (plugin_name , handler ),
990
990
)
991
991
except TypeError :
992
992
raise err .OperationalError (
993
- 2061 ,
993
+ CR . CR_AUTH_PLUGIN_ERR ,
994
994
"Authentication plugin '%s'"
995
995
" %r didn't respond with string. Returned '%r' to prompt %r"
996
996
% (plugin_name , handler , resp , prompt ),
997
997
)
998
998
else :
999
999
raise err .OperationalError (
1000
- 2059 ,
1000
+ CR . CR_AUTH_PLUGIN_CANNOT_LOAD ,
1001
1001
"Authentication plugin '%s' not configured" % (plugin_name ,),
1002
1002
)
1003
1003
pkt = self ._read_packet ()
@@ -1007,7 +1007,7 @@ def _process_auth(self, plugin_name, auth_packet):
1007
1007
return pkt
1008
1008
else :
1009
1009
raise err .OperationalError (
1010
- 2059 , "Authentication plugin '%s' not configured" % plugin_name
1010
+ CR . CR_AUTH_PLUGIN_CANNOT_LOAD , "Authentication plugin '%s' not configured" % plugin_name
1011
1011
)
1012
1012
1013
1013
self .write_packet (data )
@@ -1024,7 +1024,7 @@ def _get_auth_plugin_handler(self, plugin_name):
1024
1024
handler = plugin_class (self )
1025
1025
except TypeError :
1026
1026
raise err .OperationalError (
1027
- 2059 ,
1027
+ CR . CR_AUTH_PLUGIN_CANNOT_LOAD ,
1028
1028
"Authentication plugin '%s'"
1029
1029
" not loaded: - %r cannot be constructed with connection object"
1030
1030
% (plugin_name , plugin_class ),
@@ -1211,7 +1211,7 @@ def _read_load_local_packet(self, first_packet):
1211
1211
if (
1212
1212
not ok_packet .is_ok_packet ()
1213
1213
): # pragma: no cover - upstream induced protocol error
1214
- raise err .OperationalError (2014 , "Commands Out of Sync" )
1214
+ raise err .OperationalError (CR . CR_COMMANDS_OUT_OF_SYNC , "Commands Out of Sync" )
1215
1215
self ._read_ok_packet (ok_packet )
1216
1216
1217
1217
def _check_packet_is_eof (self , packet ):
@@ -1357,7 +1357,7 @@ def send_data(self):
1357
1357
break
1358
1358
conn .write_packet (chunk )
1359
1359
except IOError :
1360
- raise err .OperationalError (1017 , f"Can't find file '{ self .filename } '" )
1360
+ raise err .OperationalError (ER . FILE_NOT_FOUND , f"Can't find file '{ self .filename } '" )
1361
1361
finally :
1362
1362
# send the empty packet to signify we are done sending data
1363
1363
conn .write_packet (b"" )