Commit d7cc1bd8 authored by Michael W. Hudson's avatar Michael W. Hudson

Fix

[ 924301 ] A leak case with cmd.py & readline & exception

by ensuring that the readline completion function is always reset
even in the case of an exception being raised.  As a bonus, this
makes the documentation for pre & postloop accurate again.
parent 1f34eb17
......@@ -107,6 +107,15 @@ class Cmd:
"""
self.preloop()
if self.use_rawinput and self.completekey:
try:
import readline
self.old_completer = readline.get_completer()
readline.set_completer(self.complete)
readline.parse_and_bind(self.completekey+": complete")
except ImportError:
pass
try:
if intro is not None:
self.intro = intro
if self.intro:
......@@ -133,6 +142,14 @@ class Cmd:
stop = self.onecmd(line)
stop = self.postcmd(stop, line)
self.postloop()
finally:
if self.use_rawinput and self.completekey:
try:
import readline
readline.set_completer(self.old_completer)
except ImportError:
pass
def precmd(self, line):
"""Hook method executed just before the command line is
......@@ -147,13 +164,6 @@ class Cmd:
def preloop(self):
"""Hook method executed once when the cmdloop() method is called."""
if self.completekey:
try:
import readline
self.old_completer = readline.get_completer()
readline.set_completer(self.complete)
readline.parse_and_bind(self.completekey+": complete")
except ImportError:
pass
def postloop(self):
......@@ -161,11 +171,6 @@ class Cmd:
return.
"""
if self.completekey:
try:
import readline
readline.set_completer(self.old_completer)
except ImportError:
pass
def parseline(self, line):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment