aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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')