From 568e38b08a58b756e33bd8126d7bebf3318930e3 Mon Sep 17 00:00:00 2001 From: Peter Saveliev Date: Wed, 31 Jan 2024 17:08:31 +0100 Subject: [PATCH] cli: remove readline import Bug-Url: https://github.com/svinota/pyroute2/issues/1161 --- pyroute2/cli/console.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/pyroute2/cli/console.py b/pyroute2/cli/console.py index d643177db..7c44ff5fd 100644 --- a/pyroute2/cli/console.py +++ b/pyroute2/cli/console.py @@ -6,17 +6,9 @@ from pyroute2.cli.session import Session from pyroute2.ndb.main import NDB -try: - import readline - - HAS_READLINE = True -except ImportError: - HAS_READLINE = False - class Console(code.InteractiveConsole): def __init__(self, stdout=None, log=None, sources=None): - global HAS_READLINE self.db = NDB(log=log, sources=sources) self.db.config.update( {'show_format': 'json', 'recordset_pipe': 'true'} @@ -28,10 +20,6 @@ def __init__(self, stdout=None, log=None, sources=None): self.prompt = '' self.set_prompt() code.InteractiveConsole.__init__(self) - if HAS_READLINE: - readline.parse_and_bind('tab: complete') - readline.set_completer(self.completer) - readline.set_completion_display_matches_hook(self.display) def close(self): self.db.close() @@ -92,6 +80,11 @@ def interact(self, readfunc=None): self.showtraceback() continue + def set_completer(self, readline): + readline.parse_and_bind('tab: complete') + readline.set_completer(self.completer) + readline.set_completion_display_matches_hook(self.display) + def completer(self, text, state): if state == 0: d = [x for x in dir(self.session.ptr) if x.startswith(text)]