##// END OF EJS Templates
- add support for PyCrust-style _getAttributeNames magic method. Closes #50....
fperez -
Show More
@@ -5,7 +5,7 b' Class which mimics a module.'
5 Needed to allow pickle to correctly resolve namespaces during IPython
5 Needed to allow pickle to correctly resolve namespaces during IPython
6 sessions.
6 sessions.
7
7
8 $Id: FakeModule.py 410 2004-11-04 07:58:17Z fperez $"""
8 $Id: FakeModule.py 1322 2006-05-24 07:51:39Z fperez $"""
9
9
10 #*****************************************************************************
10 #*****************************************************************************
11 # Copyright (C) 2002-2004 Fernando Perez. <fperez@colorado.edu>
11 # Copyright (C) 2002-2004 Fernando Perez. <fperez@colorado.edu>
@@ -35,6 +35,9 b' class FakeModule:'
35
35
36 self.__dict__ = adict
36 self.__dict__ = adict
37
37
38 # modules should have a __file__ attribute
39 adict['__file__'] = __file__
40
38 def __getattr__(self,key):
41 def __getattr__(self,key):
39 try:
42 try:
40 return self.__dict__[key]
43 return self.__dict__[key]
@@ -1,7 +1,7 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Magic functions for InteractiveShell.
2 """Magic functions for InteractiveShell.
3
3
4 $Id: Magic.py 1314 2006-05-19 18:24:14Z fperez $"""
4 $Id: Magic.py 1322 2006-05-24 07:51:39Z fperez $"""
5
5
6 #*****************************************************************************
6 #*****************************************************************************
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
@@ -1874,6 +1874,12 b' Currently the magic system has the following functions:\\n"""'
1874
1874
1875 Options:
1875 Options:
1876
1876
1877 -n <number>: open the editor at a specified line number. By default,
1878 the IPython editor hook uses the unix syntax 'editor +N filename', but
1879 you can configure this by providing your own modified hook if your
1880 favorite editor supports line-number specifications with a different
1881 syntax.
1882
1877 -p: this will call the editor with the same data as the previous time
1883 -p: this will call the editor with the same data as the previous time
1878 it was used, regardless of how long ago (in your current session) it
1884 it was used, regardless of how long ago (in your current session) it
1879 was.
1885 was.
@@ -2003,16 +2009,14 b' Currently the magic system has the following functions:\\n"""'
2003 # custom exceptions
2009 # custom exceptions
2004 class DataIsObject(Exception): pass
2010 class DataIsObject(Exception): pass
2005
2011
2006 opts,args = self.parse_options(parameter_s,'prxn=i')
2012 opts,args = self.parse_options(parameter_s,'prxn:')
2007
2008 print 'opt.n: <%r>' % opts.n # dbg
2009
2010 # Set a few locals from the options for convenience:
2013 # Set a few locals from the options for convenience:
2011 opts_p = opts.has_key('p')
2014 opts_p = opts.has_key('p')
2012 opts_r = opts.has_key('r')
2015 opts_r = opts.has_key('r')
2013
2016
2014 # Default line number value
2017 # Default line number value
2015 lineno = None
2018 lineno = opts.get('n',None)
2019
2016 if opts_p:
2020 if opts_p:
2017 args = '_%s' % last_call[0]
2021 args = '_%s' % last_call[0]
2018 if not self.shell.user_ns.has_key(args):
2022 if not self.shell.user_ns.has_key(args):
@@ -2081,7 +2085,8 b' Currently the magic system has the following functions:\\n"""'
2081 # a temp file it's gone by now).
2085 # a temp file it's gone by now).
2082 if datafile:
2086 if datafile:
2083 try:
2087 try:
2084 lineno = inspect.getsourcelines(data)[1]
2088 if lineno is None:
2089 lineno = inspect.getsourcelines(data)[1]
2085 except IOError:
2090 except IOError:
2086 filename = make_filename(args)
2091 filename = make_filename(args)
2087 if filename is None:
2092 if filename is None:
@@ -219,6 +219,17 b' class Completer:'
219 # This will happen if `object` is a class and not an instance.
219 # This will happen if `object` is a class and not an instance.
220 pass
220 pass
221
221
222 # Support for PyCrust-style _getAttributeNames magic method.
223 if hasattr(object, '_getAttributeNames'):
224 try:
225 words.extend(object._getAttributeNames())
226 # Eliminate duplicates.
227 words = set(words)
228 except TypeError:
229 # `object` is a class and not an instance. Ignore
230 # this error.
231 pass
232
222 # filter out non-string attributes which may be stuffed by dir() calls
233 # filter out non-string attributes which may be stuffed by dir() calls
223 # and poor coding in third-party modules
234 # and poor coding in third-party modules
224 words = [w for w in words
235 words = [w for w in words
@@ -5,7 +5,7 b' General purpose utilities.'
5 This is a grab-bag of stuff I find useful in most programs I write. Some of
5 This is a grab-bag of stuff I find useful in most programs I write. Some of
6 these things are also convenient when working at the command line.
6 these things are also convenient when working at the command line.
7
7
8 $Id: genutils.py 1314 2006-05-19 18:24:14Z fperez $"""
8 $Id: genutils.py 1322 2006-05-24 07:51:39Z fperez $"""
9
9
10 #*****************************************************************************
10 #*****************************************************************************
11 # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu>
11 # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu>
@@ -1576,17 +1576,22 b' def chop(seq,size):'
1576 return map(chunk,xrange(0,len(seq),size))
1576 return map(chunk,xrange(0,len(seq),size))
1577
1577
1578 #----------------------------------------------------------------------------
1578 #----------------------------------------------------------------------------
1579 def with(object, **args):
1579 # with is a keyword as of python 2.5, so this function is renamed to withobj
1580 # from its old 'with' name.
1581 def with_obj(object, **args):
1580 """Set multiple attributes for an object, similar to Pascal's with.
1582 """Set multiple attributes for an object, similar to Pascal's with.
1581
1583
1582 Example:
1584 Example:
1583 with(jim,
1585 with_obj(jim,
1584 born = 1960,
1586 born = 1960,
1585 haircolour = 'Brown',
1587 haircolour = 'Brown',
1586 eyecolour = 'Green')
1588 eyecolour = 'Green')
1587
1589
1588 Credit: Greg Ewing, in
1590 Credit: Greg Ewing, in
1589 http://mail.python.org/pipermail/python-list/2001-May/040703.html"""
1591 http://mail.python.org/pipermail/python-list/2001-May/040703.html.
1592
1593 NOTE: up until IPython 0.7.2, this was called simply 'with', but 'with'
1594 has become a keyword for Python 2.5, so we had to rename it."""
1590
1595
1591 object.__dict__.update(args)
1596 object.__dict__.update(args)
1592
1597
@@ -32,7 +32,7 b" ip.set_hook('editor', calljed)"
32 You can then enable the functionality by doing 'import myiphooks'
32 You can then enable the functionality by doing 'import myiphooks'
33 somewhere in your configuration files or ipython command line.
33 somewhere in your configuration files or ipython command line.
34
34
35 $Id: hooks.py 1303 2006-05-17 03:39:29Z fperez $"""
35 $Id: hooks.py 1322 2006-05-24 07:51:39Z fperez $"""
36
36
37 #*****************************************************************************
37 #*****************************************************************************
38 # Copyright (C) 2005 Fernando Perez. <fperez@colorado.edu>
38 # Copyright (C) 2005 Fernando Perez. <fperez@colorado.edu>
@@ -73,7 +73,7 b' def editor(self,filename, linenum=None):'
73 if linenum is None or editor=='notepad':
73 if linenum is None or editor=='notepad':
74 linemark = ''
74 linemark = ''
75 else:
75 else:
76 linemark = '+%d' % linenum
76 linemark = '+%d' % int(linenum)
77
77
78 # Enclose in quotes if necessary and legal
78 # Enclose in quotes if necessary and legal
79 if ' ' in editor and os.path.isfile(editor) and editor[0] != '"':
79 if ' ' in editor and os.path.isfile(editor) and editor[0] != '"':
@@ -251,7 +251,6 b' class IPApi:'
251 # exposes variables 'foo' as 'x' and 'bar' as 'y' in IPython
251 # exposes variables 'foo' as 'x' and 'bar' as 'y' in IPython
252 # user namespace
252 # user namespace
253 ip.user_ns.update(dict(x=foo,y=bar))
253 ip.user_ns.update(dict(x=foo,y=bar))
254
255 """
254 """
256
255
257 # print 'vars given:',vars # dbg
256 # print 'vars given:',vars # dbg
@@ -6,7 +6,7 b' Requires Python 2.3 or newer.'
6
6
7 This file contains all the classes and helper functions specific to IPython.
7 This file contains all the classes and helper functions specific to IPython.
8
8
9 $Id: iplib.py 1314 2006-05-19 18:24:14Z fperez $
9 $Id: iplib.py 1322 2006-05-24 07:51:39Z fperez $
10 """
10 """
11
11
12 #*****************************************************************************
12 #*****************************************************************************
@@ -204,13 +204,6 b' class InteractiveShell(object,Magic):'
204 # Job manager (for jobs run as background threads)
204 # Job manager (for jobs run as background threads)
205 self.jobs = BackgroundJobManager()
205 self.jobs = BackgroundJobManager()
206
206
207 # Do the intuitively correct thing for quit/exit: we remove the
208 # builtins if they exist, and our own magics will deal with this
209 try:
210 del __builtin__.exit, __builtin__.quit
211 except AttributeError:
212 pass
213
214 # Store the actual shell's name
207 # Store the actual shell's name
215 self.name = name
208 self.name = name
216
209
@@ -1231,7 +1224,8 b' want to merge them back into the new files.""" % locals()'
1231 """Utility routine for edit_syntax_error"""
1224 """Utility routine for edit_syntax_error"""
1232
1225
1233 if e.filename in ('<ipython console>','<input>','<string>',
1226 if e.filename in ('<ipython console>','<input>','<string>',
1234 '<console>',None):
1227 '<console>','<BackgroundJob compilation>',
1228 None):
1235
1229
1236 return False
1230 return False
1237 try:
1231 try:
@@ -1269,11 +1263,14 b' want to merge them back into the new files.""" % locals()'
1269 except:
1263 except:
1270 self.showtraceback()
1264 self.showtraceback()
1271 else:
1265 else:
1272 f = file(err.filename)
1273 try:
1266 try:
1274 sys.displayhook(f.read())
1267 f = file(err.filename)
1275 finally:
1268 try:
1276 f.close()
1269 sys.displayhook(f.read())
1270 finally:
1271 f.close()
1272 except:
1273 self.showtraceback()
1277
1274
1278 def showsyntaxerror(self, filename=None):
1275 def showsyntaxerror(self, filename=None):
1279 """Display the syntax error that just occurred.
1276 """Display the syntax error that just occurred.
@@ -1316,7 +1313,16 b' want to merge them back into the new files.""" % locals()'
1316 pdb.pm()
1313 pdb.pm()
1317
1314
1318 def showtraceback(self,exc_tuple = None,filename=None,tb_offset=None):
1315 def showtraceback(self,exc_tuple = None,filename=None,tb_offset=None):
1319 """Display the exception that just occurred."""
1316 """Display the exception that just occurred.
1317
1318 If nothing is known about the exception, this is the method which
1319 should be used throughout the code for presenting user tracebacks,
1320 rather htan directly invoking the InteractiveTB object.
1321
1322 A specific showsyntaxerror() also exists, but this method can take
1323 care of calling it if needed, so unless you are explicitly catching a
1324 SyntaxError exception, don't try to analyze the stack manually and
1325 simply call this method."""
1320
1326
1321 # Though this won't be called by syntax errors in the input line,
1327 # Though this won't be called by syntax errors in the input line,
1322 # there may be SyntaxError cases whith imported code.
1328 # there may be SyntaxError cases whith imported code.
@@ -1793,7 +1799,12 b' want to merge them back into the new files.""" % locals()'
1793 else:
1799 else:
1794 self.input_hist_raw.append('%s\n' % line)
1800 self.input_hist_raw.append('%s\n' % line)
1795
1801
1796 lineout = self.prefilter(line,continue_prompt)
1802 try:
1803 lineout = self.prefilter(line,continue_prompt)
1804 except:
1805 # blanket except, in case a user-defined prefilter crashes, so it
1806 # can't take all of ipython with it.
1807 self.showtraceback()
1797 return lineout
1808 return lineout
1798
1809
1799 def split_user_input(self,line):
1810 def split_user_input(self,line):
@@ -1,3 +1,40 b''
1 2006-05-24 Fernando Perez <Fernando.Perez@colorado.edu>
2
3 * IPython/completer.py (Completer.attr_matches): add support for
4 PyCrust-style _getAttributeNames magic method. Patch contributed
5 by <mscott-AT-goldenspud.com>. Closes #50.
6
7 * IPython/iplib.py (InteractiveShell.__init__): remove the
8 deletion of exit/quit from __builtin__, which can break
9 third-party tools like the Zope debugging console. The
10 %exit/%quit magics remain. In general, it's probably a good idea
11 not to delete anything from __builtin__, since we never know what
12 that will break. In any case, python now (for 2.5) will support
13 'real' exit/quit, so this issue is moot. Closes #55.
14
15 * IPython/genutils.py (with_obj): rename the 'with' function to
16 'withobj' to avoid incompatibilities with Python 2.5, where 'with'
17 becomes a language keyword. Closes #53.
18
19 * IPython/FakeModule.py (FakeModule.__init__): add a proper
20 __file__ attribute to this so it fools more things into thinking
21 it is a real module. Closes #59.
22
23 * IPython/Magic.py (magic_edit): add -n option to open the editor
24 at a specific line number. After a patch by Stefan van der Walt.
25
26 2006-05-23 Fernando Perez <Fernando.Perez@colorado.edu>
27
28 * IPython/iplib.py (edit_syntax_error): fix crash when for some
29 reason the file could not be opened. After automatic crash
30 reports sent by James Graham <jgraham-AT-ast.cam.ac.uk> and
31 Charles Dolan <charlespatrickdolan-AT-yahoo.com>.
32 (_should_recompile): Don't fire editor if using %bg, since there
33 is no file in the first place. From the same report as above.
34 (raw_input): protect against faulty third-party prefilters. After
35 an automatic crash report sent by Dirk Laurie <dirk-AT-sun.ac.za>
36 while running under SAGE.
37
1 2006-05-23 Ville Vainio <vivainio@gmail.com>
38 2006-05-23 Ville Vainio <vivainio@gmail.com>
2
39
3 * ipapi.py: Stripped down ip.to_user_ns() to work only as
40 * ipapi.py: Stripped down ip.to_user_ns() to work only as
General Comments 0
You need to be logged in to leave comments. Login now