validators: Data-validation functions

Various low level data validators.

fontTools.ufoLib.validators.isDictEnough(value)[source]

Some objects will likely come in that aren’t dicts but are dict-ish enough.

fontTools.ufoLib.validators.genericTypeValidator(value, typ)[source]

Generic. (Added at version 2.)

fontTools.ufoLib.validators.genericIntListValidator(values, validValues)[source]

Generic. (Added at version 2.)

fontTools.ufoLib.validators.genericNonNegativeIntValidator(value)[source]

Generic. (Added at version 3.)

fontTools.ufoLib.validators.genericNonNegativeNumberValidator(value)[source]

Generic. (Added at version 3.)

fontTools.ufoLib.validators.genericDictValidator(value, prototype)[source]

Generic. (Added at version 3.)

fontTools.ufoLib.validators.fontInfoStyleMapStyleNameValidator(value)[source]

Version 2+.

fontTools.ufoLib.validators.fontInfoOpenTypeGaspRangeRecordsValidator(value)[source]

Version 3+.

fontTools.ufoLib.validators.fontInfoOpenTypeHeadCreatedValidator(value)[source]

Version 2+.

fontTools.ufoLib.validators.fontInfoOpenTypeNameRecordsValidator(value)[source]

Version 3+.

fontTools.ufoLib.validators.fontInfoOpenTypeOS2WeightClassValidator(value)[source]

Version 2+.

fontTools.ufoLib.validators.fontInfoOpenTypeOS2WidthClassValidator(value)[source]

Version 2+.

fontTools.ufoLib.validators.fontInfoVersion2OpenTypeOS2PanoseValidator(values)[source]

Version 2.

fontTools.ufoLib.validators.fontInfoVersion3OpenTypeOS2PanoseValidator(values)[source]

Version 3+.

fontTools.ufoLib.validators.fontInfoOpenTypeOS2FamilyClassValidator(values)[source]

Version 2+.

fontTools.ufoLib.validators.fontInfoPostscriptBluesValidator(values)[source]

Version 2+.

fontTools.ufoLib.validators.fontInfoPostscriptOtherBluesValidator(values)[source]

Version 2+.

fontTools.ufoLib.validators.fontInfoPostscriptStemsValidator(values)[source]

Version 2+.

fontTools.ufoLib.validators.fontInfoPostscriptWindowsCharacterSetValidator(value)[source]

Version 2+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataUniqueIDValidator(value)[source]

Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataVendorValidator(value)[source]

Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataCreditsValidator(value)[source]

Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataDescriptionValidator(value)[source]

Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataLicenseValidator(value)[source]

Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataTrademarkValidator(value)[source]

Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataCopyrightValidator(value)[source]

Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataLicenseeValidator(value)[source]

Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataTextValue(value)[source]

Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataExtensionsValidator(value)[source]

Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataExtensionValidator(value)[source]

Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataExtensionItemValidator(value)[source]

Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataExtensionNameValidator(value)[source]

Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataExtensionValueValidator(value)[source]

Version 3+.

fontTools.ufoLib.validators.guidelinesValidator(value, identifiers=None)[source]

Version 3+.

fontTools.ufoLib.validators.guidelineValidator(value)[source]

Version 3+.

fontTools.ufoLib.validators.anchorsValidator(value, identifiers=None)[source]

Version 3+.

fontTools.ufoLib.validators.anchorValidator(value)[source]

Version 3+.

fontTools.ufoLib.validators.identifierValidator(value)[source]

Version 3+.

>>> identifierValidator("a")
True
>>> identifierValidator("")
False
>>> identifierValidator("a" * 101)
False
fontTools.ufoLib.validators.colorValidator(value)[source]

Version 3+.

>>> colorValidator("0,0,0,0")
True
>>> colorValidator(".5,.5,.5,.5")
True
>>> colorValidator("0.5,0.5,0.5,0.5")
True
>>> colorValidator("1,1,1,1")
True
>>> colorValidator("2,0,0,0")
False
>>> colorValidator("0,2,0,0")
False
>>> colorValidator("0,0,2,0")
False
>>> colorValidator("0,0,0,2")
False
>>> colorValidator("1r,1,1,1")
False
>>> colorValidator("1,1g,1,1")
False
>>> colorValidator("1,1,1b,1")
False
>>> colorValidator("1,1,1,1a")
False
>>> colorValidator("1 1 1 1")
False
>>> colorValidator("1 1,1,1")
False
>>> colorValidator("1,1 1,1")
False
>>> colorValidator("1,1,1 1")
False
>>> colorValidator("1, 1, 1, 1")
True
fontTools.ufoLib.validators.imageValidator(value)[source]

