-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy path_string_constraints.py
More file actions
64 lines (40 loc) · 2.15 KB
/
_string_constraints.py
File metadata and controls
64 lines (40 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Copyright (c) 2025 the Eclipse BaSyx Authors
#
# This program and the accompanying materials are made available under the terms of the MIT License, available in
# the LICENSE file of this project.
#
# SPDX-License-Identifier: MIT
"""
This module implements constraint functions for the listed constrained string types.
All types are constrained in length (min and max).
.. warning::
This module is intended for internal use only.
The following types aliased in the :mod:`~server.app.interfaces.base` module are constrained:
- :class:`~server.app.interfaces.base.CodeType`
- :class:`~server.app.interfaces.base.ShortIdType`
- :class:`~server.app.interfaces.base.LocatorType`
- :class:`~server.app.interfaces.base.TextType`
- :class:`~server.app.interfaces.base.SchemeType`
"""
from typing import Callable, Type
from basyx.aas.model._string_constraints import check, constrain_attr, _T
def check_code_type(value: str, type_name: str = "CodeType") -> None:
return check(value, type_name, 1, 32)
def check_short_id_type(value: str, type_name: str = "ShortIdType") -> None:
return check(value, type_name, 1, 128)
def check_locator_type(value: str, type_name: str = "LocatorType") -> None:
return check(value, type_name, 1, 2048)
def check_text_type(value: str, type_name: str = "TextType") -> None:
return check(value, type_name, 1, 2048)
def check_scheme_type(value: str, type_name: str = "SchemeType") -> None:
return check(value, type_name, 1, 128)
def constrain_code_type(pub_attr_name: str) -> Callable[[Type[_T]], Type[_T]]:
return constrain_attr(pub_attr_name, check_code_type)
def constrain_short_id_type(pub_attr_name: str) -> Callable[[Type[_T]], Type[_T]]:
return constrain_attr(pub_attr_name, check_short_id_type)
def constrain_locator_type(pub_attr_name: str) -> Callable[[Type[_T]], Type[_T]]:
return constrain_attr(pub_attr_name, check_locator_type)
def constrain_text_type(pub_attr_name: str) -> Callable[[Type[_T]], Type[_T]]:
return constrain_attr(pub_attr_name, check_text_type)
def constrain_scheme_type(pub_attr_name: str) -> Callable[[Type[_T]], Type[_T]]:
return constrain_attr(pub_attr_name, check_scheme_type)