8000 Merge branch 'main' of https://github.com/python/cpython · python/cpython@7fc0f86 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7fc0f86

Browse files
committed
Merge branch 'main' of https://github.com/python/cpython
2 parents aa80588 + f49a1df commit 7fc0f86

13 files changed

+393
-352
lines changed

Doc/whatsnew/3.14.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,15 @@ asyncio
728728
reduces memory usage.
729729
(Contributed by Kumar Aditya in :gh:`107803`.)
730730

731+
732+
base64
733+
------
734+
735+
* Improve the performance of :func:`base64.b16decode` by up to ten times,
736+
and reduce the import time of :mod:`base64` by up to six times.
737+
(Contributed by Bénédikt Tran, Chris Markiewicz, and Adam Turner in :gh:`118761`.)
738+
739+
731740
io
732741
---
733742
* :mod:`io` which provides the built-in :func:`open` makes less system calls

Lib/base64.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# Modified 30-Dec-2003 by Barry Warsaw to add full RFC 3548 support
55
# Modified 22-May-2007 by Guido van Rossum to use bytes everywhere
66

7-
import re
87
import struct
98
import binascii
109

@@ -284,7 +283,7 @@ def b16decode(s, casefold=False):
284283
s = _bytes_from_decode_data(s)
285284
if casefold:
286285
s = s.upper()
287-
if re.search(b'[^0-9A-F]', s):
286+
if s.translate(None, delete=b'0123456789ABCDEF'):
288287
raise binascii.Error('Non-base16 digit found')
289288
return binascii.unhexlify(s)
290289

Lib/test/test_sqlite3/test_cli.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,22 @@ def test_interact(self):
9090
out, err = self.run_cli()
9191
self.assertIn(self.MEMORY_DB_MSG, err)
9292
self.assertIn(self.MEMORY_DB_MSG, err)
93-
self.assertTrue(out.endswith(self.PS1))
93+
self.assertEndsWith(out, self.PS1)
9494
self.assertEqual(out.count(self.PS1), 1)
9595
self.assertEqual(out.count(self.PS2), 0)
9696

9797
def test_interact_quit(self):
9898
out, err = self.run_cli(commands=(".quit",))
9999
self.assertIn(self.MEMORY_DB_MSG, err)
100-
self.assertTrue(out.endswith(self.PS1))
100+
self.assertEndsWith(out, self.PS1)
101101
self.assertEqual(out.count(self.PS1), 1)
102102
self.assertEqual(out.count(self.PS2), 0)
103103

104104
def test_interact_version(self):
105105
out, err = self.run_cli(commands=(".version",))
106106
self.assertIn(self.MEMORY_DB_MSG, err)
107107
self.assertIn(sqlite3.sqlite_version + "\n", out)
108-
self.assertTrue(out.endswith(self.PS1))
108+
self.assertEndsWith(out, self.PS1)
109109
self.assertEqual(out.count(self.PS1), 2)
110110
self.assertEqual(out.count(self.PS2), 0)
111111
self.assertIn(sqlite3.sqlite_version, out)
@@ -114,14 +114,14 @@ def test_interact_valid_sql(self):
114114
out, err = self.run_cli(commands=("SELECT 1;",))
115115
self.assertIn(self.MEMORY_DB_MSG, err)
116116
self.assertIn("(1,)\n", out)
117-
self.assertTrue(out.endswith(self.PS1))
117+
self.assertEndsWith(out, self.PS1)
118118
self.assertEqual(out.count(self.PS1), 2)
119119
self.assertEqual(out.count(self.PS2), 0)
120120

121121
def test_interact_incomplete_multiline_sql(self):
122122
out, err = self.run_cli(commands=("SELECT 1",))
123123
self.assertIn(self.MEMORY_DB_MSG, err)
124-
self.assertTrue(out.endswith(self.PS2))
124+
self.assertEndsWith(out, self.PS2)
125125
self.assertEqual(out.count(self.PS1), 1)
126126
self.assertEqual(out.count(self.PS2), 1)
127127

@@ -130,15 +130,15 @@ def test_interact_valid_multiline_sql(self):
130130
self.assertIn(self.MEMORY_DB_MSG, err)
131131
self.assertIn(self.PS2, out)
132132
self.assertIn("(1,)\n", out)
133-
self.assertTrue(out.endswith(self.PS1))
133+
self.assertEndsWith(out, self.PS1)
134134
self.assertEqual(out.count(self.PS1), 2)
135135
self.assertEqual(out.count(self.PS2), 1)
136136

137137
def test_interact_invalid_sql(self):
138138
out, err = self.run_cli(commands=("sel;",))
139139
self.assertIn(self.MEMORY_DB_MSG, err)
140140
self.assertIn("OperationalError (SQLITE_ERROR)", err)
141-
self.assertTrue(out.endswith(self.PS1))
141+
self.assertEndsWith(out, self.PS1)
142142
self.assertEqual(out.count(self.PS1), 2)
143143
self.assertEqual(out.count(self.PS2), 0)
144144

@@ -147,7 +147,7 @@ def test_interact_on_disk_file(self):
147147

148148
out, err = self.run_cli(TESTFN, commands=("CREATE TABLE t(t);",))
149149
self.assertIn(TESTFN, err)
150-
self.assertTrue(out.endswith(self.PS1))
150+
self.assertEndsWith(out, self.PS1)
151151

