[Python-checkins] python/dist/src/Lib pprint.py,1.23,1.24
fdrake@users.sourceforge.net
fdrake@users.sourceforge.net
Mon, 30 Dec 2002 23:14:22 -0800
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv15282
Modified Files:
pprint.py
Log Message:
- PrettyPrinter.isreadable(), .isrecursive():
Pass the right number of args to .format(). (Caught by
pychecker.)
- Protect the global namespace more carefully.
- Don't use the types module now that we don't need to.
Index: pprint.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pprint.py,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** pprint.py 8 Jul 2002 12:28:06 -0000 1.23
--- pprint.py 31 Dec 2002 07:14:18 -0000 1.24
***************
*** 35,45 ****
"""
! from types import DictType, ListType, TupleType, StringType
! import sys
! try:
! from cStringIO import StringIO
! except ImportError:
! from StringIO import StringIO
__all__ = ["pprint","pformat","isreadable","isrecursive","saferepr",
--- 35,41 ----
"""
! import sys as _sys
! from cStringIO import StringIO as _StringIO
__all__ = ["pprint","pformat","isreadable","isrecursive","saferepr",
***************
*** 48,52 ****
# cache these for faster access:
_commajoin = ", ".join
- _sys_modules = sys.modules
_id = id
_len = len
--- 44,47 ----
***************
*** 105,109 ****
self._stream = stream
else:
! self._stream = sys.stdout
def pprint(self, object):
--- 100,104 ----
self._stream = stream
else:
! self._stream = _sys.stdout
def pprint(self, object):
***************
*** 111,123 ****
def pformat(self, object):
! sio = StringIO()
self._format(object, sio, 0, 0, {}, 0)
return sio.getvalue()
def isrecursive(self, object):
! return self.format(object, {}, 0)[2]
def isreadable(self, object):
! s, readable, recursive = self.format(object, {}, 0)
return readable and not recursive
--- 106,118 ----
def pformat(self, object):
! sio = _StringIO()
self._format(object, sio, 0, 0, {}, 0)
return sio.getvalue()
def isrecursive(self, object):
! return self.format(object, {}, 0, 0)[2]
def isreadable(self, object):
! s, readable, recursive = self.format(object, {}, 0, 0)
return readable and not recursive
***************
*** 136,140 ****
if sepLines:
! if typ is DictType:
write('{')
if self._indent_per_level > 1:
--- 131,135 ----
if sepLines:
! if typ is dict:
write('{')
if self._indent_per_level > 1:
***************
*** 163,168 ****
return
! if typ is ListType or typ is TupleType:
! if typ is ListType:
write('[')
endchar = ']'
--- 158,163 ----
return
! if typ is list or typ is tuple:
! if typ is list:
write('[')
endchar = ']'
***************
*** 185,189 ****
indent = indent - self._indent_per_level
del context[objid]
! if typ is TupleType and length == 1:
write(',')
write(endchar)
--- 180,184 ----
indent = indent - self._indent_per_level
del context[objid]
! if typ is tuple and length == 1:
write(',')
write(endchar)
***************
*** 213,218 ****
def _safe_repr(object, context, maxlevels, level):
typ = _type(object)
! if typ is StringType:
! if 'locale' not in _sys_modules:
return `object`, True, False
if "'" in object and '"' not in object:
--- 208,213 ----
def _safe_repr(object, context, maxlevels, level):
typ = _type(object)
! if typ is str:
! if 'locale' not in _sys.modules:
return `object`, True, False
if "'" in object and '"' not in object:
***************
*** 223,227 ****
quotes = {"'": "\\'"}
qget = quotes.get
! sio = StringIO()
write = sio.write
for char in object:
--- 218,222 ----
quotes = {"'": "\\'"}
qget = quotes.get
! sio = _StringIO()
write = sio.write
for char in object:
***************
*** 232,236 ****
return ("%s%s%s" % (closure, sio.getvalue(), closure)), True, False
! if typ is DictType:
if not object:
return "{}", True, False
--- 227,231 ----
return ("%s%s%s" % (closure, sio.getvalue(), closure)), True, False
! if typ is dict:
if not object:
return "{}", True, False
***************
*** 257,262 ****
return "{%s}" % _commajoin(components), readable, recursive
! if typ is ListType or typ is TupleType:
! if typ is ListType:
if not object:
return "[]", True, False
--- 252,257 ----
return "{%s}" % _commajoin(components), readable, recursive
! if typ is list or typ is tuple:
! if typ is list:
if not object:
return "[]", True, False