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 May 14, 2021
1 parent 508b4c3 commit 89a9297
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
13 changes: 8 additions & 5 deletions justext/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import re
import os
import sys
import cgi

import codecs

from .core import *
from ._compat import urllib, URLError
from ._compat import urllib, URLError, escape, PY3


def usage():
Expand Down Expand Up @@ -91,7 +91,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 +105,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 +150,10 @@ def main():

stream_writer = codecs.lookup('utf8')[-1]
fp_in = sys.stdin
fp_out = stream_writer(sys.stdout)
if PY3:
fp_out = stream_writer(sys.stdout.buffer)
else:
fp_out = stream_writer(sys.stdout)
stoplist = None
format = 'default'
no_headings = False
Expand Down
7 changes: 7 additions & 0 deletions justext/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ def ignored(*exceptions):
yield
except tuple(exceptions):
pass


# note that cgi is depecrated and removed since 3.8
try:
from html import escape
except ImportError:
from cgi import escape

0 comments on commit 89a9297

Please sign in to comment.