8000 ruff format · PyMySQL/PyMySQL@99f74aa · GitHub
[go: up one dir, main page]

Skip to content

Commit 99f74aa

Browse files
committed
ruff format
1 parent 2f40db1 commit 99f74aa

17 files changed

+69
-188
lines changed

pymysql/_auth.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ def _init_nacl():
6262

6363
_nacl_bindings = bindings
6464
except ImportError:
65-
raise RuntimeError(
66-
"'pynacl' package is required for ed25519_password auth method"
67-
)
65+
raise RuntimeError("'pynacl' package is required for ed25519_password auth method")
68< 6D40 code>66

6967

7068
def _scalar_clamp(s32):
@@ -222,9 +220,7 @@ def caching_sha2_password_auth(conn, pkt):
222220
# else: fast auth is tried in initial handshake
223221

224222
if not pkt.is_extra_auth_data():
225-
raise OperationalError(
226-
"caching sha2: Unknown packet for fast auth: %s" % pkt._data[:1]
227-
)
223+
raise OperationalError("caching sha2: Unknown packet for fast auth: %s" % pkt._data[:1])
228224

229225
# magic numbers:
230226
# 2 - request public key

pymysql/charset.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ def __init__(self, id, name, collation, is_default=False):
99
self.is_default = is_default
1010

1111
def __repr__(self):
12-
return (
13-
f"Charset(id={self.id}, name={self.name!r}, collation={self.collation!r})"
14-
)
12+
return f"Charset(id={self.id}, name={self.name!r}, collation={self.collation!r})"
1513

1614
@property
1715
def encoding(self):

pymysql/connections.py

