remote.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:guides-cms 作者: pluralsight 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号