本文整理汇总了Python中plistlib.loads方法的典型用法代码示例。如果您正苦于以下问题:Python plistlib.loads方法的具体用法?Python plistlib.loads怎么用?Python plistlib.loads使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plistlib
的用法示例。
在下文中一共展示了plistlib.loads方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import loads [as 别名]
def main():
try:
try:
plist_file = determine_plist_path(sys.argv[1])
with open(plist_file, 'rb') as f:
plist_data = plistlib.load(f)
except IndexError:
plist_file = '<stdin>'
plist_data = plistlib.loads(sys.stdin.buffer.read())
print(yaml.dump(plist_data, default_flow_style=False), end='')
except IOError:
print(f'{RED}Error: The requested plist file {plist_file} was not found{ENDC}')
exit(1)
except plistlib.InvalidFileException:
print(f'{RED}Error: Unable to parse the requested plist file {plist_file}{ENDC}')
exit(1)
except KeyboardInterrupt:
pass
示例2: _parse_osx_xml_plist_data
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import loads [as 别名]
def _parse_osx_xml_plist_data(data):
import plistlib
import re
dict_values = {}
try: # Python 2
xml_data = plistlib.readPlistFromString(data)
except AttributeError: # Python => 3.4
# pylint: disable=no-member
xml_data = plistlib.loads(data)
items_dict = xml_data[0]['_items'][0]
r = re.compile(r'.*UUID.*') # Find to example "platform_UUID" key
uuid_keys = list(filter(r.match, list(items_dict.keys())))
if uuid_keys:
dict_values['UUID'] = items_dict[uuid_keys[0]]
if not uuid_keys:
r = re.compile(r'.*serial.*number.*') # Find to example "serial_number" key
serialnumber_keys = list(filter(r.match, list(items_dict.keys())))
if serialnumber_keys:
dict_values['serialnumber'] = items_dict[serialnumber_keys[0]]
return dict_values
示例3: test_int
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import loads [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)
示例4: test_keysort
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import loads [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'])
示例5: test_skipkeys
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import loads [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'})
示例6: test_tuple_members
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import loads [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'])
示例7: test_list_members
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import loads [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'])
示例8: test_dataobject_deprecated
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import loads [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)
示例9: test_tuple_members
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import loads [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'])
示例10: test_dict_members
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import loads [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'])
示例11: test_xml_encodings
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import loads [as 别名]
def test_xml_encodings(self):
base = TESTDATA[plistlib.FMT_XML]
for xml_encoding, encoding, bom in [
(b'utf-8', 'utf-8', codecs.BOM_UTF8),
(b'utf-16', 'utf-16-le', codecs.BOM_UTF16_LE),
(b'utf-16', 'utf-16-be', codecs.BOM_UTF16_BE),
# Expat does not support UTF-32
#(b'utf-32', 'utf-32-le', codecs.BOM_UTF32_LE),
#(b'utf-32', 'utf-32-be', codecs.BOM_UTF32_BE),
]:
pl = self._create(fmt=plistlib.FMT_XML)
with self.subTest(encoding=encoding):
data = base.replace(b'UTF-8', xml_encoding)
data = bom + data.decode('utf-8').encode(encoding)
pl2 = plistlib.loads(data)
self.assertEqual(dict(pl), dict(pl2))
示例12: test_cycles
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import loads [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)
示例13: parse_plist_input_data
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import loads [as 别名]
def parse_plist_input_data(f):
"""Parses plist data as HTTP input from request.
The unserialized data is attached to the global **g** object as **g.plist_data**.
:status 400: If invalid plist data was supplied in the request.
"""
@wraps(f)
def decorator(*args, **kwargs):
try:
if current_app.debug:
current_app.logger.debug(request.data)
g.plist_data = plistlib.loads(request.data)
except:
current_app.logger.info('could not parse property list input data')
abort(400, 'invalid input data')
return f(*args, **kwargs)
return decorator
示例14: handle_airplay_play
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import loads [as 别名]
def handle_airplay_play(self, request):
"""Handle AirPlay play requests."""
self.state.play_count += 1
if self.state.always_auth_fail or not self.state.has_authenticated:
return web.Response(status=503)
if self.state.injected_play_fails > 0:
self.state.injected_play_fails -= 1
return web.Response(status=500)
headers = request.headers
# Verify headers first
assert headers["User-Agent"] == "MediaControl/1.0"
assert headers["Content-Type"] == "application/x-apple-binary-plist"
body = await request.read()
parsed = plistlib.loads(body)
self.state.last_airplay_url = parsed["Content-Location"]
self.state.last_airplay_start = parsed["Start-Position"]
self.state.last_airplay_uuid = parsed["X-Apple-Session-ID"]
return web.Response(status=200)
示例15: finish_authentication
# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import loads [as 别名]
def finish_authentication(self, username, password):
"""Finish authentication process.
A username (generated by new_credentials) and the PIN code shown on
screen must be provided.
"""
# Step 1
self.srp.step1(username, password)
data = await self._send_plist("step1", method="pin", user=username)
resp = plistlib.loads(data)
# Step 2
pub_key, key_proof = self.srp.step2(resp["pk"], resp["salt"])
await self._send_plist(
"step2", pk=binascii.unhexlify(pub_key), proof=binascii.unhexlify(key_proof)
)
# Step 3
epk, tag = self.srp.step3()
await self._send_plist("step3", epk=epk, authTag=tag)
return True