[PackageKit: 7/8] fix yum encoding issues seen with kpackagekit (#668282)

Nils Philippsen nphilipp at fedoraproject.org
Thu Oct 27 10:57:38 UTC 2011


commit 132d5632b640ea62d716d7e574ed632a02042013
Author: Nils Philippsen <nils at redhat.com>
Date:   Thu Oct 27 12:45:08 2011 +0200

    fix yum encoding issues seen with kpackagekit (#668282)

 PackageKit-0.6.19-yum-encoding.patch |  110 ++++++++++++++++++++++++++++++++++
 PackageKit.spec                      |    9 +++-
 2 files changed, 118 insertions(+), 1 deletions(-)
---
diff --git a/PackageKit-0.6.19-yum-encoding.patch b/PackageKit-0.6.19-yum-encoding.patch
new file mode 100644
index 0000000..6073b0b
--- /dev/null
+++ b/PackageKit-0.6.19-yum-encoding.patch
@@ -0,0 +1,110 @@
+From a7d50f5f4a9f69e33075fbe05d4ae42158d1b9c9 Mon Sep 17 00:00:00 2001
+From: Nils Philippsen <nils at redhat.com>
+Date: Wed, 26 Oct 2011 17:31:36 +0200
+Subject: [PATCH 1/2] python: implement and use utf8 stream writer for stdout,
+ stderr
+
+The C-side (glib) really wants stuff to be encoded in UTF-8.
+(cherry picked from commit b5a5011f31d6062cd00ee6b02ddf356d691e67e6)
+---
+ lib/python/packagekit/backend.py |   45 ++++++++++++++++++++++++++++++++++++++
+ 1 files changed, 45 insertions(+), 0 deletions(-)
+
+diff --git a/lib/python/packagekit/backend.py b/lib/python/packagekit/backend.py
+index ae7bbad..4c7fd2c 100644
+--- a/lib/python/packagekit/backend.py
++++ b/lib/python/packagekit/backend.py
+@@ -37,8 +37,49 @@ def _to_unicode(txt, encoding='utf-8'):
+             txt = unicode(txt, encoding, errors='replace')
+     return txt
+ 
++def _to_utf8(txt, errors='replace'):
++    '''convert practically anything to a utf-8-encoded byte string'''
++
++    # convert to unicode object
++    if isinstance(txt, str):
++        txt = txt.decode('utf-8', errors=errors)
++    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=errors)
++        except:
++            # no __str__(), __unicode__() methods, use representation
++            txt = unicode(repr(txt))
++
++    # return encoded as UTF-8
++    return txt.encode('utf-8', errors=errors)
++
+ # Classes
+ 
++class _UTF8Writer(codecs.StreamWriter):
++
++    encoding = 'utf-8'
++
++    def __init__(self, stream, errors='replace'):
++        codecs.StreamWriter.__init__(self, stream, errors)
++
++    def encode(self, inp, errors='strict'):
++        try:
++            l = len(inp)
++        except TypeError:
++            try:
++                l = len(unicode(inp))
++            except:
++                try:
++                    l = len(str(inp))
++                except:
++                    l = 1
++        return (_to_utf8(inp, errors=errors), l)
++
+ class PkError(Exception):
+     def __init__(self, code, details):
+         self.code = code
+@@ -49,6 +90,10 @@ class PkError(Exception):
+ class PackageKitBaseBackend:
+ 
+     def __init__(self, cmds):
++        # Make sys.stdout/stderr cope with UTF-8
++        sys.stdout = _UTF8Writer(sys.stdout)
++        sys.stderr = _UTF8Writer(sys.stderr)
++
+         # Setup a custom exception handler
+         installExceptionHandler(self)
+         self.cmds = cmds
+-- 
+1.7.6.4
+
+
+From 01226fbdfc6cd9f03183048c7531ed324d4b5412 Mon Sep 17 00:00:00 2001
+From: Nils Philippsen <nils at redhat.com>
+Date: Wed, 26 Oct 2011 17:33:18 +0200
+Subject: [PATCH 2/2] yum: don't let yum.misc.setup_locale() override stdout
+ codec
+
+Use our own stdout/stderr wrappers, as what codecs.getwriter() supplies
+only works for unicode, but not for already encoded data.
+(cherry picked from commit 31b9a6942a65f8eeeb67c6ea376429e8c5eac43f)
+---
+ backends/yum/yumBackend.py |    2 +-
+ 1 files changed, 1 insertions(+), 1 deletions(-)
+
+diff --git a/backends/yum/yumBackend.py b/backends/yum/yumBackend.py
+index 479ee2d..dfed1a2 100755
+--- a/backends/yum/yumBackend.py
++++ b/backends/yum/yumBackend.py
+@@ -3482,7 +3482,7 @@ class PackageKitYumBase(yum.YumBase):
+             raise PkError(ERROR_FAILED_CONFIG_PARSING, _to_unicode(e))
+ 
+         # setup to use LANG for descriptions
+-        yum.misc.setup_locale(override_time=True)
++        yum.misc.setup_locale(override_time=True, override_codecs=False)
+ 
+         self.missingGPGKey = None
+         self.dsCallback = DepSolveCallback(backend)
+-- 
+1.7.6.4
+
diff --git a/PackageKit.spec b/PackageKit.spec
index 2f793fb..3c6dc68 100644
--- a/PackageKit.spec
+++ b/PackageKit.spec
@@ -3,7 +3,7 @@
 Summary:   Package management service
 Name:      PackageKit
 Version:   0.6.19
-Release:   2%{?dist}
+Release:   3%{?dist}
 License:   GPLv2+ and LGPLv2+
 URL:       http://www.packagekit.org
 Source0:   http://www.packagekit.org/releases/%{name}-%{version}.tar.xz
@@ -14,6 +14,9 @@ Patch0:    PackageKit-0.3.8-Fedora-Vendor.conf.patch
 # Fedora specific: the yum backend doesn't do time estimation correctly
 Patch1:    PackageKit-0.4.4-Fedora-turn-off-time.conf.patch
 
+# upstream fix
+Patch2:    PackageKit-0.6.19-yum-encoding.patch
+
 Requires: PackageKit-glib = %{version}-%{release}
 Requires: PackageKit-backend
 Requires: shared-mime-info
@@ -250,6 +253,7 @@ user to restart the computer or remove and re-insert the device.
 %setup -q
 %patch0 -p1 -b .fedora
 %patch1 -p1 -b .no-time
+%patch2 -p1 -b .yum-encoding
 
 %build
 %configure \
@@ -463,6 +467,9 @@ update-mime-database %{_datadir}/mime &> /dev/null || :
 %{_includedir}/PackageKit/backend/*.h
 
 %changelog
+* Thu Oct 27 2011 Nils Philippsen <nils at redhat.com> - 0.6.19-3
+- fix yum encoding issues seen with kpackagekit (#668282)
+
 * Tue Oct 04 2011 Richard Hughes  <rhughes at redhat.com> - 0.6.19-2
 - It turns out the buildroot overrides take longer than just waiting
   for "koji wait-repo f16-build"


More information about the scm-commits mailing list