diff -r e7f6cef7a4cc Lib/pprint.py --- a/Lib/pprint.py Tue Aug 13 20:18:52 2013 +0200 +++ b/Lib/pprint.py Wed Aug 14 22:38:12 2013 +0300 @@ -294,24 +294,8 @@ def _safe_repr(object, context, maxlevels, level): typ = _type(object) - if typ is str: - if 'locale' not in _sys.modules: - return repr(object), True, False - if "'" in object and '"' not in object: - closure = '"' - quotes = {'"': '\\"'} - else: - closure = "'" - quotes = {"'": "\\'"} - qget = quotes.get - sio = _StringIO() - write = sio.write - for char in object: - if char.isalpha(): - write(char) - else: - write(qget(char, repr(char)[1:-1])) - return ("%s%s%s" % (closure, sio.getvalue(), closure)), True, False + if typ in _builtin_scalars: + return repr(object), True, False r = getattr(typ, "__repr__", None) if issubclass(typ, dict) and r is dict.__repr__: @@ -376,6 +360,8 @@ rep = repr(object) return rep, (rep and not rep.startswith('<')), False +_builtin_scalars = frozenset({str, bytes, bytearray, int, float, complex, + bool, type(None)}) def _recursion(object): return (""