本文整理汇总了Python中tarfile.PAX_NUMBER_FIELDS属性的典型用法代码示例。如果您正苦于以下问题:Python tarfile.PAX_NUMBER_FIELDS属性的具体用法?Python tarfile.PAX_NUMBER_FIELDS怎么用?Python tarfile.PAX_NUMBER_FIELDS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类tarfile
的用法示例。
在下文中一共展示了tarfile.PAX_NUMBER_FIELDS属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pax_global_header
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import PAX_NUMBER_FIELDS [as 别名]
def test_pax_global_header(self):
pax_headers = {
u"foo": u"bar",
u"uid": u"0",
u"mtime": u"1.23",
u"test": u"\xe4\xf6\xfc",
u"\xe4\xf6\xfc": u"test"}
tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT,
pax_headers=pax_headers)
try:
tar.addfile(tarfile.TarInfo("test"))
finally:
tar.close()
# Test if the global header was written correctly.
tar = tarfile.open(tmpname, encoding="iso8859-1")
try:
self.assertEqual(tar.pax_headers, pax_headers)
self.assertEqual(tar.getmembers()[0].pax_headers, pax_headers)
# Test if all the fields are unicode.
for key, val in tar.pax_headers.iteritems():
self.assertTrue(type(key) is unicode)
self.assertTrue(type(val) is unicode)
if key in tarfile.PAX_NUMBER_FIELDS:
try:
tarfile.PAX_NUMBER_FIELDS[key](val)
except (TypeError, ValueError):
self.fail("unable to convert pax header field")
finally:
tar.close()
示例2: test_pax_global_header
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import PAX_NUMBER_FIELDS [as 别名]
def test_pax_global_header(self):
pax_headers = {
u"foo": u"bar",
u"uid": u"0",
u"mtime": u"1.23",
u"test": u"���",
u"���": u"test"}
tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT,
pax_headers=pax_headers)
tar.addfile(tarfile.TarInfo("test"))
tar.close()
# Test if the global header was written correctly.
tar = tarfile.open(tmpname, encoding="iso8859-1")
self.assertEqual(tar.pax_headers, pax_headers)
self.assertEqual(tar.getmembers()[0].pax_headers, pax_headers)
# Test if all the fields are unicode.
for key, val in tar.pax_headers.iteritems():
self.assertTrue(type(key) is unicode)
self.assertTrue(type(val) is unicode)
if key in tarfile.PAX_NUMBER_FIELDS:
try:
tarfile.PAX_NUMBER_FIELDS[key](val)
except (TypeError, ValueError):
self.fail("unable to convert pax header field")
示例3: test_pax_global_header
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import PAX_NUMBER_FIELDS [as 别名]
def test_pax_global_header(self):
pax_headers = {
"foo": "bar",
"uid": "0",
"mtime": "1.23",
"test": "\xe4\xf6\xfc",
"\xe4\xf6\xfc": "test"}
tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT,
pax_headers=pax_headers)
try:
tar.addfile(tarfile.TarInfo("test"))
finally:
tar.close()
# Test if the global header was written correctly.
tar = tarfile.open(tmpname, encoding="iso8859-1")
try:
self.assertEqual(tar.pax_headers, pax_headers)
self.assertEqual(tar.getmembers()[0].pax_headers, pax_headers)
# Test if all the fields are strings.
for key, val in tar.pax_headers.items():
self.assertIsNot(type(key), bytes)
self.assertIsNot(type(val), bytes)
if key in tarfile.PAX_NUMBER_FIELDS:
try:
tarfile.PAX_NUMBER_FIELDS[key](val)
except (TypeError, ValueError):
self.fail("unable to convert pax header field")
finally:
tar.close()