Add dbi.NoRecordError and update Quotes to use it

This commit is contained in:
James Vega 2004-08-16 17:34:58 +00:00
parent eb1dac0d60
commit 46c71a7521
2 changed files with 9 additions and 9 deletions

View File

@ -55,9 +55,6 @@ except ImportError:
raise callbacks.Error, 'You need to have PySQLite installed to use this '\
'plugin. Download it at <http://pysqlite.sf.net/>'
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):

View File

@ -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()