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


Python plistlib.FMT_BINARY属性代码示例

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


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

示例1: test_tuple_members

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_BINARY [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],
                })
                if fmt != plistlib.FMT_BINARY:
                    self.assertIsNot(pl2['first'], pl2['second']) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:20,代码来源:test_plistlib.py

示例2: test_cycles

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_BINARY [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

示例3: _send_plist

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_BINARY [as 别名]
def _send_plist(self, step, **kwargs):
        plist = dict((str(k), v) for k, v in kwargs.items())

        headers = copy(_AIRPLAY_HEADERS)
        headers["Content-Type"] = "application/x-apple-binary-plist"

        # TODO: For some reason pylint does not find FMT_BINARY, why?
        # pylint: disable=no-member
        resp, code = await self.http.post_data(
            "pair-setup-pin", data=plistlib.dumps(plist, fmt=plistlib.FMT_BINARY)
        )
        if code != 200:
            raise AuthenticationError("{0} failed with code {1}".format(step, code))
        return resp


# pylint: disable=too-few-public-methods 
开发者ID:postlund,项目名称:pyatv,代码行数:19,代码来源:auth.py

示例4: write_plist_to_file

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_BINARY [as 别名]
def write_plist_to_file(deserialised_plist, output_path):
    #Using plistLib to write plist
    out_file = None
    try:
        print('Writing out .. ' + output_path)
        out_file = open(output_path, 'wb')
        try:
            plistlib.dump(deserialised_plist, out_file, fmt=plistlib.FMT_BINARY)
            out_file.close()
            return True
        except (TypeError, OverflowError, OSError) as ex:
            out_file.close()
            print('Had an exception (error)')
            traceback.print_exc()
    except OSError as ex:
        print('Error opening file for writing: Error={} Path={}'.format(output_path, str(ex)))
    # Try using biplist
    try:
        print('Writing out (using biplist) .. ' + output_path)
        biplist.writePlist(deserialised_plist, output_path)
        return True
    except (biplist.InvalidPlistException, biplist.NotBinaryPlistException, OSError) as ex:
        print('Had an exception (error)')
        traceback.print_exc() 
开发者ID:ydkhatri,项目名称:mac_apt,代码行数:26,代码来源:deserializer.py

示例5: dump

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_BINARY [as 别名]
def dump(value, fp, fmt=FMT_XML, sort_keys=True, skipkeys=False):
    if _check_py3():
        plistlib.dump(value, fp, fmt=fmt, sort_keys=sort_keys, skipkeys=skipkeys)
    else:
        if fmt == FMT_XML:
            # We need to monkey patch a bunch here too in order to avoid auto-sorting
            # of keys
            writer = plistlib.PlistWriter(fp)
            def writeDict(d):
                if d:
                    writer.beginElement("dict")
                    items = sorted(d.items()) if sort_keys else d.items()
                    for key, value in items:
                        if not isinstance(key, basestring):
                            if skipkeys:
                                continue
                            raise TypeError("keys must be strings")
                        writer.simpleElement("key", key)
                        writer.writeValue(value)
                    writer.endElement("dict")
                else:
                    writer.simpleElement("dict")
            writer.writeDict = writeDict
            writer.writeln("<plist version=\"1.0\">")
            writer.writeValue(value)
            writer.writeln("</plist>")
        elif fmt == FMT_BINARY:
            # Assume binary at this point
            writer = _BinaryPlistWriter(fp, sort_keys=sort_keys, skipkeys=skipkeys)
            writer.write(value)
        else:
            # Not a proper format
            raise ValueError("Unsupported format: {}".format(fmt)) 
开发者ID:corpnewt,项目名称:USBMap,代码行数:35,代码来源:plist.py

示例6: print_info

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_BINARY [as 别名]
def print_info(self, post_data):
        print ("[*] Found one..")
        z = plistlib.loads(post_data, fmt=plistlib.FMT_BINARY)['SenderRecordData']
        result = re.search('<key>ValidatedPhoneHashes</key>(.*)</array>', str(z))
        rez = result.group(1)
        if rez:
            rez = rez.replace("<array>",'').replace("<string>",'').replace("</string>",'').replace("\\n",'').replace("\\t",'')
            # print (rez)
            devices.append({"ip":self.client_address[0],"hash":rez, "phone":""})
            logger.debug("IPv6:{}\nPhone hash: {}".format(self.client_address[0],rez)) 
开发者ID:hexway,项目名称:apple_bleee,代码行数:12,代码来源:server.py

示例7: handle_ask

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_BINARY [as 别名]
def handle_ask(self):
        content_length = int(self.headers['Content-Length'])
        post_data = self.rfile.read(content_length)

        AirDropUtil.write_debug(self.config, post_data, 'receive_ask_request.plist')

        ask_response = {'ReceiverModelName': self.config.computer_model,
                        'ReceiverComputerName': self.config.computer_name}
        ask_resp_binary = plistlib.dumps(ask_response, fmt=plistlib.FMT_BINARY)

        AirDropUtil.write_debug(self.config, ask_resp_binary, 'receive_ask_response.plist')

        self._set_response(len(ask_resp_binary))
        self.wfile.write(ask_resp_binary) 
开发者ID:hexway,项目名称:apple_bleee,代码行数:16,代码来源:server.py

示例8: send_discover

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_BINARY [as 别名]
def send_discover(self):
        # discover_body = {}
        a = '/root/.opendrop/debug/receive_discover_request.plist'
        discover_body = plistlib.readPlist(a)
        if self.config.record_data:
            discover_body['SenderRecordData'] = self.config.record_data
        discover_plist_binary = plistlib.dumps(discover_body, fmt=plistlib.FMT_BINARY)
        # print (discover_plist_binary)
        success, response_bytes = self.send_POST('/Discover', discover_plist_binary)
        response = plistlib.loads(response_bytes)
        # print (response)
        # if name is returned, then receiver is discoverable
        return response 
开发者ID:hexway,项目名称:apple_bleee,代码行数:15,代码来源:client.py

示例9: dump

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_BINARY [as 别名]
def dump(value, fp, fmt=FMT_XML, sort_keys=True, skipkeys=False):
    if _check_py3():
        plistlib.dump(value, fp, fmt=fmt, sort_keys=sort_keys, skipkeys=skipkeys)
    else:
        if fmt == FMT_XML:
            # We need to monkey patch a bunch here too in order to avoid auto-sorting
            # of keys
            writer = plistlib.PlistWriter(fp)
            def writeDict(d):
                if d:
                    writer.beginElement("dict")
                    items = sorted(d.items()) if sort_keys else d.items()
                    for key, value in items:
                        if not isinstance(key, (str,unicode)):
                            if skipkeys:
                                continue
                            raise TypeError("keys must be strings")
                        writer.simpleElement("key", key)
                        writer.writeValue(value)
                    writer.endElement("dict")
                else:
                    writer.simpleElement("dict")
            writer.writeDict = writeDict
            writer.writeln("<plist version=\"1.0\">")
            writer.writeValue(value)
            writer.writeln("</plist>")
        elif fmt == FMT_BINARY:
            # Assume binary at this point
            writer = _BinaryPlistWriter(fp, sort_keys=sort_keys, skipkeys=skipkeys)
            writer.write(value)
        else:
            # Not a proper format
            raise ValueError("Unsupported format: {}".format(fmt)) 
开发者ID:B0hrer,项目名称:thinkpad-x1c5-hackintosh,代码行数:35,代码来源:plist.py

示例10: test_dump_duplicates

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_BINARY [as 别名]
def test_dump_duplicates(self):
        # Test effectiveness of saving duplicated objects
        for x in (None, False, True, 12345, 123.45, 'abcde', b'abcde',
                  datetime.datetime(2004, 10, 26, 10, 33, 33),
                  plistlib.Data(b'abcde'), bytearray(b'abcde'),
                  [12, 345], (12, 345), {'12': 345}):
            with self.subTest(x=x):
                data = plistlib.dumps([x]*1000, fmt=plistlib.FMT_BINARY)
                self.assertLess(len(data), 1100, repr(data)) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:11,代码来源:test_plistlib.py

示例11: test_identity

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_BINARY [as 别名]
def test_identity(self):
        for x in (None, False, True, 12345, 123.45, 'abcde', b'abcde',
                  datetime.datetime(2004, 10, 26, 10, 33, 33),
                  plistlib.Data(b'abcde'), bytearray(b'abcde'),
                  [12, 345], (12, 345), {'12': 345}):
            with self.subTest(x=x):
                data = plistlib.dumps([x]*2, fmt=plistlib.FMT_BINARY)
                a, b = plistlib.loads(data)
                if isinstance(x, tuple):
                    x = list(x)
                self.assertEqual(a, x)
                self.assertEqual(b, x)
                self.assertIs(a, b) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:15,代码来源:test_plistlib.py

示例12: test_parse_binary_plist

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_BINARY [as 别名]
def test_parse_binary_plist(self):
        data = {"key": "value"}
        in_data = tags.raw_tag("plst", plistlib.dumps(data, fmt=plistlib.FMT_BINARY))
        parsed = parser.parse(in_data, lookup_tag)
        self.assertEqual(1, len(parsed))
        self.assertEqual(data, parser.first(parsed, "plst")) 
开发者ID:postlund,项目名称:pyatv,代码行数:8,代码来源:test_parser.py

示例13: play_url

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_BINARY [as 别名]
def play_url(self, url, position=0):
        """Play media from an URL on the device."""
        body = {
            "Content-Location": url,
            "Start-Position": position,
            "X-Apple-Session-ID": str(uuid4()),
        }

        retry = 0
        while retry < PLAY_RETRIES:
            _LOGGER.debug("Starting to play %s", url)

            # pylint: disable=no-member
            _, status = await self.http.post_data(
                "play",
                headers=HEADERS,
                data=plistlib.dumps(body, fmt=plistlib.FMT_BINARY),
            )

            # Sometimes AirPlay fails with "Internal Server Error", we
            # apply a "lets try again"-approach to that
            if status == 500:
                retry += 1
                _LOGGER.debug(
                    "Failed to stream %s, retry %d of %d", url, retry, PLAY_RETRIES
                )
                await asyncio.sleep(1.0, loop=self.loop)
                continue

            # TODO: Should be more fine-grained
            if 400 <= status < 600:
                raise exceptions.AuthenticationError("Status code: " + str(status))

            await self._wait_for_media_to_end()
            return

        raise exceptions.PlaybackError("Max retries exceeded")

    # Poll playback-info to find out if something is playing. It might take
    # some time until the media starts playing, give it 5 seconds (attempts) 
开发者ID:postlund,项目名称:pyatv,代码行数:42,代码来源:player.py

示例14: read_bplist

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_BINARY [as 别名]
def read_bplist(data, start, length):
    """Extract a binary plist from a position in a sequence."""
    # TODO: pylint doesn't find FMT_BINARY, why?
    # pylint: disable=no-member
    return plistlib.loads(data[start : start + length], fmt=plistlib.FMT_BINARY) 
开发者ID:postlund,项目名称:pyatv,代码行数:7,代码来源:tags.py

示例15: alert_discovery

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_BINARY [as 别名]
def alert_discovery(self, post_data):
        try:
            z = plistlib.loads(post_data, fmt=plistlib.FMT_BINARY)['SenderRecordData']
            result = re.search('<key>ValidatedPhoneHashes</key>(.*)</array>', str(z))
            rez = result.group(1)
            if rez:
                rez = rez.replace("<array>",'').replace("<string>",'').replace("</string>",'').replace("\\n",'').replace("\\t",'')
                self.callback(
                    {"ip":self.client_address[0],"hash":rez, "phone":""}
                )
                
                logger.debug("IPv6:{}\nPhone hash: {}".format(self.client_address[0],rez))
        except Exception as e:
            print(e)
            pass 
开发者ID:ElevenPaths,项目名称:HomePWN,代码行数:17,代码来源:server.py


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