Show More
@@ -1,55 +1,67 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 'import IPython.rlineimpl as readline'. |
|
5 | 5 | |
|
6 | 6 | In addition to normal readline stuff, this module provides have_readline |
|
7 | 7 | boolean and _outputfile variable used in genutils. |
|
8 | 8 | """ |
|
9 | 9 | |
|
10 | 10 | import sys |
|
11 | 11 | |
|
12 | 12 | try: |
|
13 | 13 | from readline import * |
|
14 | 14 | import readline as _rl |
|
15 | 15 | have_readline = True |
|
16 | 16 | except ImportError: |
|
17 | 17 | try: |
|
18 | 18 | from pyreadline import * |
|
19 | 19 | import pyreadline as _rl |
|
20 | 20 | have_readline = True |
|
21 | 21 | except ImportError: |
|
22 | 22 | have_readline = False |
|
23 | 23 | |
|
24 | 24 | if sys.platform == 'win32' and have_readline: |
|
25 | 25 | try: |
|
26 | 26 | _outputfile=_rl.GetOutputFile() |
|
27 | 27 | except AttributeError: |
|
28 | 28 | print "Failed GetOutputFile" |
|
29 | 29 | have_readline = False |
|
30 | 30 | |
|
31 | 31 | # Test to see if libedit is being used instead of GNU readline. |
|
32 | 32 | # Thanks to Boyd Waters for this patch. |
|
33 | 33 | uses_libedit = False |
|
34 | 34 | if sys.platform == 'darwin' and have_readline: |
|
35 | 35 | import commands |
|
36 | # Boyd's patch had a 'while True' here, I'm always a little worried about | |
|
37 | # infinite loops with such code, so for now I'm taking a more conservative | |
|
38 | # approach. See https://bugs.launchpad.net/ipython/+bug/411599. | |
|
39 | for i in range(10): | |
|
40 | try: | |
|
36 | 41 | (status, result) = commands.getstatusoutput( "otool -L %s | grep libedit" % _rl.__file__ ) |
|
42 | break | |
|
43 | except IOError, (errno, strerror): | |
|
44 | if errno == 4: | |
|
45 | continue | |
|
46 | else | |
|
47 | break | |
|
48 | ||
|
37 | 49 | if status == 0 and len(result) > 0: |
|
38 | 50 | # we are bound to libedit - new in Leopard |
|
39 | 51 | _rl.parse_and_bind("bind ^I rl_complete") |
|
40 | 52 | print "Leopard libedit detected." |
|
41 | 53 | uses_libedit = True |
|
42 | 54 | |
|
43 | 55 | |
|
44 | 56 | # the clear_history() function was only introduced in Python 2.4 and is |
|
45 | 57 | # actually optional in the readline API, so we must explicitly check for its |
|
46 | 58 | # existence. Some known platforms actually don't have it. This thread: |
|
47 | 59 | # http://mail.python.org/pipermail/python-dev/2003-August/037845.html |
|
48 | 60 | # has the original discussion. |
|
49 | 61 | |
|
50 | 62 | if have_readline: |
|
51 | 63 | try: |
|
52 | 64 | _rl.clear_history |
|
53 | 65 | except AttributeError: |
|
54 | 66 | def clear_history(): pass |
|
55 | 67 | _rl.clear_history = clear_history |
General Comments 0
You need to be logged in to leave comments.
Login now