@@ -70,7 +70,7 @@ def shannon_entropy(data, iterator=None):
7070def display (digest ):
7171 str_i = "Display: "
7272 for i in digest :
73- str_i += str (i ) + " "
73+ str_i += f" { str (i )} "
7474 sys .stderr .write (str_i )
7575
7676
@@ -157,7 +157,7 @@ def calc_hashid(self):
157157 data = self .bfilter .tobytes ()
158158 self .hashid = self .hashfunc (data )
159159 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 ])
161161
162162 def _raw_merge (self , bfilter ):
163163 """
@@ -197,14 +197,13 @@ def _hash(self, value):
197197 # value = value.__str__() # Comment out line if you're filtering strings()
198198 if self .do_hashes :
199199 digest = int .from_bytes (self .hashfunc (value .encode ("utf8" )).digest (), "big" )
200+ elif self .data_is_hex :
201+ digest = int (value , 16 )
200202 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 )
208207 if self .fast :
209208 yield (digest % self .bitcount )
210209 else :
@@ -244,10 +243,7 @@ def _add(self, __hash):
244243 # The purpose here is to spread out the hashes to create a unique
245244 # hash with unique locations in the filter array,
246245 # 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
251247
252248 def query (self , value ):
253249 """
@@ -304,17 +300,18 @@ def load(self, filename):
304300 return True
305301
306302 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
318315
319316 def stat (self ):
320317 if self .bitcalc :
0 commit comments