From: Barış Metin Date: Wed, 10 Feb 2010 16:23:46 +0000 (+0000) Subject: fallback to old modules for centos5 (python 2.4) X-Git-Tag: PLCAPI-5.0-2^2~1 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=65056a32be3655c4bd4793bdde02ac465bc62d84;p=plcapi.git fallback to old modules for centos5 (python 2.4) --- diff --git a/PLC/Auth.py b/PLC/Auth.py index 945c8ce5..08c9d2cf 100644 --- a/PLC/Auth.py +++ b/PLC/Auth.py @@ -9,7 +9,10 @@ # import crypt -import hashlib +try: + from hashlib import sha1 as sha +except ImportError: + import sha import hmac import time @@ -257,7 +260,7 @@ class BootAuth(Auth): # We encode in UTF-8 before calculating the HMAC, which is # an 8-bit algorithm. # python 2.6 insists on receiving a 'str' as opposed to a 'unicode' - digest = hmac.new(str(key), msg.encode('utf-8'), hashlib.sha1).hexdigest() + digest = hmac.new(str(key), msg.encode('utf-8'), sha).hexdigest() if digest != auth['value']: raise PLCAuthenticationFailure, "Call could not be authenticated" diff --git a/PLC/Persons.py b/PLC/Persons.py index 59ff6ddc..be3f2d3c 100644 --- a/PLC/Persons.py +++ b/PLC/Persons.py @@ -10,7 +10,10 @@ from types import StringTypes from datetime import datetime -import hashlib +try: + from hashlib import md5 +except ImportError: + from md5 import md5 import time from random import Random import re @@ -116,7 +119,7 @@ class Person(Row): else: # Generate a somewhat unique 8 character salt string salt = str(time.time()) + str(Random().random()) - salt = hashlib.md5(salt).hexdigest()[:8] + salt = md5(salt).hexdigest()[:8] return crypt.crypt(password.encode(self.api.encoding), magic + salt + "$") validate_date_created = Row.validate_timestamp