Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/lib64/python3..../xml/etree
File: ElementTree.py
if ltag not in HTML_EMPTY:
[1000] Fix | Delete
write("</" + tag + ">")
[1001] Fix | Delete
if elem.tail:
[1002] Fix | Delete
write(_escape_cdata(elem.tail))
[1003] Fix | Delete
[1004] Fix | Delete
def _serialize_text(write, elem):
[1005] Fix | Delete
for part in elem.itertext():
[1006] Fix | Delete
write(part)
[1007] Fix | Delete
if elem.tail:
[1008] Fix | Delete
write(elem.tail)
[1009] Fix | Delete
[1010] Fix | Delete
_serialize = {
[1011] Fix | Delete
"xml": _serialize_xml,
[1012] Fix | Delete
"html": _serialize_html,
[1013] Fix | Delete
"text": _serialize_text,
[1014] Fix | Delete
# this optional method is imported at the end of the module
[1015] Fix | Delete
# "c14n": _serialize_c14n,
[1016] Fix | Delete
}
[1017] Fix | Delete
[1018] Fix | Delete
[1019] Fix | Delete
def register_namespace(prefix, uri):
[1020] Fix | Delete
"""Register a namespace prefix.
[1021] Fix | Delete
[1022] Fix | Delete
The registry is global, and any existing mapping for either the
[1023] Fix | Delete
given prefix or the namespace URI will be removed.
[1024] Fix | Delete
[1025] Fix | Delete
*prefix* is the namespace prefix, *uri* is a namespace uri. Tags and
[1026] Fix | Delete
attributes in this namespace will be serialized with prefix if possible.
[1027] Fix | Delete
[1028] Fix | Delete
ValueError is raised if prefix is reserved or is invalid.
[1029] Fix | Delete
[1030] Fix | Delete
"""
[1031] Fix | Delete
if re.match(r"ns\d+$", prefix):
[1032] Fix | Delete
raise ValueError("Prefix format reserved for internal use")
[1033] Fix | Delete
for k, v in list(_namespace_map.items()):
[1034] Fix | Delete
if k == uri or v == prefix:
[1035] Fix | Delete
del _namespace_map[k]
[1036] Fix | Delete
_namespace_map[uri] = prefix
[1037] Fix | Delete
[1038] Fix | Delete
_namespace_map = {
[1039] Fix | Delete
# "well-known" namespace prefixes
[1040] Fix | Delete
"http://www.w3.org/XML/1998/namespace": "xml",
[1041] Fix | Delete
"http://www.w3.org/1999/xhtml": "html",
[1042] Fix | Delete
"http://www.w3.org/1999/02/22-rdf-syntax-ns#": "rdf",
[1043] Fix | Delete
"http://schemas.xmlsoap.org/wsdl/": "wsdl",
[1044] Fix | Delete
# xml schema
[1045] Fix | Delete
"http://www.w3.org/2001/XMLSchema": "xs",
[1046] Fix | Delete
"http://www.w3.org/2001/XMLSchema-instance": "xsi",
[1047] Fix | Delete
# dublin core
[1048] Fix | Delete
"http://purl.org/dc/elements/1.1/": "dc",
[1049] Fix | Delete
}
[1050] Fix | Delete
# For tests and troubleshooting
[1051] Fix | Delete
register_namespace._namespace_map = _namespace_map
[1052] Fix | Delete
[1053] Fix | Delete
def _raise_serialization_error(text):
[1054] Fix | Delete
raise TypeError(
[1055] Fix | Delete
"cannot serialize %r (type %s)" % (text, type(text).__name__)
[1056] Fix | Delete
)
[1057] Fix | Delete
[1058] Fix | Delete
def _escape_cdata(text):
[1059] Fix | Delete
# escape character data
[1060] Fix | Delete
try:
[1061] Fix | Delete
# it's worth avoiding do-nothing calls for strings that are
[1062] Fix | Delete
# shorter than 500 characters, or so. assume that's, by far,
[1063] Fix | Delete
# the most common case in most applications.
[1064] Fix | Delete
if "&" in text:
[1065] Fix | Delete
text = text.replace("&", "&amp;")
[1066] Fix | Delete
if "<" in text:
[1067] Fix | Delete
text = text.replace("<", "&lt;")
[1068] Fix | Delete
if ">" in text:
[1069] Fix | Delete
text = text.replace(">", "&gt;")
[1070] Fix | Delete
return text
[1071] Fix | Delete
except (TypeError, AttributeError):
[1072] Fix | Delete
_raise_serialization_error(text)
[1073] Fix | Delete
[1074] Fix | Delete
def _escape_attrib(text):
[1075] Fix | Delete
# escape attribute value
[1076] Fix | Delete
try:
[1077] Fix | Delete
if "&" in text:
[1078] Fix | Delete
text = text.replace("&", "&amp;")
[1079] Fix | Delete
if "<" in text:
[1080] Fix | Delete
text = text.replace("<", "&lt;")
[1081] Fix | Delete
if ">" in text:
[1082] Fix | Delete
text = text.replace(">", "&gt;")
[1083] Fix | Delete
if "\"" in text:
[1084] Fix | Delete
text = text.replace("\"", "&quot;")
[1085] Fix | Delete
# The following business with carriage returns is to satisfy
[1086] Fix | Delete
# Section 2.11 of the XML specification, stating that
[1087] Fix | Delete
# CR or CR LN should be replaced with just LN
[1088] Fix | Delete
# http://www.w3.org/TR/REC-xml/#sec-line-ends
[1089] Fix | Delete
if "\r\n" in text:
[1090] Fix | Delete
text = text.replace("\r\n", "\n")
[1091] Fix | Delete
if "\r" in text:
[1092] Fix | Delete
text = text.replace("\r", "\n")
[1093] Fix | Delete
#The following four lines are issue 17582
[1094] Fix | Delete
if "\n" in text:
[1095] Fix | Delete
text = text.replace("\n", "&#10;")
[1096] Fix | Delete
if "\t" in text:
[1097] Fix | Delete
text = text.replace("\t", "&#09;")
[1098] Fix | Delete
return text
[1099] Fix | Delete
except (TypeError, AttributeError):
[1100] Fix | Delete
_raise_serialization_error(text)
[1101] Fix | Delete
[1102] Fix | Delete
def _escape_attrib_html(text):
[1103] Fix | Delete
# escape attribute value
[1104] Fix | Delete
try:
[1105] Fix | Delete
if "&" in text:
[1106] Fix | Delete
text = text.replace("&", "&amp;")
[1107] Fix | Delete
if ">" in text:
[1108] Fix | Delete
text = text.replace(">", "&gt;")
[1109] Fix | Delete
if "\"" in text:
[1110] Fix | Delete
text = text.replace("\"", "&quot;")
[1111] Fix | Delete
return text
[1112] Fix | Delete
except (TypeError, AttributeError):
[1113] Fix | Delete
_raise_serialization_error(text)
[1114] Fix | Delete
[1115] Fix | Delete
# --------------------------------------------------------------------
[1116] Fix | Delete
[1117] Fix | Delete
def tostring(element, encoding=None, method=None, *,
[1118] Fix | Delete
short_empty_elements=True):
[1119] Fix | Delete
"""Generate string representation of XML element.
[1120] Fix | Delete
[1121] Fix | Delete
All subelements are included. If encoding is "unicode", a string
[1122] Fix | Delete
is returned. Otherwise a bytestring is returned.
[1123] Fix | Delete
[1124] Fix | Delete
*element* is an Element instance, *encoding* is an optional output
[1125] Fix | Delete
encoding defaulting to US-ASCII, *method* is an optional output which can
[1126] Fix | Delete
be one of "xml" (default), "html", "text" or "c14n".
[1127] Fix | Delete
[1128] Fix | Delete
Returns an (optionally) encoded string containing the XML data.
[1129] Fix | Delete
[1130] Fix | Delete
"""
[1131] Fix | Delete
stream = io.StringIO() if encoding == 'unicode' else io.BytesIO()
[1132] Fix | Delete
ElementTree(element).write(stream, encoding, method=method,
[1133] Fix | Delete
short_empty_elements=short_empty_elements)
[1134] Fix | Delete
return stream.getvalue()
[1135] Fix | Delete
[1136] Fix | Delete
class _ListDataStream(io.BufferedIOBase):
[1137] Fix | Delete
"""An auxiliary stream accumulating into a list reference."""
[1138] Fix | Delete
def __init__(self, lst):
[1139] Fix | Delete
self.lst = lst
[1140] Fix | Delete
[1141] Fix | Delete
def writable(self):
[1142] Fix | Delete
return True
[1143] Fix | Delete
[1144] Fix | Delete
def seekable(self):
[1145] Fix | Delete
return True
[1146] Fix | Delete
[1147] Fix | Delete
def write(self, b):
[1148] Fix | Delete
self.lst.append(b)
[1149] Fix | Delete
[1150] Fix | Delete
def tell(self):
[1151] Fix | Delete
return len(self.lst)
[1152] Fix | Delete
[1153] Fix | Delete
def tostringlist(element, encoding=None, method=None, *,
[1154] Fix | Delete
short_empty_elements=True):
[1155] Fix | Delete
lst = []
[1156] Fix | Delete
stream = _ListDataStream(lst)
[1157] Fix | Delete
ElementTree(element).write(stream, encoding, method=method,
[1158] Fix | Delete
short_empty_elements=short_empty_elements)
[1159] Fix | Delete
return lst
[1160] Fix | Delete
[1161] Fix | Delete
[1162] Fix | Delete
def dump(elem):
[1163] Fix | Delete
"""Write element tree or element structure to sys.stdout.
[1164] Fix | Delete
[1165] Fix | Delete
This function should be used for debugging only.
[1166] Fix | Delete
[1167] Fix | Delete
*elem* is either an ElementTree, or a single Element. The exact output
[1168] Fix | Delete
format is implementation dependent. In this version, it's written as an
[1169] Fix | Delete
ordinary XML file.
[1170] Fix | Delete
[1171] Fix | Delete
"""
[1172] Fix | Delete
# debugging
[1173] Fix | Delete
if not isinstance(elem, ElementTree):
[1174] Fix | Delete
elem = ElementTree(elem)
[1175] Fix | Delete
elem.write(sys.stdout, encoding="unicode")
[1176] Fix | Delete
tail = elem.getroot().tail
[1177] Fix | Delete
if not tail or tail[-1] != "\n":
[1178] Fix | Delete
sys.stdout.write("\n")
[1179] Fix | Delete
[1180] Fix | Delete
# --------------------------------------------------------------------
[1181] Fix | Delete
# parsing
[1182] Fix | Delete
[1183] Fix | Delete
[1184] Fix | Delete
def parse(source, parser=None):
[1185] Fix | Delete
"""Parse XML document into element tree.
[1186] Fix | Delete
[1187] Fix | Delete
*source* is a filename or file object containing XML data,
[1188] Fix | Delete
*parser* is an optional parser instance defaulting to XMLParser.
[1189] Fix | Delete
[1190] Fix | Delete
Return an ElementTree instance.
[1191] Fix | Delete
[1192] Fix | Delete
"""
[1193] Fix | Delete
tree = ElementTree()
[1194] Fix | Delete
tree.parse(source, parser)
[1195] Fix | Delete
return tree
[1196] Fix | Delete
[1197] Fix | Delete
[1198] Fix | Delete
def iterparse(source, events=None, parser=None):
[1199] Fix | Delete
"""Incrementally parse XML document into ElementTree.
[1200] Fix | Delete
[1201] Fix | Delete
This class also reports what's going on to the user based on the
[1202] Fix | Delete
*events* it is initialized with. The supported events are the strings
[1203] Fix | Delete
"start", "end", "start-ns" and "end-ns" (the "ns" events are used to get
[1204] Fix | Delete
detailed namespace information). If *events* is omitted, only
[1205] Fix | Delete
"end" events are reported.
[1206] Fix | Delete
[1207] Fix | Delete
*source* is a filename or file object containing XML data, *events* is
[1208] Fix | Delete
a list of events to report back, *parser* is an optional parser instance.
[1209] Fix | Delete
[1210] Fix | Delete
Returns an iterator providing (event, elem) pairs.
[1211] Fix | Delete
[1212] Fix | Delete
"""
[1213] Fix | Delete
# Use the internal, undocumented _parser argument for now; When the
[1214] Fix | Delete
# parser argument of iterparse is removed, this can be killed.
[1215] Fix | Delete
pullparser = XMLPullParser(events=events, _parser=parser)
[1216] Fix | Delete
def iterator():
[1217] Fix | Delete
try:
[1218] Fix | Delete
while True:
[1219] Fix | Delete
yield from pullparser.read_events()
[1220] Fix | Delete
# load event buffer
[1221] Fix | Delete
data = source.read(16 * 1024)
[1222] Fix | Delete
if not data:
[1223] Fix | Delete
break
[1224] Fix | Delete
pullparser.feed(data)
[1225] Fix | Delete
root = pullparser._close_and_return_root()
[1226] Fix | Delete
yield from pullparser.read_events()
[1227] Fix | Delete
it.root = root
[1228] Fix | Delete
finally:
[1229] Fix | Delete
if close_source:
[1230] Fix | Delete
source.close()
[1231] Fix | Delete
[1232] Fix | Delete
class IterParseIterator(collections.Iterator):
[1233] Fix | Delete
__next__ = iterator().__next__
[1234] Fix | Delete
it = IterParseIterator()
[1235] Fix | Delete
it.root = None
[1236] Fix | Delete
del iterator, IterParseIterator
[1237] Fix | Delete
[1238] Fix | Delete
close_source = False
[1239] Fix | Delete
if not hasattr(source, "read"):
[1240] Fix | Delete
source = open(source, "rb")
[1241] Fix | Delete
close_source = True
[1242] Fix | Delete
[1243] Fix | Delete
return it
[1244] Fix | Delete
[1245] Fix | Delete
[1246] Fix | Delete
class XMLPullParser:
[1247] Fix | Delete
[1248] Fix | Delete
def __init__(self, events=None, *, _parser=None):
[1249] Fix | Delete
# The _parser argument is for internal use only and must not be relied
[1250] Fix | Delete
# upon in user code. It will be removed in a future release.
[1251] Fix | Delete
# See http://bugs.python.org/issue17741 for more details.
[1252] Fix | Delete
[1253] Fix | Delete
self._events_queue = collections.deque()
[1254] Fix | Delete
self._parser = _parser or XMLParser(target=TreeBuilder())
[1255] Fix | Delete
# wire up the parser for event reporting
[1256] Fix | Delete
if events is None:
[1257] Fix | Delete
events = ("end",)
[1258] Fix | Delete
self._parser._setevents(self._events_queue, events)
[1259] Fix | Delete
[1260] Fix | Delete
def feed(self, data):
[1261] Fix | Delete
"""Feed encoded data to parser."""
[1262] Fix | Delete
if self._parser is None:
[1263] Fix | Delete
raise ValueError("feed() called after end of stream")
[1264] Fix | Delete
if data:
[1265] Fix | Delete
try:
[1266] Fix | Delete
self._parser.feed(data)
[1267] Fix | Delete
except SyntaxError as exc:
[1268] Fix | Delete
self._events_queue.append(exc)
[1269] Fix | Delete
[1270] Fix | Delete
def _close_and_return_root(self):
[1271] Fix | Delete
# iterparse needs this to set its root attribute properly :(
[1272] Fix | Delete
root = self._parser.close()
[1273] Fix | Delete
self._parser = None
[1274] Fix | Delete
return root
[1275] Fix | Delete
[1276] Fix | Delete
def close(self):
[1277] Fix | Delete
"""Finish feeding data to parser.
[1278] Fix | Delete
[1279] Fix | Delete
Unlike XMLParser, does not return the root element. Use
[1280] Fix | Delete
read_events() to consume elements from XMLPullParser.
[1281] Fix | Delete
"""
[1282] Fix | Delete
self._close_and_return_root()
[1283] Fix | Delete
[1284] Fix | Delete
def read_events(self):
[1285] Fix | Delete
"""Return an iterator over currently available (event, elem) pairs.
[1286] Fix | Delete
[1287] Fix | Delete
Events are consumed from the internal event queue as they are
[1288] Fix | Delete
retrieved from the iterator.
[1289] Fix | Delete
"""
[1290] Fix | Delete
events = self._events_queue
[1291] Fix | Delete
while events:
[1292] Fix | Delete
event = events.popleft()
[1293] Fix | Delete
if isinstance(event, Exception):
[1294] Fix | Delete
raise event
[1295] Fix | Delete
else:
[1296] Fix | Delete
yield event
[1297] Fix | Delete
[1298] Fix | Delete
[1299] Fix | Delete
def XML(text, parser=None):
[1300] Fix | Delete
"""Parse XML document from string constant.
[1301] Fix | Delete
[1302] Fix | Delete
This function can be used to embed "XML Literals" in Python code.
[1303] Fix | Delete
[1304] Fix | Delete
*text* is a string containing XML data, *parser* is an
[1305] Fix | Delete
optional parser instance, defaulting to the standard XMLParser.
[1306] Fix | Delete
[1307] Fix | Delete
Returns an Element instance.
[1308] Fix | Delete
[1309] Fix | Delete
"""
[1310] Fix | Delete
if not parser:
[1311] Fix | Delete
parser = XMLParser(target=TreeBuilder())
[1312] Fix | Delete
parser.feed(text)
[1313] Fix | Delete
return parser.close()
[1314] Fix | Delete
[1315] Fix | Delete
[1316] Fix | Delete
def XMLID(text, parser=None):
[1317] Fix | Delete
"""Parse XML document from string constant for its IDs.
[1318] Fix | Delete
[1319] Fix | Delete
*text* is a string containing XML data, *parser* is an
[1320] Fix | Delete
optional parser instance, defaulting to the standard XMLParser.
[1321] Fix | Delete
[1322] Fix | Delete
Returns an (Element, dict) tuple, in which the
[1323] Fix | Delete
dict maps element id:s to elements.
[1324] Fix | Delete
[1325] Fix | Delete
"""
[1326] Fix | Delete
if not parser:
[1327] Fix | Delete
parser = XMLParser(target=TreeBuilder())
[1328] Fix | Delete
parser.feed(text)
[1329] Fix | Delete
tree = parser.close()
[1330] Fix | Delete
ids = {}
[1331] Fix | Delete
for elem in tree.iter():
[1332] Fix | Delete
id = elem.get("id")
[1333] Fix | Delete
if id:
[1334] Fix | Delete
ids[id] = elem
[1335] Fix | Delete
return tree, ids
[1336] Fix | Delete
[1337] Fix | Delete
# Parse XML document from string constant. Alias for XML().
[1338] Fix | Delete
fromstring = XML
[1339] Fix | Delete
[1340] Fix | Delete
def fromstringlist(sequence, parser=None):
[1341] Fix | Delete
"""Parse XML document from sequence of string fragments.
[1342] Fix | Delete
[1343] Fix | Delete
*sequence* is a list of other sequence, *parser* is an optional parser
[1344] Fix | Delete
instance, defaulting to the standard XMLParser.
[1345] Fix | Delete
[1346] Fix | Delete
Returns an Element instance.
[1347] Fix | Delete
[1348] Fix | Delete
"""
[1349] Fix | Delete
if not parser:
[1350] Fix | Delete
parser = XMLParser(target=TreeBuilder())
[1351] Fix | Delete
for text in sequence:
[1352] Fix | Delete
parser.feed(text)
[1353] Fix | Delete
return parser.close()
[1354] Fix | Delete
[1355] Fix | Delete
# --------------------------------------------------------------------
[1356] Fix | Delete
[1357] Fix | Delete
[1358] Fix | Delete
class TreeBuilder:
[1359] Fix | Delete
"""Generic element structure builder.
[1360] Fix | Delete
[1361] Fix | Delete
This builder converts a sequence of start, data, and end method
[1362] Fix | Delete
calls to a well-formed element structure.
[1363] Fix | Delete
[1364] Fix | Delete
You can use this class to build an element structure using a custom XML
[1365] Fix | Delete
parser, or a parser for some other XML-like format.
[1366] Fix | Delete
[1367] Fix | Delete
*element_factory* is an optional element factory which is called
[1368] Fix | Delete
to create new Element instances, as necessary.
[1369] Fix | Delete
[1370] Fix | Delete
"""
[1371] Fix | Delete
def __init__(self, element_factory=None):
[1372] Fix | Delete
self._data = [] # data collector
[1373] Fix | Delete
self._elem = [] # element stack
[1374] Fix | Delete
self._last = None # last element
[1375] Fix | Delete
self._tail = None # true if we're after an end tag
[1376] Fix | Delete
if element_factory is None:
[1377] Fix | Delete
element_factory = Element
[1378] Fix | Delete
self._factory = element_factory
[1379] Fix | Delete
[1380] Fix | Delete
def close(self):
[1381] Fix | Delete
"""Flush builder buffers and return toplevel document Element."""
[1382] Fix | Delete
assert len(self._elem) == 0, "missing end tags"
[1383] Fix | Delete
assert self._last is not None, "missing toplevel element"
[1384] Fix | Delete
return self._last
[1385] Fix | Delete
[1386] Fix | Delete
def _flush(self):
[1387] Fix | Delete
if self._data:
[1388] Fix | Delete
if self._last is not None:
[1389] Fix | Delete
text = "".join(self._data)
[1390] Fix | Delete
if self._tail:
[1391] Fix | Delete
assert self._last.tail is None, "internal error (tail)"
[1392] Fix | Delete
self._last.tail = text
[1393] Fix | Delete
else:
[1394] Fix | Delete
assert self._last.text is None, "internal error (text)"
[1395] Fix | Delete
self._last.text = text
[1396] Fix | Delete
self._data = []
[1397] Fix | Delete
[1398] Fix | Delete
def data(self, data):
[1399] Fix | Delete
"""Add text to current element."""
[1400] Fix | Delete
self._data.append(data)
[1401] Fix | Delete
[1402] Fix | Delete
def start(self, tag, attrs):
[1403] Fix | Delete
"""Open new element and return it.
[1404] Fix | Delete
[1405] Fix | Delete
*tag* is the element name, *attrs* is a dict containing element
[1406] Fix | Delete
attributes.
[1407] Fix | Delete
[1408] Fix | Delete
"""
[1409] Fix | Delete
self._flush()
[1410] Fix | Delete
self._last = elem = self._factory(tag, attrs)
[1411] Fix | Delete
if self._elem:
[1412] Fix | Delete
self._elem[-1].append(elem)
[1413] Fix | Delete
self._elem.append(elem)
[1414] Fix | Delete
self._tail = 0
[1415] Fix | Delete
return elem
[1416] Fix | Delete
[1417] Fix | Delete
def end(self, tag):
[1418] Fix | Delete
"""Close and return current Element.
[1419] Fix | Delete
[1420] Fix | Delete
*tag* is the element name.
[1421] Fix | Delete
[1422] Fix | Delete
"""
[1423] Fix | Delete
self._flush()
[1424] Fix | Delete
self._last = self._elem.pop()
[1425] Fix | Delete
assert self._last.tag == tag,\
[1426] Fix | Delete
"end tag mismatch (expected %s, got %s)" % (
[1427] Fix | Delete
self._last.tag, tag)
[1428] Fix | Delete
self._tail = 1
[1429] Fix | Delete
return self._last
[1430] Fix | Delete
[1431] Fix | Delete
[1432] Fix | Delete
# also see ElementTree and TreeBuilder
[1433] Fix | Delete
class XMLParser:
[1434] Fix | Delete
"""Element structure builder for XML source data based on the expat parser.
[1435] Fix | Delete
[1436] Fix | Delete
*html* are predefined HTML entities (deprecated and not supported),
[1437] Fix | Delete
*target* is an optional target object which defaults to an instance of the
[1438] Fix | Delete
standard TreeBuilder class, *encoding* is an optional encoding string
[1439] Fix | Delete
which if given, overrides the encoding specified in the XML file:
[1440] Fix | Delete
http://www.iana.org/assignments/character-sets
[1441] Fix | Delete
[1442] Fix | Delete
"""
[1443] Fix | Delete
[1444] Fix | Delete
def __init__(self, html=0, target=None, encoding=None):
[1445] Fix | Delete
try:
[1446] Fix | Delete
from xml.parsers import expat
[1447] Fix | Delete
except ImportError:
[1448] Fix | Delete
try:
[1449] Fix | Delete
import pyexpat as expat
[1450] Fix | Delete
except ImportError:
[1451] Fix | Delete
raise ImportError(
[1452] Fix | Delete
"No module named expat; use SimpleXMLTreeBuilder instead"
[1453] Fix | Delete
)
[1454] Fix | Delete
parser = expat.ParserCreate(encoding, "}")
[1455] Fix | Delete
if target is None:
[1456] Fix | Delete
target = TreeBuilder()
[1457] Fix | Delete
# underscored names are provided for compatibility only
[1458] Fix | Delete
self.parser = self._parser = parser
[1459] Fix | Delete
self.target = self._target = target
[1460] Fix | Delete
self._error = expat.error
[1461] Fix | Delete
self._names = {} # name memo cache
[1462] Fix | Delete
# main callbacks
[1463] Fix | Delete
parser.DefaultHandlerExpand = self._default
[1464] Fix | Delete
if hasattr(target, 'start'):
[1465] Fix | Delete
parser.StartElementHandler = self._start
[1466] Fix | Delete
if hasattr(target, 'end'):
[1467] Fix | Delete
parser.EndElementHandler = self._end
[1468] Fix | Delete
if hasattr(target, 'data'):
[1469] Fix | Delete
parser.CharacterDataHandler = target.data
[1470] Fix | Delete
# miscellaneous callbacks
[1471] Fix | Delete
if hasattr(target, 'comment'):
[1472] Fix | Delete
parser.CommentHandler = target.comment
[1473] Fix | Delete
if hasattr(target, 'pi'):
[1474] Fix | Delete
parser.ProcessingInstructionHandler = target.pi
[1475] Fix | Delete
# Configure pyexpat: buffering, new-style attribute handling.
[1476] Fix | Delete
parser.buffer_text = 1
[1477] Fix | Delete
parser.ordered_attributes = 1
[1478] Fix | Delete
parser.specified_attributes = 1
[1479] Fix | Delete
self._doctype = None
[1480] Fix | Delete
self.entity = {}
[1481] Fix | Delete
try:
[1482] Fix | Delete
self.version = "Expat %d.%d.%d" % expat.version_info
[1483] Fix | Delete
except AttributeError:
[1484] Fix | Delete
pass # unknown
[1485] Fix | Delete
[1486] Fix | Delete
def _setevents(self, events_queue, events_to_report):
[1487] Fix | Delete
# Internal API for XMLPullParser
[1488] Fix | Delete
# events_to_report: a list of events to report during parsing (same as
[1489] Fix | Delete
# the *events* of XMLPullParser's constructor.
[1490] Fix | Delete
# events_queue: a list of actual parsing events that will be populated
[1491] Fix | Delete
# by the underlying parser.
[1492] Fix | Delete
#
[1493] Fix | Delete
parser = self._parser
[1494] Fix | Delete
append = events_queue.append
[1495] Fix | Delete
for event_name in events_to_report:
[1496] Fix | Delete
if event_name == "start":
[1497] Fix | Delete
parser.ordered_attributes = 1
[1498] Fix | Delete
parser.specified_attributes = 1
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function