Commits

Benoit Chesneau  committed b262167

make it compatible with py26

  • Participants
  • Parent commits cc8f085

Comments (0)

Files changed (1)

File friendpaste/http.py

 
 from datetime import datetime, timedelta
 import base64
-import md5
+try:
+    from hashlib import md5 as _md5
+except ImportError:
+    import md5
+    _md5 = md5.new
 import random
 import cPickle as pickle
 
     We also sign them with md5 and SECRET_KEY defined
     in Amisphere settings """
     pickled = pickle.dumps(session_data)
-    pickled_md5 = md5.new(pickled + settings.SECRET_KEY).hexdigest()
+    pickled_md5 = _md5(pickled + settings.SECRET_KEY).hexdigest()
     return base64.encodestring(pickled + pickled_md5)
 
 def _decode_session_data(session_data):
     """ decode session object from database """
     encoded_data = base64.decodestring(session_data)
     pickled, tamper_check = encoded_data[:-32], encoded_data[-32:]
-    if md5.new(pickled + settings.SECRET_KEY).hexdigest() != tamper_check:
+    if _md5(pickled + settings.SECRET_KEY).hexdigest() != tamper_check:
         raise SuspiciousOperation, "User tampered with session cookie."
     try:
         return pickle.loads(pickled)