[kupfer] data: Use md5 for source cache file hash



commit 6fe9bf44e04295fc579edde658594430afa77a65
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Sun Aug 23 00:00:21 2009 +0200

    data: Use md5 for source cache file hash

 kupfer/data.py |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
---
diff --git a/kupfer/data.py b/kupfer/data.py
index cda6942..e158d15 100644
--- a/kupfer/data.py
+++ b/kupfer/data.py
@@ -1,5 +1,5 @@
-import base64
 import gzip
+import hashlib
 import itertools
 import os
 import cPickle as pickle
@@ -263,10 +263,8 @@ class SourcePickler (pretty.OutputMixin):
 
 	def get_filename(self, source):
 		"""Return cache filename for @source"""
-		# python string hash
-		h = "%x" % abs(hash(repr(source)))
-		bytes = "".join(chr(int(h[i:i+2], 16)) for i in xrange(0, len(h), 2))
-		hashstr = base64.urlsafe_b64encode(bytes).rstrip("=")
+		bytes = hashlib.md5(repr(source)).digest()
+		hashstr = bytes.encode("base64").rstrip("\n=").replace("/", "-")
 		filename = self.name_template % (hashstr, self.pickle_version)
 		return os.path.join(config.get_cache_home(), filename)
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]