當前位置: 首頁>>代碼示例>>Python>>正文


Python tarfile.PAX_NUMBER_FIELDS屬性代碼示例

本文整理匯總了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() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:34,代碼來源:test_tarfile.py

示例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") 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:29,代碼來源:test_tarfile.py

示例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() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:33,代碼來源:test_tarfile.py


注:本文中的tarfile.PAX_NUMBER_FIELDS屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。