Please do not reply directly to this email. All additional
comments should be made in the comments box of this bug.
https://bugzilla.redhat.com/show_bug.cgi?id=668282
--- Comment #37 from Toshio Ernie Kuratomi <a.badger(a)gmail.com> 2011-10-24 17:06:31
EDT ---
Created attachment 529967
-->
https://bugzilla.redhat.com/attachment.cgi?id=529967
UNTESTED patch that adds more robustness on top of Kevin's fix
Looks decent. It seems like there's a few assumptions in the original code
that you're porting that might not bear out in practice. Here's a slightly
revised patch that uses python-kitchen's to_unicode and to_bytes methods. Also
untested but it should be more robust in corner cases. (One of which, passing
an object to to_unicode/to_utf8 is sprinkled quite liberally throughout this
patch :-)
The get_update_detail() function looks like it would benefit from a rewrite
with a determination to not mix unicode string and byte str types together but
I didn't want to get too invasive with a patch this close to the deadline.
The assumption I'm making is that the APIs that we're using here must all be
utf-8 encoded bytes (neither python unicode type nor other encodings (like
shift-js, big5, or latin-1) would work). With that in mind, we need to be more
pedantic about just what data we're passing through. (Making sure to convert
byte strings which are not utf-8 encoded into utf-8.)
Also, constructions like:
try:
raise Exception('café')
except Exception, e:
self.error('%s' % _to_unicode(e))
wouldn't do the right thing under the old code. (the "e" variable would be
an
exception object so the _to_unicode()/_to_utf8() function in yumBackend.py
would have passed that object through to the string format unchanged. That
could have raised an exception depending on the user's locale settings, the
exception message, and whether that message was a unicode string or a byte
str.) Porting to the kitchen to_bytes() function fixes that as to_bytes() will
convert an object to a str representation of the object.
Note that my changes are just to help prevent issues that were present in the
original code and in the simple port by Kevin don't suddenly raise tracebacks
at a later point. The actual fixing of this particular bug looks like it would
be fixed via the logical changes that Kevin's patch makes. This is just a more
robust implementation of those changes.
There are ways that someone who knows the code can optimize this better. If
you know that a function will always be given wither a unicode string or a byte
str of type utf8, you can simply call to_bytes() on it instead of doing
to_bytes(to_unicode()). Similarly, if my blanket assumption about all APIs
being called here needing byte str of encoding utf8, you can optimize aways
some of the function calls.
--
Configure bugmail:
https://bugzilla.redhat.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.