py23 Remove uses of __cmp__ and cmp()
diff --git a/Lib/fontTools/ttLib/tables/DefaultTable.py b/Lib/fontTools/ttLib/tables/DefaultTable.py
index 0da4f9b..1532e1e 100644
--- a/Lib/fontTools/ttLib/tables/DefaultTable.py
+++ b/Lib/fontTools/ttLib/tables/DefaultTable.py
@@ -36,9 +36,7 @@
 	def __repr__(self):
 		return "<'%s' table at %x>" % (self.tableTag, id(self))
 	
-	def __cmp__(self, other):
-		if not isinstance(self, type(other)): return cmp(type(self), type(other))
-		if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
-
-		return cmp(self.__dict__, other.__dict__)
-
+	def __eq__(self, other):
+		if type(self) != type(other):
+			raise TypeError("unordered types %s() < %s()", type(self), type(other))
+		return self.__dict__ == other.__dict__
diff --git a/Lib/fontTools/ttLib/tables/M_E_T_A_.py b/Lib/fontTools/ttLib/tables/M_E_T_A_.py
index 0ec42a9..83ebeb1 100644
--- a/Lib/fontTools/ttLib/tables/M_E_T_A_.py
+++ b/Lib/fontTools/ttLib/tables/M_E_T_A_.py
@@ -224,16 +224,6 @@
 			datum = struct.pack(">L", self.offset)
 		data = data + datum
 		return data
-
-
-	def __cmp__(self, other):
-		"""Compare method, so a list of NameRecords can be sorted
-		according to the spec by just sorting it..."""
-
-		if not isinstance(self, type(other)): return cmp(type(self), type(other))
-		if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
-
-		return cmp(self.glyphID, other.glyphID)
 	
 	def __repr__(self):
 		return "GlyphRecord[ glyphID: " + str(self.glyphID) + ", nMetaEntry: " + str(self.nMetaEntry) + ", offset: " + str(self.offset) + " ]"
@@ -311,15 +301,6 @@
 			datum = struct.pack(">L", self.offset)
 		data = data + datum
 		return data
-
-	def __cmp__(self, other):
-		"""Compare method, so a list of NameRecords can be sorted
-		according to the spec by just sorting it..."""
-
-		if not isinstance(self, type(other)): return cmp(type(self), type(other))
-		if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
-
-		return cmp(self.labelID, other.labelID)
 	
 	def __repr__(self):
 		return "StringRecord [ labelID: " + str(self.labelID) + " aka " + getLabelString(self.labelID) \
diff --git a/Lib/fontTools/ttLib/tables/_c_m_a_p.py b/Lib/fontTools/ttLib/tables/_c_m_a_p.py
index a1fa2a3..224b346 100644
--- a/Lib/fontTools/ttLib/tables/_c_m_a_p.py
+++ b/Lib/fontTools/ttLib/tables/_c_m_a_p.py
@@ -52,7 +52,7 @@
 			tables.append(table)
 	
 	def compile(self, ttFont):
-		self.tables.sort()    # sort according to the spec; see CmapSubtable.__cmp__()
+		self.tables.sort()    # sort according to the spec; see CmapSubtable.__lt__()
 		numSubTables = len(self.tables)
 		totalOffset = 4 + 8 * numSubTables
 		data = struct.pack(">HH", self.tableVersion, numSubTables)
@@ -149,10 +149,11 @@
 				writer.comment(Unicode[code])
 			writer.newline()
 	
-	def __cmp__(self, other):
-		if not isinstance(self, type(other)): return cmp(type(self), type(other))
+	def __lt__(self, other):
+		if not isinstance(other, CmapSubtable):
+			raise TypeError("unordered types %s() < %s()", type(self), type(other))
 
-		# implemented so that list.sort() sorts according to the cmap spec.
+		# implemented so that list.sort() sorts according to the spec.
 		selfTuple = (
 			getattr(self, "platformID", None),
 			getattr(self, "platEncID", None),
@@ -163,7 +164,7 @@
 			getattr(other, "platEncID", None),
 			getattr(other, "language", None),
 			other.__dict__)
