Plugin normalization, sanitation, etc. Removed unused imports, for the most part.

This commit is contained in:
Jeremy Fincher 2005-01-29 21:24:17 +00:00
parent 70da904be2
commit 68b1d65d68
13 changed files with 42 additions and 79 deletions

View File

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

View File

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

View File

@ -28,7 +28,6 @@
###
import sys
import time
import supybot.conf as conf
import supybot.ircdb as ircdb

View File

@ -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.' %

View File

@ -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 <text> 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'])

View File

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

View File

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

View File

@ -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.' %

View File

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

View File

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

View File

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

View File

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

View File

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