From cf4773d64f21dbdfa03521864d2aa6d2f1ea34c6 Mon Sep 17 00:00:00 2001 From: "adrian.sampson" Date: Thu, 5 Feb 2009 00:52:27 +0000 Subject: [PATCH] used un-meta-class constructor to reduce verbosity of exception classdefs --HG-- extra : convert_revision : svn%3A41726ec3-264d-0410-9c23-a9f1637257cc/trunk%40103 --- beets/player/bpd.py | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/beets/player/bpd.py b/beets/player/bpd.py index ec0ab4c5d..59c5834d2 100755 --- a/beets/player/bpd.py +++ b/beets/player/bpd.py @@ -59,13 +59,19 @@ class BPDError(Exception): to the given command. """ return ErrorResponse(self.code, cmd.name, self.message) - -class ArgumentTypeError(object): - """An error resulting from trying to cast an input argument. + +def make_bpd_error(self, s_code, s_message): + """Create a BPDError subclass for a static code and message. """ - code = ERROR_ARG - message = 'invalid type for argument' - def __init__(self): pass + class NewBPDError(BPDError): + code = s_code + message = s_message + def __init__(self): pass + return NewBPDError + +ArgumentTypeError = make_bpd_error(ERROR_ARG, 'invalid type for argument') +ArgumentIndexError = make_bpd_error(ERROR_ARG, 'argument out of range') +ArgumentNotFoundError = make_bpd_error(ERROR_NO_EXIST, 'argument not found') def cast_arg(t, val): """Attempts to call t on val, raising a CommandArgumentError @@ -82,19 +88,6 @@ def cast_arg(t, val): except ValueError: raise CommandArgumentError() -class ArgumentIndexError(object): - """An error resulting from an out-of-range index argument. - """ - code = ERROR_ARG - message = 'argument out of range' - def __init__(self): pass - -class ArgumentNotFoundError(object): - """An error for arguments that do not exist.""" - code = ERROR_NO_EXIST - message = 'argument not found' - def __init__(self): pass - class BPDClose(Exception): """Raised by a command invocation to indicate that the connection should be closed.