[Treepkg-commits] r418 - trunk/treepkg

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Aug 24 17:41:48 CEST 2010


Author: aheinecke
Date: 2010-08-24 17:41:48 +0200 (Tue, 24 Aug 2010)
New Revision: 418

Modified:
   trunk/treepkg/util.py
Log:
Use an exception to use either hashlib or md5


Modified: trunk/treepkg/util.py
===================================================================
--- trunk/treepkg/util.py	2010-08-24 13:50:17 UTC (rev 417)
+++ trunk/treepkg/util.py	2010-08-24 15:41:48 UTC (rev 418)
@@ -14,12 +14,11 @@
 import fnmatch
 import pwd
 import os.path
-import sys
-if sys.version_info < (2, 5):
-    import md5
-else:
-    import hashlib
-
+try:
+    from hashlib import md5 as new_md5
+except ImportError:
+    # fall back to md5 for Python versions before 2.5
+    from md5 import new as new_md5
 import run
 
 
@@ -169,10 +168,7 @@
         raise RuntimeError("Could not create md5sum. File not found: %s"
                             % filename)
     f = file(filename, 'rb')
-    if sys.version_info < (2, 5):
-        m = md5.new()
-    else:
-        m = hashlib.md5()
+    m = new_md5()
     while True:
         d = f.read(8096)
         if not d:



More information about the Treepkg-commits mailing list