Skip to content

Commit 39c45f8

Browse files
committed
Simplified the readline lib loading
1 parent fd14639 commit 39c45f8

1 file changed

Lines changed: 8 additions & 17 deletions

File tree

cmd2.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,13 @@ def __subclasshook__(cls, C):
134134
pass
135135

136136

137-
# Tells what implementation of readline we are using
137+
# Check what implementation of readline we are using
138138
class RlType(Enum):
139139
GNU = 1
140140
PYREADLINE = 2
141141
NONE = 3
142142

143143

144-
# Check what implementation of readline we are using
145144
rl_type = RlType.NONE
146145

147146
if 'pyreadline' in sys.modules:
@@ -151,24 +150,16 @@ class RlType(Enum):
151150
# noinspection PyProtectedMember
152151
orig_pyreadline_display = readline.rl.mode._display_completions
153152

154-
else:
155-
readline_lib_path = ''
156-
157-
if 'gnureadline' in sys.modules:
158-
readline_lib_path = sys.modules['gnureadline'].__dict__['__file__']
159-
elif 'readline' in sys.modules:
160-
readline_lib_path = sys.modules['readline'].__dict__['__file__']
153+
elif 'gnureadline' in sys.modules or 'readline' in sys.modules:
154+
rl_type = RlType.GNU
161155

162156
# Load the readline lib so we can make changes to it
163-
if readline_lib_path:
164-
rl_type = RlType.GNU
165-
166-
import ctypes
167-
readline_lib = ctypes.CDLL(readline_lib_path)
157+
import ctypes
158+
readline_lib = ctypes.CDLL(readline.__file__)
168159

169-
# Save address that rl_basic_quote_characters is pointing to since we need to override and restore it
170-
rl_basic_quote_characters = ctypes.c_char_p.in_dll(readline_lib, "rl_basic_quote_characters")
171-
orig_rl_basic_quote_characters_addr = ctypes.cast(rl_basic_quote_characters, ctypes.c_void_p).value
160+
# Save address that rl_basic_quote_characters is pointing to since we need to override and restore it
161+
rl_basic_quote_characters = ctypes.c_char_p.in_dll(readline_lib, "rl_basic_quote_characters")
162+
orig_rl_basic_quote_characters_addr = ctypes.cast(rl_basic_quote_characters, ctypes.c_void_p).value
172163

173164

174165
# BrokenPipeError and FileNotFoundError exist only in Python 3. Use IOError for Python 2.

0 commit comments

Comments
 (0)