summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-06-01 16:02:36 +0200
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-06-01 20:51:22 +0200
commit0a4383b895d169670a3c25c52dcab4e8e656f182 (patch)
tree6d0a6b73d4bb473a5c578d7c3123cded963b8284
parent1dc56421493df2b9016b0096998cd668a429ab9e (diff)
downloadtools-0a4383b895d169670a3c25c52dcab4e8e656f182.tar.gz
tools-0a4383b895d169670a3c25c52dcab4e8e656f182.tar.bz2
tools-0a4383b895d169670a3c25c52dcab4e8e656f182.tar.xz
tools-0a4383b895d169670a3c25c52dcab4e8e656f182.zip
news.py: Fixed error when using Python 3.8 or later
cgi.escape was removed in favour of html.escape.
-rw-r--r--_news_colors.py9
-rwxr-xr-xnews.py2
2 files changed, 8 insertions, 3 deletions
diff --git a/_news_colors.py b/_news_colors.py
index fd0782c..88bdc03 100644
--- a/_news_colors.py
+++ b/_news_colors.py
@@ -20,7 +20,12 @@
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
-import cgi
+try:
+ # py3
+ from html import escape as html_escape
+except ImportError:
+ # py2
+ from cgi import escape as html_escape
__all__ = ['make_html_colors_dict', 'make_txt_colors_dict', 'make_forum_colors_dict']
@@ -51,7 +56,7 @@ class HtmlDate(object):
class HtmlLink(object):
__slots__ = ()
def __format__(self, target):
- target = cgi.escape(target, True)
+ target = html_escape(target, True)
return '<a href="%s">%s</a>' % (target, target)
class HtmlSignature(object):
diff --git a/news.py b/news.py
index f5bbb52..531445a 100755
--- a/news.py
+++ b/news.py
@@ -124,7 +124,7 @@ class JSONWriter(BasicWriter):
entry, author = entry.rstrip('\n').rsplit('\n', 1)
self.stream.write('"title":"%s",' % title.format(**{'title':NOPFmt()})) # FIXME: assumes the first line is always the title
self.stream.write('"date":"%s",' % date.format(**{'date':NOPFmt()})) # FIXME: assumes the second line is always the date
- self.stream.write('"author":"%s",' % author.format(**{'author':NOPFmt()})) # FIXME: assumes the second line is always the date
+ self.stream.write('"author":"%s",' % author.format(**{'author':NOPFmt()})) # FIXME: assumes the last line is always the author
self.stream.write('"html":"')
entry = entry.lstrip('\n')
entry = entry.replace('\n\n', '<br/>')