-		return cmp(selfTuple, otherTuple)
+		return selfTuple < otherTuple
 
 
 class cmap_format_0(CmapSubtable):
@@ -1076,21 +1077,7 @@
 		threeByteString = struct.pack(">L", val)[:3]
 	return threeByteString
 
-def cmpUVSListEntry(first, second):
-	uv1, glyphName1 = first
-	uv2, glyphName2 = second
-	
-	if (glyphName1 == None) and (glyphName2 != None):
-		return -1
-	elif (glyphName2 == None) and (glyphName1 != None):
-		return 1
-		
-	ret = cmp(uv1, uv2)
-	if ret:
-		return ret
-	return cmp(glyphName1, glyphName2)
-		
-		
+
 class cmap_format_14(CmapSubtable):
 
 	def decompileHeader(self, data, ttFont):
@@ -1163,7 +1150,7 @@
 		uvsList = sorted(uvsDict.keys())
 		for uvs in uvsList:
 			uvList = uvsDict[uvs]
-			uvList.sort(cmpUVSListEntry)
+			uvList.sort(key=lambda item: (item[1] != None, item[0], item[1]))
 			for uv, gname in uvList:
 				if gname == None:
 					gname = "None"
@@ -1177,7 +1164,7 @@
 		self.format = safeEval(attrs["format"])
 		self.length = safeEval(attrs["length"])
 		self.numVarSelectorRecords = safeEval(attrs["numVarSelectorRecords"])
-		self.language = 0xFF # provide a value so that  CmapSubtable.__cmp__() won't fail
+		self.language = 0xFF # provide a value so that  CmapSubtable.__lt__() won't fail
 		if not hasattr(self, "cmap"):
 			self.cmap = {} # so that clients that expect this to exist in a cmap table won't fail.
 		if not hasattr(self, "uvsDict"):
diff --git a/Lib/fontTools/ttLib/tables/_g_l_y_f.py b/Lib/fontTools/ttLib/tables/_g_l_y_f.py
index 4e1d929..2be2974 100644
--- a/Lib/fontTools/ttLib/tables/_g_l_y_f.py
+++ b/Lib/fontTools/ttLib/tables/_g_l_y_f.py
@@ -723,12 +723,11 @@
 			data = data + "\0" * nPadBytes
 
 		self.data = data
-	
-	def __cmp__(self, other):
-		if not isinstance(self, type(other)): return cmp(type(self), type(other))
-		if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
 
-		return cmp(self.__dict__, other.__dict__)
+	def __eq__(self, other):
+		if type(self) != type(other):
+			raise TypeError("unordered types %s() < %s()", type(self), type(other))
+		return self.__dict__ == other.__dict__
 
 
 class GlyphComponent:
@@ -886,11 +885,10 @@
 			self.transform = [[scale, 0], [0, scale]]
 		self.flags = safeEval(attrs["flags"])
 	
-	def __cmp__(self, other):
-		if not isinstance(self, type(other)): return cmp(type(self), type(other))
-		if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
-
-		return cmp(self.__dict__, other.__dict__)
+	def __eq__(self, other):
+		if type(self) != type(other):
+			raise TypeError("unordered types %s() < %s()", type(self), type(other))
+		return self.__dict__ == other.__dict__
 
 class GlyphCoordinates:
 
@@ -967,6 +965,11 @@
 			a[2*i  ] = int(.5 + x * t[0][0] + y * t[1][0])
 			a[2*i+1] = int(.5 + x * t[0][1] + y * t[1][1])
 
+	def __eq__(self, other):
+		if type(self) != type(other):
+			raise TypeError("unordered types %s() < %s()", type(self), type(other))
+		return self._a == other._a
+
 
 def reprflag(flag):
 	bin = ""
