fonttools/Lib/fontTools/ttLib/tables/DefaultTable.py
Cosimo Lupo d82a31dd57 return NotImplemented from __ne__ if __eq__ returns NotImplemented
otherwise `not NotImplemented` (always False) is returned from __ne__ when `type(self) != type(other)`, leading to illogic results like:

>>> from fontTools.ttLib.tables.DefaultTable import DefaultTable
>>> t = DefaultTable('test')
>>> t == 0
False
>>> t != 0
False

The latter of course should return True.
2016-03-11 15:10:50 +00:00

50 lines
1.3 KiB
Python

from __future__ import print_function, division, absolute_import
from fontTools.misc.py23 import *
from fontTools.ttLib import getClassTag
class DefaultTable(object):
dependencies = []
def __init__(self, tag=None):
if tag is None:
tag = getClassTag(self.__class__)
self.tableTag = Tag(tag)
def decompile(self, data, ttFont):
self.data = data
def compile(self, ttFont):
return self.data
def toXML(self, writer, ttFont, progress=None):
if hasattr(self, "ERROR"):
writer.comment("An error occurred during the decompilation of this table")
writer.newline()
writer.comment(self.ERROR)
writer.newline()
writer.begintag("hexdata")
writer.newline()
writer.dumphex(self.compile(ttFont))
writer.endtag("hexdata")
writer.newline()
def fromXML(self, name, attrs, content, ttFont):
from fontTools.misc.textTools import readHex
from fontTools import ttLib
if name != "hexdata":
raise ttLib.TTLibError("can't handle '%s' element" % name)
self.decompile(readHex(content), ttFont)
def __repr__(self):
return "<'%s' table at %x>" % (self.tableTag, id(self))
def __eq__(self, other):
if type(self) != type(other):
return NotImplemented
return self.__dict__ == other.__dict__
def __ne__(self, other):
result = self.__eq__(other)
return result if result is NotImplemented else not result