diff options
author | Georg Brandl <georg@python.org> | 2010-07-30 22:20:16 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2010-07-30 22:20:16 (GMT) |
commit | b90ffd88f1486896a380ee3a2e2ae0dfc8da1d49 (patch) | |
tree | af992a06e0ef9100a0c938f5d29fd3216ba2c1f5 /Lib/pdb.py | |
parent | 635edd199030f2c2f7de4369638c4c9a29226219 (diff) | |
download | cpython-b90ffd88f1486896a380ee3a2e2ae0dfc8da1d49.zip cpython-b90ffd88f1486896a380ee3a2e2ae0dfc8da1d49.tar.gz cpython-b90ffd88f1486896a380ee3a2e2ae0dfc8da1d49.tar.bz2 |
Part of #7245: when KeyboardInterrupt is raised while defining commands, restore the old commands instead of producing a traceback.
Diffstat (limited to 'Lib/pdb.py')
-rwxr-xr-x | Lib/pdb.py | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -371,7 +371,7 @@ class Pdb(bdb.Bdb, cmd.Cmd): else: return self.handle_command_def(line) - def handle_command_def(self,line): + def handle_command_def(self, line): """Handles one command line during command list definition.""" cmd, arg, line = self.parseline(line) if not cmd: @@ -457,14 +457,33 @@ class Pdb(bdb.Bdb, cmd.Cmd): self.error("Usage: commands [bnum]\n ...\n end") return self.commands_bnum = bnum + # Save old definitions for the case of a keyboard interrupt. + if bnum in self.commands: + old_command_defs = (self.commands[bnum], + self.commands_doprompt[bnum], + self.commands_silent[bnum]) + else: + old_command_defs = None self.commands[bnum] = [] self.commands_doprompt[bnum] = True self.commands_silent[bnum] = False + prompt_back = self.prompt self.prompt = '(com) ' self.commands_defining = True try: self.cmdloop() + except KeyboardInterrupt: + # Restore old definitions. + if old_command_defs: + self.commands[bnum] = old_command_defs[0] + self.commands_doprompt[bnum] = old_command_defs[1] + self.commands_silent[bnum] = old_command_defs[2] + else: + del self.commands[bnum] + del self.commands_doprompt[bnum] + del self.commands_silent[bnum] + self.error('command definition aborted, old commands restored') finally: self.commands_defining = False self.prompt = prompt_back |