bpo-13743: Add some documentation strings to xml.dom.minidom (GH-16355)

This commit is contained in:
Alex Itkes 2020-04-12 17:21:58 +03:00 committed by GitHub
parent 5fd8123dfd
commit 63e5b59c06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -719,6 +719,14 @@ def unlink(self):
Node.unlink(self) Node.unlink(self)
def getAttribute(self, attname): def getAttribute(self, attname):
"""Returns the value of the specified attribute.
Returns the value of the element's attribute named attname as
a string. An empty string is returned if the element does not
have such an attribute. Note that an empty string may also be
returned as an explicitly given attribute value, use the
hasAttribute method to distinguish these two cases.
"""
if self._attrs is None: if self._attrs is None:
return "" return ""
try: try:
@ -829,6 +837,11 @@ def removeAttributeNode(self, node):
removeAttributeNodeNS = removeAttributeNode removeAttributeNodeNS = removeAttributeNode
def hasAttribute(self, name): def hasAttribute(self, name):
"""Checks whether the element has an attribute with the specified name.
Returns True if the element has an attribute with the specified name.
Otherwise, returns False.
"""
if self._attrs is None: if self._attrs is None:
return False return False
return name in self._attrs return name in self._attrs
@ -839,6 +852,11 @@ def hasAttributeNS(self, namespaceURI, localName):
return (namespaceURI, localName) in self._attrsNS return (namespaceURI, localName) in self._attrsNS
def getElementsByTagName(self, name): def getElementsByTagName(self, name):
"""Returns all descendant elements with the given tag name.
Returns the list of all descendant elements (not direct children
only) with the specified tag name.
"""
return _get_elements_by_tagName_helper(self, name, NodeList()) return _get_elements_by_tagName_helper(self, name, NodeList())
def getElementsByTagNameNS(self, namespaceURI, localName): def getElementsByTagNameNS(self, namespaceURI, localName):
@ -849,6 +867,11 @@ def __repr__(self):
return "<DOM Element: %s at %#x>" % (self.tagName, id(self)) return "<DOM Element: %s at %#x>" % (self.tagName, id(self))
def writexml(self, writer, indent="", addindent="", newl=""): def writexml(self, writer, indent="", addindent="", newl=""):
"""Write an XML element to a file-like object
Write the element to the writer object that must provide
a write method (e.g. a file or StringIO object).
"""
# indent = current indentation # indent = current indentation
# addindent = indentation to add to higher levels # addindent = indentation to add to higher levels
# newl = newline string # newl = newline string

View File

@ -0,0 +1 @@
Some methods within xml.dom.minidom.Element class are now better documented.