diff --git a/earwigbot/commands/link.py b/earwigbot/commands/link.py index aafb114..32d939b 100644 --- a/earwigbot/commands/link.py +++ b/earwigbot/commands/link.py @@ -21,7 +21,6 @@ # SOFTWARE. import re -from urllib import quote from earwigbot.commands import Command diff --git a/earwigbot/irc/connection.py b/earwigbot/irc/connection.py index 9886f2e..38c0bdb 100644 --- a/earwigbot/irc/connection.py +++ b/earwigbot/irc/connection.py @@ -31,12 +31,13 @@ __all__ = ["IRCConnection"] class IRCConnection(object): """Interface with an IRC server.""" - def __init__(self, host, port, nick, ident, realname): + def __init__(self, host, port, nick, ident, realname, logger): self._host = host self._port = port self._nick = nick self._ident = ident self._realname = realname + self.logger = logger self._is_running = False self._send_lock = Lock() diff --git a/earwigbot/irc/data.py b/earwigbot/irc/data.py index b1edbb4..3bff616 100644 --- a/earwigbot/irc/data.py +++ b/earwigbot/irc/data.py @@ -42,7 +42,7 @@ class Data(object): 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) + return res.format(self._bot, self.my_nick, self.line) def __str__(self): """Return a nice string representation of the Data.""" diff --git a/earwigbot/irc/frontend.py b/earwigbot/irc/frontend.py index 2a69953..b8582b0 100644 --- a/earwigbot/irc/frontend.py +++ b/earwigbot/irc/frontend.py @@ -39,12 +39,10 @@ class Frontend(IRCConnection): def __init__(self, bot): self.bot = bot - self.logger = bot.logger.getChild("frontend") - cf = bot.config.irc["frontend"] base = super(Frontend, self) base.__init__(cf["host"], cf["port"], cf["nick"], cf["ident"], - cf["realname"]) + cf["realname"], bot.logger.getChild("frontend")) self._connect() def __repr__(self): diff --git a/earwigbot/irc/watcher.py b/earwigbot/irc/watcher.py index 8b89763..caf7fdd 100644 --- a/earwigbot/irc/watcher.py +++ b/earwigbot/irc/watcher.py @@ -39,12 +39,10 @@ class Watcher(IRCConnection): def __init__(self, bot): self.bot = bot - self.logger = bot.logger.getChild("watcher") - cf = bot.config.irc["watcher"] base = super(Watcher, self) base.__init__(cf["host"], cf["port"], cf["nick"], cf["ident"], - cf["realname"]) + cf["realname"], bot.logger.getChild("watcher")) self._prepare_process_hook() self._connect() diff --git a/earwigbot/wiki/copyvios/exclusions.py b/earwigbot/wiki/copyvios/exclusions.py index 4640b1f..f0bfb30 100644 --- a/earwigbot/wiki/copyvios/exclusions.py +++ b/earwigbot/wiki/copyvios/exclusions.py @@ -114,7 +114,7 @@ class ExclusionsDB(object): else: conn.execute(query3, (sitename, url)) conn.executemany(query4, [(sitename, url) for url in urls]) - if conn.execute(query5, (name,)).fetchone(): + if conn.execute(query5, (sitename,)).fetchone(): conn.execute(query6, (time(), sitename)) else: conn.execute(query7, (sitename, time())) @@ -136,7 +136,7 @@ class ExclusionsDB(object): This only updates the exclusions database for the *sitename* site. """ max_staleness = 60 * 60 * 24 * 30 - time_since_update = int(time() - self._get_last_update()) + time_since_update = int(time() - self._get_last_update(sitename)) if time_since_update > max_staleness: log = u"Updating stale database: {0} (last updated {1} seconds ago)" self._logger.info(log.format(sitename, time_since_update)) diff --git a/earwigbot/wiki/copyvios/parsers.py b/earwigbot/wiki/copyvios/parsers.py index b258730..d7906e4 100644 --- a/earwigbot/wiki/copyvios/parsers.py +++ b/earwigbot/wiki/copyvios/parsers.py @@ -23,9 +23,9 @@ from os import path try: - from bs4 import BeautifulSoup + import bs4 except ImportError: - BeautifulSoup = None + bs4 = None try: import mwparserfromhell @@ -52,7 +52,7 @@ class BaseTextParser(object): def __str__(self): """Return a nice string representation of the text parser.""" name = self.__class__.__name__ - return "<{0} of text with size {1}>".format(name, len(text)) + return "<{0} of text with size {1}>".format(name, len(self.text)) class ArticleTextParser(BaseTextParser): @@ -136,9 +136,9 @@ class HTMLTextParser(BaseTextParser): (http://www.crummy.com/software/BeautifulSoup/). """ try: - soup = BeautifulSoup(self.text, "lxml").body + soup = bs4.BeautifulSoup(self.text, "lxml").body except ValueError: - soup = BeautifulSoup(self.text).body + soup = bs4.BeautifulSoup(self.text).body is_comment = lambda text: isinstance(text, bs4.element.Comment) [comment.extract() for comment in soup.find_all(text=is_comment)] diff --git a/earwigbot/wiki/site.py b/earwigbot/wiki/site.py index 93f636d..46b5a4b 100644 --- a/earwigbot/wiki/site.py +++ b/earwigbot/wiki/site.py @@ -185,9 +185,9 @@ class Site(object): name, password = self._login_info login = "({0}, {1})".format(repr(name), "hidden" if password else None) cookies = self._cookiejar.__class__.__name__ - try: - cookies += "({0!r})".format(self._cookiejar.filename) - except AttributeError: + if hasattr(self._cookiejar, "filename"): + cookies += "({0!r})".format(getattr(self._cookiejar, "filename")) + else: cookies += "()" agent = self._opener.addheaders[0][1] return res.format(login, cookies, agent, **self.__dict__) @@ -445,10 +445,11 @@ class Site(object): FileCookieJar raises NotImplementedError) or no default filename was given (LWPCookieJar and MozillaCookieJar raise ValueError). """ - try: - self._cookiejar.save() - except (AttributeError, NotImplementedError, ValueError): - pass + if hasattr(self._cookiejar, "save"): + try: + gettattr(self._cookiejar, "save")() + except (NotImplementedError, ValueError): + pass def _login(self, login, token=None, attempt=0): """Safely login through the API. diff --git a/earwigbot/wiki/sitesdb.py b/earwigbot/wiki/sitesdb.py index a858e59..e2e2a8a 100644 --- a/earwigbot/wiki/sitesdb.py +++ b/earwigbot/wiki/sitesdb.py @@ -323,7 +323,7 @@ class SitesDB(object): # Name arg given, but don't look at others unless `name` isn't found: if name: try: - return self._get_site_object(name) + return self._get_site_object(name) except SiteNotFoundError: if project and lang: name = self._get_site_name_from_sitesdb(project, lang)