From: <fri...@us...> - 2008-12-26 14:24:32
|
Revision: 9488 http://translate.svn.sourceforge.net/translate/?rev=9488&view=rev Author: friedelwolff Date: 2008-12-26 14:24:27 +0000 (Fri, 26 Dec 2008) Log Message: ----------- [Contributed by Leonardo Ferreira Fontenelle] Provide a wrapper for the md5 library that is located in different places in different versions of Python. Use this rather to avoid deprecation warnings. This fixes bug 634. Modified Paths: -------------- src/trunk/translate/storage/html.py src/trunk/translate/tools/podebug.py Added Paths: ----------- src/trunk/translate/misc/hash.py Added: src/trunk/translate/misc/hash.py =================================================================== --- src/trunk/translate/misc/hash.py (rev 0) +++ src/trunk/translate/misc/hash.py 2008-12-26 14:24:27 UTC (rev 9488) @@ -0,0 +1,30 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright 2008 Zuza Software Foundation +# +# This file is part of translate. +# +# 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 of the License, 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; if not, see <http://www.gnu.org/licenses/>. + +"""This module contains some temporary glue to make us work with md5 hashes on +old and new versions of Python. The function md5_f() wraps whatever is +available.""" + +try: + import hashlib + md5_f = hashlib.md5 +except ImportError: + import md5 + md5_f = md5.new Modified: src/trunk/translate/storage/html.py =================================================================== --- src/trunk/translate/storage/html.py 2008-12-24 09:28:53 UTC (rev 9487) +++ src/trunk/translate/storage/html.py 2008-12-26 14:24:27 UTC (rev 9488) @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # -# Copyright 2004-2006 Zuza Software Foundation +# Copyright 2004-2006,2008 Zuza Software Foundation # # This file is part of translate. # @@ -69,7 +69,7 @@ def guess_encoding(self, htmlsrc): """Returns the encoding of the html text. - + We look for 'charset=' within a meta tag to do this. """ @@ -104,17 +104,17 @@ strings to help our regexes out. """ - - import md5 - + + from translate.misc import hash + self.phpdict = {} result = re.findall('(?s)<\?(.*?)\?>', text) for cmd in result: - h = md5.new(cmd).hexdigest() + h = hash.md5_f(cmd).hexdigest() self.phpdict[h] = cmd text = text.replace(cmd,h) return text - + def reintrophp(self, text): """Replaces the PHP placeholders in text with the real code""" for hash, code in self.phpdict.items(): @@ -136,7 +136,7 @@ def strip_html(self, text): """Strip unnecessary html from the text. - + HTML tags are deemed unnecessary if it fully encloses the translatable text, eg. '<a href="index.html">Home Page</a>'. @@ -252,10 +252,10 @@ def handle_comment(self, data): # we don't do anything with comments pass - + def handle_pi(self, data): self.handle_data("<?%s>" % data) class POHTMLParser(htmlfile): pass - + Modified: src/trunk/translate/tools/podebug.py =================================================================== --- src/trunk/translate/tools/podebug.py 2008-12-24 09:28:53 UTC (rev 9487) +++ src/trunk/translate/tools/podebug.py 2008-12-26 14:24:27 UTC (rev 9488) @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # -# Copyright 2004-2006 Zuza Software Foundation +# Copyright 2004-2006,2008 Zuza Software Foundation # # This file is part of translate. # @@ -29,7 +29,7 @@ from translate.misc.rich import map_rich, only_strings import os import re -import md5 +from translate.misc import hash def add_prefix(prefix, strings): for string in strings: @@ -152,7 +152,7 @@ hashable = unit.getlocations()[0] else: hashable = unit.source - prefix = md5.new(hashable).hexdigest()[:self.hash] + " " + prefix = hash.md5_f(hashable).hexdigest()[:self.hash] + " " if self.rewritefunc: unit.rich_target = map_rich(only_strings(self.rewritefunc), unit.rich_source) elif not unit.istranslated(): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |