From f77fe5163d4b462b01b64a00ef7261a928b2a1ad Mon Sep 17 00:00:00 2001 From: Abhinav Sarkar Date: Sat, 3 Jan 2009 17:05:46 +0000 Subject: [PATCH] made changes to remove the warning about depracation of md5 module in python 2.6 --- lastfm/api.py | 12 ++++++++++-- lastfm/filecache.py | 13 +++++++++++-- test/wsgi_test_app.py | 12 ++++++++++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/lastfm/api.py b/lastfm/api.py index b6abaf3..323399f 100644 --- a/lastfm/api.py +++ b/lastfm/api.py @@ -363,7 +363,7 @@ class Api(object): if name == 'api_sig': continue sig += ("%s%s" % (name, params[name])) sig += self.secret - hashed_sig = md5.new(sig).hexdigest() + hashed_sig = md5hash(sig) return hashed_sig else: raise AuthenticationFailedError("api secret must be present to call this method") @@ -387,7 +387,6 @@ class Api(object): return "" % self._api_key from datetime import datetime -import md5 import sys import time import urllib @@ -408,6 +407,15 @@ from lastfm.track import Track from lastfm.user import User from lastfm.venue import Venue +if sys.version < '2.6': + import md5 + def md5hash(string): + return md5.new(string).hexdigest() +else: + from hashlib import md5 + def md5hash(string): + return md5(string).hexdigest() + if sys.version_info >= (2, 5): import xml.etree.cElementTree as ElementTree else: diff --git a/lastfm/filecache.py b/lastfm/filecache.py index a97cafc..558c270 100644 --- a/lastfm/filecache.py +++ b/lastfm/filecache.py @@ -4,7 +4,16 @@ __author__ = "Abhinav Sarkar " __version__ = "0.2" __license__ = "GNU Lesser General Public License" -import md5 +import sys +if sys.version < '2.6': + import md5 + def md5hash(string): + return md5.new(string).hexdigest() +else: + from hashlib import md5 + def md5hash(string): + return md5(string).hexdigest() + import os import tempfile @@ -83,7 +92,7 @@ class FileCache(object): self._root_directory = root_directory def _GetPath(self,key): - hashed_key = md5.new(key).hexdigest() + hashed_key = md5hash(key) return os.path.join(self._root_directory, self._GetPrefix(hashed_key), hashed_key) diff --git a/test/wsgi_test_app.py b/test/wsgi_test_app.py index ebdb3bd..582c0bc 100644 --- a/test/wsgi_test_app.py +++ b/test/wsgi_test_app.py @@ -1,6 +1,14 @@ from urlparse import urlunparse -import md5 import os +import sys +if sys.version < '2.6': + import md5 + def md5hash(string): + return md5.new(string).hexdigest() +else: + from hashlib import md5 + def md5hash(string): + return md5(string).hexdigest() """ A simple WSGI application for testing. """ @@ -20,7 +28,7 @@ def test_app(environ, start_response): environ['QUERY_STRING'], '' )) - key = md5.new(url).hexdigest() + key = md5hash(url) status = '200 OK' response_headers = [('Content-type','text/xml')] start_response(status, response_headers)