Validate public.markColor.
git-svn-id: http://svn.robofab.com/branches/ufo3k@412 b5fa9d6c-a76f-4ffd-b3cb-f825fc41095c
This commit is contained in:
parent
7f6b0a7d69
commit
62bd9d2774
@ -363,7 +363,7 @@ class UFOReader(object):
|
||||
if not self._checkForFile(path):
|
||||
return {}
|
||||
data = self._readPlist(path)
|
||||
valid, message = libValidator(data)
|
||||
valid, message = fontLibValidator(data)
|
||||
if not valid:
|
||||
raise UFOLibError(message)
|
||||
return data
|
||||
@ -828,7 +828,7 @@ class UFOWriter(object):
|
||||
Write lib.plist. This method requires a
|
||||
lib dict as an argument.
|
||||
"""
|
||||
valid, message = libValidator(libDict)
|
||||
valid, message = fontLibValidator(libDict)
|
||||
if not valid:
|
||||
raise UFOLibError(message)
|
||||
self._makeDirectory()
|
||||
|
@ -19,7 +19,7 @@ from robofab.pens.pointPen import AbstractPointPen
|
||||
from plistlib import readPlist, writePlistToString
|
||||
from filenames import userNameToFileName
|
||||
from validators import isDictEnough, genericTypeValidator, colorValidator,\
|
||||
guidelinesValidator, anchorsValidator, identifierValidator, imageValidator, libValidator
|
||||
guidelinesValidator, anchorsValidator, identifierValidator, imageValidator, glyphLibValidator
|
||||
|
||||
try:
|
||||
set
|
||||
@ -988,7 +988,7 @@ def _readLib(glyphObject, children):
|
||||
from plistFromTree import readPlistFromTree
|
||||
assert len(children) == 1
|
||||
lib = readPlistFromTree(children[0])
|
||||
valid, message = libValidator(lib)
|
||||
valid, message = glyphLibValidator(lib)
|
||||
if not valid:
|
||||
raise GlifLibError(message)
|
||||
_relaxedSetattr(glyphObject, "lib", lib)
|
||||
|
@ -891,29 +891,29 @@ def groupsValidator(value):
|
||||
# lib.plist/lib
|
||||
# -------------
|
||||
|
||||
def libValidator(value):
|
||||
def fontLibValidator(value):
|
||||
"""
|
||||
Check the validity of the lib.
|
||||
Version 3+ (though it's backwards compatible with UFO 1 and UFO 2).
|
||||
|
||||
>>> lib = {"foo" : "bar"}
|
||||
>>> libValidator(lib)
|
||||
>>> fontLibValidator(lib)
|
||||
(True, None)
|
||||
|
||||
>>> lib = {"public.awesome" : "hello"}
|
||||
>>> libValidator(lib)
|
||||
>>> fontLibValidator(lib)
|
||||
(True, None)
|
||||
|
||||
>>> lib = {"public.glyphOrder" : ["A", "C", "B"]}
|
||||
>>> libValidator(lib)
|
||||
>>> fontLibValidator(lib)
|
||||
(True, None)
|
||||
|
||||
>>> lib = {"public.glyphOrder" : "hello"}
|
||||
>>> libValidator(lib)
|
||||
>>> fontLibValidator(lib)
|
||||
(False, 'public.glyphOrder is not properly formatted.')
|
||||
|
||||
>>> lib = {"public.glyphOrder" : ["A", 1, "B"]}
|
||||
>>> libValidator(lib)
|
||||
>>> fontLibValidator(lib)
|
||||
(False, 'public.glyphOrder is not properly formatted.')
|
||||
"""
|
||||
bogusFormatMessage = "The lib data is not in the correct format."
|
||||
@ -932,6 +932,44 @@ def libValidator(value):
|
||||
return False, bogusGlyphOrderMessage
|
||||
return True, None
|
||||
|
||||
# --------
|
||||
# GLIF lib
|
||||
# --------
|
||||
|
||||
def glyphLibValidator(value):
|
||||
"""
|
||||
Check the validity of the lib.
|
||||
Version 3+ (though it's backwards compatible with UFO 1 and UFO 2).
|
||||
|
||||
>>> lib = {"foo" : "bar"}
|
||||
>>> glyphLibValidator(lib)
|
||||
(True, None)
|
||||
|
||||
>>> lib = {"public.awesome" : "hello"}
|
||||
>>> glyphLibValidator(lib)
|
||||
(True, None)
|
||||
|
||||
>>> lib = {"public.markColor" : "1,0,0,0.5"}
|
||||
>>> glyphLibValidator(lib)
|
||||
(True, None)
|
||||
|
||||
>>> lib = {"public.markColor" : 1}
|
||||
>>> glyphLibValidator(lib)
|
||||
(False, 'public.markColor is not properly formatted.')
|
||||
"""
|
||||
bogusFormatMessage = "The lib data is not in the correct format."
|
||||
if not isDictEnough(value):
|
||||
return False, bogusFormatMessage
|
||||
for key, value in value.items():
|
||||
if not isinstance(key, basestring):
|
||||
return False, bogusFormatMessage
|
||||
# public.markColor
|
||||
if key == "public.markColor":
|
||||
if not colorValidator(value):
|
||||
return False, "public.markColor is not properly formatted."
|
||||
return True, None
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import doctest
|
||||
doctest.testmod()
|
||||
|
Loading…
x
Reference in New Issue
Block a user