Make __cmp__() functions stable

This commit is contained in:
Behdad Esfahbod 2013-10-28 12:07:15 +01:00
parent d95db25720
commit 0ba7aa7ab5
9 changed files with 28 additions and 42 deletions

View File

@ -37,9 +37,8 @@ class DefaultTable:
return "<'%s' table at %x>" % (self.tableTag, id(self))
def __cmp__(self, other):
if type(self) != type(other) or \
self.__class__ != other.__class__:
return cmp(id(self), id(other))
if type(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__)

View File

@ -238,9 +238,8 @@ class GlyphRecord:
"""Compare method, so a list of NameRecords can be sorted
according to the spec by just sorting it..."""
if type(self) != type(other) or \
self.__class__ != other.__class__:
return cmp(id(self), id(other))
if type(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)
@ -328,9 +327,8 @@ class StringRecord:
"""Compare method, so a list of NameRecords can be sorted
according to the spec by just sorting it..."""
if type(self) != type(other) or \
self.__class__ != other.__class__:
return cmp(id(self), id(other))
if type(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)

View File

@ -151,9 +151,8 @@ class CmapSubtable:
writer.newline()
def __cmp__(self, other):
if type(self) != type(other) or \
self.__class__ != other.__class__:
return cmp(id(self), id(other))
if type(self) != type(other): return cmp(type(self), type(other))
if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
# implemented so that list.sort() sorts according to the cmap spec.
selfTuple = (

View File

@ -721,9 +721,8 @@ class Glyph:
self.data = data
def __cmp__(self, other):
if type(self) != type(other) or \
self.__class__ != other.__class__:
return cmp(id(self), id(other))
if type(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__)
@ -885,9 +884,8 @@ class GlyphComponent:
self.flags = safeEval(attrs["flags"])
def __cmp__(self, other):
if type(self) != type(other) or \
self.__class__ != other.__class__:
return cmp(id(self), id(other))
if type(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__)

View File

@ -90,9 +90,8 @@ class table__h_e_a_d(DefaultTable.DefaultTable):
setattr(self, name, value)
def __cmp__(self, other):
if type(self) != type(other) or \
self.__class__ != other.__class__:
return cmp(id(self), id(other))
if type(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()

View File

@ -164,9 +164,8 @@ class KernTable_format_0:
del self.kernTable[pair]
def __cmp__(self, other):
if type(self) != type(other) or \
self.__class__ != other.__class__:
return cmp(id(self), id(other))
if type(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__)

View File

@ -60,9 +60,8 @@ class table__l_o_c_a(DefaultTable.DefaultTable):
return len(self.locations)
def __cmp__(self, other):
if type(self) != type(other) or \
self.__class__ != other.__class__:
return cmp(id(self), id(other))
if type(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)

View File

@ -89,9 +89,8 @@ class table__n_a_m_e(DefaultTable.DefaultTable):
return None # not found
def __cmp__(self, other):
if type(self) != type(other) or \
self.__class__ != other.__class__:
return cmp(id(self), id(other))
if type(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)
@ -139,9 +138,8 @@ class NameRecord:
"""Compare method, so a list of NameRecords can be sorted
according to the spec by just sorting it..."""
if type(self) != type(other) or \
self.__class__ != other.__class__:
return cmp(id(self), id(other))
if type(self) != type(other): return cmp(type(self), type(other))
if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
selftuple = (self.platformID,
self.platEncID,

View File

@ -288,9 +288,8 @@ class OTTableWriter:
return hash(self.items)
def __cmp__(self, other):
if type(self) != type(other) or \
self.__class__ != other.__class__:
return cmp(id(self), id(other))
if type(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)
@ -671,9 +670,8 @@ class BaseTable:
setattr(self, conv.name, value)
def __cmp__(self, other):
if type(self) != type(other) or \
self.__class__ != other.__class__:
return cmp(id(self), id(other))
if type(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__)
@ -835,8 +833,7 @@ class ValueRecord:
setattr(self, name, value)
def __cmp__(self, other):
if type(self) != type(other) or \
self.__class__ != other.__class__:
return cmp(id(self), id(other))
if type(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__)