Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/lib64/python3..../xml/etree
File: ElementTree.py
{uri}local, or if the tag argument is given, the URI part of a QName.
[500] Fix | Delete
[501] Fix | Delete
*tag* is an optional argument which if given, will make the first
[502] Fix | Delete
argument (text_or_uri) be interpreted as a URI, and this argument (tag)
[503] Fix | Delete
be interpreted as a local name.
[504] Fix | Delete
[505] Fix | Delete
"""
[506] Fix | Delete
def __init__(self, text_or_uri, tag=None):
[507] Fix | Delete
if tag:
[508] Fix | Delete
text_or_uri = "{%s}%s" % (text_or_uri, tag)
[509] Fix | Delete
self.text = text_or_uri
[510] Fix | Delete
def __str__(self):
[511] Fix | Delete
return self.text
[512] Fix | Delete
def __repr__(self):
[513] Fix | Delete
return '<%s %r>' % (self.__class__.__name__, self.text)
[514] Fix | Delete
def __hash__(self):
[515] Fix | Delete
return hash(self.text)
[516] Fix | Delete
def __le__(self, other):
[517] Fix | Delete
if isinstance(other, QName):
[518] Fix | Delete
return self.text <= other.text
[519] Fix | Delete
return self.text <= other
[520] Fix | Delete
def __lt__(self, other):
[521] Fix | Delete
if isinstance(other, QName):
[522] Fix | Delete
return self.text < other.text
[523] Fix | Delete
return self.text < other
[524] Fix | Delete
def __ge__(self, other):
[525] Fix | Delete
if isinstance(other, QName):
[526] Fix | Delete
return self.text >= other.text
[527] Fix | Delete
return self.text >= other
[528] Fix | Delete
def __gt__(self, other):
[529] Fix | Delete
if isinstance(other, QName):
[530] Fix | Delete
return self.text > other.text
[531] Fix | Delete
return self.text > other
[532] Fix | Delete
def __eq__(self, other):
[533] Fix | Delete
if isinstance(other, QName):
[534] Fix | Delete
return self.text == other.text
[535] Fix | Delete
return self.text == other
[536] Fix | Delete
[537] Fix | Delete
# --------------------------------------------------------------------
[538] Fix | Delete
[539] Fix | Delete
[540] Fix | Delete
class ElementTree:
[541] Fix | Delete
"""An XML element hierarchy.
[542] Fix | Delete
[543] Fix | Delete
This class also provides support for serialization to and from
[544] Fix | Delete
standard XML.
[545] Fix | Delete
[546] Fix | Delete
*element* is an optional root element node,
[547] Fix | Delete
*file* is an optional file handle or file name of an XML file whose
[548] Fix | Delete
contents will be used to initialize the tree with.
[549] Fix | Delete
[550] Fix | Delete
"""
[551] Fix | Delete
def __init__(self, element=None, file=None):
[552] Fix | Delete
# assert element is None or iselement(element)
[553] Fix | Delete
self._root = element # first node
[554] Fix | Delete
if file:
[555] Fix | Delete
self.parse(file)
[556] Fix | Delete
[557] Fix | Delete
def getroot(self):
[558] Fix | Delete
"""Return root element of this tree."""
[559] Fix | Delete
return self._root
[560] Fix | Delete
[561] Fix | Delete
def _setroot(self, element):
[562] Fix | Delete
"""Replace root element of this tree.
[563] Fix | Delete
[564] Fix | Delete
This will discard the current contents of the tree and replace it
[565] Fix | Delete
with the given element. Use with care!
[566] Fix | Delete
[567] Fix | Delete
"""
[568] Fix | Delete
# assert iselement(element)
[569] Fix | Delete
self._root = element
[570] Fix | Delete
[571] Fix | Delete
def parse(self, source, parser=None):
[572] Fix | Delete
"""Load external XML document into element tree.
[573] Fix | Delete
[574] Fix | Delete
*source* is a file name or file object, *parser* is an optional parser
[575] Fix | Delete
instance that defaults to XMLParser.
[576] Fix | Delete
[577] Fix | Delete
ParseError is raised if the parser fails to parse the document.
[578] Fix | Delete
[579] Fix | Delete
Returns the root element of the given source document.
[580] Fix | Delete
[581] Fix | Delete
"""
[582] Fix | Delete
close_source = False
[583] Fix | Delete
if not hasattr(source, "read"):
[584] Fix | Delete
source = open(source, "rb")
[585] Fix | Delete
close_source = True
[586] Fix | Delete
try:
[587] Fix | Delete
if parser is None:
[588] Fix | Delete
# If no parser was specified, create a default XMLParser
[589] Fix | Delete
parser = XMLParser()
[590] Fix | Delete
if hasattr(parser, '_parse_whole'):
[591] Fix | Delete
# The default XMLParser, when it comes from an accelerator,
[592] Fix | Delete
# can define an internal _parse_whole API for efficiency.
[593] Fix | Delete
# It can be used to parse the whole source without feeding
[594] Fix | Delete
# it with chunks.
[595] Fix | Delete
self._root = parser._parse_whole(source)
[596] Fix | Delete
return self._root
[597] Fix | Delete
while True:
[598] Fix | Delete
data = source.read(65536)
[599] Fix | Delete
if not data:
[600] Fix | Delete
break
[601] Fix | Delete
parser.feed(data)
[602] Fix | Delete
self._root = parser.close()
[603] Fix | Delete
return self._root
[604] Fix | Delete
finally:
[605] Fix | Delete
if close_source:
[606] Fix | Delete
source.close()
[607] Fix | Delete
[608] Fix | Delete
def iter(self, tag=None):
[609] Fix | Delete
"""Create and return tree iterator for the root element.
[610] Fix | Delete
[611] Fix | Delete
The iterator loops over all elements in this tree, in document order.
[612] Fix | Delete
[613] Fix | Delete
*tag* is a string with the tag name to iterate over
[614] Fix | Delete
(default is to return all elements).
[615] Fix | Delete
[616] Fix | Delete
"""
[617] Fix | Delete
# assert self._root is not None
[618] Fix | Delete
return self._root.iter(tag)
[619] Fix | Delete
[620] Fix | Delete
# compatibility
[621] Fix | Delete
def getiterator(self, tag=None):
[622] Fix | Delete
# Change for a DeprecationWarning in 1.4
[623] Fix | Delete
warnings.warn(
[624] Fix | Delete
"This method will be removed in future versions. "
[625] Fix | Delete
"Use 'tree.iter()' or 'list(tree.iter())' instead.",
[626] Fix | Delete
PendingDeprecationWarning, stacklevel=2
[627] Fix | Delete
)
[628] Fix | Delete
return list(self.iter(tag))
[629] Fix | Delete
[630] Fix | Delete
def find(self, path, namespaces=None):
[631] Fix | Delete
"""Find first matching element by tag name or path.
[632] Fix | Delete
[633] Fix | Delete
Same as getroot().find(path), which is Element.find()
[634] Fix | Delete
[635] Fix | Delete
*path* is a string having either an element tag or an XPath,
[636] Fix | Delete
*namespaces* is an optional mapping from namespace prefix to full name.
[637] Fix | Delete
[638] Fix | Delete
Return the first matching element, or None if no element was found.
[639] Fix | Delete
[640] Fix | Delete
"""
[641] Fix | Delete
# assert self._root is not None
[642] Fix | Delete
if path[:1] == "/":
[643] Fix | Delete
path = "." + path
[644] Fix | Delete
warnings.warn(
[645] Fix | Delete
"This search is broken in 1.3 and earlier, and will be "
[646] Fix | Delete
"fixed in a future version. If you rely on the current "
[647] Fix | Delete
"behaviour, change it to %r" % path,
[648] Fix | Delete
FutureWarning, stacklevel=2
[649] Fix | Delete
)
[650] Fix | Delete
return self._root.find(path, namespaces)
[651] Fix | Delete
[652] Fix | Delete
def findtext(self, path, default=None, namespaces=None):
[653] Fix | Delete
"""Find first matching element by tag name or path.
[654] Fix | Delete
[655] Fix | Delete
Same as getroot().findtext(path), which is Element.findtext()
[656] Fix | Delete
[657] Fix | Delete
*path* is a string having either an element tag or an XPath,
[658] Fix | Delete
*namespaces* is an optional mapping from namespace prefix to full name.
[659] Fix | Delete
[660] Fix | Delete
Return the first matching element, or None if no element was found.
[661] Fix | Delete
[662] Fix | Delete
"""
[663] Fix | Delete
# assert self._root is not None
[664] Fix | Delete
if path[:1] == "/":
[665] Fix | Delete
path = "." + path
[666] Fix | Delete
warnings.warn(
[667] Fix | Delete
"This search is broken in 1.3 and earlier, and will be "
[668] Fix | Delete
"fixed in a future version. If you rely on the current "
[669] Fix | Delete
"behaviour, change it to %r" % path,
[670] Fix | Delete
FutureWarning, stacklevel=2
[671] Fix | Delete
)
[672] Fix | Delete
return self._root.findtext(path, default, namespaces)
[673] Fix | Delete
[674] Fix | Delete
def findall(self, path, namespaces=None):
[675] Fix | Delete
"""Find all matching subelements by tag name or path.
[676] Fix | Delete
[677] Fix | Delete
Same as getroot().findall(path), which is Element.findall().
[678] Fix | Delete
[679] Fix | Delete
*path* is a string having either an element tag or an XPath,
[680] Fix | Delete
*namespaces* is an optional mapping from namespace prefix to full name.
[681] Fix | Delete
[682] Fix | Delete
Return list containing all matching elements in document order.
[683] Fix | Delete
[684] Fix | Delete
"""
[685] Fix | Delete
# assert self._root is not None
[686] Fix | Delete
if path[:1] == "/":
[687] Fix | Delete
path = "." + path
[688] Fix | Delete
warnings.warn(
[689] Fix | Delete
"This search is broken in 1.3 and earlier, and will be "
[690] Fix | Delete
"fixed in a future version. If you rely on the current "
[691] Fix | Delete
"behaviour, change it to %r" % path,
[692] Fix | Delete
FutureWarning, stacklevel=2
[693] Fix | Delete
)
[694] Fix | Delete
return self._root.findall(path, namespaces)
[695] Fix | Delete
[696] Fix | Delete
def iterfind(self, path, namespaces=None):
[697] Fix | Delete
"""Find all matching subelements by tag name or path.
[698] Fix | Delete
[699] Fix | Delete
Same as getroot().iterfind(path), which is element.iterfind()
[700] Fix | Delete
[701] Fix | Delete
*path* is a string having either an element tag or an XPath,
[702] Fix | Delete
*namespaces* is an optional mapping from namespace prefix to full name.
[703] Fix | Delete
[704] Fix | Delete
Return an iterable yielding all matching elements in document order.
[705] Fix | Delete
[706] Fix | Delete
"""
[707] Fix | Delete
# assert self._root is not None
[708] Fix | Delete
if path[:1] == "/":
[709] Fix | Delete
path = "." + path
[710] Fix | Delete
warnings.warn(
[711] Fix | Delete
"This search is broken in 1.3 and earlier, and will be "
[712] Fix | Delete
"fixed in a future version. If you rely on the current "
[713] Fix | Delete
"behaviour, change it to %r" % path,
[714] Fix | Delete
FutureWarning, stacklevel=2
[715] Fix | Delete
)
[716] Fix | Delete
return self._root.iterfind(path, namespaces)
[717] Fix | Delete
[718] Fix | Delete
def write(self, file_or_filename,
[719] Fix | Delete
encoding=None,
[720] Fix | Delete
xml_declaration=None,
[721] Fix | Delete
default_namespace=None,
[722] Fix | Delete
method=None, *,
[723] Fix | Delete
short_empty_elements=True):
[724] Fix | Delete
"""Write element tree to a file as XML.
[725] Fix | Delete
[726] Fix | Delete
Arguments:
[727] Fix | Delete
*file_or_filename* -- file name or a file object opened for writing
[728] Fix | Delete
[729] Fix | Delete
*encoding* -- the output encoding (default: US-ASCII)
[730] Fix | Delete
[731] Fix | Delete
*xml_declaration* -- bool indicating if an XML declaration should be
[732] Fix | Delete
added to the output. If None, an XML declaration
[733] Fix | Delete
is added if encoding IS NOT either of:
[734] Fix | Delete
US-ASCII, UTF-8, or Unicode
[735] Fix | Delete
[736] Fix | Delete
*default_namespace* -- sets the default XML namespace (for "xmlns")
[737] Fix | Delete
[738] Fix | Delete
*method* -- either "xml" (default), "html, "text", or "c14n"
[739] Fix | Delete
[740] Fix | Delete
*short_empty_elements* -- controls the formatting of elements
[741] Fix | Delete
that contain no content. If True (default)
[742] Fix | Delete
they are emitted as a single self-closed
[743] Fix | Delete
tag, otherwise they are emitted as a pair
[744] Fix | Delete
of start/end tags
[745] Fix | Delete
[746] Fix | Delete
"""
[747] Fix | Delete
if not method:
[748] Fix | Delete
method = "xml"
[749] Fix | Delete
elif method not in _serialize:
[750] Fix | Delete
raise ValueError("unknown method %r" % method)
[751] Fix | Delete
if not encoding:
[752] Fix | Delete
if method == "c14n":
[753] Fix | Delete
encoding = "utf-8"
[754] Fix | Delete
else:
[755] Fix | Delete
encoding = "us-ascii"
[756] Fix | Delete
enc_lower = encoding.lower()
[757] Fix | Delete
with _get_writer(file_or_filename, enc_lower) as write:
[758] Fix | Delete
if method == "xml" and (xml_declaration or
[759] Fix | Delete
(xml_declaration is None and
[760] Fix | Delete
enc_lower not in ("utf-8", "us-ascii", "unicode"))):
[761] Fix | Delete
declared_encoding = encoding
[762] Fix | Delete
if enc_lower == "unicode":
[763] Fix | Delete
# Retrieve the default encoding for the xml declaration
[764] Fix | Delete
import locale
[765] Fix | Delete
declared_encoding = locale.getpreferredencoding()
[766] Fix | Delete
write("<?xml version='1.0' encoding='%s'?>\n" % (
[767] Fix | Delete
declared_encoding,))
[768] Fix | Delete
if method == "text":
[769] Fix | Delete
_serialize_text(write, self._root)
[770] Fix | Delete
else:
[771] Fix | Delete
qnames, namespaces = _namespaces(self._root, default_namespace)
[772] Fix | Delete
serialize = _serialize[method]
[773] Fix | Delete
serialize(write, self._root, qnames, namespaces,
[774] Fix | Delete
short_empty_elements=short_empty_elements)
[775] Fix | Delete
[776] Fix | Delete
def write_c14n(self, file):
[777] Fix | Delete
# lxml.etree compatibility. use output method instead
[778] Fix | Delete
return self.write(file, method="c14n")
[779] Fix | Delete
[780] Fix | Delete
# --------------------------------------------------------------------
[781] Fix | Delete
# serialization support
[782] Fix | Delete
[783] Fix | Delete
@contextlib.contextmanager
[784] Fix | Delete
def _get_writer(file_or_filename, encoding):
[785] Fix | Delete
# returns text write method and release all resources after using
[786] Fix | Delete
try:
[787] Fix | Delete
write = file_or_filename.write
[788] Fix | Delete
except AttributeError:
[789] Fix | Delete
# file_or_filename is a file name
[790] Fix | Delete
if encoding == "unicode":
[791] Fix | Delete
file = open(file_or_filename, "w")
[792] Fix | Delete
else:
[793] Fix | Delete
file = open(file_or_filename, "w", encoding=encoding,
[794] Fix | Delete
errors="xmlcharrefreplace")
[795] Fix | Delete
with file:
[796] Fix | Delete
yield file.write
[797] Fix | Delete
else:
[798] Fix | Delete
# file_or_filename is a file-like object
[799] Fix | Delete
# encoding determines if it is a text or binary writer
[800] Fix | Delete
if encoding == "unicode":
[801] Fix | Delete
# use a text writer as is
[802] Fix | Delete
yield write
[803] Fix | Delete
else:
[804] Fix | Delete
# wrap a binary writer with TextIOWrapper
[805] Fix | Delete
with contextlib.ExitStack() as stack:
[806] Fix | Delete
if isinstance(file_or_filename, io.BufferedIOBase):
[807] Fix | Delete
file = file_or_filename
[808] Fix | Delete
elif isinstance(file_or_filename, io.RawIOBase):
[809] Fix | Delete
file = io.BufferedWriter(file_or_filename)
[810] Fix | Delete
# Keep the original file open when the BufferedWriter is
[811] Fix | Delete
# destroyed
[812] Fix | Delete
stack.callback(file.detach)
[813] Fix | Delete
else:
[814] Fix | Delete
# This is to handle passed objects that aren't in the
[815] Fix | Delete
# IOBase hierarchy, but just have a write method
[816] Fix | Delete
file = io.BufferedIOBase()
[817] Fix | Delete
file.writable = lambda: True
[818] Fix | Delete
file.write = write
[819] Fix | Delete
try:
[820] Fix | Delete
# TextIOWrapper uses this methods to determine
[821] Fix | Delete
# if BOM (for UTF-16, etc) should be added
[822] Fix | Delete
file.seekable = file_or_filename.seekable
[823] Fix | Delete
file.tell = file_or_filename.tell
[824] Fix | Delete
except AttributeError:
[825] Fix | Delete
pass
[826] Fix | Delete
file = io.TextIOWrapper(file,
[827] Fix | Delete
encoding=encoding,
[828] Fix | Delete
errors="xmlcharrefreplace",
[829] Fix | Delete
newline="\n")
[830] Fix | Delete
# Keep the original file open when the TextIOWrapper is
[831] Fix | Delete
# destroyed
[832] Fix | Delete
stack.callback(file.detach)
[833] Fix | Delete
yield file.write
[834] Fix | Delete
[835] Fix | Delete
def _namespaces(elem, default_namespace=None):
[836] Fix | Delete
# identify namespaces used in this tree
[837] Fix | Delete
[838] Fix | Delete
# maps qnames to *encoded* prefix:local names
[839] Fix | Delete
qnames = {None: None}
[840] Fix | Delete
[841] Fix | Delete
# maps uri:s to prefixes
[842] Fix | Delete
namespaces = {}
[843] Fix | Delete
if default_namespace:
[844] Fix | Delete
namespaces[default_namespace] = ""
[845] Fix | Delete
[846] Fix | Delete
def add_qname(qname):
[847] Fix | Delete
# calculate serialized qname representation
[848] Fix | Delete
try:
[849] Fix | Delete
if qname[:1] == "{":
[850] Fix | Delete
uri, tag = qname[1:].rsplit("}", 1)
[851] Fix | Delete
prefix = namespaces.get(uri)
[852] Fix | Delete
if prefix is None:
[853] Fix | Delete
prefix = _namespace_map.get(uri)
[854] Fix | Delete
if prefix is None:
[855] Fix | Delete
prefix = "ns%d" % len(namespaces)
[856] Fix | Delete
if prefix != "xml":
[857] Fix | Delete
namespaces[uri] = prefix
[858] Fix | Delete
if prefix:
[859] Fix | Delete
qnames[qname] = "%s:%s" % (prefix, tag)
[860] Fix | Delete
else:
[861] Fix | Delete
qnames[qname] = tag # default element
[862] Fix | Delete
else:
[863] Fix | Delete
if default_namespace:
[864] Fix | Delete
# FIXME: can this be handled in XML 1.0?
[865] Fix | Delete
raise ValueError(
[866] Fix | Delete
"cannot use non-qualified names with "
[867] Fix | Delete
"default_namespace option"
[868] Fix | Delete
)
[869] Fix | Delete
qnames[qname] = qname
[870] Fix | Delete
except TypeError:
[871] Fix | Delete
_raise_serialization_error(qname)
[872] Fix | Delete
[873] Fix | Delete
# populate qname and namespaces table
[874] Fix | Delete
for elem in elem.iter():
[875] Fix | Delete
tag = elem.tag
[876] Fix | Delete
if isinstance(tag, QName):
[877] Fix | Delete
if tag.text not in qnames:
[878] Fix | Delete
add_qname(tag.text)
[879] Fix | Delete
elif isinstance(tag, str):
[880] Fix | Delete
if tag not in qnames:
[881] Fix | Delete
add_qname(tag)
[882] Fix | Delete
elif tag is not None and tag is not Comment and tag is not PI:
[883] Fix | Delete
_raise_serialization_error(tag)
[884] Fix | Delete
for key, value in elem.items():
[885] Fix | Delete
if isinstance(key, QName):
[886] Fix | Delete
key = key.text
[887] Fix | Delete
if key not in qnames:
[888] Fix | Delete
add_qname(key)
[889] Fix | Delete
if isinstance(value, QName) and value.text not in qnames:
[890] Fix | Delete
add_qname(value.text)
[891] Fix | Delete
text = elem.text
[892] Fix | Delete
if isinstance(text, QName) and text.text not in qnames:
[893] Fix | Delete
add_qname(text.text)
[894] Fix | Delete
return qnames, namespaces
[895] Fix | Delete
[896] Fix | Delete
def _serialize_xml(write, elem, qnames, namespaces,
[897] Fix | Delete
short_empty_elements, **kwargs):
[898] Fix | Delete
tag = elem.tag
[899] Fix | Delete
text = elem.text
[900] Fix | Delete
if tag is Comment:
[901] Fix | Delete
write("<!--%s-->" % text)
[902] Fix | Delete
elif tag is ProcessingInstruction:
[903] Fix | Delete
write("<?%s?>" % text)
[904] Fix | Delete
else:
[905] Fix | Delete
tag = qnames[tag]
[906] Fix | Delete
if tag is None:
[907] Fix | Delete
if text:
[908] Fix | Delete
write(_escape_cdata(text))
[909] Fix | Delete
for e in elem:
[910] Fix | Delete
_serialize_xml(write, e, qnames, None,
[911] Fix | Delete
short_empty_elements=short_empty_elements)
[912] Fix | Delete
else:
[913] Fix | Delete
write("<" + tag)
[914] Fix | Delete
items = list(elem.items())
[915] Fix | Delete
if items or namespaces:
[916] Fix | Delete
if namespaces:
[917] Fix | Delete
for v, k in sorted(namespaces.items(),
[918] Fix | Delete
key=lambda x: x[1]): # sort on prefix
[919] Fix | Delete
if k:
[920] Fix | Delete
k = ":" + k
[921] Fix | Delete
write(" xmlns%s=\"%s\"" % (
[922] Fix | Delete
k,
[923] Fix | Delete
_escape_attrib(v)
[924] Fix | Delete
))
[925] Fix | Delete
for k, v in sorted(items): # lexical order
[926] Fix | Delete
if isinstance(k, QName):
[927] Fix | Delete
k = k.text
[928] Fix | Delete
if isinstance(v, QName):
[929] Fix | Delete
v = qnames[v.text]
[930] Fix | Delete
else:
[931] Fix | Delete
v = _escape_attrib(v)
[932] Fix | Delete
write(" %s=\"%s\"" % (qnames[k], v))
[933] Fix | Delete
if text or len(elem) or not short_empty_elements:
[934] Fix | Delete
write(">")
[935] Fix | Delete
if text:
[936] Fix | Delete
write(_escape_cdata(text))
[937] Fix | Delete
for e in elem:
[938] Fix | Delete
_serialize_xml(write, e, qnames, None,
[939] Fix | Delete
short_empty_elements=short_empty_elements)
[940] Fix | Delete
write("</" + tag + ">")
[941] Fix | Delete
else:
[942] Fix | Delete
write(" />")
[943] Fix | Delete
if elem.tail:
[944] Fix | Delete
write(_escape_cdata(elem.tail))
[945] Fix | Delete
[946] Fix | Delete
HTML_EMPTY = ("area", "base", "basefont", "br", "col", "frame", "hr",
[947] Fix | Delete
"img", "input", "isindex", "link", "meta", "param")
[948] Fix | Delete
[949] Fix | Delete
try:
[950] Fix | Delete
HTML_EMPTY = set(HTML_EMPTY)
[951] Fix | Delete
except NameError:
[952] Fix | Delete
pass
[953] Fix | Delete
[954] Fix | Delete
def _serialize_html(write, elem, qnames, namespaces, **kwargs):
[955] Fix | Delete
tag = elem.tag
[956] Fix | Delete
text = elem.text
[957] Fix | Delete
if tag is Comment:
[958] Fix | Delete
write("<!--%s-->" % _escape_cdata(text))
[959] Fix | Delete
elif tag is ProcessingInstruction:
[960] Fix | Delete
write("<?%s?>" % _escape_cdata(text))
[961] Fix | Delete
else:
[962] Fix | Delete
tag = qnames[tag]
[963] Fix | Delete
if tag is None:
[964] Fix | Delete
if text:
[965] Fix | Delete
write(_escape_cdata(text))
[966] Fix | Delete
for e in elem:
[967] Fix | Delete
_serialize_html(write, e, qnames, None)
[968] Fix | Delete
else:
[969] Fix | Delete
write("<" + tag)
[970] Fix | Delete
items = list(elem.items())
[971] Fix | Delete
if items or namespaces:
[972] Fix | Delete
if namespaces:
[973] Fix | Delete
for v, k in sorted(namespaces.items(),
[974] Fix | Delete
key=lambda x: x[1]): # sort on prefix
[975] Fix | Delete
if k:
[976] Fix | Delete
k = ":" + k
[977] Fix | Delete
write(" xmlns%s=\"%s\"" % (
[978] Fix | Delete
k,
[979] Fix | Delete
_escape_attrib(v)
[980] Fix | Delete
))
[981] Fix | Delete
for k, v in sorted(items): # lexical order
[982] Fix | Delete
if isinstance(k, QName):
[983] Fix | Delete
k = k.text
[984] Fix | Delete
if isinstance(v, QName):
[985] Fix | Delete
v = qnames[v.text]
[986] Fix | Delete
else:
[987] Fix | Delete
v = _escape_attrib_html(v)
[988] Fix | Delete
# FIXME: handle boolean attributes
[989] Fix | Delete
write(" %s=\"%s\"" % (qnames[k], v))
[990] Fix | Delete
write(">")
[991] Fix | Delete
ltag = tag.lower()
[992] Fix | Delete
if text:
[993] Fix | Delete
if ltag == "script" or ltag == "style":
[994] Fix | Delete
write(text)
[995] Fix | Delete
else:
[996] Fix | Delete
write(_escape_cdata(text))
[997] Fix | Delete
for e in elem:
[998] Fix | Delete
_serialize_html(write, e, qnames, None)
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function