2017-03-05 05:56:23 +00:00
|
|
|
import re
|
|
|
|
|
|
|
|
def pascal_to_loudsnakes(text):
|
2017-04-21 01:31:48 +00:00
|
|
|
'''
|
|
|
|
NoSuchPhoto -> NO_SUCH_PHOTO
|
|
|
|
'''
|
2017-03-05 05:56:23 +00:00
|
|
|
match = re.findall('[A-Z][a-z]*', text)
|
|
|
|
text = '_'.join(match)
|
|
|
|
text = text.upper()
|
|
|
|
return text
|
|
|
|
|
2017-03-05 06:27:24 +00:00
|
|
|
|
2017-03-17 09:30:02 +00:00
|
|
|
class ErrorTypeAdder(type):
|
|
|
|
'''
|
|
|
|
Thanks Unutbu
|
|
|
|
http://stackoverflow.com/a/18126678
|
|
|
|
'''
|
|
|
|
def __init__(cls, name, bases, clsdict):
|
|
|
|
type.__init__(cls, name, bases, clsdict)
|
|
|
|
cls.error_type = pascal_to_loudsnakes(name)
|
2017-03-05 05:56:23 +00:00
|
|
|
|
2017-03-17 09:30:02 +00:00
|
|
|
class EtiquetteException(Exception, metaclass=ErrorTypeAdder):
|
|
|
|
error_message = ''
|
2017-03-05 05:56:23 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2017-03-05 06:27:24 +00:00
|
|
|
self.given_args = args
|
|
|
|
self.given_kwargs = kwargs
|
2017-03-05 05:56:23 +00:00
|
|
|
self.error_message = self.error_message.format(*args, **kwargs)
|
2017-03-17 09:30:02 +00:00
|
|
|
|
2017-02-26 09:04:07 +00:00
|
|
|
|
2016-12-16 23:45:46 +00:00
|
|
|
# NO SUCH
|
2017-03-17 09:30:02 +00:00
|
|
|
class NoSuch(EtiquetteException):
|
2016-12-13 03:49:36 +00:00
|
|
|
pass
|
|
|
|
|
2017-03-05 05:56:23 +00:00
|
|
|
class NoSuchAlbum(NoSuch):
|
|
|
|
error_message = 'Album "{}" does not exist.'
|
2017-02-05 02:30:02 +00:00
|
|
|
|
2017-03-05 05:56:23 +00:00
|
|
|
class NoSuchBookmark(NoSuch):
|
|
|
|
error_message = 'Bookmark "{}" does not exist.'
|
2016-12-13 03:49:36 +00:00
|
|
|
|
2017-03-05 05:56:23 +00:00
|
|
|
class NoSuchGroup(NoSuch):
|
|
|
|
error_message = 'Group "{}" does not exist.'
|
2016-12-13 03:49:36 +00:00
|
|
|
|
2017-03-05 05:56:23 +00:00
|
|
|
class NoSuchPhoto(NoSuch):
|
|
|
|
error_message = 'Photo "{}" does not exist.'
|
2016-12-13 03:49:36 +00:00
|
|
|
|
2017-03-05 05:56:23 +00:00
|
|
|
class NoSuchSynonym(NoSuch):
|
|
|
|
error_message = 'Synonym "{}" does not exist.'
|
2016-12-13 03:49:36 +00:00
|
|
|
|
2017-03-05 05:56:23 +00:00
|
|
|
class NoSuchTag(NoSuch):
|
|
|
|
error_message = 'Tag "{}" does not exist.'
|
|
|
|
|
|
|
|
class NoSuchUser(NoSuch):
|
|
|
|
error_message = 'User "{}" does not exist.'
|
2016-12-16 23:45:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
# EXISTS
|
2017-03-17 09:30:02 +00:00
|
|
|
class AlbumExists(EtiquetteException):
|
2017-03-17 06:57:31 +00:00
|
|
|
error_message = 'Album "{}" already exists.'
|
|
|
|
def __init__(self, album):
|
|
|
|
self.album = album
|
2017-03-17 09:30:02 +00:00
|
|
|
EtiquetteException.__init__(self, album.id)
|
2017-03-17 06:57:31 +00:00
|
|
|
|
2017-03-17 09:30:02 +00:00
|
|
|
class GroupExists(EtiquetteException):
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = '{member} already in group {group}'
|
2016-12-13 03:49:36 +00:00
|
|
|
|
2017-03-17 09:30:02 +00:00
|
|
|
class PhotoExists(EtiquetteException):
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = 'Photo "{}" already exists.'
|
|
|
|
def __init__(self, photo):
|
|
|
|
self.photo = photo
|
2017-03-17 09:30:02 +00:00
|
|
|
EtiquetteException.__init__(self, photo.id)
|
2016-12-13 03:49:36 +00:00
|
|
|
|
2017-03-17 09:30:02 +00:00
|
|
|
class TagExists(EtiquetteException):
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = 'Tag "{}" already exists.'
|
|
|
|
def __init__(self, tag):
|
|
|
|
self.tag = tag
|
2017-03-17 09:30:02 +00:00
|
|
|
EtiquetteException.__init__(self, tag.name)
|
2016-12-13 03:49:36 +00:00
|
|
|
|
2017-03-17 09:30:02 +00:00
|
|
|
class UserExists(EtiquetteException):
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = 'User "{}" already exists.'
|
|
|
|
def __init__(self, user):
|
|
|
|
self.user = user
|
2017-03-17 09:30:02 +00:00
|
|
|
EtiquetteException.__init__(self, user.username)
|
2016-12-13 03:49:36 +00:00
|
|
|
|
|
|
|
|
2016-12-16 23:45:46 +00:00
|
|
|
# TAG ERRORS
|
2017-02-26 09:04:07 +00:00
|
|
|
class CantSynonymSelf(EtiquetteException):
|
|
|
|
error_message = 'Cannot apply synonym to self.'
|
2016-12-21 05:33:14 +00:00
|
|
|
|
2017-03-05 06:27:24 +00:00
|
|
|
class EasyBakeError(EtiquetteException):
|
2017-03-17 09:30:02 +00:00
|
|
|
error_message = '{}'
|
2017-03-05 06:27:24 +00:00
|
|
|
|
2017-03-17 09:30:02 +00:00
|
|
|
class RecursiveGrouping(EtiquetteException):
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = '{group} is an ancestor of {member}.'
|
2016-12-21 02:31:09 +00:00
|
|
|
|
2017-03-17 09:30:02 +00:00
|
|
|
class TagTooLong(EtiquetteException):
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = 'Tag "{}" is too long.'
|
2016-12-13 03:49:36 +00:00
|
|
|
|
2017-03-17 09:30:02 +00:00
|
|
|
class TagTooShort(EtiquetteException):
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = 'Tag "{}" has too few valid characters.'
|
2016-12-13 03:49:36 +00:00
|
|
|
|
2016-12-16 23:45:46 +00:00
|
|
|
|
|
|
|
# USER ERRORS
|
2017-03-17 08:08:51 +00:00
|
|
|
class AlreadySignedIn(EtiquetteException):
|
|
|
|
error_message = 'You\'re already signed in.'
|
|
|
|
|
2017-03-17 09:30:02 +00:00
|
|
|
class InvalidUsernameChars(EtiquetteException):
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = 'Username "{username}" contains invalid characters: {badchars}.'
|
2016-12-16 23:45:46 +00:00
|
|
|
|
2017-03-17 09:30:02 +00:00
|
|
|
class PasswordTooShort(EtiquetteException):
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = 'Password is shorter than the minimum of {min_length}.'
|
2016-12-16 23:45:46 +00:00
|
|
|
|
2017-03-17 09:30:02 +00:00
|
|
|
class UsernameTooLong(EtiquetteException):
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = 'Username "{username}" is longer than maximum of {max_length}.'
|
2016-12-16 23:45:46 +00:00
|
|
|
|
2017-03-17 09:30:02 +00:00
|
|
|
class UsernameTooShort(EtiquetteException):
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = 'Username "{username}" is shorter than minimum of {min_length}.'
|
2016-12-16 23:45:46 +00:00
|
|
|
|
2017-02-26 09:04:07 +00:00
|
|
|
class WrongLogin(EtiquetteException):
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = 'Wrong username-password combination.'
|
2016-12-16 23:45:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
# GENERAL ERRORS
|
2017-03-17 02:54:12 +00:00
|
|
|
class FeatureDisabled(EtiquetteException):
|
|
|
|
'''
|
|
|
|
For when features of the system have been disabled by the configuration.
|
|
|
|
'''
|
|
|
|
error_message = 'This feature has been disabled.'
|
|
|
|
|
2017-02-26 09:04:07 +00:00
|
|
|
class NotExclusive(EtiquetteException):
|
2016-12-13 03:49:36 +00:00
|
|
|
'''
|
|
|
|
For when two or more mutually exclusive actions have been requested.
|
|
|
|
'''
|
2017-04-21 01:29:30 +00:00
|
|
|
error_message = 'One and only one of {} must be passed.'
|
2016-12-13 03:49:36 +00:00
|
|
|
|
2017-03-17 09:30:02 +00:00
|
|
|
class OutOfOrder(EtiquetteException):
|
2016-12-13 03:49:36 +00:00
|
|
|
'''
|
2017-02-26 09:04:07 +00:00
|
|
|
For when a requested minmax range (a, b) has b > a
|
2016-12-13 03:49:36 +00:00
|
|
|
'''
|
2017-03-05 05:56:23 +00:00
|
|
|
error_message = 'Range "{range}": minimum "{min}" and maximum "{max}" are out of order.'
|