Merge branch 'testing'

This commit is contained in:
Valentin Lorentz 2011-02-14 18:22:18 +01:00
commit 9f5b3f635a
21 changed files with 203 additions and 58 deletions

View File

@ -50,11 +50,8 @@ class AutoMode(callbacks.Plugin):
return return
fallthrough = self.registryValue('fallthrough', channel) fallthrough = self.registryValue('fallthrough', channel)
def do(type): def do(type):
if ircdb.checkCapability(msg.prefix, 'owner') and not \
self.registryValue('owner'):
raise Continue
cap = ircdb.makeChannelCapability(channel, type) cap = ircdb.makeChannelCapability(channel, type)
if ircdb.checkCapability(msg.prefix, cap): if ircdb.checkCapability(msg.prefix, cap, ignoreOwner=True):
if self.registryValue(type, channel): if self.registryValue(type, channel):
self.log.info('Sending auto-%s of %s in %s.', self.log.info('Sending auto-%s of %s in %s.',
type, msg.prefix, channel) type, msg.prefix, channel)

View File

@ -57,7 +57,9 @@ conf.registerGlobalValue(BadWords,'requireWordBoundaries',
words to be independent words, or whether it will censor them within other words to be independent words, or whether it will censor them within other
words. For instance, if 'darn' is a bad word, then if this is true, 'darn' words. For instance, if 'darn' is a bad word, then if this is true, 'darn'
will be censored, but 'darnit' will not. You probably want this to be will be censored, but 'darnit' will not. You probably want this to be
false."""))) false. After changing this setting, the BadWords regexp needs to be
regenerated by adding/removing a word to the list, or reloading the
plugin.""")))
class String256(registry.String): class String256(registry.String):
def __call__(self): def __call__(self):

View File

