/usr/lib/python2.7/dist-packages/ratelimit/mixins.py is in python-django-ratelimit 0.4.0+8+gd58c489-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | # -*- coding: utf-8 -*-
from .decorators import ratelimit
class RateLimitMixin(object):
"""
Mixin for usage in Class Based Views
configured with the decorator ``ratelimit`` defaults.
Configure the class-attributes prefixed with ``ratelimit_``
for customization of the ratelimit process.
Example::
class ContactView(RateLimitMixin, FormView):
form_class = ContactForm
template_name = "contact.html"
ratelimit_block = True
def form_valid(self, form):
# do sth. here
return super(ContactView, self).form_valid(form)
"""
ratelimit_ip = True
ratelimit_block = False
ratelimit_method = ['POST']
ratelimit_field = None
ratelimit_rate = '5/m'
ratelimit_skip_if = None
ratelimit_keys = None
def get_ratelimit_config(self):
return dict(
(k[len("ratelimit_"):], v)
for k, v in vars(self.__class__).items()
if k.startswith("ratelimit")
)
def dispatch(self, *args, **kwargs):
return ratelimit(
**self.get_ratelimit_config()
)(super(RateLimitMixin, self).dispatch)(*args, **kwargs)
|