Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

A collection of basic policies for resources anti-spammer

Project description

A collection of basic policies for resources anti-spammer.

http://img3.douban.com/view/biz/raw/public/f477075ba610e94.jpg

Install from Pypi

pip install bpolicy

Basic Example

import memcache
from bpolicy.consts import MINUTE, HOUR
from bpolicy import RatedPolicyFactory, ClockPolicyFactory, GenerationedPolicyFactory
from bpolicy import chained_policy, silent_check

store = memcache.Client(['127.0.0.1:9013'])
rated_factory = RatedPolicyFactory(quota=10, interval=1 * MINUTE)
clock_factory = ClockPolicyFactory(start_time=time(hour=1), end_time=time(hour=6), discount=0.3)
generationed_factory = GenerationedPolicyFactory(quota=10, interval=1 * HOUR, discount=0.5, max_keep_traking=3)


def check_policy(identity):
    return silent_check(chained_policy('hello', [generationed_factory, clock_factory, rated_factory], store), identity)


identity = "88.88.23.1"
for i in range(100):
    if check_policy(identity):
        print("success")
    else:
        print("banded")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for bpolicy, version 0.3.3
Filename, size File type Python version Upload date Hashes
Filename, size bpolicy-0.3.3.tar.gz (5.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page