From 68b1d65d6864b2611dd206e782526ca965782be4 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Sat, 29 Jan 2005 21:24:17 +0000 Subject: [PATCH] Plugin normalization, sanitation, etc. Removed unused imports, for the most part. --- plugins/Admin/plugin.py | 2 -- plugins/Babelfish/plugin.py | 1 - plugins/Channel/plugin.py | 1 - plugins/Dict/plugin.py | 6 ++---- plugins/Filter/plugin.py | 6 +----- plugins/Format/plugin.py | 9 --------- plugins/Herald/plugin.py | 2 -- plugins/Misc/plugin.py | 6 ++---- plugins/Owner/plugin.py | 35 ++++++++++++++++------------------- plugins/Owner/test.py | 2 +- plugins/Status/plugin.py | 36 ++++++++++++++---------------------- plugins/User/plugin.py | 12 ++++++------ plugins/Utilities/plugin.py | 3 --- 13 files changed, 42 insertions(+), 79 deletions(-) diff --git a/plugins/Admin/plugin.py b/plugins/Admin/plugin.py index dbeb82856..9da5434dd 100644 --- a/plugins/Admin/plugin.py +++ b/plugins/Admin/plugin.py @@ -29,9 +29,7 @@ import sys import time -import pprint -import supybot.log as log import supybot.conf as conf import supybot.ircdb as ircdb import supybot.utils as utils diff --git a/plugins/Babelfish/plugin.py b/plugins/Babelfish/plugin.py index 376e10919..700112cb5 100644 --- a/plugins/Babelfish/plugin.py +++ b/plugins/Babelfish/plugin.py @@ -34,7 +34,6 @@ import babelfish import supybot.conf as conf import supybot.utils as utils from supybot.commands import * -import supybot.registry as registry import supybot.callbacks as callbacks class Babelfish(callbacks.Privmsg): diff --git a/plugins/Channel/plugin.py b/plugins/Channel/plugin.py index e4a53cc1c..caa93950e 100644 --- a/plugins/Channel/plugin.py +++ b/plugins/Channel/plugin.py @@ -28,7 +28,6 @@ ### import sys -import time import supybot.conf as conf import supybot.ircdb as ircdb diff --git a/plugins/Dict/plugin.py b/plugins/Dict/plugin.py index 7522b70d0..b3270d842 100644 --- a/plugins/Dict/plugin.py +++ b/plugins/Dict/plugin.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. ### -import sets import random import socket @@ -37,7 +36,6 @@ import supybot.conf as conf import supybot.utils as utils from supybot.commands import * import supybot.ircutils as ircutils -import supybot.registry as registry import supybot.callbacks as callbacks class Dict(callbacks.Privmsg): @@ -81,7 +79,7 @@ class Dict(callbacks.Privmsg): conn = dictclient.Connection(server) except socket.error, e: irc.error(utils.web.strError(e), Raise=True) - dbs = sets.Set(conn.getdbdescs()) + dbs = set(conn.getdbdescs()) if words[0] in dbs: dictionary = words.pop(0) else: @@ -97,7 +95,7 @@ class Dict(callbacks.Privmsg): irc.error('You must give a word to define.', Raise=True) word = ' '.join(words) definitions = conn.define(dictionary, word) - dbs = sets.Set() + dbs = set() if not definitions: if dictionary == '*': irc.reply('No definition for %s could be found.' % diff --git a/plugins/Filter/plugin.py b/plugins/Filter/plugin.py index be25166e6..5aaf24eaa 100644 --- a/plugins/Filter/plugin.py +++ b/plugins/Filter/plugin.py @@ -27,12 +27,9 @@ # POSSIBILITY OF SUCH DAMAGE. ### -import supybot.plugins as plugins - import re import string import random -import itertools from cStringIO import StringIO import supybot.conf as conf @@ -40,7 +37,6 @@ import supybot.utils as utils from supybot.commands import * import supybot.ircmsgs as ircmsgs import supybot.ircutils as ircutils -import supybot.registry as registry import supybot.callbacks as callbacks class MyFilterProxy(object): @@ -377,7 +373,7 @@ class Filter(callbacks.Privmsg): Returns colorized like a rainbow. """ - colors = itertools.cycle([4, 7, 8, 3, 2, 12, 6]) + colors = utils.iter.cycle([4, 7, 8, 3, 2, 12, 6]) L = [self._color(c, fg=colors.next()) for c in text] irc.reply(''.join(L) + '\x03') rainbow = wrap(rainbow, ['text']) diff --git a/plugins/Format/plugin.py b/plugins/Format/plugin.py index bcb3ffeff..9b39c7fbe 100644 --- a/plugins/Format/plugin.py +++ b/plugins/Format/plugin.py @@ -27,13 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. ### -import supybot - -__revision__ = "$Id: Format.py,v 1.19 2004/11/30 04:49:21 jemfinch Exp $" -__author__ = supybot.authors.jemfinch - -import supybot.plugins as plugins - import string import supybot.conf as conf @@ -42,7 +35,6 @@ from supybot.commands import * import supybot.ircutils as ircutils import supybot.callbacks as callbacks - def configure(advanced): # This will be called by setup.py to configure this module. Advanced is # a bool that specifies whether the user identified himself as an advanced @@ -51,7 +43,6 @@ def configure(advanced): from supybot.questions import expect, anything, something, yn conf.registerPlugin('Format', True) - class Format(callbacks.Privmsg): def bold(self, irc, msg, args, text): """ diff --git a/plugins/Herald/plugin.py b/plugins/Herald/plugin.py index 10165c491..c89aa29e7 100644 --- a/plugins/Herald/plugin.py +++ b/plugins/Herald/plugin.py @@ -29,7 +29,6 @@ import os import time -import getopt import supybot.log as log import supybot.conf as conf @@ -40,7 +39,6 @@ from supybot.commands import * import supybot.ircmsgs as ircmsgs import supybot.plugins as plugins import supybot.ircutils as ircutils -import supybot.registry as registry import supybot.callbacks as callbacks filename = conf.supybot.directories.data.dirize('Herald.db') diff --git a/plugins/Misc/plugin.py b/plugins/Misc/plugin.py index c281ffd3e..3609c086f 100644 --- a/plugins/Misc/plugin.py +++ b/plugins/Misc/plugin.py @@ -31,10 +31,8 @@ import os import sys import time -import supybot.log as log import supybot.conf as conf import supybot.utils as utils -import supybot.world as world from supybot.commands import * import supybot.ircdb as ircdb import supybot.irclib as irclib @@ -70,8 +68,8 @@ class Misc(callbacks.Privmsg): 'invalid command flood.', banmask, punishment) if tokens and tokens[0] == 'Error:': self.log.warning('Apparent error loop with another Supybot ' - 'observed at %s. Consider ignoring this bot ' - 'permanently.', log.timestamp()) + 'observed. Consider ignoring this bot ' + 'permanently.') ircdb.ignores.add(banmask, time.time() + punishment) irc.reply('You\'ve given me %s invalid commands within the last ' 'minute; I\'m now ignoring you for %s.' % diff --git a/plugins/Owner/plugin.py b/plugins/Owner/plugin.py index ce70f527b..7d6d42329 100644 --- a/plugins/Owner/plugin.py +++ b/plugins/Owner/plugin.py @@ -29,7 +29,6 @@ import gc import os -import imp import sre import sys import socket @@ -48,7 +47,6 @@ import supybot.ircmsgs as ircmsgs import supybot.ircutils as ircutils import supybot.registry as registry import supybot.callbacks as callbacks -import supybot.structures as structures ### # supybot.commands. @@ -365,33 +363,32 @@ class Owner(callbacks.Privmsg): """ L = [] if level == 'high': - L.append('Regexp cache flushed: %s cleared.' % - utils.nItems('regexp', len(sre._cache))) + L.append(format('Regexp cache flushed: %n cleared.', + (len(sre._cache), 'regexp'))) sre.purge() - L.append('Pattern cache flushed: %s cleared.' % - utils.nItems('compiled pattern', - len(ircutils._patternCache))) + L.append(format('Pattern cache flushed: %n cleared.', + (len(ircutils._patternCache), 'compiled pattern'))) ircutils._patternCache.clear() - L.append('hostmaskPatternEqual cache flushed: %s cleared.' % - utils.nItems('result', - len(ircutils._hostmaskPatternEqualCache))) + L.append(format('hostmaskPatternEqual cache flushed: %n cleared.', + (len(ircutils._hostmaskPatternEqualCache), + 'result'))) ircutils._hostmaskPatternEqualCache.clear() - L.append('ircdb username cache flushed: %s cleared.' % - utils.nItems('username to id mapping', - len(ircdb.users._nameCache))) + L.append(format('ircdb username cache flushed: %n cleared.', + (len(ircdb.users._nameCache), + 'username to id mapping'))) ircdb.users._nameCache.clear() - L.append('ircdb hostmask cache flushed: %s cleared.' % - utils.nItems('hostmask to id mapping', - len(ircdb.users._hostmaskCache))) + L.append(format('ircdb hostmask cache flushed: %n cleared.', + (len(ircdb.users._hostmaskCache), + 'hostmask to id mapping'))) ircdb.users._hostmaskCache.clear() - L.append('linecache line cache flushed: %s cleared.' % - utils.nItems('line', len(linecache.cache))) + L.append(format('linecache line cache flushed: %s cleared.', + (len(linecache.cache, 'line')))) linecache.clearcache() sys.exc_clear() collected = world.upkeep() if gc.garbage: L.append('Garbage! %r.' % gc.garbage) - L.append('%s collected.' % utils.nItems('object', collected)) + L.append(format('%n collected.', (collected, 'object'))) irc.reply(' '.join(L)) upkeep = wrap(upkeep, [additional(('literal', ['high']))]) diff --git a/plugins/Owner/test.py b/plugins/Owner/test.py index 6911d2d21..8ad0a760c 100644 --- a/plugins/Owner/test.py +++ b/plugins/Owner/test.py @@ -66,7 +66,7 @@ class OwnerTestCase(PluginTestCase): self.assertNotError('load Channel') self.assertNotError('unload Channel') self.assertError('unload Channel') - self.assertNotError('load CHANNEL') + self.assertNotError('load Channel') self.assertNotError('unload CHANNEL') def testDisable(self): diff --git a/plugins/Status/plugin.py b/plugins/Status/plugin.py index b1d3c0cb2..2bd29705f 100644 --- a/plugins/Status/plugin.py +++ b/plugins/Status/plugin.py @@ -27,27 +27,22 @@ # POSSIBILITY OF SUCH DAMAGE. ### -import supybot.plugins as plugins - import os import sys -import sets import time -import os.path import threading -from itertools import islice, ifilter, imap import supybot.conf as conf import supybot.utils as utils import supybot.world as world from supybot.commands import * -import supybot.registry as registry import supybot.callbacks as callbacks class Status(callbacks.Privmsg): def __init__(self, irc): self.__parent = super(Status, self) self.__parent.__init__(irc) + # XXX It'd be nice if these could be kept in the registry. self.sentMsgs = 0 self.recvdMsgs = 0 self.sentBytes = 0 @@ -77,9 +72,8 @@ class Status(callbacks.Privmsg): networks.setdefault(Irc.network, []).append(Irc.nick) networks = networks.items() networks.sort() - networks = ['%s as %s' % (net, utils.str.commaAndify(nicks)) - for (net, nicks) in networks] - L = ['I am connected to %s.' % utils.str.commaAndify(networks)] + networks = [format('%s as %L', net, nicks) for (net,nicks) in networks] + L = [format('I am connected to %L.', networks)] if world.profiling: L.append('I am currently in code profiling mode.') irc.reply(' '.join(L)) @@ -92,11 +86,9 @@ class Status(callbacks.Privmsg): """ threads = [t.getName() for t in threading.enumerate()] threads.sort() - s = 'I have spawned %s; %s %s still currently active: %s.' % \ - (utils.str.nItems('thread', world.threadsSpawned), - utils.str.nItems('thread', len(threads)), - utils.str.be(len(threads)), - utils.str.commaAndify(threads)) + s = format('I have spawned %n; %n %b still currently active: %L.', + (world.threadsSpawned, 'thread'), + (len(threads), 'thread'), len(threads), threads) irc.reply(s) threads = wrap(threads) @@ -139,9 +131,9 @@ class Status(callbacks.Privmsg): 'of system time, for a total of %.2f seconds of CPU ' \ 'time. %s' % (user, system, user + system, children) if self.registryValue('cpu.threads', target): - spawned = utils.str.nItems('thread', world.threadsSpawned) - response += 'I have spawned %s; I currently have %s still ' \ - 'running.' % (spawned, activeThreads) + response += format('I have spawned %n; I currently have %i still ' + 'running.', + (world.threadsSpawned, 'thread'), activeThreads) if self.registryValue('cpu.memory', target): mem = 'an unknown amount' pid = os.getpid() @@ -179,10 +171,10 @@ class Status(callbacks.Privmsg): if cb.isCommand(attr) and \ attr == callbacks.canonicalName(attr): commands += 1 - s = 'I offer a total of %s in %s. I have processed %s.' % \ - (utils.str.nItems('command', commands), - utils.str.nItems('plugin', callbacksPrivmsg, 'command-based'), - utils.str.nItems('command', world.commandsProcessed)) + s = format('I offer a total of %n in %n. I have processed %n.', + (commands, 'command'), + (callbacksPrivmsg, 'command-based', 'plugin'), + (world.commandsProcessed, 'command')) irc.reply(s) cmd = wrap(cmd) @@ -191,7 +183,7 @@ class Status(callbacks.Privmsg): Returns a list of the commands offered by the bot. """ - commands = sets.Set() + commands = set() for cb in irc.callbacks: if isinstance(cb, callbacks.Privmsg) and \ not isinstance(cb, callbacks.PrivmsgRegexp) and cb.public: diff --git a/plugins/User/plugin.py b/plugins/User/plugin.py index 3253a48eb..279b1a03a 100644 --- a/plugins/User/plugin.py +++ b/plugins/User/plugin.py @@ -39,7 +39,7 @@ import supybot.callbacks as callbacks class User(callbacks.Privmsg): def _checkNotChannel(self, irc, msg, password=' '): - if password and ircutils.isChannel(msg.args[0]): + if password and irc.isChannel(msg.args[0]): raise callbacks.Error, conf.supybot.replies.requiresPrivacy() def list(self, irc, msg, args, optlist, glob): @@ -411,11 +411,11 @@ class User(callbacks.Privmsg): admins += 1 except KeyError: pass - irc.reply('I have %s registered users ' - 'with %s registered hostmasks; ' - '%s and %s.' % (users, hostmasks, - utils.str.nItems('owner', owners), - utils.str.nItems('admin', admins))) + irc.reply(format('I have %s registered users ' + 'with %s registered hostmasks; ' + '%n and %n.', + users, hostmasks, + (owners, 'owner'), (admins, 'admin'))) stats = wrap(stats) diff --git a/plugins/Utilities/plugin.py b/plugins/Utilities/plugin.py index 41dcaaee8..d6bfad8cf 100644 --- a/plugins/Utilities/plugin.py +++ b/plugins/Utilities/plugin.py @@ -29,11 +29,8 @@ import types import random -import string -import supybot.utils as utils from supybot.commands import * -import supybot.ircmsgs as ircmsgs import supybot.ircutils as ircutils import supybot.callbacks as callbacks