From: <ul...@us...> - 2012-07-16 19:55:55
|
Revision: 86 http://adc.svn.sourceforge.net/adc/?rev=86&view=rev Author: ullner Date: 2012-07-16 19:55:49 +0000 (Mon, 16 Jul 2012) Log Message: ----------- Removing Base32 conversion from bloom.py; see base32.py Modified Paths: -------------- trunk/Source/Python/bloom.py Modified: trunk/Source/Python/bloom.py =================================================================== --- trunk/Source/Python/bloom.py 2012-07-16 19:54:18 UTC (rev 85) +++ trunk/Source/Python/bloom.py 2012-07-16 19:55:49 UTC (rev 86) @@ -1,5 +1,6 @@ from math import log, ceil import base64, sys +import base32 try: from bitarray import bitarray except ImportError: @@ -9,19 +10,6 @@ """ HASH_BITS = 192 -def toBase32(s): - """Returns a base32 encoded string, stripped from padding""" - return base64.b32encode(s).strip('=') - -def fromBase32(base32): - """Padds a base32 string and returns it decoded""" - quanta, leftover = divmod(len(base32), 8) - if leftover: - base32+='='*(8-leftover) - try: - return base64.b32decode(base32) - except TypeError, e: - print str(e)+' %s size: %d'% ( base32, len(base32)) class HashBloom(object): @staticmethod @@ -97,7 +85,7 @@ bit = start+i byte = bit/ 8 pos = bit % 8 - if ord(fromBase32(str(tth))[byte]) & (1 << pos): + if ord(base32.fromBase32(str(tth))[byte]) & (1 << pos): x |= (1 << i) return x % len(self.bitarray) @@ -110,7 +98,7 @@ hb.reset(k,m,h) for tth in tths: hb.add(tth) - ok_ctrl = (ctrl == toBase32(hb.bitarray.tostring())) + ok_ctrl = (ctrl == base32.toBase32(hb.bitarray.tostring())) ok_match = hb.match(tths[0]) return ok_ctrl , ok_match This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |