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