From becd135c5242b1a093bdcf88026c7c7328d4e7d7 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sun, 8 Jul 2012 16:09:00 -0400 Subject: [PATCH] Minor cleanup for afc_copyvios, mainly Unicode fixes. --- earwigbot/tasks/afc_copyvios.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/earwigbot/tasks/afc_copyvios.py b/earwigbot/tasks/afc_copyvios.py index 12c6b80..3dc3902 100644 --- a/earwigbot/tasks/afc_copyvios.py +++ b/earwigbot/tasks/afc_copyvios.py @@ -23,6 +23,7 @@ from hashlib import sha256 from os.path import expanduser from threading import Lock +from urllib import quote import oursql @@ -86,9 +87,10 @@ class AFCCopyvios(Task): confidence = "{0}%".format(round(result.confidence * 100, 2)) if result.violation: + safeurl = quote(url.encode("utf8"), safe="/:").decode("utf8") content = page.get() - template = "\{\{{0}|url={1}|confidence={2}\}\}\n" - template = template.format(self.template, url, confidence) + template = u"\{\{{0}|url={1}|confidence={2}\}\}\n" + template = template.format(self.template, safeurl, confidence) newtext = template + content if "{url}" in self.summary: page.edit(newtext, self.summary.format(url=url)) @@ -110,9 +112,7 @@ class AFCCopyvios(Task): with self.conn.cursor() as cursor: cursor.execute(query, (pageid,)) results = cursor.fetchall() - if results: - return True - return False + return True if results else False def log_processed(self, pageid): """Adds pageid to our database of processed pages. @@ -138,8 +138,8 @@ class AFCCopyvios(Task): be) retained for one day; this task does not remove old entries (that is handled by the Toolserver component). - This will only be called if "cache_results" == True in the task's - config, which is False by default. + This will only be called if ``cache_results == True`` in the task's + config, which is ``False`` by default. """ pageid = page.pageid hash = sha256(page.get()).hexdigest()