]> git.mxchange.org Git - quix0rs-apt-p2p.git/blobdiff - hash.py
* removing hack to allow threading
[quix0rs-apt-p2p.git] / hash.py
diff --git a/hash.py b/hash.py
index bc6868668b00c48c27f4616179b703f2428ad4c0..441c58a4967ce66d2ad758e919d849f8b3158465 100644 (file)
--- a/hash.py
+++ b/hash.py
@@ -1,16 +1,18 @@
-## Copyright 2002 Andrew Loewenstern, All Rights Reserved
+## Copyright 2002-2003 Andrew Loewenstern, All Rights Reserved
+# see LICENSE.txt for license information
 
 from sha import sha
 import whrandom
 
+
 def intify(hstr):
     """20 bit hash, big-endian -> long python integer"""
     assert len(hstr) == 20
     return long(hstr.encode('hex'), 16)
 
-def stringify(int):
+def stringify(num):
     """long int -> 20-character string"""
-    str = hex(int)[2:]
+    str = hex(num)[2:]
     if str[-1] == 'L':
         str = str[:-1]
     if len(str) % 2 != 0:
@@ -27,7 +29,7 @@ def newID():
     """returns a new pseudorandom globally unique ID string"""
     h = sha()
     for i in range(20):
-        h.update(chr(whrandom.randrange(0,256)))
+        h.update(chr(whrandom.randint(0,255)))
     return h.digest()
 
 def newIDInRange(min, max):
@@ -35,7 +37,7 @@ def newIDInRange(min, max):
     
 def randRange(min, max):
     return min + intify(newID()) % (max - min)
-
+    
 
 ### Test Cases ###
 import unittest
@@ -49,7 +51,7 @@ class NewID(unittest.TestCase):
 
 class Intify(unittest.TestCase):
     known = [('\0' * 20, 0),
-             ('\xff' * 20, 2L**160 - 1),
+            ('\xff' * 20, 2L**160 - 1),
             ]
     def testKnown(self):
         for str, value in self.known: