From 20e7555e5998b71e74ce438635be0cde8aaee509 Mon Sep 17 00:00:00 2001 From: Michael Hogg Date: Mon, 30 Sep 2013 09:54:25 +1000 Subject: [PATCH 1/3] Update PpmImagePlugin.py Bug fix for encoding of b_whitespace --- PIL/PpmImagePlugin.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/PIL/PpmImagePlugin.py b/PIL/PpmImagePlugin.py index c7c9c2eb4..a9c2bb283 100644 --- a/PIL/PpmImagePlugin.py +++ b/PIL/PpmImagePlugin.py @@ -24,7 +24,10 @@ from PIL import Image, ImageFile # # -------------------------------------------------------------------- -b_whitespace = string.whitespace.encode('ascii','ignore') +import locale +locale_name,locale_id = locale.getlocale() +b_whitespace = string.whitespace.decode(locale_id) +b_whitespace = b_whitespace.encode('ascii','ignore') MODES = { # standard From 800729e092577bca0398b59d9ab68d2351782c3d Mon Sep 17 00:00:00 2001 From: Michael Hogg Date: Mon, 30 Sep 2013 17:24:22 +1000 Subject: [PATCH 2/3] Update PpmImagePlugin.py Bug fix when locale has not been set --- PIL/PpmImagePlugin.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/PIL/PpmImagePlugin.py b/PIL/PpmImagePlugin.py index a9c2bb283..444342bee 100644 --- a/PIL/PpmImagePlugin.py +++ b/PIL/PpmImagePlugin.py @@ -25,8 +25,10 @@ from PIL import Image, ImageFile # -------------------------------------------------------------------- import locale -locale_name,locale_id = locale.getlocale() -b_whitespace = string.whitespace.decode(locale_id) +locale_lang,locale_enc = locale.getlocale() +if locale_enc is None: + locale_lang,locale_enc = locale.getdefaultlocale() +b_whitespace = string.whitespace.decode(locale_enc) b_whitespace = b_whitespace.encode('ascii','ignore') MODES = { From e70424644ac4e805b9e79642ec8f3af8e459d576 Mon Sep 17 00:00:00 2001 From: Michael Hogg Date: Mon, 30 Sep 2013 17:44:11 +1000 Subject: [PATCH 3/3] Update PpmImagePlugin.py Making it work for Python 3.x --- PIL/PpmImagePlugin.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/PIL/PpmImagePlugin.py b/PIL/PpmImagePlugin.py index 444342bee..9aa5b1135 100644 --- a/PIL/PpmImagePlugin.py +++ b/PIL/PpmImagePlugin.py @@ -24,11 +24,14 @@ from PIL import Image, ImageFile # # -------------------------------------------------------------------- -import locale -locale_lang,locale_enc = locale.getlocale() -if locale_enc is None: - locale_lang,locale_enc = locale.getdefaultlocale() -b_whitespace = string.whitespace.decode(locale_enc) +b_whitespace = string.whitespace +try: + import locale + locale_lang,locale_enc = locale.getlocale() + if locale_enc is None: + locale_lang,locale_enc = locale.getdefaultlocale() + b_whitespace = b_whitespace.decode(locale_enc) +except: pass b_whitespace = b_whitespace.encode('ascii','ignore') MODES = {