Use utf8 wherever it's needed

This commit is contained in:
Stefan Ritter 2011-05-18 22:56:50 +02:00
parent 31c53768e9
commit c5ee3f08d2
1 changed files with 14 additions and 10 deletions

View File

@ -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