@ -1,7 +1,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Supybot-fr\n" "Project-Id-Version: Supybot-fr\n"
"POT-Creation-Date: 2010-10-16 18:51+CEST\n" "POT-Creation-Date: 2011-01-29 11:48+CET\n"
"PO-Revision-Date: \n" "PO-Revision-Date: \n"
"Last-Translator: Valentin Lorentz <progval@gmail.com>\n" "Last-Translator: Valentin Lorentz <progval@gmail.com>\n"
"Language-Team: Supybot-fr <progval@gmail.com>\n" "Language-Team: Supybot-fr <progval@gmail.com>\n"
@ -13,6 +13,13 @@ msgstr ""
"X-Poedit-Country: France\n" "X-Poedit-Country: France\n"
"X-Poedit-SourceCharset: ASCII\n" "X-Poedit-SourceCharset: ASCII\n"
#: __init__.py:30
msgid ""
"\n"
"Filters bad words on outgoing messages from the bot, so the bot can't be made\n"
"to say bad words.\n"
msgstr ""
#: config.py:40 #: config.py:40
msgid "Would you like to add some bad words?" msgid "Would you like to add some bad words?"
msgstr "Voulez-vous ajouter quelques mots interdits ?" msgstr "Voulez-vous ajouter quelques mots interdits ?"
@ -33,17 +40,19 @@ msgid ""
" words to be independent words, or whether it will censor them within other\n" " words to be independent words, or whether it will censor them within other\n"
" words. For instance, if 'darn' is a bad word, then if this is true, 'darn'\n" " words. For instance, if 'darn' is a bad word, then if this is true, 'darn'\n"
" will be censored, but 'darnit' will not. You probably want this to be\n" " will be censored, but 'darnit' will not. You probably want this to be\n"
" false." " false. After changing this setting, the BadWords regexp needs to be\n"
msgstr "Détermine si le bot requiert que les gros mots soient indépendants, ou si ils peuvent être dans d'autres mots. Par exemple, si 'pute' est censuré et que c'est True, 'merde' sera censuré, mais pas 'emmerder'. Il est probablement mieux que ceci soit False." " regenerated by adding/removing a word to the list, or reloading the\n"
" plugin."
msgstr "Détermine si le bot requiert que les gros mots soient indépendants, ou si ils peuvent être dans d'autres mots. Par exemple, si 'merde' est censuré et que c'est True, 'merde' sera censuré, mais pas 'emmerder'. Il est probablement mieux que ceci soit False. Après avoir modifié ce paramètre, l'expression régulière de BadWords doit être regénérée en ajoutant/supprimant un mot de la liste, ou en rechargeant le plugin."
#: config.py:71 #: config.py:73
msgid "" msgid ""
"Determines what characters will replace bad words; a\n" "Determines what characters will replace bad words; a\n"
" chunk of these characters matching the size of the replaced bad word will\n" " chunk of these characters matching the size of the replaced bad word will\n"
" be used to replace the bad words you've configured." " be used to replace the bad words you've configured."
msgstr "Détermine par quels caractères seront remplacés les gros mots ; un morceau de ces caractères ayant la même taille que le mot remplacé sera utilisé pour remplacer les gros mots que vous avez configurés." msgstr "Détermine par quels caractères seront remplacés les gros mots ; un morceau de ces caractères ayant la même taille que le mot remplacé sera utilisé pour remplacer les gros mots que vous avez configurés."
#: config.py:79 #: config.py:81
msgid "" msgid ""
"Determines the manner in which\n" "Determines the manner in which\n"
" bad words will be replaced. 'nastyCharacters' (the default) will replace a\n" " bad words will be replaced. 'nastyCharacters' (the default) will replace a\n"
@ -54,13 +63,13 @@ msgid ""
" supybot.plugins.BadWords.simpleReplacement." " supybot.plugins.BadWords.simpleReplacement."
msgstr "Détermine la manière dont les gros mots sont remplacés. 'nastyCharacters' (par défaut) remplacera un gros mot par le même nombre de 'caractères obscènes' (comme ceux utilisés dans les bandes dessinées ; configurables dans supybot.plugins.BadWords.nastyChars). 'simple' remplacera le mot pas une simple chaîne (peu importe la taille du gros mot) ; cette chaîne est configurable dans supybot.plugins.BadWords.simpleReplacement." msgstr "Détermine la manière dont les gros mots sont remplacés. 'nastyCharacters' (par défaut) remplacera un gros mot par le même nombre de 'caractères obscènes' (comme ceux utilisés dans les bandes dessinées ; configurables dans supybot.plugins.BadWords.nastyChars). 'simple' remplacera le mot pas une simple chaîne (peu importe la taille du gros mot) ; cette chaîne est configurable dans supybot.plugins.BadWords.simpleReplacement."
#: config.py:87 #: config.py:89
msgid "" msgid ""
"Determines what word will replace bad\n" "Determines what word will replace bad\n"
" words if the replacement method is 'simple'." " words if the replacement method is 'simple'."
msgstr "Détermin quel mot remplacera les mots interdits, si la méthode de remplacement est 'simple'." msgstr "Détermin quel mot remplacera les mots interdits, si la méthode de remplacement est 'simple'."
#: config.py:90 #: config.py:92
msgid "" msgid ""
"Determines whether the bot will strip\n" "Determines whether the bot will strip\n"
" formatting characters from messages before it checks them for bad words.\n" " formatting characters from messages before it checks them for bad words.\n"
@ -69,13 +78,33 @@ msgid ""
" plugins that do coloring or bolding of text." " plugins that do coloring or bolding of text."
msgstr "Détermine si le bot retirera les caractères de formattage avant de vérifier qu'ils contiennent des gros mots. Si ceci est False, ce sera relativement simple de contourner la protection. Si c'est True, toutefois, il fera perdre toute couleur ou formattage des autres plugins" msgstr "Détermine si le bot retirera les caractères de formattage avant de vérifier qu'ils contiennent des gros mots. Si ceci est False, ce sera relativement simple de contourner la protection. Si c'est True, toutefois, il fera perdre toute couleur ou formattage des autres plugins"
#: config.py:97 #: config.py:99
msgid "" msgid ""
"Determines whether the bot will kick people with\n" "Determines whether the bot will kick people with\n"
" a warning when they use bad words." " a warning when they use bad words."
msgstr "Détermine si le bot kickera les gens avec un avertissement lorsqu'ils utilisent des gros mots." msgstr "Détermine si le bot kickera les gens avec un avertissement lorsqu'ils utilisent des gros mots."
#: plugin.py:110 #: config.py:102
msgid ""
"You have been kicked for using a word\n"
" prohibited in the presence of this bot. Please use more appropriate\n"
" language in the future."
msgstr "Vous avez été kické(e) parce que vous avez utilisé un mot interdit en la présence de ce bot. Veuillez utiliser un langage plus approprié par le futur."
#: config.py:104
msgid ""
"Determines the kick message used by the\n"
" bot when kicking users for saying bad words."
msgstr "Détermine le message de kick utilisé par le bot lorsqu'il kick des utilisateurs utilisant des gros mots."
#: plugin.py:46
msgid ""
"Maintains a list of words that the bot is not allowed to say.\n"
" Can also be used to kick people that say these words, if the bot\n"
" has op."
msgstr ""
#: plugin.py:113
msgid "" msgid ""
"takes no arguments\n" "takes no arguments\n"
"\n" "\n"
@ -86,26 +115,26 @@ msgstr ""
"\n" "\n"
"Retourne une liste de mots qui sont censurés." "Retourne une liste de mots qui sont censurés."
#: plugin.py:120 #: plugin.py:123
msgid "I'm not currently censoring any bad words." msgid "I'm not currently censoring any bad words."
msgstr "Je ne censure actuellement aucun mot." msgstr "Je ne censure actuellement aucun mot."
#: plugin.py:125 #: plugin.py:128
msgid "" msgid ""
"<word> [<word> ...]\n" "<word> [<word> ...]\n"
"\n" "\n"
" Adds all <word>s to the list of words the bot isn't to say.\n" " Adds all <word>s to the list of words being censored.\n"
" " " "
msgstr "" msgstr ""
"<mot> [<mot> ...]\n" "<mot> [<mot> ...]\n"
"\n" "\n"
"Ajoute tous les mots à la liste des mots que le bot ne doit pas dire." "Ajoute tous les mots à la liste des mots que le bot ne doit pas dire."
#: plugin.py:137 #: plugin.py:140
msgid "" msgid ""
"<word> [<word> ...]\n" "<word> [<word> ...]\n"
"\n" "\n"
" Removes a <word>s from the list of words the bot isn't to say.\n" " Removes <word>s from the list of words being censored.\n"
" " " "
msgstr "" msgstr ""
"<mot> [<mot> ...]\n" "<mot> [<mot> ...]\n"

