Skip to content

Commit 7515b64

Browse files
gh-139105: Correct the EOF key shown on Windows in sqlite3's .help (#139106)
Signed-off-by: Keming <kemingy94@gmail.com> Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent 386d9d0 commit 7515b64

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

‎Lib/sqlite3/__main__.py‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
from ._completer import completer
1616

1717

18+
# IDLE uses CTRL-D for EOF on all platforms (gh-102628).
19+
if sys.platform == "win32" and "idlelib.run" not in sys.modules:
20+
EOF_KEY = "CTRL-Z"
21+
else:
22+
EOF_KEY = "CTRL-D"
23+
24+
1825
def execute(c, sql, suppress_errors=True, theme=theme_no_color):
1926
"""Helper that wraps execution of SQL code.
2027
@@ -70,7 +77,7 @@ def runsource(self, source, filename="<input>", symbol="single"):
7077
print(f"Enter SQL code or one of the below commands, and press enter.\n\n"
7178
f"{t.builtin}.version{t.reset} Print underlying SQLite library version\n"
7279
f"{t.builtin}.help{t.reset} Print this help message\n"
73-
f"{t.builtin}.quit{t.reset} Exit the CLI, equivalent to CTRL-D\n")
80+
f"{t.builtin}.quit{t.reset} Exit the CLI, equivalent to {EOF_KEY}\n")
7481
case "quit":
7582
sys.exit(0)
7683
case "":
@@ -115,16 +122,12 @@ def main(*args):
115122
db_name = repr(args.filename)
116123

117124
# Prepare REPL banner and prompts.
118-
if sys.platform == "win32" and "idlelib.run" not in sys.modules:
119-
eofkey = "CTRL-Z"
120-
else:
121-
eofkey = "CTRL-D"
122125
banner = dedent(f"""
123126
sqlite3 shell, running on SQLite version {sqlite3.sqlite_version}
124127
Connected to {db_name}
125128
126129
Each command will be run using execute() on the cursor.
127-
Type ".help" for more information; type ".quit" or {eofkey} to quit.
130+
Type ".help" for more information; type ".quit" or {EOF_KEY} to quit.
128131
""").strip()
129132

130133
theme = get_theme()

‎Lib/test/test_sqlite3/test_cli.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class InteractiveSession(unittest.TestCase):
8282
MEMORY_DB_MSG = "Connected to a transient in-memory database"
8383
PS1 = "\001\002sqlite> \001\002"
8484
PS2 = "\001\002 ... \001\002"
85+
EOF_KEY = "CTRL-Z" if sys.platform == "win32" else "CTRL-D"
8586

8687
def run_cli(self, *args, commands=()):
8788
with (
@@ -104,11 +105,19 @@ def run_cli(self, *args, commands=()):
104105
def test_interact(self):
105106
out, err = self.run_cli()
106107
self.assertIn(self.MEMORY_DB_MSG, err)
107-
self.assertIn(self.MEMORY_DB_MSG, err)
108+
self.assertIn(f'type ".quit" or {self.EOF_KEY} to quit', err)
108109
self.assertEndsWith(out, self.PS1)
109110
self.assertEqual(out.count(self.PS1), 1)
110111
self.assertEqual(out.count(self.PS2), 0)
111112

113+
def test_interact_help(self):
114+
out, err = self.run_cli(commands=(".help",))
115+
self.assertIn(self.MEMORY_DB_MSG, err)
116+
self.assertIn(f"Exit the CLI, equivalent to {self.EOF_KEY}", out)
117+
self.assertEndsWith(out, self.PS1)
118+
self.assertEqual(out.count(self.PS1), 2)
119+
self.assertEqual(out.count(self.PS2), 0)
120+
112121
def test_interact_quit(self):
113122
out, err = self.run_cli(commands=(".quit",))
114123
self.assertIn(self.MEMORY_DB_MSG, err)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Correct the EOF key shown in the :mod:`sqlite3` CLI ``.help`` text on Windows.

0 commit comments

Comments
 (0)