index.html?h=contrib%2Ffix_crash_pipe (1656B)
- From 7e737993e1320b0a7ea82618cb8031e93d8b2e80 Mon Sep 17 00:00:00 2001
- From: Tanguy Ortolo <tanguy+debian@ortolo.eu>
- Date: Sun, 10 Mar 2019 15:27:25 +0100
- Subject: Fix an encoding crash when redirected to a pipe
- ITS Tool crashes when output is redirected to a pipe. This comes from
- Python not knowing the preferred encoding for stdout, and using ASCII by
- default, therefore failing to encode anything outside of it.
- This patch makes ITS Tool write to an UTF-8 encoding wrapper around
- stdout.
- ---
- itstool.in | 5 ++++-
- 1 file changed, 4 insertions(+), 1 deletion(-)
- diff --git a/itstool.in b/itstool.in
- index 5b0051f..592dc77 100755
- --- a/itstool.in
- +++ b/itstool.in
- @@ -48,6 +48,7 @@ if PY3:
- """Return a string that can be safely print()ed"""
- # Since print works on both bytes and unicode, just return the argument
- return s
- + uout = sys.stdout
- else:
- string_types = basestring,
- ustr = ustr_type = unicode
- @@ -60,6 +61,8 @@ else:
- # print may not work on unicode if the output encoding cannot be
- # detected, so just encode with UTF-8
- return unicode.encode(s, 'utf-8')
- + import codecs
- + uout = codecs.getwriter('utf-8')(sys.stdout)
- NS_ITS = 'http://www.w3.org/2005/11/its'
- NS_ITST = 'http://itstool.org/extensions/'
- @@ -1565,7 +1568,7 @@ if __name__ == '__main__':
- if opts.test is None:
- doc.generate_messages()
- if opts.output is None or opts.output == '-':
- - out = sys.stdout
- + out = uout
- else:
- try:
- out = io.open(opts.output, 'wt', encoding='utf-8')
- --
- cgit v1.1