Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python2..../xml/etree
File: ElementTree.py
return
[500] Fix | Delete
if self.text:
[501] Fix | Delete
yield self.text
[502] Fix | Delete
for e in self:
[503] Fix | Delete
for s in e.itertext():
[504] Fix | Delete
yield s
[505] Fix | Delete
if e.tail:
[506] Fix | Delete
yield e.tail
[507] Fix | Delete
[508] Fix | Delete
# compatibility
[509] Fix | Delete
_Element = _ElementInterface = Element
[510] Fix | Delete
[511] Fix | Delete
##
[512] Fix | Delete
# Subelement factory. This function creates an element instance, and
[513] Fix | Delete
# appends it to an existing element.
[514] Fix | Delete
# <p>
[515] Fix | Delete
# The element name, attribute names, and attribute values can be
[516] Fix | Delete
# either 8-bit ASCII strings or Unicode strings.
[517] Fix | Delete
#
[518] Fix | Delete
# @param parent The parent element.
[519] Fix | Delete
# @param tag The subelement name.
[520] Fix | Delete
# @param attrib An optional dictionary, containing element attributes.
[521] Fix | Delete
# @param **extra Additional attributes, given as keyword arguments.
[522] Fix | Delete
# @return An element instance.
[523] Fix | Delete
# @defreturn Element
[524] Fix | Delete
[525] Fix | Delete
def SubElement(parent, tag, attrib={}, **extra):
[526] Fix | Delete
attrib = attrib.copy()
[527] Fix | Delete
attrib.update(extra)
[528] Fix | Delete
element = parent.makeelement(tag, attrib)
[529] Fix | Delete
parent.append(element)
[530] Fix | Delete
return element
[531] Fix | Delete
[532] Fix | Delete
##
[533] Fix | Delete
# Comment element factory. This factory function creates a special
[534] Fix | Delete
# element that will be serialized as an XML comment by the standard
[535] Fix | Delete
# serializer.
[536] Fix | Delete
# <p>
[537] Fix | Delete
# The comment string can be either an 8-bit ASCII string or a Unicode
[538] Fix | Delete
# string.
[539] Fix | Delete
#
[540] Fix | Delete
# @param text A string containing the comment string.
[541] Fix | Delete
# @return An element instance, representing a comment.
[542] Fix | Delete
# @defreturn Element
[543] Fix | Delete
[544] Fix | Delete
def Comment(text=None):
[545] Fix | Delete
element = Element(Comment)
[546] Fix | Delete
element.text = text
[547] Fix | Delete
return element
[548] Fix | Delete
[549] Fix | Delete
##
[550] Fix | Delete
# PI element factory. This factory function creates a special element
[551] Fix | Delete
# that will be serialized as an XML processing instruction by the standard
[552] Fix | Delete
# serializer.
[553] Fix | Delete
#
[554] Fix | Delete
# @param target A string containing the PI target.
[555] Fix | Delete
# @param text A string containing the PI contents, if any.
[556] Fix | Delete
# @return An element instance, representing a PI.
[557] Fix | Delete
# @defreturn Element
[558] Fix | Delete
[559] Fix | Delete
def ProcessingInstruction(target, text=None):
[560] Fix | Delete
element = Element(ProcessingInstruction)
[561] Fix | Delete
element.text = target
[562] Fix | Delete
if text:
[563] Fix | Delete
element.text = element.text + " " + text
[564] Fix | Delete
return element
[565] Fix | Delete
[566] Fix | Delete
PI = ProcessingInstruction
[567] Fix | Delete
[568] Fix | Delete
##
[569] Fix | Delete
# QName wrapper. This can be used to wrap a QName attribute value, in
[570] Fix | Delete
# order to get proper namespace handling on output.
[571] Fix | Delete
#
[572] Fix | Delete
# @param text A string containing the QName value, in the form {uri}local,
[573] Fix | Delete
# or, if the tag argument is given, the URI part of a QName.
[574] Fix | Delete
# @param tag Optional tag. If given, the first argument is interpreted as
[575] Fix | Delete
# a URI, and this argument is interpreted as a local name.
[576] Fix | Delete
# @return An opaque object, representing the QName.
[577] Fix | Delete
[578] Fix | Delete
class QName(object):
[579] Fix | Delete
def __init__(self, text_or_uri, tag=None):
[580] Fix | Delete
if tag:
[581] Fix | Delete
text_or_uri = "{%s}%s" % (text_or_uri, tag)
[582] Fix | Delete
self.text = text_or_uri
[583] Fix | Delete
def __str__(self):
[584] Fix | Delete
return self.text
[585] Fix | Delete
def __hash__(self):
[586] Fix | Delete
return hash(self.text)
[587] Fix | Delete
def __cmp__(self, other):
[588] Fix | Delete
if isinstance(other, QName):
[589] Fix | Delete
return cmp(self.text, other.text)
[590] Fix | Delete
return cmp(self.text, other)
[591] Fix | Delete
[592] Fix | Delete
# --------------------------------------------------------------------
[593] Fix | Delete
[594] Fix | Delete
##
[595] Fix | Delete
# ElementTree wrapper class. This class represents an entire element
[596] Fix | Delete
# hierarchy, and adds some extra support for serialization to and from
[597] Fix | Delete
# standard XML.
[598] Fix | Delete
#
[599] Fix | Delete
# @param element Optional root element.
[600] Fix | Delete
# @keyparam file Optional file handle or file name. If given, the
[601] Fix | Delete
# tree is initialized with the contents of this XML file.
[602] Fix | Delete
[603] Fix | Delete
class ElementTree(object):
[604] Fix | Delete
[605] Fix | Delete
def __init__(self, element=None, file=None):
[606] Fix | Delete
# assert element is None or iselement(element)
[607] Fix | Delete
self._root = element # first node
[608] Fix | Delete
if file:
[609] Fix | Delete
self.parse(file)
[610] Fix | Delete
[611] Fix | Delete
##
[612] Fix | Delete
# Gets the root element for this tree.
[613] Fix | Delete
#
[614] Fix | Delete
# @return An element instance.
[615] Fix | Delete
# @defreturn Element
[616] Fix | Delete
[617] Fix | Delete
def getroot(self):
[618] Fix | Delete
return self._root
[619] Fix | Delete
[620] Fix | Delete
##
[621] Fix | Delete
# Replaces the root element for this tree. This discards the
[622] Fix | Delete
# current contents of the tree, and replaces it with the given
[623] Fix | Delete
# element. Use with care.
[624] Fix | Delete
#
[625] Fix | Delete
# @param element An element instance.
[626] Fix | Delete
[627] Fix | Delete
def _setroot(self, element):
[628] Fix | Delete
# assert iselement(element)
[629] Fix | Delete
self._root = element
[630] Fix | Delete
[631] Fix | Delete
##
[632] Fix | Delete
# Loads an external XML document into this element tree.
[633] Fix | Delete
#
[634] Fix | Delete
# @param source A file name or file object. If a file object is
[635] Fix | Delete
# given, it only has to implement a <b>read(n)</b> method.
[636] Fix | Delete
# @keyparam parser An optional parser instance. If not given, the
[637] Fix | Delete
# standard {@link XMLParser} parser is used.
[638] Fix | Delete
# @return The document root element.
[639] Fix | Delete
# @defreturn Element
[640] Fix | Delete
# @exception ParseError If the parser fails to parse the document.
[641] Fix | Delete
[642] Fix | Delete
def parse(self, source, parser=None):
[643] Fix | Delete
close_source = False
[644] Fix | Delete
if not hasattr(source, "read"):
[645] Fix | Delete
source = open(source, "rb")
[646] Fix | Delete
close_source = True
[647] Fix | Delete
try:
[648] Fix | Delete
if not parser:
[649] Fix | Delete
parser = XMLParser(target=TreeBuilder())
[650] Fix | Delete
while 1:
[651] Fix | Delete
data = source.read(65536)
[652] Fix | Delete
if not data:
[653] Fix | Delete
break
[654] Fix | Delete
parser.feed(data)
[655] Fix | Delete
self._root = parser.close()
[656] Fix | Delete
return self._root
[657] Fix | Delete
finally:
[658] Fix | Delete
if close_source:
[659] Fix | Delete
source.close()
[660] Fix | Delete
[661] Fix | Delete
##
[662] Fix | Delete
# Creates a tree iterator for the root element. The iterator loops
[663] Fix | Delete
# over all elements in this tree, in document order.
[664] Fix | Delete
#
[665] Fix | Delete
# @param tag What tags to look for (default is to return all elements)
[666] Fix | Delete
# @return An iterator.
[667] Fix | Delete
# @defreturn iterator
[668] Fix | Delete
[669] Fix | Delete
def iter(self, tag=None):
[670] Fix | Delete
# assert self._root is not None
[671] Fix | Delete
return self._root.iter(tag)
[672] Fix | Delete
[673] Fix | Delete
# compatibility
[674] Fix | Delete
def getiterator(self, tag=None):
[675] Fix | Delete
# Change for a DeprecationWarning in 1.4
[676] Fix | Delete
warnings.warn(
[677] Fix | Delete
"This method will be removed in future versions. "
[678] Fix | Delete
"Use 'tree.iter()' or 'list(tree.iter())' instead.",
[679] Fix | Delete
PendingDeprecationWarning, stacklevel=2
[680] Fix | Delete
)
[681] Fix | Delete
return list(self.iter(tag))
[682] Fix | Delete
[683] Fix | Delete
##
[684] Fix | Delete
# Same as getroot().find(path), starting at the root of the
[685] Fix | Delete
# tree.
[686] Fix | Delete
#
[687] Fix | Delete
# @param path What element to look for.
[688] Fix | Delete
# @keyparam namespaces Optional namespace prefix map.
[689] Fix | Delete
# @return The first matching element, or None if no element was found.
[690] Fix | Delete
# @defreturn Element or None
[691] Fix | Delete
[692] Fix | Delete
def find(self, path, namespaces=None):
[693] Fix | Delete
# assert self._root is not None
[694] Fix | Delete
if path[:1] == "/":
[695] Fix | Delete
path = "." + path
[696] Fix | Delete
warnings.warn(
[697] Fix | Delete
"This search is broken in 1.3 and earlier, and will be "
[698] Fix | Delete
"fixed in a future version. If you rely on the current "
[699] Fix | Delete
"behaviour, change it to %r" % path,
[700] Fix | Delete
FutureWarning, stacklevel=2
[701] Fix | Delete
)
[702] Fix | Delete
return self._root.find(path, namespaces)
[703] Fix | Delete
[704] Fix | Delete
##
[705] Fix | Delete
# Same as getroot().findtext(path), starting at the root of the tree.
[706] Fix | Delete
#
[707] Fix | Delete
# @param path What element to look for.
[708] Fix | Delete
# @param default What to return if the element was not found.
[709] Fix | Delete
# @keyparam namespaces Optional namespace prefix map.
[710] Fix | Delete
# @return The text content of the first matching element, or the
[711] Fix | Delete
# default value no element was found. Note that if the element
[712] Fix | Delete
# is found, but has no text content, this method returns an
[713] Fix | Delete
# empty string.
[714] Fix | Delete
# @defreturn string
[715] Fix | Delete
[716] Fix | Delete
def findtext(self, path, default=None, namespaces=None):
[717] Fix | Delete
# assert self._root is not None
[718] Fix | Delete
if path[:1] == "/":
[719] Fix | Delete
path = "." + path
[720] Fix | Delete
warnings.warn(
[721] Fix | Delete
"This search is broken in 1.3 and earlier, and will be "
[722] Fix | Delete
"fixed in a future version. If you rely on the current "
[723] Fix | Delete
"behaviour, change it to %r" % path,
[724] Fix | Delete
FutureWarning, stacklevel=2
[725] Fix | Delete
)
[726] Fix | Delete
return self._root.findtext(path, default, namespaces)
[727] Fix | Delete
[728] Fix | Delete
##
[729] Fix | Delete
# Same as getroot().findall(path), starting at the root of the tree.
[730] Fix | Delete
#
[731] Fix | Delete
# @param path What element to look for.
[732] Fix | Delete
# @keyparam namespaces Optional namespace prefix map.
[733] Fix | Delete
# @return A list or iterator containing all matching elements,
[734] Fix | Delete
# in document order.
[735] Fix | Delete
# @defreturn list of Element instances
[736] Fix | Delete
[737] Fix | Delete
def findall(self, path, namespaces=None):
[738] Fix | Delete
# assert self._root is not None
[739] Fix | Delete
if path[:1] == "/":
[740] Fix | Delete
path = "." + path
[741] Fix | Delete
warnings.warn(
[742] Fix | Delete
"This search is broken in 1.3 and earlier, and will be "
[743] Fix | Delete
"fixed in a future version. If you rely on the current "
[744] Fix | Delete
"behaviour, change it to %r" % path,
[745] Fix | Delete
FutureWarning, stacklevel=2
[746] Fix | Delete
)
[747] Fix | Delete
return self._root.findall(path, namespaces)
[748] Fix | Delete
[749] Fix | Delete
##
[750] Fix | Delete
# Finds all matching subelements, by tag name or path.
[751] Fix | Delete
# Same as getroot().iterfind(path).
[752] Fix | Delete
#
[753] Fix | Delete
# @param path What element to look for.
[754] Fix | Delete
# @keyparam namespaces Optional namespace prefix map.
[755] Fix | Delete
# @return An iterator or sequence containing all matching elements,
[756] Fix | Delete
# in document order.
[757] Fix | Delete
# @defreturn a generated sequence of Element instances
[758] Fix | Delete
[759] Fix | Delete
def iterfind(self, path, namespaces=None):
[760] Fix | Delete
# assert self._root is not None
[761] Fix | Delete
if path[:1] == "/":
[762] Fix | Delete
path = "." + path
[763] Fix | Delete
warnings.warn(
[764] Fix | Delete
"This search is broken in 1.3 and earlier, and will be "
[765] Fix | Delete
"fixed in a future version. If you rely on the current "
[766] Fix | Delete
"behaviour, change it to %r" % path,
[767] Fix | Delete
FutureWarning, stacklevel=2
[768] Fix | Delete
)
[769] Fix | Delete
return self._root.iterfind(path, namespaces)
[770] Fix | Delete
[771] Fix | Delete
##
[772] Fix | Delete
# Writes the element tree to a file, as XML.
[773] Fix | Delete
#
[774] Fix | Delete
# @def write(file, **options)
[775] Fix | Delete
# @param file A file name, or a file object opened for writing.
[776] Fix | Delete
# @param **options Options, given as keyword arguments.
[777] Fix | Delete
# @keyparam encoding Optional output encoding (default is US-ASCII).
[778] Fix | Delete
# @keyparam xml_declaration Controls if an XML declaration should
[779] Fix | Delete
# be added to the file. Use False for never, True for always,
[780] Fix | Delete
# None for only if not US-ASCII or UTF-8. None is default.
[781] Fix | Delete
# @keyparam default_namespace Sets the default XML namespace (for "xmlns").
[782] Fix | Delete
# @keyparam method Optional output method ("xml", "html", "text" or
[783] Fix | Delete
# "c14n"; default is "xml").
[784] Fix | Delete
[785] Fix | Delete
def write(self, file_or_filename,
[786] Fix | Delete
# keyword arguments
[787] Fix | Delete
encoding=None,
[788] Fix | Delete
xml_declaration=None,
[789] Fix | Delete
default_namespace=None,
[790] Fix | Delete
method=None):
[791] Fix | Delete
# assert self._root is not None
[792] Fix | Delete
if not method:
[793] Fix | Delete
method = "xml"
[794] Fix | Delete
elif method not in _serialize:
[795] Fix | Delete
# FIXME: raise an ImportError for c14n if ElementC14N is missing?
[796] Fix | Delete
raise ValueError("unknown method %r" % method)
[797] Fix | Delete
if hasattr(file_or_filename, "write"):
[798] Fix | Delete
file = file_or_filename
[799] Fix | Delete
else:
[800] Fix | Delete
file = open(file_or_filename, "wb")
[801] Fix | Delete
write = file.write
[802] Fix | Delete
if not encoding:
[803] Fix | Delete
if method == "c14n":
[804] Fix | Delete
encoding = "utf-8"
[805] Fix | Delete
else:
[806] Fix | Delete
encoding = "us-ascii"
[807] Fix | Delete
elif xml_declaration or (xml_declaration is None and
[808] Fix | Delete
encoding not in ("utf-8", "us-ascii")):
[809] Fix | Delete
if method == "xml":
[810] Fix | Delete
write("<?xml version='1.0' encoding='%s'?>\n" % encoding)
[811] Fix | Delete
if method == "text":
[812] Fix | Delete
_serialize_text(write, self._root, encoding)
[813] Fix | Delete
else:
[814] Fix | Delete
qnames, namespaces = _namespaces(
[815] Fix | Delete
self._root, encoding, default_namespace
[816] Fix | Delete
)
[817] Fix | Delete
serialize = _serialize[method]
[818] Fix | Delete
serialize(write, self._root, encoding, qnames, namespaces)
[819] Fix | Delete
if file_or_filename is not file:
[820] Fix | Delete
file.close()
[821] Fix | Delete
[822] Fix | Delete
def write_c14n(self, file):
[823] Fix | Delete
# lxml.etree compatibility. use output method instead
[824] Fix | Delete
return self.write(file, method="c14n")
[825] Fix | Delete
[826] Fix | Delete
# --------------------------------------------------------------------
[827] Fix | Delete
# serialization support
[828] Fix | Delete
[829] Fix | Delete
def _namespaces(elem, encoding, default_namespace=None):
[830] Fix | Delete
# identify namespaces used in this tree
[831] Fix | Delete
[832] Fix | Delete
# maps qnames to *encoded* prefix:local names
[833] Fix | Delete
qnames = {None: None}
[834] Fix | Delete
[835] Fix | Delete
# maps uri:s to prefixes
[836] Fix | Delete
namespaces = {}
[837] Fix | Delete
if default_namespace:
[838] Fix | Delete
namespaces[default_namespace] = ""
[839] Fix | Delete
[840] Fix | Delete
def encode(text):
[841] Fix | Delete
return text.encode(encoding)
[842] Fix | Delete
[843] Fix | Delete
def add_qname(qname):
[844] Fix | Delete
# calculate serialized qname representation
[845] Fix | Delete
try:
[846] Fix | Delete
if qname[:1] == "{":
[847] Fix | Delete
uri, tag = qname[1:].rsplit("}", 1)
[848] Fix | Delete
prefix = namespaces.get(uri)
[849] Fix | Delete
if prefix is None:
[850] Fix | Delete
prefix = _namespace_map.get(uri)
[851] Fix | Delete
if prefix is None:
[852] Fix | Delete
prefix = "ns%d" % len(namespaces)
[853] Fix | Delete
if prefix != "xml":
[854] Fix | Delete
namespaces[uri] = prefix
[855] Fix | Delete
if prefix:
[856] Fix | Delete
qnames[qname] = encode("%s:%s" % (prefix, tag))
[857] Fix | Delete
else:
[858] Fix | Delete
qnames[qname] = encode(tag) # default element
[859] Fix | Delete
else:
[860] Fix | Delete
if default_namespace:
[861] Fix | Delete
# FIXME: can this be handled in XML 1.0?
[862] Fix | Delete
raise ValueError(
[863] Fix | Delete
"cannot use non-qualified names with "
[864] Fix | Delete
"default_namespace option"
[865] Fix | Delete
)
[866] Fix | Delete
qnames[qname] = encode(qname)
[867] Fix | Delete
except TypeError:
[868] Fix | Delete
_raise_serialization_error(qname)
[869] Fix | Delete
[870] Fix | Delete
# populate qname and namespaces table
[871] Fix | Delete
try:
[872] Fix | Delete
iterate = elem.iter
[873] Fix | Delete
except AttributeError:
[874] Fix | Delete
iterate = elem.getiterator # cET compatibility
[875] Fix | Delete
for elem in iterate():
[876] Fix | Delete
tag = elem.tag
[877] Fix | Delete
if isinstance(tag, QName):
[878] Fix | Delete
if tag.text not in qnames:
[879] Fix | Delete
add_qname(tag.text)
[880] Fix | Delete
elif isinstance(tag, basestring):
[881] Fix | Delete
if tag not in qnames:
[882] Fix | Delete
add_qname(tag)
[883] Fix | Delete
elif tag is not None and tag is not Comment and tag is not PI:
[884] Fix | Delete
_raise_serialization_error(tag)
[885] Fix | Delete
for key, value in elem.items():
[886] Fix | Delete
if isinstance(key, QName):
[887] Fix | Delete
key = key.text
[888] Fix | Delete
if key not in qnames:
[889] Fix | Delete
add_qname(key)
[890] Fix | Delete
if isinstance(value, QName) and value.text not in qnames:
[891] Fix | Delete
add_qname(value.text)
[892] Fix | Delete
text = elem.text
[893] Fix | Delete
if isinstance(text, QName) and text.text not in qnames:
[894] Fix | Delete
add_qname(text.text)
[895] Fix | Delete
return qnames, namespaces
[896] Fix | Delete
[897] Fix | Delete
def _serialize_xml(write, elem, encoding, qnames, namespaces):
[898] Fix | Delete
tag = elem.tag
[899] Fix | Delete
text = elem.text
[900] Fix | Delete
if tag is Comment:
[901] Fix | Delete
write("<!--%s-->" % _encode(text, encoding))
[902] Fix | Delete
elif tag is ProcessingInstruction:
[903] Fix | Delete
write("<?%s?>" % _encode(text, encoding))
[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, encoding))
[909] Fix | Delete
for e in elem:
[910] Fix | Delete
_serialize_xml(write, e, encoding, qnames, None)
[911] Fix | Delete
else:
[912] Fix | Delete
write("<" + tag)
[913] Fix | Delete
items = elem.items()
[914] Fix | Delete
if items or namespaces:
[915] Fix | Delete
if namespaces:
[916] Fix | Delete
for v, k in sorted(namespaces.items(),
[917] Fix | Delete
key=lambda x: x[1]): # sort on prefix
[918] Fix | Delete
if k:
[919] Fix | Delete
k = ":" + k
[920] Fix | Delete
write(" xmlns%s=\"%s\"" % (
[921] Fix | Delete
k.encode(encoding),
[922] Fix | Delete
_escape_attrib(v, encoding)
[923] Fix | Delete
))
[924] Fix | Delete
for k, v in sorted(items): # lexical order
[925] Fix | Delete
if isinstance(k, QName):
[926] Fix | Delete
k = k.text
[927] Fix | Delete
if isinstance(v, QName):
[928] Fix | Delete
v = qnames[v.text]
[929] Fix | Delete
else:
[930] Fix | Delete
v = _escape_attrib(v, encoding)
[931] Fix | Delete
write(" %s=\"%s\"" % (qnames[k], v))
[932] Fix | Delete
if text or len(elem):
[933] Fix | Delete
write(">")
[934] Fix | Delete
if text:
[935] Fix | Delete
write(_escape_cdata(text, encoding))
[936] Fix | Delete
for e in elem:
[937] Fix | Delete
_serialize_xml(write, e, encoding, qnames, None)
[938] Fix | Delete
write("</" + tag + ">")
[939] Fix | Delete
else:
[940] Fix | Delete
write(" />")
[941] Fix | Delete
if elem.tail:
[942] Fix | Delete
write(_escape_cdata(elem.tail, encoding))
[943] Fix | Delete
[944] Fix | Delete
HTML_EMPTY = ("area", "base", "basefont", "br", "col", "frame", "hr",
[945] Fix | Delete
"img", "input", "isindex", "link", "meta", "param")
[946] Fix | Delete
[947] Fix | Delete
try:
[948] Fix | Delete
HTML_EMPTY = set(HTML_EMPTY)
[949] Fix | Delete
except NameError:
[950] Fix | Delete
pass
[951] Fix | Delete
[952] Fix | Delete
def _serialize_html(write, elem, encoding, qnames, namespaces):
[953] Fix | Delete
tag = elem.tag
[954] Fix | Delete
text = elem.text
[955] Fix | Delete
if tag is Comment:
[956] Fix | Delete
write("<!--%s-->" % _escape_cdata(text, encoding))
[957] Fix | Delete
elif tag is ProcessingInstruction:
[958] Fix | Delete
write("<?%s?>" % _escape_cdata(text, encoding))
[959] Fix | Delete
else:
[960] Fix | Delete
tag = qnames[tag]
[961] Fix | Delete
if tag is None:
[962] Fix | Delete
if text:
[963] Fix | Delete
write(_escape_cdata(text, encoding))
[964] Fix | Delete
for e in elem:
[965] Fix | Delete
_serialize_html(write, e, encoding, qnames, None)
[966] Fix | Delete
else:
[967] Fix | Delete
write("<" + tag)
[968] Fix | Delete
items = elem.items()
[969] Fix | Delete
if items or namespaces:
[970] Fix | Delete
if namespaces:
[971] Fix | Delete
for v, k in sorted(namespaces.items(),
[972] Fix | Delete
key=lambda x: x[1]): # sort on prefix
[973] Fix | Delete
if k:
[974] Fix | Delete
k = ":" + k
[975] Fix | Delete
write(" xmlns%s=\"%s\"" % (
[976] Fix | Delete
k.encode(encoding),
[977] Fix | Delete
_escape_attrib(v, encoding)
[978] Fix | Delete
))
[979] Fix | Delete
for k, v in sorted(items): # lexical order
[980] Fix | Delete
if isinstance(k, QName):
[981] Fix | Delete
k = k.text
[982] Fix | Delete
if isinstance(v, QName):
[983] Fix | Delete
v = qnames[v.text]
[984] Fix | Delete
else:
[985] Fix | Delete
v = _escape_attrib_html(v, encoding)
[986] Fix | Delete
# FIXME: handle boolean attributes
[987] Fix | Delete
write(" %s=\"%s\"" % (qnames[k], v))
[988] Fix | Delete
write(">")
[989] Fix | Delete
ltag = tag.lower()
[990] Fix | Delete
if text:
[991] Fix | Delete
if ltag == "script" or ltag == "style":
[992] Fix | Delete
write(_encode(text, encoding))
[993] Fix | Delete
else:
[994] Fix | Delete
write(_escape_cdata(text, encoding))
[995] Fix | Delete
for e in elem:
[996] Fix | Delete
_serialize_html(write, e, encoding, qnames, None)
[997] Fix | Delete
if ltag not in HTML_EMPTY:
[998] Fix | Delete
write("</" + tag + ">")
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function