Skip to content

Commit 5077599

Browse files
committed
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r83259 | georg.brandl | 2010-07-30 09:03:39 +0200 (Fr, 30 Jul 2010) | 1 line Clarification. ........ r83261 | georg.brandl | 2010-07-30 09:21:26 +0200 (Fr, 30 Jul 2010) | 1 line #9230: allow Pdb.checkline() to be called without a current frame, for setting breakpoints before starting debugging. ........ r83264 | georg.brandl | 2010-07-30 10:45:26 +0200 (Fr, 30 Jul 2010) | 1 line Document the "jump" command in pdb.__doc__, and add a version tag for "until X". ........ r83265 | georg.brandl | 2010-07-30 10:54:49 +0200 (Fr, 30 Jul 2010) | 1 line #8015: fix crash when entering an empty line for breakpoint commands. Also restore environment properly when an exception occurs during the definition of commands. ........ r83268 | georg.brandl | 2010-07-30 11:23:23 +0200 (Fr, 30 Jul 2010) | 2 lines Issue #8048: Prevent doctests from failing when sys.displayhook has been reassigned. ........ r83269 | georg.brandl | 2010-07-30 11:43:00 +0200 (Fr, 30 Jul 2010) | 1 line #6719: In pdb, do not stop somewhere in the encodings machinery if the source file to be debugged is in a non-builtin encoding. ........ r83271 | georg.brandl | 2010-07-30 11:59:28 +0200 (Fr, 30 Jul 2010) | 1 line #5727: Restore the ability to use readline when calling into pdb in doctests. ........ r83272 | georg.brandl | 2010-07-30 12:29:19 +0200 (Fr, 30 Jul 2010) | 1 line #5294: Fix the behavior of pdb "continue" command when called in the top-level debugged frame. ........ r83281 | georg.brandl | 2010-07-30 15:36:43 +0200 (Fr, 30 Jul 2010) | 1 line Add myself for pdb. ........
1 parent f59f9b1 commit 5077599

8 files changed

Lines changed: 123 additions & 15 deletions

File tree

Doc/library/ftplib.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ followed by ``lines`` for the text version or ``binary`` for the binary version.
220220
Retrieve a file or directory listing in ASCII transfer mode. *command*
221221
should be an appropriate ``RETR`` command (see :meth:`retrbinary`) or a
222222
command such as ``LIST``, ``NLST`` or ``MLSD`` (usually just the string
223-
``'LIST'``). The *callback* function is called for each line, with the
224-
trailing CRLF stripped. The default *callback* prints the line to
225-
``sys.stdout``.
223+
``'LIST'``). The *callback* function is called for each line with a
224+
string argument containing the line with the trailing CRLF stripped.
225+
The default *callback* prints the line to ``sys.stdout``.
226226

227227

228228
.. method:: FTP.set_pasv(boolean)

