aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/exceptions.py
diff options
context:
space:
mode:
authorTom Christie2012-09-04 21:58:35 +0100
committerTom Christie2012-09-04 21:58:35 +0100
commitc28b719333b16935e53c76fef79b096cb11322ed (patch)
tree5b22784601e52b9b9f7db9385cceb51339681065 /djangorestframework/exceptions.py
parent8457c871963264c9f62552f30307e98221a1c25d (diff)
downloaddjango-rest-framework-c28b719333b16935e53c76fef79b096cb11322ed.tar.bz2
Refactored throttling
Diffstat (limited to 'djangorestframework/exceptions.py')
-rw-r--r--djangorestframework/exceptions.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/djangorestframework/exceptions.py b/djangorestframework/exceptions.py
index 51c5dbb7..0b4dacf7 100644
--- a/djangorestframework/exceptions.py
+++ b/djangorestframework/exceptions.py
@@ -49,8 +49,14 @@ class UnsupportedMediaType(APIException):
class Throttled(APIException):
status_code = status.HTTP_429_TOO_MANY_REQUESTS
- default_detail = "Request was throttled. Expected available in %d seconds."
+ default_detail = "Request was throttled."
+ extra_detail = "Expected available in %d second%s."
- def __init__(self, wait, detail=None):
+ def __init__(self, wait=None, detail=None):
import math
- self.detail = (detail or self.default_detail) % int(math.ceil(wait))
+ self.wait = wait and math.ceil(wait) or None
+ if wait is not None:
+ format = detail or self.default_detail + self.extra_detail
+ self.detail = format % (self.wait, self.wait != 1 and 's' or '')
+ else:
+ self.detail = detail or self.default_detail