Be a bit more lenient with dict-like objects at the top level.
git-svn-id: http://svn.robofab.com/branches/ufo3k@387 b5fa9d6c-a76f-4ffd-b3cb-f825fc41095c
This commit is contained in:
parent
91b7ba0e72
commit
2cddcd6e3e
@ -757,7 +757,7 @@ class UFOWriter(object):
|
||||
dict of kerning pairs as an argument.
|
||||
"""
|
||||
invalidFormatMessage = "The kerning is not properly formatted."
|
||||
if not isinstance(kerning, dict):
|
||||
if not isDictEnough(kerning):
|
||||
raise UFOLibError(invalidFormatMessage)
|
||||
for pair, value in kerning.items():
|
||||
if not isinstance(pair, (list, tuple)):
|
||||
|
@ -17,7 +17,7 @@ from xmlTreeBuilder import buildTree, stripCharacterData
|
||||
from robofab.pens.pointPen import AbstractPointPen
|
||||
from plistlib import readPlist, writePlistToString
|
||||
from filenames import userNameToFileName
|
||||
from validators import genericTypeValidator, colorValidator, guidelinesValidator, identifierValidator, imageValidator, libValidator
|
||||
from validators import isDictEnough, genericTypeValidator, colorValidator, guidelinesValidator, identifierValidator, imageValidator, libValidator
|
||||
|
||||
try:
|
||||
set
|
||||
@ -639,8 +639,10 @@ def _writeGuidelines(glyphObject, writer, identifiers):
|
||||
def _writeLib(glyphObject, writer):
|
||||
from ufoLib.plistlib import PlistWriter
|
||||
lib = getattr(glyphObject, "lib", None)
|
||||
if not isinstance(lib, dict):
|
||||
if not isDictEnough(lib):
|
||||
raise GlifLibError("lib attribute must be a dict.")
|
||||
if not isinstance(lib, dict):
|
||||
lib = dict(lib)
|
||||
writer.begintag("lib")
|
||||
writer.newline()
|
||||
plistWriter = PlistWriter(writer.file, indentLevel=writer.indentlevel,
|
||||
|
@ -8,6 +8,19 @@ import calendar
|
||||
# Generic
|
||||
# -------
|
||||
|
||||
def isDictEnough(value):
|
||||
"""
|
||||
Some objects will likely come in that aren't
|
||||
dicts but are dict-ish enough.
|
||||
"""
|
||||
if isinstance(value, dict):
|
||||
return True
|
||||
attrs = ("keys", "values", "items")
|
||||
for attr in attrs:
|
||||
if not hasattr(value, attr):
|
||||
return False
|
||||
return True
|
||||
|
||||
def genericTypeValidator(value, typ):
|
||||
"""
|
||||
Generic. (Added at version 2.)
|
||||
@ -796,7 +809,7 @@ def groupsValidator(value):
|
||||
(False, 'The glyph "A" occurs in too many kerning groups.')
|
||||
"""
|
||||
bogusFormatMessage = "The group data is not in the correct format."
|
||||
if not isinstance(value, dict):
|
||||
if not isDictEnough(value):
|
||||
return False, bogusFormatMessage
|
||||
firstSideMapping = {}
|
||||
secondSideMapping = {}
|
||||
@ -856,7 +869,7 @@ def libValidator(value):
|
||||
(False, 'public.glyphOrder is not properly formatted.')
|
||||
"""
|
||||
bogusFormatMessage = "The lib data is not in the correct format."
|
||||
if not isinstance(value, dict):
|
||||
if not isDictEnough(value):
|
||||
return False, bogusFormatMessage
|
||||
for key, value in value.items():
|
||||
if not isinstance(key, basestring):
|
||||
|
Loading…
x
Reference in New Issue
Block a user