# HG changeset patch # User Andre Heinecke # Date 1282664508 0 # Node ID 61e72399914c290d061ea49fb216f07715777ddb # Parent b90bb9f2bb77cac3fc3d8bb1e3d3023cfd37cc5c Use an exception to use either hashlib or md5 diff -r b90bb9f2bb77 -r 61e72399914c treepkg/util.py --- 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: