8000 we have these constants, why not make use of them? · PyMySQL/PyMySQL@030dfaa · GitHub
[go: up one dir, main page]

Skip to content

Commit 030dfaa

Browse files
committed
we have these constants, why not make use of them?
1 parent afbef5e commit 030dfaa

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

pymysql/connections.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from . import _auth
1414

1515
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
1717
from . import converters
1818
from .cursors import Cursor
1919
from .optionfile import Parser
@@ -441,7 +441,7 @@ def get_autocommit(self):
441441
def _read_ok_packet(self):
442442
pkt = self._read_packet()
443443
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")
445445
ok = OKPacketWrapper(pkt)
446446
self.server_status = ok.server_status
447447
return ok
@@ -654,7 +654,7 @@ def connect(self, sock=None):
654654

655655
if isinstance(e, (OSError, IOError, socket.error)):
656656
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)
658658
)
659659
# Keep original exception and traceback to investigate error.
660660
exc.original_exception = e
@@ -945,7 +945,7 @@ def _process_auth(self, plugin_name, auth_packet):
945945
except AttributeError:
946946
if plugin_name != b"dialog":
947947
raise err.OperationalError(
948-
2059,
948+
CR.CR_AUTH_PLUGIN_CANNOT_LOAD,
949949
"Authentication plugin '%s'"
950950
" not loaded: - %r missing authenticate method"
951951
% (plugin_name, type(handler)),
@@ -983,21 +983,21 @@ def _process_auth(self, plugin_name, auth_packet):
983983
self.write_packet(resp + b"\0")
984984
except AttributeError:
985985
raise err.OperationalError(
986-
2059,
986+
CR.CR_AUTH_PLUGIN_CANNOT_LOAD,
987987
"Authentication plugin '%s'"
988988
" not loaded: - %r missing prompt method"
989989
% (plugin_name, handler),
990990
)
991991
except TypeError:
992992
raise err.OperationalError(
993-
2061,
993+
CR.CR_AUTH_PLUGIN_ERR,
994994
"Authentication plugin '%s'"
995995
" %r didn't respond with string. Returned '%r' to prompt %r"
996996
% (plugin_name, handler, resp, prompt),
997997
)
998998
else:
999999
raise err.OperationalError(
1000-
2059,
1000+
CR.CR_AUTH_PLUGIN_CANNOT_LOAD,
10011001
"Authentication plugin '%s' not configured" % (plugin_name,),
10021002
)
10031003
pkt = self._read_packet()
@@ -1007,7 +1007,7 @@ def _process_auth(self, plugin_name, auth_packet):
10071007
return pkt
10081008
else:
10091009
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
10111011
)
10121012

10131013
self.write_packet(data)
@@ -1024,7 +1024,7 @@ def _get_auth_plugin_handler(self, plugin_name):
10241024
handler = plugin_class(self)
10251025
except TypeError:
10261026
raise err.OperationalError(
1027-
2059,
1027+
CR.CR_AUTH_PLUGIN_CANNOT_LOAD,
10281028
"Authentication plugin '%s'"
10291029
" not loaded: - %r cannot be constructed with connection object"
10301030
% (plugin_name, plugin_class),
@@ -1211,7 +1211,7 @@ def _read_load_local_packet(self, first_packet):
12111211
if (
12121212
not ok_packet.is_ok_packet()
12131213
): # 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")
12151215
self._read_ok_packet(ok_packet)
12161216

12171217
def _check_packet_is_eof(self, packet):
@@ -1357,7 +1357,7 @@ def send_data(self):
13571357
break
13581358
conn.write_packet(chunk)
13591359
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}'")
13611361
finally:
13621362
# send the empty packet to signify we are done sending data
13631363
conn.write_packet(b"")

0 commit comments

Comments
 (0)
0