From bd8b360bc507df659c11b8062397978dea0b56e7 Mon Sep 17 00:00:00 2001 From: Bruno Cauet Date: Tue, 9 Dec 2014 15:18:48 +0100 Subject: [PATCH] Fix string.printable: respect POSIX spec Remove non-space whitespace chars from string.printable --- Lib/string.py | 4 ++-- Lib/test/test_string.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Lib/string.py b/Lib/string.py index 72a09f7..d627337 100644 --- a/Lib/string.py +++ b/Lib/string.py @@ -10,7 +10,7 @@ digits -- a string containing all ASCII decimal digits hexdigits -- a string containing all ASCII hexadecimal digits octdigits -- a string containing all ASCII octal digits punctuation -- a string containing all ASCII punctuation characters -printable -- a string containing all ASCII characters considered printable +printable -- a string containing all ASCII characters considered printable by POSIX """ @@ -25,7 +25,7 @@ digits = '0123456789' hexdigits = digits + 'abcdef' + 'ABCDEF' octdigits = '01234567' punctuation = """!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~""" -printable = digits + ascii_letters + punctuation + whitespace +printable = digits + ascii_letters + punctuation + ' ' # Functions which aren't available as string methods. diff --git a/Lib/test/test_string.py b/Lib/test/test_string.py index 3e65071..ba8e8b6 100644 --- a/Lib/test/test_string.py +++ b/Lib/test/test_string.py @@ -166,6 +166,9 @@ class ModuleTest(unittest.TestCase): fmt._vformat("{i}", args, kwargs, set(), -1) self.assertIn("recursion", str(err.exception)) + def test_printable(self): + self.assertTrue(string.printable.isprintable()) + def test_main(): support.run_unittest(ModuleTest) -- 2.1.3