Python plistlib.writePlistToString() Examples
The following are 30
code examples of plistlib.writePlistToString().
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: profile.py From salt-osx with MIT License | 6 votes |
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()
Example #2
Source File: test_sim.py From ccs-calendarserver with Apache License 2.0 | 6 votes |
def test_loadServerConfig(self): """ The Calendar Server host and port are loaded from the [server] section of the configuration file specified. """ config = FilePath(self.mktemp()) config.setContent( writePlistToString({"servers": { "PodA": { "enabled": True, "uri": 'https://127.0.0.3:8432/', "stats": {"enabled": False}, }, }}) ) sim = LoadSimulator.fromCommandLine(['--config', config.path]) self.assertEquals(sim.servers["PodA"]["uri"], "https://127.0.0.3:8432/")
Example #3
Source File: test_sim.py From ccs-calendarserver with Apache License 2.0 | 6 votes |
def test_loadArrivalConfig(self): """ The arrival policy type and arguments are loaded from the [arrival] section of the configuration file specified. """ config = FilePath(self.mktemp()) config.setContent( writePlistToString({ "arrival": { "factory": "contrib.performance.loadtest.population.SmoothRampUp", "params": { "groups": 10, "groupSize": 1, "interval": 3, }, }, }) ) sim = LoadSimulator.fromCommandLine(['--config', config.path]) self.assertEquals( sim.arrival, Arrival(SmoothRampUp, dict(groups=10, groupSize=1, interval=3)))
Example #4
Source File: mobile_config.py From pymobiledevice with GNU General Public License v3.0 | 6 votes |
def RemoveProfile(self, ident): profiles = self.GetProfileList() if not profiles: return if not profiles["ProfileMetadata"].has_key(ident): self.logger.info("Trying to remove not installed profile %s", ident) return meta = profiles["ProfileMetadata"][ident] pprint(meta) data = plistlib.writePlistToString({"PayloadType": "Configuration", "PayloadIdentifier": ident, "PayloadUUID": meta["PayloadUUID"], "PayloadVersion": meta["PayloadVersion"] }) self.service.sendPlist({"RequestType":"RemoveProfile", "ProfileIdentifier": plistlib.Data(data)}) return self.service.recvPlist()
Example #5
Source File: test_sim.py From ccs-calendarserver with Apache License 2.0 | 6 votes |
def test_loadLogObservers(self): """ Log observers specified in the [observers] section of the configuration file are added to the logging system. """ config = FilePath(self.mktemp()) config.setContent( writePlistToString( { "observers": [ { "type": "contrib.performance.loadtest.population.SimpleStatistics", "params": {}, }, ] } ) ) sim = LoadSimulator.fromCommandLine(['--config', config.path]) self.assertEquals(len(sim.observers), 1) self.assertIsInstance(sim.observers[0], SimpleStatistics)
Example #6
Source File: test_plistlib.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 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 plistlib.writePlistToString(testString) else: self.assertRaises(ValueError, plistlib.writePlistToString, testString)
Example #7
Source File: test_plistlib.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_appleformatting(self): pl = plistlib.readPlistFromString(TESTDATA) data = plistlib.writePlistToString(pl) self.assertEqual(data, TESTDATA, "generated data was not identical to Apple's output")
Example #8
Source File: test_plistlib.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_nondictroot(self): test1 = "abc" test2 = [1, 2, 3, "abc"] result1 = plistlib.readPlistFromString(plistlib.writePlistToString(test1)) result2 = plistlib.readPlistFromString(plistlib.writePlistToString(test2)) self.assertEqual(test1, result1) self.assertEqual(test2, result2)
Example #9
Source File: test_plistlib.py From CTFCrackTools with GNU General Public License v3.0 | 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 plistlib.writePlistToString(testString) else: self.assertRaises(ValueError, plistlib.writePlistToString, testString)
Example #10
Source File: test_plistlib.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_appleformatting(self): pl = plistlib.readPlistFromString(TESTDATA) data = plistlib.writePlistToString(pl) self.assertEqual(data, TESTDATA, "generated data was not identical to Apple's output")
Example #11
Source File: test_plistlib.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_string(self): pl = self._create() data = plistlib.writePlistToString(pl) pl2 = plistlib.readPlistFromString(data) self.assertEqual(dict(pl), dict(pl2)) data2 = plistlib.writePlistToString(pl2) self.assertEqual(data, data2)
Example #12
Source File: __init__.py From Alfred_SourceTree with MIT License | 5 votes |
def writePlistToString(rootObject, binary=True): if not binary: rootObject = wrapDataObject(rootObject, binary) if hasattr(plistlib, "dumps"): return plistlib.dumps(rootObject) elif hasattr(plistlib, "writePlistToBytes"): return plistlib.writePlistToBytes(rootObject) else: return plistlib.writePlistToString(rootObject) else: ioObject = io.BytesIO() writer = PlistWriter(ioObject) writer.writeRoot(rootObject) return ioObject.getvalue()
Example #13
Source File: test_plistlib.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_nondictroot(self): test1 = "abc" test2 = [1, 2, 3, "abc"] result1 = plistlib.readPlistFromString(plistlib.writePlistToString(test1)) result2 = plistlib.readPlistFromString(plistlib.writePlistToString(test2)) self.assertEqual(test1, result1) self.assertEqual(test2, result2)
Example #14
Source File: test_plistlib.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_nondictroot(self): test1 = "abc" test2 = [1, 2, 3, "abc"] result1 = plistlib.readPlistFromString(plistlib.writePlistToString(test1)) result2 = plistlib.readPlistFromString(plistlib.writePlistToString(test2)) self.assertEqual(test1, result1) self.assertEqual(test2, result2)
Example #15
Source File: mobile_config.py From pymobiledevice with GNU General Public License v3.0 | 5 votes |
def InstallProfile(self, s): #s = plistlib.writePlistToString(payload) self.service.sendPlist({"RequestType":"InstallProfile", "Payload": plistlib.Data(s)}) return self.service.recvPlist()
Example #16
Source File: lockdown.py From pymobiledevice with GNU General Public License v3.0 | 5 votes |
def pair(self): self.DevicePublicKey = self.getValue("", "DevicePublicKey") if self.DevicePublicKey == '': self.logger.error("Unable to retreive DevicePublicKey") return False self.logger.info("Creating host key & certificate") certPem, privateKeyPem, DeviceCertificate = ca_do_everything(self.DevicePublicKey) pair_record = {"DevicePublicKey": plistlib.Data(self.DevicePublicKey), "DeviceCertificate": plistlib.Data(DeviceCertificate), "HostCertificate": plistlib.Data(certPem), "HostID": self.hostID, "RootCertificate": plistlib.Data(certPem), "SystemBUID": "30142955-444094379208051516"} pair = {"Label": self.label, "Request": "Pair", "PairRecord": pair_record} self.c.sendPlist(pair) pair = self.c.recvPlist() if pair and pair.get("Result") == "Success" or pair.has_key("EscrowBag"): pair_record["HostPrivateKey"] = plistlib.Data(privateKeyPem) pair_record["EscrowBag"] = pair.get("EscrowBag") writeHomeFile(HOMEFOLDER, "%s.plist" % self.identifier, plistlib.writePlistToString(pair_record)) self.paired = True return True elif pair and pair.get("Error") == "PasswordProtected": self.c.close() raise NotTrustedError else: self.logger.error(pair.get("Error")) self.c.close() raise PairingError
Example #17
Source File: plist_service.py From pymobiledevice with GNU General Public License v3.0 | 5 votes |
def sendPlist(self, d): payload = plistlib.writePlistToString(d) l = struct.pack(">L", len(payload)) return self.send(l + payload)
Example #18
Source File: test_plistlib.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_nondictroot(self): test1 = "abc" test2 = [1, 2, 3, "abc"] result1 = plistlib.readPlistFromString(plistlib.writePlistToString(test1)) result2 = plistlib.readPlistFromString(plistlib.writePlistToString(test2)) self.assertEqual(test1, result1) self.assertEqual(test2, result2)
Example #19
Source File: test_plistlib.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_appleformatting(self): pl = plistlib.readPlistFromString(TESTDATA) data = plistlib.writePlistToString(pl) self.assertEqual(data, TESTDATA, "generated data was not identical to Apple's output")
Example #20
Source File: test_plistlib.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_string(self): pl = self._create() data = plistlib.writePlistToString(pl) pl2 = plistlib.readPlistFromString(data) self.assertEqual(dict(pl), dict(pl2)) data2 = plistlib.writePlistToString(pl2) self.assertEqual(data, data2)
Example #21
Source File: test_plistlib.py From medicare-demo with Apache License 2.0 | 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 plistlib.writePlistToString(testString) else: self.assertRaises(ValueError, plistlib.writePlistToString, testString)
Example #22
Source File: test_plistlib.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_appleformatting(self): pl = plistlib.readPlistFromString(TESTDATA) data = plistlib.writePlistToString(pl) self.assertEqual(data, TESTDATA, "generated data was not identical to Apple's output")
Example #23
Source File: test_plistlib.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_indentation_dict_mix(self): data = {'1': {'2': [{'3': [[[[[{'test': plistlib.Data(b'aaaaaa')}]]]]]}]}} self.assertEqual(plistlib.readPlistFromString(plistlib.writePlistToString(data)), data)
Example #24
Source File: test_plistlib.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_indentation_dict(self): data = {'1': {'2': {'3': {'4': {'5': {'6': {'7': {'8': {'9': plistlib.Data(b'aaaaaa')}}}}}}}}} self.assertEqual(plistlib.readPlistFromString(plistlib.writePlistToString(data)), data)
Example #25
Source File: test_plistlib.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_indentation_array(self): data = [[[[[[[[{'test': plistlib.Data(b'aaaaaa')}]]]]]]]] self.assertEqual(plistlib.readPlistFromString(plistlib.writePlistToString(data)), data)
Example #26
Source File: test_plistlib.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_string(self): pl = self._create() data = plistlib.writePlistToString(pl) pl2 = plistlib.readPlistFromString(data) self.assertEqual(dict(pl), dict(pl2)) data2 = plistlib.writePlistToString(pl2) self.assertEqual(data, data2)
Example #27
Source File: test_sim.py From ccs-calendarserver with Apache License 2.0 | 5 votes |
def test_requireClient(self): """ At least one client is required, so if a configuration with an empty clients array is specified, a single default client type is used. """ config = FilePath(self.mktemp()) config.setContent(writePlistToString({"clients": []})) sim = LoadSimulator.fromCommandLine( ['--config', config.path, '--clients', config.path] ) expectedParameters = PopulationParameters() expectedParameters.addClient( 1, ClientType(OS_X_10_6, {}, [Eventer, Inviter, Accepter])) self.assertEquals(sim.parameters, expectedParameters)
Example #28
Source File: test_sim.py From ccs-calendarserver with Apache License 2.0 | 5 votes |
def test_generateRecordsDefaultPatterns(self): """ L{LoadSimulator.fromCommandLine} takes an account loader from the config file and uses it to generate user records for use in the simulation. """ config = VALID_CONFIG.copy() config["accounts"] = { "loader": "contrib.performance.loadtest.sim.generateRecords", "params": { "count": 2 }, } configpath = FilePath(self.mktemp()) configpath.setContent(writePlistToString(config)) sim = LoadSimulator.fromCommandLine(['--config', configpath.path], StringIO()) self.assertEqual(2, len(sim.records)) self.assertEqual(sim.records[0].uid, 'user1') self.assertEqual(sim.records[0].password, 'user1') self.assertEqual(sim.records[0].commonName, 'User 1') self.assertEqual(sim.records[0].email, 'user1@example.com') self.assertEqual(sim.records[1].uid, 'user2') self.assertEqual(sim.records[1].password, 'user2') self.assertEqual(sim.records[1].commonName, 'User 2') self.assertEqual(sim.records[1].email, 'user2@example.com')
Example #29
Source File: test_sim.py From ccs-calendarserver with Apache License 2.0 | 5 votes |
def test_loadDefaultAccountsFromFile(self): """ L{LoadSimulator.fromCommandLine} takes an account loader (with empty path)from the config file and uses it to create user records for use in the simulation. """ config = VALID_CONFIG.copy() config["accounts"] = { "loader": "contrib.performance.loadtest.sim.recordsFromCSVFile", "params": { "path": "", "interleavePods": True, }, } configpath = FilePath(self.mktemp()) configpath.setContent(writePlistToString(config)) sim = LoadSimulator.fromCommandLine(['--config', configpath.path], StringIO()) self.assertEqual(99, len(sim.records)) self.assertEqual(sim.records[0].uid, 'user01') self.assertEqual(sim.records[0].password, 'user01') self.assertEqual(sim.records[0].commonName, 'User 01') self.assertEqual(sim.records[0].email, 'user01@example.com') self.assertEqual(sim.records[98].uid, 'user99') self.assertEqual(sim.records[98].password, 'user99') self.assertEqual(sim.records[98].commonName, 'User 99') self.assertEqual(sim.records[98].email, 'user99@example.com')
Example #30
Source File: ampsim.py From ccs-calendarserver with Apache License 2.0 | 5 votes |
def connectionMade(self): super(Manager, self).connectionMade() for record in self.loadsim.records: self.callRemote(Account, uid=record.uid, password=record.password, commonName=record.commonName, email=record.email, guid=record.guid) workerConfig = deepcopy(self.loadsim.configTemplate) # The list of workers is for the manager only; the workers themselves # know they're workers because they _don't_ receive this list. del workerConfig["workers"] # The manager loads the accounts via the configured loader, then sends # them out to the workers (right above), which look at the state at an # instance level and therefore don't need a globally-named directory # record loader. del workerConfig["accounts"] workerConfig["workerID"] = self.whichWorker workerConfig["workerCount"] = self.numWorkers workerConfig["observers"] = [] workerConfig.pop("accounts", None) plist = writePlistToString(workerConfig) self.output.write("Initiating worker configuration\n") def completed(x): self.output.write("Worker configuration complete.\n") def failed(reason): self.output.write("Worker configuration failed. {}\n".format(reason)) self.callRemote(Configure, plist=plist).addCallback(completed).addErrback(failed)