Merge lp:~jameinel/hydrazine/bug_612641_encoding into lp:hydrazine

Proposed by John A Meinel
Status: Merged
Approved by: Martin Pool
Approved revision: 78
Merged at revision: 85
Proposed branch: lp:~jameinel/hydrazine/bug_612641_encoding
Merge into: lp:hydrazine
Diff against target: 17 lines (+6/-1)
1 file modified
feed-pqm (+6/-1)
To merge this branch: bzr merge lp:~jameinel/hydrazine/bug_612641_encoding
Reviewer Review Type Date Requested Status
hydrazine-core Pending
Review via email: mp+37317@code.launchpad.net

Commit message

Encode to ascii if we can't print the comment normally.

Description of the change

An attempt to avoid encoding failures crashing feed-pqm completely.

Ideally we'd do something based on sys.stdout.encoding or whatever. But since we are just doing "print", I just did the easy hack.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

I think this if fine as a stop-script-throwing-so-I-can-work hack. As a proper fix, how about using the bzr ui object rather than print as I had to init it anyway to get password promting working earlier?

Revision history for this message
Martin Pool (mbp) wrote :

On 4 October 2010 19:39, Martin [gz] <email address hidden> wrote:
> I think this if fine as a stop-script-throwing-so-I-can-work hack. As a proper fix, how about using the bzr ui object rather than print as I had to init it anyway to get password promting working earlier?

mm, it would probably be better to write everything to a stream with
(get_terminal_encoding(), 'replace').

--
Martin

Revision history for this message
Martin Packman (gz) wrote :

I was thinking the ui object would do that step for us, like here:

    def prompt(self, prompt, **kwargs):
        """Emit prompt on the CLI.

        :param kwargs: Dictionary of arguments to insert into the prompt,
            to allow UIs to reformat the prompt.
        """
        if kwargs:
            # See <https://launchpad.net/bugs/365891>
            prompt = prompt % kwargs
        prompt = prompt.encode(osutils.get_terminal_encoding(), 'replace')
        self.clear_term()
        self.stderr.write(prompt)

But it seems most of the methods aren't actually that careful with unicode vs. str and could do with sorting out.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'feed-pqm'
2--- feed-pqm 2010-06-28 19:13:18 +0000
3+++ feed-pqm 2010-10-01 21:08:46 +0000
4@@ -102,7 +102,12 @@
5 print "Recent comments:"
6 comments = list(mp.all_comments) #XXX: See bug lp:583761
7 for comment in comments[-1:]:
8- print "%s: %s" % (comment.author.name, comment.message_body)
9+ val = "%s: %s" % (comment.author.name, comment.message_body)
10+ try:
11+ print val
12+ except UnicodeError:
13+ val = val.encode('ascii', 'replace')
14+ print val
15
16
17 def set_message(mp):

Subscribers

People subscribed via source and target branches

to all changes: