Fixed #8570: Corrected some code that was using 8-space tabs for some reason. Thanks to Manuel Saelices for the report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9019 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2008-09-14 07:04:40 +00:00
parent 5a4feb9ec2
commit 24d3129edd
1 changed files with 17 additions and 17 deletions

View File

@ -2,27 +2,27 @@ try:
import cPickle as pickle import cPickle as pickle
except ImportError: except ImportError:
import pickle import pickle
from django.conf import settings from django.conf import settings
from django.utils.hashcompat import md5_constructor from django.utils.hashcompat import md5_constructor
from django.forms import BooleanField from django.forms import BooleanField
def security_hash(request, form, *args): def security_hash(request, form, *args):
""" """
Calculates a security hash for the given Form instance. Calculates a security hash for the given Form instance.
This creates a list of the form field names/values in a deterministic This creates a list of the form field names/values in a deterministic
order, pickles the result with the SECRET_KEY setting, then takes an md5 order, pickles the result with the SECRET_KEY setting, then takes an md5
hash of that. hash of that.
""" """
data = [(bf.name, bf.field.clean(bf.data) or '') for bf in form] data = [(bf.name, bf.field.clean(bf.data) or '') for bf in form]
data.extend(args) data.extend(args)
data.append(settings.SECRET_KEY) data.append(settings.SECRET_KEY)
# Use HIGHEST_PROTOCOL because it's the most efficient. It requires # Use HIGHEST_PROTOCOL because it's the most efficient. It requires
# Python 2.3, but Django requires 2.3 anyway, so that's OK. # Python 2.3, but Django requires 2.3 anyway, so that's OK.
pickled = pickle.dumps(data, pickle.HIGHEST_PROTOCOL) pickled = pickle.dumps(data, pickle.HIGHEST_PROTOCOL)
return md5_constructor(pickled).hexdigest() return md5_constructor(pickled).hexdigest()