Skip to content

Commit d937ce3

Browse files
committed
Minor cleanup
1 parent 73d8a2b commit d937ce3

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

rest_framework/exceptions.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
from __future__ import unicode_literals
88
from rest_framework import status
9+
import math
910

1011

1112
class APIException(Exception):
@@ -14,10 +15,9 @@ class APIException(Exception):
1415
Subclasses should provide `.status_code` and `.detail` properties.
1516
"""
1617
status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
17-
default_detail = ""
18+
default_detail = ''
1819

19-
def __init__(self, detail=None, status_code=None):
20-
self.status_code = status_code or self.status_code
20+
def __init__(self, detail=None):
2121
self.detail = detail or self.default_detail
2222

2323

@@ -46,15 +46,15 @@ class MethodNotAllowed(APIException):
4646
default_detail = "Method '%s' not allowed."
4747

4848
def __init__(self, method, detail=None):
49-
super(MethodNotAllowed, self).__init__((detail or self.default_detail) % method)
49+
self.detail = (detail or self.default_detail) % method
5050

5151

5252
class NotAcceptable(APIException):
5353
status_code = status.HTTP_406_NOT_ACCEPTABLE
5454
default_detail = "Could not satisfy the request's Accept header"
5555

5656
def __init__(self, detail=None, available_renderers=None):
57-
super(NotAcceptable, self).__init__(detail)
57+
self.detail = detail or self.default_detail
5858
self.available_renderers = available_renderers
5959

6060

@@ -63,7 +63,7 @@ class UnsupportedMediaType(APIException):
6363
default_detail = "Unsupported media type '%s' in request."
6464

6565
def __init__(self, media_type, detail=None):
66-
super(UnsupportedMediaType, self).__init__((detail or self.default_detail) % media_type)
66+
self.detail = (detail or self.default_detail) % media_type
6767

6868

6969
class Throttled(APIException):
@@ -72,10 +72,10 @@ class Throttled(APIException):
7272
extra_detail = "Expected available in %d second%s."
7373

7474
def __init__(self, wait=None, detail=None):
75-
super(Throttled, self).__init__(detail)
76-
77-
import math
78-
self.wait = wait and math.ceil(wait) or None
79-
if wait is not None:
80-
format = self.detail + self.extra_detail
81-
self.detail = format % (self.wait, self.wait != 1 and 's' or '')
75+
if wait is None:
76+
self.detail = detail or self.default_detail
77+
self.wait = None
78+
else:
79+
format = (detail or self.default_detail) + self.extra_detail
80+
self.detail = format % (wait, wait != 1 and 's' or '')
81+
self.wait = math.ceil(wait)

0 commit comments

Comments
 (0)