| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import re
- class validators_base:
- @staticmethod
- def _validate_generic_name(content: str, name: str = "it") -> str:
- copy = content.replace("-", "").replace("_", "")
- if not copy.isalpha():
- raise ValueError(
- name.title() + " can contain only _ and alphanumeric chars."
- )
- return content
- @staticmethod
- def _validate_white_chars(content: str, name: str = "it") -> str:
- contain = str(" ") in content
- contain = contain or str("\t") in content
- contain = contain or str("\r") in content
- contain = contain or str("\n") in content
- if contain:
- raise ValueError(
- name.title() + " can not contain whitespace chars."
- )
-
- return content
- @staticmethod
- def _validate_lenght(
- content: str,
- name: str,
- minimum: int,
- maximum: int | None
- ) -> str:
- if len(content) < minimum:
- raise ValueError(name.title() + " is too short.")
- if maximum is not None and len(content) > maximum:
- raise ValueError(name.title() + " is too long.")
- return content
|