UFOReader: have readInfo return a dict

but keep current behavior whereby caller can pass an Info object.
The readInfo method was the only one that takes an output argument,
all the others just return some raw data.
I like to fully construct my classes in their __init__ method.
E.g. Info(**reader.readInfo())
This commit is contained in:
Cosimo Lupo 2018-10-25 15:36:08 +01:00
parent 59d9abf5f3
commit 440c71345a
No known key found for this signature in database
GPG Key ID: 59D54DB0C9976482

View File

@ -466,7 +466,7 @@ class UFOReader(_UFOBaseIO):
raise UFOLibError("fontinfo.plist is not properly formatted.") raise UFOLibError("fontinfo.plist is not properly formatted.")
return data return data
def readInfo(self, info, validate=None): def readInfo(self, info=None, validate=None):
""" """
Read fontinfo.plist. It requires an object that allows Read fontinfo.plist. It requires an object that allows
setting attributes with names that follow the fontinfo.plist setting attributes with names that follow the fontinfo.plist
@ -509,12 +509,17 @@ class UFOReader(_UFOBaseIO):
# validate data # validate data
if validate: if validate:
infoDataToSet = validateInfoVersion3Data(infoDataToSet) infoDataToSet = validateInfoVersion3Data(infoDataToSet)
# populate the object if info is not None:
for attr, value in list(infoDataToSet.items()): # populate the object
try: for attr, value in infoDataToSet.items():
setattr(info, attr, value) try:
except AttributeError: setattr(info, attr, value)
raise UFOLibError("The supplied info object does not support setting a necessary attribute (%s)." % attr) except AttributeError:
raise UFOLibError(
"The supplied info object does not support setting a "
"necessary attribute (%s)." % attr
)
return infoDataToSet
# kerning.plist # kerning.plist