compression.py 文件源码

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

项目:atropos 作者: jdidion 项目源码 文件源码
def open_gzip_file(filename, mode, use_system=True):
    """Open a gzip file, preferring the system gzip program if `use_system`
    is True, falling back to the gzip python library.

    Args:
        mode: The file open mode.
        use_system: Whether to try to use the system gzip program.
    """
    if use_system:
        try:
            if 'r' in mode:
                gzfile = GzipReader(filename)
            else:
                gzfile = GzipWriter(filename)
            if 't' in mode:
                gzfile = io.TextIOWrapper(gzfile)
            return gzfile
        except:
            pass

    gzfile = gzip.open(filename, mode)
    if 'b' in mode:
        if 'r' in mode:
            gzfile = io.BufferedReader(gzfile)
        else:
            gzfile = io.BufferedWriter(gzfile)
    return gzfile
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号