+9-28
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,7 @@ def __init__(
222222
password = passwd
223223

224224
if compress or named_pipe:
225-
raise NotImplementedError(
226-
"compress and named_pipe arguments are not supported"
227-
)
225+
raise NotImplementedError("compress and named_pipe arguments are not supported")
228226

229227
self._local_infile = bool(local_infile)
230228
if self._local_infile:
@@ -273,9 +271,7 @@ def _config(key, arg):
273271
ssl = {
274272
"ca": ssl_ca,
275273
"check_hostname": bool(ssl_verify_identity),
276-
"verify_mode": ssl_verify_cert
277-
if ssl_verify_cert is not None
278-
else False,
274+
"verify_mode": ssl_verify_cert if ssl_verify_cert is not None else False,
279275
}
280276
if ssl_cert is not None:
281277
ssl["cert"] = ssl_cert
@@ -531,9 +527,7 @@ def escape_string(self, s):
531527

532528
def _quote_bytes(self, s):
533529
if self.server_status & SERVER_STATUS.SERVER_STATUS_NO_BACKSLASH_ESCAPES:
534-
return "'{}'".format(
535-
s.replace(b"'", b"''").decode("ascii", "surrogateescape")
536-
)
530+
return "'{}'".format(s.replace(b"'", b"''").decode("ascii", "surrogateescape"))
537531
return converters.escape_bytes(s)
538532

539533
def cursor(self, cursor=None):
@@ -886,9 +880,7 @@ def _request_authentication(self):
886880
if isinstance(self.user, str):
887881
self.user = self.user.encode(self.encoding)
888882

889-
data_init = struct.pack(
890-
"<iIB23s", self.client_flag, MAX_PACKET_LEN, charset_id, b""
891-
)
883+
data_init = struct.pack("<iIB23s", self.client_flag, MAX_PACKET_LEN, charset_id, b"")
892884

893885
if self.ssl and self.server_capabilities & CLIENT.SSL:
894886
self.write_packet(data_init)
@@ -961,10 +953,7 @@ def _request_authentication(self):
961953
# https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::AuthSwitchRequest
962954
auth_packet.read_uint8() # 0xfe packet identifier
963955
plugin_name = auth_packet.read_string()
964-
if (
965-
self.server_capabilities & CLIENT.PLUGIN_AUTH
966-
and plugin_name is not None
967-
):
956+
if self.server_capabilities & CLIENT.PLUGIN_AUTH and plugin_name is not None:
968957
auth_packet = self._process_auth(plugin_name, auth_packet)
969958
else:
970959
raise err.OperationalError("received unknown auth switch request")
@@ -1006,10 +995,7 @@ def _process_auth(self, plugin_name, auth_packet):
1006995
elif plugin_name == b"client_ed25519":
1007996
data = _auth.ed25519_password(self.password, auth_packet.read_all())
1008997
elif plugin_name == b"mysql_old_password":
1009-
data = (
1010-
_auth.scramble_old_password(self.password, auth_packet.read_all())
1011-
+ b"\0"
1012-
)
998+
data = _auth.scramble_old_password(self.password, auth_packet.read_all()) + b"\0"
1013999
elif plugin_name == b"mysql_clear_password":
10141000
# https://dev.mysql.com/doc/internals/en/clear-text-authentication.html
10151001
data = self.password + b"\0"
@@ -1032,8 +1018,7 @@ def _process_auth(self, plugin_name, auth_packet):
10321018
raise err.OperationalError(
10331019
CR.CR_AUTH_PLUGIN_CANNOT_LOAD,
10341020
"Authentication plugin '%s'"
1035-
" not loaded: - %r missing prompt method"
1036-
% (plugin_name, handler),
1021+
" not loaded: - %r missing prompt method" % (plugin_name, handler),
10371022
)
10381023
except TypeError:
10391024
raise err.OperationalError(
@@ -1256,9 +1241,7 @@ def _read_load_local_packet(self, first_packet):
12561241
raise
12571242

12581243
ok_packet = self.connection._read_packet()
1259-
if (
1260-
not ok_packet.is_ok_packet()
1261-
): # pragma: no cover - upstream induced protocol error
1244+
if not ok_packet.is_ok_packet(): # pragma: no cover - upstream induced protocol error
12621245
raise err.OperationalError(
12631246
CR.CR_COMMANDS_OUT_OF_SYNC,
12641247
"Commands Out of Sync",
@@ -1413,9 +1396,7 @@ def send_data(self):
14131396

14141397
try:
14151398
with open(self.filename, "rb") as open_file:
1416-
packet_size = min(
1417-
conn.max_allowed_packet, 16 * 1024
1418-
) # 16KB is efficient enough
1399+
packet_size = min(conn.max_allowed_packet, 16 * 1024) # 16KB is efficient enough
14191400
while True:
14201401
chunk = open_file.read(packet_size)
14211402
if not chunk:

pymysql/converters.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ def escape_string(value, mapping=None):
8282

8383

8484
def escape_bytes_prefixed(value, mapping=None):
85-
return "_binary'%s'" % value.decode("ascii", "surrogateescape").translate(
86-
_escape_table
87-
)
85+
return "_binary'%s'" % value.decode("ascii", "surrogateescape").translate(_escape_table)
1241
8886

8987

9088
def escape_bytes(value, mapping=None):

pymysql/cursors.py

+4-12
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,7 @@ def executemany(self, query, args):
191191
self.rowcount = sum(self.execute(query, arg) for arg in args)
192192
return self.rowcount
193193

194-
def _do_execute_many(
195-
self, prefix, values, postfix, args, max_stmt_length, encoding
196-
):
194+
def _do_execute_many(self, prefix, values, postfix, args, max_stmt_length, encoding):
197195
conn = self._get_db()
198196
escape = self._escape_args
199197
if isinstance(prefix, str):
@@ -256,9 +254,7 @@ def callproc(self, procname, args=()):
256254
fmt = f"@_{procname}_%d=%s"
257255
self._query(
258256
"SET %s"
259-
% ",".join(
260-
fmt % (index, conn.escape(arg)) for index, arg in enumerate(args)
261-
)
257+
% ",".join(fmt % (index, conn.escape(arg)) for index, arg in enumerate(args))
262258
)
263259
self.nextset()
264260

@@ -506,18 +502,14 @@ def scroll(self, value, mode="relative"):
506502

507503
if mode == "relative":
508504
if value < 0:
509-
raise err.NotSupportedError(
510-
"Backwards scrolling not supported by this cursor"
511-
)
505+
raise err.NotSupportedError("Backwards scrolling not supported by this cursor")
512506

513507
for _ in range(value):
514508
self.read_next()
515509
self.rownumber += value
516510
elif mode == "absolute":
517511
if value < self.rownumber:
518-
raise err.NotSupportedError(
519-
"Backwards scrolling not supported by this cursor"
520-
)
512+
raise err.NotSupportedError("Backwards scrolling not supported by this cursor")
521513

522514
end = value - self.rownumber
523515
for _ in range(end):

pymysql/protocol.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ def advance(self, length):
8989
new_position = self._position + length
9090
if new_position < 0 or new_position > len(self._data):
9191
raise Exception(
92-
"Invalid advance amount (%s) for cursor. "
93-
"Position=%s" % (length, new_position)
92+
"Invalid advance amount (%s) for cursor. Position=%s" % (length, new_position)
9493
)
9594
self._position = new_position
9695

@@ -322,9 +321,7 @@ class EOFPacketWrapper:
322321

323322
def __init__(self, from_packet):
324323
if not from_packet.is_eof_packet():
325-
raise ValueError(
326-
f"Cannot create '{self.__class__}' object from invalid packet type"
327-
)
324+
raise ValueError(f"Cannot create '{self.__class__}' object from invalid packet type")
328325

329326
self.packet = from_packet
330327
self.warning_count, self.server_status = self.packet.read_struct("<xhh")
@@ -345,9 +342,7 @@ class LoadLocalPacketWrapper:
345342

346343
def __init__(self, from_packet):
347344
if not from_packet.is_load_local_packet():
348-
raise ValueError(
349-
f"Cannot create '{self.__class__}' object from invalid packet type"
350-
)
345+
raise ValueError(f"Cannot create '{self.__class__}' object from invalid packet type")
351346

352347
self.packet = from_packet
353348
self.filename = self.packet.get_all_data()[1:]

pymysql/tests/test_DictCursor.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ def setUp(self):
2323
c.execute("drop table if exists dictcursor")
2424
# include in filterwarnings since for unbuffered dict cursor warning for lack of table
2525
# will only be propagated at start of next execute() call
26-
c.execute(
27-
"""CREATE TABLE dictcursor (name char(20), age int , DOB datetime)"""
28-
)
26+
c.execute("""CREATE TABLE dictcursor (name char(20), age int , DOB datetime)""")
2927
data = [
3028
("bob", 21, "1990-02-06 23:04:56"),
3129
("jim", 56, "1955-05-09 13:12:45"),
@@ -59,15 +57,11 @@ def test_DictCursor(self):
5957
# same again, but via fetchall => tuple)
6058
c.execute("SELECT * from dictcursor where name='bob'")
6159
r = c.fetchall()
62-
self.assertEqual(
63-
[bob], r, "fetch a 1 row result via fetchall failed via DictCursor"
64-
)
60+
self.assertEqual([bob], r, "fetch a 1 row result via fetchall failed via DictCursor")
6561
# same test again but iterate over the
6662
c.execute("SELECT * from dictcursor where name='bob'")
6763
for r in c:
68-
self.assertEqual(
69-
bob, r, "fetch a 1 row result via iteration failed via DictCursor"
70-
)
64+
self.assertEqual(bob, r, "fetch a 1 row result via iteration failed via DictCursor")
7165
# get all 3 row via fetchall
7266
c.execute("SELECT * from dictcursor")
7367
r = c.fetchall()

pymysql/tests/test_SSCursor.py

+4-13
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ def test_SSCursor(self):
2727

2828
# Create table
2929
cursor.execute(
30-
"CREATE TABLE tz_data ("
31-
"region VARCHAR(64),"
32-
"zone VARCHAR(64),"
33-
"name VARCHAR(64))"
30+
"CREATE TABLE tz_data (region VARCHAR(64), zone VARCHAR(64), name VARCHAR(64))"
3431
)
3532

3633
conn.begin()
@@ -57,9 +54,7 @@ def test_SSCursor(self):
5754
)
5855

5956
# Test cursor.rownumber
60-
self.assertEqual(
61-
cursor.rownumber, iter, "cursor.rowcount != %s" % (str(iter))
62-
)
57+
self.assertEqual(cursor.rownumber, iter, "cursor.rowcount != %s" % (str(iter)))
6358

6459
# Test row came out the same as it went in
6560
self.assertEqual((row in data), True, "Row not found in source data")
@@ -141,9 +136,7 @@ def test_execution_time_limit(self):
141136

142137
# this will sleep 0.01 seconds per row
143138
if db_type == "mysql":
144-
sql = (
145-
"SELECT /*+ MAX_EXECUTION_TIME(2000) */ data, sleep(0.01) FROM test"
146-
)
139+
sql = "SELECT /*+ MAX_EXECUTION_TIME(2000) */ data, sleep(0.01) FROM test"
147140
else:
148141
sql = "SET STATEMENT max_statement_time=2 FOR SELECT data, sleep(0.01) FROM test"
149142

@@ -161,9 +154,7 @@ def test_execution_time_limit(self):
161154
)
162155

163156
if db_type == "mysql":
164-
sql = (
165-
"SELECT /*+ MAX_EXECUTION_TIME(2000) */ data, sleep(0.01) FROM test"
166-
)
157+
sql = "SELECT /*+ MAX_EXECUTION_TIME(2000) */ data, sleep(0.01) FROM test"
167158
else:
168159
sql = "SET STATEMENT max_statement_time=2 FOR SELECT data, sleep(0.01) FROM test"
169160
cur.execute(sql)

pymysql/tests/test_basic.py

+8-18
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ def test_datatypes(self):
6060
r = c.fetchone()
6161
self.assertEqual(b"\x01", r[0])
6262
self.assertEqual(v[1:10], r[1:10])
63-
self.assertEqual(
64-
datetime.timedelta(0, 60 * (v[10].hour * 60 + v[10].minute)), r[10]
65-
)
63+
self.assertEqual(datetime.timedelta(0, 60 * (v[10].hour * 60 + v[10].minute)), r[10])
6664
self.assertEqual(datetime.datetime(*v[-1][:6]), r[-1])
6765

6866
c.execute("delete from test_datatypes")
@@ -81,13 +79,9 @@ def test_datatypes(self):
8179

8280
# check sequences type
8381
for seq_type in (tuple, list, set, frozenset):
84-
c.execute(
85-
"insert into test_datatypes (i, l) values (2,4), (6,8), (10,12)"
86-
)
82+
c.execute("insert into test_datatypes (i, l) values (2,4), (6,8), (10,12)")
8783
seq = seq_type([2, 6])
88-
c.execute(
89-
"select l from test_datatypes where i in %s order by i", (seq,)
90-
)
84+
c.execute("select l from test_datatypes where i in %s order by i", (seq,))
9185
r = c.fetchall()
9286
self.assertEqual(((4,), (8,)), r)
9387
c.execute("delete from test_datatypes")
@@ -138,9 +132,7 @@ def test_binary(self):
138132
"""test binary data"""
139133
data = bytes(bytearray(range(255)))
140134
conn = self.connect()
141-
self.safe_create_table(
142-
conn, "test_binary", "create table test_binary (b binary(255))"
143-
)
135+
self.safe_create_table(conn, "test_binary", "create table test_binary (b binary(255))")
144136

145137
with conn.cursor() as c:
146138
c.execute("insert into test_binary (b) values (_binary %s)", (data,))
@@ -287,9 +279,7 @@ def test_single_tuple(self):
287279
"""test a single tuple"""
288280
conn = self.connect()
289281
c = conn.cursor()
290-
self.safe_create_table(
291-
conn, "mystuff", "create table mystuff (id integer primary key)"
292-
)
282+
self.safe_create_table(conn, "mystuff", "create table mystuff (id integer primary key)")
293283
c.execute("insert into mystuff (id) values (1)")
294284
c.execute("insert into mystuff (id) values (2)")
295285
c.execute("select id from mystuff where id in %s", ((1,),))
@@ -364,7 +354,7 @@ def test_bulk_insert(self):
364354

365355
data = [(0, "bob", 21, 123), (1, "jim", 56, 45), (2, "fred", 100, 180)]
366356
cursor.executemany(
367-
"insert into bulkinsert (id, name, age, height) " "values (%s,%s,%s,%s)",
357+
"insert into bulkinsert (id, name, age, height) values (%s,%s,%s,%s)",
368358
data,
369359
)
370360
self.assertEqual(
@@ -414,14 +404,14 @@ def test_bulk_insert_single_record(self):
414404
cursor = conn.cursor()
415405
data = [(0, "bob", 21, 123)]
416406
cursor.executemany(
417-
"insert into bulkinsert (id, name, age, height) " "values (%s,%s,%s,%s)",
407+
"insert into bulkinsert (id, name, age, height) values (%s,%s,%s,%s)",
418408
data,
419409
)
420410
cursor.execute("commit")
421411
self._verify_records(data)
422412

423413
def test_issue_288(self):
424-
"""executemany should work with "insert ... on update" """
414+
"""executemany should work with "insert ... on update"""
425415
conn = self.connect()
426416
cursor = conn.cursor()
427417
data = [(0, "bob", 21, 123), (1, "jim", 56, 45), (2, "fred", 100, 180)]

pymysql/tests/test_charset.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,14 @@ def test_utf8():
55
utf8mb3 = pymysql.charset.charset_by_name("utf8mb3")
66
assert utf8mb3.name == "utf8mb3"
77
assert utf8mb3.collation == "utf8mb3_general_ci"
8-
assert (
9-
repr(utf8mb3)
10-
== "Charset(id=33, name='utf8mb3', collation='utf8mb3_general_ci')"
11-
)
8+
assert repr(utf8mb3) == "Charset(id=33, name='utf8mb3', collation='utf8mb3_general_ci')"
129

1310
# MySQL 8.0 changed the default collation for utf8mb4.
1411
# But we use old default for compatibility.
1512
utf8mb4 = pymysql.charset.charset_by_name("utf8mb4")
1613
assert utf8mb4.name == "utf8mb4"
1714
assert utf8mb4.collation == "utf8mb4_general_ci"
18-
assert (
19-
repr(utf8mb4)
20-
== "Charset(id=45, name='utf8mb4', collation='utf8mb4_general_ci')"
21-
)
15+
assert repr(utf8mb4) == "Charset(id=45, name='utf8mb4', collation='utf8mb4_general_ci')"
2216

2317
# utf8 is alias of utf8mb4 since MySQL 8.0, and PyMySQL v1.1.
2418
utf8 = pymysql.charset.charset_by_name("utf8")

0 commit comments

Comments
 (0)
0