diff --git a/IPython/rlineimpl.py b/IPython/rlineimpl.py index 8f6beb5..12b793a 100644 --- a/IPython/rlineimpl.py +++ b/IPython/rlineimpl.py @@ -1,54 +1,40 @@ # -*- coding: utf-8 -*- -""" Imports and provides the "correct" version of readline for the platform. +""" Imports and provides the 'correct' version of readline for the platform. -Readline is used throughout IPython as "import IPython.rlineimpl as readline. +Readline is used throughout IPython as 'import IPython.rlineimpl as readline'. -In addition to normal readline stuff, this module provides have_readline boolean -and _outputfile variable used in genutils. +In addition to normal readline stuff, this module provides have_readline +boolean and _outputfile variable used in genutils. $Id: Magic.py 1096 2006-01-28 20:08:02Z vivainio $""" - import sys -have_readline = False +try: + from readline import * + import readline as _rl + have_readline = True +except ImportError: + have_readline = False -if sys.platform == 'win32': +if sys.platform == 'win32' and have_readline: try: - import pyreadline.rlmain - #add config for inputrcpath here: - #pyreadline.rlmain.config_path="c:/python/test_config.ini" - from readline import * - #print "Using the new pyreadline (thanks for participating in the testing!)" - - have_readline = True - - import readline as _rl - except ImportError: - #print "IPython team recommends the new pyreadline for Windows use, " - #print "It's superior especially with non-US keyboard layouts." - #print "Try installing it with 'easy_install pyreadline (ctypes is required) or" - #print "svn co http://ipython.scipy.org/svn/ipython/pyreadline/trunk pyreadline" - #print "Trying 'old' windows readline." - #print "Using 'old' readline, you might want to try pyreadline:" - #print "http://projects.scipy.org/ipython/ipython/wiki/PyReadline/Intro" - try: - from readline import * - import readline as _rl - have_readline = True - except ImportError: - pass - - if have_readline: - try: - _outputfile=_rl.GetOutputFile() - except NameError: - print "Failed GetOutputFile" - have_readline = False + _outputfile=_rl.GetOutputFile() + except NameError: + print "Failed GetOutputFile" + have_readline = False -else: +# the clear_history() function was only introduced in Python 2.4 and is +# actually optional in the readline API, so we must explicitly check for its +# existence. Some known platforms actually don't have it. This thread: +# http://mail.python.org/pipermail/python-dev/2003-August/037845.html +# has the original discussion. + +if have_readline: + import readline try: - from readline import * - have_readline = True - except ImportError: - pass + readline.clear_history + except AttributeError: + def clear_history(): pass + readline.clear_history = clear_history + del readline diff --git a/doc/ChangeLog b/doc/ChangeLog index 79b8498..944a11a 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,5 +1,10 @@ 2007-05-10 Fernando Perez + * IPython/rlineimpl.py: check for clear_history in readline and + make it a dummy no-op if not available. This function isn't + guaranteed to be in the API and appeared in Python 2.4, so we need + to check it ourselves. Also, clean up this file quite a bit. + * ipython.1: update man page and full manual with information about threads (remove outdated warning). Closes #151.