test_archive_util.py 文件源码

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

项目:setuptools 作者: pypa 项目源码 文件源码
def tarfile_with_unicode(tmpdir):
    """
    Create a tarfile containing only a file whose name is
    a zero byte file called testima?ge.png.
    """
    tarobj = io.BytesIO()

    with tarfile.open(fileobj=tarobj, mode="w:gz") as tgz:
        data = b""

        filename = "testima?ge.png"
        if six.PY2:
            filename = filename.decode('utf-8')

        t = tarfile.TarInfo(filename)
        t.size = len(data)

        tgz.addfile(t, io.BytesIO(data))

    target = tmpdir / 'unicode-pkg-1.0.tar.gz'
    with open(str(target), mode='wb') as tf:
        tf.write(tarobj.getvalue())
    return str(target)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号