From 46c71a752125bb9d28e7d2addb3364c29957b88e Mon Sep 17 00:00:00 2001 From: James Vega Date: Mon, 16 Aug 2004 17:34:58 +0000 Subject: [PATCH] Add dbi.NoRecordError and update Quotes to use it --- plugins/Quotes.py | 9 +++------ src/dbi.py | 9 ++++++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/Quotes.py b/plugins/Quotes.py index dd9676219..2503ffbb5 100644 --- a/plugins/Quotes.py +++ b/plugins/Quotes.py @@ -55,9 +55,6 @@ except ImportError: raise callbacks.Error, 'You need to have PySQLite installed to use this '\ 'plugin. Download it at ' -class QuotesError(Exception): - pass - class QuoteRecord(object): __metaclass__ = dbi.Record __fields__ = [ @@ -161,7 +158,7 @@ class SqliteQuotesDB(object): cursor.execute("""SELECT added_by, added_at, quote FROM quotes WHERE id=%s""", id) if cursor.rowcount == 0: - raise QuotesDBError, id + raise dbi.NoRecordError, id (by, at, text) = cursor.fetchone() return QuoteRecord(id, by=by, at=int(at), text=text) @@ -170,7 +167,7 @@ class SqliteQuotesDB(object): cursor = db.cursor() cursor.execute("""DELETE FROM quotes WHERE id=%s""", id) if cursor.rowcount == 0: - raise QuotesDBError, id + raise dbi.NoRecordError, id db.commit() def QuotesDB(): @@ -291,7 +288,7 @@ class Quotes(callbacks.Privmsg): try: quote = self.db.get(channel, id) irc.reply(str(quote)) - except QuotesDBError, e: + except dbi.NoRecordError, e: irc.error('There isn\'t a quote with that id.') def remove(self, irc, msg, args): diff --git a/src/dbi.py b/src/dbi.py index 105f7d769..1981606be 100644 --- a/src/dbi.py +++ b/src/dbi.py @@ -47,7 +47,10 @@ import supybot.utils as utils class Error(Exception): """General error for this module.""" - + +class NoRecordError(KeyError): + pass + class MappingInterface(object): """This is a class to represent the underlying representation of a map from integer keys to strings.""" @@ -56,7 +59,7 @@ class MappingInterface(object): raise NotImplementedError def get(id): - """Gets the record matching id. Raises KeyError otherwise.""" + """Gets the record matching id. Raises NoRecordError otherwise.""" raise NotImplementedError def set(id, s): @@ -149,7 +152,7 @@ class FlatfileMapping(MappingInterface): (lineId, s) = self._splitLine(line) if lineId == strId: return s - raise KeyError, id + raise NoRecordError, id finally: fd.close()