py3k: Add true Unicode support to OleFileIO

The day has arrived when Python provides an official way to handle Unicode
strings.
This commit is contained in:
Brian Crowell 2012-10-15 20:59:31 -05:00 committed by Brian Crowell
parent fc035814bd
commit 3a665a7835

View File

@ -37,7 +37,7 @@
# #
import StringIO import StringIO
import sys
def i16(c, o = 0): def i16(c, o = 0):
return ord(c[o])+(ord(c[o+1])<<8) return ord(c[o])+(ord(c[o+1])<<8)
@ -327,9 +327,12 @@ class OleFileIO:
def _unicode(self, s): def _unicode(self, s):
# Map unicode string to Latin 1 # Map unicode string to Latin 1
# FIXME: some day, Python will provide an official way to handle if sys.version_info >= (3,0):
# Unicode strings, but until then, this will have to do... # Provide actual Unicode string
return filter(ord, s) 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): def loaddirectory(self, sect):
# Load the directory. The directory is stored in a standard # Load the directory. The directory is stored in a standard