# validators: Data-validation functions

Various low level data validators.

fontTools.ufoLib.validators.isDictEnough(value: Any) → bool

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

fontTools.ufoLib.validators.genericTypeValidator(value: Any, typ: Type[Any]) → bool

  Generic. (Added at version 2.)

fontTools.ufoLib.validators.genericIntListValidator(values: Any, validValues: Sequence[int]) → bool

  Generic. (Added at version 2.)

fontTools.ufoLib.validators.genericNonNegativeIntValidator(value: Any) → bool

  Generic. (Added at version 3.)

fontTools.ufoLib.validators.genericNonNegativeNumberValidator(value: Any) → bool

  Generic. (Added at version 3.)

fontTools.ufoLib.validators.genericDictValidator(value: Any, prototype: dict[str, tuple[type | tuple[Type[Any], ...], bool]]) → bool

  Generic. (Added at version 3.)

fontTools.ufoLib.validators.fontInfoStyleMapStyleNameValidator(value: Any) → bool

  Version 2+.

fontTools.ufoLib.validators.fontInfoOpenTypeGaspRangeRecordsValidator(value: Any) → bool

  Version 3+.

fontTools.ufoLib.validators.fontInfoOpenTypeHeadCreatedValidator(value: Any) → bool

  Version 2+.

fontTools.ufoLib.validators.fontInfoOpenTypeNameRecordsValidator(value: Any) → bool

  Version 3+.

fontTools.ufoLib.validators.fontInfoOpenTypeOS2WeightClassValidator(value: Any) → bool

  Version 2+.

fontTools.ufoLib.validators.fontInfoOpenTypeOS2WidthClassValidator(value: Any) → bool

  Version 2+.

fontTools.ufoLib.validators.fontInfoVersion2OpenTypeOS2PanoseValidator(values: Any) → bool

  Version 2.

fontTools.ufoLib.validators.fontInfoVersion3OpenTypeOS2PanoseValidator(values: Any) → bool

  Version 3+.

fontTools.ufoLib.validators.fontInfoOpenTypeOS2FamilyClassValidator(values: Any) → bool

  Version 2+.

fontTools.ufoLib.validators.fontInfoPostscriptBluesValidator(values: Any) → bool

  Version 2+.

fontTools.ufoLib.validators.fontInfoPostscriptOtherBluesValidator(values: Any) → bool

  Version 2+.

fontTools.ufoLib.validators.fontInfoPostscriptStemsValidator(values: Any) → bool

  Version 2+.

fontTools.ufoLib.validators.fontInfoPostscriptWindowsCharacterSetValidator(value: Any) → bool

  Version 2+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataUniqueIDValidator(value: Any) → bool

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataVendorValidator(value: Any) → bool

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataCreditsValidator(value: Any) → bool

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataDescriptionValidator(value: Any) → bool

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataLicenseValidator(value: Any) → bool

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataTrademarkValidator(value: Any) → bool

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataCopyrightValidator(value: Any) → bool

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataLicenseeValidator(value: Any) → bool

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataTextValue(value: Any) → bool

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataExtensionsValidator(value: Any) → bool

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataExtensionValidator(value: Any) → bool

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataExtensionItemValidator(value: Any) → bool

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataExtensionNameValidator(value: Any) → bool

  Version 3+.

fontTools.ufoLib.validators.fontInfoWOFFMetadataExtensionValueValidator(value: Any) → bool

  Version 3+.

fontTools.ufoLib.validators.guidelinesValidator(value: Any, identifiers: set[str] | None = None) → bool

  Version 3+.

fontTools.ufoLib.validators.guidelineValidator(value: Any) → bool

  Version 3+.

fontTools.ufoLib.validators.anchorsValidator(value: Any, identifiers: set[str] | None = None) → bool

  Version 3+.

fontTools.ufoLib.validators.anchorValidator(value: Any) → bool

  Version 3+.

fontTools.ufoLib.validators.identifierValidator(value: Any) → bool

  Version 3+.

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

fontTools.ufoLib.validators.colorValidator(value: Any) → bool

  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: str | None = None, data: bytes | None = None, fileObj: Any | None = None) → tuple[bool, Any]

  Version 3+.

  This checks the signature of the image data.

fontTools.ufoLib.validators.layerContentsValidator(value: Any, ufoPathOrFileSystem: str | FS) → tuple[bool, str | None]

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

fontTools.ufoLib.validators.groupsValidator(value: Any) → tuple[bool, str | None]

  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: Any) → tuple[bool, str | None]

  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: Any) → tuple[bool, str | None]

  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: Any) → tuple[bool, str | None]

  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.