Skip to content

Commit

Permalink
Use the 'html' when using python >= 3.8 in module __main__
Browse files Browse the repository at this point in the history
The 'cgi.escape' function was deprecated since Python 3.2. It has been
removed from Python 3.8.

Use 'html.escape' instead.

fix #36
  • Loading branch information
Damien Garaud committed Apr 26, 2021
1 parent 508b4c3 commit 4d9d5fc
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions justext/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import re
import os
import sys
import cgi
import six
try:
from html import escape
except ImportError:
from cgi import escape
import codecs

from .core import *
Expand Down Expand Up @@ -91,7 +95,7 @@ def output_default(paragraphs, fp=sys.stdout, no_boilerplate=True):
else:
tag = 'b'

print('<%s> %s' % (tag, cgi.escape(paragraph.text)), file=fp)
print('<%s> %s' % (tag, escape(paragraph.text, quote=False)), file=fp)


def output_detailed(paragraphs, fp=sys.stdout):
Expand All @@ -105,7 +109,7 @@ def output_detailed(paragraphs, fp=sys.stdout):
paragraph.cf_class,
int(paragraph.heading),
paragraph.xpath,
cgi.escape(paragraph.text)
escape(paragraph.text, quote=False)
)
print(output, file=fp)

Expand Down Expand Up @@ -150,7 +154,10 @@ def main():

stream_writer = codecs.lookup('utf8')[-1]
fp_in = sys.stdin
fp_out = stream_writer(sys.stdout)
if six.PY2:
fp_out = stream_writer(sys.stdout)
else:
fp_out = stream_writer(sys.stdout.buffer)
stoplist = None
format = 'default'
no_headings = False
Expand Down

0 comments on commit 4d9d5fc

Please sign in to comment.