From c2f6ece39db14ba87ad33d6a7103193cf2e64050 Mon Sep 17 00:00:00 2001 From: mathieui Date: Fri, 2 Aug 2013 23:59:49 +0200 Subject: Fix #2300 (use re.sub in the replace plugin) --- plugins/replace.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/plugins/replace.py b/plugins/replace.py index 5f1e33d1..e238552f 100644 --- a/plugins/replace.py +++ b/plugins/replace.py @@ -66,6 +66,7 @@ from plugin import BasePlugin import tabs import datetime import random +import re from sleekxmpp.xmlstream.stanzabase import JID class Plugin(BasePlugin): @@ -88,16 +89,9 @@ class Plugin(BasePlugin): body = message['body'] for pattern in self.patterns: new = body - while True: - # we don't use a replace on all occurence, otherwise the - # result would be the same for all occurence of the pattern - # and that's not desirable in some of them (for example the - # ones that provide random results) - new = body.replace('%%%s%%' % pattern, - self.patterns[pattern](message, tab), 1) - if new == body: - break - body = new + body = re.sub('%%%s%%' % pattern, + lambda x: self.patterns[pattern](message, tab), + body) message['body'] = body -- cgit v1.2.3