From 1b88f63d270a776de528fe27ff3a40899f2ee843 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sat, 5 May 2012 16:15:29 -0400 Subject: [PATCH] Moving two exceptions out of earwigbot.irc --- earwigbot/exceptions.py | 21 +++++++++++++++++++-- earwigbot/irc/connection.py | 13 ++++--------- earwigbot/irc/data.py | 12 ++++-------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/earwigbot/exceptions.py b/earwigbot/exceptions.py index 05d8226..d1303dc 100644 --- a/earwigbot/exceptions.py +++ b/earwigbot/exceptions.py @@ -26,6 +26,9 @@ EarwigBot Exceptions This module contains all exceptions used by EarwigBot:: EarwigBotError + +-- IRCError + | +-- BrokenSocketError + | +-- KwargParseError +-- WikiToolsetError +-- SiteNotFoundError +-- SiteAPIError @@ -49,10 +52,24 @@ EarwigBotError +-- SearchQueryError """ -class EarwigBotErorr(Exception): +class EarwigBotError(Exception): """Base exception class for errors in EarwigBot.""" -class WikiToolsetError(EarwigBotErorr): +class IRCError(EarwigBotError): + """Base exception class for errors in IRC-relation sections of the bot.""" + +class BrokenSocketError(IRCError): + """A socket has broken, because it is not sending data. + + Raised by earwigbot.irc.IRCConnection()._get(). + """ + +class KwargParseError(IRCError): + """Couldn't parse a certain keyword argument in Data().args, probably + because it was given incorrectly: e.g., no value (abc), just a value + (=xyz), just an equal sign (=), instead of the correct (abc=xyz).""" + +class WikiToolsetError(EarwigBotError): """Base exception class for errors in the Wiki Toolset.""" class SiteNotFoundError(WikiToolsetError): diff --git a/earwigbot/irc/connection.py b/earwigbot/irc/connection.py index f819534..b8c864a 100644 --- a/earwigbot/irc/connection.py +++ b/earwigbot/irc/connection.py @@ -24,14 +24,9 @@ import socket from threading import Lock from time import sleep -__all__ = ["BrokenSocketException", "IRCConnection"] +from earwigbot.exceptions import BrokenSocketError -class BrokenSocketException(Exception): - """A socket has broken, because it is not sending data. - - Raised by IRCConnection()._get(). - """ - pass +__all__ = ["IRCConnection"] class IRCConnection(object): """A class to interface with IRC.""" @@ -72,7 +67,7 @@ class IRCConnection(object): data = self._sock.recv(size) if not data: # Socket isn't giving us any data, so it is dead or broken: - raise BrokenSocketException() + raise BrokenSocketError() return data def _send(self, msg): @@ -137,7 +132,7 @@ class IRCConnection(object): while 1: try: read_buffer += self._get() - except BrokenSocketException: + except BrokenSocketError: self._is_running = False break diff --git a/earwigbot/irc/data.py b/earwigbot/irc/data.py index b83bcf6..83b8166 100644 --- a/earwigbot/irc/data.py +++ b/earwigbot/irc/data.py @@ -22,13 +22,9 @@ import re -__all__ = ["KwargParseException", "Data"] +from earwigbot.exceptions import KwargParseError -class KwargParseException(Exception): - """Couldn't parse a certain keyword argument in self.args, probably because - it was given incorrectly: e.g., no value (abc), just a value (=xyz), just - an equal sign (=), instead of the correct (abc=xyz).""" - pass +__all__ = ["Data"] class Data(object): """Store data from an individual line received on IRC.""" @@ -81,8 +77,8 @@ class Data(object): try: key, value = re.findall("^(.*?)\=(.*?)$", arg)[0] except IndexError: - raise KwargParseException(arg) + raise KwargParseError(arg) if key and value: self.kwargs[key] = value else: - raise KwargParseException(arg) + raise KwargParseError(arg)