View File

@ -5,7 +5,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2010-10-16 18:51+CEST\n" "POT-Creation-Date: 2011-01-29 11:48+CET\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -15,6 +15,14 @@ msgstr ""
"Generated-By: pygettext.py 1.5\n" "Generated-By: pygettext.py 1.5\n"
#: __init__.py:30
#, docstring
msgid ""
"\n"
"Filters bad words on outgoing messages from the bot, so the bot can't be made\n"
"to say bad words.\n"
msgstr ""
#: config.py:40 #: config.py:40
msgid "Would you like to add some bad words?" msgid "Would you like to add some bad words?"
msgstr "" msgstr ""
@ -35,17 +43,19 @@ msgid ""
" words to be independent words, or whether it will censor them within other\n" " words to be independent words, or whether it will censor them within other\n"
" words. For instance, if 'darn' is a bad word, then if this is true, 'darn'\n" " words. For instance, if 'darn' is a bad word, then if this is true, 'darn'\n"
" will be censored, but 'darnit' will not. You probably want this to be\n" " will be censored, but 'darnit' will not. You probably want this to be\n"
" false." " false. After changing this setting, the BadWords regexp needs to be\n"
" regenerated by adding/removing a word to the list, or reloading the\n"
" plugin."
msgstr "" msgstr ""
#: config.py:71 #: config.py:73
msgid "" msgid ""
"Determines what characters will replace bad words; a\n" "Determines what characters will replace bad words; a\n"
" chunk of these characters matching the size of the replaced bad word will\n" " chunk of these characters matching the size of the replaced bad word will\n"
" be used to replace the bad words you've configured." " be used to replace the bad words you've configured."
msgstr "" msgstr ""
#: config.py:79 #: config.py:81
msgid "" msgid ""
"Determines the manner in which\n" "Determines the manner in which\n"
" bad words will be replaced. 'nastyCharacters' (the default) will replace a\n" " bad words will be replaced. 'nastyCharacters' (the default) will replace a\n"
@ -56,13 +66,13 @@ msgid ""
" supybot.plugins.BadWords.simpleReplacement." " supybot.plugins.BadWords.simpleReplacement."
msgstr "" msgstr ""
#: config.py:87 #: config.py:89
msgid "" msgid ""
"Determines what word will replace bad\n" "Determines what word will replace bad\n"
" words if the replacement method is 'simple'." " words if the replacement method is 'simple'."
msgstr "" msgstr ""
#: config.py:90 #: config.py:92
msgid "" msgid ""
"Determines whether the bot will strip\n" "Determines whether the bot will strip\n"
" formatting characters from messages before it checks them for bad words.\n" " formatting characters from messages before it checks them for bad words.\n"
@ -71,13 +81,34 @@ msgid ""
" plugins that do coloring or bolding of text." " plugins that do coloring or bolding of text."
msgstr "" msgstr ""
#: config.py:97 #: config.py:99
msgid "" msgid ""
"Determines whether the bot will kick people with\n" "Determines whether the bot will kick people with\n"
" a warning when they use bad words." " a warning when they use bad words."
msgstr "" msgstr ""
#: plugin.py:110 #: config.py:102
msgid ""
"You have been kicked for using a word\n"
" prohibited in the presence of this bot. Please use more appropriate\n"
" language in the future."
msgstr ""
#: config.py:104
msgid ""
"Determines the kick message used by the\n"
" bot when kicking users for saying bad words."
msgstr ""
#: plugin.py:46
#, docstring
msgid ""
"Maintains a list of words that the bot is not allowed to say.\n"
" Can also be used to kick people that say these words, if the bot\n"
" has op."
msgstr ""
#: plugin.py:113
#, docstring #, docstring
msgid "" msgid ""
"takes no arguments\n" "takes no arguments\n"
@ -86,25 +117,25 @@ msgid ""
" " " "
msgstr "" msgstr ""
#: plugin.py:120 #: plugin.py:123
msgid "I'm not currently censoring any bad words." msgid "I'm not currently censoring any bad words."
msgstr "" msgstr ""
#: plugin.py:125 #: plugin.py:128
#, docstring #, docstring
msgid "" msgid ""
"<word> [<word> ...]\n" "<word> [<word> ...]\n"
"\n" "\n"
" Adds all <word>s to the list of words the bot isn't to say.\n" " Adds all <word>s to the list of words being censored.\n"
" " " "
msgstr "" msgstr ""
#: plugin.py:137 #: plugin.py:140
#, docstring #, docstring
msgid "" msgid ""
"<word> [<word> ...]\n" "<word> [<word> ...]\n"
"\n" "\n"
" Removes a <word>s from the list of words the bot isn't to say.\n" " Removes <word>s from the list of words being censored.\n"
" " " "
msgstr "" msgstr ""

