Fixed #12362 -- Corrected Python 2.4 incompatibility with hmac constructor in contrib.messages. Thanks to Jeremy Dunck for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11814 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
dd27fe74c7
commit
7cb8892fdb
|
@ -1,7 +1,7 @@
|
||||||
import hmac
|
import hmac
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.hashcompat import sha_constructor
|
from django.utils.hashcompat import sha_hmac
|
||||||
from django.contrib.messages import constants
|
from django.contrib.messages import constants
|
||||||
from django.contrib.messages.storage.base import BaseStorage, Message
|
from django.contrib.messages.storage.base import BaseStorage, Message
|
||||||
from django.utils import simplejson as json
|
from django.utils import simplejson as json
|
||||||
|
@ -41,7 +41,6 @@ class MessageDecoder(json.JSONDecoder):
|
||||||
decoded = super(MessageDecoder, self).decode(s, **kwargs)
|
decoded = super(MessageDecoder, self).decode(s, **kwargs)
|
||||||
return self.process_messages(decoded)
|
return self.process_messages(decoded)
|
||||||
|
|
||||||
|
|
||||||
class CookieStorage(BaseStorage):
|
class CookieStorage(BaseStorage):
|
||||||
"""
|
"""
|
||||||
Stores messages in a cookie.
|
Stores messages in a cookie.
|
||||||
|
@ -103,7 +102,7 @@ class CookieStorage(BaseStorage):
|
||||||
SECRET_KEY, modified to make it unique for the present purpose.
|
SECRET_KEY, modified to make it unique for the present purpose.
|
||||||
"""
|
"""
|
||||||
key = 'django.contrib.messages' + settings.SECRET_KEY
|
key = 'django.contrib.messages' + settings.SECRET_KEY
|
||||||
return hmac.new(key, value, sha_constructor).hexdigest()
|
return hmac.new(key, value, sha_hmac).hexdigest()
|
||||||
|
|
||||||
def _encode(self, messages, encode_empty=False):
|
def _encode(self, messages, encode_empty=False):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -8,9 +8,13 @@ available.
|
||||||
try:
|
try:
|
||||||
import hashlib
|
import hashlib
|
||||||
md5_constructor = hashlib.md5
|
md5_constructor = hashlib.md5
|
||||||
|
md5_hmac = md5_constructor
|
||||||
sha_constructor = hashlib.sha1
|
sha_constructor = hashlib.sha1
|
||||||
|
sha_hmac = sha_constructor
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import md5
|
import md5
|
||||||
md5_constructor = md5.new
|
md5_constructor = md5.new
|
||||||
|
md5_hmac = md5
|
||||||
import sha
|
import sha
|
||||||
sha_constructor = sha.new
|
sha_constructor = sha.new
|
||||||
|
sha_hmac = sha
|
||||||
|
|
Loading…
Reference in New Issue