diff --git a/Lib/fontTools/ttLib/tables/_h_e_a_d.py b/Lib/fontTools/ttLib/tables/_h_e_a_d.py
index 3ef1717..0d150b6 100644
--- a/Lib/fontTools/ttLib/tables/_h_e_a_d.py
+++ b/Lib/fontTools/ttLib/tables/_h_e_a_d.py
@@ -86,19 +86,6 @@
 		else:
 			value = safeEval(value)
 		setattr(self, name, value)
-	
-	def __cmp__(self, other):
-		if not isinstance(self, type(other)): return cmp(type(self), type(other))
-		if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
-
-		selfdict = self.__dict__.copy()
-		otherdict = other.__dict__.copy()
-		# for testing purposes, compare without the modified and checkSumAdjustment
-		# fields, since they are allowed to be different.
-		for key in ["modified", "checkSumAdjustment"]:
-			del selfdict[key]
-			del otherdict[key]
-		return cmp(selfdict, otherdict)
 
 
 def calc_mac_epoch_diff():
diff --git a/Lib/fontTools/ttLib/tables/_k_e_r_n.py b/Lib/fontTools/ttLib/tables/_k_e_r_n.py
index 718468a..e27575b 100644
--- a/Lib/fontTools/ttLib/tables/_k_e_r_n.py
+++ b/Lib/fontTools/ttLib/tables/_k_e_r_n.py
@@ -160,12 +160,6 @@
 	
 	def __delitem__(self, pair):
 		del self.kernTable[pair]
-	
-	def __cmp__(self, other):
-		if not isinstance(self, type(other)): return cmp(type(self), type(other))
-		if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
-
-		return cmp(self.__dict__, other.__dict__)
 
 
 class KernTable_format_2:
diff --git a/Lib/fontTools/ttLib/tables/_l_o_c_a.py b/Lib/fontTools/ttLib/tables/_l_o_c_a.py
index 9a0dcc5..daa9d03 100644
--- a/Lib/fontTools/ttLib/tables/_l_o_c_a.py
+++ b/Lib/fontTools/ttLib/tables/_l_o_c_a.py
@@ -58,10 +58,4 @@
 	
 	def __len__(self):
 		return len(self.locations)
-	
-	def __cmp__(self, other):
-		if not isinstance(self, type(other)): return cmp(type(self), type(other))
-		if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
-
-		return cmp(self.locations, other.locations)
 
diff --git a/Lib/fontTools/ttLib/tables/_n_a_m_e.py b/Lib/fontTools/ttLib/tables/_n_a_m_e.py
index 32645e5..3584bfc 100644
--- a/Lib/fontTools/ttLib/tables/_n_a_m_e.py
+++ b/Lib/fontTools/ttLib/tables/_n_a_m_e.py
@@ -48,7 +48,7 @@
 			# only happens when there are NO name table entries read
 			# from the TTX file
 			self.names = []
-		self.names.sort()  # sort according to the spec; see NameRecord.__cmp__()
+		self.names.sort()  # sort according to the spec; see NameRecord.__lt__()
 		stringData = ""
 		format = 0
 		n = len(self.names)
@@ -87,12 +87,6 @@
 					return namerecord
 		return None # not found
 	
-	def __cmp__(self, other):
-		if not isinstance(self, type(other)): return cmp(type(self), type(other))
-		if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
-
-		return cmp(self.names, other.names)
-	
 
 class NameRecord:
 	
@@ -128,27 +122,26 @@
 		else:
 			self.string = s.encode("latin1")
 	
-	def __cmp__(self, other):
-		"""Compare method, so a list of NameRecords can be sorted
-		according to the spec by just sorting it..."""
+	def __lt__(self, other):
+		if type(self) != type(other):
+			raise TypeError("unordered types %s() < %s()", type(self), type(other))
 
