Permalink
Browse files

Simplify ratelimit handling due to update on reddit's end.

  • Loading branch information...
bboe committed Mar 18, 2012
1 parent 0e1d2b5 commit 93ce734db5d43dc33227586e84b8caaebbdafb19
Showing with 6 additions and 14 deletions.
  1. +1 −1 reddit/decorators.py
  2. +5 −13 reddit/errors.py
View
@@ -154,7 +154,7 @@ def parse_api_json_response(func): # pylint: disable-msg=R0912
def error_checked_func(self, *args, **kwargs):
return_value = func(self, *args, **kwargs)
allowed = ('captcha', 'data', 'errors', 'kind', 'names', 'next',
- 'prev', 'users')
+ 'prev', 'ratelimit', 'users')
if isinstance(return_value, dict):
for key in return_value:
if key not in allowed:
View
@@ -90,19 +90,11 @@ class NotLoggedIn(APIException):
class RateLimitExceeded(APIException):
"""An exception for when something wrong has happened too many times."""
ERROR_TYPE = 'RATELIMIT'
- MINUTES_RE = re.compile('(\d+) minutes')
- SECONDS_RE = re.compile('(\d+) seconds')
-
- @property
- def sleep_time(self):
- match = self.MINUTES_RE.search(self.message)
- if match:
- return int(match.group(1)) * 60
- match = self.SECONDS_RE.search(self.message)
- if match:
- return int(match.group(1))
- # This should never happen
- assert False
+
+ def __init__(self, error_type, message, field='', response=None):
+ super(RateLimitExceeded, self).__init__(error_type, message,
+ field, response)
+ self.sleep_time = self.response['ratelimit']
def _build_error_mapping():

0 comments on commit 93ce734

Please sign in to comment.