def my_safe_repr(object, context, maxlevels, level): typ = pprint._type(object) if typ is unicode: r = 'u"%s"' % (object.encode("utf8").replace('"', r'\"')) return (r, True, False) else: return pprint._safe_repr(object, context, maxlevels, level)
def ascii_format(object_, context, maxlevels, level): typ = pprint._type(object_) if typ is unicode: object_ = str(object_).replace('"', '\\"') # replace " to ' rep = "\"%s\"" % object_ # repr(object_) return rep, (rep and not rep.startswith('<')), False return pprint._safe_repr(object_, context, maxlevels, level)
def pprintFormatter(thing, context, maxlevels, level): typ = pprint._type(thing) if typ is unicode: thing = str(thing) return pprint._safe_repr(thing, context, maxlevels, level)
def format_print(object, context, maxlevels, level): typ = pprint._type(object) if typ is unicode: object = str(object) return pprint._safe_repr(object, context, maxlevels, level)
def my_safe_repr(object, context, maxlevels, level): typ = pprint._type(object) if typ is unicode: object = str(object) return pprint._safe_repr(object, context, maxlevels, level)
def no_unicode(object, context, maxlevels, level): """ change unicode u'foo' to string 'foo' when pretty printing""" if pprint._type(object) is unicode: object = str(object) return pprint._safe_repr(object, context, maxlevels, level)
def concat(object, context, maxlevels, level): """ Concatenate any string which pprint displays. This is recursive, so it also should apply to dictionary keys and values, for example.""" if pprint._type(object) is (unicode or str): if len(object) > pprint_concatenation_length: object = object[:pprint_concatenation_length] + '...' return pprint._safe_repr(object, context, maxlevels, level)
def suppress_unicode_repr(object, context, maxlevels, level): typ = pprint._type(object) if typ is unicode: object = str(object) return pprint._safe_repr(object, context, maxlevels, level)
def my_safe_repr(object, context, maxlevels, level): typ = pprint._type(object) if typ is unicode: object = str(object.encode('utf-8')) return pprint._safe_repr(object, context, maxlevels, level)
def de_unicode(object, context, maxlevels, level): if pprint._type(object) is unicode: object = str(object) return pprint._safe_repr(object, context, maxlevels, level)