From 173c07a0bfa8244008f3d3b7ccb0de9c47956116 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Fri, 16 Feb 2018 22:13:54 -0800 Subject: [PATCH] Add some more exception hierarchy. Exists / InvalidUN/PW. --- etiquette/exceptions.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/etiquette/exceptions.py b/etiquette/exceptions.py index 9f71af6..119499f 100644 --- a/etiquette/exceptions.py +++ b/etiquette/exceptions.py @@ -72,28 +72,31 @@ class NoSuchUser(NoSuch): # EXISTS -class AlbumExists(EtiquetteException): +class Exists(EtiquetteException): + pass + +class AlbumExists(Exists): error_message = 'Album "{}" already exists.' def __init__(self, album): self.album = album EtiquetteException.__init__(self, album) -class GroupExists(EtiquetteException): +class GroupExists(Exists): error_message = '{member} already in group {group}' -class PhotoExists(EtiquetteException): +class PhotoExists(Exists): error_message = 'Photo "{}" already exists.' def __init__(self, photo): self.photo = photo EtiquetteException.__init__(self, photo) -class TagExists(EtiquetteException): +class TagExists(Exists): error_message = 'Tag "{}" already exists.' def __init__(self, tag): self.tag = tag EtiquetteException.__init__(self, tag) -class UserExists(EtiquetteException): +class UserExists(Exists): error_message = 'User "{}" already exists.' def __init__(self, user): self.user = user @@ -121,16 +124,22 @@ class TagTooShort(EtiquetteException): class AlreadySignedIn(EtiquetteException): error_message = 'You\'re already signed in.' -class InvalidUsernameChars(EtiquetteException): +class InvalidPassword(EtiquetteException): + error_message = 'Password is invalid.' + +class InvalidUsername(EtiquetteException): + error_message = 'Username "{username}" is invalid.' + +class InvalidUsernameChars(InvalidUsername): error_message = 'Username "{username}" contains invalid characters: {badchars}.' -class PasswordTooShort(EtiquetteException): +class PasswordTooShort(InvalidPassword): error_message = 'Password is shorter than the minimum of {min_length}.' -class UsernameTooLong(EtiquetteException): +class UsernameTooLong(InvalidUsername): error_message = 'Username "{username}" is longer than maximum of {max_length}.' -class UsernameTooShort(EtiquetteException): +class UsernameTooShort(InvalidUsername): error_message = 'Username "{username}" is shorter than minimum of {min_length}.' class WrongLogin(EtiquetteException):