Python plistlib 模块,writePlistToBytes() 实例源码

我们从Python开源项目中,提取了以下17个代码示例,用于说明如何使用plistlib.writePlistToBytes()

项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_bytes(self):
        pl = self._create()
        data = plistlib.writePlistToBytes(pl)
        pl2 = plistlib.readPlistFromBytes(data)
        self.assertEqual(dict(pl), dict(pl2))
        data2 = plistlib.writePlistToBytes(pl2)
        self.assertEqual(data, data2)
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_appleformatting(self):
        pl = plistlib.readPlistFromBytes(TESTDATA)
        data = plistlib.writePlistToBytes(pl)
        self.assertEqual(data, TESTDATA,
                         "generated data was not identical to Apple's output")
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_controlcharacters(self):
        for i in range(128):
            c = chr(i)
            testString = "string containing %s" % c
            if i >= 32 or c in "\r\n\t":
                # \r, \n and \t are the only legal control chars in XML
                plistlib.writePlistToBytes(testString)
            else:
                self.assertRaises(ValueError,
                                  plistlib.writePlistToBytes,
                                  testString)
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_nondictroot(self):
        test1 = "abc"
        test2 = [1, 2, 3, "abc"]
        result1 = plistlib.readPlistFromBytes(plistlib.writePlistToBytes(test1))
        result2 = plistlib.readPlistFromBytes(plistlib.writePlistToBytes(test2))
        self.assertEqual(test1, result1)
        self.assertEqual(test2, result2)
项目:iOS-private-api-checker    作者:NetEaseGame    | 项目源码 | 文件源码
def writePlistToString(rootObject, binary=True):
    if not binary:
        rootObject = wrapDataObject(rootObject, binary)
        if hasattr(plistlib, "dumps"):
            return plistlib.dumps(rootObject)
        elif hasattr(plistlib, "writePlistToBytes"):
            return plistlib.writePlistToBytes(rootObject)
        else:
            return plistlib.writePlistToString(rootObject)
    else:
        ioObject = io.BytesIO()
        writer = PlistWriter(ioObject)
        writer.writeRoot(rootObject)
        return ioObject.getvalue()
项目:timer-workflow    作者:5fth    | 项目源码 | 文件源码
def writePlistToString(rootObject, binary=True):
    if not binary:
        rootObject = wrapDataObject(rootObject, binary)
        if six.PY3:
            return plistlib.writePlistToBytes(rootObject)
        else:
            return plistlib.writePlistToString(rootObject)
    else:
        io = six.BytesIO()
        writer = PlistWriter(io)
        writer.writeRoot(rootObject)
        return io.getvalue()
项目:Alfred_SourceTree    作者:yourtion    | 项目源码 | 文件源码
def writePlistToString(rootObject, binary=True):
    if not binary:
        rootObject = wrapDataObject(rootObject, binary)
        if hasattr(plistlib, "dumps"):
            return plistlib.dumps(rootObject)
        elif hasattr(plistlib, "writePlistToBytes"):
            return plistlib.writePlistToBytes(rootObject)
        else:
            return plistlib.writePlistToString(rootObject)
    else:
        ioObject = io.BytesIO()
        writer = PlistWriter(ioObject)
        writer.writeRoot(rootObject)
        return ioObject.getvalue()
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_bytes(self):
        pl = self._create()
        data = plistlib.writePlistToBytes(pl)
        pl2 = plistlib.readPlistFromBytes(data)
        self.assertEqual(dict(pl), dict(pl2))
        data2 = plistlib.writePlistToBytes(pl2)
        self.assertEqual(data, data2)
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_indentation_array(self):
        data = [[[[[[[[{'test': plistlib.Data(b'aaaaaa')}]]]]]]]]
        self.assertEqual(plistlib.readPlistFromBytes(plistlib.writePlistToBytes(data)), data)
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_indentation_dict(self):
        data = {'1': {'2': {'3': {'4': {'5': {'6': {'7': {'8': {'9': plistlib.Data(b'aaaaaa')}}}}}}}}}
        self.assertEqual(plistlib.readPlistFromBytes(plistlib.writePlistToBytes(data)), data)
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_indentation_dict_mix(self):
        data = {'1': {'2': [{'3': [[[[[{'test': plistlib.Data(b'aaaaaa')}]]]]]}]}}
        self.assertEqual(plistlib.readPlistFromBytes(plistlib.writePlistToBytes(data)), data)
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_appleformatting(self):
        pl = plistlib.readPlistFromBytes(TESTDATA)
        data = plistlib.writePlistToBytes(pl)
        self.assertEqual(data, TESTDATA,
                         "generated data was not identical to Apple's output")
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_nondictroot(self):
        test1 = "abc"
        test2 = [1, 2, 3, "abc"]
        result1 = plistlib.readPlistFromBytes(plistlib.writePlistToBytes(test1))
        result2 = plistlib.readPlistFromBytes(plistlib.writePlistToBytes(test2))
        self.assertEqual(test1, result1)
        self.assertEqual(test2, result2)
