[Python-checkins] r83284 - in python/branches/py3k: Doc/library/bdb.rst Lib/bdb.py

georg.brandl python-checkins at python.org
Fri Jul 30 17:01:27 CEST 2010


Author: georg.brandl
Date: Fri Jul 30 17:01:23 2010
New Revision: 83284

Log:
Add Breakpoint.bpformat(), which returns the info usually printed by bpprint().  Necessary for major refactoring of pdb output handling.

Modified:
   python/branches/py3k/Doc/library/bdb.rst
   python/branches/py3k/Lib/bdb.py

Modified: python/branches/py3k/Doc/library/bdb.rst
==============================================================================
--- python/branches/py3k/Doc/library/bdb.rst	(original)
+++ python/branches/py3k/Doc/library/bdb.rst	Fri Jul 30 17:01:23 2010
@@ -50,9 +50,10 @@
       Mark the breakpoint as disabled.
 
 
-   .. method:: bpprint(out=None)
+   .. method:: bpformat()
 
-      Print all the information about the breakpoint:
+      Return a string with all the information about the breakpoint, nicely
+      formatted:
 
       * The breakpoint number.
       * If it is temporary or not.
@@ -61,6 +62,13 @@
       * If it must be ignored the next N times.
       * The breakpoint hit count.
 
+      .. versionadded:: 3.2
+
+   .. method:: bpprint(out=None)
+
+      Print the output of :meth:`bpformat` to the file *out*, or if it is
+      ``None``, to standard output.
+
 
 .. class:: Bdb(skip=None)
 

Modified: python/branches/py3k/Lib/bdb.py
==============================================================================
--- python/branches/py3k/Lib/bdb.py	(original)
+++ python/branches/py3k/Lib/bdb.py	Fri Jul 30 17:01:23 2010
@@ -499,6 +499,9 @@
     def bpprint(self, out=None):
         if out is None:
             out = sys.stdout
+        print(self.bpformat(), file=out)
+
+    def bpformat(self):
         if self.temporary:
             disp = 'del  '
         else:
@@ -507,17 +510,19 @@
             disp = disp + 'yes  '
         else:
             disp = disp + 'no   '
-        print('%-4dbreakpoint   %s at %s:%d' % (self.number, disp,
-                                                       self.file, self.line), file=out)
+        ret = '%-4dbreakpoint   %s at %s:%d' % (self.number, disp,
+                                                self.file, self.line)
         if self.cond:
-            print('\tstop only if %s' % (self.cond,), file=out)
+            ret += '\n\tstop only if %s' % (self.cond,)
         if self.ignore:
-            print('\tignore next %d hits' % (self.ignore), file=out)
-        if (self.hits):
-            if (self.hits > 1): ss = 's'
-            else: ss = ''
-            print(('\tbreakpoint already hit %d time%s' %
-                          (self.hits, ss)), file=out)
+            ret += '\n\tignore next %d hits' % (self.ignore,)
+        if self.hits:
+            if self.hits > 1:
+                ss = 's'
+            else:
+                ss = ''
+            ret += '\n\tbreakpoint already hit %d time%s' % (self.hits, ss)
+        return ret
 
     def __str__(self):
         return 'breakpoint %s at %s:%s' % (self.number, self.file, self.line)


More information about the Python-checkins mailing list