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


Python plistlib.dumps方法代码示例

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


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

示例1: send_packet

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import dumps [as 别名]
def send_packet(self, payload: dict, reqtype: int = 8):
        """
        Args:
            payload: required

            # The following args only used in the first request
            reqtype: request type, always 8 
            tag: int
        """
        body_data = plistlib.dumps(payload)
        if self._first:  # first package
            length = 16 + len(body_data)
            header = struct.pack(
                "IIII", length, 1, reqtype,
                self._tag)  # version: 1, request: 8(?), tag: 1(?)
        else:
            header = struct.pack(">I", len(body_data))
        self.sendall(header + body_data) 
开发者ID:openatx,项目名称:facebook-wda,代码行数:20,代码来源:usbmux.py

示例2: _content_to_uuid

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import dumps [as 别名]
def _content_to_uuid(payload):
    '''
    Generate a UUID based upon the payload content

    :param payload:
    :return:
    '''
    log.debug('Attempting to Hash {}'.format(payload))

    if six.PY3:
        str_payload = plistlib.dumps(payload)
    else:
        str_payload = plistlib.writePlistToString(payload)
    hashobj = hashlib.md5(str_payload)

    identifier = re.sub(
        b'([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})',
        b'\\1-\\2-\\3-\\4-\\5',
        binascii.hexlify(hashobj.digest()))

    return identifier.decode() 
开发者ID:mosen,项目名称:salt-osx,代码行数:23,代码来源:profile.py

示例3: dumps

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import dumps [as 别名]
def dumps(value, fmt=FMT_XML, skipkeys=False, sort_keys=True):
    if _check_py3():
        return plistlib.dumps(value, fmt=fmt, skipkeys=skipkeys, sort_keys=sort_keys).decode("utf-8")
    else:
        # We avoid using writePlistToString() as that uses
        # cStringIO and fails when Unicode strings are detected
        f = StringIO()
        dump(value, f, fmt=fmt, skipkeys=skipkeys, sort_keys=sort_keys)
        return f.getvalue()

###                        ###
# Binary Plist Stuff For Py2 #
###                        ###

# From the python 3 plistlib.py source:  https://github.com/python/cpython/blob/3.7/Lib/plistlib.py
# Tweaked to function on Python 2 
开发者ID:corpnewt,项目名称:USBMap,代码行数:18,代码来源:plist.py

示例4: test_int

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import dumps [as 别名]
def test_int(self):
        for pl in [0, 2**8-1, 2**8, 2**16-1, 2**16, 2**32-1, 2**32,
                   2**63-1, 2**64-1, 1, -2**63]:
            for fmt in ALL_FORMATS:
                with self.subTest(pl=pl, fmt=fmt):
                    data = plistlib.dumps(pl, fmt=fmt)
                    pl2 = plistlib.loads(data)
                    self.assertIsInstance(pl2, int)
                    self.assertEqual(pl, pl2)
                    data2 = plistlib.dumps(pl2, fmt=fmt)
                    self.assertEqual(data, data2)

        for fmt in ALL_FORMATS:
            for pl in (2 ** 64 + 1, 2 ** 127-1, -2**64, -2 ** 127):
                with self.subTest(pl=pl, fmt=fmt):
                    self.assertRaises(OverflowError, plistlib.dumps,
                                      pl, fmt=fmt) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_plistlib.py

示例5: test_keysort

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import dumps [as 别名]
def test_keysort(self):
        pl = collections.OrderedDict()
        pl['b'] = 1
        pl['a'] = 2
        pl['c'] = 3

        for fmt in ALL_FORMATS:
            for sort_keys in (False, True):
                with self.subTest(fmt=fmt, sort_keys=sort_keys):
                    data = plistlib.dumps(pl, fmt=fmt, sort_keys=sort_keys)
                    pl2 = plistlib.loads(data, dict_type=collections.OrderedDict)

                    self.assertEqual(dict(pl), dict(pl2))
                    if sort_keys:
                        self.assertEqual(list(pl2.keys()), ['a', 'b', 'c'])
                    else:
                        self.assertEqual(list(pl2.keys()), ['b', 'a', 'c']) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_plistlib.py