项目:devpi    作者:devpi    | 项目源码 | 文件源码
def gen_launchd(tw, config, writer):
    devpibin = py.path.local(sys.argv[0])
    plist_content = write_plist_to_bytes(OrderedDict([
        ("Label", "net.devpi"),
        ("ProgramArguments", [str(devpibin)] + config.args._raw),
        ("RunAtLoad", True),
    ]))
    writer("net.devpi.plist", plist_content)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_bytes_deprecated(self):
        pl = {
            'key': 42,
            'sub': {
                'key': 9,
                'alt': 'value',
                'data': b'buffer',
            }
        }
        with self.assertWarns(DeprecationWarning):
            data = plistlib.writePlistToBytes(pl)

        with self.assertWarns(DeprecationWarning):
            pl2 = plistlib.readPlistFromBytes(data)

        self.assertIsInstance(pl2, plistlib._InternalDict)
        self.assertEqual(pl2, plistlib._InternalDict(
            key=42,
            sub=plistlib._InternalDict(
                key=9,
                alt='value',
                data=plistlib.Data(b'buffer'),
            )
        ))

        with self.assertWarns(DeprecationWarning):
            data2 = plistlib.writePlistToBytes(pl2)
        self.assertEqual(data, data2)
项目:alfred-workFlows-iossimulator    作者:sampayo    | 项目源码 | 文件源码
def writePlistToString(rootObject, binary=True):
    if not binary:
        rootObject = wrapDataObject(rootObject, binary)
        if hasattr(plistlib, "dumps"):
            return plistlib.dumps(rootObject)
        elif hasattr(plistlib, "writePlistToBytes"):
            return plistlib.writePlistToBytes(rootObject)
        else:
            return plistlib.writePlistToString(rootObject)
    else:
        ioObject = io.BytesIO()
        writer = PlistWriter(ioObject)
        writer.writeRoot(rootObject)
        return ioObject.getvalue()
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_bytes_deprecated(self):
        pl = {
            'key': 42,
            'sub': {
                'key': 9,
                'alt': 'value',
                'data': b'buffer',
            }
        }
        with self.assertWarns(DeprecationWarning):
            data = plistlib.writePlistToBytes(pl)

        with self.assertWarns(DeprecationWarning):
            pl2 = plistlib.readPlistFromBytes(data)

        self.assertIsInstance(pl2, plistlib._InternalDict)
        self.assertEqual(pl2, plistlib._InternalDict(
            key=42,
            sub=plistlib._InternalDict(
                key=9,
                alt='value',
                data=plistlib.Data(b'buffer'),
            )
        ))

        with self.assertWarns(DeprecationWarning):
            data2 = plistlib.writePlistToBytes(pl2)
        self.assertEqual(data, data2)