summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-09-22 20:33:01 +0000
committerZac Medico <zmedico@gentoo.org>2009-09-22 20:33:01 +0000
commita60d0c7d4b7807bca6c18c11608fe42c6ca6c488 (patch)
tree59f117a7654e5c43468568511bbe17c2de1feb36
parentf6c5620a3e093567f6b5eff414a012607a39ca5c (diff)
downloadportage-a60d0c7d4b7807bca6c18c11608fe42c6ca6c488.tar.gz
portage-a60d0c7d4b7807bca6c18c11608fe42c6ca6c488.tar.bz2
portage-a60d0c7d4b7807bca6c18c11608fe42c6ca6c488.zip
Fix for python 3.x compatibility.
svn path=/main/trunk/; revision=14381
-rw-r--r--pym/portage/cache/anydbm.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/pym/portage/cache/anydbm.py b/pym/portage/cache/anydbm.py
index 143c321e1..6add2da60 100644
--- a/pym/portage/cache/anydbm.py
+++ b/pym/portage/cache/anydbm.py
@@ -3,7 +3,11 @@
# License: GPL2
# $Id$
-anydbm_module = __import__("anydbm")
+try:
+ anydbm_module = __import__("anydbm")
+except ImportError:
+ # python 3.x
+ import dbm as anydbm_module
try:
import cPickle as pickle
except ImportError:
@@ -31,8 +35,10 @@ class database(fs_template.FsBased):
self._db_path = os.path.join(self.location, fs_template.gen_label(self.location, self.label)+default_db)
self.__db = None
try:
- self.__db = anydbm_module.open(
- _unicode_encode(self._db_path), 'w', self._perms)
+ # dbm.open() will not work with bytes in python-3.1:
+ # TypeError: can't concat bytes to str
+ self.__db = anydbm_module.open(self._db_path,
+ 'w', self._perms)
except anydbm_module.error:
# XXX handle this at some point
try:
@@ -44,8 +50,10 @@ class database(fs_template.FsBased):
# try again if failed
try:
if self.__db == None:
- self.__db = anydbm_module.open(
- _unicode_encode(self._db_path), 'c', self._perms)
+ # dbm.open() will not work with bytes in python-3.1:
+ # TypeError: can't concat bytes to str
+ self.__db = anydbm_module.open(self._db_path,
+ 'c', self._perms)
except anydbm_module.error as e:
raise cache_errors.InitializationError(self.__class__, e)
self._ensure_access(self._db_path)