Mailing List Archive

python/dist/src/Lib pdb.py,1.57,1.58
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv31684

Modified Files:
pdb.py
Log Message:
Implement a `pp' command, which is like `p' except that it
pretty-prints the value of its expression argument.


Index: pdb.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pdb.py,v
retrieving revision 1.57
retrieving revision 1.58
diff -C2 -d -r1.57 -r1.58
*** pdb.py 10 Sep 2002 21:57:14 -0000 1.57
--- pdb.py 5 Nov 2002 22:40:20 -0000 1.58
***************
*** 12,15 ****
--- 12,16 ----
import os
import re
+ import pprint

# Create a custom safe Repr instance and increase its maxstring.
***************
*** 533,549 ****
do_rv = do_retval

! def do_p(self, arg):
try:
! value = eval(arg, self.curframe.f_globals,
! self.curframe.f_locals)
except:
t, v = sys.exc_info()[:2]
! if type(t) == type(''):
exc_type_name = t
else: exc_type_name = t.__name__
print '***', exc_type_name + ':', `v`
! return

! print `value`

def do_list(self, arg):
--- 534,560 ----
do_rv = do_retval

! def _getval(self, arg):
try:
! return eval(arg, self.curframe.f_globals,
! self.curframe.f_locals)
except:
t, v = sys.exc_info()[:2]
! if isinstance(t, str):
exc_type_name = t
else: exc_type_name = t.__name__
print '***', exc_type_name + ':', `v`
! raise

! def do_p(self, arg):
! try:
! print repr(self._getval(arg))
! except:
! pass
!
! def do_pp(self, arg):
! try:
! pprint.pprint(self._getval(arg))
! except:
! pass

def do_list(self, arg):
***************
*** 817,820 ****
--- 828,835 ----
print """p expression
Print the value of the expression."""
+
+ def help_pp(self):
+ print """pp expression
+ Pretty-print the value of the expression."""

def help_exec(self):