Minor enhancements to rate limiting information

If rate limiting information hasn't been retrieved already, it will be checked
rather than just assuming 5000 requests remaining of 5000.

Add an additional attribute `rate_limiting_resettime` to reflect github's new
X-RateLimit-Reset header. This integer value is a unix timestamp.

RateLimiting unit test updated accordingly.
This commit is contained in:
Ed Jackson
2013-08-06 10:42:57 -05:00
parent 0a1e1fa488
commit 211e4633ee
4 changed files with 42 additions and 3 deletions
+4 -1
View File
@@ -87,7 +87,8 @@ class Requester:
self.__connectionClass = self.__httpConnectionClass
else:
assert False, "Unknown URL scheme"
self.rate_limiting = (5000, 5000)
self.rate_limiting = (-1, -1)
self.rate_limiting_resettime = 0
self.FIX_REPO_GET_GIT_REF = True
self.per_page = per_page
@@ -175,6 +176,8 @@ class Requester:
if "x-ratelimit-remaining" in responseHeaders and "x-ratelimit-limit" in responseHeaders:
self.rate_limiting = (int(responseHeaders["x-ratelimit-remaining"]), int(responseHeaders["x-ratelimit-limit"]))
if "x-ratelimit-reset" in responseHeaders:
self.rate_limiting_resettime = int(responseHeaders["x-ratelimit-reset"])
if "x-oauth-scopes" in responseHeaders:
self.oauth_scopes = responseHeaders["x-oauth-scopes"].split(", ")