From f1d117f20083ed1ff999ba7306a085a8b6593ac7 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Thu, 4 Dec 2008 21:33:13 +0000 Subject: [PATCH] 0002503: Change md5 module by hashlib Fallback to md5 if importerror svn: r11419 --- src/ThumbNails.py | 7 +++++-- src/docgen/ODFDoc.py | 7 +++++-- src/plugins/NarrativeWeb.py | 9 ++++++--- src/plugins/Verify.py | 7 +++++-- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/ThumbNails.py b/src/ThumbNails.py index e9071c371..e726e61bd 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 != 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 e488558ed..3c7755085 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 726ea4a78..1d54ada14 100644 --- a/src/plugins/NarrativeWeb.py +++ b/src/plugins/NarrativeWeb.py @@ -34,7 +34,10 @@ Narrative Web Page generator. #------------------------------------------------------------------------ import cgi import os -import md5 +try: + from hashlib import md5 +except ImportError: + from md5 import md5 import time import locale import shutil @@ -325,7 +328,7 @@ class BasePage: of.close() def lnkfmt(self,text): - return md5.new(text).hexdigest() + return md5(text).hexdigest() def display_footer(self, of,db): of.write('\n\n') @@ -976,7 +979,7 @@ class SurnamePage(BasePage): BasePage.__init__(self, title, options, archive, media_list, "") - of = self.create_link_file(md5.new(title).hexdigest(),'srn') + of = self.create_link_file(md5(title).hexdigest(),'srn') self.display_header(of,db,title,get_researcher().get_name(),True) msg = _("This page contains an index of all the individuals in the " diff --git a/src/plugins/Verify.py b/src/plugins/Verify.py index 16563e81f..79dafc8e4 100644 --- a/src/plugins/Verify.py +++ b/src/plugins/Verify.py @@ -32,7 +32,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 #------------------------------------------------------------------------ @@ -551,7 +554,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):