diff options
author | Lars Wirzenius <liw@liw.fi> | 2016-02-20 10:25:47 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2016-02-20 10:54:20 +0200 |
commit | 2281a8af22f037969524dfeceb6e19f105183222 (patch) | |
tree | 341bc471daec791138b66bdfe69f032646b855c0 | |
parent | 9276bb50ec08489e463bd0be8cc4995e83ed8af6 (diff) | |
download | distix-2281a8af22f037969524dfeceb6e19f105183222.tar.gz |
Fix showing non-ASCII text
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | distixlib/plugins/list_plugin.py | 4 | ||||
-rw-r--r-- | distixlib/plugins/show_plugin.py | 11 | ||||
-rw-r--r-- | yarns/040-new.yarn | 6 |
4 files changed, 18 insertions, 6 deletions
@@ -10,6 +10,9 @@ Version 0.3+git, not yet released * New command `distix import-maildir` imports mails from a Maildir folder. +* Various problems showing text not in ASCII have been fixed. There + may be more lurking about. + Version 0.3, released 2016-01-08 -------------------------------- diff --git a/distixlib/plugins/list_plugin.py b/distixlib/plugins/list_plugin.py index 8406480..232b776 100644 --- a/distixlib/plugins/list_plugin.py +++ b/distixlib/plugins/list_plugin.py @@ -17,6 +17,7 @@ import glob +import locale import os import cliapp @@ -64,6 +65,7 @@ class ListPlugin(cliapp.Plugin): def _list_ticket(self, ticket): ticket_id = ticket.get_ticket_id() - title = ticket.get_title() + _, encoding = locale.getdefaultlocale() + title = ticket.get_title().encode(encoding or 'UTF8') self.app.output.write( '{ticket_id} {title}\n'.format(ticket_id=ticket_id, title=title)) diff --git a/distixlib/plugins/show_plugin.py b/distixlib/plugins/show_plugin.py index 6fa3e95..4858ee4 100644 --- a/distixlib/plugins/show_plugin.py +++ b/distixlib/plugins/show_plugin.py @@ -16,6 +16,7 @@ # =*= License: GPL-3+ =*= +import locale import os import uuid @@ -27,7 +28,7 @@ import distixlib class ShowTicketPlugin(cliapp.Plugin): - _template = '''\ + _template = u'''\ % title = metadata.get_first_value('title') {{ticket_id}}: {{title}} @@ -38,7 +39,7 @@ class ShowTicketPlugin(cliapp.Plugin): % end % for msg in msgs: -{{msg.get_payload(decode=True)}} +{{unicode(msg.get_payload(decode=True), encoding, 'ignore')}} % end ''' @@ -65,8 +66,12 @@ class ShowTicketPlugin(cliapp.Plugin): def _show_ticket(self, template, ticket): ticket_id = ticket.get_ticket_id() + _, encoding = locale.getdefaultlocale() + if encoding is None: + encoding = 'UTF8' rendered = template.render( + encoding=encoding, ticket_id=ticket_id, metadata=ticket.get_ticket_metadata(), msgs=ticket.get_messages()) - self.app.output.write(rendered) + self.app.output.write(rendered.encode(encoding)) diff --git a/yarns/040-new.yarn b/yarns/040-new.yarn index 4777fdb..fc2bff8 100644 --- a/yarns/040-new.yarn +++ b/yarns/040-new.yarn @@ -13,10 +13,12 @@ This chapter has scenarios for creating new tickets. THEN attempt succeeded AND output is "" - WHEN user attempts to run distix new new-ticket-title +We create a new ticket, with a title that contains non-ASCII text. + + WHEN user attempts to run distix new new-ticket-title-gröt THEN attempt succeeded AND everything in REPO is committed to git WHEN user attempts to run distix list THEN attempt succeeded - AND output matches "^[0-9a-f]{32} new-ticket-title$" + AND output matches "^[0-9a-f]{32} new-ticket-title-gröt$" |