From c575dff0070577cf9d38fa5a3548785d886bfcf8 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Mon, 8 Jul 2013 22:16:25 -0700 Subject: [PATCH] ignore high ascii characters in string.whitespace --- PIL/PpmImagePlugin.py | 2 +- Tests/test_locale.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 Tests/test_locale.py diff --git a/PIL/PpmImagePlugin.py b/PIL/PpmImagePlugin.py index 26f8e70f9..c7c9c2eb4 100644 --- a/PIL/PpmImagePlugin.py +++ b/PIL/PpmImagePlugin.py @@ -24,7 +24,7 @@ from PIL import Image, ImageFile # # -------------------------------------------------------------------- -b_whitespace = string.whitespace.encode() +b_whitespace = string.whitespace.encode('ascii','ignore') MODES = { # standard diff --git a/Tests/test_locale.py b/Tests/test_locale.py new file mode 100644 index 000000000..2683c561b --- /dev/null +++ b/Tests/test_locale.py @@ -0,0 +1,31 @@ +from tester import * +from PIL import Image + +import locale + +# ref https://github.com/python-imaging/Pillow/issues/272 +## on windows, in polish locale: + +## import locale +## print locale.setlocale(locale.LC_ALL, 'polish') +## import string +## print len(string.whitespace) +## print ord(string.whitespace[6]) + +## Polish_Poland.1250 +## 7 +## 160 + +# one of string.whitespace is not freely convertable into ascii. + +path = "Images/lena.jpg" + +def test_sanity(): + assert_no_exception(lambda: Image.open(path)) + try: + locale.setlocale(locale.LC_ALL, "polish") + except: + skip('polish locale not available') + import string + assert_no_exception(lambda: Image.open(path)) +