Fix errors with Python3

This commit is contained in:
Gregory Soutade 2022-09-18 17:22:17 +02:00
parent 4ece9e9079
commit 0d5d5ce535
3 changed files with 11 additions and 8 deletions

View File

@ -102,7 +102,7 @@ except ImportError:
import optparse import optparse
from random import random, randint from random import random, randint
import codecs import codecs
import urllib.parse
# ---- Python version compat # ---- Python version compat
@ -1273,7 +1273,7 @@ class Markdown(object):
if is_inline_img: if is_inline_img:
img_class_str = ' class="inlineimage"' img_class_str = ' class="inlineimage"'
result = '<img src="%s" alt="%s"%s%s%s' \ result = '<img src="%s" alt="%s"%s%s%s' \
% (url.replace('"', '&quot;'), % (urllib.parse.quote(url),
_xml_escape_attr(link_text), _xml_escape_attr(link_text),
title_str, img_class_str, self.empty_element_suffix) title_str, img_class_str, self.empty_element_suffix)
if "smarty-pants" in self.extras: if "smarty-pants" in self.extras:
@ -1323,7 +1323,7 @@ class Markdown(object):
if is_img: if is_img:
img_class_str = self._html_class_str_from_tag("img") img_class_str = self._html_class_str_from_tag("img")
result = '<img src="%s" alt="%s"%s%s%s' \ result = '<img src="%s" alt="%s"%s%s%s' \
% (url.replace('"', '&quot;'), % (urllib.parse.quote(url),
link_text.replace('"', '&quot;'), link_text.replace('"', '&quot;'),
title_str, img_class_str, self.empty_element_suffix) title_str, img_class_str, self.empty_element_suffix)
if "smarty-pants" in self.extras: if "smarty-pants" in self.extras:

View File

@ -116,7 +116,7 @@ class Blog(models.Model):
if os.path.isdir(srcname): if os.path.isdir(srcname):
if not os.path.exists(dstname): if not os.path.exists(dstname):
os.makedirs(dstname) os.makedirs(dstname)
self.copytree(srcname, dstname, ignore=True) shutil.copytree(srcname, dstname, ignore=True)
else: else:
return self.copytree(srcname, dstname) return self.copytree(srcname, dstname)
else: else:
@ -187,7 +187,11 @@ class Blog(models.Model):
if obj.__module__ in generated: continue if obj.__module__ in generated: continue
e = obj(hash_posts, hash_posts_content) e = obj(hash_posts, hash_posts_content)
print('Go for {}'.format(e)) print('Go for {}'.format(e))
try:
r = e.generate(self, self.src_path, self.output_path) r = e.generate(self, self.src_path, self.output_path)
except Exception as err:
self.report += err
continue
generated.append(obj.__module__) generated.append(obj.__module__)
if not r is None: if not r is None:
self.report = self.report + '<br/>\n' + r self.report = self.report + '<br/>\n' + r

View File

@ -192,7 +192,7 @@ class Search:
def search(self, blog, string): def search(self, blog, string):
hashtable = self._loadDatabase(blog) hashtable = self._loadDatabase(blog)
string = self._prepare_string(string.encode('utf-8')) string = self._prepare_string(string)
wordlist = string.split(' ') wordlist = string.split(' ')
@ -207,8 +207,7 @@ class Search:
for post in hashtable[key]: for post in hashtable[key]:
res[post[0]] = res.get(post[0],0) + post[1] res[post[0]] = res.get(post[0],0) + post[1]
sorted_res = sorted(res.iteritems(), key=operator.itemgetter(1)) sorted_res = sorted(res.items(), key=operator.itemgetter(1), reverse=True)
sorted_res.reverse()
res = [sorted_res[i][0] for i in range(len(sorted_res))] res = [sorted_res[i][0] for i in range(len(sorted_res))]