我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用tarfile.PAX_NUMBER_FIELDS。
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.assertTrue(type(key) is not bytes) self.assertTrue(type(val) is not 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()
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()
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()
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") 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()
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")