* [gentoo-commits] portage r13911 - main/trunk/pym/portage/dbapi
@ 2009-08-04 23:07 Zac Medico (zmedico)
0 siblings, 0 replies; only message in thread
From: Zac Medico (zmedico) @ 2009-08-04 23:07 UTC (permalink / raw
To: gentoo-commits
Author: zmedico
Date: 2009-08-04 23:07:57 +0000 (Tue, 04 Aug 2009)
New Revision: 13911
Modified:
main/trunk/pym/portage/dbapi/bintree.py
Log:
Fix bindbapi.aux_get and aux_update to work with py3k/unicode.
Modified: main/trunk/pym/portage/dbapi/bintree.py
===================================================================
--- main/trunk/pym/portage/dbapi/bintree.py 2009-08-04 22:45:47 UTC (rev 13910)
+++ main/trunk/pym/portage/dbapi/bintree.py 2009-08-04 23:07:57 UTC (rev 13911)
@@ -24,6 +24,7 @@
import codecs
import os, errno, stat
import re
+import sys
from itertools import chain, izip
class bindbapi(fakedbapi):
@@ -66,7 +67,12 @@
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 @@
# 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 @@
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]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-08-04 23:08 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-04 23:07 [gentoo-commits] portage r13911 - main/trunk/pym/portage/dbapi Zac Medico (zmedico)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox