| 331 | return script_value |
| 332 | |
| 333 | def validate_value(self, value_wrapper: ScriptValueWrapper, *, ignore_required=False): |
| 334 | if self.constant: |
| 335 | return None |
| 336 | |
| 337 | user_value = value_wrapper.user_value |
| 338 | |
| 339 | if is_empty(user_value): |
| 340 | if self.required and not ignore_required: |
| 341 | return 'is not specified' |
| 342 | return None |
| 343 | |
| 344 | value_string = self.value_to_repr(user_value) |
| 345 | |
| 346 | if self.no_value: |
| 347 | if isinstance(user_value, bool): |
| 348 | return None |
| 349 | if isinstance(user_value, str) and user_value.lower() in ['true', 'false']: |
| 350 | return None |
| 351 | return 'should be boolean, but has value ' + value_string |
| 352 | |
| 353 | if self.type == 'text' or self.type == 'multiline_text': |
| 354 | if self.regex is not None: |
| 355 | regex_pattern = self.regex.get('pattern', None) |
| 356 | if not is_empty(regex_pattern): |
| 357 | regex_matched = re.fullmatch(regex_pattern, user_value) |
| 358 | if not regex_matched: |
| 359 | description = self.regex.get('description') or regex_pattern |
| 360 | return 'does not match regex pattern: ' + description |
| 361 | if (not is_empty(self.max_length)) and (len(user_value) > int(self.max_length)): |
| 362 | return 'is longer than allowed char length (' \ |
| 363 | + str(len(user_value)) + ' > ' + str(self.max_length) + ')' |
| 364 | return None |
| 365 | |
| 366 | if self.type == 'file_upload': |
| 367 | if not os.path.exists(user_value): |
| 368 | return 'Cannot find file ' + user_value |
| 369 | return None |
| 370 | |
| 371 | if self.type == 'int': |
| 372 | if not (isinstance(user_value, int) or ( |
| 373 | isinstance(user_value, str) and string_utils.is_integer(user_value))): |
| 374 | return 'should be integer, but has value ' + value_string |
| 375 | |
| 376 | int_value = int(user_value) |
| 377 | |
| 378 | if (not is_empty(self.max)) and (int_value > int(self.max)): |
| 379 | return 'is greater than allowed value (' \ |
| 380 | + value_string + ' > ' + str(self.max) + ')' |
| 381 | |
| 382 | if (not is_empty(self.min)) and (int_value < int(self.min)): |
| 383 | return 'is lower than allowed value (' \ |
| 384 | + value_string + ' < ' + str(self.min) + ')' |
| 385 | return None |
| 386 | |
| 387 | if self.type in ('ip', 'ip4', 'ip6'): |
| 388 | try: |
| 389 | address = ip_address(user_value.strip()) |
| 390 | if self.type == 'ip4': |