Skip to content

Commit 9d06e82

Browse files
alexbrasetvikjaybaird
authored andcommitted
Handle unicode keys.
1 parent 764f18f commit 9d06e82

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pybloom/pybloom.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- encoding: utf-8 -*-
12
"""This module implements a bloom filter probabilistic data structure and
23
an a Scalable Bloom Filter that grows in size as your add more items to it
34
without increasing the false positive error_rate.
@@ -68,7 +69,7 @@ def make_hashfuncs(num_slices, num_bits):
6869
num_salts += 1
6970
salts = [hashfn(hashfn(pack('I', i)).digest()) for i in xrange(num_salts)]
7071
def _make_hashfuncs(key):
71-
if isinstance(key, basestring) and not isinstance(key, unicode):
72+
if isinstance(key, unicode):
7273
key = key.encode('utf-8')
7374
else:
7475
key = str(key)
@@ -254,7 +255,11 @@ def __init__(self, initial_capacity=100, error_rate=0.001,
254255
False
255256
>>> "test" in b
256257
True
257-
258+
>>> unicode_string = u'¡'
259+
>>> b.add(unicode_string)
260+
False
261+
>>> unicode_string in b
262+
True
258263
"""
259264
if not error_rate or error_rate < 0:
260265
raise ValueError("Error_Rate must be a decimal less than 0.")

0 commit comments

Comments
 (0)