comparison treepkg/util.py @ 457:b90bb9f2bb77

Use the Hashlib module instead of MD5 if the python version is >=2.5
author Andre Heinecke <aheinecke@intevation.de>
date Tue, 24 Aug 2010 13:50:17 +0000
parents e7e0ace683c6
children 61e72399914c
comparison
equal deleted inserted replaced
456:e7e0ace683c6 457:b90bb9f2bb77
12 import tempfile 12 import tempfile
13 import shutil 13 import shutil
14 import fnmatch 14 import fnmatch
15 import pwd 15 import pwd
16 import os.path 16 import os.path
17 import warnings 17 import sys
18 warnings.simplefilter("ignore", category=DeprecationWarning) 18 if sys.version_info < (2, 5):
19 import md5 19 import md5
20 else:
21 import hashlib
20 22
21 import run 23 import run
22 24
23 25
24 def import_dotted_name(dotted_name): 26 def import_dotted_name(dotted_name):
165 """ calculates the md5sum of a file """ 167 """ calculates the md5sum of a file """
166 if not os.path.isfile(filename): 168 if not os.path.isfile(filename):
167 raise RuntimeError("Could not create md5sum. File not found: %s" 169 raise RuntimeError("Could not create md5sum. File not found: %s"
168 % filename) 170 % filename)
169 f = file(filename, 'rb') 171 f = file(filename, 'rb')
170 m = md5.new() 172 if sys.version_info < (2, 5):
173 m = md5.new()
174 else:
175 m = hashlib.md5()
171 while True: 176 while True:
172 d = f.read(8096) 177 d = f.read(8096)
173 if not d: 178 if not d:
174 break 179 break
175 m.update(d) 180 m.update(d)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)