Skip to content

Commit 91a8ac2

Browse files
author
Ralf Schlatterbeck
committed
python2.4 compatibility fix
1 parent 14d6f18 commit 91a8ac2

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

roundup/anypy/hashlib_.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
try:
66
from hashlib import md5, sha1 # new in Python 2.5
7+
shamodule = sha1
78
except ImportError:
89
from md5 import md5 # deprecated in Python 2.6
910
from sha import sha as sha1 # deprecated in Python 2.6
11+
import sha as shamodule
1012

1113
# vim: ts=8 sts=4 sw=4 si

roundup/password.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import re, string, random
2525
from base64 import b64encode, b64decode
26-
from roundup.anypy.hashlib_ import md5, sha1
26+
from roundup.anypy.hashlib_ import md5, sha1, shamodule
2727
try:
2828
import crypt
2929
except ImportError:
@@ -59,10 +59,6 @@ def h64decode(data):
5959
#no m2crypto - make our own pbkdf2 function
6060
from struct import pack
6161
from hmac import HMAC
62-
try:
63-
from hashlib import sha1
64-
except ImportError:
65-
from sha import new as sha1
6662

6763
def xor_bytes(left, right):
6864
"perform bitwise-xor of two byte-strings"
@@ -71,7 +67,7 @@ def xor_bytes(left, right):
7167
def _pbkdf2(password, salt, rounds, keylen):
7268
digest_size = 20 # sha1 generates 20-byte blocks
7369
total_blocks = int((keylen+digest_size-1)/digest_size)
74-
hmac_template = HMAC(password, None, sha1)
70+
hmac_template = HMAC(password, None, shamodule)
7571
out = _bempty
7672
for i in xrange(1, total_blocks+1):
7773
hmac = hmac_template.copy()

0 commit comments

Comments
 (0)