2to3 --fix=imports with manual fixups
diff --git a/Lib/fontTools/ttLib/__init__.py b/Lib/fontTools/ttLib/__init__.py
index b68624d..05b76f9 100644
--- a/Lib/fontTools/ttLib/__init__.py
+++ b/Lib/fontTools/ttLib/__init__.py
@@ -392,8 +392,11 @@
# fall back to DefaultTable, retaining the binary table data
print("An exception occurred during the decompilation of the '%s' table" % tag)
from .tables.DefaultTable import DefaultTable
- import StringIO
- file = StringIO.StringIO()
+ try:
+ from cStringIO import StringIO
+ except ImportError:
+ from io import StringIO
+ file = StringIO()
traceback.print_exc(file=file)
table = DefaultTable(tag)
table.ERROR = file.getvalue()
diff --git a/Lib/fontTools/ttLib/macUtils.py b/Lib/fontTools/ttLib/macUtils.py
index 3e05177..85a375c 100644
--- a/Lib/fontTools/ttLib/macUtils.py
+++ b/Lib/fontTools/ttLib/macUtils.py
@@ -5,7 +5,10 @@
if sys.platform not in ("mac", "darwin"):
raise ImportError("This module is Mac-only!")
-import cStringIO
+try:
+ from cStringIO import StringIO
+except ImportError:
+ from io import StringIO
try:
from Carbon import Res
except ImportError:
@@ -64,7 +67,7 @@
res = Res.Get1NamedResource('sfnt', res_name_or_index)
else:
res = Res.Get1IndResource('sfnt', res_name_or_index)
- self.file = cStringIO.StringIO(res.data)
+ self.file = StringIO(res.data)
Res.CloseResFile(resref)
self.name = path
@@ -78,7 +81,7 @@
"""Simple (Mac-only) file wrapper for 'sfnt' resources."""
def __init__(self, path, ttFont, res_id=None):
- self.file = cStringIO.StringIO()
+ self.file = StringIO()
self.name = path
self.closed = 0
fullname = ttFont['name'].getName(4, 1, 0) # Full name, mac, default encoding
diff --git a/Lib/fontTools/ttLib/tables/C_F_F_.py b/Lib/fontTools/ttLib/tables/C_F_F_.py
index 146aca5..c860368 100644
--- a/Lib/fontTools/ttLib/tables/C_F_F_.py
+++ b/Lib/fontTools/ttLib/tables/C_F_F_.py
@@ -1,5 +1,9 @@
from . import DefaultTable
from fontTools import cffLib
+try:
+ from cStringIO import StringIO
+except ImportError:
+ from io import StringIO
class table_C_F_F_(DefaultTable.DefaultTable):
@@ -10,12 +14,10 @@
self._gaveGlyphOrder = 0
def decompile(self, data, otFont):
- from cStringIO import StringIO
self.cff.decompile(StringIO(data), otFont)
assert len(self.cff) == 1, "can't deal with multi-font CFF tables."
def compile(self, otFont):
- from cStringIO import StringIO
f = StringIO()
self.cff.compile(f, otFont)
return f.getvalue()