##// END OF EJS Templates
Minor formatting cleanups, remove more svn keyword marks
Fernando Perez -
Show More
@@ -1,317 +1,316 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 #
2 #
3 # File: ipy_profile_zope.py
3 # File: ipy_profile_zope.py
4 #
4 #
5 # Copyright (c) InQuant GmbH
5 # Copyright (c) InQuant GmbH
6 #
6 #
7 # An ipython profile for zope and plone. Some ideas
7 # An ipython profile for zope and plone. Some ideas
8 # stolen from http://www.tomster.org.
8 # stolen from http://www.tomster.org.
9 #
9 #
10 # Distributed under the terms of the BSD License. The full license is in
10 # Distributed under the terms of the BSD License. The full license is in
11 # the file COPYING, distributed as part of this software.
11 # the file COPYING, distributed as part of this software.
12
12
13 __author__ = """Stefan Eletzhofer <stefan.eletzhofer@inquant.de>"""
13 __author__ = """Stefan Eletzhofer <stefan.eletzhofer@inquant.de>"""
14 __docformat__ = 'plaintext'
14 __docformat__ = 'plaintext'
15 __revision__ = "$Revision$"
16
15
17 from IPython import ipapi
16 from IPython import ipapi
18 from IPython import Release
17 from IPython import Release
19 from types import StringType
18 from types import StringType
20 import sys
19 import sys
21 import os
20 import os
22 import textwrap
21 import textwrap
23
22
24 # The import below effectively obsoletes your old-style ipythonrc[.ini],
23 # The import below effectively obsoletes your old-style ipythonrc[.ini],
25 # so consider yourself warned!
24 # so consider yourself warned!
26 # import ipy_defaults
25 # import ipy_defaults
27
26
28 _marker = []
27 _marker = []
29 def shasattr(obj, attr, acquire=False):
28 def shasattr(obj, attr, acquire=False):
30 """ See Archetypes/utils.py
29 """ See Archetypes/utils.py
31 """
30 """
32 if not acquire:
31 if not acquire:
33 obj = obj.aq_base
32 obj = obj.aq_base
34 return getattr(obj, attr, _marker) is not _marker
33 return getattr(obj, attr, _marker) is not _marker
35
34
36 class ZopeDebug(object):
35 class ZopeDebug(object):
37 def __init__(self):
36 def __init__(self):
38
37
39 self.instancehome = os.environ.get( "INSTANCE_HOME" )
38 self.instancehome = os.environ.get( "INSTANCE_HOME" )
40
39
41 configfile = os.environ.get( "CONFIG_FILE" )
40 configfile = os.environ.get( "CONFIG_FILE" )
42 if configfile is None and self.instancehome is not None:
41 if configfile is None and self.instancehome is not None:
43 configfile = os.path.join( self.instancehome, "etc", "zope.conf" )
42 configfile = os.path.join( self.instancehome, "etc", "zope.conf" )
44
43
45 if configfile is None:
44 if configfile is None:
46 raise RuntimeError( "CONFIG_FILE env not set" )
45 raise RuntimeError( "CONFIG_FILE env not set" )
47
46
48 print "CONFIG_FILE=", configfile
47 print "CONFIG_FILE=", configfile
49 print "INSTANCE_HOME=", self.instancehome
48 print "INSTANCE_HOME=", self.instancehome
50
49
51 self.configfile = configfile
50 self.configfile = configfile
52
51
53 try:
52 try:
54 from Zope2 import configure
53 from Zope2 import configure
55 except ImportError:
54 except ImportError:
56 from Zope import configure
55 from Zope import configure
57
56
58 configure( configfile )
57 configure( configfile )
59
58
60 try:
59 try:
61 import Zope2
60 import Zope2
62 app = Zope2.app()
61 app = Zope2.app()
63 except ImportError:
62 except ImportError:
64 import Zope
63 import Zope
65 app = Zope.app()
64 app = Zope.app()
66
65
67 from Testing.makerequest import makerequest
66 from Testing.makerequest import makerequest
68 self.app = makerequest( app )
67 self.app = makerequest( app )
69
68
70 try:
69 try:
71 self._make_permissive()
70 self._make_permissive()
72 print "Permissive security installed"
71 print "Permissive security installed"
73 except:
72 except:
74 print "Permissive security NOT installed"
73 print "Permissive security NOT installed"
75
74
76 self._pwd = self.portal or self.app
75 self._pwd = self.portal or self.app
77
76
78 try:
77 try:
79 from zope.component import getSiteManager
78 from zope.component import getSiteManager
80 from zope.component import getGlobalSiteManager
79 from zope.component import getGlobalSiteManager
81 from zope.app.component.hooks import setSite
80 from zope.app.component.hooks import setSite
82
81
83 if self.portal is not None:
82 if self.portal is not None:
84 setSite( self.portal )
83 setSite( self.portal )
85
84
86 gsm = getGlobalSiteManager()
85 gsm = getGlobalSiteManager()
87 sm = getSiteManager()
86 sm = getSiteManager()
88
87
89 if sm is gsm:
88 if sm is gsm:
90 print "ERROR SETTING SITE!"
89 print "ERROR SETTING SITE!"
91 except:
90 except:
92 pass
91 pass
93
92
94
93
95 @property
94 @property
96 def utils(self):
95 def utils(self):
97 class Utils(object):
96 class Utils(object):
98 commit = self.commit
97 commit = self.commit
99 sync = self.sync
98 sync = self.sync
100 objectInfo = self.objectInfo
99 objectInfo = self.objectInfo
101 ls = self.ls
100 ls = self.ls
102 pwd = self.pwd
101 pwd = self.pwd
103 cd = self.cd
102 cd = self.cd
104 su = self.su
103 su = self.su
105 getCatalogInfo = self.getCatalogInfo
104 getCatalogInfo = self.getCatalogInfo
106
105
107 @property
106 @property
108 def cwd(self):
107 def cwd(self):
109 return self.pwd()
108 return self.pwd()
110
109
111 return Utils()
110 return Utils()
112
111
113 @property
112 @property
114 def namespace(self):
113 def namespace(self):
115 return dict( utils=self.utils, app=self.app, portal=self.portal )
114 return dict( utils=self.utils, app=self.app, portal=self.portal )
116
115
117 @property
116 @property
118 def portal(self):
117 def portal(self):
119 portals = self.app.objectValues( "Plone Site" )
118 portals = self.app.objectValues( "Plone Site" )
120 if len(portals):
119 if len(portals):
121 return portals[0]
120 return portals[0]
122 else:
121 else:
123 raise KeyError( "No Plone Site found.")
122 raise KeyError( "No Plone Site found.")
124
123
125 def pwd(self):
124 def pwd(self):
126 return self._pwd
125 return self._pwd
127
126
128 def _make_permissive(self):
127 def _make_permissive(self):
129 """
128 """
130 Make a permissive security manager with all rights. Hell,
129 Make a permissive security manager with all rights. Hell,
131 we're developers, aren't we? Security is for whimps. :)
130 we're developers, aren't we? Security is for whimps. :)
132 """
131 """
133 from Products.CMFCore.tests.base.security import PermissiveSecurityPolicy
132 from Products.CMFCore.tests.base.security import PermissiveSecurityPolicy
134 import AccessControl
133 import AccessControl
135 from AccessControl.SecurityManagement import newSecurityManager
134 from AccessControl.SecurityManagement import newSecurityManager
136 from AccessControl.SecurityManager import setSecurityPolicy
135 from AccessControl.SecurityManager import setSecurityPolicy
137
136
138 _policy = PermissiveSecurityPolicy()
137 _policy = PermissiveSecurityPolicy()
139 self.oldpolicy = setSecurityPolicy(_policy)
138 self.oldpolicy = setSecurityPolicy(_policy)
140 newSecurityManager(None, AccessControl.User.system)
139 newSecurityManager(None, AccessControl.User.system)
141
140
142 def su(self, username):
141 def su(self, username):
143 """ Change to named user.
142 """ Change to named user.
144 """
143 """
145 # TODO Make it easy to change back to permissive security.
144 # TODO Make it easy to change back to permissive security.
146 user = self.portal.acl_users.getUser(username)
145 user = self.portal.acl_users.getUser(username)
147 if not user:
146 if not user:
148 print "Can't find %s in %s" % (username, self.portal.acl_users)
147 print "Can't find %s in %s" % (username, self.portal.acl_users)
149 return
148 return
150
149
151 from AccessControl import ZopeSecurityPolicy
150 from AccessControl import ZopeSecurityPolicy
152 import AccessControl
151 import AccessControl
153 from AccessControl.SecurityManagement import newSecurityManager, getSecurityManager
152 from AccessControl.SecurityManagement import newSecurityManager, getSecurityManager
154 from AccessControl.SecurityManager import setSecurityPolicy
153 from AccessControl.SecurityManager import setSecurityPolicy
155
154
156 _policy = ZopeSecurityPolicy
155 _policy = ZopeSecurityPolicy
157 self.oldpolicy = setSecurityPolicy(_policy)
156 self.oldpolicy = setSecurityPolicy(_policy)
158 wrapped_user = user.__of__(self.portal.acl_users)
157 wrapped_user = user.__of__(self.portal.acl_users)
159 newSecurityManager(None, user)
158 newSecurityManager(None, user)
160 print 'User changed.'
159 print 'User changed.'
161 return getSecurityManager().getUser()
160 return getSecurityManager().getUser()
162
161
163 def getCatalogInfo(self, obj=None, catalog='portal_catalog', query=None, sort_on='created', sort_order='reverse' ):
162 def getCatalogInfo(self, obj=None, catalog='portal_catalog', query=None, sort_on='created', sort_order='reverse' ):
164 """ Inspect portal_catalog. Pass an object or object id for a
163 """ Inspect portal_catalog. Pass an object or object id for a
165 default query on that object, or pass an explicit query.
164 default query on that object, or pass an explicit query.
166 """
165 """
167 if obj and query:
166 if obj and query:
168 print "Ignoring %s, using query." % obj
167 print "Ignoring %s, using query." % obj
169
168
170 catalog = self.portal.get(catalog)
169 catalog = self.portal.get(catalog)
171 if not catalog:
170 if not catalog:
172 return 'No catalog'
171 return 'No catalog'
173
172
174 indexes = catalog._catalog.indexes
173 indexes = catalog._catalog.indexes
175 if not query:
174 if not query:
176 if type(obj) is StringType:
175 if type(obj) is StringType:
177 cwd = self.pwd()
176 cwd = self.pwd()
178 obj = cwd.unrestrictedTraverse( obj )
177 obj = cwd.unrestrictedTraverse( obj )
179 # If the default in the signature is mutable, its value will
178 # If the default in the signature is mutable, its value will
180 # persist across invocations.
179 # persist across invocations.
181 query = {}
180 query = {}
182 if indexes.get('path'):
181 if indexes.get('path'):
183 from string import join
182 from string import join
184 path = join(obj.getPhysicalPath(), '/')
183 path = join(obj.getPhysicalPath(), '/')
185 query.update({'path': path})
184 query.update({'path': path})
186 if indexes.get('getID'):
185 if indexes.get('getID'):
187 query.update({'getID': obj.id, })
186 query.update({'getID': obj.id, })
188 if indexes.get('UID') and shasattr(obj, 'UID'):
187 if indexes.get('UID') and shasattr(obj, 'UID'):
189 query.update({'UID': obj.UID(), })
188 query.update({'UID': obj.UID(), })
190 if indexes.get(sort_on):
189 if indexes.get(sort_on):
191 query.update({'sort_on': sort_on, 'sort_order': sort_order})
190 query.update({'sort_on': sort_on, 'sort_order': sort_order})
192 if not query:
191 if not query:
193 return 'Empty query'
192 return 'Empty query'
194 results = catalog(**query)
193 results = catalog(**query)
195
194
196 result_info = []
195 result_info = []
197 for r in results:
196 for r in results:
198 rid = r.getRID()
197 rid = r.getRID()
199 if rid:
198 if rid:
200 result_info.append(
199 result_info.append(
201 {'path': catalog.getpath(rid),
200 {'path': catalog.getpath(rid),
202 'metadata': catalog.getMetadataForRID(rid),
201 'metadata': catalog.getMetadataForRID(rid),
203 'indexes': catalog.getIndexDataForRID(rid), }
202 'indexes': catalog.getIndexDataForRID(rid), }
204 )
203 )
205 else:
204 else:
206 result_info.append({'missing': rid})
205 result_info.append({'missing': rid})
207
206
208 if len(result_info) == 1:
207 if len(result_info) == 1:
209 return result_info[0]
208 return result_info[0]
210 return result_info
209 return result_info
211
210
212 def commit(self):
211 def commit(self):
213 """
212 """
214 Commit the transaction.
213 Commit the transaction.
215 """
214 """
216 try:
215 try:
217 import transaction
216 import transaction
218 transaction.get().commit()
217 transaction.get().commit()
219 except ImportError:
218 except ImportError:
220 get_transaction().commit()
219 get_transaction().commit()
221
220
222 def sync(self):
221 def sync(self):
223 """
222 """
224 Sync the app's view of the zodb.
223 Sync the app's view of the zodb.
225 """
224 """
226 self.app._p_jar.sync()
225 self.app._p_jar.sync()
227
226
228 def objectInfo( self, o ):
227 def objectInfo( self, o ):
229 """
228 """
230 Return a descriptive string of an object
229 Return a descriptive string of an object
231 """
230 """
232 Title = ""
231 Title = ""
233 t = getattr( o, 'Title', None )
232 t = getattr( o, 'Title', None )
234 if t:
233 if t:
235 Title = t()
234 Title = t()
236 return {'id': o.getId(),
235 return {'id': o.getId(),
237 'Title': Title,
236 'Title': Title,
238 'portal_type': getattr( o, 'portal_type', o.meta_type),
237 'portal_type': getattr( o, 'portal_type', o.meta_type),
239 'folderish': o.isPrincipiaFolderish
238 'folderish': o.isPrincipiaFolderish
240 }
239 }
241
240
242 def cd( self, path ):
241 def cd( self, path ):
243 """
242 """
244 Change current dir to a specific folder.
243 Change current dir to a specific folder.
245
244
246 cd( ".." )
245 cd( ".." )
247 cd( "/plone/Members/admin" )
246 cd( "/plone/Members/admin" )
248 cd( portal.Members.admin )
247 cd( portal.Members.admin )
249 etc.
248 etc.
250 """
249 """
251 if type(path) is not StringType:
250 if type(path) is not StringType:
252 path = '/'.join(path.getPhysicalPath())
251 path = '/'.join(path.getPhysicalPath())
253 cwd = self.pwd()
252 cwd = self.pwd()
254 x = cwd.unrestrictedTraverse( path )
253 x = cwd.unrestrictedTraverse( path )
255 if x is None:
254 if x is None:
256 raise KeyError( "Can't cd to %s" % path )
255 raise KeyError( "Can't cd to %s" % path )
257
256
258 print "%s -> %s" % ( self.pwd().getId(), x.getId() )
257 print "%s -> %s" % ( self.pwd().getId(), x.getId() )
259 self._pwd = x
258 self._pwd = x
260
259
261 def ls( self, x=None ):
260 def ls( self, x=None ):
262 """
261 """
263 List object(s)
262 List object(s)
264 """
263 """
265 if type(x) is StringType:
264 if type(x) is StringType:
266 cwd = self.pwd()
265 cwd = self.pwd()
267 x = cwd.unrestrictedTraverse( x )
266 x = cwd.unrestrictedTraverse( x )
268 if x is None:
267 if x is None:
269 x = self.pwd()
268 x = self.pwd()
270 if x.isPrincipiaFolderish:
269 if x.isPrincipiaFolderish:
271 return [self.objectInfo(o) for id, o in x.objectItems()]
270 return [self.objectInfo(o) for id, o in x.objectItems()]
272 else:
271 else:
273 return self.objectInfo( x )
272 return self.objectInfo( x )
274
273
275 zope_debug = None
274 zope_debug = None
276
275
277 def ipy_set_trace():
276 def ipy_set_trace():
278 import IPython; IPython.Debugger.Pdb().set_trace()
277 import IPython; IPython.Debugger.Pdb().set_trace()
279
278
280 def main():
279 def main():
281 global zope_debug
280 global zope_debug
282 ip = ipapi.get()
281 ip = ipapi.get()
283 o = ip.options
282 o = ip.options
284 # autocall to "full" mode (smart mode is default, I like full mode)
283 # autocall to "full" mode (smart mode is default, I like full mode)
285
284
286 SOFTWARE_HOME = os.environ.get( "SOFTWARE_HOME" )
285 SOFTWARE_HOME = os.environ.get( "SOFTWARE_HOME" )
287 sys.path.append( SOFTWARE_HOME )
286 sys.path.append( SOFTWARE_HOME )
288 print "SOFTWARE_HOME=%s\n" % SOFTWARE_HOME
287 print "SOFTWARE_HOME=%s\n" % SOFTWARE_HOME
289
288
290 zope_debug = ZopeDebug()
289 zope_debug = ZopeDebug()
291
290
292 # <HACK ALERT>
291 # <HACK ALERT>
293 import pdb;
292 import pdb;
294 pdb.set_trace = ipy_set_trace
293 pdb.set_trace = ipy_set_trace
295 # </HACK ALERT>
294 # </HACK ALERT>
296
295
297 # I like my banner minimal.
296 # I like my banner minimal.
298 o.banner = "ZOPE Py %s IPy %s\n" % (sys.version.split('\n')[0],Release.version)
297 o.banner = "ZOPE Py %s IPy %s\n" % (sys.version.split('\n')[0],Release.version)
299
298
300 print textwrap.dedent("""\
299 print textwrap.dedent("""\
301 ZOPE mode iPython shell.
300 ZOPE mode iPython shell.
302
301
303 Bound names:
302 Bound names:
304 app
303 app
305 portal
304 portal
306 utils.{ %s }
305 utils.{ %s }
307
306
308 Uses the $SOFTWARE_HOME and $CONFIG_FILE environment
307 Uses the $SOFTWARE_HOME and $CONFIG_FILE environment
309 variables.
308 variables.
310 """ % ( ",".join([ x for x in dir(zope_debug.utils) if not x.startswith("_") ] ) ) )
309 """ % ( ",".join([ x for x in dir(zope_debug.utils) if not x.startswith("_") ] ) ) )
311
310
312
311
313 ip.user_ns.update( zope_debug.namespace )
312 ip.user_ns.update( zope_debug.namespace )
314
313
315
314
316 main()
315 main()
317 # vim: set ft=python ts=4 sw=4 expandtab :
316 # vim: set ft=python ts=4 sw=4 expandtab :
@@ -1,632 +1,631 b''
1 # -*- Mode: Shell-Script -*- Not really, but shows comments correctly
1 # -*- Mode: Shell-Script -*- Not really, but shows comments correctly
2 # $Id: ipythonrc 2156 2007-03-19 02:32:19Z fperez $
3
2
4 #***************************************************************************
3 #***************************************************************************
5 #
4 #
6 # Configuration file for IPython -- ipythonrc format
5 # Configuration file for IPython -- ipythonrc format
7 #
6 #
8 # ===========================================================
7 # ===========================================================
9 # Deprecation note: you should look into modifying ipy_user_conf.py (located
8 # Deprecation note: you should look into modifying ipy_user_conf.py (located
10 # in ~/.ipython or ~/_ipython, depending on your platform) instead, it's a
9 # in ~/.ipython or ~/_ipython, depending on your platform) instead, it's a
11 # more flexible and robust (and better supported!) configuration
10 # more flexible and robust (and better supported!) configuration
12 # method.
11 # method.
13 # ===========================================================
12 # ===========================================================
14 #
13 #
15 # The format of this file is simply one of 'key value' lines.
14 # The format of this file is simply one of 'key value' lines.
16 # Lines containing only whitespace at the beginning and then a # are ignored
15 # Lines containing only whitespace at the beginning and then a # are ignored
17 # as comments. But comments can NOT be put on lines with data.
16 # as comments. But comments can NOT be put on lines with data.
18
17
19 # The meaning and use of each key are explained below.
18 # The meaning and use of each key are explained below.
20
19
21 #---------------------------------------------------------------------------
20 #---------------------------------------------------------------------------
22 # Section: included files
21 # Section: included files
23
22
24 # Put one or more *config* files (with the syntax of this file) you want to
23 # Put one or more *config* files (with the syntax of this file) you want to
25 # include. For keys with a unique value the outermost file has precedence. For
24 # include. For keys with a unique value the outermost file has precedence. For
26 # keys with multiple values, they all get assembled into a list which then
25 # keys with multiple values, they all get assembled into a list which then
27 # gets loaded by IPython.
26 # gets loaded by IPython.
28
27
29 # In this file, all lists of things should simply be space-separated.
28 # In this file, all lists of things should simply be space-separated.
30
29
31 # This allows you to build hierarchies of files which recursively load
30 # This allows you to build hierarchies of files which recursively load
32 # lower-level services. If this is your main ~/.ipython/ipythonrc file, you
31 # lower-level services. If this is your main ~/.ipython/ipythonrc file, you
33 # should only keep here basic things you always want available. Then you can
32 # should only keep here basic things you always want available. Then you can
34 # include it in every other special-purpose config file you create.
33 # include it in every other special-purpose config file you create.
35 include
34 include
36
35
37 #---------------------------------------------------------------------------
36 #---------------------------------------------------------------------------
38 # Section: startup setup
37 # Section: startup setup
39
38
40 # These are mostly things which parallel a command line option of the same
39 # These are mostly things which parallel a command line option of the same
41 # name.
40 # name.
42
41
43 # Keys in this section should only appear once. If any key from this section
42 # Keys in this section should only appear once. If any key from this section
44 # is encountered more than once, the last value remains, all earlier ones get
43 # is encountered more than once, the last value remains, all earlier ones get
45 # discarded.
44 # discarded.
46
45
47
46
48 # Automatic calling of callable objects. If set to 1 or 2, callable objects
47 # Automatic calling of callable objects. If set to 1 or 2, callable objects
49 # are automatically called when invoked at the command line, even if you don't
48 # are automatically called when invoked at the command line, even if you don't
50 # type parentheses. IPython adds the parentheses for you. For example:
49 # type parentheses. IPython adds the parentheses for you. For example:
51
50
52 #In [1]: str 45
51 #In [1]: str 45
53 #------> str(45)
52 #------> str(45)
54 #Out[1]: '45'
53 #Out[1]: '45'
55
54
56 # IPython reprints your line with '---->' indicating that it added
55 # IPython reprints your line with '---->' indicating that it added
57 # parentheses. While this option is very convenient for interactive use, it
56 # parentheses. While this option is very convenient for interactive use, it
58 # may occasionally cause problems with objects which have side-effects if
57 # may occasionally cause problems with objects which have side-effects if
59 # called unexpectedly.
58 # called unexpectedly.
60
59
61 # The valid values for autocall are:
60 # The valid values for autocall are:
62
61
63 # autocall 0 -> disabled (you can toggle it at runtime with the %autocall magic)
62 # autocall 0 -> disabled (you can toggle it at runtime with the %autocall magic)
64
63
65 # autocall 1 -> active, but do not apply if there are no arguments on the line.
64 # autocall 1 -> active, but do not apply if there are no arguments on the line.
66
65
67 # In this mode, you get:
66 # In this mode, you get:
68
67
69 #In [1]: callable
68 #In [1]: callable
70 #Out[1]: <built-in function callable>
69 #Out[1]: <built-in function callable>
71
70
72 #In [2]: callable 'hello'
71 #In [2]: callable 'hello'
73 #------> callable('hello')
72 #------> callable('hello')
74 #Out[2]: False
73 #Out[2]: False
75
74
76 # 2 -> Active always. Even if no arguments are present, the callable object
75 # 2 -> Active always. Even if no arguments are present, the callable object
77 # is called:
76 # is called:
78
77
79 #In [4]: callable
78 #In [4]: callable
80 #------> callable()
79 #------> callable()
81
80
82 # Note that even with autocall off, you can still use '/' at the start of a
81 # Note that even with autocall off, you can still use '/' at the start of a
83 # line to treat the first argument on the command line as a function and add
82 # line to treat the first argument on the command line as a function and add
84 # parentheses to it:
83 # parentheses to it:
85
84
86 #In [8]: /str 43
85 #In [8]: /str 43
87 #------> str(43)
86 #------> str(43)
88 #Out[8]: '43'
87 #Out[8]: '43'
89
88
90 autocall 1
89 autocall 1
91
90
92 # Auto-edit syntax errors. When you use the %edit magic in ipython to edit
91 # Auto-edit syntax errors. When you use the %edit magic in ipython to edit
93 # source code (see the 'editor' variable below), it is possible that you save
92 # source code (see the 'editor' variable below), it is possible that you save
94 # a file with syntax errors in it. If this variable is true, IPython will ask
93 # a file with syntax errors in it. If this variable is true, IPython will ask
95 # you whether to re-open the editor immediately to correct such an error.
94 # you whether to re-open the editor immediately to correct such an error.
96
95
97 autoedit_syntax 0
96 autoedit_syntax 0
98
97
99 # Auto-indent. IPython can recognize lines ending in ':' and indent the next
98 # Auto-indent. IPython can recognize lines ending in ':' and indent the next
100 # line, while also un-indenting automatically after 'raise' or 'return'.
99 # line, while also un-indenting automatically after 'raise' or 'return'.
101
100
102 # This feature uses the readline library, so it will honor your ~/.inputrc
101 # This feature uses the readline library, so it will honor your ~/.inputrc
103 # configuration (or whatever file your INPUTRC variable points to). Adding
102 # configuration (or whatever file your INPUTRC variable points to). Adding
104 # the following lines to your .inputrc file can make indent/unindenting more
103 # the following lines to your .inputrc file can make indent/unindenting more
105 # convenient (M-i indents, M-u unindents):
104 # convenient (M-i indents, M-u unindents):
106
105
107 # $if Python
106 # $if Python
108 # "\M-i": " "
107 # "\M-i": " "
109 # "\M-u": "\d\d\d\d"
108 # "\M-u": "\d\d\d\d"
110 # $endif
109 # $endif
111
110
112 # The feature is potentially a bit dangerous, because it can cause problems
111 # The feature is potentially a bit dangerous, because it can cause problems
113 # with pasting of indented code (the pasted code gets re-indented on each
112 # with pasting of indented code (the pasted code gets re-indented on each
114 # line). But it's a huge time-saver when working interactively. The magic
113 # line). But it's a huge time-saver when working interactively. The magic
115 # function %autoindent allows you to toggle it on/off at runtime.
114 # function %autoindent allows you to toggle it on/off at runtime.
116
115
117 autoindent 1
116 autoindent 1
118
117
119 # Auto-magic. This gives you access to all the magic functions without having
118 # Auto-magic. This gives you access to all the magic functions without having
120 # to prepend them with an % sign. If you define a variable with the same name
119 # to prepend them with an % sign. If you define a variable with the same name
121 # as a magic function (say who=1), you will need to access the magic function
120 # as a magic function (say who=1), you will need to access the magic function
122 # with % (%who in this example). However, if later you delete your variable
121 # with % (%who in this example). However, if later you delete your variable
123 # (del who), you'll recover the automagic calling form.
122 # (del who), you'll recover the automagic calling form.
124
123
125 # Considering that many magic functions provide a lot of shell-like
124 # Considering that many magic functions provide a lot of shell-like
126 # functionality, automagic gives you something close to a full Python+system
125 # functionality, automagic gives you something close to a full Python+system
127 # shell environment (and you can extend it further if you want).
126 # shell environment (and you can extend it further if you want).
128
127
129 automagic 1
128 automagic 1
130
129
131 # Size of the output cache. After this many entries are stored, the cache will
130 # Size of the output cache. After this many entries are stored, the cache will
132 # get flushed. Depending on the size of your intermediate calculations, you
131 # get flushed. Depending on the size of your intermediate calculations, you
133 # may have memory problems if you make it too big, since keeping things in the
132 # may have memory problems if you make it too big, since keeping things in the
134 # cache prevents Python from reclaiming the memory for old results. Experiment
133 # cache prevents Python from reclaiming the memory for old results. Experiment
135 # with a value that works well for you.
134 # with a value that works well for you.
136
135
137 # If you choose cache_size 0 IPython will revert to python's regular >>>
136 # If you choose cache_size 0 IPython will revert to python's regular >>>
138 # unnumbered prompt. You will still have _, __ and ___ for your last three
137 # unnumbered prompt. You will still have _, __ and ___ for your last three
139 # results, but that will be it. No dynamic _1, _2, etc. will be created. If
138 # results, but that will be it. No dynamic _1, _2, etc. will be created. If
140 # you are running on a slow machine or with very limited memory, this may
139 # you are running on a slow machine or with very limited memory, this may
141 # help.
140 # help.
142
141
143 cache_size 1000
142 cache_size 1000
144
143
145 # Classic mode: Setting 'classic 1' you lose many of IPython niceties,
144 # Classic mode: Setting 'classic 1' you lose many of IPython niceties,
146 # but that's your choice! Classic 1 -> same as IPython -classic.
145 # but that's your choice! Classic 1 -> same as IPython -classic.
147 # Note that this is _not_ the normal python interpreter, it's simply
146 # Note that this is _not_ the normal python interpreter, it's simply
148 # IPython emulating most of the classic interpreter's behavior.
147 # IPython emulating most of the classic interpreter's behavior.
149 classic 0
148 classic 0
150
149
151 # colors - Coloring option for prompts and traceback printouts.
150 # colors - Coloring option for prompts and traceback printouts.
152
151
153 # Currently available schemes: NoColor, Linux, LightBG.
152 # Currently available schemes: NoColor, Linux, LightBG.
154
153
155 # This option allows coloring the prompts and traceback printouts. This
154 # This option allows coloring the prompts and traceback printouts. This
156 # requires a terminal which can properly handle color escape sequences. If you
155 # requires a terminal which can properly handle color escape sequences. If you
157 # are having problems with this, use the NoColor scheme (uses no color escapes
156 # are having problems with this, use the NoColor scheme (uses no color escapes
158 # at all).
157 # at all).
159
158
160 # The Linux option works well in linux console type environments: dark
159 # The Linux option works well in linux console type environments: dark
161 # background with light fonts.
160 # background with light fonts.
162
161
163 # LightBG is similar to Linux but swaps dark/light colors to be more readable
162 # LightBG is similar to Linux but swaps dark/light colors to be more readable
164 # in light background terminals.
163 # in light background terminals.
165
164
166 # keep uncommented only the one you want:
165 # keep uncommented only the one you want:
167 colors Linux
166 colors Linux
168 #colors LightBG
167 #colors LightBG
169 #colors NoColor
168 #colors NoColor
170
169
171 ########################
170 ########################
172 # Note to Windows users
171 # Note to Windows users
173 #
172 #
174 # Color and readline support is avaialble to Windows users via Gary Bishop's
173 # Color and readline support is avaialble to Windows users via Gary Bishop's
175 # readline library. You can find Gary's tools at
174 # readline library. You can find Gary's tools at
176 # http://sourceforge.net/projects/uncpythontools.
175 # http://sourceforge.net/projects/uncpythontools.
177 # Note that his readline module requires in turn the ctypes library, available
176 # Note that his readline module requires in turn the ctypes library, available
178 # at http://starship.python.net/crew/theller/ctypes.
177 # at http://starship.python.net/crew/theller/ctypes.
179 ########################
178 ########################
180
179
181 # color_info: IPython can display information about objects via a set of
180 # color_info: IPython can display information about objects via a set of
182 # functions, and optionally can use colors for this, syntax highlighting
181 # functions, and optionally can use colors for this, syntax highlighting
183 # source code and various other elements. This information is passed through a
182 # source code and various other elements. This information is passed through a
184 # pager (it defaults to 'less' if $PAGER is not set).
183 # pager (it defaults to 'less' if $PAGER is not set).
185
184
186 # If your pager has problems, try to setting it to properly handle escapes
185 # If your pager has problems, try to setting it to properly handle escapes
187 # (see the less manpage for detail), or disable this option. The magic
186 # (see the less manpage for detail), or disable this option. The magic
188 # function %color_info allows you to toggle this interactively for testing.
187 # function %color_info allows you to toggle this interactively for testing.
189
188
190 color_info 1
189 color_info 1
191
190
192 # confirm_exit: set to 1 if you want IPython to confirm when you try to exit
191 # confirm_exit: set to 1 if you want IPython to confirm when you try to exit
193 # with an EOF (Control-d in Unix, Control-Z/Enter in Windows). Note that using
192 # with an EOF (Control-d in Unix, Control-Z/Enter in Windows). Note that using
194 # the magic functions %Exit or %Quit you can force a direct exit, bypassing
193 # the magic functions %Exit or %Quit you can force a direct exit, bypassing
195 # any confirmation.
194 # any confirmation.
196
195
197 confirm_exit 1
196 confirm_exit 1
198
197
199 # Use deep_reload() as a substitute for reload() by default. deep_reload() is
198 # Use deep_reload() as a substitute for reload() by default. deep_reload() is
200 # still available as dreload() and appears as a builtin.
199 # still available as dreload() and appears as a builtin.
201
200
202 deep_reload 0
201 deep_reload 0
203
202
204 # Which editor to use with the %edit command. If you leave this at 0, IPython
203 # Which editor to use with the %edit command. If you leave this at 0, IPython
205 # will honor your EDITOR environment variable. Since this editor is invoked on
204 # will honor your EDITOR environment variable. Since this editor is invoked on
206 # the fly by ipython and is meant for editing small code snippets, you may
205 # the fly by ipython and is meant for editing small code snippets, you may
207 # want to use a small, lightweight editor here.
206 # want to use a small, lightweight editor here.
208
207
209 # For Emacs users, setting up your Emacs server properly as described in the
208 # For Emacs users, setting up your Emacs server properly as described in the
210 # manual is a good idea. An alternative is to use jed, a very light editor
209 # manual is a good idea. An alternative is to use jed, a very light editor
211 # with much of the feel of Emacs (though not as powerful for heavy-duty work).
210 # with much of the feel of Emacs (though not as powerful for heavy-duty work).
212
211
213 editor 0
212 editor 0
214
213
215 # log 1 -> same as ipython -log. This automatically logs to ./ipython.log
214 # log 1 -> same as ipython -log. This automatically logs to ./ipython.log
216 log 0
215 log 0
217
216
218 # Same as ipython -Logfile YourLogfileName.
217 # Same as ipython -Logfile YourLogfileName.
219 # Don't use with log 1 (use one or the other)
218 # Don't use with log 1 (use one or the other)
220 logfile ''
219 logfile ''
221
220
222 # banner 0 -> same as ipython -nobanner
221 # banner 0 -> same as ipython -nobanner
223 banner 1
222 banner 1
224
223
225 # messages 0 -> same as ipython -nomessages
224 # messages 0 -> same as ipython -nomessages
226 messages 1
225 messages 1
227
226
228 # Automatically call the pdb debugger after every uncaught exception. If you
227 # Automatically call the pdb debugger after every uncaught exception. If you
229 # are used to debugging using pdb, this puts you automatically inside of it
228 # are used to debugging using pdb, this puts you automatically inside of it
230 # after any call (either in IPython or in code called by it) which triggers an
229 # after any call (either in IPython or in code called by it) which triggers an
231 # exception which goes uncaught.
230 # exception which goes uncaught.
232 pdb 0
231 pdb 0
233
232
234 # Enable the pprint module for printing. pprint tends to give a more readable
233 # Enable the pprint module for printing. pprint tends to give a more readable
235 # display (than print) for complex nested data structures.
234 # display (than print) for complex nested data structures.
236 pprint 1
235 pprint 1
237
236
238 # Prompt strings
237 # Prompt strings
239
238
240 # Most bash-like escapes can be used to customize IPython's prompts, as well as
239 # Most bash-like escapes can be used to customize IPython's prompts, as well as
241 # a few additional ones which are IPython-specific. All valid prompt escapes
240 # a few additional ones which are IPython-specific. All valid prompt escapes
242 # are described in detail in the Customization section of the IPython HTML/PDF
241 # are described in detail in the Customization section of the IPython HTML/PDF
243 # manual.
242 # manual.
244
243
245 # Use \# to represent the current prompt number, and quote them to protect
244 # Use \# to represent the current prompt number, and quote them to protect
246 # spaces.
245 # spaces.
247 prompt_in1 'In [\#]: '
246 prompt_in1 'In [\#]: '
248
247
249 # \D is replaced by as many dots as there are digits in the
248 # \D is replaced by as many dots as there are digits in the
250 # current value of \#.
249 # current value of \#.
251 prompt_in2 ' .\D.: '
250 prompt_in2 ' .\D.: '
252
251
253 prompt_out 'Out[\#]: '
252 prompt_out 'Out[\#]: '
254
253
255 # Select whether to left-pad the output prompts to match the length of the
254 # Select whether to left-pad the output prompts to match the length of the
256 # input ones. This allows you for example to use a simple '>' as an output
255 # input ones. This allows you for example to use a simple '>' as an output
257 # prompt, and yet have the output line up with the input. If set to false,
256 # prompt, and yet have the output line up with the input. If set to false,
258 # the output prompts will be unpadded (flush left).
257 # the output prompts will be unpadded (flush left).
259 prompts_pad_left 1
258 prompts_pad_left 1
260
259
261 # Pylab support: when ipython is started with the -pylab switch, by default it
260 # Pylab support: when ipython is started with the -pylab switch, by default it
262 # executes 'from matplotlib.pylab import *'. Set this variable to false if you
261 # executes 'from matplotlib.pylab import *'. Set this variable to false if you
263 # want to disable this behavior.
262 # want to disable this behavior.
264
263
265 # For details on pylab, see the matplotlib website:
264 # For details on pylab, see the matplotlib website:
266 # http://matplotlib.sf.net
265 # http://matplotlib.sf.net
267 pylab_import_all 1
266 pylab_import_all 1
268
267
269
268
270 # quick 1 -> same as ipython -quick
269 # quick 1 -> same as ipython -quick
271 quick 0
270 quick 0
272
271
273 # Use the readline library (1) or not (0). Most users will want this on, but
272 # Use the readline library (1) or not (0). Most users will want this on, but
274 # if you experience strange problems with line management (mainly when using
273 # if you experience strange problems with line management (mainly when using
275 # IPython inside Emacs buffers) you may try disabling it. Not having it on
274 # IPython inside Emacs buffers) you may try disabling it. Not having it on
276 # prevents you from getting command history with the arrow keys, searching and
275 # prevents you from getting command history with the arrow keys, searching and
277 # name completion using TAB.
276 # name completion using TAB.
278
277
279 readline 1
278 readline 1
280
279
281 # Screen Length: number of lines of your screen. This is used to control
280 # Screen Length: number of lines of your screen. This is used to control
282 # printing of very long strings. Strings longer than this number of lines will
281 # printing of very long strings. Strings longer than this number of lines will
283 # be paged with the less command instead of directly printed.
282 # be paged with the less command instead of directly printed.
284
283
285 # The default value for this is 0, which means IPython will auto-detect your
284 # The default value for this is 0, which means IPython will auto-detect your
286 # screen size every time it needs to print. If for some reason this isn't
285 # screen size every time it needs to print. If for some reason this isn't
287 # working well (it needs curses support), specify it yourself. Otherwise don't
286 # working well (it needs curses support), specify it yourself. Otherwise don't
288 # change the default.
287 # change the default.
289
288
290 screen_length 0
289 screen_length 0
291
290
292 # Prompt separators for input and output.
291 # Prompt separators for input and output.
293 # Use \n for newline explicitly, without quotes.
292 # Use \n for newline explicitly, without quotes.
294 # Use 0 (like at the cmd line) to turn off a given separator.
293 # Use 0 (like at the cmd line) to turn off a given separator.
295
294
296 # The structure of prompt printing is:
295 # The structure of prompt printing is:
297 # (SeparateIn)Input....
296 # (SeparateIn)Input....
298 # (SeparateOut)Output...
297 # (SeparateOut)Output...
299 # (SeparateOut2), # that is, no newline is printed after Out2
298 # (SeparateOut2), # that is, no newline is printed after Out2
300 # By choosing these you can organize your output any way you want.
299 # By choosing these you can organize your output any way you want.
301
300
302 separate_in \n
301 separate_in \n
303 separate_out 0
302 separate_out 0
304 separate_out2 0
303 separate_out2 0
305
304
306 # 'nosep 1' is a shorthand for '-SeparateIn 0 -SeparateOut 0 -SeparateOut2 0'.
305 # 'nosep 1' is a shorthand for '-SeparateIn 0 -SeparateOut 0 -SeparateOut2 0'.
307 # Simply removes all input/output separators, overriding the choices above.
306 # Simply removes all input/output separators, overriding the choices above.
308 nosep 0
307 nosep 0
309
308
310 # Wildcard searches - IPython has a system for searching names using
309 # Wildcard searches - IPython has a system for searching names using
311 # shell-like wildcards; type %psearch? for details. This variables sets
310 # shell-like wildcards; type %psearch? for details. This variables sets
312 # whether by default such searches should be case sensitive or not. You can
311 # whether by default such searches should be case sensitive or not. You can
313 # always override the default at the system command line or the IPython
312 # always override the default at the system command line or the IPython
314 # prompt.
313 # prompt.
315
314
316 wildcards_case_sensitive 1
315 wildcards_case_sensitive 1
317
316
318 # Object information: at what level of detail to display the string form of an
317 # Object information: at what level of detail to display the string form of an
319 # object. If set to 0, ipython will compute the string form of any object X,
318 # object. If set to 0, ipython will compute the string form of any object X,
320 # by calling str(X), when X? is typed. If set to 1, str(X) will only be
319 # by calling str(X), when X? is typed. If set to 1, str(X) will only be
321 # computed when X?? is given, and if set to 2 or higher, it will never be
320 # computed when X?? is given, and if set to 2 or higher, it will never be
322 # computed (there is no X??? level of detail). This is mostly of use to
321 # computed (there is no X??? level of detail). This is mostly of use to
323 # people who frequently manipulate objects whose string representation is
322 # people who frequently manipulate objects whose string representation is
324 # extremely expensive to compute.
323 # extremely expensive to compute.
325
324
326 object_info_string_level 0
325 object_info_string_level 0
327
326
328 # xmode - Exception reporting mode.
327 # xmode - Exception reporting mode.
329
328
330 # Valid modes: Plain, Context and Verbose.
329 # Valid modes: Plain, Context and Verbose.
331
330
332 # Plain: similar to python's normal traceback printing.
331 # Plain: similar to python's normal traceback printing.
333
332
334 # Context: prints 5 lines of context source code around each line in the
333 # Context: prints 5 lines of context source code around each line in the
335 # traceback.
334 # traceback.
336
335
337 # Verbose: similar to Context, but additionally prints the variables currently
336 # Verbose: similar to Context, but additionally prints the variables currently
338 # visible where the exception happened (shortening their strings if too
337 # visible where the exception happened (shortening their strings if too
339 # long). This can potentially be very slow, if you happen to have a huge data
338 # long). This can potentially be very slow, if you happen to have a huge data
340 # structure whose string representation is complex to compute. Your computer
339 # structure whose string representation is complex to compute. Your computer
341 # may appear to freeze for a while with cpu usage at 100%. If this occurs, you
340 # may appear to freeze for a while with cpu usage at 100%. If this occurs, you
342 # can cancel the traceback with Ctrl-C (maybe hitting it more than once).
341 # can cancel the traceback with Ctrl-C (maybe hitting it more than once).
343
342
344 #xmode Plain
343 #xmode Plain
345 xmode Context
344 xmode Context
346 #xmode Verbose
345 #xmode Verbose
347
346
348 # multi_line_specials: if true, allow magics, aliases and shell escapes (via
347 # multi_line_specials: if true, allow magics, aliases and shell escapes (via
349 # !cmd) to be used in multi-line input (like for loops). For example, if you
348 # !cmd) to be used in multi-line input (like for loops). For example, if you
350 # have this active, the following is valid in IPython:
349 # have this active, the following is valid in IPython:
351 #
350 #
352 #In [17]: for i in range(3):
351 #In [17]: for i in range(3):
353 # ....: mkdir $i
352 # ....: mkdir $i
354 # ....: !touch $i/hello
353 # ....: !touch $i/hello
355 # ....: ls -l $i
354 # ....: ls -l $i
356
355
357 multi_line_specials 1
356 multi_line_specials 1
358
357
359
358
360 # System calls: When IPython makes system calls (e.g. via special syntax like
359 # System calls: When IPython makes system calls (e.g. via special syntax like
361 # !cmd or !!cmd, or magics like %sc or %sx), it can print the command it is
360 # !cmd or !!cmd, or magics like %sc or %sx), it can print the command it is
362 # executing to standard output, prefixed by a header string.
361 # executing to standard output, prefixed by a header string.
363
362
364 system_header "IPython system call: "
363 system_header "IPython system call: "
365
364
366 system_verbose 1
365 system_verbose 1
367
366
368 # wxversion: request a specific wxPython version (used for -wthread)
367 # wxversion: request a specific wxPython version (used for -wthread)
369
368
370 # Set this to the value of wxPython you want to use, but note that this
369 # Set this to the value of wxPython you want to use, but note that this
371 # feature requires you to have the wxversion Python module to work. If you
370 # feature requires you to have the wxversion Python module to work. If you
372 # don't have the wxversion module (try 'import wxversion' at the prompt to
371 # don't have the wxversion module (try 'import wxversion' at the prompt to
373 # check) or simply want to leave the system to pick up the default, leave this
372 # check) or simply want to leave the system to pick up the default, leave this
374 # variable at 0.
373 # variable at 0.
375
374
376 wxversion 0
375 wxversion 0
377
376
378 #---------------------------------------------------------------------------
377 #---------------------------------------------------------------------------
379 # Section: Readline configuration (readline is not available for MS-Windows)
378 # Section: Readline configuration (readline is not available for MS-Windows)
380
379
381 # This is done via the following options:
380 # This is done via the following options:
382
381
383 # (i) readline_parse_and_bind: this option can appear as many times as you
382 # (i) readline_parse_and_bind: this option can appear as many times as you
384 # want, each time defining a string to be executed via a
383 # want, each time defining a string to be executed via a
385 # readline.parse_and_bind() command. The syntax for valid commands of this
384 # readline.parse_and_bind() command. The syntax for valid commands of this
386 # kind can be found by reading the documentation for the GNU readline library,
385 # kind can be found by reading the documentation for the GNU readline library,
387 # as these commands are of the kind which readline accepts in its
386 # as these commands are of the kind which readline accepts in its
388 # configuration file.
387 # configuration file.
389
388
390 # The TAB key can be used to complete names at the command line in one of two
389 # The TAB key can be used to complete names at the command line in one of two
391 # ways: 'complete' and 'menu-complete'. The difference is that 'complete' only
390 # ways: 'complete' and 'menu-complete'. The difference is that 'complete' only
392 # completes as much as possible while 'menu-complete' cycles through all
391 # completes as much as possible while 'menu-complete' cycles through all
393 # possible completions. Leave the one you prefer uncommented.
392 # possible completions. Leave the one you prefer uncommented.
394
393
395 readline_parse_and_bind tab: complete
394 readline_parse_and_bind tab: complete
396 #readline_parse_and_bind tab: menu-complete
395 #readline_parse_and_bind tab: menu-complete
397
396
398 # This binds Control-l to printing the list of all possible completions when
397 # This binds Control-l to printing the list of all possible completions when
399 # there is more than one (what 'complete' does when hitting TAB twice, or at
398 # there is more than one (what 'complete' does when hitting TAB twice, or at
400 # the first TAB if show-all-if-ambiguous is on)
399 # the first TAB if show-all-if-ambiguous is on)
401 readline_parse_and_bind "\C-l": possible-completions
400 readline_parse_and_bind "\C-l": possible-completions
402
401
403 # This forces readline to automatically print the above list when tab
402 # This forces readline to automatically print the above list when tab
404 # completion is set to 'complete'. You can still get this list manually by
403 # completion is set to 'complete'. You can still get this list manually by
405 # using the key bound to 'possible-completions' (Control-l by default) or by
404 # using the key bound to 'possible-completions' (Control-l by default) or by
406 # hitting TAB twice. Turning this on makes the printing happen at the first
405 # hitting TAB twice. Turning this on makes the printing happen at the first
407 # TAB.
406 # TAB.
408 readline_parse_and_bind set show-all-if-ambiguous on
407 readline_parse_and_bind set show-all-if-ambiguous on
409
408
410 # If you have TAB set to complete names, you can rebind any key (Control-o by
409 # If you have TAB set to complete names, you can rebind any key (Control-o by
411 # default) to insert a true TAB character.
410 # default) to insert a true TAB character.
412 readline_parse_and_bind "\C-o": tab-insert
411 readline_parse_and_bind "\C-o": tab-insert
413
412
414 # These commands allow you to indent/unindent easily, with the 4-space
413 # These commands allow you to indent/unindent easily, with the 4-space
415 # convention of the Python coding standards. Since IPython's internal
414 # convention of the Python coding standards. Since IPython's internal
416 # auto-indent system also uses 4 spaces, you should not change the number of
415 # auto-indent system also uses 4 spaces, you should not change the number of
417 # spaces in the code below.
416 # spaces in the code below.
418 readline_parse_and_bind "\M-i": " "
417 readline_parse_and_bind "\M-i": " "
419 readline_parse_and_bind "\M-o": "\d\d\d\d"
418 readline_parse_and_bind "\M-o": "\d\d\d\d"
420 readline_parse_and_bind "\M-I": "\d\d\d\d"
419 readline_parse_and_bind "\M-I": "\d\d\d\d"
421
420
422 # Bindings for incremental searches in the history. These searches use the
421 # Bindings for incremental searches in the history. These searches use the
423 # string typed so far on the command line and search anything in the previous
422 # string typed so far on the command line and search anything in the previous
424 # input history containing them.
423 # input history containing them.
425 readline_parse_and_bind "\C-r": reverse-search-history
424 readline_parse_and_bind "\C-r": reverse-search-history
426 readline_parse_and_bind "\C-s": forward-search-history
425 readline_parse_and_bind "\C-s": forward-search-history
427
426
428 # Bindings for completing the current line in the history of previous
427 # Bindings for completing the current line in the history of previous
429 # commands. This allows you to recall any previous command by typing its first
428 # commands. This allows you to recall any previous command by typing its first
430 # few letters and hitting Control-p, bypassing all intermediate commands which
429 # few letters and hitting Control-p, bypassing all intermediate commands which
431 # may be in the history (much faster than hitting up-arrow 50 times!)
430 # may be in the history (much faster than hitting up-arrow 50 times!)
432 readline_parse_and_bind "\C-p": history-search-backward
431 readline_parse_and_bind "\C-p": history-search-backward
433 readline_parse_and_bind "\C-n": history-search-forward
432 readline_parse_and_bind "\C-n": history-search-forward
434
433
435 # I also like to have the same functionality on the plain arrow keys. If you'd
434 # I also like to have the same functionality on the plain arrow keys. If you'd
436 # rather have the arrows use all the history (and not just match what you've
435 # rather have the arrows use all the history (and not just match what you've
437 # typed so far), comment out or delete the next two lines.
436 # typed so far), comment out or delete the next two lines.
438 readline_parse_and_bind "\e[A": history-search-backward
437 readline_parse_and_bind "\e[A": history-search-backward
439 readline_parse_and_bind "\e[B": history-search-forward
438 readline_parse_and_bind "\e[B": history-search-forward
440
439
441 # These are typically on by default under *nix, but not win32.
440 # These are typically on by default under *nix, but not win32.
442 readline_parse_and_bind "\C-k": kill-line
441 readline_parse_and_bind "\C-k": kill-line
443 readline_parse_and_bind "\C-u": unix-line-discard
442 readline_parse_and_bind "\C-u": unix-line-discard
444
443
445 # (ii) readline_remove_delims: a string of characters to be removed from the
444 # (ii) readline_remove_delims: a string of characters to be removed from the
446 # default word-delimiters list used by readline, so that completions may be
445 # default word-delimiters list used by readline, so that completions may be
447 # performed on strings which contain them.
446 # performed on strings which contain them.
448
447
449 readline_remove_delims -/~
448 readline_remove_delims -/~
450
449
451 # (iii) readline_merge_completions: whether to merge the result of all
450 # (iii) readline_merge_completions: whether to merge the result of all
452 # possible completions or not. If true, IPython will complete filenames,
451 # possible completions or not. If true, IPython will complete filenames,
453 # python names and aliases and return all possible completions. If you set it
452 # python names and aliases and return all possible completions. If you set it
454 # to false, each completer is used at a time, and only if it doesn't return
453 # to false, each completer is used at a time, and only if it doesn't return
455 # any completions is the next one used.
454 # any completions is the next one used.
456
455
457 # The default order is: [python_matches, file_matches, alias_matches]
456 # The default order is: [python_matches, file_matches, alias_matches]
458
457
459 readline_merge_completions 1
458 readline_merge_completions 1
460
459
461 # (iv) readline_omit__names: normally hitting <tab> after a '.' in a name
460 # (iv) readline_omit__names: normally hitting <tab> after a '.' in a name
462 # will complete all attributes of an object, including all the special methods
461 # will complete all attributes of an object, including all the special methods
463 # whose names start with single or double underscores (like __getitem__ or
462 # whose names start with single or double underscores (like __getitem__ or
464 # __class__).
463 # __class__).
465
464
466 # This variable allows you to control this completion behavior:
465 # This variable allows you to control this completion behavior:
467
466
468 # readline_omit__names 1 -> completion will omit showing any names starting
467 # readline_omit__names 1 -> completion will omit showing any names starting
469 # with two __, but it will still show names starting with one _.
468 # with two __, but it will still show names starting with one _.
470
469
471 # readline_omit__names 2 -> completion will omit all names beginning with one
470 # readline_omit__names 2 -> completion will omit all names beginning with one
472 # _ (which obviously means filtering out the double __ ones).
471 # _ (which obviously means filtering out the double __ ones).
473
472
474 # Even when this option is set, you can still see those names by explicitly
473 # Even when this option is set, you can still see those names by explicitly
475 # typing a _ after the period and hitting <tab>: 'name._<tab>' will always
474 # typing a _ after the period and hitting <tab>: 'name._<tab>' will always
476 # complete attribute names starting with '_'.
475 # complete attribute names starting with '_'.
477
476
478 # This option is off by default so that new users see all attributes of any
477 # This option is off by default so that new users see all attributes of any
479 # objects they are dealing with.
478 # objects they are dealing with.
480
479
481 readline_omit__names 0
480 readline_omit__names 0
482
481
483 #---------------------------------------------------------------------------
482 #---------------------------------------------------------------------------
484 # Section: modules to be loaded with 'import ...'
483 # Section: modules to be loaded with 'import ...'
485
484
486 # List, separated by spaces, the names of the modules you want to import
485 # List, separated by spaces, the names of the modules you want to import
487
486
488 # Example:
487 # Example:
489 # import_mod sys os
488 # import_mod sys os
490 # will produce internally the statements
489 # will produce internally the statements
491 # import sys
490 # import sys
492 # import os
491 # import os
493
492
494 # Each import is executed in its own try/except block, so if one module
493 # Each import is executed in its own try/except block, so if one module
495 # fails to load the others will still be ok.
494 # fails to load the others will still be ok.
496
495
497 import_mod
496 import_mod
498
497
499 #---------------------------------------------------------------------------
498 #---------------------------------------------------------------------------
500 # Section: modules to import some functions from: 'from ... import ...'
499 # Section: modules to import some functions from: 'from ... import ...'
501
500
502 # List, one per line, the modules for which you want only to import some
501 # List, one per line, the modules for which you want only to import some
503 # functions. Give the module name first and then the name of functions to be
502 # functions. Give the module name first and then the name of functions to be
504 # imported from that module.
503 # imported from that module.
505
504
506 # Example:
505 # Example:
507
506
508 # import_some IPython.genutils timing timings
507 # import_some IPython.genutils timing timings
509 # will produce internally the statement
508 # will produce internally the statement
510 # from IPython.genutils import timing, timings
509 # from IPython.genutils import timing, timings
511
510
512 # timing() and timings() are two IPython utilities for timing the execution of
511 # timing() and timings() are two IPython utilities for timing the execution of
513 # your own functions, which you may find useful. Just commment out the above
512 # your own functions, which you may find useful. Just commment out the above
514 # line if you want to test them.
513 # line if you want to test them.
515
514
516 # If you have more than one modules_some line, each gets its own try/except
515 # If you have more than one modules_some line, each gets its own try/except
517 # block (like modules, see above).
516 # block (like modules, see above).
518
517
519 import_some
518 import_some
520
519
521 #---------------------------------------------------------------------------
520 #---------------------------------------------------------------------------
522 # Section: modules to import all from : 'from ... import *'
521 # Section: modules to import all from : 'from ... import *'
523
522
524 # List (same syntax as import_mod above) those modules for which you want to
523 # List (same syntax as import_mod above) those modules for which you want to
525 # import all functions. Remember, this is a potentially dangerous thing to do,
524 # import all functions. Remember, this is a potentially dangerous thing to do,
526 # since it is very easy to overwrite names of things you need. Use with
525 # since it is very easy to overwrite names of things you need. Use with
527 # caution.
526 # caution.
528
527
529 # Example:
528 # Example:
530 # import_all sys os
529 # import_all sys os
531 # will produce internally the statements
530 # will produce internally the statements
532 # from sys import *
531 # from sys import *
533 # from os import *
532 # from os import *
534
533
535 # As before, each will be called in a separate try/except block.
534 # As before, each will be called in a separate try/except block.
536
535
537 import_all
536 import_all
538
537
539 #---------------------------------------------------------------------------
538 #---------------------------------------------------------------------------
540 # Section: Python code to execute.
539 # Section: Python code to execute.
541
540
542 # Put here code to be explicitly executed (keep it simple!)
541 # Put here code to be explicitly executed (keep it simple!)
543 # Put one line of python code per line. All whitespace is removed (this is a
542 # Put one line of python code per line. All whitespace is removed (this is a
544 # feature, not a bug), so don't get fancy building loops here.
543 # feature, not a bug), so don't get fancy building loops here.
545 # This is just for quick convenient creation of things you want available.
544 # This is just for quick convenient creation of things you want available.
546
545
547 # Example:
546 # Example:
548 # execute x = 1
547 # execute x = 1
549 # execute print 'hello world'; y = z = 'a'
548 # execute print 'hello world'; y = z = 'a'
550 # will produce internally
549 # will produce internally
551 # x = 1
550 # x = 1
552 # print 'hello world'; y = z = 'a'
551 # print 'hello world'; y = z = 'a'
553 # and each *line* (not each statement, we don't do python syntax parsing) is
552 # and each *line* (not each statement, we don't do python syntax parsing) is
554 # executed in its own try/except block.
553 # executed in its own try/except block.
555
554
556 execute
555 execute
557
556
558 # Note for the adventurous: you can use this to define your own names for the
557 # Note for the adventurous: you can use this to define your own names for the
559 # magic functions, by playing some namespace tricks:
558 # magic functions, by playing some namespace tricks:
560
559
561 # execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile
560 # execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile
562
561
563 # defines %pf as a new name for %profile.
562 # defines %pf as a new name for %profile.
564
563
565 #---------------------------------------------------------------------------
564 #---------------------------------------------------------------------------
566 # Section: Pyhton files to load and execute.
565 # Section: Pyhton files to load and execute.
567
566
568 # Put here the full names of files you want executed with execfile(file). If
567 # Put here the full names of files you want executed with execfile(file). If
569 # you want complicated initialization, just write whatever you want in a
568 # you want complicated initialization, just write whatever you want in a
570 # regular python file and load it from here.
569 # regular python file and load it from here.
571
570
572 # Filenames defined here (which *must* include the extension) are searched for
571 # Filenames defined here (which *must* include the extension) are searched for
573 # through all of sys.path. Since IPython adds your .ipython directory to
572 # through all of sys.path. Since IPython adds your .ipython directory to
574 # sys.path, they can also be placed in your .ipython dir and will be
573 # sys.path, they can also be placed in your .ipython dir and will be
575 # found. Otherwise (if you want to execute things not in .ipyton nor in
574 # found. Otherwise (if you want to execute things not in .ipyton nor in
576 # sys.path) give a full path (you can use ~, it gets expanded)
575 # sys.path) give a full path (you can use ~, it gets expanded)
577
576
578 # Example:
577 # Example:
579 # execfile file1.py ~/file2.py
578 # execfile file1.py ~/file2.py
580 # will generate
579 # will generate
581 # execfile('file1.py')
580 # execfile('file1.py')
582 # execfile('_path_to_your_home/file2.py')
581 # execfile('_path_to_your_home/file2.py')
583
582
584 # As before, each file gets its own try/except block.
583 # As before, each file gets its own try/except block.
585
584
586 execfile
585 execfile
587
586
588 # If you are feeling adventurous, you can even add functionality to IPython
587 # If you are feeling adventurous, you can even add functionality to IPython
589 # through here. IPython works through a global variable called __ip which
588 # through here. IPython works through a global variable called __ip which
590 # exists at the time when these files are read. If you know what you are doing
589 # exists at the time when these files are read. If you know what you are doing
591 # (read the source) you can add functions to __ip in files loaded here.
590 # (read the source) you can add functions to __ip in files loaded here.
592
591
593 # The file example-magic.py contains a simple but correct example. Try it:
592 # The file example-magic.py contains a simple but correct example. Try it:
594
593
595 # execfile example-magic.py
594 # execfile example-magic.py
596
595
597 # Look at the examples in IPython/iplib.py for more details on how these magic
596 # Look at the examples in IPython/iplib.py for more details on how these magic
598 # functions need to process their arguments.
597 # functions need to process their arguments.
599
598
600 #---------------------------------------------------------------------------
599 #---------------------------------------------------------------------------
601 # Section: aliases for system shell commands
600 # Section: aliases for system shell commands
602
601
603 # Here you can define your own names for system commands. The syntax is
602 # Here you can define your own names for system commands. The syntax is
604 # similar to that of the builtin %alias function:
603 # similar to that of the builtin %alias function:
605
604
606 # alias alias_name command_string
605 # alias alias_name command_string
607
606
608 # The resulting aliases are auto-generated magic functions (hence usable as
607 # The resulting aliases are auto-generated magic functions (hence usable as
609 # %alias_name)
608 # %alias_name)
610
609
611 # For example:
610 # For example:
612
611
613 # alias myls ls -la
612 # alias myls ls -la
614
613
615 # will define 'myls' as an alias for executing the system command 'ls -la'.
614 # will define 'myls' as an alias for executing the system command 'ls -la'.
616 # This allows you to customize IPython's environment to have the same aliases
615 # This allows you to customize IPython's environment to have the same aliases
617 # you are accustomed to from your own shell.
616 # you are accustomed to from your own shell.
618
617
619 # You can also define aliases with parameters using %s specifiers (one per
618 # You can also define aliases with parameters using %s specifiers (one per
620 # parameter):
619 # parameter):
621
620
622 # alias parts echo first %s second %s
621 # alias parts echo first %s second %s
623
622
624 # will give you in IPython:
623 # will give you in IPython:
625 # >>> %parts A B
624 # >>> %parts A B
626 # first A second B
625 # first A second B
627
626
628 # Use one 'alias' statement per alias you wish to define.
627 # Use one 'alias' statement per alias you wish to define.
629
628
630 # alias
629 # alias
631
630
632 #************************* end of file <ipythonrc> ************************
631 #************************* end of file <ipythonrc> ************************
@@ -1,137 +1,137 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 Color schemes for exception handling code in IPython.
3 Color schemes for exception handling code in IPython.
4 """
4 """
5
5
6 #*****************************************************************************
6 #*****************************************************************************
7 # Copyright (C) 2005-2006 Fernando Perez <fperez@colorado.edu>
7 # Copyright (C) 2005-2006 Fernando Perez <fperez@colorado.edu>
8 #
8 #
9 # Distributed under the terms of the BSD License. The full license is in
9 # Distributed under the terms of the BSD License. The full license is in
10 # the file COPYING, distributed as part of this software.
10 # the file COPYING, distributed as part of this software.
11 #*****************************************************************************
11 #*****************************************************************************
12
12
13 #****************************************************************************
13 #****************************************************************************
14 # Required modules
14 # Required modules
15 from IPython.ColorANSI import ColorSchemeTable, TermColors, ColorScheme
15 from IPython.ColorANSI import ColorSchemeTable, TermColors, ColorScheme
16
16
17 def exception_colors():
17 def exception_colors():
18 """Return a color table with fields for exception reporting.
18 """Return a color table with fields for exception reporting.
19
19
20 The table is an instance of ColorSchemeTable with schemes added for
20 The table is an instance of ColorSchemeTable with schemes added for
21 'Linux', 'LightBG' and 'NoColor' and fields for exception handling filled
21 'Linux', 'LightBG' and 'NoColor' and fields for exception handling filled
22 in.
22 in.
23
23
24 Examples:
24 Examples:
25
25
26 >>> ec = exception_colors()
26 >>> ec = exception_colors()
27 >>> ec.active_scheme_name
27 >>> ec.active_scheme_name
28 ''
28 ''
29 >>> print ec.active_colors
29 >>> print ec.active_colors
30 None
30 None
31
31
32 Now we activate a color scheme:
32 Now we activate a color scheme:
33 >>> ec.set_active_scheme('NoColor')
33 >>> ec.set_active_scheme('NoColor')
34 >>> ec.active_scheme_name
34 >>> ec.active_scheme_name
35 'NoColor'
35 'NoColor'
36 >>> ec.active_colors.keys()
36 >>> ec.active_colors.keys()
37 ['em', 'caret', '__allownew', 'name', 'val', 'vName', 'Normal', 'normalEm',
37 ['em', 'caret', '__allownew', 'name', 'val', 'vName', 'Normal', 'normalEm',
38 'filename', 'linenoEm', 'excName', 'lineno', 'valEm', 'filenameEm',
38 'filename', 'linenoEm', 'excName', 'lineno', 'valEm', 'filenameEm',
39 'nameEm', 'line', 'topline']
39 'nameEm', 'line', 'topline']
40 """
40 """
41
41
42 ex_colors = ColorSchemeTable()
42 ex_colors = ColorSchemeTable()
43
43
44 # Populate it with color schemes
44 # Populate it with color schemes
45 C = TermColors # shorthand and local lookup
45 C = TermColors # shorthand and local lookup
46 ex_colors.add_scheme(ColorScheme(
46 ex_colors.add_scheme(ColorScheme(
47 'NoColor',
47 'NoColor',
48 # The color to be used for the top line
48 # The color to be used for the top line
49 topline = C.NoColor,
49 topline = C.NoColor,
50
50
51 # The colors to be used in the traceback
51 # The colors to be used in the traceback
52 filename = C.NoColor,
52 filename = C.NoColor,
53 lineno = C.NoColor,
53 lineno = C.NoColor,
54 name = C.NoColor,
54 name = C.NoColor,
55 vName = C.NoColor,
55 vName = C.NoColor,
56 val = C.NoColor,
56 val = C.NoColor,
57 em = C.NoColor,
57 em = C.NoColor,
58
58
59 # Emphasized colors for the last frame of the traceback
59 # Emphasized colors for the last frame of the traceback
60 normalEm = C.NoColor,
60 normalEm = C.NoColor,
61 filenameEm = C.NoColor,
61 filenameEm = C.NoColor,
62 linenoEm = C.NoColor,
62 linenoEm = C.NoColor,
63 nameEm = C.NoColor,
63 nameEm = C.NoColor,
64 valEm = C.NoColor,
64 valEm = C.NoColor,
65
65
66 # Colors for printing the exception
66 # Colors for printing the exception
67 excName = C.NoColor,
67 excName = C.NoColor,
68 line = C.NoColor,
68 line = C.NoColor,
69 caret = C.NoColor,
69 caret = C.NoColor,
70 Normal = C.NoColor
70 Normal = C.NoColor
71 ))
71 ))
72
72
73 # make some schemes as instances so we can copy them for modification easily
73 # make some schemes as instances so we can copy them for modification easily
74 ex_colors.add_scheme(ColorScheme(
74 ex_colors.add_scheme(ColorScheme(
75 'Linux',
75 'Linux',
76 # The color to be used for the top line
76 # The color to be used for the top line
77 topline = C.LightRed,
77 topline = C.LightRed,
78
78
79 # The colors to be used in the traceback
79 # The colors to be used in the traceback
80 filename = C.Green,
80 filename = C.Green,
81 lineno = C.Green,
81 lineno = C.Green,
82 name = C.Purple,
82 name = C.Purple,
83 vName = C.Cyan,
83 vName = C.Cyan,
84 val = C.Green,
84 val = C.Green,
85 em = C.LightCyan,
85 em = C.LightCyan,
86
86
87 # Emphasized colors for the last frame of the traceback
87 # Emphasized colors for the last frame of the traceback
88 normalEm = C.LightCyan,
88 normalEm = C.LightCyan,
89 filenameEm = C.LightGreen,
89 filenameEm = C.LightGreen,
90 linenoEm = C.LightGreen,
90 linenoEm = C.LightGreen,
91 nameEm = C.LightPurple,
91 nameEm = C.LightPurple,
92 valEm = C.LightBlue,
92 valEm = C.LightBlue,
93
93
94 # Colors for printing the exception
94 # Colors for printing the exception
95 excName = C.LightRed,
95 excName = C.LightRed,
96 line = C.Yellow,
96 line = C.Yellow,
97 caret = C.White,
97 caret = C.White,
98 Normal = C.Normal
98 Normal = C.Normal
99 ))
99 ))
100
100
101 # For light backgrounds, swap dark/light colors
101 # For light backgrounds, swap dark/light colors
102 ex_colors.add_scheme(ColorScheme(
102 ex_colors.add_scheme(ColorScheme(
103 'LightBG',
103 'LightBG',
104 # The color to be used for the top line
104 # The color to be used for the top line
105 topline = C.Red,
105 topline = C.Red,
106
106
107 # The colors to be used in the traceback
107 # The colors to be used in the traceback
108 filename = C.LightGreen,
108 filename = C.LightGreen,
109 lineno = C.LightGreen,
109 lineno = C.LightGreen,
110 name = C.LightPurple,
110 name = C.LightPurple,
111 vName = C.Cyan,
111 vName = C.Cyan,
112 val = C.LightGreen,
112 val = C.LightGreen,
113 em = C.Cyan,
113 em = C.Cyan,
114
114
115 # Emphasized colors for the last frame of the traceback
115 # Emphasized colors for the last frame of the traceback
116 normalEm = C.Cyan,
116 normalEm = C.Cyan,
117 filenameEm = C.Green,
117 filenameEm = C.Green,
118 linenoEm = C.Green,
118 linenoEm = C.Green,
119 nameEm = C.Purple,
119 nameEm = C.Purple,
120 valEm = C.Blue,
120 valEm = C.Blue,
121
121
122 # Colors for printing the exception
122 # Colors for printing the exception
123 excName = C.Red,
123 excName = C.Red,
124 #line = C.Brown, # brown often is displayed as yellow
124 #line = C.Brown, # brown often is displayed as yellow
125 line = C.Red,
125 line = C.Red,
126 caret = C.Normal,
126 caret = C.Normal,
127 Normal = C.Normal
127 Normal = C.Normal,
128 ))
128 ))
129
129
130 return ex_colors
130 return ex_colors
131
131
132
132
133 # For backwards compatibility, keep around a single global object. Note that
133 # For backwards compatibility, keep around a single global object. Note that
134 # this should NOT be used, the factory function should be used instead, since
134 # this should NOT be used, the factory function should be used instead, since
135 # these objects are stateful and it's very easy to get strange bugs if any code
135 # these objects are stateful and it's very easy to get strange bugs if any code
136 # modifies the module-level object's state.
136 # modifies the module-level object's state.
137 ExceptionColors = exception_colors()
137 ExceptionColors = exception_colors()
General Comments 0
You need to be logged in to leave comments. Login now