diff --git a/IPython/Magic.py b/IPython/Magic.py index 6c8db93..a17475b 100644 --- a/IPython/Magic.py +++ b/IPython/Magic.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Magic functions for InteractiveShell. -$Id: Magic.py 1096 2006-01-28 20:08:02Z vivainio $""" +$Id: Magic.py 1099 2006-01-29 21:05:57Z vivainio $""" #***************************************************************************** # Copyright (C) 2001 Janko Hauser and @@ -2008,22 +2008,9 @@ Currently the magic system has the following functions:\n""" if not new_scheme: print 'You must specify a color scheme.' return - # Under Windows, check for Gary Bishop's readline, which is necessary - # for ANSI coloring - if os.name in ['nt','dos']: - try: - import readline - except ImportError: - has_readline = 0 - else: - try: - readline.GetOutputFile() - except AttributeError: - has_readline = 0 - else: - has_readline = 1 - if not has_readline: - msg = """\ + import IPython.rlineimpl as readline + if not readline.have_readline: + msg = """\ Proper color support under MS Windows requires Gary Bishop's readline library. You can find it at: http://sourceforge.net/projects/uncpythontools @@ -2031,8 +2018,8 @@ Gary's readline needs the ctypes module, from: http://starship.python.net/crew/theller/ctypes Defaulting color scheme to 'NoColor'""" - new_scheme = 'NoColor' - warn(msg) + new_scheme = 'NoColor' + warn(msg) # local shortcut shell = self.shell diff --git a/IPython/__init__.py b/IPython/__init__.py index c95fbee..1193867 100644 --- a/IPython/__init__.py +++ b/IPython/__init__.py @@ -27,7 +27,7 @@ IPython tries to: IPython requires Python 2.2 or newer. -$Id: __init__.py 1025 2006-01-16 20:22:21Z vivainio $""" +$Id: __init__.py 1099 2006-01-29 21:05:57Z vivainio $""" #***************************************************************************** # Copyright (C) 2001-2004 Fernando Perez. @@ -45,7 +45,7 @@ if sys.version[0:3] < '2.3': __all__ = ['deep_reload','genutils','ipstruct','ultraTB','DPyGetOpt', 'Itpl','hooks','ConfigLoader','OutputTrap','Release','Shell', 'platutils','platutils_win32','platutils_posix','platutils_dummy', - 'ipapi','path'] + 'ipapi','path','rlineimpl'] # Load __all__ in IPython namespace so that a simple 'import IPython' gives # access to them via IPython. diff --git a/IPython/completer.py b/IPython/completer.py index 4eef327..def6add 100644 --- a/IPython/completer.py +++ b/IPython/completer.py @@ -69,8 +69,9 @@ import glob import keyword import os import re -import readline import sys +import IPython.rlineimpl as readline + import types # Python 2.4 offers sets as a builtin diff --git a/IPython/genutils.py b/IPython/genutils.py index dbd6620..a816d7f 100644 --- a/IPython/genutils.py +++ b/IPython/genutils.py @@ -5,7 +5,7 @@ General purpose utilities. This is a grab-bag of stuff I find useful in most programs I write. Some of these things are also convenient when working at the command line. -$Id: genutils.py 1077 2006-01-24 18:15:27Z vivainio $""" +$Id: genutils.py 1099 2006-01-29 21:05:57Z vivainio $""" #***************************************************************************** # Copyright (C) 2001-2006 Fernando Perez. @@ -71,8 +71,8 @@ except AttributeError: _quotesre = re.compile(r'[\'"](.*)[\'"]') _wordchars = ('abcdfeghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.~*?' - 'ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ' - 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ%s' + 'ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ' + 'ÀÃ�ÂÃÄÅÆÇÈÉÊËÌÃ�ÃŽÃ�Ã�ÑÒÓÔÕÖØÙÚÛÜÃ�Þ%s' % os.sep) def shlex_split(s): @@ -147,24 +147,12 @@ class IOTerm: # Global variable to be used for all I/O Term = IOTerm() -# Windows-specific code to load Gary Bishop's readline and configure it -# automatically for the users -# Note: os.name on cygwin returns posix, so this should only pick up 'native' -# windows. Cygwin returns 'cygwin' for sys.platform. -if os.name == 'nt': - try: - import readline - except ImportError: - pass - else: - try: - _out = readline.GetOutputFile() - except AttributeError: - pass - else: - # Remake Term to use the readline i/o facilities - Term = IOTerm(cout=_out,cerr=_out) - del _out +import IPython.rlineimpl as readline +# Remake Term to use the readline i/o facilities +if readline.have_readline: + + Term = IOTerm(cout=readline._outputfile,cerr=readline._outputfile) + #**************************************************************************** # Generic warning/error printer, used by everything else diff --git a/IPython/iplib.py b/IPython/iplib.py index 43e4abf..7843a76 100644 --- a/IPython/iplib.py +++ b/IPython/iplib.py @@ -6,7 +6,7 @@ Requires Python 2.3 or newer. This file contains all the classes and helper functions specific to IPython. -$Id: iplib.py 1098 2006-01-29 16:14:21Z vivainio $ +$Id: iplib.py 1099 2006-01-29 21:05:57Z vivainio $ """ #***************************************************************************** @@ -1170,29 +1170,15 @@ want to merge them back into the new files.""" % locals() def init_readline(self): """Command history completion/saving/reloading.""" - - using_pyreadline = False - if sys.platform == 'win32': - try: - import pyreadline as readline - using_pyrl = True - print "Using the new pyreadline (thanks for participating in the testing!)" - except ImportError: - print "The IPython team recommends the new pyreadline for Windows use, it wasn't found." - 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." - - - try: - if not using_pyreadline: - import readline - except ImportError: + + import IPython.rlineimpl as readline + if not readline.have_readline: self.has_readline = 0 self.readline = None # no point in bugging windows users with this every time: warn('Readline services not available on this platform.') else: + sys.modules['readline'] = readline import atexit from IPython.completer import IPCompleter self.Completer = IPCompleter(self, diff --git a/IPython/rlineimpl.py b/IPython/rlineimpl.py new file mode 100644 index 0000000..3ca563b --- /dev/null +++ b/IPython/rlineimpl.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +""" Imports and provides the "correct" version of readline for the platform. + +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. + +$Id: Magic.py 1096 2006-01-28 20:08:02Z vivainio $""" + + +import sys + +have_readline = False + +if sys.platform == 'win32': + try: + from pyreadline import * + print "Using the new pyreadline (thanks for participating in the testing!)" + have_readline = True + except ImportError: + print "The IPython team recommends the new pyreadline for Windows use, it wasn't found." + 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." + + from readline import * + have_readline = True +else: + try: + from readline import * + have_readline = True + except ImportError: + pass + + +if have_readline: + try: + _outputfile=GetOutputFile() + except AttributeError: + have_readline = False +