@@ -70,7 +70,7 @@ def shannon_entropy(data, iterator=None):
70
70
def display (digest ):
71
71
str_i = "Display: "
72
72
for i in digest :
73
- str_i += str (i ) + " "
73
+ str_i += f" { str (i )} "
74
74
sys .stderr .write (str_i )
75
75
76
76
@@ -157,7 +157,7 @@ def calc_hashid(self):
157
157
data = self .bfilter .tobytes ()
158
158
self .hashid = self .hashfunc (data )
159
159
del data
160
- sys .stderr .write ("BLOOM: HASHID: %s\n " % self .hashid .hexdigest ()[0 :8 ])
160
+ sys .stderr .write ("BLOOM: HASHID: %s\n " % self .hashid .hexdigest ()[:8 ])
161
161
162
162
def _raw_merge (self , bfilter ):
163
163
"""
@@ -197,14 +197,13 @@ def _hash(self, value):
197
197
# value = value.__str__() # Comment out line if you're filtering strings()
198
198
if self .do_hashes :
199
199
digest = int .from_bytes (self .hashfunc (value .encode ("utf8" )).digest (), "big" )
200
+ elif self .data_is_hex :
201
+ digest = int (value , 16 )
200
202
else :
201
- if self .data_is_hex :
202
- digest = int (value , 16 )
203
- else :
204
- try :
205
- digest = int (value .hex (), 16 )
206
- except :
207
- digest = int (binascii .hexlify (value ), 16 )
203
+ try :
204
+ digest = int (value .hex (), 16 )
205
+ except :
206
+ digest = int (binascii .hexlify (value ), 16 )
208
207
if self .fast :
209
208
yield (digest % self .bitcount )
210
209
else :
@@ -244,10 +243,7 @@ def _add(self, __hash):
244
243
# The purpose here is to spread out the hashes to create a unique
245
244
# hash with unique locations in the filter array,
246
245
# rather than just a big long hash blob.
247
- if self .fast :
248
- self .bitset += 1
249
- else :
250
- self .bitset += self .slices
246
+ self .bitset += 1 if self .fast else self .slices
251
247
252
248
def query (self , value ):
253
249
"""
@@ -304,17 +300,18 @@ def load(self, filename):
304
300
return True
305
301
306
302
def save (self , filename = None ):
307
- if not self .saving :
308
- if filename is None and self .filename is None :
309
- sys .stderr .write ("A Filename must be provided\n " )
310
- return False
311
- else :
312
- self .saving = True
313
- if filename is not None :
314
- self .filename = filename
315
- compress_pickle (self .filename , self )
316
- self .saving = False
317
- return True
303
+ if self .saving :
304
+ return
305
+ if filename is None and self .filename is None :
306
+ sys .stderr .write ("A Filename must be provided\n " )
307
+ return False
308
+ else :
309
+ self .saving = True
310
+ if filename is not None :
311
+ self .filename = filename
312
+ compress_pickle (self .filename , self )
313
+ self .saving = False
314
+ return True
318
315
319
316
def stat (self ):
320
317
if self .bitcalc :
0 commit comments