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