View File

@ -43,6 +43,9 @@ from supybot.i18n import PluginInternationalization, internationalizeDocstring
_ = PluginInternationalization('BadWords') _ = PluginInternationalization('BadWords')
class BadWords(callbacks.Privmsg): class BadWords(callbacks.Privmsg):
"""Maintains a list of words that the bot is not allowed to say.
Can also be used to kick people that say these words, if the bot
has op."""
def __init__(self, irc): def __init__(self, irc):
self.__parent = super(BadWords, self) self.__parent = super(BadWords, self)
self.__parent.__init__(irc) self.__parent.__init__(irc)
@ -68,7 +71,7 @@ class BadWords(callbacks.Privmsg):
def inFilter(self, irc, msg): def inFilter(self, irc, msg):
self.filtering = True self.filtering = True
# We need to check for bad words here rather than in doPrivmsg because # We need to check for bad words here rather than in doPrivmsg because
# messages don't get to doPrivmsg is the user is ignored. # messages don't get to doPrivmsg if the user is ignored.
if msg.command == 'PRIVMSG': if msg.command == 'PRIVMSG':
self.updateRegexp() self.updateRegexp()
s = ircutils.stripFormatting(msg.args[1]) s = ircutils.stripFormatting(msg.args[1])
@ -124,7 +127,7 @@ class BadWords(callbacks.Privmsg):
def add(self, irc, msg, args, words): def add(self, irc, msg, args, words):
"""<word> [<word> ...] """<word> [<word> ...]
Adds all <word>s to the list of words the bot isn't to say. Adds all <word>s to the list of words being censored.
""" """
set = self.words() set = self.words()
set.update(words) set.update(words)
@ -136,7 +139,7 @@ class BadWords(callbacks.Privmsg):
def remove(self, irc, msg, args, words): def remove(self, irc, msg, args, words):
"""<word> [<word> ...] """<word> [<word> ...]
Removes a <word>s from the list of words the bot isn't to say. Removes <word>s from the list of words being censored.
""" """
set = self.words() set = self.words()
for word in words: for word in words:

View File

@ -34,7 +34,7 @@ msgid ""
msgstr "" msgstr ""
"<groupe>\n" "<groupe>\n"
"\n" "\n"
"Retourne les variables de configuration qui sont dans le <groupe> de configuration. Si la variable a des sous-variables, elle sera précédée par le signe '@'. Si une variable est une 'ChannelValue', elle sera précédée par le signe '#'. Plus d'informations : http://supybot-fr.tk/Configuration" "Retourne les variables de configuration qui sont dans le <groupe> de configuration. Si la variable a des sous-variables, elle sera précédée par le signe '@'. Si une variable est une 'ChannelValue', elle sera précédée par le signe '#'. Plus d'informations : http://supybot.fr.cr/Configuration"
#: plugin.py:148 #: plugin.py:148
msgid "There don't seem to be any values in %s." msgid "There don't seem to be any values in %s."

