From 12814aa7b174428ef7c2baf83411b12fef921e0b Mon Sep 17 00:00:00 2001
From: Chris Simpkins <git.simpkins@gmail.com>
Date: Thu, 29 Aug 2019 22:58:42 -0400
Subject: [PATCH] refactor array.fromstring to array.frombytes

fromstring is a deprecated array method
---
 Lib/fontTools/designspaceLib/__init__.py     |  2 +-
 Lib/fontTools/svgLib/path/__init__.py        |  8 ++++----
 Lib/fontTools/ttLib/tables/G_P_K_G_.py       |  4 ++--
 Lib/fontTools/ttLib/tables/G__l_o_c.py       |  4 ++--
 Lib/fontTools/ttLib/tables/L_T_S_H_.py       |  2 +-
 Lib/fontTools/ttLib/tables/T_S_I__5.py       |  2 +-
 Lib/fontTools/ttLib/tables/TupleVariation.py |  4 ++--
 Lib/fontTools/ttLib/tables/_c_m_a_p.py       | 10 +++++-----
 Lib/fontTools/ttLib/tables/_c_v_t.py         |  2 +-
 Lib/fontTools/ttLib/tables/_g_l_y_f.py       |  2 +-
 Lib/fontTools/ttLib/tables/_g_v_a_r.py       |  2 +-
 Lib/fontTools/ttLib/tables/_l_o_c_a.py       |  2 +-
 Lib/fontTools/ttLib/tables/_p_o_s_t.py       |  4 ++--
 Lib/fontTools/varLib/designspace.py          |  2 +-
 Snippets/svg2glif.py                         |  2 +-
 Tests/svgLib/path/path_test.py               |  6 +++---
 16 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/Lib/fontTools/designspaceLib/__init__.py b/Lib/fontTools/designspaceLib/__init__.py
index 8063ac5..72a4cee 100644
--- a/Lib/fontTools/designspaceLib/__init__.py
+++ b/Lib/fontTools/designspaceLib/__init__.py
@@ -38,7 +38,7 @@ def to_plist(value):
     except AttributeError:
         # Python 3
         string = plistlib.dumps(value).decode()
-    return ET.fromstring(string)[0]
+    return ET.frombytes(string)[0]
 
 
 def from_plist(element):
diff --git a/Lib/fontTools/svgLib/path/__init__.py b/Lib/fontTools/svgLib/path/__init__.py
index 4f17e76..a18abd9 100644
--- a/Lib/fontTools/svgLib/path/__init__.py
+++ b/Lib/fontTools/svgLib/path/__init__.py
@@ -27,10 +27,10 @@ class SVGPath(object):
         svg.draw(pen)
 
     Or reading from a string containing SVG data, using the alternative
-    'fromstring' (a class method):
+    'frombytes' (a class method):
 
         data = '<?xml version="1.0" ...'
