##// END OF EJS Templates
Fix NameError: name '_rl' is not defined
cgohlke -
Show More
@@ -1,74 +1,74 b''
1 1 # -*- coding: utf-8 -*-
2 2 """ Imports and provides the 'correct' version of readline for the platform.
3 3
4 4 Readline is used throughout IPython as::
5 5
6 6 import IPython.utils.rlineimpl as readline
7 7
8 8 In addition to normal readline stuff, this module provides have_readline
9 9 boolean and _outputfile variable used in IPython.utils.
10 10 """
11 11
12 12 import sys
13 13 import warnings
14 14
15 15 _rlmod_names = ['gnureadline', 'readline']
16 16
17 17 have_readline = False
18 18 for _rlmod_name in _rlmod_names:
19 19 try:
20 20 # import readline as _rl
21 21 _rl = __import__(_rlmod_name)
22 22 # from readline import *
23 23 globals().update({k:v for k,v in _rl.__dict__.items() if not k.startswith('_')})
24 24 except ImportError:
25 25 pass
26 26 else:
27 27 have_readline = True
28 28 break
29 29
30 if sys.platform == 'win32' or sys.platform == 'cli':
30 if have_readline and (sys.platform == 'win32' or sys.platform == 'cli'):
31 31 try:
32 32 _outputfile=_rl.GetOutputFile()
33 33 except AttributeError:
34 34 warnings.warn("Failed GetOutputFile")
35 35 have_readline = False
36 36
37 37 # Test to see if libedit is being used instead of GNU readline.
38 38 # Thanks to Boyd Waters for the original patch.
39 39 uses_libedit = False
40 40
41 41 if have_readline:
42 42 # Official Python docs state that 'libedit' is in the docstring for libedit readline:
43 43 uses_libedit = _rl.__doc__ and 'libedit' in _rl.__doc__
44 44 # Note that many non-System Pythons also do not use proper readline,
45 45 # but do not report libedit at all, nor are they linked dynamically against libedit.
46 46 # known culprits of this include: EPD, Fink
47 47 # There is not much we can do to detect this, until we find a specific failure
48 48 # case, rather than relying on the readline module to self-identify as broken.
49 49
50 50 if uses_libedit and sys.platform == 'darwin':
51 51 _rl.parse_and_bind("bind ^I rl_complete")
52 52 warnings.warn('\n'.join(['', "*"*78,
53 53 "libedit detected - readline will not be well behaved, including but not limited to:",
54 54 " * crashes on tab completion",
55 55 " * incorrect history navigation",
56 56 " * corrupting long-lines",
57 57 " * failure to wrap or indent lines properly",
58 58 "It is highly recommended that you install gnureadline, which is installable with:",
59 59 " pip install gnureadline",
60 60 "*"*78]),
61 61 RuntimeWarning)
62 62
63 63 # the clear_history() function was only introduced in Python 2.4 and is
64 64 # actually optional in the readline API, so we must explicitly check for its
65 65 # existence. Some known platforms actually don't have it. This thread:
66 66 # http://mail.python.org/pipermail/python-dev/2003-August/037845.html
67 67 # has the original discussion.
68 68
69 69 if have_readline:
70 70 try:
71 71 _rl.clear_history
72 72 except AttributeError:
73 73 def clear_history(): pass
74 74 _rl.clear_history = clear_history
General Comments 0
You need to be logged in to leave comments. Login now