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