From eacc95143304805aacdcac828377f5dec5db53bd Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Tue, 9 Aug 2016 11:06:48 -0300 Subject: [PATCH] =?UTF-8?q?Gera=20hash=20da=20proposi=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/utils.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/sapl/utils.py b/sapl/utils.py index 08b0dbeaf..922dc90f4 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -221,8 +221,12 @@ def intervalos_tem_intersecao(a_inicio, a_fim, b_inicio, b_fim): return maior_inicio <= menor_fim -def gerar_hash_arquivo(arquivo, pk, hasher=hashlib.md5(), blocksize=65536): - with open(arquivo, 'rb') as arq: - for chunk in iter(lambda: arq.read(blocksize), b''): - hasher.update(chunk) - return 'P' + hasher.hexdigest() + '/' + pk +def gerar_hash_arquivo(arquivo, pk, block_size=2**20): + md5 = hashlib.md5() + file = open(arquivo, 'rb') + while True: + data = file.read(block_size) + if not data: + break + md5.update(data) + return 'P' + md5.hexdigest() + '/' + pk