When reading from XML, populate all members that are computed
Not really all... Propagated counts are still not populated. Most of mti_tests pass again. Four failing now. NB: In the code being removed in this commit, this line: "setattr(self, conv.repeat, len(seq)+conv.aux)" had the wrong sign for conv.aux. Should have been a minus.
This commit is contained in:
parent
6250b60ec3
commit
1eb8afbfa3
@ -567,12 +567,35 @@ class BaseTable(object):
|
|||||||
def getConverterByName(self, name):
|
def getConverterByName(self, name):
|
||||||
return self.convertersByName[name]
|
return self.convertersByName[name]
|
||||||
|
|
||||||
|
def populateDefaults(self, propagator=None):
|
||||||
|
for conv in self.getConverters():
|
||||||
|
if conv.repeat:
|
||||||
|
if not hasattr(self, conv.name):
|
||||||
|
setattr(self, conv.name, [])
|
||||||
|
countValue = len(getattr(self, conv.name)) - conv.aux
|
||||||
|
try:
|
||||||
|
count_conv = self.getConverterByName(conv.repeat)
|
||||||
|
setattr(self, conv.repeat, countValue)
|
||||||
|
except KeyError:
|
||||||
|
# conv.repeat is a propagated count
|
||||||
|
if propagator and conv.repeat in propagator:
|
||||||
|
propagator[conv.repeat].setValue(countValue)
|
||||||
|
else:
|
||||||
|
if conv.aux and not eval(conv.aux, None, self.__dict__):
|
||||||
|
continue
|
||||||
|
if hasattr(self, conv.name):
|
||||||
|
continue # Warn if it should NOT be present?!
|
||||||
|
if hasattr(conv, 'writeNullOffset'):
|
||||||
|
setattr(self, conv.name, None) # Warn?
|
||||||
|
#elif not conv.isCount:
|
||||||
|
# # Warn?
|
||||||
|
# pass
|
||||||
|
|
||||||
def decompile(self, reader, font):
|
def decompile(self, reader, font):
|
||||||
self.readFormat(reader)
|
self.readFormat(reader)
|
||||||
table = {}
|
table = {}
|
||||||
self.__rawTable = table # for debugging
|
self.__rawTable = table # for debugging
|
||||||
converters = self.getConverters()
|
for conv in self.getConverters():
|
||||||
for conv in converters:
|
|
||||||
if conv.name == "SubTable":
|
if conv.name == "SubTable":
|
||||||
conv = conv.getConverter(reader.tableTag,
|
conv = conv.getConverter(reader.tableTag,
|
||||||
table["LookupType"])
|
table["LookupType"])
|
||||||
@ -716,16 +739,7 @@ class BaseTable(object):
|
|||||||
if seq is None:
|
if seq is None:
|
||||||
seq = []
|
seq = []
|
||||||
setattr(self, conv.name, seq)
|
setattr(self, conv.name, seq)
|
||||||
try:
|
|
||||||
count_conv = self.getConverterByName(conv.repeat)
|
|
||||||
setattr(self, conv.repeat, -conv.aux)
|
|
||||||
except KeyError:
|
|
||||||
# TODO: Count is propagated.
|
|
||||||
# We don't have access upstream currently.
|
|
||||||
pass
|
|
||||||
seq.append(value)
|
seq.append(value)
|
||||||
if hasattr(self, conv.repeat):
|
|
||||||
setattr(self, conv.repeat, len(seq)+conv.aux)
|
|
||||||
else:
|
else:
|
||||||
setattr(self, conv.name, value)
|
setattr(self, conv.name, value)
|
||||||
|
|
||||||
|
@ -339,13 +339,17 @@ class Struct(BaseConverter):
|
|||||||
Format = attrs.get("Format")
|
Format = attrs.get("Format")
|
||||||
if Format is not None:
|
if Format is not None:
|
||||||
table.Format = int(Format)
|
table.Format = int(Format)
|
||||||
|
|
||||||
for element in content:
|
for element in content:
|
||||||
if isinstance(element, tuple):
|
if isinstance(element, tuple):
|
||||||
name, attrs, content = element
|
name, attrs, content = element
|
||||||
table.fromXML(name, attrs, content, font)
|
table.fromXML(name, attrs, content, font)
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
# TODO Fill in items that are not set by XML.
|
|
||||||
|
if not hasattr(table, 'postRead'):
|
||||||
|
table.populateDefaults()
|
||||||
|
|
||||||
return table
|
return table
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user