[mirrorbrain-commits] r7974 - /trunk/mirrordoctor/mb/hashes.py

From: <poeml_at_mirrorbrain.org>
Date: Wed, 10 Mar 2010 13:31:59 -0000
Author: poeml
Date: Wed Mar 10 14:31:57 2010
New Revision: 7974

URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=7974&view=rev
Log:
mb makehashes:
- The code should now work also with Python 2.4's hash modules.

Modified:
    trunk/mirrordoctor/mb/hashes.py

Modified: trunk/mirrordoctor/mb/hashes.py
URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mirrordoctor/mb/hashes.py?rev=7974&r1=7973&r2=7974&view=diff
==============================================================================
--- trunk/mirrordoctor/mb/hashes.py (original)
+++ trunk/mirrordoctor/mb/hashes.py Wed Mar 10 14:31:57 2010
_at_@ -13,9 +13,10 @@
 except ImportError:
     import md5
     md5 = md5
-    import sha1
-    sha1 = sha1
-    # I guess that Python 2.4 didn't have a sha256 counterpart
+    import sha
+    sha1 = sha
+    sha1.sha1 = sha1.sha
+    # I think Python 2.4 didn't have a sha256 counterpart
     sha256 = None
 
 PIECESIZE = 262144
_at_@ -211,7 +212,8 @@
 
         m = md5.md5()
         s1 = sha1.sha1()
-        s256 = sha256.sha256()
+        if sha256:
+            s256 = sha256.sha256()
         short_read_before = False
 
         f = open(self.src, 'rb')
_at_@ -228,20 +230,22 @@
 
             m.update(buf)
             s1.update(buf)
-            s256.update(buf)
+            if sha256:
+                s256.update(buf)
 
             self.npieces += 1
-            self.pieces.append(hashlib.sha1(buf).digest())
-            self.pieceshex.append(hashlib.sha1(buf).hexdigest())
+            self.pieces.append(sha1.sha1(buf).digest())
+            self.pieceshex.append(sha1.sha1(buf).hexdigest())
 
         f.close()
 
         self.md5 = m.digest()
+        self.md5hex = m.hexdigest()
         self.sha1 = s1.digest()
-        self.sha256 = s256.digest()
-        self.md5hex = m.hexdigest()
         self.sha1hex = s1.hexdigest()
-        self.sha256hex = s256.hexdigest()
+        if sha256:
+            self.sha256 = s256.digest()
+            self.sha256hex = s256.hexdigest()
 
         # if present, grab PGP signature
         if os.path.exists(self.src + '.asc'):




_______________________________________________
mirrorbrain-commits mailing list
Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/

Note: To remove yourself from this list, send a mail with the content
 	unsubscribe
to the address mirrorbrain-commits-request_at_mirrorbrain.org
Received on Wed Mar 10 2010 - 13:32:06 GMT

This archive was generated by hypermail 2.3.0 : Mon Feb 20 2012 - 23:47:04 GMT