Skip to content

Commit

Permalink
[3.11] pythongh-108590: Revert pythongh-108657 (commit 400a1ce) (pyth…
Browse files Browse the repository at this point in the history
…on#108686)

(cherry picked from commit 2a3926f)

Reverted per Serhiy's request.
  • Loading branch information
erlend-aasland committed Aug 30, 2023
1 parent f8ab975 commit 8888729
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 41 deletions.
27 changes: 2 additions & 25 deletions Lib/sqlite3/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,6 @@
# future enhancements, you should normally quote any identifier that
# is an English language word, even if you do not have to."


from contextlib import contextmanager


def _force_decode(bs, *args, **kwargs):
# gh-108590: Don't fail if the database contains invalid Unicode data.
try:
return bs.decode(*args, **kwargs)
except UnicodeDecodeError:
return "".join([chr(c) for c in bs])


@contextmanager
def _text_factory(con, factory):
saved_factory = con.text_factory
con.text_factory = factory
try:
yield
finally:
con.text_factory = saved_factory


def _iterdump(connection):
"""
Returns an iterator to the dump of the database in an SQL text format.
Expand Down Expand Up @@ -85,9 +63,8 @@ def _iterdump(connection):
table_name_ident,
",".join("""'||quote("{0}")||'""".format(col.replace('"', '""')) for col in column_names))
query_res = cu.execute(q)
with _text_factory(connection, bytes):
for row in query_res:
yield("{0};".format(_force_decode(row[0])))
for row in query_res:
yield("{0};".format(row[0]))

# Now when the type is 'index', 'trigger', or 'view'
q = """
Expand Down
15 changes: 0 additions & 15 deletions Lib/test/test_sqlite3/test_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,6 @@ def test_dump_virtual_tables(self):
actual = list(self.cx.iterdump())
self.assertEqual(expected, actual)

def test_dump_unicode_invalid(self):
# gh-108590
expected = [
"BEGIN TRANSACTION;",
"CREATE TABLE foo (data TEXT);",
"INSERT INTO \"foo\" VALUES('a\x9f');",
"COMMIT;",
]
self.cu.executescript("""
CREATE TABLE foo (data TEXT);
INSERT INTO foo VALUES (CAST(X'619f' AS TEXT));
""")
actual = list(self.cx.iterdump())
self.assertEqual(expected, actual)


if __name__ == "__main__":
unittest.main()

This file was deleted.

0 comments on commit 8888729

Please sign in to comment.