Lib/bdb.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ def stop_here(self, frame):
109109
self.is_skipped_module(frame.f_globals.get('__name__')):
110110
return False
111111
if frame is self.stopframe:
112+
if self.stoplineno == -1:
113+
return False
112114
return frame.f_lineno >= self.stoplineno
113115
while frame is not None and frame is not self.stopframe:
114116
if frame is self.botframe:
@@ -166,10 +168,12 @@ def user_exception(self, frame, exc_info):
166168
but only if we are to stop at or just below this level."""
167169
pass
168170

169-
def _set_stopinfo(self, stopframe, returnframe, stoplineno=-1):
171+
def _set_stopinfo(self, stopframe, returnframe, stoplineno=0):
170172
self.stopframe = stopframe
171173
self.returnframe = returnframe
172174
self.quitting = 0
175+
# stoplineno >= 0 means: stop at line >= the stoplineno
176+
# stoplineno -1 means: don't stop at all
173177
self.stoplineno = stoplineno
174178

175179
# Derived classes and clients can call the following methods
@@ -182,7 +186,7 @@ def set_until(self, frame): #the name "until" is borrowed from gdb
182186

183187
def set_step(self):
184188
"""Stop after one line of code."""
185-
self._set_stopinfo(None,None)
189+
self._set_stopinfo(None, None)
186190

187191
def set_next(self, frame):
188192
"""Stop on the next line in or below the given frame."""
@@ -209,7 +213,7 @@ def set_trace(self, frame=None):
209213

210214
def set_continue(self):
211215
# Don't stop except at breakpoints or when finished
212-
self._set_stopinfo(self.botframe, None)
216+
self._set_stopinfo(self.botframe, None, -1)
213217
if not self.breaks:
214218
# no breakpoints; run without debugger overhead
215219
sys.settrace(None)

Lib/doctest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ def __init__(self, out):
335335
self.__out = out
336336
self.__debugger_used = False
337337
pdb.Pdb.__init__(self, stdout=out)
338+
# still use input() to get user input
339+
self.use_rawinput = 1
338340

339341
def set_trace(self, frame=None):
340342
self.__debugger_used = True
@@ -1381,12 +1383,17 @@ def run(self, test, compileflags=None, out=None, clear_globs=True):
13811383
self.save_linecache_getlines = linecache.getlines
13821384
linecache.getlines = self.__patched_linecache_getlines
13831385

1386+
# Make sure sys.displayhook just prints the value to stdout
1387+
save_displayhook = sys.displayhook
1388+
sys.displayhook = sys.__displayhook__
1389+
13841390
try:
13851391
return self.__run(test, compileflags, out)
13861392
finally:
13871393
sys.stdout = save_stdout
13881394
pdb.set_trace = save_set_trace
13891395
linecache.getlines = self.save_linecache_getlines
1396+
sys.displayhook = save_displayhook
13901397
if clear_globs:
13911398
test.globs.clear()
13921399

Lib/pdb.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,18 @@ def bp_commands(self,frame):
183183

184184
def user_return(self, frame, return_value):
185185
"""This function is called when a return trap is set here."""
186+
if self._wait_for_mainpyfile:
187+
return
186188
frame.f_locals['__return__'] = return_value
187189
print >>self.stdout, '--Return--'
188190
self.interaction(frame, None)
189191

190192
def user_exception(self, frame, exc_info):
191-
exc_type, exc_value, exc_traceback = exc_info
192193
"""This function is called if an exception occurs,
193194
but only if we are to stop at or just below this level."""
195+
if self._wait_for_mainpyfile:
196+
return
197+
exc_type, exc_value, exc_traceback = exc_info
194198
frame.f_locals['__exception__'] = exc_type, exc_value
195199
if type(exc_type) == type(''):
196200
exc_type_name = exc_type
@@ -277,16 +281,18 @@ def onecmd(self, line):
277281
return self.handle_command_def(line)
278282

279283
def handle_command_def(self,line):
280-
""" Handles one command line during command list definition. """
284+
"""Handles one command line during command list definition."""
281285
cmd, arg, line = self.parseline(line)
286+
if not cmd:
287+
return
282288
if cmd == 'silent':
283289
self.commands_silent[self.commands_bnum] = True
284290
return # continue to handle other cmd def in the cmd list
285291
elif cmd == 'end':
286292
self.cmdqueue = []
287293
return 1 # end of cmd list
288294
cmdlist = self.commands[self.commands_bnum]
289-
if (arg):
295+
if arg:
290296
cmdlist.append(cmd+' '+arg)
291297
else:
292298
cmdlist.append(cmd)
@@ -329,9 +335,11 @@ def do_commands(self, arg):
329335
prompt_back = self.prompt
330336
self.prompt = '(com) '
331337
self.commands_defining = True
332-
self.cmdloop()
333-
self.commands_defining = False
334-
self.prompt = prompt_back
338+
try:
339+
self.cmdloop()
340+
finally:
341+
self.commands_defining = False
342+
self.prompt = prompt_back
335343

336344
def do_break(self, arg, temporary = 0):
337345
# break [ ([filename:]lineno | function) [, "condition"] ]
@@ -467,7 +475,10 @@ def checkline(self, filename, lineno):
467475
Return `lineno` if it is, 0 if not (e.g. a docstring, comment, blank
468476
line or EOF). Warning: testing is not comprehensive.
469477
"""
470-
line = linecache.getline(filename, lineno, self.curframe.f_globals)
478+
# this method should be callable before starting debugging, so default
479+
# to "no globals" if there is no current frame
480+
globs = self.curframe.f_globals if hasattr(self, 'curframe') else None
481+
line = linecache.getline(filename, lineno, globs)
471482
if not line:
472483
print >>self.stdout, 'End of file'
473484
return 0
@@ -1298,7 +1309,7 @@ def main():
12981309
# changed by the user from the command line. There is a "restart" command
12991310
# which allows explicit specification of command line arguments.
13001311
pdb = Pdb()
1301-
while 1:
1312+
while True:
13021313
try:
13031314
pdb._runscript(mainpyfile)
13041315
if pdb._user_requested_quit:

