|
14 | 14 | SIMPLE_VERSION_RE, |
15 | 15 | UUID_RE, |
16 | 16 | ) |
| 17 | +from .utils.common_validators import trim_string_before |
17 | 18 |
|
18 | 19 | assert issubclass(LogLevel, Enum) # nosec |
19 | 20 | assert issubclass(BootModeEnum, Enum) # nosec |
@@ -150,32 +151,36 @@ def concatenate(*args: "IDStr", link_char: str = " ") -> "IDStr": |
150 | 151 | return IDStr(result) |
151 | 152 |
|
152 | 153 |
|
153 | | -class ShortTruncatedStr(ConstrainedStr): |
154 | | - """A truncated string used to input e.g. titles or display names |
155 | | -
|
156 | | - - Strips whitespaces and truncate strings that exceed the specified characters limit (curtail_length). |
157 | | - - Ensures that the **input** data length to the API is controlled and prevents exceeding large inputs silently, |
158 | | - i.e. without raising errors. |
159 | | -
|
160 | | - SEE https://github.com/ITISFoundation/osparc-simcore/pull/5989#discussion_r1650506583 |
161 | | -
|
162 | | - DEPRECATED: Use instead Annotated[str, StringConstraints(strip_whitespace=True), trim_string_before(max_length=600)] |
163 | | - """ |
164 | | - |
165 | | - strip_whitespace = True |
166 | | - curtail_length = 600 |
167 | | - |
168 | | - |
169 | | -class LongTruncatedStr(ConstrainedStr): |
170 | | - """Use to input e.g. descriptions or summaries |
171 | | -
|
172 | | - Analogous to ShortTruncatedStr |
173 | | -
|
174 | | - DEPRECATED: Use instead Annotated[str, StringConstraints(strip_whitespace=True), trim_string_before(max_length=65536)] |
175 | | - """ |
| 154 | +_SHORT_TRUNCATED_STR_MAX_LENGTH: Final[int] = 600 |
| 155 | +ShortTruncatedStr: TypeAlias = Annotated[ |
| 156 | + str, |
| 157 | + StringConstraints(strip_whitespace=True), |
| 158 | + trim_string_before(max_length=_SHORT_TRUNCATED_STR_MAX_LENGTH), |
| 159 | + annotated_types.doc( |
| 160 | + """ |
| 161 | + A truncated string used to input e.g. titles or display names. |
| 162 | + Strips whitespaces and truncate strings that exceed the specified characters limit (curtail_length). |
| 163 | + Ensures that the **input** data length to the API is controlled and prevents exceeding large inputs silently, |
| 164 | + i.e. without raising errors. |
| 165 | + """ |
| 166 | + # SEE https://github.com/ITISFoundation/osparc-simcore/pull/5989#discussion_r1650506583 |
| 167 | + ), |
| 168 | +] |
176 | 169 |
|
177 | | - strip_whitespace = True |
178 | | - curtail_length = 65536 # same as github descripton |
| 170 | +_LONG_TRUNCATED_STR_MAX_LENGTH: Final[int] = 65536 # same as github description |
| 171 | +LongTruncatedStr: TypeAlias = Annotated[ |
| 172 | + str, |
| 173 | + StringConstraints(strip_whitespace=True), |
| 174 | + trim_string_before(max_length=_LONG_TRUNCATED_STR_MAX_LENGTH), |
| 175 | + annotated_types.doc( |
| 176 | + """ |
| 177 | + A truncated string used to input e.g. descriptions or summaries. |
| 178 | + Strips whitespaces and truncate strings that exceed the specified characters limit (curtail_length). |
| 179 | + Ensures that the **input** data length to the API is controlled and prevents exceeding large inputs silently, |
| 180 | + i.e. without raising errors. |
| 181 | + """ |
| 182 | + ), |
| 183 | +] |
179 | 184 |
|
180 | 185 |
|
181 | 186 | # auto-incremented primary-key IDs |
|
0 commit comments