152152
out, _ = self.run_cli(TESTFN, commands=("SELECT count(t) FROM t;",))
153153
self.assertIn("(0,)\n", out)

Lib/test/test_sqlite3/test_dbapi.py

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,45 +59,34 @@ def test_param_style(self):
5959
sqlite.paramstyle)
6060

6161
def test_warning(self):
62-
self.assertTrue(issubclass(sqlite.Warning, Exception),
63-
"Warning is not a subclass of Exception")
62+
self.assertIsSubclass(sqlite.Warning, Exception)
6463

6564
def test_error(self):
66-
self.assertTrue(issubclass(sqlite.Error, Exception),
67-
"Error is not a subclass of Exception")
65+
self.assertIsSubclass(sqlite.Error, Exception)
6866

6967
def test_interface_error(self):
70-
self.assertTrue(issubclass(sqlite.InterfaceError, sqlite.Error),
71-
"InterfaceError is not a subclass of Error")
68+
self.assertIsSubclass(sqlite.InterfaceError, sqlite.Error)
7269

7370
def test_database_error(self):
74-
self.assertTrue(issubclass(sqlite.DatabaseError, sqlite.Error),
75-
"DatabaseError is not a subclass of Error")
71+
self.assertIsSubclass(sqlite.DatabaseError, sqlite.Error)
7672

7773
def test_data_error(self):
78-
self.assertTrue(issubclass(sqlite.DataError, sqlite.DatabaseError),
79-
"DataError is not a subclass of DatabaseError")
74+
self.assertIsSubclass(sqlite.DataError, sqlite.DatabaseError)
8075

8176
def test_operational_error(self):
82-
self.assertTrue(issubclass(sqlite.OperationalError, sqlite.DatabaseError),
83-
"OperationalError is not a subclass of DatabaseError")
77+
self.assertIsSubclass(sqlite.OperationalError, sqlite.DatabaseError)
8478

8579
def test_integrity_error(self):
86-
self.assertTrue(issubclass(sqlite.IntegrityError, sqlite.DatabaseError),
87-
"IntegrityError is not a subclass of DatabaseError")
80+
self.assertIsSubclass(sqlite.IntegrityError, sqlite.DatabaseError)
8881

8982
def test_internal_error(self):
90-
self.assertTrue(issubclass(sqlite.InternalError, sqlite.DatabaseError),
91-
"InternalError is not a subclass of DatabaseError")
83+
self.assertIsSubclass(sqlite.InternalError, sqlite.DatabaseError)
9284

9385
def test_programming_error(self):
94-
self.assertTrue(issubclass(sqlite.ProgrammingError, sqlite.DatabaseError),
95-
"ProgrammingError is not a subclass of DatabaseError")
86+
self.assertIsSubclass(sqlite.ProgrammingError, sqlite.DatabaseError)
9687

9788
def test_not_supported_error(self):
98-
self.assertTrue(issubclass(sqlite.NotSupportedError,
99-
sqlite.DatabaseError),
100-
"NotSupportedError is not a subclass of DatabaseError")
89+
self.assertIsSubclass(sqlite.NotSupportedError, sqlite.DatabaseError)
10190

10291
def test_module_constants(self):
10392
consts = [
@@ -274,7 +263,7 @@ def test_module_constants(self):
274263
consts.append("SQLITE_IOERR_CORRUPTFS")
275264
for const in consts:
276265
with self.subTest(const=const):
277-
self.assertTrue(hasattr(sqlite, const))
266+
self.assertHasAttr(sqlite, const)
278267

279268
def test_error_code_on_exception(self):
280269
err_msg = "unable to open database file"
@@ -288,7 +277,7 @@ def test_error_code_on_exception(self):
288277
sqlite.connect(db)
289278
e = cm.exception
290279
self.assertEqual(e.sqlite_errorcode, err_code)
291-
self.assertTrue(e.sqlite_errorname.startswith("SQLITE_CANTOPEN"))
280+
self.assertStartsWith(e.sqlite_errorname, "SQLITE_CANTOPEN")
292281

293282
def test_extended_error_code_on_exception(self):
294283
with memory_database() as con:
@@ -425,7 +414,7 @@ def test_connection_exceptions(self):
425414
]
426415
for exc in exceptions:
427416
with self.subTest(exc=exc):
428-
self.assertTrue(hasattr(self.cx, exc))
417+
self.assertHasAttr(self.cx, exc)
429418
self.assertIs(getattr(sqlite, exc), getattr(self.cx, exc))
430419

431420
def test_interrupt_on_closed_db(self):

Lib/test/test_sqlite3/test_factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def test_custom(self):
280280
austria = "Österreich"
281281
row = self.con.execute("select ?", (austria,)).fetchone()
282282
self.assertEqual(type(row[0]), str, "type of row[0] must be unicode")
283-
self.assertTrue(row[0].endswith("reich"), "column must contain original data")
283+
self.assertEndsWith(row[0], "reich", "column must contain original data")
284284

285285

286286
class TextFactoryTestsWithEmbeddedZeroBytes(unittest.TestCase):

0 commit comments

Comments
 (0)
0