Use hashlib rather than sha where available.
authorAdam Sampson <ats@offog.org>
Fri, 30 Jan 2009 09:27:34 +0000 (09:27 +0000)
committerAdam Sampson <ats@offog.org>
Fri, 30 Jan 2009 09:27:34 +0000 (09:27 +0000)
sha is deprecated in Python 2.6.

rawdoglib/rawdog.py

index 2a790efee961a22be0527243ca4af7dac5dec1bf..ba4b5b1668626c803036d024a385359249379920 100644 (file)
@@ -20,7 +20,7 @@ VERSION = "2.12rc3"
 STATE_VERSION = 2
 import feedparser, feedfinder, plugins
 from persister import Persistable, Persister
-import os, time, sha, getopt, sys, re, cgi, socket, urllib2, calendar
+import os, time, getopt, sys, re, cgi, socket, urllib2, calendar
 import string, locale
 from StringIO import StringIO
 import types
@@ -31,6 +31,19 @@ try:
 except:
        have_threading = 0
 
+try:
+       import hashlib
+except:
+       hashlib = None
+       import sha
+
+def new_sha1(s = ""):
+       """Return a new SHA1 hash object."""
+       if hashlib is None:
+               return sha.new(s)
+       else:
+               return hashlib.sha1(s)
+
 def set_socket_timeout(n):
        """Set the system socket timeout."""
        if hasattr(socket, "setdefaulttimeout"):
@@ -255,7 +268,7 @@ def write_ascii(f, s, config):
 
 def short_hash(s):
        """Return a human-manipulatable 'short hash' of a string."""
-       return sha.new(s).hexdigest()[-8:]
+       return new_sha1(s).hexdigest()[-8:]
 
 def decode_structure(struct, encoding):
        """Walk through a structure returned by feedparser, decoding any
@@ -504,7 +517,7 @@ class Article:
                system (i.e. it can't just be the article ID, because that
                would collide if more than one feed included the same
                article)."""
-               h = sha.new()
+               h = new_sha1()
                def add_hash(s):
                        h.update(s.encode("UTF-8"))