From 2e058808fe2fd1a94f0525ddb0efe83b93bc9b05 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Fri, 7 Aug 2015 15:44:58 +0100 Subject: [PATCH] [py23] define BytesIO, StringIO and 'UnicodeIO' to disambiguate bytes vs unicode in-memory streams --- Lib/fontTools/misc/py23.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Lib/fontTools/misc/py23.py b/Lib/fontTools/misc/py23.py index affccdc21..a447496da 100644 --- a/Lib/fontTools/misc/py23.py +++ b/Lib/fontTools/misc/py23.py @@ -90,10 +90,18 @@ except NameError: def byteord(c): return c if isinstance(c, int) else ord(c) + +# the 'io' module provides the same I/O interface on both 2 and 3. +# here we define an alias of io.StringIO to disambiguate it eternally... +from io import BytesIO +from io import StringIO as UnicodeIO try: + # in python 2, by 'StringIO' we still mean a stream of *byte* strings from StringIO import StringIO except ImportError: - from io import BytesIO as StringIO + # in Python 3, we mean instead a stream of *unicode* strings + StringIO = UnicodeIO + def strjoin(iterable, joiner=''): return tostr(joiner).join(iterable)