Update usage of utils.iter functions.

This commit is contained in:
James Vega 2005-01-31 15:22:48 +00:00
parent 4d32d36982
commit 0fde2393e6
13 changed files with 31 additions and 33 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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