Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 469d3e7

Browse files
committed
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
svn+ssh://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 d343286 commit 469d3e7

8 files changed

Lines changed: 122 additions & 14 deletions

File tree

Doc/library/ftplib.rst

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

187187

188188
.. 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:
@@ -165,10 +167,12 @@ def user_exception(self, frame, exc_info):
165167
but only if we are to stop at or just below this level."""
166168
pass
167169

168-
def _set_stopinfo(self, stopframe, returnframe, stoplineno=-1):
170+
def _set_stopinfo(self, stopframe, returnframe, stoplineno=0):
169171
self.stopframe = stopframe
170172
self.returnframe = returnframe
171173
self.quitting = 0
174+
# stoplineno >= 0 means: stop at line >= the stoplineno
175+
# stoplineno -1 means: don't stop at all
172176
self.stoplineno = stoplineno
173177

174178
# Derived classes and clients can call the following methods
@@ -181,7 +185,7 @@ def set_until(self, frame): #the name "until" is borrowed from gdb
181185

182186
def set_step(self):
183187
"""Stop after one line of code."""
184-
self._set_stopinfo(None,None)
188+
self._set_stopinfo(None, None)
185189

186190
def set_next(self, frame):
187191
"""Stop on the next line in or below the given frame."""
@@ -208,7 +212,7 @@ def set_trace(self, frame=None):
208212

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

Lib/doctest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ def __init__(self, out):
318318
self.__out = out
319319
self.__debugger_used = False
320320
pdb.Pdb.__init__(self, stdout=out)
321+
# still use input() to get user input
322+
self.use_rawinput = 1
321323

322324
def set_trace(self, frame=None):
323325
self.__debugger_used = True
@@ -1379,12 +1381,17 @@ def out(s):
13791381
self.save_linecache_getlines = linecache.getlines
13801382
linecache.getlines = self.__patched_linecache_getlines
13811383

1384+
# Make sure sys.displayhook just prints the value to stdout
1385+
save_displayhook = sys.displayhook
1386+
sys.displayhook = sys.__displayhook__
1387+
13821388
try:
13831389
return self.__run(test, compileflags, out)
13841390
finally:
13851391
sys.stdout = save_stdout
13861392
pdb.set_trace = save_set_trace
13871393
linecache.getlines = self.save_linecache_getlines
1394+
sys.displayhook = save_displayhook
13881395
if clear_globs:
13891396
test.globs.clear()
13901397
import builtins

Lib/pdb.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,17 @@ 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('--Return--', file=self.stdout)
188190
self.interaction(frame, None)
189191

190192
def user_exception(self, frame, exc_info):
191193
"""This function is called if an exception occurs,
192194
but only if we are to stop at or just below this level."""
195+
if self._wait_for_mainpyfile:
196+
return
193197
exc_type, exc_value, exc_traceback = exc_info
194198
frame.f_locals['__exception__'] = exc_type, exc_value
195199
exc_type_name = exc_type.__name__
@@ -275,16 +279,18 @@ def onecmd(self, line):
275279
return self.handle_command_def(line)
276280

277281
def handle_command_def(self,line):
278-
""" Handles one command line during command list definition. """
282+
"""Handles one command line during command list definition."""
279283
cmd, arg, line = self.parseline(line)
284+
if not cmd:
285+
return
280286
if cmd == 'silent':
281287
self.commands_silent[self.commands_bnum] = True
282288
return # continue to handle other cmd def in the cmd list
283289
elif cmd == 'end':
284290
self.cmdqueue = []
285291
return 1 # end of cmd list
286292
cmdlist = self.commands[self.commands_bnum]
287-
if (arg):
293+
if arg:
288294
cmdlist.append(cmd+' '+arg)
289295
else:
290296
cmdlist.append(cmd)
@@ -327,9 +333,11 @@ def do_commands(self, arg):
327333
prompt_back = self.prompt
328334
self.prompt = '(com) '
329335
self.commands_defining = True
330-
self.cmdloop()
331-
self.commands_defining = False
332-
self.prompt = prompt_back
336+
try:
337+
self.cmdloop()
338+
finally:
339+
self.commands_defining = False
340+
self.prompt = prompt_back
333341

334342
def do_break(self, arg, temporary = 0):
335343
# break [ ([filename:]lineno | function) [, "condition"] ]
@@ -465,7 +473,10 @@ def checkline(self, filename, lineno):
465473
Return `lineno` if it is, 0 if not (e.g. a docstring, comment, blank
466474
line or EOF). Warning: testing is not comprehensive.
467475
"""
468-
line = linecache.getline(filename, lineno, self.curframe.f_globals)
476+
# this method should be callable before starting debugging, so default
477+
# to "no globals" if there is no current frame
478+
globs = self.curframe.f_globals if hasattr(self, 'curframe') else None
479+
line = linecache.getline(filename, lineno, globs)
469480
if not line:
470481
print('End of file', file=self.stdout)
471482
return 0
@@ -1293,7 +1304,7 @@ def main():
12931304
# changed by the user from the command line. There is a "restart" command
12941305
# which allows explicit specification of command line arguments.
12951306
pdb = Pdb()
1296-
while 1:
1307+
while True:
12971308
try:
12981309
pdb._runscript(mainpyfile)
12991310
if pdb._user_requested_quit:

