[svn r57535] extending hacks for a safe representation of objects

to also work for broken __repr__s on newstyle classes.

--HG--
branch : trunk
This commit is contained in:
hpk
2008-08-21 11:48:46 +02:00
parent d5e61e470d
commit 5f666c99b7
3 changed files with 19 additions and 2 deletions

View File

@@ -30,10 +30,17 @@ class SafeRepr(repr.Repr):
# Do we need a commandline switch for this?
self.maxstring = 240 # 3 * 80 chars
self.maxother = 160 # 2 * 80 chars
def repr(self, x):
return self._callhelper(repr.Repr.repr, self, x)
def repr_instance(self, x, level):
return self._callhelper(__builtin__.repr, x)
def _callhelper(self, call, x, *args):
try:
# Try the vanilla repr and make sure that the result is a string
s = str(__builtin__.repr(x))
s = call(x, *args)
except (KeyboardInterrupt, MemoryError, SystemExit):
raise
except Exception ,e:
@@ -60,4 +67,5 @@ class SafeRepr(repr.Repr):
s = s[:i] + '...' + s[len(s)-j:]
return s
_repr = SafeRepr().repr