| @@ -75,6 +75,14 @@ class Bot(object): | |||||
| self.commands.load() | self.commands.load() | ||||
| self.tasks.load() | self.tasks.load() | ||||
| def __repr__(self): | |||||
| """Return the canonical string representation of the Bot.""" | |||||
| return "Bot(config={0!r})".format(self.config) | |||||
| def __str__(self): | |||||
| """Return a nice string representation of the Bot.""" | |||||
| return "<Bot at {0}>".format(self.config.root_dir) | |||||
| def _dispatch_irc_component(self, name, klass): | def _dispatch_irc_component(self, name, klass): | ||||
| """Create a new IRC component, record it internally, and start it.""" | """Create a new IRC component, record it internally, and start it.""" | ||||
| component = klass(self) | component = klass(self) | ||||
| @@ -75,6 +75,15 @@ class Command(object): | |||||
| self.setup() | self.setup() | ||||
| def __repr__(self): | |||||
| """Return the canonical string representation of the Command.""" | |||||
| res = "Command(name={0!r}, commands={1!r}, hooks={2!r}, bot={3!r})" | |||||
| return res.format(self.name, self.commands, self.hooks, self.bot) | |||||
| def __str__(self): | |||||
| """Return a nice string representation of the Command.""" | |||||
| return "<Command {0} of {1}>".format(self.name, self.bot) | |||||
| def setup(self): | def setup(self): | ||||
| """Hook called immediately after the command is loaded. | """Hook called immediately after the command is loaded. | ||||
| @@ -87,6 +87,15 @@ class BotConfig(object): | |||||
| (self._irc, ("watcher", "nickservPassword")), | (self._irc, ("watcher", "nickservPassword")), | ||||
| ] | ] | ||||
| def __repr__(self): | |||||
| """Return the canonical string representation of the BotConfig.""" | |||||
| res = "BotConfig(root_dir={0!r}, level={1!r})" | |||||
| return res.format(self.root_dir, self.logging_level) | |||||
| def __str__(self): | |||||
| """Return a nice string representation of the BotConfig.""" | |||||
| return "<BotConfig at {0}>".format(self.root_dir) | |||||
| def _load(self): | def _load(self): | ||||
| """Load data from our JSON config file (config.yml) into self._data.""" | """Load data from our JSON config file (config.yml) into self._data.""" | ||||
| filename = self._config_path | filename = self._config_path | ||||
| @@ -44,6 +44,17 @@ class IRCConnection(object): | |||||
| self._last_recv = time() | self._last_recv = time() | ||||
| self._last_ping = 0 | self._last_ping = 0 | ||||
| def __repr__(self): | |||||
| """Return the canonical string representation of the IRCConnection.""" | |||||
| res = "IRCConnection(host={0!r}, port={1!r}, nick={2!r}, ident={3!r}, realname={4!r})" | |||||
| return res.format(self.host, self.port, self.nick, self.ident, | |||||
| self.realname) | |||||
| def __str__(self): | |||||
| """Return a nice string representation of the IRCConnection.""" | |||||
| res = "<IRCConnection {0}!{1} at {2}:{3}>" | |||||
| return res.format(self.nick, self.ident, self.host, self.port) | |||||
| def _connect(self): | def _connect(self): | ||||
| """Connect to our IRC server.""" | """Connect to our IRC server.""" | ||||
| self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||||
| @@ -39,6 +39,15 @@ class Data(object): | |||||
| self._parse(msgtype) | self._parse(msgtype) | ||||
| def __repr__(self): | |||||
| """Return the canonical string representation of the Data.""" | |||||
| res = "Data(bot={0!r}, my_nick={1!r}, line={2!r})" | |||||
| return res.format(self.bot, self.my_nick, self.line) | |||||
| def __str__(self): | |||||
| """Return a nice string representation of the Data.""" | |||||
| return "<Data of {0!r}>".format(" ".join(self.line)) | |||||
| def _parse(self, msgtype): | def _parse(self, msgtype): | ||||
| """Parse a line from IRC into its components as instance attributes.""" | """Parse a line from IRC into its components as instance attributes.""" | ||||
| sender = re.findall(":(.*?)!(.*?)@(.*?)\Z", self.line[0])[0] | sender = re.findall(":(.*?)!(.*?)@(.*?)\Z", self.line[0])[0] | ||||
| @@ -47,6 +47,17 @@ class Frontend(IRCConnection): | |||||
| cf["realname"]) | cf["realname"]) | ||||
| self._connect() | self._connect() | ||||
| def __repr__(self): | |||||
| """Return the canonical string representation of the Frontend.""" | |||||
| res = "Frontend(host={0!r}, port={1!r}, nick={2!r}, ident={3!r}, realname={4!r}, bot={5!r})" | |||||
| return res.format(self.host, self.port, self.nick, self.ident, | |||||
| self.realname, self.bot) | |||||
| def __str__(self): | |||||
| """Return a nice string representation of the Frontend.""" | |||||
| res = "<Frontend {0}!{1} at {2}:{3}>" | |||||
| return res.format(self.nick, self.ident, self.host, self.port) | |||||
| def _process_message(self, line): | def _process_message(self, line): | ||||
| """Process a single message from IRC.""" | """Process a single message from IRC.""" | ||||
| if line[1] == "JOIN": | if line[1] == "JOIN": | ||||
| @@ -37,6 +37,14 @@ class RC(object): | |||||
| self.chan = chan | self.chan = chan | ||||
| self.msg = msg | self.msg = msg | ||||
| def __repr__(self): | |||||
| """Return the canonical string representation of the RC.""" | |||||
| return "RC(chan={0!r}, msg={1!r})".format(self.chan, self.msg) | |||||
| def __str__(self): | |||||
| """Return a nice string representation of the RC.""" | |||||
| return "<RC of {0!r} on {1}>".format(self.msg, self.chan) | |||||
| def parse(self): | def parse(self): | ||||
| """Parse a recent change event into some variables.""" | """Parse a recent change event into some variables.""" | ||||
| # Strip IRC color codes; we don't want or need 'em: | # Strip IRC color codes; we don't want or need 'em: | ||||
| @@ -48,6 +48,17 @@ class Watcher(IRCConnection): | |||||
| self._prepare_process_hook() | self._prepare_process_hook() | ||||
| self._connect() | self._connect() | ||||
| def __repr__(self): | |||||
| """Return the canonical string representation of the Watcher.""" | |||||
| res = "Watcher(host={0!r}, port={1!r}, nick={2!r}, ident={3!r}, realname={4!r}, bot={5!r})" | |||||
| return res.format(self.host, self.port, self.nick, self.ident, | |||||
| self.realname, self.bot) | |||||
| def __str__(self): | |||||
| """Return a nice string representation of the Watcher.""" | |||||
| res = "<Watcher {0}!{1} at {2}:{3}>" | |||||
| return res.format(self.nick, self.ident, self.host, self.port) | |||||
| def _process_message(self, line): | def _process_message(self, line): | ||||
| """Process a single message from IRC.""" | """Process a single message from IRC.""" | ||||
| if line[1] == "PRIVMSG": | if line[1] == "PRIVMSG": | ||||
| @@ -57,6 +57,16 @@ class _ResourceManager(object): | |||||
| self._resource_base = base # e.g. Command or Task | self._resource_base = base # e.g. Command or Task | ||||
| self._resource_access_lock = RLock() | self._resource_access_lock = RLock() | ||||
| def __repr__(self): | |||||
| """Return the canonical string representation of the manager.""" | |||||
| res = "{0}(bot={1!r}, name={2!r}, base={3!r})" | |||||
| return res.format(self.__class__.__name__, self.bot, | |||||
| self._resource_name, self._resource_base) | |||||
| def __str__(self): | |||||
| """Return a nice string representation of the manager.""" | |||||
| return "<{0} of {1}>".format(self.__class__.__name__, self.bot) | |||||
| def __iter__(self): | def __iter__(self): | ||||
| with self.lock: | with self.lock: | ||||
| for resource in self._resources.itervalues(): | for resource in self._resources.itervalues(): | ||||
| @@ -56,6 +56,16 @@ class Task(object): | |||||
| self.logger = bot.tasks.logger.getChild(self.name) | self.logger = bot.tasks.logger.getChild(self.name) | ||||
| self.setup() | self.setup() | ||||
| def __repr__(self): | |||||
| """Return the canonical string representation of the Task.""" | |||||
| res = "Task(name={0!r}, number={1!r}, bot={2!r})" | |||||
| return res.format(self.name, self.number, self.bot) | |||||
| def __str__(self): | |||||
| """Return a nice string representation of the Task.""" | |||||
| res = "<Task {0} ({1}) of {2}>" | |||||
| return res.format(self.name, self.number, self.bot) | |||||
| def setup(self): | def setup(self): | ||||
| """Hook called immediately after the task is loaded. | """Hook called immediately after the task is loaded. | ||||
| @@ -63,6 +63,15 @@ class SitesDB(object): | |||||
| self._cookie_file = path.join(bot.config.root_dir, ".cookies") | self._cookie_file = path.join(bot.config.root_dir, ".cookies") | ||||
| self._cookiejar = None | self._cookiejar = None | ||||
| def __repr__(self): | |||||
| """Return the canonical string representation of the SitesDB.""" | |||||
| res = "SitesDB(config={0!r}, sitesdb={1!r}, cookie_file={2!r})" | |||||
| return res.format(self.config, self._sitesdb, self._cookie_file) | |||||
| def __str__(self): | |||||
| """Return a nice string representation of the SitesDB.""" | |||||
| return "<SitesDB at {0}>".format(self._sitesdb) | |||||
| def _get_cookiejar(self): | def _get_cookiejar(self): | ||||
| """Return a LWPCookieJar object loaded from our .cookies file. | """Return a LWPCookieJar object loaded from our .cookies file. | ||||