changeset 458:61e72399914c

Use an exception to use either hashlib or md5
author Andre Heinecke <aheinecke@intevation.de>
date Tue, 24 Aug 2010 15:41:48 +0000
parents b90bb9f2bb77
children 31874ce6d621
files treepkg/util.py
diffstat 1 files changed, 6 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/treepkg/util.py	Tue Aug 24 13:50:17 2010 +0000
+++ b/treepkg/util.py	Tue Aug 24 15:41:48 2010 +0000
@@ -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:
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)