Skip to content

Commit

Permalink
Added sleep_time attribute to RateLimitExceeded exception.
Browse files Browse the repository at this point in the history
  • Loading branch information
bboe committed Feb 18, 2012
1 parent 327a56a commit 4572d55
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions reddit/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# along with reddit_api. If not, see <http://www.gnu.org/licenses/>.

import inspect
import re
import sys


Expand Down Expand Up @@ -88,6 +89,19 @@ 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 _build_error_mapping():
Expand Down

0 comments on commit 4572d55

Please sign in to comment.