utf8 fix
This commit is contained in:
parent
b06dc41a2c
commit
f676c2da59
53
blogthon.cgi
53
blogthon.cgi
@ -23,8 +23,9 @@ import codecs
|
|||||||
# print() will output ascii, but we want utf-8 (python3)
|
# print() will output ascii, but we want utf-8 (python3)
|
||||||
try:
|
try:
|
||||||
sys.stdout = codecs.getwriter('utf8')(sys.stdout.buffer)
|
sys.stdout = codecs.getwriter('utf8')(sys.stdout.buffer)
|
||||||
|
utf8 = True
|
||||||
except:
|
except:
|
||||||
None
|
utf8 = False
|
||||||
|
|
||||||
# Backward compatibilty to python2
|
# Backward compatibilty to python2
|
||||||
try:
|
try:
|
||||||
@ -227,10 +228,16 @@ if cname and ctext and ctitle:
|
|||||||
else:
|
else:
|
||||||
comments_file = os.path.join(entries_dir, ctitle + ".comments")
|
comments_file = os.path.join(entries_dir, ctitle + ".comments")
|
||||||
if not os.path.exists(comments_file):
|
if not os.path.exists(comments_file):
|
||||||
content = open(comments_file, "w", encoding="utf8")
|
if utf8:
|
||||||
|
content = open(comments_file, "w", encoding="utf8")
|
||||||
|
else:
|
||||||
|
content = open(comments_file, "w")
|
||||||
content.close()
|
content.close()
|
||||||
|
|
||||||
content = open(comments_file, "a", encoding="utf8")
|
if utf8:
|
||||||
|
content = open(comments_file, "a", encoding="utf8")
|
||||||
|
else:
|
||||||
|
content = open(comments_file, "a")
|
||||||
content.write("-." + cname + "\n")
|
content.write("-." + cname + "\n")
|
||||||
content.write("+." + time.strftime("%c", time.localtime()) + "\n")
|
content.write("+." + time.strftime("%c", time.localtime()) + "\n")
|
||||||
ctext = ctext.split("\n")
|
ctext = ctext.split("\n")
|
||||||
@ -306,7 +313,10 @@ if feed_display == "atom":
|
|||||||
print(ind*3 + "<id>urn:uuid:%s</id>" % title_md5sum)
|
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 + "<updated>%s-%s-%sT%s:%s:%sZ</updated>" % (str(date[0]), month, day, hour, min, sec))
|
||||||
print(ind*3 + "<summary>")
|
print(ind*3 + "<summary>")
|
||||||
content = open(str(entries[i][1]), "r", encoding="utf8")
|
if utf8:
|
||||||
|
content = open(str(entries[i][1]), "r", encoding="utf8")
|
||||||
|
else:
|
||||||
|
content = open(str(entries[i][1]), "r")
|
||||||
for h in range(0, int(feed_preview)):
|
for h in range(0, int(feed_preview)):
|
||||||
rss_line = content.readline().strip()
|
rss_line = content.readline().strip()
|
||||||
if rss_line != "":
|
if rss_line != "":
|
||||||
@ -336,7 +346,10 @@ elif feed_display == "rss":
|
|||||||
print(ind*3 + "<link>%s?p=%s</link>" % (blog_url, title))
|
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 + "<guid>%s?p=%s</guid>" % (blog_url, title))
|
||||||
print(ind*3 + "<pubDate>%s</pubDate>" % date)
|
print(ind*3 + "<pubDate>%s</pubDate>" % date)
|
||||||
content = open(str(entries[i][1]), "r", encoding="utf8")
|
if utf8:
|
||||||
|
content = open(str(entries[i][1]), "r", encoding="utf8")
|
||||||
|
else:
|
||||||
|
content = open(str(entries[i][1]), "r")
|
||||||
rss_description= ""
|
rss_description= ""
|
||||||
for h in range(0, int(feed_preview)):
|
for h in range(0, int(feed_preview)):
|
||||||
line = content.readline().strip()
|
line = content.readline().strip()
|
||||||
@ -400,7 +413,10 @@ else:
|
|||||||
print(ind*3 + "<div class=\"pages_list\">")
|
print(ind*3 + "<div class=\"pages_list\">")
|
||||||
print(ind*4 + "<ul class=\"pages_list\">")
|
print(ind*4 + "<ul class=\"pages_list\">")
|
||||||
for staticpage in staticpages_list:
|
for staticpage in staticpages_list:
|
||||||
file = open(staticpage, "r", encoding="utf8")
|
if utf8:
|
||||||
|
file = open(staticpage, "r", encoding="utf8")
|
||||||
|
else:
|
||||||
|
file = open(staticpage, "r")
|
||||||
header = file.readline()
|
header = file.readline()
|
||||||
if header.split(":", 1)[0] == "extern_link":
|
if header.split(":", 1)[0] == "extern_link":
|
||||||
link = header.split(":", 1)[1].strip()
|
link = header.split(":", 1)[1].strip()
|
||||||
@ -442,7 +458,10 @@ else:
|
|||||||
print(ind*3 + "<div class=\"linklist_list\">")
|
print(ind*3 + "<div class=\"linklist_list\">")
|
||||||
print(ind*4 + "<ul class=\"linklist_list\">")
|
print(ind*4 + "<ul class=\"linklist_list\">")
|
||||||
try:
|
try:
|
||||||
content = open("linklist", "r", encoding="utf8")
|
if utf8:
|
||||||
|
content = open("linklist", "r", encoding="utf8")
|
||||||
|
else:
|
||||||
|
content = open("linklist", "r")
|
||||||
for line in content:
|
for line in content:
|
||||||
if line.strip() is "":
|
if line.strip() is "":
|
||||||
print("<br />")
|
print("<br />")
|
||||||
@ -462,7 +481,10 @@ else:
|
|||||||
|
|
||||||
# Staticpage
|
# Staticpage
|
||||||
if static_display != "":
|
if static_display != "":
|
||||||
content = open(os.path.join(staticpages_dir, static_display), "r", encoding="utf-8")
|
if utf8:
|
||||||
|
content = open(os.path.join(staticpages_dir, static_display), "r", encoding="utf-8")
|
||||||
|
else:
|
||||||
|
content = open(os.path.join(staticpages_dir, static_display), "r")
|
||||||
print(ind*3 + "<div class=\"entry\">")
|
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_title\">%s</div>" % re.sub("^\.", "", re.sub("\d+?-", "", static_display)))
|
||||||
print(ind*4 + "<div class=\"entry_content\">")
|
print(ind*4 + "<div class=\"entry_content\">")
|
||||||
@ -501,7 +523,10 @@ else:
|
|||||||
if month_display == date_to_compare or not month_display:
|
if month_display == date_to_compare or not month_display:
|
||||||
if post_display == title.replace(" ", "-") or not post_display:
|
if post_display == title.replace(" ", "-") or not post_display:
|
||||||
if allentries_display == "1" or entry_counter < entries_per_page:
|
if allentries_display == "1" or entry_counter < entries_per_page:
|
||||||
content = open(entry, "r", encoding="utf8")
|
if utf8:
|
||||||
|
content = open(entry, "r", encoding="utf8")
|
||||||
|
else:
|
||||||
|
content = open(entry, "r")
|
||||||
print(ind*3 + "<div class=\"entry\">")
|
print(ind*3 + "<div class=\"entry\">")
|
||||||
if permalinks:
|
if permalinks:
|
||||||
print(ind*4 + "<div class=\"entry_title\"><a href=\"?p=%s\" class=\"entry_title\">%s</a></div>" % (title.replace(" ", "-"), title))
|
print(ind*4 + "<div class=\"entry_title\"><a href=\"?p=%s\" class=\"entry_title\">%s</a></div>" % (title.replace(" ", "-"), title))
|
||||||
@ -526,7 +551,10 @@ else:
|
|||||||
comments_file = glob(os.path.join(entries_dir, title + ".comments"))
|
comments_file = glob(os.path.join(entries_dir, title + ".comments"))
|
||||||
if post_display:
|
if post_display:
|
||||||
if comments_file:
|
if comments_file:
|
||||||
comments_content = open(comments_file[0], "r", encoding="utf8")
|
if utf8:
|
||||||
|
comments_content = open(comments_file[0], "r", encoding="utf8")
|
||||||
|
else:
|
||||||
|
comments_content = open(comments_file[0], "r")
|
||||||
print(ind*3 + "</div>")
|
print(ind*3 + "</div>")
|
||||||
print(ind*2 + "</div>")
|
print(ind*2 + "</div>")
|
||||||
print("")
|
print("")
|
||||||
@ -592,7 +620,10 @@ else:
|
|||||||
print(ind*3 + "</div>")
|
print(ind*3 + "</div>")
|
||||||
print("")
|
print("")
|
||||||
elif comments_file and not post_display:
|
elif comments_file and not post_display:
|
||||||
comments_content = open(comments_file[0], "r", encoding="utf8")
|
if utf8:
|
||||||
|
comments_content = open(comments_file[0], "r", encoding="utf8")
|
||||||
|
else:
|
||||||
|
comments_content = open(comments_file[0], "r")
|
||||||
comments_counter = 0
|
comments_counter = 0
|
||||||
for line in comments_content:
|
for line in comments_content:
|
||||||
if line.split(".", 1)[0] == "-": comments_counter += 1
|
if line.split(".", 1)[0] == "-": comments_counter += 1
|
||||||
|
Loading…
Reference in New Issue
Block a user