##// END OF EJS Templates
Apply Ville's patch, closes #87
fperez -
Show More
@@ -15,7 +15,7 b' details on the PSF (Python Software Foundation) standard license, see:'
15 15
16 16 http://www.python.org/2.2.3/license.html
17 17
18 $Id: Debugger.py 1324 2006-05-24 20:25:11Z fperez $"""
18 $Id: Debugger.py 1786 2006-09-27 05:47:28Z fperez $"""
19 19
20 20 #*****************************************************************************
21 21 #
@@ -68,44 +68,122 b' class Pdb(pdb.Pdb):'
68 68 # Ugly hack: we can't call the parent constructor, because it binds
69 69 # readline and breaks tab-completion. This means we have to COPY the
70 70 # constructor here, and that requires tracking various python versions.
71
72 def __init__(self,color_scheme='NoColor'):
73 bdb.Bdb.__init__(self)
74 cmd.Cmd.__init__(self,completekey=None) # don't load readline
75 self.prompt = 'ipdb> ' # The default prompt is '(Pdb)'
76 self.aliases = {}
77
78 # These two lines are part of the py2.4 constructor, let's put them
79 # unconditionally here as they won't cause any problems in 2.3.
80 self.mainpyfile = ''
81 self._wait_for_mainpyfile = 0
82
83 # Read $HOME/.pdbrc and ./.pdbrc
84 try:
85 self.rcLines = _file_lines(os.path.join(os.environ['HOME'],
86 ".pdbrc"))
87 except KeyError:
71
72 if sys.version[:3] == '2.5':
73 def __init__(self,color_scheme='NoColor',completekey=None,
74 stdin=None, stdout=None):
75 bdb.Bdb.__init__(self)
76
77 # IPython change
78 # don't load readline
79 cmd.Cmd.__init__(self,completekey,stdin,stdout)
80 #cmd.Cmd.__init__(self, completekey, stdin, stdout)
81 # /IPython change
82
83 if stdout:
84 self.use_rawinput = 0
85 self.prompt = '(Pdb) '
86 self.aliases = {}
87 self.mainpyfile = ''
88 self._wait_for_mainpyfile = 0
89 # Try to load readline if it exists
90 try:
91 import readline
92 except ImportError:
93 pass
94
95 # Read $HOME/.pdbrc and ./.pdbrc
88 96 self.rcLines = []
89 self.rcLines.extend(_file_lines(".pdbrc"))
97 if 'HOME' in os.environ:
98 envHome = os.environ['HOME']
99 try:
100 rcFile = open(os.path.join(envHome, ".pdbrc"))
101 except IOError:
102 pass
103 else:
104 for line in rcFile.readlines():
105 self.rcLines.append(line)
106 rcFile.close()
107 try:
108 rcFile = open(".pdbrc")
109 except IOError:
110 pass
111 else:
112 for line in rcFile.readlines():
113 self.rcLines.append(line)
114 rcFile.close()
90 115
91 # Create color table: we copy the default one from the traceback
92 # module and add a few attributes needed for debugging
93 self.color_scheme_table = ExceptionColors.copy()
94
95 # shorthands
96 C = ColorANSI.TermColors
97 cst = self.color_scheme_table
116 self.commands = {} # associates a command list to breakpoint numbers
117 self.commands_doprompt = {} # for each bp num, tells if the prompt must be disp. after execing the cmd list
118 self.commands_silent = {} # for each bp num, tells if the stack trace must be disp. after execing the cmd list
119 self.commands_defining = False # True while in the process of defining a command list
120 self.commands_bnum = None # The breakpoint number for which we are defining a list
121
122
123 # IPython changes...
124
125 self.prompt = 'ipdb> ' # The default prompt is '(Pdb)'
126 self.aliases = {}
127
128 # Create color table: we copy the default one from the traceback
129 # module and add a few attributes needed for debugging
130 self.color_scheme_table = ExceptionColors.copy()
131
132 # shorthands
133 C = ColorANSI.TermColors
134 cst = self.color_scheme_table
135
136 cst['NoColor'].colors.breakpoint_enabled = C.NoColor
137 cst['NoColor'].colors.breakpoint_disabled = C.NoColor
138
139 cst['Linux'].colors.breakpoint_enabled = C.LightRed
140 cst['Linux'].colors.breakpoint_disabled = C.Red
141
142 cst['LightBG'].colors.breakpoint_enabled = C.LightRed
143 cst['LightBG'].colors.breakpoint_disabled = C.Red
144
145 self.set_colors(color_scheme)
146
147
148 else:
149
150 def __init__(self,color_scheme='NoColor'):
151 bdb.Bdb.__init__(self)
152 cmd.Cmd.__init__(self,completekey=None) # don't load readline
153 self.prompt = 'ipdb> ' # The default prompt is '(Pdb)'
154 self.aliases = {}
155
156 # These two lines are part of the py2.4 constructor, let's put them
157 # unconditionally here as they won't cause any problems in 2.3.
158 self.mainpyfile = ''
159 self._wait_for_mainpyfile = 0
160
161 # Read $HOME/.pdbrc and ./.pdbrc
162 try:
163 self.rcLines = _file_lines(os.path.join(os.environ['HOME'],
164 ".pdbrc"))
165 except KeyError:
166 self.rcLines = []
167 self.rcLines.extend(_file_lines(".pdbrc"))
168
169 # Create color table: we copy the default one from the traceback
170 # module and add a few attributes needed for debugging
171 self.color_scheme_table = ExceptionColors.copy()
172
173 # shorthands
174 C = ColorANSI.TermColors
175 cst = self.color_scheme_table
98 176
99 cst['NoColor'].colors.breakpoint_enabled = C.NoColor
100 cst['NoColor'].colors.breakpoint_disabled = C.NoColor
177 cst['NoColor'].colors.breakpoint_enabled = C.NoColor
178 cst['NoColor'].colors.breakpoint_disabled = C.NoColor
101 179
102 cst['Linux'].colors.breakpoint_enabled = C.LightRed
103 cst['Linux'].colors.breakpoint_disabled = C.Red
180 cst['Linux'].colors.breakpoint_enabled = C.LightRed
181 cst['Linux'].colors.breakpoint_disabled = C.Red
104 182
105 cst['LightBG'].colors.breakpoint_enabled = C.LightRed
106 cst['LightBG'].colors.breakpoint_disabled = C.Red
183 cst['LightBG'].colors.breakpoint_enabled = C.LightRed
184 cst['LightBG'].colors.breakpoint_disabled = C.Red
107 185
108 self.set_colors(color_scheme)
186 self.set_colors(color_scheme)
109 187
110 188 def set_colors(self, scheme):
111 189 """Shorthand access to the color table scheme selector method."""
@@ -6,7 +6,7 b' Requires Python 2.3 or newer.'
6 6
7 7 This file contains all the classes and helper functions specific to IPython.
8 8
9 $Id: iplib.py 1785 2006-09-26 21:08:22Z vivainio $
9 $Id: iplib.py 1786 2006-09-27 05:47:28Z fperez $
10 10 """
11 11
12 12 #*****************************************************************************
@@ -2029,8 +2029,22 b' want to merge them back into the new files.""" % locals()'
2029 2029 """simple prefilter function, for debugging"""
2030 2030 return self.handle_normal(line,continue_prompt)
2031 2031
2032
2033 def multiline_prefilter(self, line, continue_prompt):
2034 """ Run _prefilter for each line of input
2035
2036 Covers cases where there are multiple lines in the user entry,
2037 which is the case when the user goes back to a multiline history
2038 entry and presses enter.
2039
2040 """
2041 out = []
2042 for l in line.rstrip('\n').split('\n'):
2043 out.append(self._prefilter(l, continue_prompt))
2044 return '\n'.join(out)
2045
2032 2046 # Set the default prefilter() function (this can be user-overridden)
2033 prefilter = _prefilter
2047 prefilter = multiline_prefilter
2034 2048
2035 2049 def handle_normal(self,line,continue_prompt=None,
2036 2050 pre=None,iFun=None,theRest=None):
@@ -32,6 +32,7 b' NOTES:'
32 32
33 33 # Stdlib imports
34 34 import optparse
35 import os
35 36 import sys
36 37
37 38 # Third-party modules.
@@ -105,7 +106,7 b' class InteractiveRunner(object):'
105 106 self.run_source(fobj,interact)
106 107 finally:
107 108 fobj.close()
108
109
109 110 def run_source(self,source,interact=False):
110 111 """Run the given source code interactively.
111 112
@@ -127,8 +128,11 b' class InteractiveRunner(object):'
127 128
128 129 # grab the true write method of stdout, in case anything later
129 130 # reassigns sys.stdout, so that we really are writing to the true
130 # stdout and not to something else.
131 write = sys.stdout.write
131 # stdout and not to something else. We also normalize all strings we
132 # write to use the native OS line separators.
133 linesep = os.linesep
134 stdwrite = sys.stdout.write
135 write = lambda s: stdwrite(s.replace('\r\n',linesep))
132 136
133 137 c = pexpect.spawn(self.program,self.args,timeout=None)
134 138 c.delaybeforesend = self.delaybeforesend
@@ -142,7 +146,9 b' class InteractiveRunner(object):'
142 146 for cmd in source:
143 147 # skip blank lines for all matches to the 'main' prompt, while the
144 148 # secondary prompts do not
145 if prompt_idx==0 and cmd.isspace():
149 if prompt_idx==0 and \
150 (cmd.isspace() or cmd.lstrip().startswith('#')):
151 print cmd,
146 152 continue
147 153
148 154 write(c.after)
@@ -156,9 +162,6 b' class InteractiveRunner(object):'
156 162 break
157 163 write(c.before)
158 164
159 if isinstance(source,file):
160 source.close()
161
162 165 if end_normal:
163 166 if interact:
164 167 c.send('\n')
@@ -232,6 +235,28 b' class PythonRunner(InteractiveRunner):'
232 235 InteractiveRunner.__init__(self,program,prompts,args)
233 236
234 237
238 class DocTestRunner(PythonRunner):
239 """A python runner customized for doctest usage."""
240
241 def run_source(self,source,interact=False):
242 """Run the given source code interactively.
243
244 See the parent docstring for details.
245 """
246
247 # if the source is a string, chop it up in lines so we can iterate
248 # over it just as if it were an open file.
249 if not isinstance(source,file):
250 source = source.splitlines(True)
251
252
253 for line in source:
254 pass
255 # finish by calling the parent run_source method
256 super(DocTestRunner,self).run_source(dsource,interact)
257
258
259
235 260 class SAGERunner(InteractiveRunner):
236 261 """Interactive SAGE runner.
237 262
@@ -60,7 +60,7 b' You can implement other color schemes easily, the syntax is fairly'
60 60 self-explanatory. Please send back new schemes you develop to the author for
61 61 possible inclusion in future releases.
62 62
63 $Id: ultraTB.py 1154 2006-02-11 23:20:05Z fperez $"""
63 $Id: ultraTB.py 1786 2006-09-27 05:47:28Z fperez $"""
64 64
65 65 #*****************************************************************************
66 66 # Copyright (C) 2001 Nathaniel Gray <n8gray@caltech.edu>
@@ -692,7 +692,7 b' class VerboseTB(TBTools):'
692 692 etb = etb.tb_next
693 693 self.pdb.botframe = etb.tb_frame
694 694 self.pdb.interaction(self.tb.tb_frame, self.tb)
695 except:
695 except 'ha': # dbg
696 696 print '*** ERROR ***'
697 697 print 'This version of pdb has a bug and crashed.'
698 698 print 'Returning to IPython...'
General Comments 0
You need to be logged in to leave comments. Login now