def get_fzf_release(access_token=None):
filename = 'fzf-{0}-release.json'.format(fzf_version)
filepath = os.path.join(os.path.dirname(__file__), filename)
try:
with open(filepath) as f:
d = f.read()
except IOError:
url = release_url
if access_token:
url = '{0}?access_token={1}'.format(url, access_token)
try:
r = urllib2.urlopen(url)
except urllib2.HTTPError as e:
if e.code == 403 and e.info().get('X-RateLimit-Remaining') == 0:
raise RuntimeError(
'GitHub rate limit reached. To increate the limit use '
'-g/--github-access-token option.\n ' + str(e)
)
elif e.code == 401 and access_token:
raise RuntimeError('Invalid GitHub access token.')
raise
d = r.read()
r.close()
mode = 'w' + ('b' if isinstance(d, bytes) else '')
try:
with open(filename, mode) as f:
f.write(d)
except IOError:
pass
try:
return json.loads(d)
except TypeError:
return json.loads(d.decode('utf-8'))
评论列表
文章目录