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.
|
dict of kerning pairs as an argument.
|
||||||
"""
|
"""
|
||||||
invalidFormatMessage = "The kerning is not properly formatted."
|
invalidFormatMessage = "The kerning is not properly formatted."
|
||||||
if not isinstance(kerning, dict):
|
if not isDictEnough(kerning):
|
||||||
raise UFOLibError(invalidFormatMessage)
|
raise UFOLibError(invalidFormatMessage)
|
||||||
for pair, value in kerning.items():
|
for pair, value in kerning.items():
|
||||||
if not isinstance(pair, (list, tuple)):
|
if not isinstance(pair, (list, tuple)):
|
||||||
|
@ -17,7 +17,7 @@ from xmlTreeBuilder import buildTree, stripCharacterData
|
|||||||
from robofab.pens.pointPen import AbstractPointPen
|
from robofab.pens.pointPen import AbstractPointPen
|
||||||
from plistlib import readPlist, writePlistToString
|
from plistlib import readPlist, writePlistToString
|
||||||
from filenames import userNameToFileName
|
from filenames import userNameToFileName
|
||||||
from validators import genericTypeValidator, colorValidator, guidelinesValidator, identifierValidator, imageValidator, libValidator
|
from validators import isDictEnough, genericTypeValidator, colorValidator, guidelinesValidator, identifierValidator, imageValidator, libValidator
|
||||||
|
|
||||||
try:
|
try:
|
||||||
set
|
set
|
||||||
@ -639,8 +639,10 @@ def _writeGuidelines(glyphObject, writer, identifiers):
|
|||||||
def _writeLib(glyphObject, writer):
|
def _writeLib(glyphObject, writer):
|
||||||
from ufoLib.plistlib import PlistWriter
|
from ufoLib.plistlib import PlistWriter
|
||||||
lib = getattr(glyphObject, "lib", None)
|
lib = getattr(glyphObject, "lib", None)
|
||||||
if not isinstance(lib, dict):
|
if not isDictEnough(lib):
|
||||||
raise GlifLibError("lib attribute must be a dict.")
|
raise GlifLibError("lib attribute must be a dict.")
|
||||||
|
if not isinstance(lib, dict):
|
||||||
|
lib = dict(lib)
|
||||||
writer.begintag("lib")
|
writer.begintag("lib")
|
||||||
writer.newline()
|
writer.newline()
|
||||||
plistWriter = PlistWriter(writer.file, indentLevel=writer.indentlevel,
|
plistWriter = PlistWriter(writer.file, indentLevel=writer.indentlevel,
|
||||||
|
@ -8,6 +8,19 @@ import calendar
|
|||||||
# Generic
|
# 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):
|
def genericTypeValidator(value, typ):
|
||||||
"""
|
"""
|
||||||
Generic. (Added at version 2.)
|
Generic. (Added at version 2.)
|
||||||
@ -796,7 +809,7 @@ def groupsValidator(value):
|
|||||||
(False, 'The glyph "A" occurs in too many kerning groups.')
|
(False, 'The glyph "A" occurs in too many kerning groups.')
|
||||||
"""
|
"""
|
||||||
bogusFormatMessage = "The group data is not in the correct format."
|
bogusFormatMessage = "The group data is not in the correct format."
|
||||||
if not isinstance(value, dict):
|
if not isDictEnough(value):
|
||||||
return False, bogusFormatMessage
|
return False, bogusFormatMessage
|
||||||
firstSideMapping = {}
|
firstSideMapping = {}
|
||||||
secondSideMapping = {}
|
secondSideMapping = {}
|
||||||
@ -856,7 +869,7 @@ def libValidator(value):
|
|||||||
(False, 'public.glyphOrder is not properly formatted.')
|
(False, 'public.glyphOrder is not properly formatted.')
|
||||||
"""
|
"""
|
||||||
bogusFormatMessage = "The lib data is not in the correct format."
|
bogusFormatMessage = "The lib data is not in the correct format."
|
||||||
if not isinstance(value, dict):
|
if not isDictEnough(value):
|
||||||
return False, bogusFormatMessage
|
return False, bogusFormatMessage
|
||||||
for key, value in value.items():
|
for key, value in value.items():
|
||||||
if not isinstance(key, basestring):
|
if not isinstance(key, basestring):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user