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
"Data", "InvalidFileException", "FMT_XML", "FMT_BINARY",
[49] Fix | Delete
"load", "dump", "loads", "dumps", "UID"
[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
@contextlib.contextmanager
[78] Fix | Delete
def _maybe_open(pathOrFile, mode):
[79] Fix | Delete
if isinstance(pathOrFile, str):
[80] Fix | Delete
with open(pathOrFile, mode) as fp:
[81] Fix | Delete
yield fp
[82] Fix | Delete
[83] Fix | Delete
else:
[84] Fix | Delete
yield pathOrFile
[85] Fix | Delete
[86] Fix | Delete
[87] Fix | Delete
def readPlist(pathOrFile):
[88] Fix | Delete
"""
[89] Fix | Delete
Read a .plist from a path or file. pathOrFile should either
[90] Fix | Delete
be a file name, or a readable binary file object.
[91] Fix | Delete
[92] Fix | Delete
This function is deprecated, use load instead.
[93] Fix | Delete
"""
[94] Fix | Delete
warn("The readPlist function is deprecated, use load() instead",
[95] Fix | Delete
DeprecationWarning, 2)
[96] Fix | Delete
[97] Fix | Delete
with _maybe_open(pathOrFile, 'rb') as fp:
[98] Fix | Delete
return load(fp, fmt=None, use_builtin_types=False)
[99] Fix | Delete
[100] Fix | Delete
def writePlist(value, pathOrFile):
[101] Fix | Delete
"""
[102] Fix | Delete
Write 'value' to a .plist file. 'pathOrFile' may either be a
[103] Fix | Delete
file name or a (writable) file object.
[104] Fix | Delete
[105] Fix | Delete
This function is deprecated, use dump instead.
[106] Fix | Delete
"""
[107] Fix | Delete
warn("The writePlist function is deprecated, use dump() instead",
[108] Fix | Delete
DeprecationWarning, 2)
[109] Fix | Delete
with _maybe_open(pathOrFile, 'wb') as fp:
[110] Fix | Delete
dump(value, fp, fmt=FMT_XML, sort_keys=True, skipkeys=False)
[111] Fix | Delete
[112] Fix | Delete
[113] Fix | Delete
def readPlistFromBytes(data):
[114] Fix | Delete
"""
[115] Fix | Delete
Read a plist data from a bytes object. Return the root object.
[116] Fix | Delete
[117] Fix | Delete
This function is deprecated, use loads instead.
[118] Fix | Delete
"""
[119] Fix | Delete
warn("The readPlistFromBytes function is deprecated, use loads() instead",
[120] Fix | Delete
DeprecationWarning, 2)
[121] Fix | Delete
return load(BytesIO(data), fmt=None, use_builtin_types=False)
[122] Fix | Delete
[123] Fix | Delete
[124] Fix | Delete
def writePlistToBytes(value):
[125] Fix | Delete
"""
[126] Fix | Delete
Return 'value' as a plist-formatted bytes object.
[127] Fix | Delete
[128] Fix | Delete
This function is deprecated, use dumps instead.
[129] Fix | Delete
"""
[130] Fix | Delete
warn("The writePlistToBytes function is deprecated, use dumps() instead",
[131] Fix | Delete
DeprecationWarning, 2)
[132] Fix | Delete
f = BytesIO()
[133] Fix | Delete
dump(value, f, fmt=FMT_XML, sort_keys=True, skipkeys=False)
[134] Fix | Delete
return f.getvalue()
[135] Fix | Delete
[136] Fix | Delete
[137] Fix | Delete
class Data:
[138] Fix | Delete
"""
[139] Fix | Delete
Wrapper for binary data.
[140] Fix | Delete
[141] Fix | Delete
This class is deprecated, use a bytes object instead.
[142] Fix | Delete
"""
[143] Fix | Delete
[144] Fix | Delete
def __init__(self, data):
[145] Fix | Delete
if not isinstance(data, bytes):
[146] Fix | Delete
raise TypeError("data must be as bytes")
[147] Fix | Delete
self.data = data
[148] Fix | Delete
[149] Fix | Delete
@classmethod
[150] Fix | Delete
def fromBase64(cls, data):
[151] Fix | Delete
# base64.decodebytes just calls binascii.a2b_base64;
[152] Fix | Delete
# it seems overkill to use both base64 and binascii.
[153] Fix | Delete
return cls(_decode_base64(data))
[154] Fix | Delete
[155] Fix | Delete
def asBase64(self, maxlinelength=76):
[156] Fix | Delete
return _encode_base64(self.data, maxlinelength)
[157] Fix | Delete
[158] Fix | Delete
def __eq__(self, other):
[159] Fix | Delete
if isinstance(other, self.__class__):
[160] Fix | Delete
return self.data == other.data
[161] Fix | Delete
elif isinstance(other, bytes):
[162] Fix | Delete
return self.data == other
[163] Fix | Delete
else:
[164] Fix | Delete
return NotImplemented
[165] Fix | Delete
[166] Fix | Delete
def __repr__(self):
[167] Fix | Delete
return "%s(%s)" % (self.__class__.__name__, repr(self.data))
[168] Fix | Delete
[169] Fix | Delete
#
[170] Fix | Delete
#
[171] Fix | Delete
# End of deprecated functionality
[172] Fix | Delete
#
[173] Fix | Delete
#
[174] Fix | Delete
[175] Fix | Delete
[176] Fix | Delete
class UID:
[177] Fix | Delete
def __init__(self, data):
[178] Fix | Delete
if not isinstance(data, int):
[179] Fix | Delete
raise TypeError("data must be an int")
[180] Fix | Delete
if data >= 1 << 64:
[181] Fix | Delete
raise ValueError("UIDs cannot be >= 2**64")
[182] Fix | Delete
if data < 0:
[183] Fix | Delete
raise ValueError("UIDs must be positive")
[184] Fix | Delete
self.data = data
[185] Fix | Delete
[186] Fix | Delete
def __index__(self):
[187] Fix | Delete
return self.data
[188] Fix | Delete
[189] Fix | Delete
def __repr__(self):
[190] Fix | Delete
return "%s(%s)" % (self.__class__.__name__, repr(self.data))
[191] Fix | Delete
[192] Fix | Delete
def __reduce__(self):
[193] Fix | Delete
return self.__class__, (self.data,)
[194] Fix | Delete
[195] Fix | Delete
def __eq__(self, other):
[196] Fix | Delete
if not isinstance(other, UID):
[197] Fix | Delete
return NotImplemented
[198] Fix | Delete
return self.data == other.data
[199] Fix | Delete
[200] Fix | Delete
def __hash__(self):
[201] Fix | Delete
return hash(self.data)
[202] Fix | Delete
[203] Fix | Delete
[204] Fix | Delete
#
[205] Fix | Delete
# XML support
[206] Fix | Delete
#
[207] Fix | Delete
[208] Fix | Delete
[209] Fix | Delete
# XML 'header'
[210] Fix | Delete
PLISTHEADER = b"""\
[211] Fix | Delete
<?xml version="1.0" encoding="UTF-8"?>
[212] Fix | Delete
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
[213] Fix | Delete
"""
[214] Fix | Delete
[215] Fix | Delete
[216] Fix | Delete
# Regex to find any control chars, except for \t \n and \r
[217] Fix | Delete
_controlCharPat = re.compile(
[218] Fix | Delete
r"[\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f"
[219] Fix | Delete
r"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f]")
[220] Fix | Delete
[221] Fix | Delete
def _encode_base64(s, maxlinelength=76):
[222] Fix | Delete
# copied from base64.encodebytes(), with added maxlinelength argument
[223] Fix | Delete
maxbinsize = (maxlinelength//4)*3
[224] Fix | Delete
pieces = []
[225] Fix | Delete
for i in range(0, len(s), maxbinsize):
[226] Fix | Delete
chunk = s[i : i + maxbinsize]
[227] Fix | Delete
pieces.append(binascii.b2a_base64(chunk))
[228] Fix | Delete
return b''.join(pieces)
[229] Fix | Delete
[230] Fix | Delete
def _decode_base64(s):
[231] Fix | Delete
if isinstance(s, str):
[232] Fix | Delete
return binascii.a2b_base64(s.encode("utf-8"))
[233] Fix | Delete
[234] Fix | Delete
else:
[235] Fix | Delete
return binascii.a2b_base64(s)
[236] Fix | Delete
[237] Fix | Delete
# Contents should conform to a subset of ISO 8601
[238] Fix | Delete
# (in particular, YYYY '-' MM '-' DD 'T' HH ':' MM ':' SS 'Z'. Smaller units
[239] Fix | Delete
# may be omitted with # a loss of precision)
[240] 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)
[241] Fix | Delete
[242] Fix | Delete
[243] Fix | Delete
def _date_from_string(s):
[244] Fix | Delete
order = ('year', 'month', 'day', 'hour', 'minute', 'second')
[245] Fix | Delete
gd = _dateParser.match(s).groupdict()
[246] Fix | Delete
lst = []
[247] Fix | Delete
for key in order:
[248] Fix | Delete
val = gd[key]
[249] Fix | Delete
if val is None:
[250] Fix | Delete
break
[251] Fix | Delete
lst.append(int(val))
[252] Fix | Delete
return datetime.datetime(*lst)
[253] Fix | Delete
[254] Fix | Delete
[255] Fix | Delete
def _date_to_string(d):
[256] Fix | Delete
return '%04d-%02d-%02dT%02d:%02d:%02dZ' % (
[257] Fix | Delete
d.year, d.month, d.day,
[258] Fix | Delete
d.hour, d.minute, d.second
[259] Fix | Delete
)
[260] Fix | Delete
[261] Fix | Delete
def _escape(text):
[262] Fix | Delete
m = _controlCharPat.search(text)
[263] Fix | Delete
if m is not None:
[264] Fix | Delete
raise ValueError("strings can't contains control characters; "
[265] Fix | Delete
"use bytes instead")
[266] Fix | Delete
text = text.replace("\r\n", "\n") # convert DOS line endings
[267] Fix | Delete
text = text.replace("\r", "\n") # convert Mac line endings
[268] Fix | Delete
text = text.replace("&", "&amp;") # escape '&'
[269] Fix | Delete
text = text.replace("<", "&lt;") # escape '<'
[270] Fix | Delete
text = text.replace(">", "&gt;") # escape '>'
[271] Fix | Delete
return text
[272] Fix | Delete
[273] Fix | Delete
class _PlistParser:
[274] Fix | Delete
def __init__(self, use_builtin_types, dict_type):
[275] Fix | Delete
self.stack = []
[276] Fix | Delete
self.current_key = None
[277] Fix | Delete
self.root = None
[278] Fix | Delete
self._use_builtin_types = use_builtin_types
[279] Fix | Delete
self._dict_type = dict_type
[280] Fix | Delete
[281] Fix | Delete
def parse(self, fileobj):
[282] Fix | Delete
self.parser = ParserCreate()
[283] Fix | Delete
self.parser.StartElementHandler = self.handle_begin_element
[284] Fix | Delete
self.parser.EndElementHandler = self.handle_end_element
[285] Fix | Delete
self.parser.CharacterDataHandler = self.handle_data
[286] Fix | Delete
self.parser.EntityDeclHandler = self.handle_entity_decl
[287] Fix | Delete
self.parser.ParseFile(fileobj)
[288] Fix | Delete
return self.root
[289] Fix | Delete
[290] Fix | Delete
def handle_entity_decl(self, entity_name, is_parameter_entity, value, base, system_id, public_id, notation_name):
[291] Fix | Delete
# Reject plist files with entity declarations to avoid XML vulnerabilies in expat.
[292] Fix | Delete
# Regular plist files don't contain those declerations, and Apple's plutil tool does not
[293] Fix | Delete
# accept them either.
[294] Fix | Delete
raise InvalidFileException("XML entity declarations are not supported in plist files")
[295] Fix | Delete
[296] Fix | Delete
def handle_begin_element(self, element, attrs):
[297] Fix | Delete
self.data = []
[298] Fix | Delete
handler = getattr(self, "begin_" + element, None)
[299] Fix | Delete
if handler is not None:
[300] Fix | Delete
handler(attrs)
[301] Fix | Delete
[302] Fix | Delete
def handle_end_element(self, element):
[303] Fix | Delete
handler = getattr(self, "end_" + element, None)
[304] Fix | Delete
if handler is not None:
[305] Fix | Delete
handler()
[306] Fix | Delete
[307] Fix | Delete
def handle_data(self, data):
[308] Fix | Delete
self.data.append(data)
[309] Fix | Delete
[310] Fix | Delete
def add_object(self, value):
[311] Fix | Delete
if self.current_key is not None:
[312] Fix | Delete
if not isinstance(self.stack[-1], type({})):
[313] Fix | Delete
raise ValueError("unexpected element at line %d" %
[314] Fix | Delete
self.parser.CurrentLineNumber)
[315] Fix | Delete
self.stack[-1][self.current_key] = value
[316] Fix | Delete
self.current_key = None
[317] Fix | Delete
elif not self.stack:
[318] Fix | Delete
# this is the root object
[319] Fix | Delete
self.root = value
[320] Fix | Delete
else:
[321] Fix | Delete
if not isinstance(self.stack[-1], type([])):
[322] Fix | Delete
raise ValueError("unexpected element at line %d" %
[323] Fix | Delete
self.parser.CurrentLineNumber)
[324] Fix | Delete
self.stack[-1].append(value)
[325] Fix | Delete
[326] Fix | Delete
def get_data(self):
[327] Fix | Delete
data = ''.join(self.data)
[328] Fix | Delete
self.data = []
[329] Fix | Delete
return data
[330] Fix | Delete
[331] Fix | Delete
# element handlers
[332] Fix | Delete
[333] Fix | Delete
def begin_dict(self, attrs):
[334] Fix | Delete
d = self._dict_type()
[335] Fix | Delete
self.add_object(d)
[336] Fix | Delete
self.stack.append(d)
[337] Fix | Delete
[338] Fix | Delete
def end_dict(self):
[339] Fix | Delete
if self.current_key:
[340] Fix | Delete
raise ValueError("missing value for key '%s' at line %d" %
[341] Fix | Delete
(self.current_key,self.parser.CurrentLineNumber))
[342] Fix | Delete
self.stack.pop()
[343] Fix | Delete
[344] Fix | Delete
def end_key(self):
[345] Fix | Delete
if self.current_key or not isinstance(self.stack[-1], type({})):
[346] Fix | Delete
raise ValueError("unexpected key at line %d" %
[347] Fix | Delete
self.parser.CurrentLineNumber)
[348] Fix | Delete
self.current_key = self.get_data()
[349] Fix | Delete
[350] Fix | Delete
def begin_array(self, attrs):
[351] Fix | Delete
a = []
[352] Fix | Delete
self.add_object(a)
[353] Fix | Delete
self.stack.append(a)
[354] Fix | Delete
[355] Fix | Delete
def end_array(self):
[356] Fix | Delete
self.stack.pop()
[357] Fix | Delete
[358] Fix | Delete
def end_true(self):
[359] Fix | Delete
self.add_object(True)
[360] Fix | Delete
[361] Fix | Delete
def end_false(self):
[362] Fix | Delete
self.add_object(False)
[363] Fix | Delete
[364] Fix | Delete
def end_integer(self):
[365] Fix | Delete
raw = self.get_data()
[366] Fix | Delete
if raw.startswith('0x') or raw.startswith('0X'):
[367] Fix | Delete
self.add_object(int(raw, 16))
[368] Fix | Delete
else:
[369] Fix | Delete
self.add_object(int(raw))
[370] Fix | Delete
[371] Fix | Delete
def end_real(self):
[372] Fix | Delete
self.add_object(float(self.get_data()))
[373] Fix | Delete
[374] Fix | Delete
def end_string(self):
[375] Fix | Delete
self.add_object(self.get_data())
[376] Fix | Delete
[377] Fix | Delete
def end_data(self):
[378] Fix | Delete
if self._use_builtin_types:
[379] Fix | Delete
self.add_object(_decode_base64(self.get_data()))
[380] Fix | Delete
[381] Fix | Delete
else:
[382] Fix | Delete
self.add_object(Data.fromBase64(self.get_data()))
[383] Fix | Delete
[384] Fix | Delete
def end_date(self):
[385] Fix | Delete
self.add_object(_date_from_string(self.get_data()))
[386] Fix | Delete
[387] Fix | Delete
[388] Fix | Delete
class _DumbXMLWriter:
[389] Fix | Delete
def __init__(self, file, indent_level=0, indent="\t"):
[390] Fix | Delete
self.file = file
[391] Fix | Delete
self.stack = []
[392] Fix | Delete
self._indent_level = indent_level
[393] Fix | Delete
self.indent = indent
[394] Fix | Delete
[395] Fix | Delete
def begin_element(self, element):
[396] Fix | Delete
self.stack.append(element)
[397] Fix | Delete
self.writeln("<%s>" % element)
[398] Fix | Delete
self._indent_level += 1
[399] Fix | Delete
[400] Fix | Delete
def end_element(self, element):
[401] Fix | Delete
assert self._indent_level > 0
[402] Fix | Delete
assert self.stack.pop() == element
[403] Fix | Delete
self._indent_level -= 1
[404] Fix | Delete
self.writeln("</%s>" % element)
[405] Fix | Delete
[406] Fix | Delete
def simple_element(self, element, value=None):
[407] Fix | Delete
if value is not None:
[408] Fix | Delete
value = _escape(value)
[409] Fix | Delete
self.writeln("<%s>%s</%s>" % (element, value, element))
[410] Fix | Delete
[411] Fix | Delete
else:
[412] Fix | Delete
self.writeln("<%s/>" % element)
[413] Fix | Delete
[414] Fix | Delete
def writeln(self, line):
[415] Fix | Delete
if line:
[416] Fix | Delete
# plist has fixed encoding of utf-8
[417] Fix | Delete
[418] Fix | Delete
# XXX: is this test needed?
[419] Fix | Delete
if isinstance(line, str):
[420] Fix | Delete
line = line.encode('utf-8')
[421] Fix | Delete
self.file.write(self._indent_level * self.indent)
[422] Fix | Delete
self.file.write(line)
[423] Fix | Delete
self.file.write(b'\n')
[424] Fix | Delete
[425] Fix | Delete
[426] Fix | Delete
class _PlistWriter(_DumbXMLWriter):
[427] Fix | Delete
def __init__(
[428] Fix | Delete
self, file, indent_level=0, indent=b"\t", writeHeader=1,
[429] Fix | Delete
sort_keys=True, skipkeys=False):
[430] Fix | Delete
[431] Fix | Delete
if writeHeader:
[432] Fix | Delete
file.write(PLISTHEADER)
[433] Fix | Delete
_DumbXMLWriter.__init__(self, file, indent_level, indent)
[434] Fix | Delete
self._sort_keys = sort_keys
[435] Fix | Delete
self._skipkeys = skipkeys
[436] Fix | Delete
[437] Fix | Delete
def write(self, value):
[438] Fix | Delete
self.writeln("<plist version=\"1.0\">")
[439] Fix | Delete
self.write_value(value)
[440] Fix | Delete
self.writeln("</plist>")
[441] Fix | Delete
[442] Fix | Delete
def write_value(self, value):
[443] Fix | Delete
if isinstance(value, str):
[444] Fix | Delete
self.simple_element("string", value)
[445] Fix | Delete
[446] Fix | Delete
elif value is True:
[447] Fix | Delete
self.simple_element("true")
[448] Fix | Delete
[449] Fix | Delete
elif value is False:
[450] Fix | Delete
self.simple_element("false")
[451] Fix | Delete
[452] Fix | Delete
elif isinstance(value, int):
[453] Fix | Delete
if -1 << 63 <= value < 1 << 64:
[454] Fix | Delete
self.simple_element("integer", "%d" % value)
[455] Fix | Delete
else:
[456] Fix | Delete
raise OverflowError(value)
[457] Fix | Delete
[458] Fix | Delete
elif isinstance(value, float):
[459] Fix | Delete
self.simple_element("real", repr(value))
[460] Fix | Delete
[461] Fix | Delete
elif isinstance(value, dict):
[462] Fix | Delete
self.write_dict(value)
[463] Fix | Delete
[464] Fix | Delete
elif isinstance(value, Data):
[465] Fix | Delete
self.write_data(value)
[466] Fix | Delete
[467] Fix | Delete
elif isinstance(value, (bytes, bytearray)):
[468] Fix | Delete
self.write_bytes(value)
[469] Fix | Delete
[470] Fix | Delete
elif isinstance(value, datetime.datetime):
[471] Fix | Delete
self.simple_element("date", _date_to_string(value))
[472] Fix | Delete
[473] Fix | Delete
elif isinstance(value, (tuple, list)):
[474] Fix | Delete
self.write_array(value)
[475] Fix | Delete
[476] Fix | Delete
else:
[477] Fix | Delete
raise TypeError("unsupported type: %s" % type(value))
[478] Fix | Delete
[479] Fix | Delete
def write_data(self, data):
[480] Fix | Delete
self.write_bytes(data.data)
[481] Fix | Delete
[482] Fix | Delete
def write_bytes(self, data):
[483] Fix | Delete
self.begin_element("data")
[484] Fix | Delete
self._indent_level -= 1
[485] Fix | Delete
maxlinelength = max(
[486] Fix | Delete
16,
[487] Fix | Delete
76 - len(self.indent.replace(b"\t", b" " * 8) * self._indent_level))
[488] Fix | Delete
[489] Fix | Delete
for line in _encode_base64(data, maxlinelength).split(b"\n"):
[490] Fix | Delete
if line:
[491] Fix | Delete
self.writeln(line)
[492] Fix | Delete
self._indent_level += 1
[493] Fix | Delete
self.end_element("data")
[494] Fix | Delete
[495] Fix | Delete
def write_dict(self, d):
[496] Fix | Delete
if d:
[497] Fix | Delete
self.begin_element("dict")
[498] Fix | Delete
if self._sort_keys:
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function