From c5ee3f08d2e725598148eba9bc043f78a7542e3d Mon Sep 17 00:00:00 2001 From: Stefan Ritter Date: Wed, 18 May 2011 22:56:50 +0200 Subject: Use utf8 wherever it's needed --- blogthon.cgi | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/blogthon.cgi b/blogthon.cgi index d7730ee..c49df11 100755 --- a/blogthon.cgi +++ b/blogthon.cgi @@ -18,6 +18,10 @@ import sys import time import locale import re +import codecs + +# print() will output ascii, but we want utf-8 +sys.stdout = codecs.getwriter('utf8')(sys.stdout.buffer) # Backward compatibilty to python2 try: @@ -220,10 +224,10 @@ if cname and ctext and ctitle: else: comments_file = os.path.join(entries_dir, ctitle + ".comments") if not os.path.exists(comments_file): - content = open(comments_file, "w") + content = open(comments_file, "w", encoding="utf8") content.close() - content = open(comments_file, "a") + content = open(comments_file, "a", encoding="utf8") content.write("-." + cname + "\n") content.write("+." + time.strftime("%c", time.localtime()) + "\n") ctext = ctext.split("\n") @@ -299,7 +303,7 @@ if feed_display == "atom": print(ind*3 + "urn:uuid:%s" % title_md5sum) print(ind*3 + "%s-%s-%sT%s:%s:%sZ" % (str(date[0]), month, day, hour, min, sec)) print(ind*3 + "") - content = open(str(entries[i][1]), "r") + content = open(str(entries[i][1]), "r", encoding="utf8") for h in range(0, int(feed_preview)): rss_line = content.readline().strip() if rss_line != "": @@ -329,7 +333,7 @@ elif feed_display == "rss": print(ind*3 + "%s?p=%s" % (blog_url, title)) print(ind*3 + "%s?p=%s" % (blog_url, title)) print(ind*3 + "%s" % date) - content = open(str(entries[i][1]), "r") + content = open(str(entries[i][1]), "r", encoding="utf8") rss_description= "" for h in range(0, int(feed_preview)): line = content.readline().strip() @@ -393,7 +397,7 @@ else: print(ind*3 + "
") print(ind*4 + "
    ") for staticpage in staticpages_list: - file = open(staticpage, "r") + file = open(staticpage, "r", encoding="utf8") header = file.readline() if header.split(":", 1)[0] == "extern_link": link = header.split(":", 1)[1].strip() @@ -435,7 +439,7 @@ else: print(ind*3 + "