Lib/test/test_doctest.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,35 @@ def exceptions(): r"""
980980
...
981981
ZeroDivisionError: integer division or modulo by zero
982982
TestResults(failed=1, attempted=1)
983+
"""
984+
def displayhook(): r"""
985+
Test that changing sys.displayhook doesn't matter for doctest.
986+
987+
>>> import sys
988+
>>> orig_displayhook = sys.displayhook
989+
>>> def my_displayhook(x):
990+
... print('hi!')
991+
>>> sys.displayhook = my_displayhook
992+
>>> def f():
993+
... '''
994+
... >>> 3
995+
... 3
996+
... '''
997+
>>> test = doctest.DocTestFinder().find(f)[0]
998+
>>> r = doctest.DocTestRunner(verbose=False).run(test)
999+
>>> post_displayhook = sys.displayhook
1000+
1001+
We need to restore sys.displayhook now, so that we'll be able to test
1002+
results.
1003+
1004+
>>> sys.displayhook = orig_displayhook
1005+
1006+
Ok, now we can check that everything is ok.
1007+
1008+
>>> r
1009+
TestResults(failed=0, attempted=1)
1010+
>>> post_displayhook is my_displayhook
1011+
True
9831012
"""
9841013
def optionflags(): r"""
9851014
Tests of `DocTestRunner`'s option flag handling.

Lib/test/test_pdb.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,48 @@ def test_pdb_skip_modules_with_callback():
126126
"""
127127

128128

129+
def test_pdb_continue_in_bottomframe():
130+
"""Test that "continue" and "next" work properly in bottom frame (issue #5294).
131+
132+
>>> def test_function():
133+
... import pdb, sys; inst = pdb.Pdb()
134+
... inst.set_trace()
135+
... inst.botframe = sys._getframe() # hackery to get the right botframe
136+
... print(1)
137+
... print(2)
138+
... print(3)
139+
... print(4)
140+
141+
>>> with PdbTestInput([
142+
... 'next',
143+
... 'break 7',
144+
... 'continue',
145+
... 'next',
146+
... 'continue',
147+
... 'continue',
148+
... ]):
149+
... test_function()
150+
> <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(4)test_function()
151+
-> inst.botframe = sys._getframe() # hackery to get the right botframe
152+
(Pdb) next
153+
> <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(5)test_function()
154+
-> print(1)
155+
(Pdb) break 7
156+
Breakpoint 1 at <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>:7
157+
(Pdb) continue
158+
1
159+
2
160+
> <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(7)test_function()
161+
-> print(3)
162+
(Pdb) next
163+
3
164+
> <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(8)test_function()
165+
-> print(4)
166+
(Pdb) continue
167+
4
168+
"""
169+
170+
129171
def test_main():
130172
from test import test_pdb
131173
test_support.run_doctest(test_pdb, verbosity=True)

Misc/NEWS

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ Core and Builtins
2424
Library
2525
-------
2626

27+
- Issue #5294: Fix the behavior of pdb's "continue" command when called
28+
in the top-level debugged frame.
29+
30+
- Issue #5727: Restore the ability to use readline when calling into pdb
31+
in doctests.
32+
33+
- Issue #6719: In pdb, do not stop somewhere in the encodings machinery
34+
if the source file to be debugged is in a non-builtin encoding.
35+
36+
- Issue #8048: Prevent doctests from failing when sys.displayhook has
37+
been reassigned.
38+
39+
- Issue #8015: In pdb, do not crash when an empty line is entered as
40+
a breakpoint command.
41+
2742
- Issue #9448: Fix a leak of OS resources (mutexes or semaphores) when
2843
re-initializing a buffered IO object by calling its ``__init__`` method.
2944

Misc/maintainers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ optparse aronacher
151151
os loewis
152152
ossaudiodev
153153
parser
154-
pdb
154+
pdb georg.brandl
155155
pickle alexandre.vassalotti, pitrou
156156
pickletools alexandre.vassalotti
157157
pipes

0 commit comments

Comments
 (0)