aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Ritter <xeno@thehappy.de>2011-05-18 22:56:50 +0200
committerStefan Ritter <xeno@thehappy.de>2011-05-18 22:56:50 +0200
commitc5ee3f08d2e725598148eba9bc043f78a7542e3d (patch)
tree1274b7bed94ef8257cb60f7ac6130b4fa9233e00
parent31c53768e9e27b29a1742eca4bc738a60085a279 (diff)
Use utf8 wherever it's needed
Diffstat (limited to '')
-rwxr-xr-xblogthon.cgi24
1 files 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 + "<id>urn:uuid:%s</id>" % title_md5sum)
print(ind*3 + "<updated>%s-%s-%sT%s:%s:%sZ</updated>" % (str(date[0]), month, day, hour, min, sec))
print(ind*3 + "<summary>")
- 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 + "<link>%s?p=%s</link>" % (blog_url, title))
print(ind*3 + "<guid>%s?p=%s</guid>" % (blog_url, title))
print(ind*3 + "<pubDate>%s</pubDate>" % 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 + "<div class=\"pages_list\">")
print(ind*4 + "<ul class=\"pages_list\">")
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 + "<div class=\"linklist_list\">")
print(ind*4 + "<ul class=\"linklist_list\">")
try:
- content = open("linklist", "r")
+ content = open("linklist", "r", encoding="utf8")
for line in content:
if line.strip() is "":
print("<br />")
@@ -455,7 +459,7 @@ else:
# Staticpage
if static_display != "":
- content = open(os.path.join(staticpages_dir, static_display), "r")
+ content = open(os.path.join(staticpages_dir, static_display), "r", encoding="utf-8")
print(ind*3 + "<div class=\"entry\">")
print(ind*4 + "<div class=\"entry_title\">%s</div>" % re.sub("^\.", "", re.sub("\d+?-", "", static_display)))
print(ind*4 + "<div class=\"entry_content\">")
@@ -494,7 +498,7 @@ else:
if month_display == date_to_compare or not month_display:
if post_display == title.replace(" ", "-") or not post_display:
if allentries_display == "1" or entry_counter < entries_per_page:
- content = open(entry, "r")
+ content = open(entry, "r", encoding="utf8")
print(ind*3 + "<div class=\"entry\">")
if permalinks:
print(ind*4 + "<div class=\"entry_title\"><a href=\"?p=%s\" class=\"entry_title\">%s</a></div>" % (title.replace(" ", "-"), title))
@@ -519,7 +523,7 @@ else:
comments_file = glob(os.path.join(entries_dir, title + ".comments"))
if post_display:
if comments_file:
- comments_content = open(comments_file[0], "r")
+ comments_content = open(comments_file[0], "r", encoding="utf8")
print(ind*3 + "</div>")
print(ind*2 + "</div>")
print("")
@@ -585,7 +589,7 @@ else:
print(ind*3 + "</div>")
print("")
elif comments_file and not post_display:
- comments_content = open(comments_file[0], "r")
+ comments_content = open(comments_file[0], "r", encoding="utf8")
comments_counter = 0
for line in comments_content:
if line.split(".", 1)[0] == "-": comments_counter += 1