View File

@ -391,7 +391,7 @@ class Filter(callbacks.Plugin):
Returns <text> colorized like a rainbow. Returns <text> colorized like a rainbow.
""" """
colors = utils.iter.cycle([4, 7, 8, 3, 2, 12, 6]) colors = utils.iter.cycle(['04', '07', '08', '03', '02', '12', '06'])
L = [self._color(c, fg=colors.next()) for c in text] L = [self._color(c, fg=colors.next()) for c in text]
irc.reply(''.join(L) + '\x03') irc.reply(''.join(L) + '\x03')
rainbow = wrap(rainbow, ['text']) rainbow = wrap(rainbow, ['text'])

View File

@ -302,7 +302,8 @@ class Google(callbacks.PluginRegexp):
url = r'http://google.com/search?q=' + s url = r'http://google.com/search?q=' + s
return url return url
_calcRe = re.compile(r'<h\d class="?r"?.*?<b>(.*?)</b>', re.I) _calcRe1 = re.compile(r'<table.*class="?obcontainer"?[^>]*>(.*?)</table>', re.I)
_calcRe2 = re.compile(r'<h\d class="?r"?.*?<b>(.*?)</b>', re.I)
_calcSupRe = re.compile(r'<sup>(.*?)</sup>', re.I) _calcSupRe = re.compile(r'<sup>(.*?)</sup>', re.I)
_calcFontRe = re.compile(r'<font size=-2>(.*?)</font>') _calcFontRe = re.compile(r'<font size=-2>(.*?)</font>')
_calcTimesRe = re.compile(r'&(?:times|#215);') _calcTimesRe = re.compile(r'&(?:times|#215);')
@ -314,12 +315,15 @@ class Google(callbacks.PluginRegexp):
""" """
url = self._googleUrl(expr) url = self._googleUrl(expr)
html = utils.web.getUrl(url) html = utils.web.getUrl(url)
match = self._calcRe.search(html) match = self._calcRe1.search(html)
if match is None:
match = self._calcRe2.search(html)
if match is not None: if match is not None:
s = match.group(1) s = match.group(1)
s = self._calcSupRe.sub(r'^(\1)', s) s = self._calcSupRe.sub(r'^(\1)', s)
s = self._calcFontRe.sub(r',', s) s = self._calcFontRe.sub(r',', s)
s = self._calcTimesRe.sub(r'*', s) s = self._calcTimesRe.sub(r'*', s)
s = utils.web.htmlToText(s)
irc.reply(s) irc.reply(s)
else: else:
irc.reply(_('Google\'s calculator didn\'t come up with anything.')) irc.reply(_('Google\'s calculator didn\'t come up with anything.'))

View File

