Remove most uses of module string
diff --git a/Lib/fontTools/ttLib/__init__.py b/Lib/fontTools/ttLib/__init__.py
index feee006..2e208b4 100644
--- a/Lib/fontTools/ttLib/__init__.py
+++ b/Lib/fontTools/ttLib/__init__.py
@@ -47,7 +47,6 @@
import sys
import os
-import string
haveMacSupport = 0
if sys.platform == "mac":
@@ -500,8 +499,7 @@
glyphName = agl.UV2AGL[unicode]
else:
# create uni<CODE> name
- glyphName = "uni" + string.upper(string.zfill(
- hex(unicode)[2:], 4))
+ glyphName = "uni%04X" % unicode
tempName = glyphName
n = 1
while tempName in allNames:
@@ -881,7 +879,7 @@
elif tag == "GlyphOrder":
return tag
if re.match("[A-Za-z_][A-Za-z_0-9]* *$", tag):
- return string.strip(tag)
+ return tag.strip()
else:
return tagToIdentifier(tag)
diff --git a/Lib/fontTools/ttLib/tables/C_B_D_T_.py b/Lib/fontTools/ttLib/tables/C_B_D_T_.py
index cb01021..2b72011 100644
--- a/Lib/fontTools/ttLib/tables/C_B_D_T_.py
+++ b/Lib/fontTools/ttLib/tables/C_B_D_T_.py
@@ -4,7 +4,6 @@
from . import E_B_D_T_
-import string
import struct
from fontTools.misc import sstruct
from .BitmapGlyphMetrics import BigGlyphMetrics, bigGlyphMetricsFormat, SmallGlyphMetrics, smallGlyphMetricsFormat
@@ -51,7 +50,7 @@
dataList.append(sstruct.pack(smallGlyphMetricsFormat, self.metrics))
dataList.append(struct.pack(">L", len(self.imageData)))
dataList.append(self.imageData)
- return string.join(dataList, "")
+ return ''.join(dataList)
class cbdt_bitmap_format_18(BitmapPlusBigMetricsMixin, ColorBitmapGlyph):
@@ -70,7 +69,7 @@
dataList.append(sstruct.pack(bigGlyphMetricsFormat, self.metrics))
dataList.append(struct.pack(">L", len(self.imageData)))
dataList.append(self.imageData)
- return string.join(dataList, "")
+ return ''.join(dataList)
class cbdt_bitmap_format_19(ColorBitmapGlyph):
diff --git a/Lib/fontTools/ttLib/tables/DefaultTable.py b/Lib/fontTools/ttLib/tables/DefaultTable.py
index 704546e..5202f6a 100644
--- a/Lib/fontTools/ttLib/tables/DefaultTable.py
+++ b/Lib/fontTools/ttLib/tables/DefaultTable.py
@@ -1,4 +1,3 @@
-import string
import sys
class DefaultTable:
diff --git a/Lib/fontTools/ttLib/tables/E_B_D_T_.py b/Lib/fontTools/ttLib/tables/E_B_D_T_.py
index 7a1dbb6..3e1e45c 100644
--- a/Lib/fontTools/ttLib/tables/E_B_D_T_.py
+++ b/Lib/fontTools/ttLib/tables/E_B_D_T_.py
@@ -1,7 +1,6 @@
from . import DefaultTable
import os
-import string
import struct
from fontTools.misc import sstruct
import itertools
@@ -113,7 +112,7 @@
# of any of the problems in the convertion that may arise.
curIndexSubTable.locations = dataLocations
- return string.join(dataList, "")
+ return ''.join(dataList)
def toXML(self, writer, ttFont):
# When exporting to XML if one of the data export formats
@@ -212,7 +211,7 @@
binaryList.append('0')
value = value >> 1
numBits -= numBitsCut
- return string.join(binaryList, "")
+ return ''.join(binaryList)
def _binary2data(binary):
byteList = []
@@ -224,7 +223,7 @@
if curBit == '1':
curByte |= 1
byteList.append(chr(curByte))
- return string.join(byteList, "")
+ return ''.join(byteList)
def _memoize(f):
class memodict(dict):
@@ -332,7 +331,7 @@
name, attr, content = element
if name == 'row':
mapParams = zip(attr['value'], itertools.repeat('1'))
- rowData = string.join(itertools.starmap(binaryConv.get, mapParams), "")
+ rowData = ''.join(itertools.starmap(binaryConv.get, mapParams))
dataRows.append(_binary2data(rowData))
bitmapObject.setRows(dataRows, bitDepth=bitDepth, metrics=metrics, reverseBytes=True)
@@ -532,7 +531,7 @@
dataList.append(chr(newByte))
# The way the data is kept is opposite the algorithm used.
- data = string.join(dataList, "")
+ data = ''.join(dataList)
if not reverseBytes:
data = _reverseBytes(data)
return data
@@ -711,7 +710,7 @@
for curComponent in self.componentArray:
curComponent.glyphCode = ttFont.getGlyphID(curComponent.name)
dataList.append(sstruct.pack(ebdtComponentFormat, curComponent))
- return string.join(dataList, "")
+ return ''.join(dataList)
class ebdt_bitmap_format_9(BitmapPlusBigMetricsMixin, ComponentBitmapGlyph):
@@ -735,7 +734,7 @@
for curComponent in self.componentArray:
curComponent.glyphCode = ttFont.getGlyphID(curComponent.name)
dataList.append(sstruct.pack(ebdtComponentFormat, curComponent))
- return string.join(dataList, "")
+ return ''.join(dataList)
# Dictionary of bitmap formats to the class representing that format
diff --git a/Lib/fontTools/ttLib/tables/E_B_L_C_.py b/Lib/fontTools/ttLib/tables/E_B_L_C_.py
index 8bff48a..b5a3e6f 100644
--- a/Lib/fontTools/ttLib/tables/E_B_L_C_.py
+++ b/Lib/fontTools/ttLib/tables/E_B_L_C_.py
@@ -1,6 +1,5 @@
from . import DefaultTable
-import string
import struct
from fontTools.misc import sstruct
import itertools
@@ -197,7 +196,7 @@
dataList.append(data)
dataList.extend(indexSubTablePairDataList)
- return string.join(dataList, "")
+ return ''.join(dataList)
def toXML(self, writer, ttFont):
writer.simpletag('header', [('version', self.version)])
@@ -477,7 +476,7 @@
# Take care of any padding issues. Only occurs in format 3.
if offsetDataSize * len(dataList) % 4 != 0:
dataList.append(struct.pack(dataFormat, 0))
- return string.join(dataList, "")
+ return ''.join(dataList)
return OffsetArrayIndexSubTableMixin
@@ -534,7 +533,7 @@
dataList = [EblcIndexSubTable.compile(self, ttFont)]
dataList.append(struct.pack(">L", self.imageSize))
dataList.append(sstruct.pack(bigGlyphMetricsFormat, self.metrics))
- return string.join(dataList, "")
+ return ''.join(dataList)
class eblc_index_sub_table_3(_createOffsetArrayIndexSubTableMixin('H'), EblcIndexSubTable):
pass
@@ -576,7 +575,7 @@
dataList.append(struct.pack(">L", len(glyphIds)))
tmp = [struct.pack(codeOffsetPairFormat, *cop) for cop in zip(idsPlusPad, offsets)]
dataList += tmp
- data = string.join(dataList, "")
+ data = ''.join(dataList)
return data
class eblc_index_sub_table_5(FixedSizeIndexSubTableMixin, EblcIndexSubTable):
@@ -604,7 +603,7 @@
dataList += [struct.pack(">H", curId) for curId in glyphIds]
if len(glyphIds) % 2 == 1:
dataList.append(struct.pack(">H", 0))
- return string.join(dataList, "")
+ return ''.join(dataList)
# Dictionary of indexFormat to the class representing that format.
eblc_sub_table_classes = {
diff --git a/Lib/fontTools/ttLib/tables/M_E_T_A_.py b/Lib/fontTools/ttLib/tables/M_E_T_A_.py
index 9137a76..9289350 100644
--- a/Lib/fontTools/ttLib/tables/M_E_T_A_.py
+++ b/Lib/fontTools/ttLib/tables/M_E_T_A_.py
@@ -2,7 +2,6 @@
import struct
from fontTools.misc import sstruct
from fontTools.misc.textTools import safeEval
-import string
import sys
diff --git a/Lib/fontTools/ttLib/tables/S_I_N_G_.py b/Lib/fontTools/ttLib/tables/S_I_N_G_.py
index 68ca8b8..0813700 100644
--- a/Lib/fontTools/ttLib/tables/S_I_N_G_.py
+++ b/Lib/fontTools/ttLib/tables/S_I_N_G_.py
@@ -2,7 +2,6 @@
from fontTools.misc import sstruct
import struct
import time
-import string
from fontTools.misc.textTools import safeEval, num2binary, binary2num
SINGFormat = """
diff --git a/Lib/fontTools/ttLib/tables/S_V_G_.py b/Lib/fontTools/ttLib/tables/S_V_G_.py
index f92d4e7..d33dcf3 100644
--- a/Lib/fontTools/ttLib/tables/S_V_G_.py
+++ b/Lib/fontTools/ttLib/tables/S_V_G_.py
@@ -50,7 +50,6 @@
import xml.etree.cElementTree as ET
except ImportError:
import xml.etree.ElementTree as ET
-import string
import re
XML = ET.XML
diff --git a/Lib/fontTools/ttLib/tables/T_S_I__1.py b/Lib/fontTools/ttLib/tables/T_S_I__1.py
index d2a9465..7f23593 100644
--- a/Lib/fontTools/ttLib/tables/T_S_I__1.py
+++ b/Lib/fontTools/ttLib/tables/T_S_I__1.py
@@ -1,5 +1,4 @@
from . import DefaultTable
-import string
class table_T_S_I__1(DefaultTable.DefaultTable):
@@ -85,7 +84,7 @@
continue
writer.begintag("glyphProgram", name=name)
writer.newline()
- writer.write_noindent(string.replace(text, "\r", "\n"))
+ writer.write_noindent(text.replace("\r", "\n"))
writer.newline()
writer.endtag("glyphProgram")
writer.newline()
@@ -98,7 +97,7 @@
continue
writer.begintag("extraProgram", name=name)
writer.newline()
- writer.write_noindent(string.replace(text, "\r", "\n"))
+ writer.write_noindent(text.replace("\r", "\n"))
writer.newline()
writer.endtag("extraProgram")
writer.newline()
@@ -108,8 +107,8 @@
if not hasattr(self, "glyphPrograms"):
self.glyphPrograms = {}
self.extraPrograms = {}
- lines = string.split(string.replace(string.join(content, ""), "\r", "\n"), "\n")
- text = string.join(lines[1:-1], "\r")
+ lines = ''.join(content).replace("\r", "\n").split("\n")
+ text = '\r'.join(lines[1:-1])
if name == "glyphProgram":
self.glyphPrograms[attrs["name"]] = text
elif name == "extraProgram":
diff --git a/Lib/fontTools/ttLib/tables/_g_l_y_f.py b/Lib/fontTools/ttLib/tables/_g_l_y_f.py
index 1f3ee8f..82b14c6 100644
--- a/Lib/fontTools/ttLib/tables/_g_l_y_f.py
+++ b/Lib/fontTools/ttLib/tables/_g_l_y_f.py
@@ -57,7 +57,6 @@
def compile(self, ttFont):
if not hasattr(self, "glyphOrder"):
self.glyphOrder = ttFont.getGlyphOrder()
- import string
locations = []
currentLocation = 0
dataList = []
@@ -69,7 +68,7 @@
currentLocation = currentLocation + len(glyphData)
dataList.append(glyphData)
locations.append(currentLocation)
- data = string.join(dataList, "")
+ data = ''.join(dataList)
if 'loca' in ttFont:
ttFont['loca'].set(locations)
ttFont['maxp'].numGlyphs = len(self.glyphs)
diff --git a/Lib/fontTools/ttLib/tables/_h_d_m_x.py b/Lib/fontTools/ttLib/tables/_h_d_m_x.py
index 63d579a..74a67e5 100644
--- a/Lib/fontTools/ttLib/tables/_h_d_m_x.py
+++ b/Lib/fontTools/ttLib/tables/_h_d_m_x.py
@@ -1,6 +1,5 @@
from . import DefaultTable
from fontTools.misc import sstruct
-import string
hdmxHeaderFormat = """
> # big endian!
@@ -75,15 +74,15 @@
def fromXML(self, name, attrs, content, ttFont):
if name != "hdmxData":
return
- content = string.join(content, "")
- lines = string.split(content, ";")
- topRow = string.split(lines[0])
+ content = ''.join(content)
+ lines = content.split(";")
+ topRow = lines[0].split()
assert topRow[0] == "ppem:", "illegal hdmx format"
ppems = list(map(int, topRow[1:]))
self.hdmx = hdmx = {}
for ppem in ppems:
hdmx[ppem] = {}
- lines = map(string.split, lines[1:])
+ lines = (line.split() for line in lines[1:])
for line in lines:
if not line:
continue
diff --git a/Lib/fontTools/ttLib/tables/_h_e_a_d.py b/Lib/fontTools/ttLib/tables/_h_e_a_d.py
index 7a9f218..a819874 100644
--- a/Lib/fontTools/ttLib/tables/_h_e_a_d.py
+++ b/Lib/fontTools/ttLib/tables/_h_e_a_d.py
@@ -1,7 +1,6 @@
from . import DefaultTable
from fontTools.misc import sstruct
import time
-import string
from fontTools.misc.textTools import safeEval, num2binary, binary2num
@@ -119,13 +118,13 @@
_weekdays = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']
def parse_date(datestring):
- datestring = string.lower(datestring)
- weekday, month, day, tim, year = string.split(datestring)
+ datestring = datestring.lower()
+ weekday, month, day, tim, year = datestring.split()
weekday = _weekdays.index(weekday)
month = _months.index(month)
year = int(year)
day = int(day)
- hour, minute, second = [int(item) for item in string.split(tim, ":")]
+ hour, minute, second = [int(item) for item in tim.split(":")]
t = (year, month, day, hour, minute, second, weekday, 0, 0)
return int(time.mktime(t) - time.timezone)
diff --git a/Lib/fontTools/ttLib/tables/_n_a_m_e.py b/Lib/fontTools/ttLib/tables/_n_a_m_e.py
index 4a09413..6bbb43a 100644
--- a/Lib/fontTools/ttLib/tables/_n_a_m_e.py
+++ b/Lib/fontTools/ttLib/tables/_n_a_m_e.py
@@ -2,7 +2,6 @@
import struct
from fontTools.misc import sstruct
from fontTools.misc.textTools import safeEval
-import string
nameRecordFormat = """
> # big endian
@@ -129,7 +128,7 @@
s = s.strip()
self.string = s.encode("utf_16_be")
else:
- s = string.strip(string.join(content, ""))
+ s = ''.join(content).strip()
self.string = unicode(s, "utf8").encode("latin1")
def __cmp__(self, other):
diff --git a/Lib/fontTools/ttLib/tables/asciiTable.py b/Lib/fontTools/ttLib/tables/asciiTable.py
index e3a38e1..c65a3b3 100644
--- a/Lib/fontTools/ttLib/tables/asciiTable.py
+++ b/Lib/fontTools/ttLib/tables/asciiTable.py
@@ -1,4 +1,3 @@
-import string
from . import DefaultTable
@@ -7,16 +6,16 @@
def toXML(self, writer, ttFont):
data = self.data
# removing null bytes. XXX needed??
- data = string.split(data, '\0')
- data = string.join(data, '')
+ data = data.split('\0')
+ data = ''.join(data)
writer.begintag("source")
writer.newline()
- writer.write_noindent(string.replace(data, "\r", "\n"))
+ writer.write_noindent(data.replace("\r", "\n"))
writer.newline()
writer.endtag("source")
writer.newline()
def fromXML(self, name, attrs, content, ttFont):
- lines = string.split(string.replace(string.join(content, ""), "\r", "\n"), "\n")
- self.data = string.join(lines[1:-1], "\r")
+ lines = ''.join(content).replace("\r", "\n").split("\n")
+ self.data = "\r".join(lines[1:-1])
diff --git a/Lib/fontTools/ttLib/tables/ttProgram.py b/Lib/fontTools/ttLib/tables/ttProgram.py
index 5996b5c..51c7794 100644
--- a/Lib/fontTools/ttLib/tables/ttProgram.py
+++ b/Lib/fontTools/ttLib/tables/ttProgram.py
@@ -1,7 +1,7 @@
"""ttLib.tables.ttProgram.py -- Assembler/disassembler for TrueType bytecode programs."""
import array
-import re, string
+import re
from fontTools.misc.textTools import num2binary, binary2num, readHex
# first, the list of instructions that eat bytes or words from the instruction stream
@@ -242,11 +242,11 @@
j = 0
for j in range(nValues):
if j and not (j % 25):
- writer.write(string.join(line, " "))
+ writer.write(' '.join(line))
writer.newline()
line = []
line.append(assembly[i+j])
- writer.write(string.join(line, " "))
+ writer.write(' '.join(line))
writer.newline()
i = i + j + 1
writer.endtag("assembly")
@@ -258,7 +258,7 @@
def fromXML(self, name, attrs, content, ttFont):
if name == "assembly":
- self.fromAssembly(string.join(content, ""))
+ self.fromAssembly(''.join(content))
self._assemble()
del self.assembly
else:
@@ -266,11 +266,11 @@
self.fromBytecode(readHex(content))
def _assemble(self,
- skipWhite=_skipWhite, mnemonicDict=mnemonicDict, strip=string.strip,
+ skipWhite=_skipWhite, mnemonicDict=mnemonicDict,
binary2num=binary2num):
assembly = self.assembly
if isinstance(assembly, type([])):
- assembly = string.join(assembly, " ")
+ assembly = ' '.join(assembly)
bytecode = []
push = bytecode.append
lenAssembly = len(assembly)
@@ -284,7 +284,7 @@
if comment:
continue
- arg = strip(arg)
+ arg = arg.strip()
if mnemonic.startswith("INSTR"):
# Unknown instruction
op = int(mnemonic[5:])