The aux_db_template.check_key() method only checks if the key is an instance of "str". This should be "basestring" for unicode compatability. I found the bug while tracking down segfaults in the "porthole" program (a pyGTK GUI for emerge, using the portage API). If a unicode package name is passed to the aux_get routine then a nonsensical KeyError is raised (eg. KeyError: u'No key provided. key: control-center-2.8.2') and that key is removed from the aux_get database. Reproducible: Always Steps to Reproduce: 1. start python and import portage 2. set up any unicode package name (eg. package_name = u'gnome-base/control-center-2.8.2') 3. attempt portage.portdb.aux_get(package_name, ["IUSE"]) (or anything in portage.auxdbkeys) Actual Results: >>> e = u"gnome-base/control-center-2.8.2" >>> portage.portdb.aux_get(e,["IUSE"]) Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/portage/pym/portage.py", line 5239, in aux_get if doregen or not self.eclassdb.is_current(mylocation,cat,pkg,self.auxdb[mylocation][cat][pkg]["INHERITED"].split()): File "/usr/lib/portage/pym/portage.py", line 4980, in is_current if not (self.packages[location][cat].has_key(pkg) and self.packages[location][cat][pkg] and eclass_list): File "/usr/lib/portage/pym/portage_db_cpickle.py", line 37, in has_key self.check_key(key) File "/usr/lib/portage/pym/portage_db_template.py", line 44, in check_key raise KeyError, "No key provided. key: %s" % (key) KeyError: u'No key provided. key: control-center-2.8.2' >>> isinstance(e,str) False >>> isinstance(e,basestring) True Expected Results: >>> d = "gnome-base/control-center-2.8.2" >>> portage.portdb.aux_get(d,["IUSE"]) ['alsa gstreamer debug debug'] --- /usr/lib/portage/pym/portage_db_template.py 2005-03-26 17:57:07.000000000 +1200 +++ portage_db_template.py 2005-05-24 14:10:00.000000000 +1200 @@ -40,7 +40,7 @@ raise NotImplementedError("db_template.__init__ was overridden") def check_key(self,key): - if (not key) or not isinstance(key, str): + if (not key) or not isinstance(key, basestring): raise KeyError, "No key provided. key: %s" % (key) def clear(self):
There's a heap of work that needs to be done to make portage unicode compatible. No guarantees until there is an official API.
Admittedly the unicode wasn't meant to have been passed to portage in the first place. But that one line in portage_db_template.check_key() was the only place that seemed to be causing problems. This was just a problem with ascii being passed on in unicode format, not with an actual unicode name.
Created attachment 59712 [details, diff] a one line patch to portage_db_template.py
Need to check out python-2.2 compatibility on this one.
Created attachment 59847 [details, diff] patch compatible with python 2.2 Ahh, sorry. to be compatible with python 2.2 it would have to be "(isinstance(key, str) or (isinstance(key, unicode))" in stead of "isinstance(key, basestring)".
A crude regex showed 14 occurrences throughout portage of issues regarding type. However, there's probably other issues too. I don't really like the idea of making those 14 places into a test that takes over half a 80-char line though. Will keep this for later when we put together a supported API, which is already planned to be released with a requirement of python 2.3.
Closing due to old age.