Skip to content

Commit

Permalink
we have these constants, why not make use of them?
Browse files Browse the repository at this point in the history
  • Loading branch information
Nothing4You committed Jan 31, 2022
1 parent afbef5e commit 030dfaa
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions pymysql/connections.py
Expand Up @@ -13,7 +13,7 @@
from . import _auth

from .charset import charset_by_name, charset_by_id
from .constants import CLIENT, COMMAND, CR, FIELD_TYPE, SERVER_STATUS
from .constants import CLIENT, COMMAND, CR, ER, FIELD_TYPE, SERVER_STATUS
from . import converters
from .cursors import Cursor
from .optionfile import Parser
Expand Down Expand Up @@ -441,7 +441,7 @@ def get_autocommit(self):
def _read_ok_packet(self):
pkt = self._read_packet()
if not pkt.is_ok_packet():
raise err.OperationalError(2014, "Command Out of Sync")
raise err.OperationalError(CR.CR_COMMANDS_OUT_OF_SYNC, "Command Out of Sync")
ok = OKPacketWrapper(pkt)
self.server_status = ok.server_status
return ok
Expand Down Expand Up @@ -654,7 +654,7 @@ def connect(self, sock=None):

if isinstance(e, (OSError, IOError, socket.error)):
exc = err.OperationalError(
2003, "Can't connect to MySQL server on %r (%s)" % (self.host, e)
CR.CR_CONN_HOST_ERROR, "Can't connect to MySQL server on %r (%s)" % (self.host, e)
)
# Keep original exception and traceback to investigate error.
exc.original_exception = e
Expand Down Expand Up @@ -945,7 +945,7 @@ def _process_auth(self, plugin_name, auth_packet):
except AttributeError:
if plugin_name != b"dialog":
raise err.OperationalError(
2059,
CR.CR_AUTH_PLUGIN_CANNOT_LOAD,
"Authentication plugin '%s'"
" not loaded: - %r missing authenticate method"
% (plugin_name, type(handler)),
Expand Down Expand Up @@ -983,21 +983,21 @@ def _process_auth(self, plugin_name, auth_packet):
self.write_packet(resp + b"\0")
except AttributeError:
raise err.OperationalError(
2059,
CR.CR_AUTH_PLUGIN_CANNOT_LOAD,
"Authentication plugin '%s'"
" not loaded: - %r missing prompt method"
% (plugin_name, handler),
)
except TypeError:
raise err.OperationalError(
2061,
CR.CR_AUTH_PLUGIN_ERR,
"Authentication plugin '%s'"
" %r didn't respond with string. Returned '%r' to prompt %r"
% (plugin_name, handler, resp, prompt),
)
else:
raise err.OperationalError(
2059,
CR.CR_AUTH_PLUGIN_CANNOT_LOAD,
"Authentication plugin '%s' not configured" % (plugin_name,),
)
pkt = self._read_packet()
Expand All @@ -1007,7 +1007,7 @@ def _process_auth(self, plugin_name, auth_packet):
return pkt
else:
raise err.OperationalError(
2059, "Authentication plugin '%s' not configured" % plugin_name
CR.CR_AUTH_PLUGIN_CANNOT_LOAD, "Authentication plugin '%s' not configured" % plugin_name
)

self.write_packet(data)
Expand All @@ -1024,7 +1024,7 @@ def _get_auth_plugin_handler(self, plugin_name):
handler = plugin_class(self)
except TypeError:
raise err.OperationalError(
2059,
CR.CR_AUTH_PLUGIN_CANNOT_LOAD,
"Authentication plugin '%s'"
" not loaded: - %r cannot be constructed with connection object"
% (plugin_name, plugin_class),
Expand Down Expand Up @@ -1211,7 +1211,7 @@ def _read_load_local_packet(self, first_packet):
if (
not ok_packet.is_ok_packet()
): # pragma: no cover - upstream induced protocol error
raise err.OperationalError(2014, "Commands Out of Sync")
raise err.OperationalError(CR.CR_COMMANDS_OUT_OF_SYNC, "Commands Out of Sync")
self._read_ok_packet(ok_packet)

def _check_packet_is_eof(self, packet):
Expand Down Expand Up @@ -1357,7 +1357,7 @@ def send_data(self):
break
conn.write_packet(chunk)
except IOError:
raise err.OperationalError(1017, f"Can't find file '{self.filename}'")
raise err.OperationalError(ER.FILE_NOT_FOUND, f"Can't find file '{self.filename}'")
finally:
# send the empty packet to signify we are done sending data
conn.write_packet(b"")

0 comments on commit 030dfaa

Please sign in to comment.