Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../xml/dom
File: minidom.py
"""Simple implementation of the Level 1 DOM.
[0] Fix | Delete
[1] Fix | Delete
Namespaces and other minor Level 2 features are also supported.
[2] Fix | Delete
[3] Fix | Delete
parse("foo.xml")
[4] Fix | Delete
[5] Fix | Delete
parseString("<foo><bar/></foo>")
[6] Fix | Delete
[7] Fix | Delete
Todo:
[8] Fix | Delete
=====
[9] Fix | Delete
* convenience methods for getting elements and text.
[10] Fix | Delete
* more testing
[11] Fix | Delete
* bring some of the writer and linearizer code into conformance with this
[12] Fix | Delete
interface
[13] Fix | Delete
* SAX 2 namespaces
[14] Fix | Delete
"""
[15] Fix | Delete
[16] Fix | Delete
import xml.dom
[17] Fix | Delete
[18] Fix | Delete
from xml.dom import EMPTY_NAMESPACE, EMPTY_PREFIX, XMLNS_NAMESPACE, domreg
[19] Fix | Delete
from xml.dom.minicompat import *
[20] Fix | Delete
from xml.dom.xmlbuilder import DOMImplementationLS, DocumentLS
[21] Fix | Delete
[22] Fix | Delete
# This is used by the ID-cache invalidation checks; the list isn't
[23] Fix | Delete
# actually complete, since the nodes being checked will never be the
[24] Fix | Delete
# DOCUMENT_NODE or DOCUMENT_FRAGMENT_NODE. (The node being checked is
[25] Fix | Delete
# the node being added or removed, not the node being modified.)
[26] Fix | Delete
#
[27] Fix | Delete
_nodeTypes_with_children = (xml.dom.Node.ELEMENT_NODE,
[28] Fix | Delete
xml.dom.Node.ENTITY_REFERENCE_NODE)
[29] Fix | Delete
[30] Fix | Delete
[31] Fix | Delete
class Node(xml.dom.Node):
[32] Fix | Delete
namespaceURI = None # this is non-null only for elements and attributes
[33] Fix | Delete
parentNode = None
[34] Fix | Delete
ownerDocument = None
[35] Fix | Delete
nextSibling = None
[36] Fix | Delete
previousSibling = None
[37] Fix | Delete
[38] Fix | Delete
prefix = EMPTY_PREFIX # non-null only for NS elements and attributes
[39] Fix | Delete
[40] Fix | Delete
def __nonzero__(self):
[41] Fix | Delete
return True
[42] Fix | Delete
[43] Fix | Delete
def toxml(self, encoding = None):
[44] Fix | Delete
return self.toprettyxml("", "", encoding)
[45] Fix | Delete
[46] Fix | Delete
def toprettyxml(self, indent="\t", newl="\n", encoding = None):
[47] Fix | Delete
# indent = the indentation string to prepend, per level
[48] Fix | Delete
# newl = the newline string to append
[49] Fix | Delete
writer = _get_StringIO()
[50] Fix | Delete
if encoding is not None:
[51] Fix | Delete
import codecs
[52] Fix | Delete
# Can't use codecs.getwriter to preserve 2.0 compatibility
[53] Fix | Delete
writer = codecs.lookup(encoding)[3](writer)
[54] Fix | Delete
if self.nodeType == Node.DOCUMENT_NODE:
[55] Fix | Delete
# Can pass encoding only to document, to put it into XML header
[56] Fix | Delete
self.writexml(writer, "", indent, newl, encoding)
[57] Fix | Delete
else:
[58] Fix | Delete
self.writexml(writer, "", indent, newl)
[59] Fix | Delete
return writer.getvalue()
[60] Fix | Delete
[61] Fix | Delete
def hasChildNodes(self):
[62] Fix | Delete
if self.childNodes:
[63] Fix | Delete
return True
[64] Fix | Delete
else:
[65] Fix | Delete
return False
[66] Fix | Delete
[67] Fix | Delete
def _get_childNodes(self):
[68] Fix | Delete
return self.childNodes
[69] Fix | Delete
[70] Fix | Delete
def _get_firstChild(self):
[71] Fix | Delete
if self.childNodes:
[72] Fix | Delete
return self.childNodes[0]
[73] Fix | Delete
[74] Fix | Delete
def _get_lastChild(self):
[75] Fix | Delete
if self.childNodes:
[76] Fix | Delete
return self.childNodes[-1]
[77] Fix | Delete
[78] Fix | Delete
def insertBefore(self, newChild, refChild):
[79] Fix | Delete
if newChild.nodeType == self.DOCUMENT_FRAGMENT_NODE:
[80] Fix | Delete
for c in tuple(newChild.childNodes):
[81] Fix | Delete
self.insertBefore(c, refChild)
[82] Fix | Delete
### The DOM does not clearly specify what to return in this case
[83] Fix | Delete
return newChild
[84] Fix | Delete
if newChild.nodeType not in self._child_node_types:
[85] Fix | Delete
raise xml.dom.HierarchyRequestErr(
[86] Fix | Delete
"%s cannot be child of %s" % (repr(newChild), repr(self)))
[87] Fix | Delete
if newChild.parentNode is not None:
[88] Fix | Delete
newChild.parentNode.removeChild(newChild)
[89] Fix | Delete
if refChild is None:
[90] Fix | Delete
self.appendChild(newChild)
[91] Fix | Delete
else:
[92] Fix | Delete
try:
[93] Fix | Delete
index = self.childNodes.index(refChild)
[94] Fix | Delete
except ValueError:
[95] Fix | Delete
raise xml.dom.NotFoundErr()
[96] Fix | Delete
if newChild.nodeType in _nodeTypes_with_children:
[97] Fix | Delete
_clear_id_cache(self)
[98] Fix | Delete
self.childNodes.insert(index, newChild)
[99] Fix | Delete
newChild.nextSibling = refChild
[100] Fix | Delete
refChild.previousSibling = newChild
[101] Fix | Delete
if index:
[102] Fix | Delete
node = self.childNodes[index-1]
[103] Fix | Delete
node.nextSibling = newChild
[104] Fix | Delete
newChild.previousSibling = node
[105] Fix | Delete
else:
[106] Fix | Delete
newChild.previousSibling = None
[107] Fix | Delete
newChild.parentNode = self
[108] Fix | Delete
return newChild
[109] Fix | Delete
[110] Fix | Delete
def appendChild(self, node):
[111] Fix | Delete
if node.nodeType == self.DOCUMENT_FRAGMENT_NODE:
[112] Fix | Delete
for c in tuple(node.childNodes):
[113] Fix | Delete
self.appendChild(c)
[114] Fix | Delete
### The DOM does not clearly specify what to return in this case
[115] Fix | Delete
return node
[116] Fix | Delete
if node.nodeType not in self._child_node_types:
[117] Fix | Delete
raise xml.dom.HierarchyRequestErr(
[118] Fix | Delete
"%s cannot be child of %s" % (repr(node), repr(self)))
[119] Fix | Delete
elif node.nodeType in _nodeTypes_with_children:
[120] Fix | Delete
_clear_id_cache(self)
[121] Fix | Delete
if node.parentNode is not None:
[122] Fix | Delete
node.parentNode.removeChild(node)
[123] Fix | Delete
_append_child(self, node)
[124] Fix | Delete
node.nextSibling = None
[125] Fix | Delete
return node
[126] Fix | Delete
[127] Fix | Delete
def replaceChild(self, newChild, oldChild):
[128] Fix | Delete
if newChild.nodeType == self.DOCUMENT_FRAGMENT_NODE:
[129] Fix | Delete
refChild = oldChild.nextSibling
[130] Fix | Delete
self.removeChild(oldChild)
[131] Fix | Delete
return self.insertBefore(newChild, refChild)
[132] Fix | Delete
if newChild.nodeType not in self._child_node_types:
[133] Fix | Delete
raise xml.dom.HierarchyRequestErr(
[134] Fix | Delete
"%s cannot be child of %s" % (repr(newChild), repr(self)))
[135] Fix | Delete
if newChild is oldChild:
[136] Fix | Delete
return
[137] Fix | Delete
if newChild.parentNode is not None:
[138] Fix | Delete
newChild.parentNode.removeChild(newChild)
[139] Fix | Delete
try:
[140] Fix | Delete
index = self.childNodes.index(oldChild)
[141] Fix | Delete
except ValueError:
[142] Fix | Delete
raise xml.dom.NotFoundErr()
[143] Fix | Delete
self.childNodes[index] = newChild
[144] Fix | Delete
newChild.parentNode = self
[145] Fix | Delete
oldChild.parentNode = None
[146] Fix | Delete
if (newChild.nodeType in _nodeTypes_with_children
[147] Fix | Delete
or oldChild.nodeType in _nodeTypes_with_children):
[148] Fix | Delete
_clear_id_cache(self)
[149] Fix | Delete
newChild.nextSibling = oldChild.nextSibling
[150] Fix | Delete
newChild.previousSibling = oldChild.previousSibling
[151] Fix | Delete
oldChild.nextSibling = None
[152] Fix | Delete
oldChild.previousSibling = None
[153] Fix | Delete
if newChild.previousSibling:
[154] Fix | Delete
newChild.previousSibling.nextSibling = newChild
[155] Fix | Delete
if newChild.nextSibling:
[156] Fix | Delete
newChild.nextSibling.previousSibling = newChild
[157] Fix | Delete
return oldChild
[158] Fix | Delete
[159] Fix | Delete
def removeChild(self, oldChild):
[160] Fix | Delete
try:
[161] Fix | Delete
self.childNodes.remove(oldChild)
[162] Fix | Delete
except ValueError:
[163] Fix | Delete
raise xml.dom.NotFoundErr()
[164] Fix | Delete
if oldChild.nextSibling is not None:
[165] Fix | Delete
oldChild.nextSibling.previousSibling = oldChild.previousSibling
[166] Fix | Delete
if oldChild.previousSibling is not None:
[167] Fix | Delete
oldChild.previousSibling.nextSibling = oldChild.nextSibling
[168] Fix | Delete
oldChild.nextSibling = oldChild.previousSibling = None
[169] Fix | Delete
if oldChild.nodeType in _nodeTypes_with_children:
[170] Fix | Delete
_clear_id_cache(self)
[171] Fix | Delete
[172] Fix | Delete
oldChild.parentNode = None
[173] Fix | Delete
return oldChild
[174] Fix | Delete
[175] Fix | Delete
def normalize(self):
[176] Fix | Delete
L = []
[177] Fix | Delete
for child in self.childNodes:
[178] Fix | Delete
if child.nodeType == Node.TEXT_NODE:
[179] Fix | Delete
if not child.data:
[180] Fix | Delete
# empty text node; discard
[181] Fix | Delete
if L:
[182] Fix | Delete
L[-1].nextSibling = child.nextSibling
[183] Fix | Delete
if child.nextSibling:
[184] Fix | Delete
child.nextSibling.previousSibling = child.previousSibling
[185] Fix | Delete
child.unlink()
[186] Fix | Delete
elif L and L[-1].nodeType == child.nodeType:
[187] Fix | Delete
# collapse text node
[188] Fix | Delete
node = L[-1]
[189] Fix | Delete
node.data = node.data + child.data
[190] Fix | Delete
node.nextSibling = child.nextSibling
[191] Fix | Delete
if child.nextSibling:
[192] Fix | Delete
child.nextSibling.previousSibling = node
[193] Fix | Delete
child.unlink()
[194] Fix | Delete
else:
[195] Fix | Delete
L.append(child)
[196] Fix | Delete
else:
[197] Fix | Delete
L.append(child)
[198] Fix | Delete
if child.nodeType == Node.ELEMENT_NODE:
[199] Fix | Delete
child.normalize()
[200] Fix | Delete
self.childNodes[:] = L
[201] Fix | Delete
[202] Fix | Delete
def cloneNode(self, deep):
[203] Fix | Delete
return _clone_node(self, deep, self.ownerDocument or self)
[204] Fix | Delete
[205] Fix | Delete
def isSupported(self, feature, version):
[206] Fix | Delete
return self.ownerDocument.implementation.hasFeature(feature, version)
[207] Fix | Delete
[208] Fix | Delete
def _get_localName(self):
[209] Fix | Delete
# Overridden in Element and Attr where localName can be Non-Null
[210] Fix | Delete
return None
[211] Fix | Delete
[212] Fix | Delete
# Node interfaces from Level 3 (WD 9 April 2002)
[213] Fix | Delete
[214] Fix | Delete
def isSameNode(self, other):
[215] Fix | Delete
return self is other
[216] Fix | Delete
[217] Fix | Delete
def getInterface(self, feature):
[218] Fix | Delete
if self.isSupported(feature, None):
[219] Fix | Delete
return self
[220] Fix | Delete
else:
[221] Fix | Delete
return None
[222] Fix | Delete
[223] Fix | Delete
# The "user data" functions use a dictionary that is only present
[224] Fix | Delete
# if some user data has been set, so be careful not to assume it
[225] Fix | Delete
# exists.
[226] Fix | Delete
[227] Fix | Delete
def getUserData(self, key):
[228] Fix | Delete
try:
[229] Fix | Delete
return self._user_data[key][0]
[230] Fix | Delete
except (AttributeError, KeyError):
[231] Fix | Delete
return None
[232] Fix | Delete
[233] Fix | Delete
def setUserData(self, key, data, handler):
[234] Fix | Delete
old = None
[235] Fix | Delete
try:
[236] Fix | Delete
d = self._user_data
[237] Fix | Delete
except AttributeError:
[238] Fix | Delete
d = {}
[239] Fix | Delete
self._user_data = d
[240] Fix | Delete
if key in d:
[241] Fix | Delete
old = d[key][0]
[242] Fix | Delete
if data is None:
[243] Fix | Delete
# ignore handlers passed for None
[244] Fix | Delete
handler = None
[245] Fix | Delete
if old is not None:
[246] Fix | Delete
del d[key]
[247] Fix | Delete
else:
[248] Fix | Delete
d[key] = (data, handler)
[249] Fix | Delete
return old
[250] Fix | Delete
[251] Fix | Delete
def _call_user_data_handler(self, operation, src, dst):
[252] Fix | Delete
if hasattr(self, "_user_data"):
[253] Fix | Delete
for key, (data, handler) in self._user_data.items():
[254] Fix | Delete
if handler is not None:
[255] Fix | Delete
handler.handle(operation, key, data, src, dst)
[256] Fix | Delete
[257] Fix | Delete
# minidom-specific API:
[258] Fix | Delete
[259] Fix | Delete
def unlink(self):
[260] Fix | Delete
self.parentNode = self.ownerDocument = None
[261] Fix | Delete
if self.childNodes:
[262] Fix | Delete
for child in self.childNodes:
[263] Fix | Delete
child.unlink()
[264] Fix | Delete
self.childNodes = NodeList()
[265] Fix | Delete
self.previousSibling = None
[266] Fix | Delete
self.nextSibling = None
[267] Fix | Delete
[268] Fix | Delete
defproperty(Node, "firstChild", doc="First child node, or None.")
[269] Fix | Delete
defproperty(Node, "lastChild", doc="Last child node, or None.")
[270] Fix | Delete
defproperty(Node, "localName", doc="Namespace-local name of this node.")
[271] Fix | Delete
[272] Fix | Delete
[273] Fix | Delete
def _append_child(self, node):
[274] Fix | Delete
# fast path with less checks; usable by DOM builders if careful
[275] Fix | Delete
childNodes = self.childNodes
[276] Fix | Delete
if childNodes:
[277] Fix | Delete
last = childNodes[-1]
[278] Fix | Delete
node.__dict__["previousSibling"] = last
[279] Fix | Delete
last.__dict__["nextSibling"] = node
[280] Fix | Delete
childNodes.append(node)
[281] Fix | Delete
node.__dict__["parentNode"] = self
[282] Fix | Delete
[283] Fix | Delete
def _in_document(node):
[284] Fix | Delete
# return True iff node is part of a document tree
[285] Fix | Delete
while node is not None:
[286] Fix | Delete
if node.nodeType == Node.DOCUMENT_NODE:
[287] Fix | Delete
return True
[288] Fix | Delete
node = node.parentNode
[289] Fix | Delete
return False
[290] Fix | Delete
[291] Fix | Delete
def _write_data(writer, data):
[292] Fix | Delete
"Writes datachars to writer."
[293] Fix | Delete
if data:
[294] Fix | Delete
data = data.replace("&", "&amp;").replace("<", "&lt;"). \
[295] Fix | Delete
replace("\"", "&quot;").replace(">", "&gt;")
[296] Fix | Delete
writer.write(data)
[297] Fix | Delete
[298] Fix | Delete
def _get_elements_by_tagName_helper(parent, name, rc):
[299] Fix | Delete
for node in parent.childNodes:
[300] Fix | Delete
if node.nodeType == Node.ELEMENT_NODE and \
[301] Fix | Delete
(name == "*" or node.tagName == name):
[302] Fix | Delete
rc.append(node)
[303] Fix | Delete
_get_elements_by_tagName_helper(node, name, rc)
[304] Fix | Delete
return rc
[305] Fix | Delete
[306] Fix | Delete
def _get_elements_by_tagName_ns_helper(parent, nsURI, localName, rc):
[307] Fix | Delete
for node in parent.childNodes:
[308] Fix | Delete
if node.nodeType == Node.ELEMENT_NODE:
[309] Fix | Delete
if ((localName == "*" or node.localName == localName) and
[310] Fix | Delete
(nsURI == "*" or node.namespaceURI == nsURI)):
[311] Fix | Delete
rc.append(node)
[312] Fix | Delete
_get_elements_by_tagName_ns_helper(node, nsURI, localName, rc)
[313] Fix | Delete
return rc
[314] Fix | Delete
[315] Fix | Delete
class DocumentFragment(Node):
[316] Fix | Delete
nodeType = Node.DOCUMENT_FRAGMENT_NODE
[317] Fix | Delete
nodeName = "#document-fragment"
[318] Fix | Delete
nodeValue = None
[319] Fix | Delete
attributes = None
[320] Fix | Delete
parentNode = None
[321] Fix | Delete
_child_node_types = (Node.ELEMENT_NODE,
[322] Fix | Delete
Node.TEXT_NODE,
[323] Fix | Delete
Node.CDATA_SECTION_NODE,
[324] Fix | Delete
Node.ENTITY_REFERENCE_NODE,
[325] Fix | Delete
Node.PROCESSING_INSTRUCTION_NODE,
[326] Fix | Delete
Node.COMMENT_NODE,
[327] Fix | Delete
Node.NOTATION_NODE)
[328] Fix | Delete
[329] Fix | Delete
def __init__(self):
[330] Fix | Delete
self.childNodes = NodeList()
[331] Fix | Delete
[332] Fix | Delete
[333] Fix | Delete
class Attr(Node):
[334] Fix | Delete
nodeType = Node.ATTRIBUTE_NODE
[335] Fix | Delete
attributes = None
[336] Fix | Delete
ownerElement = None
[337] Fix | Delete
specified = False
[338] Fix | Delete
_is_id = False
[339] Fix | Delete
[340] Fix | Delete
_child_node_types = (Node.TEXT_NODE, Node.ENTITY_REFERENCE_NODE)
[341] Fix | Delete
[342] Fix | Delete
def __init__(self, qName, namespaceURI=EMPTY_NAMESPACE, localName=None,
[343] Fix | Delete
prefix=None):
[344] Fix | Delete
# skip setattr for performance
[345] Fix | Delete
d = self.__dict__
[346] Fix | Delete
d["nodeName"] = d["name"] = qName
[347] Fix | Delete
d["namespaceURI"] = namespaceURI
[348] Fix | Delete
d["prefix"] = prefix
[349] Fix | Delete
d['childNodes'] = NodeList()
[350] Fix | Delete
[351] Fix | Delete
# Add the single child node that represents the value of the attr
[352] Fix | Delete
self.childNodes.append(Text())
[353] Fix | Delete
[354] Fix | Delete
# nodeValue and value are set elsewhere
[355] Fix | Delete
[356] Fix | Delete
def _get_localName(self):
[357] Fix | Delete
return self.nodeName.split(":", 1)[-1]
[358] Fix | Delete
[359] Fix | Delete
def _get_specified(self):
[360] Fix | Delete
return self.specified
[361] Fix | Delete
[362] Fix | Delete
def __setattr__(self, name, value):
[363] Fix | Delete
d = self.__dict__
[364] Fix | Delete
if name in ("value", "nodeValue"):
[365] Fix | Delete
d["value"] = d["nodeValue"] = value
[366] Fix | Delete
d2 = self.childNodes[0].__dict__
[367] Fix | Delete
d2["data"] = d2["nodeValue"] = value
[368] Fix | Delete
if self.ownerElement is not None:
[369] Fix | Delete
_clear_id_cache(self.ownerElement)
[370] Fix | Delete
elif name in ("name", "nodeName"):
[371] Fix | Delete
d["name"] = d["nodeName"] = value
[372] Fix | Delete
if self.ownerElement is not None:
[373] Fix | Delete
_clear_id_cache(self.ownerElement)
[374] Fix | Delete
else:
[375] Fix | Delete
d[name] = value
[376] Fix | Delete
[377] Fix | Delete
def _set_prefix(self, prefix):
[378] Fix | Delete
nsuri = self.namespaceURI
[379] Fix | Delete
if prefix == "xmlns":
[380] Fix | Delete
if nsuri and nsuri != XMLNS_NAMESPACE:
[381] Fix | Delete
raise xml.dom.NamespaceErr(
[382] Fix | Delete
"illegal use of 'xmlns' prefix for the wrong namespace")
[383] Fix | Delete
d = self.__dict__
[384] Fix | Delete
d['prefix'] = prefix
[385] Fix | Delete
if prefix is None:
[386] Fix | Delete
newName = self.localName
[387] Fix | Delete
else:
[388] Fix | Delete
newName = "%s:%s" % (prefix, self.localName)
[389] Fix | Delete
if self.ownerElement:
[390] Fix | Delete
_clear_id_cache(self.ownerElement)
[391] Fix | Delete
d['nodeName'] = d['name'] = newName
[392] Fix | Delete
[393] Fix | Delete
def _set_value(self, value):
[394] Fix | Delete
d = self.__dict__
[395] Fix | Delete
d['value'] = d['nodeValue'] = value
[396] Fix | Delete
if self.ownerElement:
[397] Fix | Delete
_clear_id_cache(self.ownerElement)
[398] Fix | Delete
self.childNodes[0].data = value
[399] Fix | Delete
[400] Fix | Delete
def unlink(self):
[401] Fix | Delete
# This implementation does not call the base implementation
[402] Fix | Delete
# since most of that is not needed, and the expense of the
[403] Fix | Delete
# method call is not warranted. We duplicate the removal of
[404] Fix | Delete
# children, but that's all we needed from the base class.
[405] Fix | Delete
elem = self.ownerElement
[406] Fix | Delete
if elem is not None:
[407] Fix | Delete
del elem._attrs[self.nodeName]
[408] Fix | Delete
del elem._attrsNS[(self.namespaceURI, self.localName)]
[409] Fix | Delete
if self._is_id:
[410] Fix | Delete
self._is_id = False
[411] Fix | Delete
elem._magic_id_nodes -= 1
[412] Fix | Delete
self.ownerDocument._magic_id_count -= 1
[413] Fix | Delete
for child in self.childNodes:
[414] Fix | Delete
child.unlink()
[415] Fix | Delete
del self.childNodes[:]
[416] Fix | Delete
[417] Fix | Delete
def _get_isId(self):
[418] Fix | Delete
if self._is_id:
[419] Fix | Delete
return True
[420] Fix | Delete
doc = self.ownerDocument
[421] Fix | Delete
elem = self.ownerElement
[422] Fix | Delete
if doc is None or elem is None:
[423] Fix | Delete
return False
[424] Fix | Delete
[425] Fix | Delete
info = doc._get_elem_info(elem)
[426] Fix | Delete
if info is None:
[427] Fix | Delete
return False
[428] Fix | Delete
if self.namespaceURI:
[429] Fix | Delete
return info.isIdNS(self.namespaceURI, self.localName)
[430] Fix | Delete
else:
[431] Fix | Delete
return info.isId(self.nodeName)
[432] Fix | Delete
[433] Fix | Delete
def _get_schemaType(self):
[434] Fix | Delete
doc = self.ownerDocument
[435] Fix | Delete
elem = self.ownerElement
[436] Fix | Delete
if doc is None or elem is None:
[437] Fix | Delete
return _no_type
[438] Fix | Delete
[439] Fix | Delete
info = doc._get_elem_info(elem)
[440] Fix | Delete
if info is None:
[441] Fix | Delete
return _no_type
[442] Fix | Delete
if self.namespaceURI:
[443] Fix | Delete
return info.getAttributeTypeNS(self.namespaceURI, self.localName)
[444] Fix | Delete
else:
[445] Fix | Delete
return info.getAttributeType(self.nodeName)
[446] Fix | Delete
[447] Fix | Delete
defproperty(Attr, "isId", doc="True if this attribute is an ID.")
[448] Fix | Delete
defproperty(Attr, "localName", doc="Namespace-local name of this attribute.")
[449] Fix | Delete
defproperty(Attr, "schemaType", doc="Schema type for this attribute.")
[450] Fix | Delete
[451] Fix | Delete
[452] Fix | Delete
class NamedNodeMap(object):
[453] Fix | Delete
"""The attribute list is a transient interface to the underlying
[454] Fix | Delete
dictionaries. Mutations here will change the underlying element's
[455] Fix | Delete
dictionary.
[456] Fix | Delete
[457] Fix | Delete
Ordering is imposed artificially and does not reflect the order of
[458] Fix | Delete
attributes as found in an input document.
[459] Fix | Delete
"""
[460] Fix | Delete
[461] Fix | Delete
__slots__ = ('_attrs', '_attrsNS', '_ownerElement')
[462] Fix | Delete
[463] Fix | Delete
def __init__(self, attrs, attrsNS, ownerElement):
[464] Fix | Delete
self._attrs = attrs
[465] Fix | Delete
self._attrsNS = attrsNS
[466] Fix | Delete
self._ownerElement = ownerElement
[467] Fix | Delete
[468] Fix | Delete
def _get_length(self):
[469] Fix | Delete
return len(self._attrs)
[470] Fix | Delete
[471] Fix | Delete
def item(self, index):
[472] Fix | Delete
try:
[473] Fix | Delete
return self[self._attrs.keys()[index]]
[474] Fix | Delete
except IndexError:
[475] Fix | Delete
return None
[476] Fix | Delete
[477] Fix | Delete
def items(self):
[478] Fix | Delete
L = []
[479] Fix | Delete
for node in self._attrs.values():
[480] Fix | Delete
L.append((node.nodeName, node.value))
[481] Fix | Delete
return L
[482] Fix | Delete
[483] Fix | Delete
def itemsNS(self):
[484] Fix | Delete
L = []
[485] Fix | Delete
for node in self._attrs.values():
[486] Fix | Delete
L.append(((node.namespaceURI, node.localName), node.value))
[487] Fix | Delete
return L
[488] Fix | Delete
[489] Fix | Delete
def has_key(self, key):
[490] Fix | Delete
if isinstance(key, StringTypes):
[491] Fix | Delete
return key in self._attrs
[492] Fix | Delete
else:
[493] Fix | Delete
return key in self._attrsNS
[494] Fix | Delete
[495] Fix | Delete
def keys(self):
[496] Fix | Delete
return self._attrs.keys()
[497] Fix | Delete
[498] Fix | Delete
def keysNS(self):
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function