Coverage for .tox/testcoverage/lib/python2.7/site-packages/py/_io/saferepr : 37%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" subclass of repr.Repr that limits the resulting size of repr() and includes information on exceptions raised during the call. """
# Strictly speaking wrong on narrow builds def repr(u): if "'" not in u: return py.builtin._totext("'%s'") % u elif '"' not in u: return py.builtin._totext('"%s"') % u else: return py.builtin._totext("'%s'") % u.replace("'", r"\'") s = repr(x[:self.maxstring]) if len(s) > self.maxstring: i = max(0, (self.maxstring-3)//2) j = max(0, self.maxstring-3-i) s = repr(x[:i] + x[len(x)-j:]) s = s[:i] + '...' + s[len(s)-j:] return s
return self._callhelper(builtin_repr, x)
# Try the vanilla repr and make sure that the result is a string except py.builtin._sysex: raise except: cls, e, tb = sys.exc_info() exc_name = getattr(cls, '__name__', 'unknown') try: exc_info = str(e) except py.builtin._sysex: raise except: exc_info = 'unknown' return '<[%s("%s") raised in repr()] %s object at 0x%x>' % ( exc_name, exc_info, x.__class__.__name__, id(x)) else: i = max(0, (self.maxsize-3)//2) j = max(0, self.maxsize-3-i) s = s[:i] + '...' + s[len(s)-j:]
""" return a size-limited safe repr-string for the given object. Failing __repr__ functions of user instances will be represented with a short exception info and 'saferepr' generally takes care to never raise exceptions itself. This function is a wrapper around the Repr/reprlib functionality of the standard 2.6 lib. """ # review exception handling |