From cdb7bce7344395fdf7c8c70ced6b6ebc1c9aa3b4 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Fri, 23 Mar 2012 23:37:53 -0400 Subject: [PATCH] Avoid backreferences in re.sub() repl to bypass re._cache_repl (#17) --- earwigbot/tasks/afc_statistics.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/earwigbot/tasks/afc_statistics.py b/earwigbot/tasks/afc_statistics.py index e52fd1f..5c147ed 100644 --- a/earwigbot/tasks/afc_statistics.py +++ b/earwigbot/tasks/afc_statistics.py @@ -117,15 +117,16 @@ class Task(BaseTask): page = self.site.get_page(self.pagename) text = page.get().encode("utf8") - newtext = re.sub("()(.*?)()", - statistics.join(("\\1\n", "\n\\3")), text, - flags=re.DOTALL) + newtext = re.sub("(.*?)", + "\n" + statistics + "\n", + text, flags=re.DOTALL) if newtext == text: self.logger.info("Chart unchanged; not saving") return # Don't edit the page if we're not adding anything - newtext = re.sub("()(.*?)()", - "\\1~~~ at ~~~~~\\3", newtext) + newtext = re.sub("(.*?)", + "~~~ at ~~~~~", + newtext) page.edit(newtext, summary, minor=True, bot=True) self.logger.info("Chart saved to [[{0}]]".format(page.title()))