示例6: test_skipkeys

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import dumps [as 别名]
def test_skipkeys(self):
        pl = {
            42: 'aNumber',
            'snake': 'aWord',
        }

        for fmt in ALL_FORMATS:
            with self.subTest(fmt=fmt):
                data = plistlib.dumps(
                    pl, fmt=fmt, skipkeys=True, sort_keys=False)

                pl2 = plistlib.loads(data)
                self.assertEqual(pl2, {'snake': 'aWord'})

                fp = BytesIO()
                plistlib.dump(
                    pl, fp, fmt=fmt, skipkeys=True, sort_keys=False)
                data = fp.getvalue()
                pl2 = plistlib.loads(fp.getvalue())
                self.assertEqual(pl2, {'snake': 'aWord'}) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:22,代码来源:test_plistlib.py

示例7: test_tuple_members

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import dumps [as 别名]
def test_tuple_members(self):
        pl = {
            'first': (1, 2),
            'second': (1, 2),
            'third': (3, 4),
        }

        for fmt in ALL_FORMATS:
            with self.subTest(fmt=fmt):
                data = plistlib.dumps(pl, fmt=fmt)
                pl2 = plistlib.loads(data)
                self.assertEqual(pl2, {
                    'first': [1, 2],
                    'second': [1, 2],
                    'third': [3, 4],
                })
                self.assertIsNot(pl2['first'], pl2['second']) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_plistlib.py

示例8: test_dict_members

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import dumps [as 别名]
def test_dict_members(self):
        pl = {
            'first': {'a': 1},
            'second': {'a': 1},
            'third': {'b': 2 },
        }

        for fmt in ALL_FORMATS:
            with self.subTest(fmt=fmt):
                data = plistlib.dumps(pl, fmt=fmt)
                pl2 = plistlib.loads(data)
                self.assertEqual(pl2, {
                    'first': {'a': 1},
                    'second': {'a': 1},
                    'third': {'b': 2 },
                })
                self.assertIsNot(pl2['first'], pl2['second']) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_plistlib.py

示例9: test_dataobject_deprecated

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import dumps [as 别名]
def test_dataobject_deprecated(self):
        in_data = { 'key': plistlib.Data(b'hello') }
        out_data = { 'key': b'hello' }

        buf = plistlib.dumps(in_data)

        cur = plistlib.loads(buf)
        self.assertEqual(cur, out_data)
        self.assertNotEqual(cur, in_data)

        cur = plistlib.loads(buf, use_builtin_types=False)
        self.assertNotEqual(cur, out_data)
        self.assertEqual(cur, in_data)

        with self.assertWarns(DeprecationWarning):
            cur = plistlib.readPlistFromBytes(buf)
        self.assertNotEqual(cur, out_data)
        self.assertEqual(cur, in_data) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,代码来源:test_plistlib.py

示例10: test_list_members

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import dumps [as 别名]
def test_list_members(self):
        pl = {
            'first': [1, 2],
            'second': [1, 2],
            'third': [3, 4],
        }

        for fmt in ALL_FORMATS:
            with self.subTest(fmt=fmt):
                data = plistlib.dumps(pl, fmt=fmt)
                pl2 = plistlib.loads(data)
                self.assertEqual(pl2, {
                    'first': [1, 2],
                    'second': [1, 2],
                    'third': [3, 4],
                })
                self.assertIsNot(pl2['first'], pl2['second']) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:19,代码来源:test_plistlib.py

示例11: test_cycles

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import dumps [as 别名]
def test_cycles(self):
        # recursive list
        a = []
        a.append(a)
        b = plistlib.loads(plistlib.dumps(a, fmt=plistlib.FMT_BINARY))
        self.assertIs(b[0], b)
        # recursive tuple
        a = ([],)
        a[0].append(a)
        b = plistlib.loads(plistlib.dumps(a, fmt=plistlib.FMT_BINARY))
        self.assertIs(b[0][0], b)
        # recursive dict
        a = {}
        a['x'] = a
        b = plistlib.loads(plistlib.dumps(a, fmt=plistlib.FMT_BINARY))
        self.assertIs(b['x'], b) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:18,代码来源:test_plistlib.py

