当前位置: 首页>>代码示例>>Python>>正文


Python tarfile.USTAR_FORMAT属性代码示例

本文整理汇总了Python中tarfile.USTAR_FORMAT属性的典型用法代码示例。如果您正苦于以下问题:Python tarfile.USTAR_FORMAT属性的具体用法?Python tarfile.USTAR_FORMAT怎么用?Python tarfile.USTAR_FORMAT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在tarfile的用法示例。


在下文中一共展示了tarfile.USTAR_FORMAT属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_ustar_limits

# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import USTAR_FORMAT [as 别名]
def test_ustar_limits(self):
        # 100 char name
        tarinfo = tarfile.TarInfo("0123456789" * 10)
        tarinfo.tobuf(tarfile.USTAR_FORMAT)

        # 101 char name that cannot be stored
        tarinfo = tarfile.TarInfo("0123456789" * 10 + "0")
        self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)

        # 256 char name with a slash at pos 156
        tarinfo = tarfile.TarInfo("123/" * 62 + "longname")
        tarinfo.tobuf(tarfile.USTAR_FORMAT)

        # 256 char name that cannot be stored
        tarinfo = tarfile.TarInfo("1234567/" * 31 + "longname")
        self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)

        # 512 char name
        tarinfo = tarfile.TarInfo("123/" * 126 + "longname")
        self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)

        # 512 char linkname
        tarinfo = tarfile.TarInfo("longlink")
        tarinfo.linkname = "123/" * 126 + "longname"
        self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)

        # uid > 8 digits
        tarinfo = tarfile.TarInfo("name")
        tarinfo.uid = 010000000
        self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:32,代码来源:test_tarfile.py

示例2: test_ustar_limits

# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import USTAR_FORMAT [as 别名]
def test_ustar_limits(self):
        # 100 char name
        tarinfo = tarfile.TarInfo("0123456789" * 10)
        tarinfo.tobuf(tarfile.USTAR_FORMAT)

        # 101 char name that cannot be stored
        tarinfo = tarfile.TarInfo("0123456789" * 10 + "0")
        self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)

        # 256 char name with a slash at pos 156
        tarinfo = tarfile.TarInfo("123/" * 62 + "longname")
        tarinfo.tobuf(tarfile.USTAR_FORMAT)

        # 256 char name that cannot be stored
        tarinfo = tarfile.TarInfo("1234567/" * 31 + "longname")
        self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)

        # 512 char name
        tarinfo = tarfile.TarInfo("123/" * 126 + "longname")
        self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)

        # 512 char linkname
        tarinfo = tarfile.TarInfo("longlink")
        tarinfo.linkname = "123/" * 126 + "longname"
        self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)

        # uid > 8 digits
        tarinfo = tarfile.TarInfo("name")
        tarinfo.uid = 0o10000000
        self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:32,代码来源:test_tarfile.py

示例3: test_number_field_limits

# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import USTAR_FORMAT [as 别名]
def test_number_field_limits(self):
        with self.assertRaises(ValueError):
            tarfile.itn(-1, 8, tarfile.USTAR_FORMAT)
        with self.assertRaises(ValueError):
            tarfile.itn(0o10000000, 8, tarfile.USTAR_FORMAT)
        with self.assertRaises(ValueError):
            tarfile.itn(-0x10000000001, 6, tarfile.GNU_FORMAT)
        with self.assertRaises(ValueError):
            tarfile.itn(0x10000000000, 6, tarfile.GNU_FORMAT) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_tarfile.py

示例4: _create_pax_generic_header

# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import USTAR_FORMAT [as 别名]
def _create_pax_generic_header(cls, pax_headers, type=tarfile.XHDTYPE):
    """Return a POSIX.1-2001 extended or global header sequence
       that contains a list of keyword, value pairs. The values
       must be unicode objects.
    """
    records = []
    for keyword, value in pax_headers.iteritems():

        try:
            keyword = keyword.encode("utf8")
        except Exception:
            pass

        try:
            value = value.encode("utf8")
        except Exception:
            pass

        l = len(keyword) + len(value) + 3   # ' ' + '=' + '\n'
        n = p = 0
        while True:
            n = l + len(str(p))
            if n == p:
                break
            p = n
        records.append("%d %s=%s\n" % (p, keyword, value))
    records = "".join(records)

    # We use a hardcoded "././@PaxHeader" name like star does
    # instead of the one that POSIX recommends.
    info = {}
    info["name"] = "././@PaxHeader"
    info["type"] = type
    info["size"] = len(records)
    info["magic"] = tarfile.POSIX_MAGIC

    # Create pax header + record blocks.
    return cls._create_header(info, tarfile.USTAR_FORMAT) + \
        cls._create_payload(records) 
开发者ID:goldmann,项目名称:docker-squash,代码行数:41,代码来源:xtarfile.py


注:本文中的tarfile.USTAR_FORMAT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。