View Code? Open in Web Editor
NEW
flask restframework, inspired by Django-rest-framework
flask-restframework's Introduction
๐ญ Iโm currently working on ...
๐ฑ Iโm currently learning ...
๐ฏ Iโm looking to collaborate on ...
๐ค Iโm looking for help with ...
๐ฌ Ask me about ...
๐ซ How to reach me: ...
โก Fun fact: ...
flask-restframework's People
Contributors
Stargazers
Watchers
flask-restframework's Issues
class AnonRateThrottle (BaseThrottle ):
"""
Limits the rate of API calls that may be made by a anonymous users.
The IP address of the request will be used as the unique cache key.
"""
scope = 'anon'
def get_cache_key (self ):
if g .current_user and g .current_user .is_authenticated :
return None # Only throttle unauthenticated requests.
return self .cache_format % {
'scope' : self .scope ,
'ident' : self .get_ident ()
}
class UserRateThrottle (BaseThrottle ):
"""
Limits the rate of API calls that may be made by a given user.
The user id will be used as a unique cache key if the user is
authenticated. For anonymous requests, the IP address of the request will
be used.
"""
scope = 'user'
def get_cache_key (self ):
if g .current_user and g .current_user .is_authenticated :
ident = g .current_user .id
else :
ident = self .get_ident ()
return self .cache_format % {
'scope' : self .scope ,
'ident' : ident
}
if i use same throttle class in different api, any one api will affect the others' throttling, because they use same cache key in class.
i don't want to write many same throttle class that only changing cache key inside.
so change the above code to support this situation.