py23 fixes for psLib and t1Lib
Still not working with Python 3 as psLib's PSTokenizer subclasses
StringIO and expects it to have buf and pos. Need to rewrite
this to implement StringIO internally.
diff --git a/Lib/fontTools/misc/psLib.py b/Lib/fontTools/misc/psLib.py
index 434e971..5b99cb3 100644
--- a/Lib/fontTools/misc/psLib.py
+++ b/Lib/fontTools/misc/psLib.py
@@ -1,7 +1,7 @@
from __future__ import print_function, division
from fontTools.misc.py23 import *
from fontTools.misc import eexec
-from psOperators import *
+from .psOperators import *
import re
import collections
from string import whitespace
@@ -320,13 +320,13 @@
def suckfont(data):
import re
- m = re.search(r"/FontName\s+/([^ \t\n\r]+)\s+def", data)
+ m = re.search(br"/FontName\s+/([^ \t\n\r]+)\s+def", data)
if m:
fontName = m.group(1)
else:
fontName = None
interpreter = PSInterpreter()
- interpreter.interpret("/Helvetica 4 dict dup /Encoding StandardEncoding put definefont pop")
+ interpreter.interpret(b"/Helvetica 4 dict dup /Encoding StandardEncoding put definefont pop")
interpreter.interpret(data)
fontdir = interpreter.dictstack[0]['FontDirectory'].value
if fontName in fontdir:
diff --git a/Lib/fontTools/t1Lib.py b/Lib/fontTools/t1Lib.py
index aae86d9..abd4f32 100644
--- a/Lib/fontTools/t1Lib.py
+++ b/Lib/fontTools/t1Lib.py
@@ -338,17 +338,17 @@
# Type 1 assertion
-_fontType1RE = re.compile(r"/FontType\s+1\s+def")
+_fontType1RE = re.compile(br"/FontType\s+1\s+def")
def assertType1(data):
- for head in ['%!PS-AdobeFont', '%!FontType1']:
+ for head in [b'%!PS-AdobeFont', b'%!FontType1']:
if data[:len(head)] == head:
break
else:
raise T1Error("not a PostScript font")
if not _fontType1RE.search(data):
raise T1Error("not a Type 1 font")
- if data.find("currentfile eexec") < 0:
+ if data.find(b"currentfile eexec") < 0:
raise T1Error("not an encrypted Type 1 font")
# XXX what else?
return data