當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。