diff --git a/plugins/Babelfish/plugin.py b/plugins/Babelfish/plugin.py index e907cb35c..911ecbdd1 100644 --- a/plugins/Babelfish/plugin.py +++ b/plugins/Babelfish/plugin.py @@ -27,8 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. ### -import random - import babelfish import supybot.conf as conf @@ -152,9 +150,9 @@ class Babelfish(callbacks.Privmsg): languages = self.registryValue('languages', msg.args[0]) if not languages: irc.error('I can\'t speak any other languages.', Raise=True) - language = random.choice(languages) + language = utils.iter.choice(languages) while not allowEnglish and language == 'English': - language = random.choice(languages) + language = utils.iter.choice(languages) irc.reply(language) randomlanguage = wrap(randomlanguage, [getopts({'allow-english': ''})]) diff --git a/plugins/Config/plugin.py b/plugins/Config/plugin.py index bb68ff50f..d08ada03a 100644 --- a/plugins/Config/plugin.py +++ b/plugins/Config/plugin.py @@ -36,6 +36,7 @@ import supybot.utils as utils import supybot.world as world import supybot.ircdb as ircdb from supybot.commands import * +from supybot.utils.iter import all import supybot.ircutils as ircutils import supybot.registry as registry import supybot.callbacks as callbacks diff --git a/plugins/Dict/plugin.py b/plugins/Dict/plugin.py index 8740ebabe..b777c5fcd 100644 --- a/plugins/Dict/plugin.py +++ b/plugins/Dict/plugin.py @@ -27,7 +27,6 @@ # POSSIBILITY OF SUCH DAMAGE. ### -import random import socket import dictclient @@ -64,7 +63,7 @@ class Dict(callbacks.Privmsg): server = conf.supybot.plugins.Dict.server() conn = dictclient.Connection(server) dbs = conn.getdbdescs().keys() - irc.reply(random.choice(dbs)) + irc.reply(utils.iter.choice(dbs)) except socket.error, e: irc.error(utils.web.strError(e)) random = wrap(random) diff --git a/plugins/Filter/plugin.py b/plugins/Filter/plugin.py index 5aaf24eaa..eb9ddb033 100644 --- a/plugins/Filter/plugin.py +++ b/plugins/Filter/plugin.py @@ -407,7 +407,7 @@ class Filter(callbacks.Privmsg): text = text.replace(',', ' ') text = text.replace("'", '') text = text.replace('one', '1') - smiley = random.choice(['<3', ':)', ':-)', ':D', ':-D']) + smiley = utils.iter.choice(['<3', ':)', ':-)', ':D', ':-D']) text += smiley*3 irc.reply(text) aol = wrap(aol, ['text']) @@ -418,7 +418,7 @@ class Filter(callbacks.Privmsg): Returns as if JeffK had said it himself. """ def randomlyPick(L): - return random.choice(L) + return utils.iter.choice(L) def quoteOrNothing(m): return randomlyPick(['"', '']).join(m.groups()) def randomlyReplace(s, probability=0.5): @@ -445,23 +445,22 @@ class Filter(callbacks.Privmsg): def randomlyLaugh(text, probability=.3): if random.random() < probability: if random.random() < .5: - insult = random.choice([' fagot1', ' fagorts', ' jerks', - 'fagot' ' jerk', ' dumbshoes', - ' dumbshoe']) + insult = utils.iter.choice([' fagot1', ' fagorts', + ' jerks', 'fagot' ' jerk', + 'dumbshoes', ' dumbshoe']) else: insult = '' - laugh1 = random.choice(['ha', 'hah', 'lol', 'l0l', 'ahh']) - laugh2 = random.choice(['ha', 'hah', 'lol', 'l0l', 'ahh']) + laugh1 = utils.iter.choice(['ha', 'hah', 'lol', 'l0l', 'ahh']) + laugh2 = utils.iter.choice(['ha', 'hah', 'lol', 'l0l', 'ahh']) laugh1 = laugh1 * random.randrange(1, 5) laugh2 = laugh2 * random.randrange(1, 5) - exclaim = random.choice(['!', '~', '!~', '~!!~~', - '!!~', '~~~!']) - exclaim += random.choice(['!', '~', '!~', '~!!~~', - '!!~', '~~~!']) - if random.random() < 0.5: - exclaim += random.choice(['!', '~', '!~', '~!!~~', - + exclaim = utils.iter.choice(['!', '~', '!~', '~!!~~', + '!!~', '~~~!']) + exclaim += utils.iter.choice(['!', '~', '!~', '~!!~~', '!!~', '~~~!']) + if random.random() < 0.5: + exclaim += utils.iter.choice(['!', '~', '!~', '~!!~~', + '!!~', '~~~!']) laugh = ''.join([' ', laugh1, laugh2, insult, exclaim]) text += laugh return text diff --git a/scripts/supybot-wizard b/scripts/supybot-wizard index 25d270b9a..01d82916a 100644 --- a/scripts/supybot-wizard +++ b/scripts/supybot-wizard @@ -51,9 +51,9 @@ import pprint import socket import logging import optparse -from itertools import imap import supybot.ansi as ansi +from utils.iter import imap import supybot.utils as utils import supybot.ircutils as ircutils import supybot.registry as registry diff --git a/src/callbacks.py b/src/callbacks.py index e93111bcf..77438ea61 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -48,7 +48,6 @@ import string import inspect import operator from cStringIO import StringIO -from itertools import imap, ifilter import supybot.log as log import supybot.conf as conf @@ -59,6 +58,7 @@ import supybot.irclib as irclib import supybot.ircmsgs as ircmsgs import supybot.ircutils as ircutils import supybot.registry as registry +from supybot.utils.iter import any, imap, ifilter def _addressed(nick, msg, prefixChars=None, nicks=None, prefixStrings=None, whenAddressedByNick=None, diff --git a/src/dbi.py b/src/dbi.py index 75fa96723..25106cc2b 100644 --- a/src/dbi.py +++ b/src/dbi.py @@ -364,7 +364,7 @@ class DB(object): def random(self): try: - return self._newRecord(*random.choice(self.map)) + return self._newRecord(*utils.iter.choice(self.map)) except IndexError: return None diff --git a/src/drivers/Socket.py b/src/drivers/Socket.py index 90f97b3b3..214af2783 100644 --- a/src/drivers/Socket.py +++ b/src/drivers/Socket.py @@ -38,7 +38,6 @@ from __future__ import division import time import select import socket -from itertools import imap import supybot.log as log import supybot.conf as conf @@ -46,6 +45,7 @@ import supybot.utils as utils import supybot.world as world import supybot.drivers as drivers import supybot.schedule as schedule +from supybot.utils.iter import imap # XXX Shouldn't the reconnect wait (at least the last one) be configurable? reconnectWaits = [0, 60, 300] diff --git a/src/drivers/__init__.py b/src/drivers/__init__.py index ecb0fea21..fda9b61c9 100644 --- a/src/drivers/__init__.py +++ b/src/drivers/__init__.py @@ -72,9 +72,9 @@ class ServersMixin(object): self.networkGroup = conf.supybot.networks.get(irc.network) self.servers = servers super(ServersMixin, self).__init__(irc) - + def _getServers(self): - # We do this, rather than itertools.cycle the servers in __init__, + # We do this, rather than utils.iter.cycle the servers in __init__, # because otherwise registry updates given as setValues or sets # wouldn't be visible until a restart. return self.networkGroup.servers()[:] # Be sure to copy! @@ -87,7 +87,7 @@ class ServersMixin(object): server = self.servers.pop(0) self.currentServer = '%s:%s' % server return server - + def empty(): """Returns whether or not the driver loop is empty.""" @@ -178,7 +178,7 @@ class Log(object): stat = staticmethod(supylog.stat) log = Log() - + def newDriver(irc, moduleName=None): """Returns a new driver for the given server using the irc given and using conf.supybot.driverModule to determine what driver to pick.""" diff --git a/src/irclib.py b/src/irclib.py index d9e1bb877..835b70cbb 100644 --- a/src/irclib.py +++ b/src/irclib.py @@ -856,7 +856,7 @@ class Irc(IrcCommandDispatcher): while len(L) <= 3: L.append('`') while ircutils.strEqual(ret, nick): - L[random.randrange(len(L))] = random.choice('0123456789') + L[random.randrange(len(L))] = utils.iter.choice('0123456789') ret = ''.join(L) return ret diff --git a/src/ircutils.py b/src/ircutils.py index 5f43cc40c..cd0b0e921 100644 --- a/src/ircutils.py +++ b/src/ircutils.py @@ -625,7 +625,7 @@ def standardSubstitute(irc, msg, text, env=None): if len(L) > 1: n = msg.nick while n == msg.nick: - n = random.choice(L) + n = utils.iter.choice(L) return n else: return msg.nick diff --git a/src/structures.py b/src/structures.py index 13cee87d4..67ad8f9a4 100644 --- a/src/structures.py +++ b/src/structures.py @@ -314,7 +314,7 @@ class TimeoutQueue(object): return self.timeout() else: return self.timeout - + def _clearOldElements(self): now = time.time() while now - self.queue.peek()[0] > self._getTimeout(): @@ -341,7 +341,7 @@ class TimeoutQueue(object): yield elt def __len__(self): - # No dependency on utils. + # No dependency on utils.iter # return ilen(self) i = 0 for _ in self: @@ -413,7 +413,7 @@ class MultiSet(object): def __contains__(self, elt): return elt in self.d - + # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: diff --git a/test/test_standardSubstitute.py b/test/test_standardSubstitute.py index 70f04cece..864937f80 100644 --- a/test/test_standardSubstitute.py +++ b/test/test_standardSubstitute.py @@ -32,6 +32,7 @@ from supybot.test import * import sets import supybot.irclib as irclib +from supybot.utils.iter import all import supybot.ircutils as ircutils class holder: