From 15089fe0fb2e5ca78afaa66d45d06bc145f73fd5 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Tue, 4 Aug 2009 23:07:57 +0000 Subject: Fix bindbapi.aux_get and aux_update to work with py3k/unicode. svn path=/main/trunk/; revision=13911 --- pym/portage/dbapi/bintree.py | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'pym') diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py index b1a78f36c..38d5367b1 100644 --- a/pym/portage/dbapi/bintree.py +++ b/pym/portage/dbapi/bintree.py @@ -24,6 +24,7 @@ from portage import dep_expand, listdir, _check_distfile, _movefile import codecs import os, errno, stat import re +import sys from itertools import chain, izip class bindbapi(fakedbapi): @@ -66,7 +67,12 @@ class bindbapi(fakedbapi): tbz2_path = self.bintree.getname(mycpv) if not os.path.exists(tbz2_path): raise KeyError(mycpv) - getitem = portage.xpak.tbz2(tbz2_path).getfile + tbz2 = portage.xpak.tbz2(tbz2_path) + def getitem(k): + v = tbz2.getfile(k) + if v is not None and not isinstance(v, unicode): + v = unicode(v, encoding='utf_8', errors='replace') + return v else: getitem = self.bintree._remotepkgs[mycpv].get mydata = {} @@ -79,15 +85,16 @@ class bindbapi(fakedbapi): # or the tbz2 is corrupt. if myval: mydata[x] = " ".join(myval.split()) - if "EAPI" in mykeys: - if not mydata.setdefault("EAPI", "0"): - mydata["EAPI"] = "0" + + if not mydata.setdefault('EAPI', u'0'): + mydata['EAPI'] = u'0' + if cache_me: aux_cache = self._aux_cache_slot_dict() for x in self._aux_cache_keys: - aux_cache[x] = mydata.get(x, "") + aux_cache[x] = mydata.get(x, u'') self._aux_cache[mycpv] = aux_cache - return [mydata.get(x, "") for x in wants] + return [mydata.get(x, u'') for x in wants] def aux_update(self, cpv, values): if not self.bintree.populated: @@ -97,7 +104,23 @@ class bindbapi(fakedbapi): raise KeyError(cpv) mytbz2 = portage.xpak.tbz2(tbz2path) mydata = mytbz2.get_data() - mydata.update(values) + + if sys.hexversion < 0x3000000: + for k, v in values.iteritems(): + if isinstance(k, unicode): + k = k.encode('utf_8', 'replace') + if isinstance(v, unicode): + v = v.encode('utf_8', 'replace') + mydata[k] = v + + else: + for k, v in values.iteritems(): + if isinstance(k, str): + k = k.encode('utf_8', 'replace') + if isinstance(v, str): + v = v.encode('utf_8', 'replace') + mydata[k] = v + for k, v in mydata.items(): if not v: del mydata[k] -- cgit v1.2.3-1-g7c22