summaryrefslogtreecommitdiffstats
path: root/Lib/code.py
diff options
context:
space:
mode:
authorSteven D'Aprano <steve@pearwood.info>2016-08-23 15:42:15 (GMT)
committerSteven D'Aprano <steve@pearwood.info>2016-08-23 15:42:15 (GMT)
commit6877ed3560aef64391657f634cbe00d16023201a (patch)
tree8509396753039f785fb8e07f9224b78871247357 /Lib/code.py
parentf4d28d43857295cab4dc82a2bc50f5e8c90123ef (diff)
downloadcpython-6877ed3560aef64391657f634cbe00d16023201a.zip
cpython-6877ed3560aef64391657f634cbe00d16023201a.tar.gz
cpython-6877ed3560aef64391657f634cbe00d16023201a.tar.bz2
Issue #27573 make the exit message configurable.
Diffstat (limited to 'Lib/code.py')
-rw-r--r--Lib/code.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/Lib/code.py b/Lib/code.py
index c8b7204..23295f4 100644
--- a/Lib/code.py
+++ b/Lib/code.py
@@ -186,7 +186,7 @@ class InteractiveConsole(InteractiveInterpreter):
"""Reset the input buffer."""
self.buffer = []
- def interact(self, banner=None):
+ def interact(self, banner=None, exitmsg=None):
"""Closely emulate the interactive Python console.
The optional banner argument specifies the banner to print
@@ -196,6 +196,11 @@ class InteractiveConsole(InteractiveInterpreter):
to confuse this with the real interpreter -- since it's so
close!).
+ The optional exitmsg argument specifies the exit message
+ printed when exiting. Pass the empty string to suppress
+ printing an exit message. If exitmsg is not given or None,
+ a default message is printed.
+
"""
try:
sys.ps1
@@ -230,7 +235,10 @@ class InteractiveConsole(InteractiveInterpreter):
self.write("\nKeyboardInterrupt\n")
self.resetbuffer()
more = 0
- self.write('now exiting %s...\n' % self.__class__.__name__)
+ if exitmsg is None:
+ self.write('now exiting %s...\n' % self.__class__.__name__)
+ elif exitmsg != '':
+ self.write('%s\n' % exitmsg)
def push(self, line):
"""Push a line to the interpreter.
@@ -268,7 +276,7 @@ class InteractiveConsole(InteractiveInterpreter):
-def interact(banner=None, readfunc=None, local=None):
+def interact(banner=None, readfunc=None, local=None, exitmsg=None):
"""Closely emulate the interactive Python interpreter.
This is a backwards compatible interface to the InteractiveConsole
@@ -280,6 +288,7 @@ def interact(banner=None, readfunc=None, local=None):
banner -- passed to InteractiveConsole.interact()
readfunc -- if not None, replaces InteractiveConsole.raw_input()
local -- passed to InteractiveInterpreter.__init__()
+ exitmsg -- passed to InteractiveConsole.interact()
"""
console = InteractiveConsole(local)
@@ -290,7 +299,7 @@ def interact(banner=None, readfunc=None, local=None):
import readline
except ImportError:
pass
- console.interact(banner)
+ console.interact(banner, exitmsg)
if __name__ == "__main__":