diff -r c02f464dd721 Lib/pprint.py --- a/Lib/pprint.py Thu Sep 26 09:35:39 2013 -0700 +++ b/Lib/pprint.py Fri Sep 27 18:01:41 2013 +0300 @@ -241,6 +241,8 @@ return if issubclass(typ, str) and len(object) > 0 and r is str.__repr__: + if not allowance: + max_width -= 1 def _str_parts(s): """ Return a list of string literals comprising the repr() @@ -268,6 +270,8 @@ yield repr(current) for i, rep in enumerate(_str_parts(object)): if i > 0: + if level == 1: + write('\\') write('\n' + ' '*indent) write(rep) return diff -r c02f464dd721 Lib/test/test_pprint.py --- a/Lib/test/test_pprint.py Thu Sep 26 09:35:39 2013 -0700 +++ b/Lib/test/test_pprint.py Fri Sep 27 18:01:41 2013 +0300 @@ -481,8 +481,8 @@ # pprint tries to wrap strings intelligently fox = 'the quick brown fox jumped over a lazy dog' self.assertEqual(pprint.pformat(fox, width=20), """\ -'the quick brown ' -'fox jumped over ' +'the quick brown '\\ +'fox jumped over '\\ 'a lazy dog'""") self.assertEqual(pprint.pformat({'a': 1, 'b': fox, 'c': 2}, width=26), """\ @@ -498,10 +498,10 @@ # - an apostrophe doesn't disrupt the pprint special = "Portons dix bons \"whiskys\"\nà l'avocat goujat\t qui fumait au zoo" self.assertEqual(pprint.pformat(special, width=20), """\ -'Portons dix bons ' -'"whiskys"\\n' -"à l'avocat " -'goujat\\t qui ' +'Portons dix '\\ +'bons "whiskys"\\n'\\ +"à l'avocat "\\ +'goujat\\t qui '\\ 'fumait au zoo'""") # An unwrappable string is formatted as its repr unwrappable = "x" * 100 @@ -511,7 +511,9 @@ special *= 10 for width in range(3, 40): formatted = pprint.pformat(special, width=width) - self.assertEqual(eval("(" + formatted + ")"), special) + self.assertEqual(eval(formatted), special) + formatted = pprint.pformat([special] * 2, width=width) + self.assertEqual(eval(formatted), [special] * 2) class DottedPrettyPrinter(pprint.PrettyPrinter):