本文整理汇总了Python中pybloomfilter.BloomFilter.from_base64方法的典型用法代码示例。如果您正苦于以下问题:Python BloomFilter.from_base64方法的具体用法?Python BloomFilter.from_base64怎么用?Python BloomFilter.from_base64使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybloomfilter.BloomFilter
的用法示例。
在下文中一共展示了BloomFilter.from_base64方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: vote
# 需要导入模块: from pybloomfilter import BloomFilter [as 别名]
# 或者: from pybloomfilter.BloomFilter import from_base64 [as 别名]
def vote(request, poll):
try:
choice_name = request.POST['choice']
selected_choice = poll.choice_set.get(choice=choice_name)
except (KeyError, Choice.DoesNotExist):
return render_to_response('detail.html', {'poll':poll, 'error_message':"You didn't select a choice."},
context_instance= RequestContext(request))
if not (poll.has_expired() or already_voted(request, poll)):
hash = request_hash(request)
poll.total_votes += 1
selected_choice.votes += 1
poll.vote_set.create(hash=hash)
selected_choice.save()
#Update the seen ips
from pybloomfilter import BloomFilter
bf = BloomFilter.from_base64('/tmp/bloom.filter', poll.ips_seen)
alreadyseen = bf.add(request.META['REMOTE_ADDR'])
if not alreadyseen:
poll.ips_seen = bf.to_base64()
poll.ips_count += 1
poll.save()
return None
示例2: open
# 需要导入模块: from pybloomfilter import BloomFilter [as 别名]
# 或者: from pybloomfilter.BloomFilter import from_base64 [as 别名]
import sys
import glob
import cPickle
from pybloomfilter import BloomFilter
folderpath = sys.argv[1]
for book_filepath in glob.glob(folderpath+'/*.txt'):
book = open(book_filepath).read()
sentences = book.split('.')
bf = BloomFilter(100000,0.01,'filter.bloom')
for sentence in sentences:
words = sentence.split()
for word in words:
bf.add(word.strip('"'))
print 'the' in bf
print 'wut' in bf
print 'laughter' in bf
BloomFilter.from_base64(book_filepath+'.bf',BloomFilter.to_base64(bf))
示例3: num_different_ips
# 需要导入模块: from pybloomfilter import BloomFilter [as 别名]
# 或者: from pybloomfilter.BloomFilter import from_base64 [as 别名]
def num_different_ips(self):
return len(BloomFilter.from_base64('/tmp/polls.bloom', self.ips_seen))