diff options
-rw-r--r-- | _news_colors.py | 9 | ||||
-rwxr-xr-x | news.py | 2 |
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): @@ -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/>') |