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 #41 from Nils Philippsen <nphilipp(a)redhat.com> 2011-10-25 08:54:35 EDT
---
Here's the pimped version of _to_utf8() I plan to commit:
--- 8< ---
def _to_utf8(txt):
'''convert practically anything to a utf-8-encoded byte
string'''
# convert to unicode object
if isinstance(txt, str):
txt = txt.decode('utf-8', errors='replace')
if not isinstance(txt, basestring):
# try to convert non-string objects like exceptions
try:
# if txt.__unicode__() exists, or txt.__str__() returns ASCII
txt = unicode(txt)
except UnicodeDecodeError:
# if txt.__str__() exists
txt = str(txt).decode('utf-8', errors='replace')
except:
# no __str__(), __unicode__() methods, use representation
txt = unicode(repr(txt))
# return encoded as UTF-8
return txt.encode('utf-8', errors='replace')
--- >8 ---
I've noticed that the packagekit python module also uses unicode objects
instead of UTF-8 encoded strings, but for the moment I'll assume this is in
order and works.
--
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.