]> arthur.barton.de Git - bup.git/commitdiff
Get rid of a sha-related DeprecationWarning in python 2.6.
authorAvery Pennarun <apenwarr@gmail.com>
Thu, 1 Apr 2010 18:48:10 +0000 (14:48 -0400)
committerAvery Pennarun <apenwarr@gmail.com>
Thu, 1 Apr 2010 18:48:10 +0000 (14:48 -0400)
hashlib is only available in python 2.5 or higher, but the 'sha' module
produces a DeprecationWarning in python 2.6 or higher.  We want to support
python 2.4 and above without any stupid warnings, so let's try using
hashlib.  If it fails, switch to the old sha module.

cmd/fsck-cmd.py
cmd/midx-cmd.py
lib/bup/git.py
lib/bup/helpers.py

index 36c8a350a0c524c1f94356c6f549b6c1dd16056a..bfd045cb966da4c1da92ef614abe3dc82aceb077 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-import sys, os, glob, subprocess, time, sha
+import sys, os, glob, subprocess, time
 from bup import options, git
 from bup.helpers import *
 
@@ -59,7 +59,7 @@ def quick_verify(base):
     wantsum = f.read(20)
     assert(len(wantsum) == 20)
     f.seek(0)
-    sum = sha.sha()
+    sum = Sha1()
     for b in chunkyreader(f, os.fstat(f.fileno()).st_size - 20):
         sum.update(b)
     if sum.digest() != wantsum:
index 490a34d5f2556415e0c99b5675bd755c44759878..e43e3126c3c44197c6b455e74f34a3a12c6fd6ed 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-import sys, math, struct, glob, sha
+import sys, math, struct, glob
 from bup import options, git
 from bup.helpers import *
 
@@ -19,7 +19,7 @@ def merge(idxlist, bits, table):
 def do_midx(outdir, outfilename, infilenames):
     if not outfilename:
         assert(outdir)
-        sum = sha.sha('\0'.join(infilenames)).hexdigest()
+        sum = Sha1('\0'.join(infilenames)).hexdigest()
         outfilename = '%s/midx-%s.midx' % (outdir, sum)
     
     inp = []
index 789e4b1926b417d8bed5aba5be5296338f160709..c7d4f728cc6684ab9c614d14b2ac9dd95e621dab 100644 (file)
@@ -1,4 +1,4 @@
-import os, errno, zlib, time, sha, subprocess, struct, stat, re, tempfile
+import os, errno, zlib, time, subprocess, struct, stat, re, tempfile
 import heapq
 from bup.helpers import *
 
@@ -288,7 +288,7 @@ class PackIdxList:
 
 def calc_hash(type, content):
     header = '%s %d\0' % (type, len(content))
-    sum = sha.sha(header)
+    sum = Sha1(header)
     sum.update(content)
     return sum.digest()
 
@@ -446,7 +446,7 @@ class PackWriter:
 
         # calculate the pack sha1sum
         f.seek(0)
-        sum = sha.sha()
+        sum = Sha1()
         while 1:
             b = f.read(65536)
             sum.update(b)
index ba71727a66d165c2d35b915569f10fdb9a025847..d8d416f49f80aec88988d90c1ea9744f145cc68f 100644 (file)
@@ -294,3 +294,16 @@ def handle_ctrl_c():
         else:
             return oldhook(exctype, value, traceback)
     sys.excepthook = newhook
+
+
+# hashlib is only available in python 2.5 or higher, but the 'sha' module
+# produces a DeprecationWarning in python 2.6 or higher.  We want to support
+# python 2.4 and above without any stupid warnings, so let's try using hashlib
+# first, and downgrade if it fails.
+try:
+    import hashlib
+except ImportError:
+    import sha
+    Sha1 = sha.sha
+else:
+    Sha1 = hashlib.sha1