Fixed another portion of incompatibilities with Python 2 (for "make html").
--- a/py/gadialog_html.py Wed Sep 01 10:13:16 2021 +0300
+++ b/py/gadialog_html.py Wed Sep 01 10:38:30 2021 +0300
@@ -4,7 +4,7 @@
import io
import sys
import codecs
-import html
+from xml.sax.saxutils import escape
import gadialog
@@ -43,7 +43,7 @@
################################################################
-HTML_HEADER = """<!DOCTYPE html>
+HTML_HEADER = u"""<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
@@ -64,7 +64,7 @@
</html>
"""
-NAME = html.escape("Dialogs")
+NAME = escape("Dialogs")
FOUT.write(HTML_HEADER.format(title=NAME))
FOUT.write("<h1>{} dictionary</h1>\n".format(NAME))
@@ -74,7 +74,7 @@
FOUT.write("<ul>\n")
odd = True
for line in lines:
- FOUT.write('<li class="{:s}">{:s}</li>\n'.format("odd" if odd else "even", html.escape(line)))
+ FOUT.write(u'<li class="{:s}">{:s}</li>\n'.format("odd" if odd else "even", escape(line)))
odd = not odd
FOUT.write("</ul>")
--- a/py/gadict_html.py Wed Sep 01 10:13:16 2021 +0300
+++ b/py/gadict_html.py Wed Sep 01 10:38:30 2021 +0300
@@ -5,7 +5,7 @@
import sys
import codecs
import re
-import html
+from xml.sax.saxutils import escape
import gadict
import gadict_freq
@@ -67,7 +67,7 @@
try:
DOM = PARSER.parse(FIN)
except gadict.ParseException as ex:
- sys.stdout.write("{:s}{:s}\n".format(FINAME, repr(ex)))
+ sys.stdout.write(u"{:s}{:s}\n".format(FINAME, repr(ex)))
if __debug__:
import traceback
traceback.print_exc()
@@ -111,36 +111,36 @@
"""
FOUT.write(HTML_HEADER.format(title=PRELUDE.name))
-FOUT.write("<h1>{} dictionary</h1>\n".format(html.escape(PRELUDE.name)))
+FOUT.write(u"<h1>{} dictionary</h1>\n".format(escape(PRELUDE.name)))
# FOUT.write("<a href='{}'>Home page</a>")
# FOUT.write(" , ".join(PRELUDE.urls))
FOUT.write("<p>License: ")
-FOUT.write(html.escape(", ".join(PRELUDE.licences)))
+FOUT.write(escape(", ".join(PRELUDE.licences)))
# FOUT.write("</p>\n<p>")
-# FOUT.write(html.escape(PRELUDE.about))
+# FOUT.write(escape(PRELUDE.about))
FOUT.write("</p>\n")
def link(lst):
buf = []
for el in lst:
- el = html.escape(el)
- lnk = "<a href='#{}'>{}</a>".format(el, el)
+ el = escape(el)
+ lnk = u"<a href='#{}'>{}</a>".format(el, el)
buf.append(lnk)
return "; ".join(buf)
for (headwords, translations) in DOM[1:]:
identity = headwords[0].headword
- FOUT.write("<div id='{}' class='article'>\n".format(html.escape(identity)))
+ FOUT.write(u"<div id='{}' class='article'>\n".format(escape(identity)))
for hw in headwords:
FOUT.write("<div>")
- FOUT.write("<span class='head'>{}</span>".format(html.escape(hw.headword)))
+ FOUT.write(u"<span class='head'>{}</span>".format(escape(hw.headword)))
if hw.pron is not None:
FOUT.write(" <span class='pron'>[")
- FOUT.write(html.escape(hw.pron))
+ FOUT.write(escape(hw.pron))
FOUT.write("]</span>")
if len(hw.attrs) > 0:
FOUT.write(" <span class='attr'>")
- l = ["«"+x+"»" for x in hw.attrs]
+ l = [u"«" + x + u"»" for x in hw.attrs]
l.sort()
FOUT.write(", ".join(l))
FOUT.write("</span>")
@@ -154,13 +154,13 @@
raise Exception("""Empty sense for article: """ + headwords.__iter__().__next__())
FOUT.write("<div class='sense'>")
if sense.pos:
- FOUT.write("<span class='pos'>«")
- FOUT.write(html.escape(sense.pos))
- FOUT.write("»</span> ")
+ FOUT.write(u"<span class='pos'>«")
+ FOUT.write(escape(sense.pos))
+ FOUT.write(u"»</span> ")
need_sep = False
if sense.topic_list and len(sense.topic_list) > 0:
FOUT.write("<span class='topic'>")
- FOUT.write(html.escape(", ".join(sense.topic_list)))
+ FOUT.write(escape(", ".join(sense.topic_list)))
FOUT.write("</span>")
need_sep = True
if sense.ant_list and len(sense.ant_list) > 0:
@@ -192,24 +192,24 @@
continue
FOUT.write("<div>")
if not LANGS or len(LANGS) > 1:
- FOUT.write("<span class='lang tr'>{}</span> ".format(html.escape(lang)))
- FOUT.write("<span class='tr'>{}</span>".format(html.escape(tr)))
+ FOUT.write(u"<span class='lang tr'>{}</span> ".format(escape(lang)))
+ FOUT.write(u"<span class='tr'>{}</span>".format(escape(tr)))
FOUT.write("</div>")
for (lang, tr) in sense.glos_list or []:
if LANGS and lang not in LANGS:
continue
FOUT.write("<div>")
if not LANGS or len(LANGS) > 1:
- FOUT.write("<span class='lang glos'>{}</span> ".format(html.escape(lang)))
- FOUT.write("<span class='glos'>{}</span>".format(html.escape(tr)))
+ FOUT.write(u"<span class='lang glos'>{}</span> ".format(escape(lang)))
+ FOUT.write(u"<span class='glos'>{}</span>".format(escape(tr)))
FOUT.write("</div>")
for (lang, tr) in sense.ex_list or []:
if LANGS and lang not in LANGS:
continue
FOUT.write("<div>")
if not LANGS or len(LANGS) > 1:
- FOUT.write("<span class='lang ex'>{}</span> ".format(html.escape(lang)))
- FOUT.write("<span class='ex'>{}</span>".format(html.escape(tr)))
+ FOUT.write(u"<span class='lang ex'>{}</span> ".format(escape(lang)))
+ FOUT.write(u"<span class='ex'>{}</span>".format(escape(tr)))
FOUT.write("</div>")
FOUT.write("</div>")
freqtags = []
@@ -218,7 +218,7 @@
freqtags.append(freqtag)
if len(freqtags) > 0:
FOUT.write("<p class='freq'>")
- FOUT.write(html.escape(",".join(freqtags)))
+ FOUT.write(escape(",".join(freqtags)))
FOUT.write("</p>")
FOUT.write("</div>")