'Get a repr-like string for the data, but truncate it at "maxlen" bytes
(ending the object graph traversal as soon as you do)'

def get_truncated_repr(self, maxlen):

    out = TruncatedStringIO(maxlen)
    try:
        self.write_repr(out, set())
    except StringTruncated:
        return (out.getvalue() + '...(truncated)')
    return out.getvalue()
