Commit 97d8d152 authored by Nate Case's avatar Nate Case Committed by Jeremy Kerr
Browse files

Eliminate hashlib requirement



If the hashlib module does not exist, use sha and md5 modules instead
to support Python 2.4.  The hashlib module was added to Python 2.5.
Signed-off-by: default avatarNate Case <ncase@xes-inc.com>
Signed-off-by: default avatarJeremy Kerr <jk@ozlabs.org>
parent 8252a61e
......@@ -28,7 +28,6 @@ import re
import datetime, time
import string
import random
import hashlib
from email.mime.text import MIMEText
import email.utils
......@@ -167,10 +166,27 @@ class HashField(models.Field):
def __init__(self, algorithm = 'sha1', *args, **kwargs):
self.algorithm = algorithm
try:
import hashlib
self.hashlib = True
except ImportError:
self.hashlib = False
if algorithm == 'sha1':
import sha
self.hash_constructor = sha.new
elif algorithm == 'md5':
import md5
self.hash_constructor = md5.new
else:
raise NameError("Unknown algorithm '%s'" % algorithm)
super(HashField, self).__init__(*args, **kwargs)
def db_type(self):
n_bytes = len(hashlib.new(self.algorithm).digest())
if self.hashlib:
n_bytes = len(hashlib.new(self.algorithm).digest())
else:
n_bytes = len(self.hash_constructor().digest())
if settings.DATABASE_ENGINE == 'postgresql':
return 'bytea'
elif settings.DATABASE_ENGINE == 'mysql':
......
......@@ -21,7 +21,12 @@
import re
import hashlib
try:
import hashlib
sha1_hash = hashlib.sha1
except ImportError:
import sha
sha1_hash = sha.sha
_hunk_re = re.compile('^\@\@ -\d+(?:,(\d+))? \+\d+(?:,(\d+))? \@\@')
_filename_re = re.compile('^(---|\+\+\+) (\S+)')
......@@ -158,7 +163,7 @@ def patch_hash(str):
lines = str.split('\n')
prefixes = ['-', '+', ' ']
hash = hashlib.sha1()
hash = sha1_hash()
for line in str.split('\n'):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment