Python plistlib.loads() Examples
The following are 30
code examples of plistlib.loads().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
plistlib
, or try the search function
.
Example #1
Source File: uuid_device.py From plugin.video.hbogoeu with GNU General Public License v2.0 | 6 votes |
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
Example #2
Source File: test_plistlib.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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'])
Example #3
Source File: test_plistlib.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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'])
Example #4
Source File: test_plistlib.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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'})
Example #5
Source File: test_plistlib.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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'])
Example #6
Source File: test_plistlib.py From ironpython3 with Apache License 2.0 | 6 votes |
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)
Example #7
Source File: airplay.py From pyatv with MIT License | 6 votes |
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)
Example #8
Source File: auth.py From pyatv with MIT License | 6 votes |
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
Example #9
Source File: decorators.py From commandment with MIT License | 6 votes |
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
Example #10
Source File: test_plistlib.py From ironpython3 with Apache License 2.0 | 6 votes |
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)
Example #11
Source File: test_plistlib.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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)
Example #12
Source File: test_plistlib.py From ironpython3 with Apache License 2.0 | 6 votes |
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)
Example #13
Source File: test_plistlib.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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)
Example #14
Source File: test_plistlib.py From ironpython3 with Apache License 2.0 | 6 votes |
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'])
Example #15
Source File: test_plistlib.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
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)
Example #16
Source File: test_plistlib.py From ironpython3 with Apache License 2.0 | 6 votes |
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'})
Example #17
Source File: test_plistlib.py From ironpython3 with Apache License 2.0 | 6 votes |
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'])
Example #18
Source File: test_plistlib.py From ironpython3 with Apache License 2.0 | 6 votes |
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'])
Example #19
Source File: uuid_device.py From plugin.video.netflix with MIT License | 6 votes |
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
Example #20
Source File: test_plistlib.py From ironpython3 with Apache License 2.0 | 6 votes |
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))
Example #21
Source File: plistinfo.py From macbuild-ansible with MIT License | 6 votes |
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
Example #22
Source File: client.py From HomePWN with GNU General Public License v3.0 | 5 votes |
def send_discover(self): a = './utildata/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) success, response_bytes = self.send_POST('/Discover', discover_plist_binary) response = plistlib.loads(response_bytes) return response
Example #23
Source File: appmanifest.py From commandment with MIT License | 5 votes |
def url_from_metadata(path: str) -> Optional[str]: """Try to determine the download URL from the spotlight attributes if the local machine is a mac.""" try: from Foundation import NSFileManager, NSPropertyListSerialization except: return None fm = NSFileManager.defaultManager() attrs, err = fm.attributesOfItemAtPath_error_(path, None) if err: return None if 'NSFileExtendedAttributes' not in attrs: return None extd_attrs = attrs['NSFileExtendedAttributes'] if 'com.apple.metadata:kMDItemWhereFroms' not in extd_attrs: return None else: plist_data: bytes = extd_attrs['com.apple.metadata:kMDItemWhereFroms'] value: List[str] = plistlib.loads(plist_data) if len(value) > 0: return value.pop(0) else: return None
Example #24
Source File: test_plistlib.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_invalidinteger(self): self.assertRaises(ValueError, plistlib.loads, b"<plist><integer>not integer</integer></plist>")
Example #25
Source File: dep.py From zentral with Apache License 2.0 | 5 votes |
def get_payload(self): # Verify payload signature, extract signed payload try: payload_data = verify_iphone_ca_signed_payload(self.get_payload_data()) except ValueError: self.abort("Could not verify signer certificate") payload = plistlib.loads(payload_data) self.serial_number = payload["SERIAL"] self.udid = payload["UDID"] return payload
Example #26
Source File: installinstallmacos.py From runMacOSinVirtualBox with MIT License | 5 votes |
def read_plist_from_string(bytestring): '''Wrapper for the differences between Python 2 and Python 3's plistlib''' try: return plistlib.loads(bytestring) except AttributeError: # plistlib module doesn't have a load function (as in Python 2) return plistlib.readPlistFromString(bytestring)
Example #27
Source File: disk.py From sky3ds.py with MIT License | 5 votes |
def get_disk_size(self): """Get sdcard size in bytes This currently is an ugly workaround. It seeks to the end of the sdcard and reads how many bytes were skipped. This should be replaced with something more clean.""" if sys.platform == 'darwin': # meh if not re.match("^\/dev\/disk[0-9]+$", self.disk_path): raise Exception("Disk path must be in format /dev/diskN") try: diskname = os.path.basename(self.disk_path) diskutil_output = subprocess.check_output(["diskutil", "list", "-plist", self.disk_path]) if sys.version_info.major == 3: diskutil_plist = plistlib.loads(diskutil_output) else: diskutil_plist = plistlib.readPlistFromString(diskutil_output) disk_plist = diskutil_plist['AllDisksAndPartitions'][0] if not disk_plist['DeviceIdentifier'] == diskname: raise Exception("DeviceIdentifier doesn't match, won't continue.") self.disk_size = disk_plist['Size'] except Exception as e: raise Exception("Can't get disk size from diskutil :(\nError was: %s" % e) else: self.diskfp.seek(0, os.SEEK_END) disk_size = self.diskfp.tell() disk_size = disk_size - disk_size % 0x2000000 if disk_size == 0: raise Exception("0 byte disk?!") self.disk_size = disk_size
Example #28
Source File: test_plistlib.py From ironpython3 with Apache License 2.0 | 5 votes |
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)
Example #29
Source File: test_plistlib.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_nonstandard_refs_size(self): # Issue #21538: Refs and offsets are 24-bit integers data = (b'bplist00' b'\xd1\x00\x00\x01\x00\x00\x02QaQb' b'\x00\x00\x08\x00\x00\x0f\x00\x00\x11' b'\x00\x00\x00\x00\x00\x00' b'\x03\x03' b'\x00\x00\x00\x00\x00\x00\x00\x03' b'\x00\x00\x00\x00\x00\x00\x00\x00' b'\x00\x00\x00\x00\x00\x00\x00\x13') self.assertEqual(plistlib.loads(data), {'a': 'b'})
Example #30
Source File: test_plistlib.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_appleformattingfromliteral(self): self.maxDiff = None for fmt in ALL_FORMATS: with self.subTest(fmt=fmt): pl = self._create(fmt=fmt) pl2 = plistlib.loads(TESTDATA[fmt], fmt=fmt) self.assertEqual(dict(pl), dict(pl2), "generated data was not identical to Apple's output") pl2 = plistlib.loads(TESTDATA[fmt]) self.assertEqual(dict(pl), dict(pl2), "generated data was not identical to Apple's output")