diff --git a/plugins/Bugzilla.py b/plugins/Bugzilla.py index 54e33f5c2..258a810d1 100644 --- a/plugins/Bugzilla.py +++ b/plugins/Bugzilla.py @@ -267,7 +267,7 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp): report['product'] = str(summary['product']) s = '%(product)s bug #%(id)s: %(title)s %(summary)s' % report irc.reply(s, prefixName=False) - bzSnarfer = wrap(bzSnarfer, decorators=['urlSnarfer']) + bzSnarfer = urlSnarfer(bzSnarfer) def urlquery2bugslist(self, url, query): """Given a URL and query list for a CSV bug list, it'll return diff --git a/plugins/Ebay.py b/plugins/Ebay.py index f902d0e49..7de86347f 100644 --- a/plugins/Ebay.py +++ b/plugins/Ebay.py @@ -127,7 +127,7 @@ class Ebay(callbacks.PrivmsgCommandAndRegexp): irc.reply(self._getResponse(url), prefixName=False) except EbayError, e: self.log.info('ebaySnarfer exception at %s: %s', url, str(e)) - ebaySnarfer = wrap(ebaySnarfer, decorators=['urlSnarfer']) + ebaySnarfer = urlSnarfer(ebaySnarfer) def _getResponse(self, url): try: diff --git a/plugins/Gameknot.py b/plugins/Gameknot.py index ef5eeebcc..6df47a6ef 100644 --- a/plugins/Gameknot.py +++ b/plugins/Gameknot.py @@ -223,7 +223,7 @@ class Gameknot(callbacks.PrivmsgCommandAndRegexp): irc.errorPossibleBug(s) except Exception, e: irc.error(utils.exnToString(e)) - gameknotSnarfer = wrap(gameknotSnarfer, decorators=['urlSnarfer']) + gameknotSnarfer = urlSnarfer(gameknotSnarfer) def gameknotStatsSnarfer(self, irc, msg, match): r"http://gameknot\.com/stats\.pl\?([^&]+)" @@ -232,7 +232,7 @@ class Gameknot(callbacks.PrivmsgCommandAndRegexp): name = match.group(1) s = self.getStats(name) irc.reply(s, prefixName=False) - gameknotStatsSnarfer = wrap(gameknotStatsSnarfer,decorators=['urlSnarfer']) + gameknotStatsSnarfer = urlSnarfer(gameknotStatsSnarfer) Class = Gameknot diff --git a/plugins/Geekquote.py b/plugins/Geekquote.py index cb8ce1fb2..71d30865f 100644 --- a/plugins/Geekquote.py +++ b/plugins/Geekquote.py @@ -58,7 +58,6 @@ import supybot.conf as conf import supybot.utils as utils from supybot.commands import * import supybot.webutils as webutils -import supybot.privmsgs as privmsgs import supybot.registry as registry import supybot.callbacks as callbacks @@ -158,7 +157,7 @@ class Geekquote(callbacks.PrivmsgCommandAndRegexp): site = match.groupdict()['site'] self.log.info('Snarfing geekquote %s from %s.' % (id, site)) self._gkBackend(irc, msg, site, id) - geekSnarfer = wrap(geekSnarfer, decorators=['urlSnarfer']) + geekSnarfer = urlSnarfer(geekSnarfer) def geekquote(self, irc, msg, args, id): """[] @@ -168,7 +167,7 @@ class Geekquote(callbacks.PrivmsgCommandAndRegexp): """ site = 'bash.org' self._gkBackend(irc, msg, site, id) - geekquote = wrap(geekquote, [optional(('id', 'geekquote'))]) + geekquote = wrap(geekquote, [additional(('id', 'geekquote'))]) def qdb(self, irc, msg, args, id): """[] @@ -176,10 +175,9 @@ class Geekquote(callbacks.PrivmsgCommandAndRegexp): Returns a random geek quote from qdb.us; the optional argument specifies which quote to retrieve. """ - id = privmsgs.getArgs(args, required=0, optional=1) site = 'qdb.us' self._gkBackend(irc, msg, site, id) - qdb = wrap(qdb, [optional(('id', 'qdb'))]) + qdb = wrap(qdb, [additional(('id', 'qdb'))]) Class = Geekquote diff --git a/plugins/Google.py b/plugins/Google.py index d4e10fdd7..c5c891e07 100644 --- a/plugins/Google.py +++ b/plugins/Google.py @@ -427,7 +427,7 @@ class Google(callbacks.PrivmsgCommandAndRegexp): if data.results: url = data.results[0].URL irc.reply(url, prefixName=False) - googleSnarfer = wrap(googleSnarfer, decorators=['urlSnarfer']) + googleSnarfer = urlSnarfer(googleSnarfer) _ggThread = re.compile(r'
Subject: ([^<]+)
', re.I) _ggGroup = re.compile(r'Newsgroups: (?:]+>)?([^<]+)(?:)?', re.I) @@ -460,7 +460,7 @@ class Google(callbacks.PrivmsgCommandAndRegexp): else: irc.errorPossibleBug('That doesn\'t appear to be a proper ' 'Google Groups page.') - googleGroups = wrap(googleGroups, decorators=['urlSnarfer']) + googleGroups = urlSnarfer(googleGroups) _calcRe = re.compile(r'(.*?)', re.I) _calcSupRe = re.compile(r'(.*?)', re.I) diff --git a/plugins/Python.py b/plugins/Python.py index a44ce8219..9cbb3af37 100644 --- a/plugins/Python.py +++ b/plugins/Python.py @@ -193,7 +193,7 @@ class Python(callbacks.PrivmsgCommandAndRegexp): resp.append('%s: %s' % self._bold(m.groups())) if resp: irc.reply('; '.join(resp), prefixName = False) - aspnRecipes = wrap(aspnRecipes, decorators=['urlSnarfer']) + aspnRecipes = urlSnarfer(aspnRecipes) Class = Python diff --git a/plugins/ShrinkUrl.py b/plugins/ShrinkUrl.py index 2511e71a5..cf0412a07 100644 --- a/plugins/ShrinkUrl.py +++ b/plugins/ShrinkUrl.py @@ -189,7 +189,7 @@ class ShrinkUrl(callbacks.PrivmsgCommandAndRegexp): if m is None: print irc, irc.__class__ m.tag('shrunken') - shrinkSnarfer = wrap(shrinkSnarfer, decorators=['urlSnarfer']) + shrinkSnarfer = urlSnarfer(shrinkSnarfer) def _getLnUrl(self, url): try: @@ -219,7 +219,7 @@ class ShrinkUrl(callbacks.PrivmsgCommandAndRegexp): m.tag('shrunken') else: irc.error(error) - ln = wrap(ln, ['url'], decorators=['thread']) + ln = thread(wrap(ln, ['url'])) _tinyRe = re.compile(r'
(http://tinyurl\.com/\w+)') def _getTinyUrl(self, url): @@ -250,7 +250,7 @@ class ShrinkUrl(callbacks.PrivmsgCommandAndRegexp): else: s = 'Could not parse the TinyURL.com results page.' irc.errorPossibleBug(s) - tiny = wrap(tiny, ['url'], decorators=['thread']) + tiny = thread(wrap(tiny, ['url'])) Class = ShrinkUrl diff --git a/plugins/Sourceforge.py b/plugins/Sourceforge.py index 0596e8f1a..4ad082872 100644 --- a/plugins/Sourceforge.py +++ b/plugins/Sourceforge.py @@ -510,7 +510,7 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp): irc.reply(resp, prefixName=False) except TrackerError, e: self.log.warning(str(e)) - sfSnarfer = wrap(sfSnarfer, decorators=['urlSnarfer']) + sfSnarfer = urlSnarfer(sfSnarfer) Class = Sourceforge diff --git a/plugins/URL.py b/plugins/URL.py index 7ed09d193..a0bf8d727 100644 --- a/plugins/URL.py +++ b/plugins/URL.py @@ -139,7 +139,7 @@ class URL(callbacks.PrivmsgCommandAndRegexp): title = utils.htmlToText(m.group(1).strip()) s = 'Title: %s (at %s)' % (title, domain) irc.reply(s, prefixName=False) - titleSnarfer = wrap(titleSnarfer, decorators=['urlSnarfer']) + titleSnarfer = urlSnarfer(titleSnarfer) def stats(self, irc, msg, args, channel): """[] @@ -152,7 +152,7 @@ class URL(callbacks.PrivmsgCommandAndRegexp): irc.reply('I have %s in my database.' % utils.nItems('URL', count)) stats = wrap(stats, ['channeldb']) - def last(self, irc, msg, args, optlist, channel): + def last(self, irc, msg, args, channel, optlist): """[] [--{from,with,without,near,proto}=] --nolimit Gives the last URL matching the given criteria. --from is from whom diff --git a/src/Misc.py b/src/Misc.py index 225431cd1..56ce1bf44 100755 --- a/src/Misc.py +++ b/src/Misc.py @@ -279,7 +279,7 @@ class Misc(callbacks.Privmsg): s = 'The current (running) version of this Supybot is %s. %s' % \ (conf.version, newest) irc.reply(s) - version = wrap(version, decorators=['thread']) + version = wrap(thread(version)) # XXX This should be converted to use commands.wrap, but since it's not # using privmsgs.*, I'm saving it for later. diff --git a/src/callbacks.py b/src/callbacks.py index 40410cbb0..eee5480fd 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -501,6 +501,8 @@ class RichReplyMethods(object): return self._error(self.__makeReply(v, s), **kwargs) def errorNoUser(self, s='', name='that user', **kwargs): + if 'Raise' not in kwargs: + kwargs['Raise'] = True v = self._getConfig(conf.supybot.replies.noUser) try: v = v % name diff --git a/src/commands.py b/src/commands.py index 70dd5206a..3995f1213 100644 --- a/src/commands.py +++ b/src/commands.py @@ -79,6 +79,12 @@ class UrlSnarfThread(world.SupyThread): super(UrlSnarfThread, self).__init__(*args, **kwargs) self.setDaemon(True) + def run(self): + try: + super(UrlSnarfThread, self).run() + except webutils.WebError, e: + log.debug('Exception in urlSnarfer: %s' % utils.exnToString(e)) + class SnarfQueue(ircutils.FloodQueue): timeout = conf.supybot.snarfThrottle def key(self, channel): @@ -134,11 +140,6 @@ def urlSnarfer(f): newf = utils.changeFunctionName(newf, f.func_name, f.__doc__) return newf -decorators = ircutils.IrcDict({ - 'thread': thread, - 'urlSnarfer': urlSnarfer, -}) - ### # Converters, which take irc, msg, args, and a state object, and build up the @@ -756,26 +757,16 @@ class Spec(object): # This is used below, but we need to rename it so its name isn't # shadowed by our locals. -_decorators = decorators -def wrap(f, specList=[], decorators=None, **kw): +def wrap(f, specList=[], **kw): spec = Spec(specList, **kw) - # XXX This is a hack, but it's just a workaround until I know the right way - # to fix this problem. - if decorators is not None and 'urlSnarfer' in decorators: - kw['allowExtra'] = True def newf(self, irc, msg, args, **kwargs): state = spec(irc, msg, args, stateAttrs={'cb': self, 'log': self.log}) f(self, irc, msg, args, *state.args, **state.kwargs) - newf = utils.changeFunctionName(newf, f.func_name, f.__doc__) - if decorators is not None: - decorators = map(_decorators.__getitem__, decorators) - for decorator in decorators: - newf = decorator(newf) - return newf + return utils.changeFunctionName(newf, f.func_name, f.__doc__) __all__ = ['wrap', 'context', 'additional', 'optional', 'any', 'compose', - 'Spec', 'first', + 'Spec', 'first', 'urlSnarfer', 'thread', 'many', 'getopts', 'getConverter', 'addConverter', 'callConverter'] if world.testing: