Fixed a performance problem.

This commit is contained in:
Jeremy Fincher 2004-09-22 13:13:37 +00:00
parent 7558a437e1
commit 99e35d6810
2 changed files with 26 additions and 16 deletions

View File

@ -40,6 +40,7 @@ import re
import string import string
import random import random
import itertools import itertools
from cStringIO import StringIO
import supybot.conf as conf import supybot.conf as conf
import supybot.utils as utils import supybot.utils as utils
@ -510,6 +511,8 @@ class Filter(callbacks.Privmsg):
'arr', 's': 'ess', 't': 'tee', 'u': 'you', 'v': 'vee', 'w': 'arr', 's': 'ess', 't': 'tee', 'u': 'you', 'v': 'vee', 'w':
'double-you', 'x': 'ecks', 'y': 'why', 'z': 'zee' 'double-you', 'x': 'ecks', 'y': 'why', 'z': 'zee'
} }
for (k, v) in _spellLetters.items():
_spellLetters[k.upper()] = v
_spellPunctuation = { _spellPunctuation = {
'!': 'exclamation point', '!': 'exclamation point',
'"': 'quote', '"': 'quote',
@ -554,21 +557,28 @@ class Filter(callbacks.Privmsg):
Returns <text>, phonetically spelled out. Returns <text>, phonetically spelled out.
""" """
text = privmsgs.getArgs(args) text = privmsgs.getArgs(args)
replaceLetters = self.registryValue('spellit.replaceLetters') d = {}
replacePunctuation = self.registryValue('spellit.replacePunctuation') if self.registryValue('spellit.replaceLetters'):
replaceNumbers = self.registryValue('spellit.replaceNumbers') d.update(self._spellLetters)
newtext = '' if self.registryValue('spellit.replaceNumbers'):
d.update(self._spellNumbers)
if self.registryValue('spellit.replacePunctuation'):
d.update(self._spellPunctuation)
# A bug in unicode on OSX prevents me from testing this.
## dd = {}
## for (c, v) in d.iteritems():
## dd[ord(c)] = unicode(v + ' ')
## irc.reply(unicode(text).translate(dd))
out = StringIO()
write = out.write
for c in text: for c in text:
if self._spellLetters.has_key(c.lower()) and replaceLetters: try:
newtext += '%s ' % self._spellLetters[c.lower()] c = d[c]
elif self._spellPunctuation.has_key(c) and replacePunctuation: write(' ')
newtext += '%s ' % self._spellPunctuation[c] except KeyError:
elif self._spellNumbers.has_key(c) and replaceNumbers: pass
newtext += '%s ' % self._spellNumbers[c] write(c)
else: irc.reply(out.getvalue())
newtext += '%s' % c
irc.reply(newtext)
Class = Filter Class = Filter