__init__.py 文件源码

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

项目:sw-delta-python 作者: alexcasalboni 项目源码 文件源码
def get_delta(asked_file_path, cached_file_path):
    """ Return a tuple of (body, mime_type), given two file paths """

    if not exists(asked_file_path):
        raise InvalidAskedFile("%s not found." % asked_file_path)

    if not exists(cached_file_path):
        raise InvalidCachedFile("%s not found." % asked_file_path)

    with open(asked_file_path, 'r') as filep:
        asked_file_string = filep.read()

    with open(cached_file_path, 'r') as filep:
        cached_file_string = filep.read()

    body = calculate_delta(asked_file_string, cached_file_string)
    mime_type = "text/sw-delta"

    if len(body) > len(asked_file_string):
        body = asked_file_string
        mime_type, _ = guess_type(asked_file_path)

    return body, mime_type
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号