Lib/test/test_doctest.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,35 @@ def exceptions(): r"""
906906
...
907907
ZeroDivisionError: integer division or modulo by zero
908908
TestResults(failed=1, attempted=1)
909+
"""
910+
def displayhook(): r"""
911+
Test that changing sys.displayhook doesn't matter for doctest.
912+
913+
>>> import sys
914+
>>> orig_displayhook = sys.displayhook
915+
>>> def my_displayhook(x):
916+
... print('hi!')
917+
>>> sys.displayhook = my_displayhook
918+
>>> def f():
919+
... '''
920+
... >>> 3
921+
... 3
922+
... '''
923+
>>> test = doctest.DocTestFinder().find(f)[0]
924+
>>> r = doctest.DocTestRunner(verbose=False).run(test)
925+
>>> post_displayhook = sys.displayhook
926+
927+
We need to restore sys.displayhook now, so that we'll be able to test
928+
results.
929+
930+
>>> sys.displayhook = orig_displayhook
931+
932+
Ok, now we can check that everything is ok.
933+
934+
>>> r
935+
TestResults(failed=0, attempted=1)
936+
>>> post_displayhook is my_displayhook
937+
True
909938
"""
910939
def optionflags(): r"""
911940
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
support.run_doctest(test_pdb, verbosity=True)

Misc/NEWS

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@ Library
8787
- Issue #7909: Do not touch paths with the special prefixes ``\\.\``
8888
or ``\\?\`` in ntpath.normpath().
8989

90+
- Issue #5294: Fix the behavior of pdb's "continue" command when called
91+
in the top-level debugged frame.
92+
93+
- Issue #5727: Restore the ability to use readline when calling into pdb
94+
in doctests.
95+
96+
- Issue #6719: In pdb, do not stop somewhere in the encodings machinery
97+
if the source file to be debugged is in a non-builtin encoding.
98+
99+
- Issue #8048: Prevent doctests from failing when sys.displayhook has
100+
been reassigned.
101+
102+
- Issue #8015: In pdb, do not crash when an empty line is entered as
103+
a breakpoint command.
104+
90105
- Issue #5146: Handle UID THREAD command correctly in imaplib.
91106

92107
- Issue #5147: Fix the header generated for cookie files written by

Misc/maintainers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ optparse aronacher
147147
os loewis
148148
ossaudiodev
149149
parser
150-
pdb
150+
pdb georg.brandl
151151
pickle alexandre.vassalotti, pitrou
152152
pickletools alexandre.vassalotti
153153
pipes

0 commit comments

Comments
 (0)