@@ -26,6 +26,9 @@ EarwigBot Exceptions | |||||
This module contains all exceptions used by EarwigBot:: | This module contains all exceptions used by EarwigBot:: | ||||
EarwigBotError | EarwigBotError | ||||
+-- IRCError | |||||
| +-- BrokenSocketError | |||||
| +-- KwargParseError | |||||
+-- WikiToolsetError | +-- WikiToolsetError | ||||
+-- SiteNotFoundError | +-- SiteNotFoundError | ||||
+-- SiteAPIError | +-- SiteAPIError | ||||
@@ -49,10 +52,24 @@ EarwigBotError | |||||
+-- SearchQueryError | +-- SearchQueryError | ||||
""" | """ | ||||
class EarwigBotErorr(Exception): | |||||
class EarwigBotError(Exception): | |||||
"""Base exception class for errors in EarwigBot.""" | """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.""" | """Base exception class for errors in the Wiki Toolset.""" | ||||
class SiteNotFoundError(WikiToolsetError): | class SiteNotFoundError(WikiToolsetError): | ||||
@@ -24,14 +24,9 @@ import socket | |||||
from threading import Lock | from threading import Lock | ||||
from time import sleep | 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): | class IRCConnection(object): | ||||
"""A class to interface with IRC.""" | """A class to interface with IRC.""" | ||||
@@ -72,7 +67,7 @@ class IRCConnection(object): | |||||
data = self._sock.recv(size) | data = self._sock.recv(size) | ||||
if not data: | if not data: | ||||
# Socket isn't giving us any data, so it is dead or broken: | # Socket isn't giving us any data, so it is dead or broken: | ||||
raise BrokenSocketException() | |||||
raise BrokenSocketError() | |||||
return data | return data | ||||
def _send(self, msg): | def _send(self, msg): | ||||
@@ -137,7 +132,7 @@ class IRCConnection(object): | |||||
while 1: | while 1: | ||||
try: | try: | ||||
read_buffer += self._get() | read_buffer += self._get() | ||||
except BrokenSocketException: | |||||
except BrokenSocketError: | |||||
self._is_running = False | self._is_running = False | ||||
break | break | ||||
@@ -22,13 +22,9 @@ | |||||
import re | 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): | class Data(object): | ||||
"""Store data from an individual line received on IRC.""" | """Store data from an individual line received on IRC.""" | ||||
@@ -81,8 +77,8 @@ class Data(object): | |||||
try: | try: | ||||
key, value = re.findall("^(.*?)\=(.*?)$", arg)[0] | key, value = re.findall("^(.*?)\=(.*?)$", arg)[0] | ||||
except IndexError: | except IndexError: | ||||
raise KwargParseException(arg) | |||||
raise KwargParseError(arg) | |||||
if key and value: | if key and value: | ||||
self.kwargs[key] = value | self.kwargs[key] = value | ||||
else: | else: | ||||
raise KwargParseException(arg) | |||||
raise KwargParseError(arg) |