[postr] Use hashlib if available (#601813)



commit fae5d758f5f428c07ed138817e4c4807fb7383f5
Author: Francisco Rojas <frojas alumnos utalca cl>
Date:   Fri Nov 13 12:58:28 2009 -0300

    Use hashlib if available (#601813)
    
    Replace md5 with hashlib without dropping support for
    Python 2.4
    
    Signed-off-by: Germán Póo-Caamaño <gpoo gnome org>

 src/flickrest.py |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/src/flickrest.py b/src/flickrest.py
index 0448a9b..018f151 100644
--- a/src/flickrest.py
+++ b/src/flickrest.py
@@ -15,12 +15,19 @@
 # this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
 # St, Fifth Floor, Boston, MA 02110-1301 USA
 
-import logging, md5, os, mimetools, urllib
+import logging, os, mimetools, urllib
 from twisted.internet import defer
 from twisted.python.failure import Failure
 import proxyclient as client
 
 try:
+    from hashlib import md5
+    has_hashlib = True
+except ImportError:
+    from md5 import md5
+    has_hashlib = False
+
+try:
     from xml.etree import ElementTree
 except ImportError:
     from elementtree import ElementTree
@@ -97,7 +104,11 @@ class Flickr:
         sig = reduce(lambda sig, key: sig + key + str(kwargs[key]),
                      sorted(kwargs.keys()),
                      self.secret)
-        kwargs['api_sig'] = md5.new(sig).hexdigest()
+        if has_hashlib:
+            kwargs['api_sig'] = md5(sig).hexdigest()
+        else:
+            kwargs['api_sig'] = md5.new(sig).hexdigest()
+
 
     def __call(self, method, kwargs):
         kwargs["method"] = method



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]