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

Skip to content

Commit d2fd4ca

Browse files
committed
Add Breakpoint.bpformat(), which returns the info usually printed by bpprint(). Necessary for major refactoring of pdb output handling.
1 parent 6cccb86 commit d2fd4ca

2 files changed

Lines changed: 24 additions & 11 deletions

File tree

Doc/library/bdb.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ The :mod:`bdb` module also defines two classes:
5050
Mark the breakpoint as disabled.
5151

5252

53-
.. method:: bpprint(out=None)
53+
.. method:: bpformat()
5454

55-
Print all the information about the breakpoint:
55+
Return a string with all the information about the breakpoint, nicely
56+
formatted:
5657

5758
* The breakpoint number.
5859
* If it is temporary or not.
@@ -61,6 +62,13 @@ The :mod:`bdb` module also defines two classes:
6162
* If it must be ignored the next N times.
6263
* The breakpoint hit count.
6364

65+
.. versionadded:: 3.2
66+
67+
.. method:: bpprint(out=None)
68+
69+
Print the output of :meth:`bpformat` to the file *out*, or if it is
70+
``None``, to standard output.
71+
6472

6573
.. class:: Bdb(skip=None)
6674

Lib/bdb.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,9 @@ def disable(self):
499499
def bpprint(self, out=None):
500500
if out is None:
501501
out = sys.stdout
502+
print(self.bpformat(), file=out)
503+
504+
def bpformat(self):
502505
if self.temporary:
503506
disp = 'del '
504507
else:
@@ -507,17 +510,19 @@ def bpprint(self, out=None):
507510
disp = disp + 'yes '
508511
else:
509512
disp = disp + 'no '
510-
print('%-4dbreakpoint %s at %s:%d' % (self.number, disp,
511-
self.file, self.line), file=out)
513+
ret = '%-4dbreakpoint %s at %s:%d' % (self.number, disp,
514+
self.file, self.line)
512515
if self.cond:
513-
print('\tstop only if %s' % (self.cond,), file=out)
516+
ret += '\n\tstop only if %s' % (self.cond,)
514517
if self.ignore:
515-
print('\tignore next %d hits' % (self.ignore), file=out)
516-
if (self.hits):
517-
if (self.hits > 1): ss = 's'
518-
else: ss = ''
519-
print(('\tbreakpoint already hit %d time%s' %
520-
(self.hits, ss)), file=out)
518+
ret += '\n\tignore next %d hits' % (self.ignore,)
519+
if self.hits:
520+
if self.hits > 1:
521+
ss = 's'
522+
else:
523+
ss = ''
524+
ret += '\n\tbreakpoint already hit %d time%s' % (self.hits, ss)
525+
return ret
521526

522527
def __str__(self):
523528
return 'breakpoint %s at %s:%s' % (self.number, self.file, self.line)

0 commit comments

Comments
 (0)