本文整理匯總了Python中plistlib.Data方法的典型用法代碼示例。如果您正苦於以下問題:Python plistlib.Data方法的具體用法?Python plistlib.Data怎麽用?Python plistlib.Data使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類plistlib
的用法示例。
在下文中一共展示了plistlib.Data方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: AddAnchorCertificate
# 需要導入模塊: import plistlib [as 別名]
# 或者: from plistlib import Data [as 別名]
def AddAnchorCertificate(self, certificate):
"""Adds a certificate payload to the profile for server identification.
Args:
certificate: str, PEM-formatted certificate.
Raises:
CertificateError: there was an error processing the certificate
"""
try:
cert = certs.Certificate(certificate)
except certs.CertError as e:
raise CertificateError(e)
payload = {PAYLOADKEYS_IDENTIFIER: self._GenerateID(cert.osx_fingerprint),
PAYLOADKEYS_TYPE: 'com.apple.security.pkcs1',
PAYLOADKEYS_DISPLAYNAME: cert.subject_cn,
PAYLOADKEYS_CONTENT: plistlib.Data(certificate)}
# Validate payload to generate its UUID
ValidatePayload(payload)
self._anchor_certs.append(payload.get(PAYLOADKEYS_UUID))
self.AddPayload(payload)
示例2: _create
# 需要導入模塊: import plistlib [as 別名]
# 或者: from plistlib import Data [as 別名]
def _create(self):
pl = dict(
aString="Doodah",
aList=["A", "B", 12, 32.5, [1, 2, 3]],
aFloat = 0.5,
anInt = 728,
aDict=dict(
anotherString="<hello & 'hi' there!>",
aUnicodeValue=u'M\xe4ssig, Ma\xdf',
aTrueValue=True,
aFalseValue=False,
deeperDict=dict(a=17, b=32.5, c=[1, 2, "text"]),
),
someData = plistlib.Data("<binary gunk>"),
someMoreData = plistlib.Data("<lots of binary gunk>\0\1\2\3" * 10),
nestedData = [plistlib.Data("<lots of binary gunk>\0\1\2\3" * 10)],
aDate = datetime.datetime(2004, 10, 26, 10, 33, 33),
)
pl[u'\xc5benraa'] = "That was a unicode key."
return pl
示例3: wrapDataObject
# 需要導入模塊: import plistlib [as 別名]
# 或者: from plistlib import Data [as 別名]
def wrapDataObject(o, for_binary=False):
if isinstance(o, Data) and not for_binary:
v = sys.version_info
if not (v[0] >= 3 and v[1] >= 4):
o = plistlib.Data(o)
elif isinstance(o, (bytes, plistlib.Data)) and for_binary:
if hasattr(o, 'data'):
o = Data(o.data)
elif isinstance(o, tuple):
o = wrapDataObject(list(o), for_binary)
o = tuple(o)
elif isinstance(o, list):
for i in range(len(o)):
o[i] = wrapDataObject(o[i], for_binary)
elif isinstance(o, dict):
for k in o:
o[k] = wrapDataObject(o[k], for_binary)
return o
示例4: test_dataobject_deprecated
# 需要導入模塊: import plistlib [as 別名]
# 或者: from plistlib import Data [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)
示例5: get_type
# 需要導入模塊: import plistlib [as 別名]
# 或者: from plistlib import Data [as 別名]
def get_type(self, value):
if isinstance(value, dict):
return self.menu_code + " Dictionary"
elif isinstance(value, list):
return self.menu_code + " Array"
elif isinstance(value, datetime.datetime):
return self.menu_code + " Date"
elif self.is_data(value):
return self.menu_code + " Data"
elif isinstance(value, bool):
return self.menu_code + " Boolean"
elif isinstance(value, (int,float,long)):
return self.menu_code + " Number"
elif isinstance(value, (str,unicode)):
return self.menu_code + " String"
else:
return self.menu_code + str(type(value))
示例6: get_data
# 需要導入模塊: import plistlib [as 別名]
# 或者: from plistlib import Data [as 別名]
def get_data(self, value):
if sys.version_info < (3,0) and isinstance(value, plistlib.Data):
value = value.data
if not len(value):
return "<>" if self.data_display == "hex" else ""
if self.data_display == "hex":
h = binascii.hexlify(value)
if sys.version_info >= (3,0):
h = h.decode("utf-8")
return "<{}>".format(" ".join((h[0+i:8+i] for i in range(0, len(h), 8))).upper())
else:
h = base64.b64encode(value)
if sys.version_info >= (3,0):
h = h.decode("utf-8")
return h
### ###
# Node Update Functions #
### ###
示例7: test_dataobject_deprecated
# 需要導入模塊: import plistlib [as 別名]
# 或者: from plistlib import Data [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.assertEqual(cur, in_data)
cur = plistlib.loads(buf, use_builtin_types=False)
self.assertEqual(cur, out_data)
self.assertEqual(cur, in_data)
with self.assertWarns(DeprecationWarning):
cur = plistlib.readPlistFromBytes(buf)
self.assertEqual(cur, out_data)
self.assertEqual(cur, in_data)
示例8: RemoveProfile
# 需要導入模塊: import plistlib [as 別名]
# 或者: from plistlib import Data [as 別名]
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()
示例9: _sanitize_args_single_value
# 需要導入模塊: import plistlib [as 別名]
# 或者: from plistlib import Data [as 別名]
def _sanitize_args_single_value(value, arg=None):
"""Makes a single value easier to read."""
if isinstance(value, plistlib.Data):
try: # Does it seem to be ASCII ?
return value.data.encode('ascii')
except UnicodeDecodeError: # No => base64 encode it
return value.asBase64(maxlinelength=1000000).strip()
elif isinstance(value, datetime.datetime):
# Keychain items can contain a date. We just store a string representation of it
return str(value)
else:
# Try to replace this value with a more meaningful string
if arg in IOS_ENUM_LIST:
try:
if 'mask' in IOS_ENUM_LIST[arg]:
has_flag = value & IOS_ENUM_LIST[arg]['mask']
if has_flag:
return IOS_ENUM_LIST[arg][value]
else:
return IOS_ENUM_LIST[arg][value]
except KeyError:
return value
else:
return value
示例10: AddMachineCertificate
# 需要導入模塊: import plistlib [as 別名]
# 或者: from plistlib import Data [as 別名]
def AddMachineCertificate(self, certificate, private_key):
"""Adds a machine certificate payload to the profile.
Args:
certificate: str, PEM-formatted certificate.
private_key: str, PEM-formatted private key.
Raises:
CertificateError: there was an error processing the certificate/key
"""
try:
cert = certs.Certificate(certificate)
pkcs12 = crypto.PKCS12Type()
pkcs12.set_certificate(crypto.load_certificate(
crypto.FILETYPE_PEM, certificate))
pkcs12.set_privatekey(crypto.load_privatekey(
crypto.FILETYPE_PEM, private_key))
except (certs.CertError, crypto.Error) as e:
raise CertificateError(e)
payload = {PAYLOADKEYS_IDENTIFIER: self._GenerateID('machine_cert'),
PAYLOADKEYS_TYPE: 'com.apple.security.pkcs12',
PAYLOADKEYS_DISPLAYNAME: cert.subject_cn,
'Password': cert.osx_fingerprint}
try:
payload[PAYLOADKEYS_CONTENT] = plistlib.Data(
pkcs12.export(cert.osx_fingerprint))
except crypto.Error as e:
raise CertificateError(e)
# Validate payload to generate its UUID
ValidatePayload(payload)
self._auth_cert = payload.get(PAYLOADKEYS_UUID)
self.AddPayload(payload)
示例11: test_indentation_array
# 需要導入模塊: import plistlib [as 別名]
# 或者: from plistlib import Data [as 別名]
def test_indentation_array(self):
data = [[[[[[[[{'test': plistlib.Data(b'aaaaaa')}]]]]]]]]
self.assertEqual(plistlib.readPlistFromString(plistlib.writePlistToString(data)), data)
示例12: test_indentation_dict
# 需要導入模塊: import plistlib [as 別名]
# 或者: from plistlib import Data [as 別名]
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)
示例13: test_indentation_dict_mix
# 需要導入模塊: import plistlib [as 別名]
# 或者: from plistlib import Data [as 別名]
def test_indentation_dict_mix(self):
data = {'1': {'2': [{'3': [[[[[{'test': plistlib.Data(b'aaaaaa')}]]]]]}]}}
self.assertEqual(plistlib.readPlistFromString(plistlib.writePlistToString(data)), data)
示例14: _getrefnum
# 需要導入模塊: import plistlib [as 別名]
# 或者: from plistlib import Data [as 別名]
def _getrefnum(self, value):
if isinstance(value, _scalars):
return self._objtable[(type(value), value)]
elif isinstance(value, plistlib.Data):
return self._objtable[(type(value.data), value.data)]
else:
return self._objidtable[id(value)]
示例15: setUp
# 需要導入模塊: import plistlib [as 別名]
# 或者: from plistlib import Data [as 別名]
def setUp(self):
self.path = os.path.join(TMPDIR, 'delete')
self.config = config.Manager(id='test', path=self.path)
template = {'string':'string', 'list':[], 'dict':{},
'integer': 1, 'boolean': True,
'date': dt.datetime.now(), 'float': 0.5,
'data': plistlib.Data('data')}
self.config.write(template)