Skip to content

Commit

Permalink
model._string_constraints: add AASd-130 to check()
Browse files Browse the repository at this point in the history
Fix #118
  • Loading branch information
jkhsjdhjs committed Oct 5, 2023
1 parent 09b68a4 commit e92a90e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions basyx/aas/model/_string_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@


_T = TypeVar("_T")
AASD130_RE = re.compile("[\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\U00010000-\U0010FFFF]*")


# Functions to verify the constraints for a given value.
Expand All @@ -37,6 +38,13 @@ def check(value: str, type_name: str, min_length: int = 0, max_length: Optional[
raise ValueError(f"{type_name} has a maximum length of {max_length}! (length: {len(value)})")
if pattern is not None and not pattern.fullmatch(value):
raise ValueError(f"{type_name} must match the pattern '{pattern.pattern}'! (value: '{value}')")
# Constraint AASd-130
if not AASD130_RE.fullmatch(value):
# It's easier to implement this as a ValueError, because otherwise AASConstraintViolation would need to be
# imported from `base` and the ConstrainedLangStringSet would need to except AASConstraintViolation errors
# as well, while only re-raising ValueErrors. Thus, even if an AASConstraintViolation would be raised here,
# in case of a ConstrainedLangStringSet it would be re-raised as a ValueError anyway.
raise ValueError(f"Every string must match the pattern '{AASD130_RE.pattern}'! (value: '{value}')")


def check_content_type(value: str, type_name: str = "ContentType") -> None:
Expand Down

0 comments on commit e92a90e

Please sign in to comment.