logo

etc_portage

Unnamed repository; edit this file 'description' to name the repository. git clone https://hacktivis.me/git/etc_portage.git

index.html?h=contrib%2Ffix_crash_pipe (1656B)


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