From 1267d6452e333e5a8546eb0f0afa2e616ecbb994 Mon Sep 17 00:00:00 2001 From: James Lu Date: Thu, 17 Oct 2019 21:55:37 -0700 Subject: [PATCH] SedRegex: abort when a search times out This requires commit https://github.com/ProgVal/Limnoria/commit/b54d8f8073b4fca1787012b211337dc707cfea45, which separates the timeout and no match cases. Also, raise the default processTimeout as the plugin now aborts on the first message that times out. From: https://github.com/jlu5/SupyPlugins/commit/e5af47993945ce8b0bdd772d144b96ca0be22acd --- plugins/SedRegex/config.py | 4 ++-- plugins/SedRegex/plugin.py | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/plugins/SedRegex/config.py b/plugins/SedRegex/config.py index ff185de04..ce2b8b396 100644 --- a/plugins/SedRegex/config.py +++ b/plugins/SedRegex/config.py @@ -1,6 +1,6 @@ ### # Copyright (c) 2015, Michael Daniel Telatynski -# Copyright (c) 2015, James Lu +# Copyright (c) 2015-2019, James Lu # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -57,7 +57,7 @@ conf.registerChannelValue(SedRegex, 'ignoreRegex', registry.Boolean(True, _("""Should Perl/sed regex replacing ignore messages which look like valid regex?"""))) conf.registerGlobalValue(SedRegex, 'processTimeout', - registry.PositiveFloat(0.05, _("""Sets the timeout when processing a single + registry.PositiveFloat(0.5, _("""Sets the timeout when processing a single regexp. The default should be adequate unless you have a busy or low-powered system that cannot process regexps quickly enough. However, diff --git a/plugins/SedRegex/plugin.py b/plugins/SedRegex/plugin.py index cacff350f..1b20b5eac 100644 --- a/plugins/SedRegex/plugin.py +++ b/plugins/SedRegex/plugin.py @@ -1,6 +1,6 @@ ### # Copyright (c) 2015, Michael Daniel Telatynski -# Copyright (c) 2015-2017, James Lu +# Copyright (c) 2015-2019, James Lu # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -154,8 +154,9 @@ class SedRegex(callbacks.PluginRegexp): messageprefix = '%s thinks %s' % (msg.nick, m.nick) try: regex_timeout = self.registryValue('processTimeout') - if regexp_wrapper(text, pattern, timeout=regex_timeout, plugin_name=self.name(), - fcn_name='replacer'): + replace_result = regexp_wrapper(text, pattern, timeout=regex_timeout, plugin_name=self.name(), + fcn_name='replacer') + if replace_result is True: if self.registryValue('boldReplacementText', msg.args[0]): replacement = ircutils.bold(replacement) subst = process(pattern.sub, replacement, @@ -168,6 +169,12 @@ class SedRegex(callbacks.PluginRegexp): irc.reply(_("%s meant to say: %s") % (messageprefix, subst), prefixNick=False) return + elif replace_result is None: + # Abort on timeout instead of looking against older messages - this prevents + # replacing the wrong message when we get a one off timeout, which usually leads + # to very confusing results. + # This requires commit https://github.com/ProgVal/Limnoria/commit/b54d8f8073b4fca1787012b211337dc707cfea45 + irc.error(_("Search timed out."), Raise=True) except Exception as e: self.log.warning(_("SedRegex error: %s"), e, exc_info=True) if self.registryValue('displayErrors', msg.args[0]):