don't depend on python2.5 Fixes #3888

This commit is contained in:
Yann Leboulanger 2008-04-27 18:11:34 +00:00
parent a9e25aa98a
commit 96a50f6c07
1 changed files with 14 additions and 3 deletions

View File

@ -30,7 +30,6 @@ import urllib
import errno
import select
import sha
import hashlib
import base64
import sys
from encodings.punycode import punycode_encode
@ -42,6 +41,18 @@ from i18n import ngettext
from xmpp_stringprep import nodeprep, resourceprep, nameprep
import xmpp
try:
# Python 2.5
import hashlib
hash_md5 = hashlib.md5
hash_sha1 = hashlib.sha1
except:
# Python 2.4
import md5
import sha
hash_md5 = md5.new
hash_sha1 = sha.new
if sys.platform == 'darwin':
from osx import nsapp
@ -1256,9 +1267,9 @@ def compute_caps_hash(identities, features, hash_method='sha-1'):
for f in features:
S += '%s<' % f
if hash_method == 'sha-1':
hash = hashlib.sha1(S)
hash = hash_sha1(S)
elif hash_method == 'md5':
hash = hashlib.md5(S)
hash = hash_md5(S)
else:
return ''
return base64.b64encode(hash.digest())