Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python3....
File: plistlib.py
r"""plistlib.py -- a tool to generate and parse MacOSX .plist files.
[0] Fix | Delete
[1] Fix | Delete
The property list (.plist) file format is a simple XML pickle supporting
[2] Fix | Delete
basic object types, like dictionaries, lists, numbers and strings.
[3] Fix | Delete
Usually the top level object is a dictionary.
[4] Fix | Delete
[5] Fix | Delete
To write out a plist file, use the dump(value, file)
[6] Fix | Delete
function. 'value' is the top level object, 'file' is
[7] Fix | Delete
a (writable) file object.
[8] Fix | Delete
[9] Fix | Delete
To parse a plist from a file, use the load(file) function,
[10] Fix | Delete
with a (readable) file object as the only argument. It
[11] Fix | Delete
returns the top level object (again, usually a dictionary).
[12] Fix | Delete
[13] Fix | Delete
To work with plist data in bytes objects, you can use loads()
[14] Fix | Delete
and dumps().
[15] Fix | Delete
[16] Fix | Delete
Values can be strings, integers, floats, booleans, tuples, lists,
[17] Fix | Delete
dictionaries (but only with string keys), Data, bytes, bytearray, or
[18] Fix | Delete
datetime.datetime objects.
[19] Fix | Delete
[20] Fix | Delete
Generate Plist example:
[21] Fix | Delete
[22] Fix | Delete
pl = dict(
[23] Fix | Delete
aString = "Doodah",
[24] Fix | Delete
aList = ["A", "B", 12, 32.1, [1, 2, 3]],
[25] Fix | Delete
aFloat = 0.1,
[26] Fix | Delete
anInt = 728,
[27] Fix | Delete
aDict = dict(
[28] Fix | Delete
anotherString = "<hello & hi there!>",
[29] Fix | Delete
aUnicodeValue = "M\xe4ssig, Ma\xdf",
[30] Fix | Delete
aTrueValue = True,
[31] Fix | Delete
aFalseValue = False,
[32] Fix | Delete
),
[33] Fix | Delete
someData = b"<binary gunk>",
[34] Fix | Delete
someMoreData = b"<lots of binary gunk>" * 10,
[35] Fix | Delete
aDate = datetime.datetime.fromtimestamp(time.mktime(time.gmtime())),
[36] Fix | Delete
)
[37] Fix | Delete
with open(fileName, 'wb') as fp:
[38] Fix | Delete
dump(pl, fp)
[39] Fix | Delete
[40] Fix | Delete
Parse Plist example:
[41] Fix | Delete
[42] Fix | Delete
with open(fileName, 'rb') as fp:
[43] Fix | Delete
pl = load(fp)
[44] Fix | Delete
print(pl["aKey"])
[45] Fix | Delete
"""
[46] Fix | Delete
__all__ = [
[47] Fix | Delete
"readPlist", "writePlist", "readPlistFromBytes", "writePlistToBytes",
[48] Fix | Delete
"Plist", "Data", "Dict", "InvalidFileException", "FMT_XML", "FMT_BINARY",
[49] Fix | Delete
"load", "dump", "loads", "dumps"
[50] Fix | Delete
]
[51] Fix | Delete
[52] Fix | Delete
import binascii
[53] Fix | Delete
import codecs
[54] Fix | Delete
import contextlib
[55] Fix | Delete
import datetime
[56] Fix | Delete
import enum
[57] Fix | Delete
from io import BytesIO
[58] Fix | Delete
import itertools
[59] Fix | Delete
import os
[60] Fix | Delete
import re
[61] Fix | Delete
import struct
[62] Fix | Delete
from warnings import warn
[63] Fix | Delete
from xml.parsers.expat import ParserCreate
[64] Fix | Delete
[65] Fix | Delete
[66] Fix | Delete
PlistFormat = enum.Enum('PlistFormat', 'FMT_XML FMT_BINARY', module=__name__)
[67] Fix | Delete
globals().update(PlistFormat.__members__)
[68] Fix | Delete
[69] Fix | Delete
[70] Fix | Delete
#
[71] Fix | Delete
#
[72] Fix | Delete
# Deprecated functionality
[73] Fix | Delete
#
[74] Fix | Delete
#
[75] Fix | Delete
[76] Fix | Delete
[77] Fix | Delete
class _InternalDict(dict):
[78] Fix | Delete
[79] Fix | Delete
# This class is needed while Dict is scheduled for deprecation:
[80] Fix | Delete
# we only need to warn when a *user* instantiates Dict or when
[81] Fix | Delete
# the "attribute notation for dict keys" is used.
[82] Fix | Delete
__slots__ = ()
[83] Fix | Delete
[84] Fix | Delete
def __getattr__(self, attr):
[85] Fix | Delete
try:
[86] Fix | Delete
value = self[attr]
[87] Fix | Delete
except KeyError:
[88] Fix | Delete
raise AttributeError(attr)
[89] Fix | Delete
warn("Attribute access from plist dicts is deprecated, use d[key] "
[90] Fix | Delete
"notation instead", DeprecationWarning, 2)
[91] Fix | Delete
return value
[92] Fix | Delete
[93] Fix | Delete
def __setattr__(self, attr, value):
[94] Fix | Delete
warn("Attribute access from plist dicts is deprecated, use d[key] "
[95] Fix | Delete
"notation instead", DeprecationWarning, 2)
[96] Fix | Delete
self[attr] = value
[97] Fix | Delete
[98] Fix | Delete
def __delattr__(self, attr):
[99] Fix | Delete
try:
[100] Fix | Delete
del self[attr]
[101] Fix | Delete
except KeyError:
[102] Fix | Delete
raise AttributeError(attr)
[103] Fix | Delete
warn("Attribute access from plist dicts is deprecated, use d[key] "
[104] Fix | Delete
"notation instead", DeprecationWarning, 2)
[105] Fix | Delete
[106] Fix | Delete
[107] Fix | Delete
class Dict(_InternalDict):
[108] Fix | Delete
[109] Fix | Delete
def __init__(self, **kwargs):
[110] Fix | Delete
warn("The plistlib.Dict class is deprecated, use builtin dict instead",
[111] Fix | Delete
DeprecationWarning, 2)
[112] Fix | Delete
super().__init__(**kwargs)
[113] Fix | Delete
[114] Fix | Delete
[115] Fix | Delete
@contextlib.contextmanager
[116] Fix | Delete
def _maybe_open(pathOrFile, mode):
[117] Fix | Delete
if isinstance(pathOrFile, str):
[118] Fix | Delete
with open(pathOrFile, mode) as fp:
[119] Fix | Delete
yield fp
[120] Fix | Delete
[121] Fix | Delete
else:
[122] Fix | Delete
yield pathOrFile
[123] Fix | Delete
[124] Fix | Delete
[125] Fix | Delete
class Plist(_InternalDict):
[126] Fix | Delete
"""This class has been deprecated. Use dump() and load()
[127] Fix | Delete
functions instead, together with regular dict objects.
[128] Fix | Delete
"""
[129] Fix | Delete
[130] Fix | Delete
def __init__(self, **kwargs):
[131] Fix | Delete
warn("The Plist class is deprecated, use the load() and "
[132] Fix | Delete
"dump() functions instead", DeprecationWarning, 2)
[133] Fix | Delete
super().__init__(**kwargs)
[134] Fix | Delete
[135] Fix | Delete
@classmethod
[136] Fix | Delete
def fromFile(cls, pathOrFile):
[137] Fix | Delete
"""Deprecated. Use the load() function instead."""
[138] Fix | Delete
with _maybe_open(pathOrFile, 'rb') as fp:
[139] Fix | Delete
value = load(fp)
[140] Fix | Delete
plist = cls()
[141] Fix | Delete
plist.update(value)
[142] Fix | Delete
return plist
[143] Fix | Delete
[144] Fix | Delete
def write(self, pathOrFile):
[145] Fix | Delete
"""Deprecated. Use the dump() function instead."""
[146] Fix | Delete
with _maybe_open(pathOrFile, 'wb') as fp:
[147] Fix | Delete
dump(self, fp)
[148] Fix | Delete
[149] Fix | Delete
[150] Fix | Delete
def readPlist(pathOrFile):
[151] Fix | Delete
"""
[152] Fix | Delete
Read a .plist from a path or file. pathOrFile should either
[153] Fix | Delete
be a file name, or a readable binary file object.
[154] Fix | Delete
[155] Fix | Delete
This function is deprecated, use load instead.
[156] Fix | Delete
"""
[157] Fix | Delete
warn("The readPlist function is deprecated, use load() instead",
[158] Fix | Delete
DeprecationWarning, 2)
[159] Fix | Delete
[160] Fix | Delete
with _maybe_open(pathOrFile, 'rb') as fp:
[161] Fix | Delete
return load(fp, fmt=None, use_builtin_types=False,
[162] Fix | Delete
dict_type=_InternalDict)
[163] Fix | Delete
[164] Fix | Delete
def writePlist(value, pathOrFile):
[165] Fix | Delete
"""
[166] Fix | Delete
Write 'value' to a .plist file. 'pathOrFile' may either be a
[167] Fix | Delete
file name or a (writable) file object.
[168] Fix | Delete
[169] Fix | Delete
This function is deprecated, use dump instead.
[170] Fix | Delete
"""
[171] Fix | Delete
warn("The writePlist function is deprecated, use dump() instead",
[172] Fix | Delete
DeprecationWarning, 2)
[173] Fix | Delete
with _maybe_open(pathOrFile, 'wb') as fp:
[174] Fix | Delete
dump(value, fp, fmt=FMT_XML, sort_keys=True, skipkeys=False)
[175] Fix | Delete
[176] Fix | Delete
[177] Fix | Delete
def readPlistFromBytes(data):
[178] Fix | Delete
"""
[179] Fix | Delete
Read a plist data from a bytes object. Return the root object.
[180] Fix | Delete
[181] Fix | Delete
This function is deprecated, use loads instead.
[182] Fix | Delete
"""
[183] Fix | Delete
warn("The readPlistFromBytes function is deprecated, use loads() instead",
[184] Fix | Delete
DeprecationWarning, 2)
[185] Fix | Delete
return load(BytesIO(data), fmt=None, use_builtin_types=False,
[186] Fix | Delete
dict_type=_InternalDict)
[187] Fix | Delete
[188] Fix | Delete
[189] Fix | Delete
def writePlistToBytes(value):
[190] Fix | Delete
"""
[191] Fix | Delete
Return 'value' as a plist-formatted bytes object.
[192] Fix | Delete
[193] Fix | Delete
This function is deprecated, use dumps instead.
[194] Fix | Delete
"""
[195] Fix | Delete
warn("The writePlistToBytes function is deprecated, use dumps() instead",
[196] Fix | Delete
DeprecationWarning, 2)
[197] Fix | Delete
f = BytesIO()
[198] Fix | Delete
dump(value, f, fmt=FMT_XML, sort_keys=True, skipkeys=False)
[199] Fix | Delete
return f.getvalue()
[200] Fix | Delete
[201] Fix | Delete
[202] Fix | Delete
class Data:
[203] Fix | Delete
"""
[204] Fix | Delete
Wrapper for binary data.
[205] Fix | Delete
[206] Fix | Delete
This class is deprecated, use a bytes object instead.
[207] Fix | Delete
"""
[208] Fix | Delete
[209] Fix | Delete
def __init__(self, data):
[210] Fix | Delete
if not isinstance(data, bytes):
[211] Fix | Delete
raise TypeError("data must be as bytes")
[212] Fix | Delete
self.data = data
[213] Fix | Delete
[214] Fix | Delete
@classmethod
[215] Fix | Delete
def fromBase64(cls, data):
[216] Fix | Delete
# base64.decodebytes just calls binascii.a2b_base64;
[217] Fix | Delete
# it seems overkill to use both base64 and binascii.
[218] Fix | Delete
return cls(_decode_base64(data))
[219] Fix | Delete
[220] Fix | Delete
def asBase64(self, maxlinelength=76):
[221] Fix | Delete
return _encode_base64(self.data, maxlinelength)
[222] Fix | Delete
[223] Fix | Delete
def __eq__(self, other):
[224] Fix | Delete
if isinstance(other, self.__class__):
[225] Fix | Delete
return self.data == other.data
[226] Fix | Delete
elif isinstance(other, bytes):
[227] Fix | Delete
return self.data == other
[228] Fix | Delete
else:
[229] Fix | Delete
return NotImplemented
[230] Fix | Delete
[231] Fix | Delete
def __repr__(self):
[232] Fix | Delete
return "%s(%s)" % (self.__class__.__name__, repr(self.data))
[233] Fix | Delete
[234] Fix | Delete
#
[235] Fix | Delete
#
[236] Fix | Delete
# End of deprecated functionality
[237] Fix | Delete
#
[238] Fix | Delete
#
[239] Fix | Delete
[240] Fix | Delete
[241] Fix | Delete
#
[242] Fix | Delete
# XML support
[243] Fix | Delete
#
[244] Fix | Delete
[245] Fix | Delete
[246] Fix | Delete
# XML 'header'
[247] Fix | Delete
PLISTHEADER = b"""\
[248] Fix | Delete
<?xml version="1.0" encoding="UTF-8"?>
[249] Fix | Delete
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
[250] Fix | Delete
"""
[251] Fix | Delete
[252] Fix | Delete
[253] Fix | Delete
# Regex to find any control chars, except for \t \n and \r
[254] Fix | Delete
_controlCharPat = re.compile(
[255] Fix | Delete
r"[\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f"
[256] Fix | Delete
r"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f]")
[257] Fix | Delete
[258] Fix | Delete
def _encode_base64(s, maxlinelength=76):
[259] Fix | Delete
# copied from base64.encodebytes(), with added maxlinelength argument
[260] Fix | Delete
maxbinsize = (maxlinelength//4)*3
[261] Fix | Delete
pieces = []
[262] Fix | Delete
for i in range(0, len(s), maxbinsize):
[263] Fix | Delete
chunk = s[i : i + maxbinsize]
[264] Fix | Delete
pieces.append(binascii.b2a_base64(chunk))
[265] Fix | Delete
return b''.join(pieces)
[266] Fix | Delete
[267] Fix | Delete
def _decode_base64(s):
[268] Fix | Delete
if isinstance(s, str):
[269] Fix | Delete
return binascii.a2b_base64(s.encode("utf-8"))
[270] Fix | Delete
[271] Fix | Delete
else:
[272] Fix | Delete
return binascii.a2b_base64(s)
[273] Fix | Delete
[274] Fix | Delete
# Contents should conform to a subset of ISO 8601
[275] Fix | Delete
# (in particular, YYYY '-' MM '-' DD 'T' HH ':' MM ':' SS 'Z'. Smaller units
[276] Fix | Delete
# may be omitted with # a loss of precision)
[277] Fix | Delete
_dateParser = re.compile(r"(?P<year>\d\d\d\d)(?:-(?P<month>\d\d)(?:-(?P<day>\d\d)(?:T(?P<hour>\d\d)(?::(?P<minute>\d\d)(?::(?P<second>\d\d))?)?)?)?)?Z", re.ASCII)
[278] Fix | Delete
[279] Fix | Delete
[280] Fix | Delete
def _date_from_string(s):
[281] Fix | Delete
order = ('year', 'month', 'day', 'hour', 'minute', 'second')
[282] Fix | Delete
gd = _dateParser.match(s).groupdict()
[283] Fix | Delete
lst = []
[284] Fix | Delete
for key in order:
[285] Fix | Delete
val = gd[key]
[286] Fix | Delete
if val is None:
[287] Fix | Delete
break
[288] Fix | Delete
lst.append(int(val))
[289] Fix | Delete
return datetime.datetime(*lst)
[290] Fix | Delete
[291] Fix | Delete
[292] Fix | Delete
def _date_to_string(d):
[293] Fix | Delete
return '%04d-%02d-%02dT%02d:%02d:%02dZ' % (
[294] Fix | Delete
d.year, d.month, d.day,
[295] Fix | Delete
d.hour, d.minute, d.second
[296] Fix | Delete
)
[297] Fix | Delete
[298] Fix | Delete
def _escape(text):
[299] Fix | Delete
m = _controlCharPat.search(text)
[300] Fix | Delete
if m is not None:
[301] Fix | Delete
raise ValueError("strings can't contains control characters; "
[302] Fix | Delete
"use bytes instead")
[303] Fix | Delete
text = text.replace("\r\n", "\n") # convert DOS line endings
[304] Fix | Delete
text = text.replace("\r", "\n") # convert Mac line endings
[305] Fix | Delete
text = text.replace("&", "&amp;") # escape '&'
[306] Fix | Delete
text = text.replace("<", "&lt;") # escape '<'
[307] Fix | Delete
text = text.replace(">", "&gt;") # escape '>'
[308] Fix | Delete
return text
[309] Fix | Delete
[310] Fix | Delete
class _PlistParser:
[311] Fix | Delete
def __init__(self, use_builtin_types, dict_type):
[312] Fix | Delete
self.stack = []
[313] Fix | Delete
self.current_key = None
[314] Fix | Delete
self.root = None
[315] Fix | Delete
self._use_builtin_types = use_builtin_types
[316] Fix | Delete
self._dict_type = dict_type
[317] Fix | Delete
[318] Fix | Delete
def parse(self, fileobj):
[319] Fix | Delete
self.parser = ParserCreate()
[320] Fix | Delete
self.parser.StartElementHandler = self.handle_begin_element
[321] Fix | Delete
self.parser.EndElementHandler = self.handle_end_element
[322] Fix | Delete
self.parser.CharacterDataHandler = self.handle_data
[323] Fix | Delete
self.parser.ParseFile(fileobj)
[324] Fix | Delete
return self.root
[325] Fix | Delete
[326] Fix | Delete
def handle_begin_element(self, element, attrs):
[327] Fix | Delete
self.data = []
[328] Fix | Delete
handler = getattr(self, "begin_" + element, None)
[329] Fix | Delete
if handler is not None:
[330] Fix | Delete
handler(attrs)
[331] Fix | Delete
[332] Fix | Delete
def handle_end_element(self, element):
[333] Fix | Delete
handler = getattr(self, "end_" + element, None)
[334] Fix | Delete
if handler is not None:
[335] Fix | Delete
handler()
[336] Fix | Delete
[337] Fix | Delete
def handle_data(self, data):
[338] Fix | Delete
self.data.append(data)
[339] Fix | Delete
[340] Fix | Delete
def add_object(self, value):
[341] Fix | Delete
if self.current_key is not None:
[342] Fix | Delete
if not isinstance(self.stack[-1], type({})):
[343] Fix | Delete
raise ValueError("unexpected element at line %d" %
[344] Fix | Delete
self.parser.CurrentLineNumber)
[345] Fix | Delete
self.stack[-1][self.current_key] = value
[346] Fix | Delete
self.current_key = None
[347] Fix | Delete
elif not self.stack:
[348] Fix | Delete
# this is the root object
[349] Fix | Delete
self.root = value
[350] Fix | Delete
else:
[351] Fix | Delete
if not isinstance(self.stack[-1], type([])):
[352] Fix | Delete
raise ValueError("unexpected element at line %d" %
[353] Fix | Delete
self.parser.CurrentLineNumber)
[354] Fix | Delete
self.stack[-1].append(value)
[355] Fix | Delete
[356] Fix | Delete
def get_data(self):
[357] Fix | Delete
data = ''.join(self.data)
[358] Fix | Delete
self.data = []
[359] Fix | Delete
return data
[360] Fix | Delete
[361] Fix | Delete
# element handlers
[362] Fix | Delete
[363] Fix | Delete
def begin_dict(self, attrs):
[364] Fix | Delete
d = self._dict_type()
[365] Fix | Delete
self.add_object(d)
[366] Fix | Delete
self.stack.append(d)
[367] Fix | Delete
[368] Fix | Delete
def end_dict(self):
[369] Fix | Delete
if self.current_key:
[370] Fix | Delete
raise ValueError("missing value for key '%s' at line %d" %
[371] Fix | Delete
(self.current_key,self.parser.CurrentLineNumber))
[372] Fix | Delete
self.stack.pop()
[373] Fix | Delete
[374] Fix | Delete
def end_key(self):
[375] Fix | Delete
if self.current_key or not isinstance(self.stack[-1], type({})):
[376] Fix | Delete
raise ValueError("unexpected key at line %d" %
[377] Fix | Delete
self.parser.CurrentLineNumber)
[378] Fix | Delete
self.current_key = self.get_data()
[379] Fix | Delete
[380] Fix | Delete
def begin_array(self, attrs):
[381] Fix | Delete
a = []
[382] Fix | Delete
self.add_object(a)
[383] Fix | Delete
self.stack.append(a)
[384] Fix | Delete
[385] Fix | Delete
def end_array(self):
[386] Fix | Delete
self.stack.pop()
[387] Fix | Delete
[388] Fix | Delete
def end_true(self):
[389] Fix | Delete
self.add_object(True)
[390] Fix | Delete
[391] Fix | Delete
def end_false(self):
[392] Fix | Delete
self.add_object(False)
[393] Fix | Delete
[394] Fix | Delete
def end_integer(self):
[395] Fix | Delete
self.add_object(int(self.get_data()))
[396] Fix | Delete
[397] Fix | Delete
def end_real(self):
[398] Fix | Delete
self.add_object(float(self.get_data()))
[399] Fix | Delete
[400] Fix | Delete
def end_string(self):
[401] Fix | Delete
self.add_object(self.get_data())
[402] Fix | Delete
[403] Fix | Delete
def end_data(self):
[404] Fix | Delete
if self._use_builtin_types:
[405] Fix | Delete
self.add_object(_decode_base64(self.get_data()))
[406] Fix | Delete
[407] Fix | Delete
else:
[408] Fix | Delete
self.add_object(Data.fromBase64(self.get_data()))
[409] Fix | Delete
[410] Fix | Delete
def end_date(self):
[411] Fix | Delete
self.add_object(_date_from_string(self.get_data()))
[412] Fix | Delete
[413] Fix | Delete
[414] Fix | Delete
class _DumbXMLWriter:
[415] Fix | Delete
def __init__(self, file, indent_level=0, indent="\t"):
[416] Fix | Delete
self.file = file
[417] Fix | Delete
self.stack = []
[418] Fix | Delete
self._indent_level = indent_level
[419] Fix | Delete
self.indent = indent
[420] Fix | Delete
[421] Fix | Delete
def begin_element(self, element):
[422] Fix | Delete
self.stack.append(element)
[423] Fix | Delete
self.writeln("<%s>" % element)
[424] Fix | Delete
self._indent_level += 1
[425] Fix | Delete
[426] Fix | Delete
def end_element(self, element):
[427] Fix | Delete
assert self._indent_level > 0
[428] Fix | Delete
assert self.stack.pop() == element
[429] Fix | Delete
self._indent_level -= 1
[430] Fix | Delete
self.writeln("</%s>" % element)
[431] Fix | Delete
[432] Fix | Delete
def simple_element(self, element, value=None):
[433] Fix | Delete
if value is not None:
[434] Fix | Delete
value = _escape(value)
[435] Fix | Delete
self.writeln("<%s>%s</%s>" % (element, value, element))
[436] Fix | Delete
[437] Fix | Delete
else:
[438] Fix | Delete
self.writeln("<%s/>" % element)
[439] Fix | Delete
[440] Fix | Delete
def writeln(self, line):
[441] Fix | Delete
if line:
[442] Fix | Delete
# plist has fixed encoding of utf-8
[443] Fix | Delete
[444] Fix | Delete
# XXX: is this test needed?
[445] Fix | Delete
if isinstance(line, str):
[446] Fix | Delete
line = line.encode('utf-8')
[447] Fix | Delete
self.file.write(self._indent_level * self.indent)
[448] Fix | Delete
self.file.write(line)
[449] Fix | Delete
self.file.write(b'\n')
[450] Fix | Delete
[451] Fix | Delete
[452] Fix | Delete
class _PlistWriter(_DumbXMLWriter):
[453] Fix | Delete
def __init__(
[454] Fix | Delete
self, file, indent_level=0, indent=b"\t", writeHeader=1,
[455] Fix | Delete
sort_keys=True, skipkeys=False):
[456] Fix | Delete
[457] Fix | Delete
if writeHeader:
[458] Fix | Delete
file.write(PLISTHEADER)
[459] Fix | Delete
_DumbXMLWriter.__init__(self, file, indent_level, indent)
[460] Fix | Delete
self._sort_keys = sort_keys
[461] Fix | Delete
self._skipkeys = skipkeys
[462] Fix | Delete
[463] Fix | Delete
def write(self, value):
[464] Fix | Delete
self.writeln("<plist version=\"1.0\">")
[465] Fix | Delete
self.write_value(value)
[466] Fix | Delete
self.writeln("</plist>")
[467] Fix | Delete
[468] Fix | Delete
def write_value(self, value):
[469] Fix | Delete
if isinstance(value, str):
[470] Fix | Delete
self.simple_element("string", value)
[471] Fix | Delete
[472] Fix | Delete
elif value is True:
[473] Fix | Delete
self.simple_element("true")
[474] Fix | Delete
[475] Fix | Delete
elif value is False:
[476] Fix | Delete
self.simple_element("false")
[477] Fix | Delete
[478] Fix | Delete
elif isinstance(value, int):
[479] Fix | Delete
if -1 << 63 <= value < 1 << 64:
[480] Fix | Delete
self.simple_element("integer", "%d" % value)
[481] Fix | Delete
else:
[482] Fix | Delete
raise OverflowError(value)
[483] Fix | Delete
[484] Fix | Delete
elif isinstance(value, float):
[485] Fix | Delete
self.simple_element("real", repr(value))
[486] Fix | Delete
[487] Fix | Delete
elif isinstance(value, dict):
[488] Fix | Delete
self.write_dict(value)
[489] Fix | Delete
[490] Fix | Delete
elif isinstance(value, Data):
[491] Fix | Delete
self.write_data(value)
[492] Fix | Delete
[493] Fix | Delete
elif isinstance(value, (bytes, bytearray)):
[494] Fix | Delete
self.write_bytes(value)
[495] Fix | Delete
[496] Fix | Delete
elif isinstance(value, datetime.datetime):
[497] Fix | Delete
self.simple_element("date", _date_to_string(value))
[498] Fix | Delete
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function