From fb31aa73c87f3cc2ba0cb78c0ef4d5049ee911e4 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Mon, 9 Jul 2012 01:32:28 -0400 Subject: [PATCH] Proper handling of unicode in some commands. --- earwigbot/commands/afc_report.py | 5 +++-- earwigbot/commands/afc_submissions.py | 2 +- earwigbot/commands/link.py | 9 ++++----- earwigbot/tasks/afc_statistics.py | 3 ++- earwigbot/wiki/page.py | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/earwigbot/commands/afc_report.py b/earwigbot/commands/afc_report.py index cb33c5f..d26f44b 100644 --- a/earwigbot/commands/afc_report.py +++ b/earwigbot/commands/afc_report.py @@ -74,12 +74,13 @@ class AFCReport(Command): return page def report(self, page): - url = page.url.replace("en.wikipedia.org/wiki", "enwp.org") + url = page.url.encode("utf8") + url = url.replace("en.wikipedia.org/wiki", "enwp.org") short = self.statistics.get_short_title(page.title) status = self.get_status(page) user = page.get_creator() user_name = user.name - user_url = user.get_talkpage().url + user_url = user.get_talkpage().url.encode("utf8") msg1 = "AfC submission report for \x0302{0}\x0F ({1}):" msg2 = "Status: \x0303{0}\x0F" diff --git a/earwigbot/commands/afc_submissions.py b/earwigbot/commands/afc_submissions.py index a7144b2..16530d3 100644 --- a/earwigbot/commands/afc_submissions.py +++ b/earwigbot/commands/afc_submissions.py @@ -54,6 +54,6 @@ class AFCSubmissions(Command): site = self.bot.wiki.get_site() category = site.get_category("Pending AfC submissions") members = category.get_members(limit=number + len(self.ignore_list)) - urls = [member.url for member in members if member.title not in self.ignore_list] + urls = [member.url.encode("utf8") for member in members if member.title not in self.ignore_list] pages = ", ".join(urls[:number]) self.reply(data, "{0} pending AfC subs: {1}".format(number, pages)) diff --git a/earwigbot/commands/link.py b/earwigbot/commands/link.py index c087600..aafb114 100644 --- a/earwigbot/commands/link.py +++ b/earwigbot/commands/link.py @@ -35,15 +35,15 @@ class Link(Command): if re.search("(\[\[(.*?)\]\])|(\{\{(.*?)\}\})", msg): links = self.parse_line(msg) - links = " , ".join(links) - self.reply(data, links) + links = u" , ".join(links) + self.reply(data, links.encode("utf8")) elif data.command == "link": if not data.args: self.reply(data, "what do you want me to link to?") return pagename = " ".join(data.args) - link = self.site.get_page(pagename).url + link = self.site.get_page(pagename).url.encode("utf8") self.reply(data, link) def parse_line(self, line): @@ -68,5 +68,4 @@ class Link(Command): return results def parse_template(self, pagename): - pagename = "".join(("Template:", pagename)) - return self.site.get_page(pagename).url + return self.site.get_page("Template:" + pagename).url diff --git a/earwigbot/tasks/afc_statistics.py b/earwigbot/tasks/afc_statistics.py index 7b852f7..c3ddfe2 100644 --- a/earwigbot/tasks/afc_statistics.py +++ b/earwigbot/tasks/afc_statistics.py @@ -269,7 +269,8 @@ class AFCStatistics(Task): tracked = [i[0] for i in cursor.fetchall()] category = self.site.get_category(self.pending_cat) - for title, pageid in category.get_members(): + for page in category.get_members(): + title, pageid = page.title, page.pageid if title in self.ignore_list: continue if pageid not in tracked: diff --git a/earwigbot/wiki/page.py b/earwigbot/wiki/page.py index 3f00b71..71479b3 100644 --- a/earwigbot/wiki/page.py +++ b/earwigbot/wiki/page.py @@ -513,9 +513,9 @@ class Page(CopyvioMixIn): return self._fullurl else: encoded = self._title.encode("utf8").replace(" ", "_") - slug = quote(encoded, safe="/:") + slug = quote(encoded, safe="/:").decode("utf8") path = self.site._article_path.replace("$1", slug) - return ''.join((self.site.url, path)) + return u"".join((self.site.url, path)) @property def namespace(self):