# validators: Data-validation functions

Various low level data validators.

fontTools.ufoLib.validators.isDictEnough(value)

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

fontTools.ufoLib.validators.genericTypeValidator(value, typ)

  Generic. (Added at version 2.)

fontTools.ufoLib.validators.genericIntListValidator(values, validValues)

  Generic. (Added at version 2.)

fontTools.ufoLib.validators.genericNonNegativeIntValidator(value)

  Generic. (Added at version 3.)

fontTools.ufoLib.validators.genericNonNegativeNumberValidator(value)

  Generic. (Added at version 3.)

fontTools.ufoLib.validators.genericDictValidator(value, prototype)

  Generic. (Added at version 3.)

fontTools.ufoLib.validators.fontInfoStyleMapStyleNameValidator(value)

  Version 2+.

fontTools.ufoLib.validators.fontInfoOpenTypeGaspRangeRecordsValidator(value)

  Version 3+.

fontTools.ufoLib.validators.fontInfoOpenTypeHeadCreatedValidator(value)

  Version 2+.

fontTools.ufoLib.validators.fontInfoOpenTypeNameRecordsValidator(value)

  Version 3+.

fontTools.ufoLib.validators.fontInfoOpenTypeOS2WeightClassValidator(value)

  Version 2+.

fontTools.ufoLib.validators.fontInfoOpenTypeOS2WidthClassValidator(value)

  Version 2+.

fontTools.ufoLib.validators.fontInfoVersion2OpenTypeOS2PanoseValidator(values)

  Version 2.

fontTools.ufoLib.validators.fontInfoVersion3OpenTypeOS2PanoseValidator(values)

  Version 3+.

fontTools.ufoLib.validators.fontInfoOpenTypeOS2FamilyClassValidator(values)

  Version 2+.

fontTools.ufoLib.validators.fontInfoPostscriptBluesValidator(values)

  Version 2+.

fontTools.ufoLib.validators.fontInfoPostscriptOtherBluesValidator(values)

  Version 2+.

fontTools.ufoLib.validators.fontInfoPostscriptStemsValidator(values)

  Version 2+.

fontTools.ufoLib.validators.fontInfoPostscriptWindowsCharacterSetValidator(value)

  Version 2+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataUniqueIDValidator(value)

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataVendorValidator(value)

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataCreditsValidator(value)

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataDescriptionValidator(value)

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataLicenseValidator(value)

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataTrademarkValidator(value)

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataCopyrightValidator(value)

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataLicenseeValidator(value)

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataTextValue(value)

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataExtensionsValidator(value)

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataExtensionValidator(value)

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataExtensionItemValidator(value)

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataExtensionNameValidator(value)

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataExtensionValueValidator(value)

  Version 3+.

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

  Version 3+.

fontTools.ufoLib.validators.guidelineValidator(value)

  Version 3+.

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

  Version 3+.

fontTools.ufoLib.validators.anchorValidator(value)

  Version 3+.

fontTools.ufoLib.validators.identifierValidator(value)

  Version 3+.

      >>> identifierValidator("a")
      True
      >>> identifierValidator("")
      False
      >>> identifierValidator("a" * 101)
      False

fontTools.ufoLib.validators.colorValidator(value)

  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)

  Version 3+.

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

  Version 3+.

  This checks the signature of the image data.

fontTools.ufoLib.validators.layerContentsValidator(value, ufoPathOrFileSystem)

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

fontTools.ufoLib.validators.groupsValidator(value)

  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)

  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)

  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)

  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.