示例12: build_device_command

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import dumps [as 别名]
def build_device_command(enrolled_device, request_type, body_command, command_uuid=None, queue=False):
    device_command = DeviceCommand(enrolled_device=enrolled_device,
                                   request_type=request_type)

    body_command["RequestType"] = request_type
    body = {"Command": body_command}

    if command_uuid:
        device_command.uuid = command_uuid
    else:
        device_command.uuid = uuid.uuid4()
    body["CommandUUID"] = str(device_command.uuid)

    device_command.body = plistlib.dumps(body).decode("utf-8")

    if not queue:
        device_command.time = timezone.now()

    device_command.save()
    return device_command 
开发者ID:zentralopensource,项目名称:zentral,代码行数:22,代码来源:commands.py

示例13: build_configuration_profile

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import dumps [as 别名]
def build_configuration_profile(enrolled_machine):
    configuration = enrolled_machine.enrollment.configuration

    payload_content = {"PayloadContent": {"com.google.santa": {"Forced": [
                            {"mcx_preference_settings": build_santa_configuration_dict(enrolled_machine)}
                        ]}},
                       "PayloadEnabled": True,
                       "PayloadIdentifier": get_payload_identifier("santa.configuration.{}".format(configuration.pk)),
                       "PayloadUUID": generate_payload_uuid(),
                       'PayloadType': 'com.apple.ManagedClient.preferences',
                       'PayloadVersion': 1}

    configuration_profile_data = {"PayloadContent": [payload_content],
                                  "PayloadDisplayName": "Zentral - Santa settings",
                                  "PayloadDescription": "Google Santa settings for Zentral",
                                  "PayloadIdentifier": "com.google.santa",
                                  "PayloadOrganization": "Zentral",
                                  "PayloadRemovalDisallowed": True,
                                  "PayloadScope": "System",
                                  "PayloadType": "Configuration",
                                  "PayloadUUID": generate_payload_uuid(),
                                  "PayloadVersion": 1}

    content = sign_payload_openssl(plistlib.dumps(configuration_profile_data))
    return "com.google.santa.zentral.mobileconfig", content 
开发者ID:zentralopensource,项目名称:zentral,代码行数:27,代码来源:utils.py

示例14: build_configuration_profile

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import dumps [as 别名]
def build_configuration_profile(enrolled_machine):
    payload_content = {"PayloadContent": {"ManagedInstalls": {"Forced": [
                           {"mcx_preference_settings": build_configuration(enrolled_machine)}
                       ]}},
                       "PayloadEnabled": True,
                       "PayloadIdentifier": get_payload_identifier("monolith.settings.0"),
                       "PayloadUUID": generate_payload_uuid(),
                       "PayloadType": "com.apple.ManagedClient.preferences",
                       "PayloadVersion": 1}
    configuration_profile_data = {"PayloadContent": [payload_content],
                                  "PayloadDescription": "Munki settings for Zentral/Monolith",
                                  "PayloadDisplayName": "Zentral - Munki settings",
                                  "PayloadIdentifier": get_payload_identifier("monolith.settings"),
                                  "PayloadOrganization": "Zentral",
                                  "PayloadRemovalDisallowed": True,
                                  "PayloadScope": "System",
                                  "PayloadType": "Configuration",
                                  "PayloadUUID": generate_payload_uuid(),
                                  "PayloadVersion": 1}
    content = sign_payload_openssl(plistlib.dumps(configuration_profile_data))
    return (get_payload_identifier("monolith.settings.mobileconfig"),
            content) 
开发者ID:zentralopensource,项目名称:zentral,代码行数:24,代码来源:utils.py

示例15: serialize_catalog

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import dumps [as 别名]
def serialize_catalog(self, tags=None):
        pkginfo_list = []

        # the repository catalogs
        for catalog in self.catalogs(tags):
            for pkginfo in catalog.iter_pkginfos():
                pkginfo_list.append(pkginfo)

        # the sub manifests attachments
        for sma in SubManifestAttachment.objects.newest().filter(sub_manifest__in=self.sub_manifests(tags)):
            pkginfo_list.append(sma.get_pkg_info())

        # the enrollment packages
        for enrollment_package in self.enrollment_packages(tags).values():
            pkginfo_list.append(enrollment_package.get_pkg_info())

        # include the catalog with all the printers for autoremove
        for printer in self.printer_set.all():
            pkginfo_list.append(printer.pkg_info)

        return plistlib.dumps(pkginfo_list)

    # the manifest 
开发者ID:zentralopensource,项目名称:zentral,代码行数:25,代码来源:models.py


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