diff options
author | Zac Medico <zmedico@gentoo.org> | 2009-08-04 23:07:57 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2009-08-04 23:07:57 +0000 |
commit | 15089fe0fb2e5ca78afaa66d45d06bc145f73fd5 (patch) | |
tree | 6499f4548d119074bfcceaea67e978b56c08cae2 | |
parent | 8198822a832c81d2346ef2725bad39022a7497cb (diff) | |
download | portage-15089fe0fb2e5ca78afaa66d45d06bc145f73fd5.tar.gz portage-15089fe0fb2e5ca78afaa66d45d06bc145f73fd5.tar.bz2 portage-15089fe0fb2e5ca78afaa66d45d06bc145f73fd5.zip |
Fix bindbapi.aux_get and aux_update to work with py3k/unicode.
svn path=/main/trunk/; revision=13911
-rw-r--r-- | pym/portage/dbapi/bintree.py | 37 |
1 files changed, 30 insertions, 7 deletions
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] |