-		if not isinstance(self, type(other)): return cmp(type(self), type(other))
-
-		selftuple = (
+		# implemented so that list.sort() sorts according to the spec.
+		selfTuple = (
 			getattr(self, "platformID", None),
 			getattr(self, "platEncID", None),
 			getattr(self, "langID", None),
 			getattr(self, "nameID", None),
 			getattr(self, "string", None),
 		)
-		othertuple = (
+		otherTuple = (
 			getattr(other, "platformID", None),
 			getattr(other, "platEncID", None),
 			getattr(other, "langID", None),
 			getattr(other, "nameID", None),
 			getattr(other, "string", None),
 		)
-		return cmp(selftuple, othertuple)
+		return selfTuple < otherTuple
 	
 	def __repr__(self):
 		return "<NameRecord NameID=%d; PlatformID=%d; LanguageID=%d>" % (
diff --git a/Lib/fontTools/ttLib/tables/otBase.py b/Lib/fontTools/ttLib/tables/otBase.py
index 80b9d80..d43f156 100644
--- a/Lib/fontTools/ttLib/tables/otBase.py
+++ b/Lib/fontTools/ttLib/tables/otBase.py
@@ -287,11 +287,10 @@
 		# only works after self._doneWriting() has been called
 		return hash(self.items)
 	
-	def __cmp__(self, other):
-		if not isinstance(self, type(other)): return cmp(type(self), type(other))
-		if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
-
-		return cmp(self.items, other.items)
+	def __eq__(self, other):
+		if type(self) != type(other):
+			raise TypeError("unordered types %s() < %s()", type(self), type(other))
+		return self.items == other.items
 	
 	def _doneWriting(self, internedTables=None):
 		# Convert CountData references to data string items
@@ -674,13 +673,14 @@
 		else:
 			setattr(self, conv.name, value)
 	
-	def __cmp__(self, other):
-		if not isinstance(self, type(other)): return cmp(type(self), type(other))
-		if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
+	def __eq__(self, other):
+		if type(self) != type(other):
+			raise TypeError("unordered types %s() < %s()", type(self), type(other))
 
 		self.ensureDecompiled()
+		other.ensureDecompiled()
 
-		return cmp(self.__dict__, other.__dict__)
+		return self.__dict__ == other.__dict__
 
 
 class FormatSwitchingBaseTable(BaseTable):
@@ -840,8 +840,7 @@
 				value.fromXML(name2, attrs2, content2, font)
 			setattr(self, name, value)
 	
-	def __cmp__(self, other):
-		if not isinstance(self, type(other)): return cmp(type(self), type(other))
-		if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
-
-		return cmp(self.__dict__, other.__dict__)
+	def __eq__(self, other):
+		if type(self) != type(other):
+			raise TypeError("unordered types %s() < %s()", type(self), type(other))
+		return self.__dict__ == other.__dict__
diff --git a/Lib/fontTools/ttLib/tables/otTables.py b/Lib/fontTools/ttLib/tables/otTables.py
index 03e199c..54a684f 100644
--- a/Lib/fontTools/ttLib/tables/otTables.py
+++ b/Lib/fontTools/ttLib/tables/otTables.py
@@ -43,7 +43,7 @@
 			# Some SIL fonts have coverage entries that don't have sorted
 			# StartCoverageIndex.  If it is so, fixup and warn.  We undo
 			# this when writing font out.
-			sorted_ranges = sorted(ranges, cmp=lambda a,b: cmp(a.StartCoverageIndex,b.StartCoverageIndex))
+			sorted_ranges = sorted(ranges, key=lambda a: a.StartCoverageIndex)
 			if ranges != sorted_ranges:
 				warnings.warn("GSUB/GPOS Coverage is not sorted by glyph ids.")
 				ranges = sorted_ranges
@@ -106,7 +106,7 @@
 					index = index + end - start + 1
 				if brokenOrder:
 					warnings.warn("GSUB/GPOS Coverage is not sorted by glyph ids.")
-					ranges.sort(cmp=lambda a,b: cmp(a.StartID,b.StartID))
+					ranges.sort(key=lambda a: a.StartID)
 				for r in ranges:
 					del r.StartID
 				format = 2