-        svg = SVGPath.fromstring(data)
+        svg = SVGPath.frombytes(data)
         svg.draw(pen)
 
     Both constructors can optionally take a 'transform' matrix (6-float
@@ -46,9 +46,9 @@ class SVGPath(object):
         self.transform = transform
 
     @classmethod
-    def fromstring(cls, data, transform=None):
+    def frombytes(cls, data, transform=None):
         self = cls(transform=transform)
-        self.root = ElementTree.fromstring(data)
+        self.root = ElementTree.frombytes(data)
         return self
 
     def draw(self, pen):
diff --git a/Lib/fontTools/ttLib/tables/G_P_K_G_.py b/Lib/fontTools/ttLib/tables/G_P_K_G_.py
index 4e13830..2849293 100644
--- a/Lib/fontTools/ttLib/tables/G_P_K_G_.py
+++ b/Lib/fontTools/ttLib/tables/G_P_K_G_.py
@@ -24,7 +24,7 @@ class table_G_P_K_G_(DefaultTable.DefaultTable):
 
 		GMAPoffsets = array.array("I")
 		endPos = (self.numGMAPs+1) * 4
-		GMAPoffsets.fromstring(newData[:endPos])
+		GMAPoffsets.frombytes(newData[:endPos])
 		if sys.byteorder != "big":
 			GMAPoffsets.byteswap()
 		self.GMAPs = []
@@ -35,7 +35,7 @@ class table_G_P_K_G_(DefaultTable.DefaultTable):
 		pos = endPos
 		endPos = pos + (self.numGlyplets + 1)*4
 		glyphletOffsets = array.array("I")
-		glyphletOffsets.fromstring(newData[pos:endPos])
+		glyphletOffsets.frombytes(newData[pos:endPos])
 		if sys.byteorder != "big":
 			glyphletOffsets.byteswap()
 		self.glyphlets = []
diff --git a/Lib/fontTools/ttLib/tables/G__l_o_c.py b/Lib/fontTools/ttLib/tables/G__l_o_c.py
index d77c483..d1d62d1 100644
--- a/Lib/fontTools/ttLib/tables/G__l_o_c.py
+++ b/Lib/fontTools/ttLib/tables/G__l_o_c.py
@@ -29,11 +29,11 @@ class table_G__l_o_c(DefaultTable.DefaultTable):
         flags = self.flags
         del self.flags
         self.locations = array.array('I' if flags & 1 else 'H')
-        self.locations.fromstring(data[:len(data) - self.numAttribs * (flags & 2)])
+        self.locations.frombytes(data[:len(data) - self.numAttribs * (flags & 2)])
         self.locations.byteswap()
         self.attribIds = array.array('H')
         if flags & 2:
-            self.attribIds.fromstring(data[-self.numAttribs * 2:])
+            self.attribIds.frombytes(data[-self.numAttribs * 2:])
             self.attribIds.byteswap()
 
     def compile(self, ttFont):
diff --git a/Lib/fontTools/ttLib/tables/L_T_S_H_.py b/Lib/fontTools/ttLib/tables/L_T_S_H_.py
index dd0f195..6bb1df2 100644
--- a/Lib/fontTools/ttLib/tables/L_T_S_H_.py
+++ b/Lib/fontTools/ttLib/tables/L_T_S_H_.py
@@ -19,7 +19,7 @@ class table_L_T_S_H_(DefaultTable.DefaultTable):
 		# ouch: the assertion is not true in Chicago!
 		#assert numGlyphs == ttFont['maxp'].numGlyphs
 		yPels = array.array("B")
-		yPels.fromstring(data)
+		yPels.frombytes(data)
 		self.yPels = {}
 		for i in range(numGlyphs):
 			self.yPels[ttFont.getGlyphName(i)] = yPels[i]
diff --git a/Lib/fontTools/ttLib/tables/T_S_I__5.py b/Lib/fontTools/ttLib/tables/T_S_I__5.py
index dbf9e5a..11a2018 100644
--- a/Lib/fontTools/ttLib/tables/T_S_I__5.py
+++ b/Lib/fontTools/ttLib/tables/T_S_I__5.py
@@ -17,7 +17,7 @@ class table_T_S_I__5(DefaultTable.DefaultTable):
 		numGlyphs = ttFont['maxp'].numGlyphs
 		assert len(data) == 2 * numGlyphs
 		a = array.array("H")
-		a.fromstring(data)
+		a.frombytes(data)
 		if sys.byteorder != "big":
 			a.byteswap()
 		self.glyphGrouping = {}
diff --git a/Lib/fontTools/ttLib/tables/TupleVariation.py b/Lib/fontTools/ttLib/tables/TupleVariation.py
index 5fa71c8..e084dff 100644
--- a/Lib/fontTools/ttLib/tables/TupleVariation.py
+++ b/Lib/fontTools/ttLib/tables/TupleVariation.py
@@ -266,7 +266,7 @@ class TupleVariation(object):
 			else:
 				points = array.array("B")
 				pointsSize = numPointsInRun
-			points.fromstring(data[pos:pos+pointsSize])
+			points.frombytes(data[pos:pos+pointsSize])
 			if sys.byteorder != "big":
 				points.byteswap()
 
@@ -424,7 +424,7 @@ class TupleVariation(object):
 				else:
 					deltas = array.array("b")
 					deltasSize = numDeltasInRun
-				deltas.fromstring(data[pos:pos+deltasSize])
+				deltas.frombytes(data[pos:pos+deltasSize])
 				if sys.byteorder != "big":
 					deltas.byteswap()
 				assert len(deltas) == numDeltasInRun
diff --git a/Lib/fontTools/ttLib/tables/_c_m_a_p.py b/Lib/fontTools/ttLib/tables/_c_m_a_p.py
index eccf69e..1eab2bf 100644
--- a/Lib/fontTools/ttLib/tables/_c_m_a_p.py
+++ b/Lib/fontTools/ttLib/tables/_c_m_a_p.py
@@ -254,7 +254,7 @@ class cmap_format_0(CmapSubtable):
 		data = self.data # decompileHeader assigns the data after the header to self.data
 		assert 262 == self.length, "Format 0 cmap subtable not 262 bytes"
 		gids = array.array("B")
-		gids.fromstring(self.data)
+		gids.frombytes(self.data)
 		charCodes = list(range(len(gids)))
 		self.cmap = _make_map(self.ttFont, charCodes, gids)
 
@@ -338,7 +338,7 @@ class cmap_format_2(CmapSubtable):
 		maxSubHeaderindex = 0
 		# get the key array, and determine the number of subHeaders.
 		allKeys = array.array("H")
-		allKeys.fromstring(data[:512])
+		allKeys.frombytes(data[:512])
 		data = data[512:]
 		if sys.byteorder != "big":
 			allKeys.byteswap()
@@ -355,7 +355,7 @@ class cmap_format_2(CmapSubtable):
 			pos += 8
 			giDataPos = pos + subHeader.idRangeOffset-2
 			giList = array.array("H")
-			giList.fromstring(data[giDataPos:giDataPos + subHeader.entryCount*2])
+			giList.frombytes(data[giDataPos:giDataPos + subHeader.entryCount*2])
 			if sys.byteorder != "big":
 				giList.byteswap()
 			subHeader.glyphIndexArray = giList
@@ -699,7 +699,7 @@ class cmap_format_4(CmapSubtable):
 		segCount = segCountX2 // 2
 
 		allCodes = array.array("H")
-		allCodes.fromstring(data)
+		allCodes.frombytes(data)
 		self.data = data = None
 
 		if sys.byteorder != "big":
@@ -871,7 +871,7 @@ class cmap_format_6(CmapSubtable):
 		data = data[4:]
 		#assert len(data) == 2 * entryCount  # XXX not true in Apple's Helvetica!!!
 		gids = array.array("H")
-		gids.fromstring(data[:2 * int(entryCount)])
+		gids.frombytes(data[:2 * int(entryCount)])
 		if sys.byteorder != "big":
 			gids.byteswap()
 		self.data = data = None
diff --git a/Lib/fontTools/ttLib/tables/_c_v_t.py b/Lib/fontTools/ttLib/tables/_c_v_t.py
index 4fbee7b..5e42dd0 100644
--- a/Lib/fontTools/ttLib/tables/_c_v_t.py
+++ b/Lib/fontTools/ttLib/tables/_c_v_t.py
@@ -9,7 +9,7 @@ class table__c_v_t(DefaultTable.DefaultTable):
 
 	def decompile(self, data, ttFont):
 		values = array.array("h")
-		values.fromstring(data)
+		values.frombytes(data)
 		if sys.byteorder != "big":
 			values.byteswap()
 		self.values = values
diff --git a/Lib/fontTools/ttLib/tables/_g_l_y_f.py b/Lib/fontTools/ttLib/tables/_g_l_y_f.py
index 58c1eb2..3598b15 100644
--- a/Lib/fontTools/ttLib/tables/_g_l_y_f.py
+++ b/Lib/fontTools/ttLib/tables/_g_l_y_f.py
@@ -511,7 +511,7 @@ class Glyph(object):
 
 	def decompileCoordinates(self, data):
 		endPtsOfContours = array.array("h")
-		endPtsOfContours.fromstring(data[:2*self.numberOfContours])
+		endPtsOfContours.frombytes(data[:2*self.numberOfContours])
 		if sys.byteorder != "big":
 			endPtsOfContours.byteswap()
 		self.endPtsOfContours = endPtsOfContours.tolist()
diff --git a/Lib/fontTools/ttLib/tables/_g_v_a_r.py b/Lib/fontTools/ttLib/tables/_g_v_a_r.py
index 9f97c31..0d5f79a 100644
--- a/Lib/fontTools/ttLib/tables/_g_v_a_r.py
+++ b/Lib/fontTools/ttLib/tables/_g_v_a_r.py
@@ -120,7 +120,7 @@ class table__g_v_a_r(DefaultTable.DefaultTable):
 			# Long format: array of UInt32
 			offsets = array.array("I")
 			offsetsSize = (glyphCount + 1) * 4
-		offsets.fromstring(data[0 : offsetsSize])
+		offsets.frombytes(data[0 : offsetsSize])
 		if sys.byteorder != "big":
 			offsets.byteswap()
 
diff --git a/Lib/fontTools/ttLib/tables/_l_o_c_a.py b/Lib/fontTools/ttLib/tables/_l_o_c_a.py
index 2fcd528..e4bafa1 100644
--- a/Lib/fontTools/ttLib/tables/_l_o_c_a.py
+++ b/Lib/fontTools/ttLib/tables/_l_o_c_a.py
@@ -20,7 +20,7 @@ class table__l_o_c_a(DefaultTable.DefaultTable):
 		else:
 			format = "H"
 		locations = array.array(format)
-		locations.fromstring(data)
+		locations.frombytes(data)
 		if sys.byteorder != "big":
 			locations.byteswap()
 		if not longFormat:
diff --git a/Lib/fontTools/ttLib/tables/_p_o_s_t.py b/Lib/fontTools/ttLib/tables/_p_o_s_t.py
index ede62da..3399cad 100644
--- a/Lib/fontTools/ttLib/tables/_p_o_s_t.py
+++ b/Lib/fontTools/ttLib/tables/_p_o_s_t.py
@@ -83,7 +83,7 @@ class table__p_o_s_t(DefaultTable.DefaultTable):
 			numGlyphs = ttFont['maxp'].numGlyphs
 		data = data[2:]
 		indices = array.array("H")
-		indices.fromstring(data[:2*numGlyphs])
+		indices.frombytes(data[:2*numGlyphs])
 		if sys.byteorder != "big":
 			indices.byteswap()
 		data = data[2*numGlyphs:]
@@ -133,7 +133,7 @@ class table__p_o_s_t(DefaultTable.DefaultTable):
 		from fontTools import agl
 		numGlyphs = ttFont['maxp'].numGlyphs
 		indices = array.array("H")
-		indices.fromstring(data)
+		indices.frombytes(data)
 		if sys.byteorder != "big":
 			indices.byteswap()
 		# In some older fonts, the size of the post table doesn't match
diff --git a/Lib/fontTools/varLib/designspace.py b/Lib/fontTools/varLib/designspace.py
index 7f235af..64fd7a4 100644
--- a/Lib/fontTools/varLib/designspace.py
+++ b/Lib/fontTools/varLib/designspace.py
@@ -104,7 +104,7 @@ def load(filename):
 
 def loads(string):
 	"""Load designspace from a string."""
-	return _load(ET.fromstring(string))
+	return _load(ET.frombytes(string))
 
 if __name__ == '__main__':
 	import sys
diff --git a/Snippets/svg2glif.py b/Snippets/svg2glif.py
index 2dd6402..a6e4e58 100755
--- a/Snippets/svg2glif.py
+++ b/Snippets/svg2glif.py
@@ -24,7 +24,7 @@ def svg2glif(svg, name, width=0, height=0, unicodes=None, transform=None,
     conversion (must be tuple of 6 floats, or a FontTools Transform object).
     """
     glyph = SimpleNamespace(width=width, height=height, unicodes=unicodes)
-    outline = SVGPath.fromstring(svg, transform=transform)
+    outline = SVGPath.frombytes(svg, transform=transform)
 
     # writeGlyphToString takes a callable (usually a glyph's drawPoints
     # method) that accepts a PointPen, however SVGPath currently only has
diff --git a/Tests/svgLib/path/path_test.py b/Tests/svgLib/path/path_test.py
index 09b9447..4bdc844 100644
--- a/Tests/svgLib/path/path_test.py
+++ b/Tests/svgLib/path/path_test.py
@@ -50,16 +50,16 @@ class SVGPathTest(object):
 
         assert pen.value == EXPECTED_PEN_COMMANDS
 
-    def test_fromstring(self):
+    def test_frombytes(self):
         pen = RecordingPen()
-        svg = SVGPath.fromstring(SVG_DATA)
+        svg = SVGPath.frombytes(SVG_DATA)
         svg.draw(pen)
 
         assert pen.value == EXPECTED_PEN_COMMANDS
 
     def test_transform(self):
         pen = RecordingPen()
-        svg = SVGPath.fromstring(SVG_DATA,
+        svg = SVGPath.frombytes(SVG_DATA,
                                  transform=(1.0, 0, 0, -1.0, 0, 1000))
         svg.draw(pen)
 
-- 
2.23.0

