Merge lp:~kissiel/checkbox/fix-unicode into lp:checkbox

Proposed by Maciej Kisielewski
Status: Merged
Approved by: Maciej Kisielewski
Approved revision: 4113
Merged at revision: 4112
Proposed branch: lp:~kissiel/checkbox/fix-unicode
Merge into: lp:checkbox
Diff against target: 27 lines (+10/-2)
1 file modified
plainbox/plainbox/impl/exporter/__init__.py (+10/-2)
To merge this branch: bzr merge lp:~kissiel/checkbox/fix-unicode
Reviewer Review Type Date Requested Status
Maciej Kisielewski Approve
Review via email: mp+278478@code.launchpad.net

Description of the change

This MR solves a bunch of problems that happened on systems with bad locale settings.

Instead of crashing, checkbox-cli now displays a warning and ignores characters that cannot be printed.

To test it run: $ LC_ALL=en_US checkbox-cli, select any test plan and proceed till finish.

For terminals with utf-8 encoding, behaviour is unchanged.

68efedb plainbox:exporter: ignore non-printable characters on certain terminals
f70908b plainbox:exporter: fix PEP-8 issue

To post a comment you must log in.
Revision history for this message
Maciej Kisielewski (kissiel) wrote :

Self-approving, as it was reviewed here: https://code.launchpad.net/~kissiel/checkbox/fix-unicode/+merge/277553, but due to broken pushes it reverted the patches, and LP marked the MR as merged.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plainbox/plainbox/impl/exporter/__init__.py'
2--- plainbox/plainbox/impl/exporter/__init__.py 2015-07-16 21:25:01 +0000
3+++ plainbox/plainbox/impl/exporter/__init__.py 2015-11-24 16:47:35 +0000
4@@ -31,8 +31,6 @@
5 from logging import getLogger
6 import base64
7
8-import pkg_resources
9-
10 from plainbox.i18n import gettext as _
11 from plainbox.abc import ISessionStateExporter
12 from plainbox.impl import deprecated
13@@ -380,4 +378,14 @@
14 object's specified encoding prior to writing.
15 :param data: the chunk of data to write.
16 """
17+ if (self.dest_stream.encoding and
18+ self.dest_stream.encoding.lower() != self.encoding.lower()):
19+ logger.warning(
20+ _("Incorrect stream encoding. Got %s, expected %s. "
21+ " some characters won't be printed"),
22+ self.dest_stream.encoding, self.encoding)
23+ # fall back to ASCII encoding
24+ return self.dest_stream.write(data.decode(
25+ 'ascii', errors='ignore'))
26+
27 return self.dest_stream.write(data.decode(self.encoding))

Subscribers

People subscribed via source and target branches