summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2013-08-02 23:59:49 +0200
committermathieui <mathieui@mathieui.net>2013-08-02 23:59:49 +0200
commitc2f6ece39db14ba87ad33d6a7103193cf2e64050 (patch)
tree34052e0b72d6cfc72288469ff6b1d9f069172862
parent9c51ea5643e1ad219e8850b87ff1cc3889512c5d (diff)
downloadpoezio-c2f6ece39db14ba87ad33d6a7103193cf2e64050.tar.gz
poezio-c2f6ece39db14ba87ad33d6a7103193cf2e64050.tar.bz2
poezio-c2f6ece39db14ba87ad33d6a7103193cf2e64050.tar.xz
poezio-c2f6ece39db14ba87ad33d6a7103193cf2e64050.zip
Fix #2300 (use re.sub in the replace plugin)
-rw-r--r--plugins/replace.py14
1 files 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