Python plistlib.FMT_BINARY Examples
The following are 30
code examples of plistlib.FMT_BINARY().
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: test_plistlib.py From android_universal with MIT License | 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 #2
Source File: test_plistlib.py From Project-New-Reign---Nemesis-Main 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], }) if fmt != plistlib.FMT_BINARY: self.assertIsNot(pl2['first'], pl2['second'])
Example #3
Source File: test_plistlib.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.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 #4
Source File: auth.py From pyatv with MIT License | 6 votes |
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
Example #5
Source File: deserializer.py From mac_apt with MIT License | 6 votes |
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()
Example #6
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 #7
Source File: deserializer.py From iLEAPP with MIT License | 6 votes |
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()
Example #8
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 #9
Source File: test_plistlib.py From android_universal with MIT License | 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 #10
Source File: dump.py From python-shortcuts with MIT License | 5 votes |
def dump(self, file_obj: BinaryIO) -> None: # type: ignore binary = plistlib.dumps( # todo: change dumps to binary and remove this plistlib.loads(self.dumps().encode('utf-8')), # type: ignore fmt=plistlib.FMT_BINARY, ) file_obj.write(binary)
Example #11
Source File: plist.py From GenSMBIOS with MIT License | 5 votes |
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))
Example #12
Source File: client.py From opendrop with GNU General Public License v3.0 | 5 votes |
def send_discover(self): discover_body = {} 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) # if name is returned, then receiver is discoverable return response.get('ReceiverComputerName')
Example #13
Source File: server.py From opendrop with GNU General Public License v3.0 | 5 votes |
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)
Example #14
Source File: test_plistlib.py From android_universal with MIT License | 5 votes |
def test_controlcharacters(self): for i in range(128): c = chr(i) testString = "string containing %s" % c if i >= 32 or c in "\r\n\t": # \r, \n and \t are the only legal control chars in XML data = plistlib.dumps(testString, fmt=plistlib.FMT_XML) if c != "\r": self.assertEqual(plistlib.loads(data), testString) else: with self.assertRaises(ValueError): plistlib.dumps(testString, fmt=plistlib.FMT_XML) plistlib.dumps(testString, fmt=plistlib.FMT_BINARY)
Example #15
Source File: test_plistlib.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_large_timestamp(self): # Issue #26709: 32-bit timestamp out of range for ts in -2**31-1, 2**31: with self.subTest(ts=ts): d = (datetime.datetime.utcfromtimestamp(0) + datetime.timedelta(seconds=ts)) data = plistlib.dumps(d, fmt=plistlib.FMT_BINARY) self.assertEqual(plistlib.loads(data), d)
Example #16
Source File: test_plistlib.py From android_universal with MIT License | 5 votes |
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))
Example #17
Source File: test_plistlib.py From android_universal with MIT License | 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 #18
Source File: test_plistlib.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.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 #19
Source File: test_plistlib.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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))
Example #20
Source File: server.py From apple_bleee with GNU General Public License v3.0 | 5 votes |
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))
Example #21
Source File: plist.py From Web-Driver-Toolkit with MIT License | 5 votes |
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))
Example #22
Source File: client.py From HomePWN with GNU General Public License v3.0 | 5 votes |
def send_ask(self, file_path, icon=None): ask_body = { 'SenderComputerName': self.config.computer_name, 'BundleID': 'com.apple.finder', 'SenderModelName': self.config.computer_model, 'SenderID': self.config.service_id, 'ConvertMediaFormats': False, } if self.config.record_data: ask_body['SenderRecordData'] = self.config.record_data if isinstance(file_path, str): file_path = [file_path] # generate icon for first file with open(file_path[0], 'rb') as f: file_header = f.read(128) flp = fleep.get(file_header) if not icon and len(flp.mime) > 0 and 'image' in flp.mime[0]: icon = AirDropUtil.generate_file_icon(f.name) if icon: ask_body['FileIcon'] = icon def file_entries(files): for file in files: file_name = os.path.basename(file) file_entry = { 'FileName': file_name, 'FileType': AirDropUtil.get_uti_type(flp), 'FileBomPath': os.path.join('.', file_name), 'FileIsDirectory': os.path.isdir(file_name), 'ConvertMediaFormats': 0 } yield file_entry ask_body['Files'] = [e for e in file_entries(file_path)] ask_body['Items'] = [] ask_binary = plistlib.dumps(ask_body, fmt=plistlib.FMT_BINARY) success, _ = self.send_POST('/Ask', ask_binary) return success
Example #23
Source File: server.py From HomePWN with GNU General Public License v3.0 | 5 votes |
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)
Example #24
Source File: plist.py From USBMap with MIT License | 5 votes |
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))
Example #25
Source File: server.py From apple_bleee with GNU General Public License v3.0 | 5 votes |
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)
Example #26
Source File: client.py From apple_bleee with GNU General Public License v3.0 | 5 votes |
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
Example #27
Source File: plist.py From thinkpad-x1c5-hackintosh with MIT License | 5 votes |
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))
Example #28
Source File: plist.py From gibMacOS with MIT License | 5 votes |
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))
Example #29
Source File: test_plistlib.py From ironpython3 with Apache License 2.0 | 5 votes |
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))
Example #30
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)