diff --git a/Lib/fontTools/agl.py b/Lib/fontTools/agl.py index 4f7ff920c..cc286e42c 100644 --- a/Lib/fontTools/agl.py +++ b/Lib/fontTools/agl.py @@ -26,7 +26,7 @@ This is used by fontTools when it has to construct glyph names for a font which doesn't include any (e.g. format 3.0 post tables). """ -from fontTools.misc.py23 import tostr +from fontTools.misc.textTools import tostr import re diff --git a/Lib/fontTools/cffLib/__init__.py b/Lib/fontTools/cffLib/__init__.py index d4cd7a173..aef6dd205 100644 --- a/Lib/fontTools/cffLib/__init__.py +++ b/Lib/fontTools/cffLib/__init__.py @@ -11,11 +11,10 @@ the demands of variable fonts. This module parses both original CFF and CFF2. """ -from fontTools.misc.py23 import bytechr, byteord, bytesjoin, tobytes, tostr from fontTools.misc import sstruct from fontTools.misc import psCharStrings from fontTools.misc.arrayTools import unionRect, intRect -from fontTools.misc.textTools import safeEval +from fontTools.misc.textTools import bytechr, byteord, bytesjoin, tobytes, tostr, safeEval from fontTools.ttLib import TTFont from fontTools.ttLib.tables.otBase import OTTableWriter from fontTools.ttLib.tables.otBase import OTTableReader diff --git a/Lib/fontTools/designspaceLib/__init__.py b/Lib/fontTools/designspaceLib/__init__.py index 3bb2bbfc9..b447a1b77 100644 --- a/Lib/fontTools/designspaceLib/__init__.py +++ b/Lib/fontTools/designspaceLib/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- -from fontTools.misc.py23 import tobytes, tostr from fontTools.misc.loggingTools import LogMixin +from fontTools.misc.textTools import tobytes, tostr import collections from io import BytesIO, StringIO import os diff --git a/Lib/fontTools/feaLib/ast.py b/Lib/fontTools/feaLib/ast.py index 5bf8b62c2..1ec8da0bd 100644 --- a/Lib/fontTools/feaLib/ast.py +++ b/Lib/fontTools/feaLib/ast.py @@ -1,7 +1,7 @@ -from fontTools.misc.py23 import byteord, tobytes from fontTools.feaLib.error import FeatureLibError from fontTools.feaLib.location import FeatureLibLocation from fontTools.misc.encodingTools import getEncoding +from fontTools.misc.textTools import byteord, tobytes from collections import OrderedDict import itertools diff --git a/Lib/fontTools/feaLib/builder.py b/Lib/fontTools/feaLib/builder.py index 989f05e20..d6f41014f 100644 --- a/Lib/fontTools/feaLib/builder.py +++ b/Lib/fontTools/feaLib/builder.py @@ -1,6 +1,5 @@ -from fontTools.misc.py23 import Tag, tostr from fontTools.misc import sstruct -from fontTools.misc.textTools import binary2num, safeEval +from fontTools.misc.textTools import Tag, tostr, binary2num, safeEval from fontTools.feaLib.error import FeatureLibError from fontTools.feaLib.lookupDebugInfo import ( LookupDebugInfo, diff --git a/Lib/fontTools/feaLib/parser.py b/Lib/fontTools/feaLib/parser.py index 199d9b3bf..830a08577 100644 --- a/Lib/fontTools/feaLib/parser.py +++ b/Lib/fontTools/feaLib/parser.py @@ -1,7 +1,7 @@ from fontTools.feaLib.error import FeatureLibError from fontTools.feaLib.lexer import Lexer, IncludingLexer, NonIncludingLexer from fontTools.misc.encodingTools import getEncoding -from fontTools.misc.py23 import bytechr, tobytes, tostr +from fontTools.misc.textTools import bytechr, tobytes, tostr import fontTools.feaLib.ast as ast import logging import os diff --git a/Lib/fontTools/misc/eexec.py b/Lib/fontTools/misc/eexec.py index 71f733c1f..d1d4bb6a0 100644 --- a/Lib/fontTools/misc/eexec.py +++ b/Lib/fontTools/misc/eexec.py @@ -12,7 +12,7 @@ the new key at the end of the operation. """ -from fontTools.misc.py23 import bytechr, bytesjoin, byteord +from fontTools.misc.textTools import bytechr, bytesjoin, byteord def _decryptChar(cipher, R): diff --git a/Lib/fontTools/misc/etree.py b/Lib/fontTools/misc/etree.py index 6e943e4b5..cd4df3655 100644 --- a/Lib/fontTools/misc/etree.py +++ b/Lib/fontTools/misc/etree.py @@ -11,7 +11,7 @@ or subclasses built-in ElementTree classes to add features that are only availble in lxml, like OrderedDict for attributes, pretty_print and iterwalk. """ -from fontTools.misc.py23 import unicode, tostr +from fontTools.misc.textTools import tostr XML_DECLARATION = """""" @@ -150,9 +150,7 @@ except ImportError: ) return - if encoding is unicode or ( - encoding is not None and encoding.lower() == "unicode" - ): + if encoding is not None and encoding.lower() == "unicode": if xml_declaration: raise ValueError( "Serialisation to unicode must not request an XML declaration" diff --git a/Lib/fontTools/misc/macCreatorType.py b/Lib/fontTools/misc/macCreatorType.py index fb237200b..6b191054b 100644 --- a/Lib/fontTools/misc/macCreatorType.py +++ b/Lib/fontTools/misc/macCreatorType.py @@ -1,4 +1,4 @@ -from fontTools.misc.py23 import Tag, bytesjoin, strjoin +from fontTools.misc.textTools import Tag, bytesjoin, strjoin try: import xattr except ImportError: @@ -18,7 +18,7 @@ def getMacCreatorAndType(path): path (str): A file path. Returns: - A tuple of two :py:class:`fontTools.py23.Tag` objects, the first + A tuple of two :py:class:`fontTools.textTools.Tag` objects, the first representing the file creator and the second representing the file type. """ diff --git a/Lib/fontTools/misc/macRes.py b/Lib/fontTools/misc/macRes.py index 2c15b347c..895ca1b84 100644 --- a/Lib/fontTools/misc/macRes.py +++ b/Lib/fontTools/misc/macRes.py @@ -1,7 +1,7 @@ -from fontTools.misc.py23 import bytesjoin, tostr from io import BytesIO import struct from fontTools.misc import sstruct +from fontTools.misc.textTools import bytesjoin, tostr from collections import OrderedDict from collections.abc import MutableMapping diff --git a/Lib/fontTools/misc/plistlib/__init__.py b/Lib/fontTools/misc/plistlib/__init__.py index 84dc41832..04ca5326b 100644 --- a/Lib/fontTools/misc/plistlib/__init__.py +++ b/Lib/fontTools/misc/plistlib/__init__.py @@ -23,7 +23,7 @@ from functools import singledispatch from fontTools.misc import etree -from fontTools.misc.py23 import tostr +from fontTools.misc.textTools import tostr # By default, we diff --git a/Lib/fontTools/misc/psCharStrings.py b/Lib/fontTools/misc/psCharStrings.py index cb6750504..29c2d3658 100644 --- a/Lib/fontTools/misc/psCharStrings.py +++ b/Lib/fontTools/misc/psCharStrings.py @@ -2,10 +2,10 @@ CFF dictionary data and Type1/Type2 CharStrings. """ -from fontTools.misc.py23 import bytechr, byteord, bytesjoin, strjoin from fontTools.misc.fixedTools import ( fixedToFloat, floatToFixed, floatToFixedToStr, strToFixedToFloat, ) +from fontTools.misc.textTools import bytechr, byteord, bytesjoin, strjoin from fontTools.pens.boundsPen import BoundsPen import struct import logging diff --git a/Lib/fontTools/misc/psLib.py b/Lib/fontTools/misc/psLib.py index 916755ce3..c97c418a8 100644 --- a/Lib/fontTools/misc/psLib.py +++ b/Lib/fontTools/misc/psLib.py @@ -1,4 +1,4 @@ -from fontTools.misc.py23 import bytechr, byteord, bytesjoin, tobytes, tostr +from fontTools.misc.textTools import bytechr, byteord, bytesjoin, tobytes, tostr from fontTools.misc import eexec from .psOperators import ( PSOperators, diff --git a/Lib/fontTools/misc/py23.py b/Lib/fontTools/misc/py23.py index 25a4cdb6f..29f634d62 100644 --- a/Lib/fontTools/misc/py23.py +++ b/Lib/fontTools/misc/py23.py @@ -8,6 +8,8 @@ from io import BytesIO from io import StringIO as UnicodeIO from types import SimpleNamespace +from .textTools import Tag, bytechr, byteord, bytesjoin, strjoin, tobytes, tostr + warnings.warn( "The py23 module has been deprecated and will be removed in a future release. " "Please update your code.", @@ -57,61 +59,7 @@ unichr = chr unicode = str zip = zip - -def bytechr(n): - return bytes([n]) - - -def byteord(c): - return c if isinstance(c, int) else ord(c) - - -def strjoin(iterable, joiner=""): - return tostr(joiner).join(iterable) - - -def tobytes(s, encoding="ascii", errors="strict"): - if isinstance(s, str): - return s.encode(encoding, errors) - else: - return bytes(s) - - -def tounicode(s, encoding="ascii", errors="strict"): - if not isinstance(s, unicode): - return s.decode(encoding, errors) - else: - return s - - -tostr = tounicode - - -class Tag(str): - @staticmethod - def transcode(blob): - if isinstance(blob, bytes): - blob = blob.decode("latin-1") - return blob - - def __new__(self, content): - return str.__new__(self, self.transcode(content)) - - def __ne__(self, other): - return not self.__eq__(other) - - def __eq__(self, other): - return str.__eq__(self, self.transcode(other)) - - def __hash__(self): - return str.__hash__(self) - - def tobytes(self): - return self.encode("latin-1") - - -def bytesjoin(iterable, joiner=b""): - return tobytes(joiner).join(tobytes(item) for item in iterable) +tounicode = tostr def xrange(*args, **kwargs): diff --git a/Lib/fontTools/misc/sstruct.py b/Lib/fontTools/misc/sstruct.py index 9f1de8bcb..6db8b5153 100644 --- a/Lib/fontTools/misc/sstruct.py +++ b/Lib/fontTools/misc/sstruct.py @@ -46,8 +46,8 @@ calcsize(fmt) it returns the size of the data in bytes. """ -from fontTools.misc.py23 import tobytes, tostr from fontTools.misc.fixedTools import fixedToFloat as fi2fl, floatToFixed as fl2fi +from fontTools.misc.textTools import tobytes, tostr import struct import re diff --git a/Lib/fontTools/misc/testTools.py b/Lib/fontTools/misc/testTools.py index 1b258e372..e13a3c4e6 100644 --- a/Lib/fontTools/misc/testTools.py +++ b/Lib/fontTools/misc/testTools.py @@ -7,7 +7,7 @@ import shutil import sys import tempfile from unittest import TestCase as _TestCase -from fontTools.misc.py23 import tobytes +from fontTools.misc.textTools import tobytes from fontTools.misc.xmlWriter import XMLWriter diff --git a/Lib/fontTools/misc/textTools.py b/Lib/fontTools/misc/textTools.py index 072976af8..bf75bcbd7 100644 --- a/Lib/fontTools/misc/textTools.py +++ b/Lib/fontTools/misc/textTools.py @@ -1,7 +1,6 @@ """fontTools.misc.textTools.py -- miscellaneous routines.""" -from fontTools.misc.py23 import bytechr, byteord, bytesjoin, strjoin, tobytes import ast import string @@ -10,6 +9,29 @@ import string safeEval = ast.literal_eval +class Tag(str): + @staticmethod + def transcode(blob): + if isinstance(blob, bytes): + blob = blob.decode("latin-1") + return blob + + def __new__(self, content): + return str.__new__(self, self.transcode(content)) + + def __ne__(self, other): + return not self.__eq__(other) + + def __eq__(self, other): + return str.__eq__(self, self.transcode(other)) + + def __hash__(self): + return str.__hash__(self) + + def tobytes(self): + return self.encode("latin-1") + + def readHex(content): """Convert a list of hex strings to binary data.""" return deHexStr(strjoin(chunk for chunk in content if isinstance(chunk, str))) @@ -97,6 +119,36 @@ def pad(data, size): return data +def tostr(s, encoding="ascii", errors="strict"): + if not isinstance(s, str): + return s.decode(encoding, errors) + else: + return s + + +def tobytes(s, encoding="ascii", errors="strict"): + if isinstance(s, str): + return s.encode(encoding, errors) + else: + return bytes(s) + + +def bytechr(n): + return bytes([n]) + + +def byteord(c): + return c if isinstance(c, int) else ord(c) + + +def strjoin(iterable, joiner=""): + return tostr(joiner).join(iterable) + + +def bytesjoin(iterable, joiner=b""): + return tobytes(joiner).join(tobytes(item) for item in iterable) + + if __name__ == "__main__": import doctest, sys sys.exit(doctest.testmod().failed) diff --git a/Lib/fontTools/misc/xmlWriter.py b/Lib/fontTools/misc/xmlWriter.py index ddc2fdb3e..9e30fa33d 100644 --- a/Lib/fontTools/misc/xmlWriter.py +++ b/Lib/fontTools/misc/xmlWriter.py @@ -1,6 +1,6 @@ """xmlWriter.py -- Simple XML authoring class""" -from fontTools.misc.py23 import byteord, strjoin, tobytes, tostr +from fontTools.misc.textTools import byteord, strjoin, tobytes, tostr import sys import os import string diff --git a/Lib/fontTools/svgLib/path/__init__.py b/Lib/fontTools/svgLib/path/__init__.py index 9440429bd..fbddeeabb 100644 --- a/Lib/fontTools/svgLib/path/__init__.py +++ b/Lib/fontTools/svgLib/path/__init__.py @@ -1,7 +1,6 @@ -from fontTools.misc.py23 import tostr - from fontTools.pens.transformPen import TransformPen from fontTools.misc import etree +from fontTools.misc.textTools import tostr from .parser import parse_path from .shapes import PathBuilder diff --git a/Lib/fontTools/t1Lib/__init__.py b/Lib/fontTools/t1Lib/__init__.py index e1d94d35f..d07d78c05 100644 --- a/Lib/fontTools/t1Lib/__init__.py +++ b/Lib/fontTools/t1Lib/__init__.py @@ -15,9 +15,9 @@ write(path, data, kind='OTHER', dohex=False) part should be written as hexadecimal or binary, but only if kind is 'OTHER'. """ -from fontTools.misc.py23 import bytechr, byteord, bytesjoin from fontTools.misc import eexec from fontTools.misc.macCreatorType import getMacCreatorAndType +from fontTools.misc.textTools import bytechr, byteord, bytesjoin import os import re diff --git a/Lib/fontTools/ttLib/sfnt.py b/Lib/fontTools/ttLib/sfnt.py index d609dc518..b2a5bd4fc 100644 --- a/Lib/fontTools/ttLib/sfnt.py +++ b/Lib/fontTools/ttLib/sfnt.py @@ -14,7 +14,7 @@ a table's length chages you need to rewrite the whole file anyway. from io import BytesIO from types import SimpleNamespace -from fontTools.misc.py23 import Tag +from fontTools.misc.textTools import Tag from fontTools.misc import sstruct from fontTools.ttLib import TTLibError import struct diff --git a/Lib/fontTools/ttLib/tables/C_B_D_T_.py b/Lib/fontTools/ttLib/tables/C_B_D_T_.py index 11bb60b8b..adf5447f1 100644 --- a/Lib/fontTools/ttLib/tables/C_B_D_T_.py +++ b/Lib/fontTools/ttLib/tables/C_B_D_T_.py @@ -3,7 +3,7 @@ # Google Author(s): Matt Fontaine -from fontTools.misc.py23 import bytesjoin +from fontTools.misc.textTools import bytesjoin from fontTools.misc import sstruct from . import E_B_D_T_ from .BitmapGlyphMetrics import BigGlyphMetrics, bigGlyphMetricsFormat, SmallGlyphMetrics, smallGlyphMetricsFormat diff --git a/Lib/fontTools/ttLib/tables/C_P_A_L_.py b/Lib/fontTools/ttLib/tables/C_P_A_L_.py index c095095e6..1ad342f12 100644 --- a/Lib/fontTools/ttLib/tables/C_P_A_L_.py +++ b/Lib/fontTools/ttLib/tables/C_P_A_L_.py @@ -2,8 +2,7 @@ # # Google Author(s): Behdad Esfahbod -from fontTools.misc.py23 import bytesjoin -from fontTools.misc.textTools import safeEval +from fontTools.misc.textTools import bytesjoin, safeEval from . import DefaultTable import array from collections import namedtuple diff --git a/Lib/fontTools/ttLib/tables/D_S_I_G_.py b/Lib/fontTools/ttLib/tables/D_S_I_G_.py index 1a520cab6..02fddee6a 100644 --- a/Lib/fontTools/ttLib/tables/D_S_I_G_.py +++ b/Lib/fontTools/ttLib/tables/D_S_I_G_.py @@ -1,5 +1,4 @@ -from fontTools.misc.py23 import bytesjoin, strjoin, tobytes, tostr -from fontTools.misc.textTools import safeEval +from fontTools.misc.textTools import bytesjoin, strjoin, tobytes, tostr, safeEval from fontTools.misc import sstruct from . import DefaultTable import base64 diff --git a/Lib/fontTools/ttLib/tables/DefaultTable.py b/Lib/fontTools/ttLib/tables/DefaultTable.py index c70480a33..dae83183d 100644 --- a/Lib/fontTools/ttLib/tables/DefaultTable.py +++ b/Lib/fontTools/ttLib/tables/DefaultTable.py @@ -1,4 +1,4 @@ -from fontTools.misc.py23 import Tag +from fontTools.misc.textTools import Tag from fontTools.ttLib import getClassTag class DefaultTable(object): diff --git a/Lib/fontTools/ttLib/tables/E_B_D_T_.py b/Lib/fontTools/ttLib/tables/E_B_D_T_.py index 5d9e7244a..0bd2ab99a 100644 --- a/Lib/fontTools/ttLib/tables/E_B_D_T_.py +++ b/Lib/fontTools/ttLib/tables/E_B_D_T_.py @@ -1,6 +1,5 @@ -from fontTools.misc.py23 import bytechr, byteord, bytesjoin, strjoin from fontTools.misc import sstruct -from fontTools.misc.textTools import safeEval, readHex, hexStr, deHexStr +from fontTools.misc.textTools import bytechr, byteord, bytesjoin, strjoin, safeEval, readHex, hexStr, deHexStr from .BitmapGlyphMetrics import BigGlyphMetrics, bigGlyphMetricsFormat, SmallGlyphMetrics, smallGlyphMetricsFormat from . import DefaultTable import itertools diff --git a/Lib/fontTools/ttLib/tables/E_B_L_C_.py b/Lib/fontTools/ttLib/tables/E_B_L_C_.py index 94d40d966..cfdbca7b3 100644 --- a/Lib/fontTools/ttLib/tables/E_B_L_C_.py +++ b/Lib/fontTools/ttLib/tables/E_B_L_C_.py @@ -1,7 +1,6 @@ -from fontTools.misc.py23 import bytesjoin from fontTools.misc import sstruct from . import DefaultTable -from fontTools.misc.textTools import safeEval +from fontTools.misc.textTools import bytesjoin, safeEval from .BitmapGlyphMetrics import BigGlyphMetrics, bigGlyphMetricsFormat, SmallGlyphMetrics, smallGlyphMetricsFormat import struct import itertools diff --git a/Lib/fontTools/ttLib/tables/G_M_A_P_.py b/Lib/fontTools/ttLib/tables/G_M_A_P_.py index 5b30dcfe4..833890da2 100644 --- a/Lib/fontTools/ttLib/tables/G_M_A_P_.py +++ b/Lib/fontTools/ttLib/tables/G_M_A_P_.py @@ -1,6 +1,5 @@ -from fontTools.misc.py23 import tobytes, tostr from fontTools.misc import sstruct -from fontTools.misc.textTools import safeEval +from fontTools.misc.textTools import tobytes, tostr, safeEval from . import DefaultTable GMAPFormat = """ diff --git a/Lib/fontTools/ttLib/tables/G_P_K_G_.py b/Lib/fontTools/ttLib/tables/G_P_K_G_.py index 7598a62aa..4f469c022 100644 --- a/Lib/fontTools/ttLib/tables/G_P_K_G_.py +++ b/Lib/fontTools/ttLib/tables/G_P_K_G_.py @@ -1,6 +1,5 @@ -from fontTools.misc.py23 import bytesjoin from fontTools.misc import sstruct -from fontTools.misc.textTools import safeEval, readHex +from fontTools.misc.textTools import bytesjoin, safeEval, readHex from . import DefaultTable import sys import array diff --git a/Lib/fontTools/ttLib/tables/M_E_T_A_.py b/Lib/fontTools/ttLib/tables/M_E_T_A_.py index d4f6bc8cf..990bfd2d9 100644 --- a/Lib/fontTools/ttLib/tables/M_E_T_A_.py +++ b/Lib/fontTools/ttLib/tables/M_E_T_A_.py @@ -1,6 +1,5 @@ -from fontTools.misc.py23 import byteord from fontTools.misc import sstruct -from fontTools.misc.textTools import safeEval +from fontTools.misc.textTools import byteord, safeEval from . import DefaultTable import pdb import struct diff --git a/Lib/fontTools/ttLib/tables/S_I_N_G_.py b/Lib/fontTools/ttLib/tables/S_I_N_G_.py index dd9b63c48..73246df4d 100644 --- a/Lib/fontTools/ttLib/tables/S_I_N_G_.py +++ b/Lib/fontTools/ttLib/tables/S_I_N_G_.py @@ -1,6 +1,5 @@ -from fontTools.misc.py23 import bytechr, byteord, tobytes, tostr from fontTools.misc import sstruct -from fontTools.misc.textTools import safeEval +from fontTools.misc.textTools import bytechr, byteord, tobytes, tostr, safeEval from . import DefaultTable SINGFormat = """ diff --git a/Lib/fontTools/ttLib/tables/S_V_G_.py b/Lib/fontTools/ttLib/tables/S_V_G_.py index 135f2718f..a59cc8659 100644 --- a/Lib/fontTools/ttLib/tables/S_V_G_.py +++ b/Lib/fontTools/ttLib/tables/S_V_G_.py @@ -1,4 +1,4 @@ -from fontTools.misc.py23 import bytesjoin, strjoin, tobytes, tostr +from fontTools.misc.textTools import bytesjoin, strjoin, tobytes, tostr from fontTools.misc import sstruct from . import DefaultTable try: diff --git a/Lib/fontTools/ttLib/tables/S__i_l_f.py b/Lib/fontTools/ttLib/tables/S__i_l_f.py index 95880b07b..f326c3860 100644 --- a/Lib/fontTools/ttLib/tables/S__i_l_f.py +++ b/Lib/fontTools/ttLib/tables/S__i_l_f.py @@ -1,7 +1,6 @@ -from fontTools.misc.py23 import byteord from fontTools.misc import sstruct from fontTools.misc.fixedTools import floatToFixedToStr -from fontTools.misc.textTools import safeEval +from fontTools.misc.textTools import byteord, safeEval # from itertools import * from . import DefaultTable from . import grUtils diff --git a/Lib/fontTools/ttLib/tables/T_S_I_V_.py b/Lib/fontTools/ttLib/tables/T_S_I_V_.py index 802144528..c1e244c64 100644 --- a/Lib/fontTools/ttLib/tables/T_S_I_V_.py +++ b/Lib/fontTools/ttLib/tables/T_S_I_V_.py @@ -1,4 +1,4 @@ -from fontTools.misc.py23 import strjoin, tobytes, tostr +from fontTools.misc.textTools import strjoin, tobytes, tostr from . import asciiTable class table_T_S_I_V_(asciiTable.asciiTable): diff --git a/Lib/fontTools/ttLib/tables/T_S_I__1.py b/Lib/fontTools/ttLib/tables/T_S_I__1.py index 9ae7acd6c..7f7608b2d 100644 --- a/Lib/fontTools/ttLib/tables/T_S_I__1.py +++ b/Lib/fontTools/ttLib/tables/T_S_I__1.py @@ -4,9 +4,9 @@ tool to store its hinting source data. TSI1 contains the text of the glyph programs in the form of low-level assembly code, as well as the 'extra' programs 'fpgm', 'ppgm' (i.e. 'prep'), and 'cvt'. """ -from fontTools.misc.py23 import strjoin, tobytes, tostr from . import DefaultTable from fontTools.misc.loggingTools import LogMixin +from fontTools.misc.textTools import strjoin, tobytes, tostr class table_T_S_I__1(LogMixin, DefaultTable.DefaultTable): diff --git a/Lib/fontTools/ttLib/tables/V_O_R_G_.py b/Lib/fontTools/ttLib/tables/V_O_R_G_.py index 0b7fe959c..8acf14b4c 100644 --- a/Lib/fontTools/ttLib/tables/V_O_R_G_.py +++ b/Lib/fontTools/ttLib/tables/V_O_R_G_.py @@ -1,5 +1,4 @@ -from fontTools.misc.py23 import bytesjoin -from fontTools.misc.textTools import safeEval +from fontTools.misc.textTools import bytesjoin, safeEval from . import DefaultTable import struct diff --git a/Lib/fontTools/ttLib/tables/_a_v_a_r.py b/Lib/fontTools/ttLib/tables/_a_v_a_r.py index 2b6a40ed8..5a02493c0 100644 --- a/Lib/fontTools/ttLib/tables/_a_v_a_r.py +++ b/Lib/fontTools/ttLib/tables/_a_v_a_r.py @@ -1,4 +1,3 @@ -from fontTools.misc.py23 import bytesjoin from fontTools.misc import sstruct from fontTools.misc.fixedTools import ( fixedToFloat as fi2fl, @@ -6,6 +5,7 @@ from fontTools.misc.fixedTools import ( floatToFixedToStr as fl2str, strToFixedToFloat as str2fl, ) +from fontTools.misc.textTools import bytesjoin from fontTools.ttLib import TTLibError from . import DefaultTable import struct diff --git a/Lib/fontTools/ttLib/tables/_c_m_a_p.py b/Lib/fontTools/ttLib/tables/_c_m_a_p.py index a65a0c25c..19b5998d6 100644 --- a/Lib/fontTools/ttLib/tables/_c_m_a_p.py +++ b/Lib/fontTools/ttLib/tables/_c_m_a_p.py @@ -1,5 +1,4 @@ -from fontTools.misc.py23 import bytesjoin -from fontTools.misc.textTools import safeEval, readHex +from fontTools.misc.textTools import bytesjoin, safeEval, readHex from fontTools.misc.encodingTools import getEncoding from fontTools.ttLib import getSearchRange from fontTools.unicode import Unicode diff --git a/Lib/fontTools/ttLib/tables/_c_v_a_r.py b/Lib/fontTools/ttLib/tables/_c_v_a_r.py index a5f1acf7d..a67efe02f 100644 --- a/Lib/fontTools/ttLib/tables/_c_v_a_r.py +++ b/Lib/fontTools/ttLib/tables/_c_v_a_r.py @@ -1,6 +1,6 @@ -from fontTools.misc.py23 import bytesjoin from . import DefaultTable from fontTools.misc import sstruct +from fontTools.misc.textTools import bytesjoin from fontTools.ttLib.tables.TupleVariation import \ compileTupleVariationStore, decompileTupleVariationStore, TupleVariation diff --git a/Lib/fontTools/ttLib/tables/_f_v_a_r.py b/Lib/fontTools/ttLib/tables/_f_v_a_r.py index 7487da623..d74091956 100644 --- a/Lib/fontTools/ttLib/tables/_f_v_a_r.py +++ b/Lib/fontTools/ttLib/tables/_f_v_a_r.py @@ -1,4 +1,3 @@ -from fontTools.misc.py23 import Tag, bytesjoin from fontTools.misc import sstruct from fontTools.misc.fixedTools import ( fixedToFloat as fi2fl, @@ -6,7 +5,7 @@ from fontTools.misc.fixedTools import ( floatToFixedToStr as fl2str, strToFixedToFloat as str2fl, ) -from fontTools.misc.textTools import safeEval +from fontTools.misc.textTools import Tag, bytesjoin, safeEval from fontTools.ttLib import TTLibError from . import DefaultTable import struct diff --git a/Lib/fontTools/ttLib/tables/_g_l_y_f.py b/Lib/fontTools/ttLib/tables/_g_l_y_f.py index e3bbddb9c..f9c682bb5 100644 --- a/Lib/fontTools/ttLib/tables/_g_l_y_f.py +++ b/Lib/fontTools/ttLib/tables/_g_l_y_f.py @@ -1,11 +1,10 @@ """_g_l_y_f.py -- Converter classes for the 'glyf' table.""" from collections import namedtuple -from fontTools.misc.py23 import tostr from fontTools.misc import sstruct from fontTools import ttLib from fontTools import version -from fontTools.misc.textTools import safeEval, pad +from fontTools.misc.textTools import tostr, safeEval, pad from fontTools.misc.arrayTools import calcIntBounds, pointInRect from fontTools.misc.bezierTools import calcQuadraticBounds from fontTools.misc.fixedTools import ( diff --git a/Lib/fontTools/ttLib/tables/_h_d_m_x.py b/Lib/fontTools/ttLib/tables/_h_d_m_x.py index 954d1bc18..9f860d2a5 100644 --- a/Lib/fontTools/ttLib/tables/_h_d_m_x.py +++ b/Lib/fontTools/ttLib/tables/_h_d_m_x.py @@ -1,5 +1,5 @@ -from fontTools.misc.py23 import bytechr, byteord, strjoin from fontTools.misc import sstruct +from fontTools.misc.textTools import bytechr, byteord, strjoin from . import DefaultTable import array from collections.abc import Mapping diff --git a/Lib/fontTools/ttLib/tables/_l_t_a_g.py b/Lib/fontTools/ttLib/tables/_l_t_a_g.py index caec72a37..ce3c6b977 100644 --- a/Lib/fontTools/ttLib/tables/_l_t_a_g.py +++ b/Lib/fontTools/ttLib/tables/_l_t_a_g.py @@ -1,5 +1,4 @@ -from fontTools.misc.py23 import bytesjoin, tobytes -from fontTools.misc.textTools import safeEval +from fontTools.misc.textTools import bytesjoin, tobytes, safeEval from . import DefaultTable import struct diff --git a/Lib/fontTools/ttLib/tables/_m_e_t_a.py b/Lib/fontTools/ttLib/tables/_m_e_t_a.py index 1a125f824..3faf0a56d 100644 --- a/Lib/fontTools/ttLib/tables/_m_e_t_a.py +++ b/Lib/fontTools/ttLib/tables/_m_e_t_a.py @@ -1,6 +1,5 @@ -from fontTools.misc.py23 import bytesjoin, strjoin from fontTools.misc import sstruct -from fontTools.misc.textTools import readHex +from fontTools.misc.textTools import bytesjoin, strjoin, readHex from fontTools.ttLib import TTLibError from . import DefaultTable diff --git a/Lib/fontTools/ttLib/tables/_n_a_m_e.py b/Lib/fontTools/ttLib/tables/_n_a_m_e.py index 206469def..b51e1b725 100644 --- a/Lib/fontTools/ttLib/tables/_n_a_m_e.py +++ b/Lib/fontTools/ttLib/tables/_n_a_m_e.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- -from fontTools.misc.py23 import bytechr, byteord, bytesjoin, strjoin, tobytes, tostr from fontTools.misc import sstruct -from fontTools.misc.textTools import safeEval +from fontTools.misc.textTools import bytechr, byteord, bytesjoin, strjoin, tobytes, tostr, safeEval from fontTools.misc.encodingTools import getEncoding from fontTools.ttLib import newTable from . import DefaultTable diff --git a/Lib/fontTools/ttLib/tables/_p_o_s_t.py b/Lib/fontTools/ttLib/tables/_p_o_s_t.py index 9bd49444e..c54b87f03 100644 --- a/Lib/fontTools/ttLib/tables/_p_o_s_t.py +++ b/Lib/fontTools/ttLib/tables/_p_o_s_t.py @@ -1,8 +1,7 @@ -from fontTools.misc.py23 import bytechr, byteord, tobytes, tostr from fontTools import ttLib from fontTools.ttLib.standardGlyphOrder import standardGlyphOrder from fontTools.misc import sstruct -from fontTools.misc.textTools import safeEval, readHex +from fontTools.misc.textTools import bytechr, byteord, tobytes, tostr, safeEval, readHex from . import DefaultTable import sys import struct diff --git a/Lib/fontTools/ttLib/tables/_t_r_a_k.py b/Lib/fontTools/ttLib/tables/_t_r_a_k.py index 7f3227dc5..3052496f5 100644 --- a/Lib/fontTools/ttLib/tables/_t_r_a_k.py +++ b/Lib/fontTools/ttLib/tables/_t_r_a_k.py @@ -1,4 +1,3 @@ -from fontTools.misc.py23 import bytesjoin from fontTools.misc import sstruct from fontTools.misc.fixedTools import ( fixedToFloat as fi2fl, @@ -6,7 +5,7 @@ from fontTools.misc.fixedTools import ( floatToFixedToStr as fl2str, strToFixedToFloat as str2fl, ) -from fontTools.misc.textTools import safeEval +from fontTools.misc.textTools import bytesjoin, safeEval from fontTools.ttLib import TTLibError from . import DefaultTable import struct diff --git a/Lib/fontTools/ttLib/tables/asciiTable.py b/Lib/fontTools/ttLib/tables/asciiTable.py index 7b036c8e1..a97d92dfe 100644 --- a/Lib/fontTools/ttLib/tables/asciiTable.py +++ b/Lib/fontTools/ttLib/tables/asciiTable.py @@ -1,4 +1,4 @@ -from fontTools.misc.py23 import strjoin, tobytes, tostr +from fontTools.misc.textTools import strjoin, tobytes, tostr from . import DefaultTable diff --git a/Lib/fontTools/ttLib/tables/otBase.py b/Lib/fontTools/ttLib/tables/otBase.py index 0e748124a..917bc982e 100644 --- a/Lib/fontTools/ttLib/tables/otBase.py +++ b/Lib/fontTools/ttLib/tables/otBase.py @@ -1,4 +1,4 @@ -from fontTools.misc.py23 import Tag, bytesjoin +from fontTools.misc.textTools import Tag, bytesjoin from .DefaultTable import DefaultTable import sys import array diff --git a/Lib/fontTools/ttLib/tables/otConverters.py b/Lib/fontTools/ttLib/tables/otConverters.py index 058813a81..3733c079d 100644 --- a/Lib/fontTools/ttLib/tables/otConverters.py +++ b/Lib/fontTools/ttLib/tables/otConverters.py @@ -1,4 +1,3 @@ -from fontTools.misc.py23 import bytesjoin, tobytes, tostr from fontTools.misc.fixedTools import ( fixedToFloat as fi2fl, floatToFixed as fl2fi, @@ -8,7 +7,7 @@ from fontTools.misc.fixedTools import ( versionToFixed as ve2fi, ) from fontTools.misc.roundTools import nearestMultipleShortestRepr, otRound -from fontTools.misc.textTools import pad, safeEval +from fontTools.misc.textTools import bytesjoin, tobytes, tostr, pad, safeEval from fontTools.ttLib import getSearchRange from .otBase import (CountReference, FormatSwitchingBaseTable, OTTableReader, OTTableWriter, ValueRecordFactory) diff --git a/Lib/fontTools/ttLib/tables/otTables.py b/Lib/fontTools/ttLib/tables/otTables.py index 679df751e..f7e854489 100644 --- a/Lib/fontTools/ttLib/tables/otTables.py +++ b/Lib/fontTools/ttLib/tables/otTables.py @@ -9,9 +9,8 @@ import copy from enum import IntEnum import itertools from collections import defaultdict, namedtuple -from fontTools.misc.py23 import bytesjoin from fontTools.misc.roundTools import otRound -from fontTools.misc.textTools import pad, safeEval +from fontTools.misc.textTools import bytesjoin, pad, safeEval from .otBase import ( BaseTable, FormatSwitchingBaseTable, ValueRecord, CountReference, getFormatSwitchingBaseTableClass, diff --git a/Lib/fontTools/ttLib/tables/ttProgram.py b/Lib/fontTools/ttLib/tables/ttProgram.py index a1dfa3c52..723775837 100644 --- a/Lib/fontTools/ttLib/tables/ttProgram.py +++ b/Lib/fontTools/ttLib/tables/ttProgram.py @@ -1,7 +1,6 @@ """ttLib.tables.ttProgram.py -- Assembler/disassembler for TrueType bytecode programs.""" -from fontTools.misc.py23 import strjoin -from fontTools.misc.textTools import num2binary, binary2num, readHex +from fontTools.misc.textTools import num2binary, binary2num, readHex, strjoin import array from io import StringIO import re diff --git a/Lib/fontTools/ttLib/ttFont.py b/Lib/fontTools/ttLib/ttFont.py index 5ccd182cd..fc0f97122 100644 --- a/Lib/fontTools/ttLib/ttFont.py +++ b/Lib/fontTools/ttLib/ttFont.py @@ -1,5 +1,5 @@ from fontTools.misc import xmlWriter -from fontTools.misc.py23 import Tag, byteord, tostr +from fontTools.misc.textTools import Tag, byteord, tostr from fontTools.misc.loggingTools import deprecateArgument from fontTools.ttLib import TTLibError from fontTools.ttLib.sfnt import SFNTReader, SFNTWriter diff --git a/Lib/fontTools/ttLib/woff2.py b/Lib/fontTools/ttLib/woff2.py index cc58afa5f..b66661ab9 100644 --- a/Lib/fontTools/ttLib/woff2.py +++ b/Lib/fontTools/ttLib/woff2.py @@ -1,4 +1,3 @@ -from fontTools.misc.py23 import Tag, bytechr, byteord, bytesjoin from io import BytesIO import sys import array @@ -6,7 +5,7 @@ import struct from collections import OrderedDict from fontTools.misc import sstruct from fontTools.misc.arrayTools import calcIntBounds -from fontTools.misc.textTools import pad +from fontTools.misc.textTools import Tag, bytechr, byteord, bytesjoin, pad from fontTools.ttLib import (TTFont, TTLibError, getTableModule, getTableClass, getSearchRange) from fontTools.ttLib.sfnt import (SFNTReader, SFNTWriter, DirectoryEntry, diff --git a/Lib/fontTools/ttx.py b/Lib/fontTools/ttx.py index 55b27513e..e3421d195 100644 --- a/Lib/fontTools/ttx.py +++ b/Lib/fontTools/ttx.py @@ -86,10 +86,10 @@ usage: ttx [options] inputfile1 [... inputfileN] """ -from fontTools.misc.py23 import Tag, tostr from fontTools.ttLib import TTFont, TTLibError from fontTools.misc.macCreatorType import getMacCreatorAndType from fontTools.unicode import setUnicodeData +from fontTools.misc.textTools import Tag, tostr from fontTools.misc.timeTools import timestampSinceEpoch from fontTools.misc.loggingTools import Timer from fontTools.misc.cliTools import makeOutputFileName diff --git a/Lib/fontTools/ufoLib/glifLib.py b/Lib/fontTools/ufoLib/glifLib.py index 3003110e5..1437d8876 100755 --- a/Lib/fontTools/ufoLib/glifLib.py +++ b/Lib/fontTools/ufoLib/glifLib.py @@ -19,7 +19,7 @@ import fs.base import fs.errors import fs.osfs import fs.path -from fontTools.misc.py23 import tobytes +from fontTools.misc.textTools import tobytes from fontTools.misc import plistlib from fontTools.pens.pointPen import AbstractPointPen, PointToSegmentPen from fontTools.ufoLib.errors import GlifLibError diff --git a/Lib/fontTools/ufoLib/plistlib.py b/Lib/fontTools/ufoLib/plistlib.py index 763816873..1f52f20a2 100644 --- a/Lib/fontTools/ufoLib/plistlib.py +++ b/Lib/fontTools/ufoLib/plistlib.py @@ -3,7 +3,7 @@ for the old ufoLib.plistlib module, which was moved to fontTools.misc.plistlib. Please use the latter instead. """ from fontTools.misc.plistlib import dump, dumps, load, loads -from fontTools.misc.py23 import tobytes +from fontTools.misc.textTools import tobytes # The following functions were part of the old py2-like ufoLib.plistlib API. # They are kept only for backward compatiblity. diff --git a/Lib/fontTools/unicodedata/__init__.py b/Lib/fontTools/unicodedata/__init__.py index 8845b8295..1c1210f97 100644 --- a/Lib/fontTools/unicodedata/__init__.py +++ b/Lib/fontTools/unicodedata/__init__.py @@ -1,4 +1,4 @@ -from fontTools.misc.py23 import byteord, tostr +from fontTools.misc.textTools import byteord, tostr import re from bisect import bisect_right diff --git a/Lib/fontTools/varLib/__init__.py b/Lib/fontTools/varLib/__init__.py index 9d39747e1..db10a72f5 100644 --- a/Lib/fontTools/varLib/__init__.py +++ b/Lib/fontTools/varLib/__init__.py @@ -18,9 +18,9 @@ Then you can make a variable-font this way: API *will* change in near future. """ -from fontTools.misc.py23 import Tag, tostr -from fontTools.misc.roundTools import noRound, otRound from fontTools.misc.vector import Vector +from fontTools.misc.roundTools import noRound, otRound +from fontTools.misc.textTools import Tag, tostr from fontTools.ttLib import TTFont, newTable from fontTools.ttLib.tables._f_v_a_r import Axis, NamedInstance from fontTools.ttLib.tables._g_l_y_f import GlyphCoordinates diff --git a/Snippets/svg2glif.py b/Snippets/svg2glif.py index 22fcc7d1f..b28cb25d1 100755 --- a/Snippets/svg2glif.py +++ b/Snippets/svg2glif.py @@ -4,7 +4,7 @@ __requires__ = ["fontTools"] -from fontTools.misc.py23 import SimpleNamespace +from types import SimpleNamespace from fontTools.svgLib import SVGPath from fontTools.pens.pointPen import SegmentToPointPen diff --git a/Tests/feaLib/lexer_test.py b/Tests/feaLib/lexer_test.py index 24dc5dbab..3df67f706 100644 --- a/Tests/feaLib/lexer_test.py +++ b/Tests/feaLib/lexer_test.py @@ -1,6 +1,6 @@ -from fontTools.misc.py23 import tobytes from fontTools.feaLib.error import FeatureLibError, IncludedFeaNotFound from fontTools.feaLib.lexer import IncludingLexer, Lexer +from fontTools.misc.textTools import tobytes from io import StringIO import os import shutil diff --git a/Tests/misc/plistlib_test.py b/Tests/misc/plistlib_test.py index b2ce408d1..5659d6900 100644 --- a/Tests/misc/plistlib_test.py +++ b/Tests/misc/plistlib_test.py @@ -5,9 +5,9 @@ import codecs import collections from io import BytesIO from numbers import Integral -from fontTools.misc.py23 import tostr from fontTools.misc import etree from fontTools.misc import plistlib +from fontTools.misc.textTools import tostr from fontTools.ufoLib.plistlib import ( readPlist, readPlistFromString, writePlist, writePlistToString, ) diff --git a/Tests/misc/xmlReader_test.py b/Tests/misc/xmlReader_test.py index f6775cbcd..ec4aff578 100644 --- a/Tests/misc/xmlReader_test.py +++ b/Tests/misc/xmlReader_test.py @@ -1,8 +1,8 @@ -from fontTools.misc.py23 import strjoin from io import BytesIO import os import unittest from fontTools.ttLib import TTFont +from fontTools.misc.textTools import strjoin from fontTools.misc.xmlReader import XMLReader, ProgressPrinter, BUFSIZE import tempfile diff --git a/Tests/misc/xmlWriter_test.py b/Tests/misc/xmlWriter_test.py index 7b9894c66..694715431 100644 --- a/Tests/misc/xmlWriter_test.py +++ b/Tests/misc/xmlWriter_test.py @@ -1,7 +1,7 @@ -from fontTools.misc.py23 import bytesjoin, tobytes from io import BytesIO import os import unittest +from fontTools.misc.textTools import bytesjoin, tobytes from fontTools.misc.xmlWriter import XMLWriter HEADER = b'\n' diff --git a/Tests/subset/subset_test.py b/Tests/subset/subset_test.py index ea63db638..4b3d9a843 100644 --- a/Tests/subset/subset_test.py +++ b/Tests/subset/subset_test.py @@ -1,6 +1,6 @@ import io -from fontTools.misc.py23 import tobytes, tostr from fontTools.misc.testTools import getXML +from fontTools.misc.textTools import tobytes, tostr from fontTools import subset from fontTools.fontBuilder import FontBuilder from fontTools.pens.ttGlyphPen import TTGlyphPen diff --git a/Tests/svgLib/path/path_test.py b/Tests/svgLib/path/path_test.py index 8ee334a07..caf351d40 100644 --- a/Tests/svgLib/path/path_test.py +++ b/Tests/svgLib/path/path_test.py @@ -1,4 +1,4 @@ -from fontTools.misc.py23 import tobytes +from fontTools.misc.textTools import tobytes from fontTools.pens.recordingPen import RecordingPen from fontTools.svgLib import SVGPath diff --git a/Tests/ttLib/tables/T_S_I__1_test.py b/Tests/ttLib/tables/T_S_I__1_test.py index 3a565adc6..b792221e1 100644 --- a/Tests/ttLib/tables/T_S_I__1_test.py +++ b/Tests/ttLib/tables/T_S_I__1_test.py @@ -1,5 +1,5 @@ -from fontTools.misc.py23 import tobytes from fontTools.misc.loggingTools import CapturingLogHandler +from fontTools.misc.textTools import tobytes from fontTools.ttLib import TTFont, TTLibError from fontTools.ttLib.tables.T_S_I__0 import table_T_S_I__0 from fontTools.ttLib.tables.T_S_I__1 import table_T_S_I__1 diff --git a/Tests/ttLib/tables/_m_o_r_x_test.py b/Tests/ttLib/tables/_m_o_r_x_test.py index 0b807f820..d65619ca6 100644 --- a/Tests/ttLib/tables/_m_o_r_x_test.py +++ b/Tests/ttLib/tables/_m_o_r_x_test.py @@ -1,6 +1,5 @@ -from fontTools.misc.py23 import bytechr, bytesjoin from fontTools.misc.testTools import FakeFont, getXML, parseXML -from fontTools.misc.textTools import deHexStr, hexStr +from fontTools.misc.textTools import bytechr, bytesjoin, deHexStr, hexStr from fontTools.ttLib import newTable import unittest diff --git a/Tests/ttLib/tables/_n_a_m_e_test.py b/Tests/ttLib/tables/_n_a_m_e_test.py index 8e8297049..38fbfef78 100644 --- a/Tests/ttLib/tables/_n_a_m_e_test.py +++ b/Tests/ttLib/tables/_n_a_m_e_test.py @@ -1,7 +1,7 @@ -from fontTools.misc.py23 import bytesjoin, tostr from fontTools.misc import sstruct from fontTools.misc.loggingTools import CapturingLogHandler from fontTools.misc.testTools import FakeFont +from fontTools.misc.textTools import bytesjoin, tostr from fontTools.misc.xmlWriter import XMLWriter from io import BytesIO import struct diff --git a/Tests/ttLib/woff2_test.py b/Tests/ttLib/woff2_test.py index c0d60ceed..7fe40dd10 100644 --- a/Tests/ttLib/woff2_test.py +++ b/Tests/ttLib/woff2_test.py @@ -1,4 +1,3 @@ -from fontTools.misc.py23 import Tag, bytechr, byteord from fontTools import ttLib from fontTools.ttLib import woff2 from fontTools.ttLib.tables import _g_l_y_f @@ -10,6 +9,7 @@ from fontTools.ttLib.woff2 import ( WOFF2HmtxTable, WOFF2Writer, unpackBase128, unpack255UShort, pack255UShort) import unittest from fontTools.misc import sstruct +from fontTools.misc.textTools import Tag, bytechr, byteord from fontTools import fontBuilder from fontTools.pens.ttGlyphPen import TTGlyphPen from io import BytesIO diff --git a/Tests/ufoLib/UFOZ_test.py b/Tests/ufoLib/UFOZ_test.py index 51362106d..6ea39e9af 100644 --- a/Tests/ufoLib/UFOZ_test.py +++ b/Tests/ufoLib/UFOZ_test.py @@ -1,7 +1,7 @@ -from fontTools.misc.py23 import tostr from fontTools.ufoLib import UFOReader, UFOWriter, UFOFileStructure from fontTools.ufoLib.errors import UFOLibError, GlifLibError from fontTools.misc import plistlib +from fontTools.misc.textTools import tostr import sys import os import fs.osfs diff --git a/Tests/varLib/instancer/instancer_test.py b/Tests/varLib/instancer/instancer_test.py index cbc313dc9..37d3da48a 100644 --- a/Tests/varLib/instancer/instancer_test.py +++ b/Tests/varLib/instancer/instancer_test.py @@ -1,5 +1,5 @@ -from fontTools.misc.py23 import Tag from fontTools.misc.fixedTools import floatToFixedToFloat +from fontTools.misc.textTools import Tag from fontTools import ttLib from fontTools import designspaceLib from fontTools.feaLib.builder import addOpenTypeFeaturesFromString