

def _log_rate_limit(self, future):
    'log GitHub rate limit headers\n        \n        - error if 0 remaining\n        - warn if 10% or less remain\n        - debug otherwise\n        '
    try:
        r = future.result()
    except HTTPError as e:
        r = e.response
        if (r is None):
            return
    limit_s = r.headers.get('X-RateLimit-Limit', '')
    remaining_s = r.headers.get('X-RateLimit-Remaining', '')
    if ((not remaining_s) or (not limit_s)):
        if (r.code < 300):
            app_log.warn('No rate limit headers. Did GitHub change? %s', json.dumps(dict(r.headers), indent=1))
        return
    remaining = int(remaining_s)
    limit = int(limit_s)
    if (remaining == 0):
        jsondata = response_text(r)
        data = json.loads(jsondata)
        app_log.error('GitHub rate limit (%s) exceeded: %s', limit, data.get('message', 'no message'))
        return
    if ((10 * remaining) > limit):
        log = app_log.debug
    else:
        log = app_log.warn
    log('%i/%i GitHub API requests remaining', remaining, limit)

dataset/ETHPy150Open jupyter/nbviewer/nbviewer/providers/github/client.py AsyncGitHubClient._log_rate_limit/original