Version 3+.

fontTools.ufoLib.validators.pngValidator(path=None, data=None, fileObj=None)[source]

Version 3+.

This checks the signature of the image data.

fontTools.ufoLib.validators.layerContentsValidator(value, ufoPathOrFileSystem)[source]

Check the validity of layercontents.plist. Version 3+.

fontTools.ufoLib.validators.groupsValidator(value)[source]

Check the validity of the groups. Version 3+ (though it’s backwards compatible with UFO 1 and UFO 2).

>>> groups = {"A" : ["A", "A"], "A2" : ["A"]}
>>> groupsValidator(groups)
(True, None)
>>> groups = {"" : ["A"]}
>>> valid, msg = groupsValidator(groups)
>>> valid
False
>>> print(msg)
A group has an empty name.
>>> groups = {"public.awesome" : ["A"]}
>>> groupsValidator(groups)
(True, None)
>>> groups = {"public.kern1." : ["A"]}
>>> valid, msg = groupsValidator(groups)
>>> valid
False
>>> print(msg)
The group data contains a kerning group with an incomplete name.
>>> groups = {"public.kern2." : ["A"]}
>>> valid, msg = groupsValidator(groups)
>>> valid
False
>>> print(msg)
The group data contains a kerning group with an incomplete name.
>>> groups = {"public.kern1.A" : ["A"], "public.kern2.A" : ["A"]}
>>> groupsValidator(groups)
(True, None)
>>> groups = {"public.kern1.A1" : ["A"], "public.kern1.A2" : ["A"]}
>>> valid, msg = groupsValidator(groups)
>>> valid
False
>>> print(msg)
The glyph "A" occurs in too many kerning groups.
fontTools.ufoLib.validators.kerningValidator(data)[source]

Check the validity of the kerning data structure. Version 3+ (though it’s backwards compatible with UFO 1 and UFO 2).

>>> kerning = {"A" : {"B" : 100}}
>>> kerningValidator(kerning)
(True, None)
>>> kerning = {"A" : ["B"]}
>>> valid, msg = kerningValidator(kerning)
>>> valid
False
>>> print(msg)
The kerning data is not in the correct format.
>>> kerning = {"A" : {"B" : "100"}}
>>> valid, msg = kerningValidator(kerning)
>>> valid
False
>>> print(msg)
The kerning data is not in the correct format.
fontTools.ufoLib.validators.fontLibValidator(value)[source]

Check the validity of the lib. Version 3+ (though it’s backwards compatible with UFO 1 and UFO 2).

>>> lib = {"foo" : "bar"}
>>> fontLibValidator(lib)
(True, None)
>>> lib = {"public.awesome" : "hello"}
>>> fontLibValidator(lib)
(True, None)
>>> lib = {"public.glyphOrder" : ["A", "C", "B"]}
>>> fontLibValidator(lib)
(True, None)
>>> lib = "hello"
>>> valid, msg = fontLibValidator(lib)
>>> valid
False
>>> print(msg)  
The lib data is not in the correct format: expected a dictionary, ...
>>> lib = {1: "hello"}
>>> valid, msg = fontLibValidator(lib)
>>> valid
False
>>> print(msg)
The lib key is not properly formatted: expected str, found int: 1
>>> lib = {"public.glyphOrder" : "hello"}
>>> valid, msg = fontLibValidator(lib)
>>> valid
False
>>> print(msg)  
public.glyphOrder is not properly formatted: expected list or tuple,...
>>> lib = {"public.glyphOrder" : ["A", 1, "B"]}
>>> valid, msg = fontLibValidator(lib)
>>> valid
False
>>> print(msg)  
public.glyphOrder is not properly formatted: expected str,...
fontTools.ufoLib.validators.glyphLibValidator(value)[source]

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}
>>> valid, msg = glyphLibValidator(lib)
>>> valid
False
>>> print(msg)
public.markColor is not properly formatted.