String: make re timeout configurable.

This commit is contained in:
Daniel Folkinshteyn 2010-08-08 01:43:05 -04:00
parent e4498664bb
commit 2d9f61e66c
2 changed files with 9 additions and 2 deletions

View File

@ -50,5 +50,11 @@ conf.registerGlobalValue(String.levenshtein, 'max',
and more time. Using nested commands, strings can get quite large, hence and more time. Using nested commands, strings can get quite large, hence
this variable, to limit the size of arguments passed to the levenshtein this variable, to limit the size of arguments passed to the levenshtein
command.""")) command."""))
conf.registerGroup(String, 're')
conf.registerGlobalValue(String.re, 'timeout',
registry.PositiveFloat(5, """Determines the maximum time, in seconds, that
a regular expression is given to execute before being terminated. Since
there is a possibility that user input for the re command can cause it to
eat up large amounts of ram or cpu time, it's a good idea to keep this
low. Most normal regexps should not take very long at all."""))
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -138,7 +138,8 @@ class String(callbacks.Plugin):
s = 'You probably don\'t want to match the empty string.' s = 'You probably don\'t want to match the empty string.'
irc.error(s) irc.error(s)
else: else:
v = commands.process(f, text, timeout=10, pn=self.name(), cn='re') t = self.registryValue('re.timeout')
v = commands.process(f, text, timeout=t, pn=self.name(), cn='re')
irc.reply(v) irc.reply(v)
re = thread(wrap(re, [first('regexpMatcher', 'regexpReplacer'), re = thread(wrap(re, [first('regexpMatcher', 'regexpReplacer'),
'text'])) 'text']))