How to use the validators.identifierValidator function in validators

To help you get started, we’ve selected a few validators examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github unified-font-object / ufoLib / Lib / ufoLib / glifLib.py View on Github external
def _buildOutlineContourFormat2(pen, (attrs, children), identifiers):
	if set(attrs.keys()) - contourAttributesFormat2:
		raise GlifLibError("Unknown attributes in contour element.")
	identifier = attrs.get("identifier")
	if identifier is not None:
		if identifier in identifiers:
			raise GlifLibError("The identifier %s is used more than once." % identifier)
		if not identifierValidator(identifier):
			raise GlifLibError("The contour identifier %s is not valid." % identifier)
		identifiers.add(identifier)
	try:
		pen.beginPath(identifier=identifier)
	except TypeError:
		pen.beginPath()
		raise warn("The beginPath method needs an identifier kwarg. The contour's identifier value has been discarded.", DeprecationWarning)
	if children:
		children = _validateAndMassagePointStructures(children, pointAttributesFormat2)
		_buildOutlinePointsFormat2(pen, children, identifiers)
	pen.endPath()
github unified-font-object / ufoLib / Lib / ufoLib / glifLib.py View on Github external
def beginPath(self, identifier=None, **kwargs):
		attrs = []
		if identifier is not None and self.formatVersion >= 2:
			if identifier in self.identifiers:
				raise GlifLibError("identifier used more than once: %s" % identifier)
			if not identifierValidator(identifier):
				raise GlifLibError("identifier not formatted properly: %s" % identifier)
			attrs.append(("identifier", identifier))
			self.identifiers.add(identifier)
		self.writer.begintag("contour", attrs)
		self.writer.newline()
		self.prevOffCurveCount = 0
github unified-font-object / ufoLib / Lib / ufoLib / glifLib.py View on Github external
def _buildOutlinePointsFormat2(pen, children, identifiers):
	for index, (subElement, attrs, dummy) in enumerate(children):
		x = attrs["x"]
		y = attrs["y"]
		segmentType = attrs["segmentType"]
		smooth = attrs["smooth"]
		name = attrs["name"]
		identifier = attrs.get("identifier")
		if identifier is not None:
			if identifier in identifiers:
				raise GlifLibError("The identifier %s is used more than once." % identifier)
			if not identifierValidator(identifier):
				raise GlifLibError("The identifier %s is not valid." % identifier)
			identifiers.add(identifier)
		try:
			pen.addPoint((x, y), segmentType=segmentType, smooth=smooth, name=name, identifier=identifier)
		except TypeError:
			pen.addPoint((x, y), segmentType=segmentType, smooth=smooth, name=name)
			raise warn("The addPoint method needs an identifier kwarg. The point's identifier value has been discarded.", DeprecationWarning)
github unified-font-object / ufoLib / Lib / ufoLib / glifLib.py View on Github external
else:
			self.prevOffCurveCount = 0
		self.prevPointTypes.append(segmentType)
		# smooth
		if smooth:
			if segmentType == "offcurve":
				raise GlifLibError("can't set smooth in an offcurve point.")
			attrs.append(("smooth", "yes"))
		# name
		if name is not None:
			attrs.append(("name", name))
		# identifier
		if identifier is not None and self.formatVersion >= 2:
			if identifier in self.identifiers:
				raise GlifLibError("identifier used more than once: %s" % identifier)
			if not identifierValidator(identifier):
				raise GlifLibError("identifier not formatted properly: %s" % identifier)
			attrs.append(("identifier", identifier))
			self.identifiers.add(identifier)
		self.writer.simpletag("point", attrs)
		self.writer.newline()
github unified-font-object / ufoLib / Lib / ufoLib / glifLib.py View on Github external
baseGlyphName = attrs.get("base")
	if baseGlyphName is None:
		raise GlifLibError("The base attribute is not defined in the component.")
	transformation = []
	for attr, default in _transformationInfo:
		value = attrs.get(attr)
		if value is None:
			value = default
		else:
			value = _number(value)
		transformation.append(value)
	identifier = attrs.get("identifier")
	if identifier is not None:
		if identifier in identifiers:
			raise GlifLibError("The identifier %s is used more than once." % identifier)
		if not identifierValidator(identifier):
			raise GlifLibError("The identifier %s is not valid." % identifier)
		identifiers.add(identifier)
	try:
		pen.addComponent(baseGlyphName, tuple(transformation), identifier=identifier)
	except TypeError:
		pen.addComponent(baseGlyphName, tuple(transformation))
		raise warn("The addComponent method needs an identifier kwarg. The component's identifier value has been discarded.", DeprecationWarning)
github unified-font-object / ufoLib / Lib / ufoLib / glifLib.py View on Github external
def addComponent(self, glyphName, transformation, identifier=None, **kwargs):
		attrs = [("base", glyphName)]
		for (attr, default), value in zip(_transformationInfo, transformation):
			if not isinstance(value, (int, float)):
				raise GlifLibError("transformation values must be int or float")
			if value != default:
				attrs.append((attr, str(value)))
		if identifier is not None and self.formatVersion >= 2:
			if identifier in self.identifiers:
				raise GlifLibError("identifier used more than once: %s" % identifier)
			if not identifierValidator(identifier):
				raise GlifLibError("identifier not formatted properly: %s" % identifier)
			attrs.append(("identifier", identifier))
			self.identifiers.add(identifier)
		self.writer.simpletag("component", attrs)
		self.writer.newline()