From 3a665a783532ec8337d7acac70b0d09e86e2a0e1 Mon Sep 17 00:00:00 2001 From: Brian Crowell Date: Mon, 15 Oct 2012 20:59:31 -0500 Subject: [PATCH] py3k: Add true Unicode support to OleFileIO The day has arrived when Python provides an official way to handle Unicode strings. --- PIL/OleFileIO.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/PIL/OleFileIO.py b/PIL/OleFileIO.py index f8c25181f..d093d71a7 100644 --- a/PIL/OleFileIO.py +++ b/PIL/OleFileIO.py @@ -37,7 +37,7 @@ # import StringIO - +import sys def i16(c, o = 0): return ord(c[o])+(ord(c[o+1])<<8) @@ -327,9 +327,12 @@ class OleFileIO: def _unicode(self, s): # Map unicode string to Latin 1 - # FIXME: some day, Python will provide an official way to handle - # Unicode strings, but until then, this will have to do... - return filter(ord, s) + if sys.version_info >= (3,0): + # Provide actual Unicode string + return s.decode('utf-16') + else: + # Old version tried to produce a Latin-1 str + return s.decode('utf-16').encode('latin-1', 'replace') def loaddirectory(self, sect): # Load the directory. The directory is stored in a standard