Browse Source

Avoid backreferences in re.sub() repl to bypass re._cache_repl (#17)

tags/v0.1^2
Ben Kurtovic 12 years ago
parent
commit
cdb7bce734
1 changed files with 6 additions and 5 deletions
  1. +6
    -5
      earwigbot/tasks/afc_statistics.py

+ 6
- 5
earwigbot/tasks/afc_statistics.py View File

@@ -117,15 +117,16 @@ class Task(BaseTask):


page = self.site.get_page(self.pagename) page = self.site.get_page(self.pagename)
text = page.get().encode("utf8") text = page.get().encode("utf8")
newtext = re.sub("(<!-- stat begin -->)(.*?)(<!-- stat end -->)",
statistics.join(("\\1\n", "\n\\3")), text,
flags=re.DOTALL)
newtext = re.sub("<!-- stat begin -->(.*?)<!-- stat end -->",
"<!-- stat begin -->\n" + statistics + "\n<!-- stat end -->",
text, flags=re.DOTALL)
if newtext == text: if newtext == text:
self.logger.info("Chart unchanged; not saving") self.logger.info("Chart unchanged; not saving")
return # Don't edit the page if we're not adding anything return # Don't edit the page if we're not adding anything


newtext = re.sub("(<!-- sig begin -->)(.*?)(<!-- sig end -->)",
"\\1~~~ at ~~~~~\\3", newtext)
newtext = re.sub("<!-- sig begin -->(.*?)<!-- sig end -->",
"<!-- sig begin -->~~~ at ~~~~~<!-- sig end -->",
newtext)
page.edit(newtext, summary, minor=True, bot=True) page.edit(newtext, summary, minor=True, bot=True)
self.logger.info("Chart saved to [[{0}]]".format(page.title())) self.logger.info("Chart saved to [[{0}]]".format(page.title()))




Loading…
Cancel
Save