2.7. _string_constraints - Constraint Functions for Constrained String Types

This module implements constraint functions for the listed constrained string types. All types are constrained in length (min and max), RevisionType and VersionType are additionally constrained by a regular expression.

Warning

This module is intended for internal use only.

The following types aliased in the base module are constrained:

check(value: str, type_name: str, min_length: int = 0, max_length: int | None = None, pattern: Pattern | None = None) None
check_content_type(value: str, type_name: str = 'ContentType') None
check_identifier(value: str, type_name: str = 'Identifier') None
check_label_type(value: str, type_name: str = 'LabelType') None
check_message_topic_type(value: str, type_name: str = 'MessageTopicType') None
check_name_type(value: str, type_name: str = 'NameType') None
check_path_type(value: str, type_name: str = 'PathType') None
check_qualifier_type(value: str, type_name: str = 'QualifierType') None
check_revision_type(value: str, type_name: str = 'RevisionType') None
check_short_name_type(value: str, type_name: str = 'ShortNameType') None
check_value_type_iec61360(value: str, type_name: str = 'ValueTypeIEC61360') None
check_version_type(value: str, type_name: str = 'VersionType') None
constrain_attr(pub_attr_name: str, constraint_check_fn: Callable[[str], None]) Callable[[Type[_T]], Type[_T]]
constrain_content_type(pub_attr_name: str) Callable[[Type[_T]], Type[_T]]
constrain_identifier(pub_attr_name: str) Callable[[Type[_T]], Type[_T]]
constrain_label_type(pub_attr_name: str) Callable[[Type[_T]], Type[_T]]
constrain_message_topic_type(pub_attr_name: str) Callable[[Type[_T]], Type[_T]]
constrain_name_type(pub_attr_name: str) Callable[[Type[_T]], Type[_T]]
constrain_path_type(pub_attr_name: str) Callable[[Type[_T]], Type[_T]]
constrain_qualifier_type(pub_attr_name: str) Callable[[Type[_T]], Type[_T]]
constrain_revision_type(pub_attr_name: str) Callable[[Type[_T]], Type[_T]]
constrain_short_name_type(pub_attr_name: str) Callable[[Type[_T]], Type[_T]]
constrain_value_type_iec61360(pub_attr_name: str) Callable[[Type[_T]], Type[_T]]
constrain_version_type(pub_attr_name: str) Callable[[Type[_T]], Type[_T]]
create_check_function(min_length: int = 0, max_length: int | None = None, pattern: Pattern | None = None) Callable[[str, str], None]

Returns a new check_type function with mandatory type_name for the given min_length, max_length and pattern constraints.

This is the type-independent alternative to check_content_type(), check_identifier(), etc. It is used for the definition of the ConstrainedLangStringSets, as a “Basic” constrained string type only exists for MultiLanguageNameType, where all values are ShortNames. All other :class:`ConstrainedLangStringSets use custom constraints.

class _T

alias of TypeVar(‘_T’)