From 4bf31829727bc839d7ba8d2076be22d285f6c523 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Thu, 4 Dec 2008 21:44:12 +0000 Subject: [PATCH] 002503: Change md5 module by hashlib. Fallback to md5 on importerror (python 2.4 users) svn: r11420 --- src/ThumbNails.py | 7 +++++-- src/docgen/ODFDoc.py | 7 +++++-- src/plugins/NarrativeWeb.py | 7 +++++-- src/plugins/Verify.py | 7 +++++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/ThumbNails.py b/src/ThumbNails.py index cc38ad5c8..7ff4c45ae 100644 --- a/src/ThumbNails.py +++ b/src/ThumbNails.py @@ -28,7 +28,10 @@ Handles generation and access to thumbnails used in GRAMPS. # #------------------------------------------------------------------------- import os -import md5 +try: + from hashlib import md5 +except ImportError: + from md5 import md5 #------------------------------------------------------------------------- # @@ -123,7 +126,7 @@ def __build_thumb_path(path, rectangle=None): extra = "" if rectangle is not None: extra = "?" + str(rectangle) - md5_hash = md5.md5(path+extra) + md5_hash = md5(path+extra) return os.path.join(const.THUMB_DIR, md5_hash.hexdigest()+'.png') #------------------------------------------------------------------------- diff --git a/src/docgen/ODFDoc.py b/src/docgen/ODFDoc.py index 390acda73..7534d8a36 100644 --- a/src/docgen/ODFDoc.py +++ b/src/docgen/ODFDoc.py @@ -28,7 +28,10 @@ # #------------------------------------------------------------------------- import os -import md5 +try: + from hashlib import md5 +except ImportError: + from md5 import md5 import zipfile import time import locale @@ -452,7 +455,7 @@ class ODFDoc(BaseDoc.BaseDoc, BaseDoc.TextDoc, BaseDoc.DrawDoc): act_width = x_cm/ratio not_extension, extension = os.path.splitext(file_name) - odf_name = md5.new(file_name).hexdigest() + extension + odf_name = md5(file_name).hexdigest() + extension media_list_item = (file_name, odf_name) if not media_list_item in self.media_list: diff --git a/src/plugins/NarrativeWeb.py b/src/plugins/NarrativeWeb.py index 9d1081bb2..3d3f5b7d1 100644 --- a/src/plugins/NarrativeWeb.py +++ b/src/plugins/NarrativeWeb.py @@ -45,7 +45,10 @@ Narrative Web Page generator. #------------------------------------------------------------------------ import os import re -import md5 +try: + from hashlib import md5 +except ImportError: + from md5 import md5 import time import locale import shutil @@ -236,7 +239,7 @@ def html_escape(text): def name_to_md5(text): """This creates an MD5 hex string to be used as filename.""" - return md5.new(text).hexdigest() + return md5(text).hexdigest() class BasePage: diff --git a/src/plugins/Verify.py b/src/plugins/Verify.py index a9939ad50..fb132ab8e 100644 --- a/src/plugins/Verify.py +++ b/src/plugins/Verify.py @@ -33,7 +33,10 @@ This is the research tool, not the low-level data ingerity check. #------------------------------------------------------------------------ import os import cPickle -import md5 +try: + from hashlib import md5 +except ImportError: + from md5 import md5 import Errors #------------------------------------------------------------------------ @@ -558,7 +561,7 @@ class VerifyResults(ManagedWindow): self.window_shown = False def load_ignored(self,db_filename): - md5sum = md5.md5(db_filename) + md5sum = md5(db_filename) self.ignores_filename = os.path.join( const.HOME_DIR,md5sum.hexdigest() + os.path.extsep + 'vfm') if not self._load_ignored(self.ignores_filename):