Utils
Generals
- modules.utils.generals.check_password(to_check: str, hashed: str) bool[source]
Check a string password with the hashed password.
- Parameters:
to_check (str) – The string password.
hashed (str) – The hashed password.
- Returns:
True if is checked, else False.
- Return type:
bool
- modules.utils.generals.creation_date() str[source]
Give the actual date.
- Returns:
Actual date in format ISO 8601.
- Return type:
str
- modules.utils.generals.encode_password(password: str) str[source]
Encode a password.
- Parameters:
password (str) – The password to encode.
- Returns:
The encoded password.
- Return type:
str
- modules.utils.generals.is_valid_email(email: str) bool[source]
Check if is a valid email.
Conditions: - An standart email direction (example@email.com)
- Parameters:
email (str) – Email to validate.
- Returns:
True if is valid, else False.
- Return type:
bool
- modules.utils.generals.is_valid_image(url: str) bool[source]
Check if is a valid image url.
Conditions: - It can be with or without ‘http://’ or ‘https://’ - Valid domain and optional route. - It can be a JPEG, PNG or GIF.
- Parameters:
url (str) – Url with image to validate.
- Returns:
True if is valid, else False.
- Return type:
bool
- modules.utils.generals.is_valid_password(password: str) bool[source]
Check if is a valid password.
Conditions: - Almost 8 characters. - Almost one uppercase. - Almost one lowecase. - Almost one number.
- Parameters:
password (str) – Password to validate.
- Returns:
True if is valid, else False.
- Return type:
bool
- modules.utils.generals.is_valid_username(username: str) bool[source]
Check if is a valid username.
Conditions: - It can have letters (upper or lowercase), numbers, dots and underscores. - It can’t end with a dot.
- Parameters:
username (str) – Username to validate.
- Returns:
True if is valid, else False.
- Return type:
bool
Exceptions
- exception modules.utils.exceptions.AlreadyInUse(error: str | None = None)[source]
Bases:
CustomExceptionCustom exception for already in use.
- default_data: str = 'Already in use'
- default_error: str = 'Username or email'
- exception modules.utils.exceptions.CustomException(data: str = 'Error', error: str | None = None, log: str | None = None, code: int = 500)[source]
Bases:
ExceptionBase class for custom exceptions with auto-logging
- exception modules.utils.exceptions.GeneralError(data: str = 'Error', error: Exception | None = None, log: str | None = None, code: int = 500)[source]
Bases:
CustomExceptionCustom exception for an exception.
- default_error: str = 'Error desconocido'
- exception modules.utils.exceptions.IncorrectCredential(user_id: ObjectId | None = None)[source]
Bases:
CustomExceptionCustom exception for incorrect credential.
- exception modules.utils.exceptions.InvalidCredential(error: str | None = None)[source]
Bases:
CustomExceptionCustom exception for invalid credentaial.
- default_data: str = 'Invalid credentials'
- default_error: str = 'Username, email or password'
- exception modules.utils.exceptions.NotFound(error: str | None = None)[source]
Bases:
CustomExceptionCustom exception for not found.
- default_data: str = 'Not Found'
- default_error: str = 'Object'
- exception modules.utils.exceptions.Unauthorized(error: str | None = None)[source]
Bases:
CustomExceptionCustom exception for unauthorized.
- default_data: str = 'Unauthorized'
- default_error: str = 'Unauthorized'
Log
Token
- class modules.utils.token.Token[source]
Bases:
objectControls the JWT in the app.
Args: __JWT_SECRET_KEY (str): The key to hash the JWT. __JWT_ALGORITHM (str): The JWT algorithm. Defaults to “HS256”. __JWT_EXPIRATION (int): The valid time of the token.