Bläddra i källkod

Moving two exceptions out of earwigbot.irc

tags/v0.1^2
Ben Kurtovic 12 år sedan
förälder
incheckning
1b88f63d27
3 ändrade filer med 27 tillägg och 19 borttagningar
  1. +19
    -2
      earwigbot/exceptions.py
  2. +4
    -9
      earwigbot/irc/connection.py
  3. +4
    -8
      earwigbot/irc/data.py

+ 19
- 2
earwigbot/exceptions.py Visa fil

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


+ 4
- 9
earwigbot/irc/connection.py Visa fil

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



+ 4
- 8
earwigbot/irc/data.py Visa fil

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

Laddar…
Avbryt
Spara