From 8e9f5eedc2c1a531b49f546c327bfa18fd42cfa5 Mon Sep 17 00:00:00 2001 From: lars Date: Tue, 16 Jun 2009 02:16:29 +0000 Subject: [PATCH] * use "hashlib" instead of "sha" (deprecated since python2.6) if available --- src/cryptobox/core/settings.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cryptobox/core/settings.py b/src/cryptobox/core/settings.py index 1bf1632..7ffe338 100644 --- a/src/cryptobox/core/settings.py +++ b/src/cryptobox/core/settings.py @@ -443,7 +443,15 @@ class CryptoBoxSettings: def __get_user_db(self): """Load the user database file if it exists. """ - import StringIO, sha + import StringIO + try: + # hashlib is available since python2.5 + import hashlib + get_hash_obj = lambda text: hashlib.sha1(text) + except ImportError: + # sha is deprecated since python2.6 + import sha + get_hash_obj = lambda text: sha.new(text) user_db_rules = StringIO.StringIO(self.userDatabaseSpec) try: try: @@ -468,7 +476,7 @@ class CryptoBoxSettings: ## validate and set default value for "admin" user user_db.validate(validate.Validator()) ## define password hash function - never use "sha" directly - SPOT - user_db.get_digest = lambda password: sha.new(password).hexdigest() + user_db.get_digest = lambda password: get_hash_obj(password).hexdigest() return user_db