@ -39,6 +39,7 @@ class GoogleTestCase(ChannelPluginTestCase):
def testCalc(self): def testCalc(self):
self.assertNotRegexp('google calc e^(i*pi)+1', r'didn\'t') self.assertNotRegexp('google calc e^(i*pi)+1', r'didn\'t')
self.assertNotRegexp('google calc 1 usd in gbp', r'didn\'t') self.assertNotRegexp('google calc 1 usd in gbp', r'didn\'t')
self.assertRegexp('google calc current time in usa', r'Time in.*USA')
def testHtmlHandled(self): def testHtmlHandled(self):
self.assertNotRegexp('google calc ' self.assertNotRegexp('google calc '

View File

@ -104,5 +104,5 @@ msgstr "Il n'y a pas de note pour %r"
#: plugin.py:182 #: plugin.py:182
msgid "Sent %s: <%s> %s" msgid "Sent %s: <%s> %s"
msgstr "Envoyé le %s : <%s> %s" msgstr "Envoyé %s : <%s> %s"

View File

@ -42,6 +42,62 @@ class Scheduler(callbacks.Plugin):
self.__parent = super(Scheduler, self) self.__parent = super(Scheduler, self)
self.__parent.__init__(irc) self.__parent.__init__(irc)
self.events = {} self.events = {}
self._restoreEvents(irc)
world.flushers.append(self._flush)
def _restoreEvents(self, irc):
try:
pkl = open(filename, 'rb')
try:
eventdict = pickle.load(pkl)
except Exception, e:
self.log.debug('Unable to load pickled data: %s', e)
return
finally:
pkl.close()
except IOError, e:
self.log.debug('Unable to open pickle file: %s', e)
return
for name, event in eventdict.iteritems():
ircobj = callbacks.ReplyIrcProxy(irc, event['msg'])
try:
if event['type'] == 'single': # non-repeating event
n = None
if schedule.schedule.counter > int(name):
# counter not reset, we're probably reloading the plugin
# though we'll never know for sure, because other
# plugins can schedule stuff, too.
n = int(name)
self._add(ircobj, event['msg'],
event['time'], event['command'], n)
elif event['type'] == 'repeat': # repeating event
self._repeat(ircobj, event['msg'], name,
event['time'], event['command'], False)
except AssertionError, e:
if str(e) == 'An event with the same name has already been scheduled.':
# we must be reloading the plugin, event is still scheduled
self.log.info('Event %s already exists, adding to dict.' % (name,))
self.events[name] = event
else:
raise
def _flush(self):
try:
pklfd, tempfn = tempfile.mkstemp(suffix='scheduler', dir=datadir)
pkl = os.fdopen(pklfd, 'wb')
try:
pickle.dump(self.events, pkl)
except Exception, e:
self.log.warning('Unable to store pickled data: %s', e)
pkl.close()
shutil.move(tempfn, filename)
except (IOError, shutil.Error), e:
self.log.warning('File error: %s', e)
def die(self):
self._flush()
world.flushers.remove(self._flush)
self.__parent.die()
def _makeCommandFunction(self, irc, msg, command, remove=True): def _makeCommandFunction(self, irc, msg, command, remove=True):
"""Makes a function suitable for scheduling from command.""" """Makes a function suitable for scheduling from command."""
@ -90,6 +146,15 @@ class Scheduler(callbacks.Plugin):
irc.error(_('Invalid event id.')) irc.error(_('Invalid event id.'))
remove = wrap(remove, ['lowered']) remove = wrap(remove, ['lowered'])
def _repeat(self, irc, msg, name, seconds, command, now=True):
f = self._makeCommandFunction(irc, msg, command, remove=False)
id = schedule.addPeriodicEvent(f, seconds, name, now)
assert id == name
self.events[name] = {'command':command,
'msg':msg,
'time':seconds,
'type':'repeat'}
@internationalizeDocstring @internationalizeDocstring
def repeat(self, irc, msg, args, name, seconds, command): def repeat(self, irc, msg, args, name, seconds, command):
"""<name> <seconds> <command> """<name> <seconds> <command>

View File

@ -50,7 +50,7 @@ class ChannelDBTestCase(ChannelPluginTestCase):
self.assertNotRegexp('seen asldfkjasdlfkj', 'KeyError') self.assertNotRegexp('seen asldfkjasdlfkj', 'KeyError')
def testAny(self): def testAny(self):
self.assertRegexp('seen any', 'test has joined') self.assertRegexp('seen any', 'test <test!user@host.domain.tld> has joined')
self.irc.feedMsg(ircmsgs.mode(self.channel, args=('+o', self.nick), self.irc.feedMsg(ircmsgs.mode(self.channel, args=('+o', self.nick),
prefix=self.prefix)) prefix=self.prefix))
self.assertRegexp('seen any %s' % self.nick, self.assertRegexp('seen any %s' % self.nick,

View File

@ -303,6 +303,8 @@ class Services(callbacks.Plugin):
pass pass
elif ('now recognized' in s) or \ elif ('now recognized' in s) or \
('already identified' in s) or \ ('already identified' in s) or \
('already logged in' in s) or \
('successfully identified' in s) or \
('password accepted' in s) or \ ('password accepted' in s) or \
('now identified' in s): ('now identified' in s):
# freenode, oftc, arstechnica, zirc, .... # freenode, oftc, arstechnica, zirc, ....

View File

@ -85,7 +85,7 @@ class String(callbacks.Plugin):
<http://docs.python.org/library/codecs.html#standard-encodings>. <http://docs.python.org/library/codecs.html#standard-encodings>.
""" """
try: try:
irc.reply(text.decode(encoding).encode('utf-8')) irc.reply(text.decode(encoding))
except LookupError: except LookupError:
irc.errorInvalid(_('encoding'), encoding) irc.errorInvalid(_('encoding'), encoding)
except binascii.Error: except binascii.Error:

View File

@ -403,9 +403,6 @@ class Topic(callbacks.Plugin):
index into the topics. <channel> is only necessary if the message index into the topics. <channel> is only necessary if the message
isn't sent in the channel itself. isn't sent in the channel itself.
""" """
if not self._checkManageCapabilities(irc, msg, channel):
capabilities = self.registryValue('requireManageCapability')
irc.errorNoCapability(capabilities, Raise=True)
topics = self._splitTopic(irc.state.getTopic(channel), channel) topics = self._splitTopic(irc.state.getTopic(channel), channel)
irc.reply(topics[number]) irc.reply(topics[number])
get = wrap(get, ['inChannel', 'topicNumber']) get = wrap(get, ['inChannel', 'topicNumber'])

View File

@ -37,7 +37,8 @@ if os.name == 'posix':
if utils.findBinaryInPath('aspell') is not None or \ if utils.findBinaryInPath('aspell') is not None or \
utils.findBinaryInPath('ispell') is not None: utils.findBinaryInPath('ispell') is not None:
def testSpell(self): def testSpell(self):
self.assertRegexp('spell Strike', 'correctly') self.assertRegexp('spell Strike',
'(correctly|Possible spellings)')
# ispell won't find any results. aspell will make some # ispell won't find any results. aspell will make some
# suggestions. # suggestions.
self.assertRegexp('spell z0opadfnaf83nflafl230kasdf023hflasdf', self.assertRegexp('spell z0opadfnaf83nflafl230kasdf023hflasdf',

View File

@ -314,7 +314,7 @@ def _getRe(f):
s = args.pop(0) s = args.pop(0)
def isRe(s): def isRe(s):
try: try:
_ = f(s) foo = f(s)
return True return True
except ValueError: except ValueError:
return False return False
@ -477,6 +477,11 @@ def checkCapability(irc, msg, args, state, cap):
if not ircdb.checkCapability(msg.prefix, cap): if not ircdb.checkCapability(msg.prefix, cap):
state.errorNoCapability(cap, Raise=True) state.errorNoCapability(cap, Raise=True)
def checkCapabilityButIgnoreOwner(irc, msg, args, state, cap):
cap = ircdb.canonicalCapability(cap)
if not ircdb.checkCapability(msg.prefix, cap, ignoreOwner=True):
state.errorNoCapability(cap, Raise=True)
def owner(irc, msg, args, state): def owner(irc, msg, args, state):
checkCapability(irc, msg, args, state, 'owner') checkCapability(irc, msg, args, state, 'owner')
@ -590,6 +595,7 @@ wrappers = ircutils.IrcDict({
'channel': getChannel, 'channel': getChannel,
'channelDb': getChannelDb, 'channelDb': getChannelDb,
'checkCapability': checkCapability, 'checkCapability': checkCapability,
'checkCapabilityButIgnoreOwner': checkCapabilityButIgnoreOwner,
'checkChannelCapability': checkChannelCapability, 'checkChannelCapability': checkChannelCapability,
'color': getIrcColor, 'color': getIrcColor,
'commandName': getCommandName, 'commandName': getCommandName,

View File

@ -1,6 +1,7 @@
### ###
# Copyright (c) 2002-2009, Jeremiah Fincher # Copyright (c) 2002-2009, Jeremiah Fincher
# Copyright (c) 2009, James Vega # Copyright (c) 2009, James Vega
# Copyright (c) 2011, Valentin Lorentz
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@ -152,7 +153,7 @@ class CapabilitySet(set):
elif self.__parent.__contains__(_invert(capability)): elif self.__parent.__contains__(_invert(capability)):
return False return False
else: else:
raise KeyError, capability return False
def __repr__(self): def __repr__(self):
return '%s([%s])' % (self.__class__.__name__, return '%s([%s])' % (self.__class__.__name__,
@ -165,16 +166,16 @@ class UserCapabilitySet(CapabilitySet):
self.__parent = super(UserCapabilitySet, self) self.__parent = super(UserCapabilitySet, self)
self.__parent.__init__(*args, **kwargs) self.__parent.__init__(*args, **kwargs)
def __contains__(self, capability): def __contains__(self, capability, ignoreOwner=False):
capability = ircutils.toLower(capability) capability = ircutils.toLower(capability)
if capability == 'owner' or capability == antiOwner: if not ignoreOwner and capability == 'owner' or capability == antiOwner:
return True return True
elif self.__parent.__contains__('owner'): elif not ignoreOwner and self.__parent.__contains__('owner'):
return True return True
else: else:
return self.__parent.__contains__(capability) return self.__parent.__contains__(capability)
def check(self, capability): def check(self, capability, ignoreOwner=False):
"""Returns the appropriate boolean for whether a given capability is """Returns the appropriate boolean for whether a given capability is
'allowed' given its (or its anticapability's) presence in the set. 'allowed' given its (or its anticapability's) presence in the set.
Differs from CapabilitySet in that it handles the 'owner' capability Differs from CapabilitySet in that it handles the 'owner' capability
@ -186,7 +187,7 @@ class UserCapabilitySet(CapabilitySet):
return not isAntiCapability(capability) return not isAntiCapability(capability)
else: else:
return isAntiCapability(capability) return isAntiCapability(capability)
elif self.__parent.__contains__('owner'): elif not ignoreOwner and self.__parent.__contains__('owner'):
if isAntiCapability(capability): if isAntiCapability(capability):
return False return False
else: else:
@ -236,7 +237,7 @@ class IrcUser(object):
"""Takes from the user the given capability.""" """Takes from the user the given capability."""
self.capabilities.remove(capability) self.capabilities.remove(capability)
def _checkCapability(self, capability): def _checkCapability(self, capability, ignoreOwner=False):
"""Checks the user for a given capability.""" """Checks the user for a given capability."""
if self.ignore: if self.ignore:
if isAntiCapability(capability): if isAntiCapability(capability):
@ -244,7 +245,7 @@ class IrcUser(object):
else: else:
return False return False
else: else:
return self.capabilities.check(capability) return self.capabilities.check(capability, ignoreOwner)
def setPassword(self, password, hashed=False): def setPassword(self, password, hashed=False):
"""Sets the user's password.""" """Sets the user's password."""
@ -1009,7 +1010,8 @@ def _checkCapabilityForUnknownUser(capability, users=users, channels=channels):
else: else:
return _x(capability, conf.supybot.capabilities.default()) return _x(capability, conf.supybot.capabilities.default())
def checkCapability(hostmask, capability, users=users, channels=channels): def checkCapability(hostmask, capability, users=users, channels=channels,
ignoreOwner=False):
"""Checks that the user specified by name/hostmask has the capability given. """Checks that the user specified by name/hostmask has the capability given.
""" """
if world.testing: if world.testing:
@ -1028,7 +1030,7 @@ def checkCapability(hostmask, capability, users=users, channels=channels):
return _checkCapabilityForUnknownUser(capability, users=users, return _checkCapabilityForUnknownUser(capability, users=users,
channels=channels) channels=channels)
if capability in u.capabilities: if capability in u.capabilities:
return u._checkCapability(capability) return u._checkCapability(capability, ignoreOwner)
else: else:
if isChannelCapability(capability): if isChannelCapability(capability):
(channel, capability) = fromChannelCapability(capability) (channel, capability) = fromChannelCapability(capability)

View File

@ -196,7 +196,7 @@ def banmask(hostmask):
L[-1] = '*' L[-1] = '*'
return '*!*@' + ':'.join(L) return '*!*@' + ':'.join(L)
else: else:
if '.' in host: if len(host.split('.')) > 2: # If it is a subdomain
return '*!*@*%s' % host[host.find('.'):] return '*!*@*%s' % host[host.find('.'):]
else: else:
return '*!*@' + host return '*!*@' + host

View File

@ -287,6 +287,7 @@ def pluralize(s):
@internationalizeFunction('depluralize') @internationalizeFunction('depluralize')
def depluralize(s): def depluralize(s):
"""Returns the singular of s.""" """Returns the singular of s."""
consonants = 'bcdfghjklmnpqrstvwxz'
_depluralizeRegex = re.compile('[%s]ies' % consonants) _depluralizeRegex = re.compile('[%s]ies' % consonants)
lowered = s.lower() lowered = s.lower()
if lowered in plurals: if lowered in plurals:

View File

@ -233,6 +233,10 @@ class FunctionsTestCase(SupyTestCase):
msg.prefix), msg.prefix),
'%r didn\'t match %r' % (msg.prefix, banmask)) '%r didn\'t match %r' % (msg.prefix, banmask))
self.assertEqual(ircutils.banmask('foobar!user@host'), '*!*@host') self.assertEqual(ircutils.banmask('foobar!user@host'), '*!*@host')
self.assertEqual(ircutils.banmask('foobar!user@host.tld'),
'*!*@host.tld')
self.assertEqual(ircutils.banmask('foobar!user@sub.host.tld'),
'*!*@*.host.tld')
self.assertEqual(ircutils.banmask('foo!bar@2001::'), '*!*@2001::*') self.assertEqual(ircutils.banmask('foo!bar@2001::'), '*!*@2001::*')
def testSeparateModes(self): def testSeparateModes(self):