2to3 Use py23 to close some of the bytes/str/unicode gaps
diff --git a/Lib/fontTools/cffLib.py b/Lib/fontTools/cffLib.py
index 1577606..7a74041 100644
--- a/Lib/fontTools/cffLib.py
+++ b/Lib/fontTools/cffLib.py
@@ -8,11 +8,7 @@
from fontTools.misc import sstruct
from fontTools.misc import psCharStrings
from fontTools.misc.textTools import safeEval
-
-try:
- basestring
-except NameError:
- basestring = str
+from fontTools.misc.py23 import *
DEBUG = 0
diff --git a/Lib/fontTools/ttLib/__init__.py b/Lib/fontTools/ttLib/__init__.py
index 5916bdf..fa07449 100644
--- a/Lib/fontTools/ttLib/__init__.py
+++ b/Lib/fontTools/ttLib/__init__.py
@@ -47,6 +47,7 @@
import sys
import os
+from fontTools.misc.py23 import *
haveMacSupport = 0
if sys.platform == "mac":
@@ -391,10 +392,6 @@
# 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
- try:
- from cStringIO import StringIO
- except ImportError:
- from io import StringIO
file = StringIO()
traceback.print_exc(file=file)
table = DefaultTable(tag)
diff --git a/Lib/fontTools/ttLib/macUtils.py b/Lib/fontTools/ttLib/macUtils.py
index 85a375c..086cbd6 100644
--- a/Lib/fontTools/ttLib/macUtils.py
+++ b/Lib/fontTools/ttLib/macUtils.py
@@ -6,14 +6,12 @@
raise ImportError("This module is Mac-only!")
try:
- from cStringIO import StringIO
-except ImportError:
- from io import StringIO
-try:
from Carbon import Res
except ImportError:
import Res
+from fontTools.misc.py23 import *
+
def MyOpenResFile(path):
mode = 1 # read only
@@ -21,7 +19,7 @@
resref = Res.FSOpenResFile(path, mode)
except Res.Error:
# try data fork
- resref = Res.FSOpenResourceFile(path, u'', mode)
+ resref = Res.FSOpenResourceFile(path, unicode(), mode)
return resref
diff --git a/Lib/fontTools/ttLib/sfnt.py b/Lib/fontTools/ttLib/sfnt.py
index 3cac90f..136dde3 100644
--- a/Lib/fontTools/ttLib/sfnt.py
+++ b/Lib/fontTools/ttLib/sfnt.py
@@ -14,8 +14,8 @@
import sys
import struct
-from fontTools.misc import sstruct
import os
+from fontTools.misc import sstruct
class SFNTReader:
diff --git a/Lib/fontTools/ttLib/tables/M_E_T_A_.py b/Lib/fontTools/ttLib/tables/M_E_T_A_.py
index 9289350..51f98bb 100644
--- a/Lib/fontTools/ttLib/tables/M_E_T_A_.py
+++ b/Lib/fontTools/ttLib/tables/M_E_T_A_.py
@@ -3,6 +3,7 @@
from fontTools.misc import sstruct
from fontTools.misc.textTools import safeEval
import sys
+from fontTools.misc.py23 import *
METAHeaderFormat = """
@@ -239,7 +240,7 @@
def mapXMLToUTF8(string):
- uString = u""
+ uString = unicode()
strLen = len(string)
i = 0
while i < strLen:
@@ -265,11 +266,11 @@
def mapUTF8toXML(string):
uString = string.decode('utf8')
- string = ""
+ string = bytes()
for uChar in uString:
i = ord(uChar)
if (i < 0x80) and (i > 0x1F):
- string = string + chr(i)
+ string = string + bytechr(i)
else:
string = string + "&#x" + hex(i)[2:] + ";"
return string