# Copyright (C) 2004 Nicolas Delon # All Rights Reserved # # This file is part of the Prelude program. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. def compute_file_digest(filename, digest): BLOCK_SIZE = 32768 file = open(filename) while True: data = file.read(BLOCK_SIZE) digest.update(data) if len(data) < BLOCK_SIZE: break file.close() return digest.hexdigest() def compute_content_digest(content, digest): return digest.new(content).hexdigest() # use the fastest md5 implementation available try: import fchksum def md5_file_digest(filename): return fchksum.fmd5t(filename)[0] except ImportError: import md5 def md5_file_digest(filename): return compute_file_digest(filename, md5.new()) import md5 def md5_content_digest(content): return compute_content_digest(content, md5) import sha def sha_file_digest(filename): return compute_file_digest(filename, sha.new()) def sha_content_digest(filename): return compute_content_digest(filename, sha)