Skip to content
This repository
Browse code

Improved compatibility with Python 2.4

python-hashlib backported to Python 2.4 is not compatible with 'hmac'
module (at least the package distributed with RHEL/CentOS 5 is not).

Use md5 and sha modules on 2.4 regardless if hashlib is present.
  • Loading branch information...
commit bcb444200b6eee778b3a640e64695c857fc42ee2 1 parent d439efb
Michal Ludvig authored June 10, 2011

Showing 1 changed file with 8 additions and 5 deletions. Show diff stats Hide diff stats

  1. 13  S3/Utils.py
13  S3/Utils.py
@@ -4,16 +4,12 @@
4 4
 ## License: GPL Version 2
5 5
 
6 6
 import os
  7
+import sys
7 8
 import time
8 9
 import re
9 10
 import string
10 11
 import random
11 12
 import rfc822
12  
-try:
13  
-    from hashlib import md5, sha1
14  
-except ImportError:
15  
-    from md5 import md5
16  
-    import sha as sha1
17 13
 import hmac
18 14
 import base64
19 15
 import errno
@@ -23,6 +19,13 @@
23 19
 import Config
24 20
 import Exceptions
25 21
 
  22
+# hashlib backported to python 2.4 / 2.5 is not compatible with hmac!
  23
+if sys.version_info[0] == 2 and sys.version_info[1] < 6:
  24
+    from md5 import md5
  25
+    import sha as sha1
  26
+else:
  27
+    from hashlib import md5, sha1
  28
+
26 29
 try:
27 30
     import xml.etree.ElementTree as ET
28 31
 except ImportError:

0 notes on commit bcb4442

Please sign in to comment.
Something went wrong with that request. Please try again.