#NEWLINE# def security_hash( request , form , * args ) : #NEWLINE# #INDENT# '\n    Calculates a security hash for the given Form instance.\n\n    This creates a list of the form field names/values in a deterministic\n    order, pickles the result with the SECRET_KEY setting, then takes an md5\n    hash of that.\n    ' #NEWLINE# data = [ ] #NEWLINE# for bf in data : #NEWLINE# #INDENT# if ( form . empty_permitted and ( not form . has_changed ( ) ) ) : #NEWLINE# #INDENT# value = ( bf . data or '' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# value = ( bf . field . clean ( bf . data ) or '' ) #NEWLINE# #UNINDENT# if isinstance ( value , basestring ) : #NEWLINE# #INDENT# value = value . strip ( ) #NEWLINE# #UNINDENT# data . append ( ( bf . name , value ) ) #NEWLINE# #UNINDENT# data . extend ( args ) #NEWLINE# data . append ( settings . SECRET_KEY ) #NEWLINE# pickled = pickle . dumps ( data , pickle . HIGHEST_PROTOCOL ) #NEWLINE# return md5_constructor ( pickled ) . hexdigest ( )