Merge lp:~qzhang/lava-dispatcher/fix-unicode-encode-err into lp:lava-dispatcher

Proposed by Spring Zhang
Status: Rejected
Rejected by: Spring Zhang
Proposed branch: lp:~qzhang/lava-dispatcher/fix-unicode-encode-err
Merge into: lp:lava-dispatcher
Diff against target: 17 lines (+6/-1)
1 file modified
lava/dispatcher/client.py (+6/-1)
To merge this branch: bzr merge lp:~qzhang/lava-dispatcher/fix-unicode-encode-err
Reviewer Review Type Date Requested Status
Paul Larson (community) Needs Information
Zygmunt Krynicki (community) Needs Information
Review via email: mp+63083@code.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

Is self.serialio expecting binary strings or unicode strings? Do you do any extra manipulation on that string? This code seems to do nothing useful because:

1) Either the serial line expects unicode strings and the world is upside down (this is not likely)
2) The serial line is happy with any bytes you send it and you just corrupt the 8th bit for no good reason.

review: Needs Information
Revision history for this message
Paul Larson (pwlars) wrote :

11 + unicode_text = text.decode('ascii', 'replace')
12 + ascii_text = unicode_text.encode('ascii', 'replace')
I *think* it should not be necessary to do both of these, only one. The issue, as I understand it, is the mixture of 8-bit strings and unicode. Were you able to reliably reproduce what Michael was seeing so that you can know the fix works?

review: Needs Information
Revision history for this message
Spring Zhang (qzhang) wrote :

> 11 + unicode_text = text.decode('ascii', 'replace')
> 12 + ascii_text = unicode_text.encode('ascii', 'replace')
> I *think* it should not be necessary to do both of these, only one. The
> issue, as I understand it, is the mixture of 8-bit strings and unicode. Were
> you able to reliably reproduce what Michael was seeing so that you can know
> the fix works?
Only line 12 will raise the same exception, so I think it needs to decode then encode back to the original forms, or only decode is necessary?
I have met the exact issue which Michael met, and do some test after the commit and no such exception found.

Revision history for this message
Spring Zhang (qzhang) wrote :

> Is self.serialio expecting binary strings or unicode strings? Do you do any
> extra manipulation on that string? This code seems to do nothing useful
> because:
No extra manipulation on the string, except the code in this commit. self.SerialIO just catch the output of serial output text and put it to both logfile and StringIO, it doesn't expect unicode or other strings, the exception raises because StringIO can't mix 8bit and Unicode string, but it goes to StringIO if no handling.

>
> 1) Either the serial line expects unicode strings and the world is upside down
> (this is not likely)
We can also encode it by Unicode not Ascii, we can determine it if unicode is more compatible.

> 2) The serial line is happy with any bytes you send it and you just corrupt
> the 8th bit for no good reason.
Exactly for serial line but StringIO won't accept mixed strings. And most characters from serial line are 8bit and StringIO corrupt with a Unicode byte.

Revision history for this message
Loïc Minier (lool) wrote :

Is this still active?

Revision history for this message
Spring Zhang (qzhang) wrote :

Ah, yes, but I can't meet the bug(#788846) when I use LAVA now, I'd like the submitter to verify if it's also ok now?

Revision history for this message
Paul Larson (pwlars) wrote :

I believe this was fixed already, please let me know if you see it again though.

Revision history for this message
Spring Zhang (qzhang) wrote :

Could you point out the branch which fixes it? I'm curious.

Revision history for this message
Loïc Minier (lool) wrote :

Should we reject this mp?

Revision history for this message
Spring Zhang (qzhang) wrote :

The issue is already fixed by some uncertain code change.

Unmerged revisions

60. By Spring Zhang

Fix error "UnicodeDecodeError: 'ascii' codec can't decode" when get_value in StringIO

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lava/dispatcher/client.py'
2--- lava/dispatcher/client.py 2011-05-26 22:31:59 +0000
3+++ lava/dispatcher/client.py 2011-06-01 09:22:03 +0000
4@@ -120,7 +120,12 @@
5 self.logfile = logfile
6
7 def write(self, text):
8- self.serialio.write(text)
9+ #in case characters which are not in rage(0..128)
10+ #throwing UnicodeEncodeError when get_value() from SerialIO
11+ unicode_text = text.decode('ascii', 'replace')
12+ ascii_text = unicode_text.encode('ascii', 'replace')
13+ self.serialio.write(ascii_text)
14+ #let logfile to record all logs
15 self.logfile.write(text)
16
17 def close(self):

Subscribers

People subscribed via source and target branches