diff options
-rw-r--r-- | pym/portage/cache/anydbm.py | 18 |
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) |