From a60d0c7d4b7807bca6c18c11608fe42c6ca6c488 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Tue, 22 Sep 2009 20:33:01 +0000 Subject: Fix for python 3.x compatibility. svn path=/main/trunk/; revision=14381 --- pym/portage/cache/anydbm.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'pym') 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) -- cgit v1.2.3-1-g7c22