aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Vilcans <martin@librador.com>2020-02-12 23:12:09 +0100
committerGitHub <noreply@github.com>2020-02-12 23:12:09 +0100
commit1f2121726e709c8445ecd793eca89387d5b78145 (patch)
tree4d1a59e997103d4343736d6646d5949c6a7d01ba
parenta45b649c175c12be9fb6f8b51854cf3076b5e1bc (diff)
parente946ac7cdb4e61458502da629d79d78cac22d060 (diff)
downloadscreenplain-1f2121726e709c8445ecd793eca89387d5b78145.tar.gz
Merge pull request #56 from jstasiak/python38-compat
Fix Python 3/3.8 compatibility
-rw-r--r--screenplain/main.py4
-rw-r--r--screenplain/richstring.py8
2 files changed, 8 insertions, 4 deletions
diff --git a/screenplain/main.py b/screenplain/main.py
index aaad69c..9f337f1 100644
--- a/screenplain/main.py
+++ b/screenplain/main.py
@@ -109,9 +109,9 @@ def main(args):
output = open(output_file, 'wb')
else:
if output_encoding:
- output = codecs.getwriter(output_encoding)(sys.stdout)
+ output = codecs.getwriter(output_encoding)(sys.stdout.buffer)
else:
- output = sys.stdout
+ output = sys.stdout.buffer
try:
if format == 'text':
diff --git a/screenplain/richstring.py b/screenplain/richstring.py
index 806787e..2fafd9b 100644
--- a/screenplain/richstring.py
+++ b/screenplain/richstring.py
@@ -3,9 +3,13 @@
# http://www.opensource.org/licenses/mit-license.php
import re
-import cgi
import six
+try:
+ from html import escape as html_escape
+except ImportError:
+ from cgi import escape as html_escape
+
_magic_re = re.compile(u'[\ue700-\ue705]')
@@ -14,7 +18,7 @@ def _escape(s):
and non-ascii characters with ampersand escapes.
"""
- encoded = cgi.escape(s).encode('ascii', 'xmlcharrefreplace')
+ encoded = html_escape(s, quote=False).encode('ascii', 'xmlcharrefreplace')
# In Py3, encoded is bytes type, so convert it to a string
return encoded.decode('ascii')