aboutsummaryrefslogtreecommitdiff
path: root/sgdfi/_util.py
diff options
context:
space:
mode:
Diffstat (limited to 'sgdfi/_util.py')
-rwxr-xr-xsgdfi/_util.py52
1 files changed, 51 insertions, 1 deletions
diff --git a/sgdfi/_util.py b/sgdfi/_util.py
index 088b1da..db097d8 100755
--- a/sgdfi/_util.py
+++ b/sgdfi/_util.py
@@ -18,7 +18,9 @@ from pytz import timezone as _timezone
__all__ = ["IID", "Enum",
"Property", "IIDProperty", "DateProperty", "BoolProperty", "EnumProperty",
- "ArrayProperty", "TextProperty", "ObjectProperty", "ValueProperty", "Base"]
+ "ArrayProperty", "TextProperty", "ObjectProperty", "ValueProperty", "Base",
+ "InvalidCredentialsError", "InvalidUserError", "InvalidPasswordError",
+ "UnauthorizedAccountError"]
# ---
# Attribute helpers.
@@ -477,4 +479,52 @@ class Base:
super().__delattr__(name, value)
attr.delete()
+# ---
+# Exceptions.
+# ---
+
+class InvalidCredentialsError(Exception):
+ """ Exception for when the credentials are invalid. """
+
+ def __init__(self, msg = None, user = None, pw = None):
+ if msg is None:
+ msg = f"Invalid credentials ({repr(user)}: {repr(pw)})."
+
+ super().__init__(msg)
+
+ self.__user = user
+ self.__pw = pw
+
+ @property
+ def user(self):
+ """ Username for which the credentials are invalid. """
+
+ return self.__user
+
+ @property
+ def pw(self):
+ """ Password which is involved in the error. """
+
+ return self.__pw
+
+class InvalidUserError(InvalidCredentialsError):
+ """ Exception for when the user identifier is invalid. """
+
+ def __init__(self, user):
+ super().__init__(f"Invalid identifier ({repr(user)}).", user = user)
+
+class InvalidPasswordError(InvalidCredentialsError):
+ """ Exception for when the password is invalid. """
+
+ def __init__(self, user, pw):
+ super().__init__(f"Invalid password for {repr(user)} ({repr(pw)}).",
+ user = user, pw = pw)
+
+class UnauthorizedAccountError(InvalidCredentialsError):
+ """ Exception for when the user is not allowed to log in. """
+
+ def __init__(self, user):
+ super().__init__(f"User with identifier {repr(user)} is not allowed " \
+ "to log in.", user = user)
+
# End of file.