utils.saferepr

Streaming, truncating, non-recursive version of repr().

Differences from regular repr():

  • Sets are represented the Python 3 way: {1, 2} vs set([1, 2]).
  • Unicode strings does not have the u' prefix, even on Python 2.
  • Empty set formatted as set() (Python 3), not set([]) (Python 2).
  • Longs don’t have the L suffix.

Very slow with no limits, super quick with limits.

Module Contents

Functions

saferepr(o,maxlen=None,maxlevels=3,seen=None) Safe version of repr().
_chaindict(mapping,LIT_DICT_KVSEP=LIT_DICT_KVSEP,LIT_LIST_SEP=LIT_LIST_SEP)
_chainlist(it,LIT_LIST_SEP=LIT_LIST_SEP)
_repr_empty_set(s)
_safetext(val)
_format_binary_bytes(val,maxlen,ellipsis=”…”)
_bytes_prefix(s)
_repr_binary_bytes(val)
_format_chars(val,maxlen)
_repr(obj)
_saferepr(o,maxlen=None,maxlevels=3,seen=None)
_reprseq(val,lit_start,lit_end,builtin_type,chainer)
reprstream(stack,seen=None,maxlevels=3,level=0,isinstance=isinstance) Streaming repr, yielding tokens.
saferepr(o, maxlen=None, maxlevels=3, seen=None)

Safe version of repr().

Warning:
Make sure you set the maxlen argument, or it will be very slow for recursive objects. With the maxlen set, it’s often faster than built-in repr.
_chaindict(mapping, LIT_DICT_KVSEP=LIT_DICT_KVSEP, LIT_LIST_SEP=LIT_LIST_SEP)
_chainlist(it, LIT_LIST_SEP=LIT_LIST_SEP)
_repr_empty_set(s)
_safetext(val)
_format_binary_bytes(val, maxlen, ellipsis="...")
_bytes_prefix(s)
_repr_binary_bytes(val)
_format_chars(val, maxlen)
_repr(obj)
_saferepr(o, maxlen=None, maxlevels=3, seen=None)
_reprseq(val, lit_start, lit_end, builtin_type, chainer)
reprstream(stack, seen=None, maxlevels=3, level=0, isinstance=isinstance)

Streaming repr, yielding tokens.