def contents_url_from_path(path):
"""
Get github API url for contents of file from full path
:param path: Path to file (<owner>/<repo>/<dir>/.../<filename>)
:returns: URL suitable for a content call with github API
"""
owner, repo, file_path = split_full_file_path(path)
# Cannot pass unicode data to pathname2url or it can raise KeyError. Must
# only pass URL-safe bytes. So, something like u'\u2026' will raise a
# KeyError but if we encode it to bytes, '%E2%80%A6', things work
# correctly.
# http://stackoverflow.com/questions/15115588/urllib-quote-throws-keyerror
owner = owner.encode('utf-8')
repo = repo.encode('utf-8')
file_path = file_path.encode('utf-8')
return urllib.pathname2url('repos/%s/%s/contents/%s' % (owner, repo,
file_path))
评论列表
文章目录