Skip to content

Commit 8cf4b51

Browse files
committed
xml.dom.minidom: add more __slots__ to limit resource usage.
1 parent 6c75301 commit 8cf4b51

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

Diff for: Lib/xml/dom/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
class Node:
1919
"""Class giving the NodeType constants."""
20+
__slots__ = ()
2021

2122
# DOM implementations may use this as a base class for their own
2223
# Node implementations. If they don't, the constants defined here

Diff for: Lib/xml/dom/minidom.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ def toprettyxml(self, indent="\t", newl="\n", encoding=None):
6262
return writer.stream.getvalue()
6363

6464
def hasChildNodes(self):
65-
if self.childNodes:
66-
return True
67-
else:
68-
return False
65+
return bool(self.childNodes)
6966

7067
def _get_childNodes(self):
7168
return self.childNodes
@@ -930,6 +927,7 @@ class Childless:
930927
"""Mixin that makes childless-ness easy to implement and avoids
931928
the complexity of the Node methods that deal with children.
932929
"""
930+
__slots__ = ()
933931

934932
attributes = None
935933
childNodes = EmptyNodeList()
@@ -1067,6 +1065,8 @@ def replaceData(self, offset, count, arg):
10671065

10681066

10691067
class Text(CharacterData):
1068+
__slots__ = ()
1069+
10701070
nodeType = Node.TEXT_NODE
10711071
nodeName = "#text"
10721072
attributes = None
@@ -1188,6 +1188,8 @@ def writexml(self, writer, indent="", addindent="", newl=""):
11881188

11891189

11901190
class CDATASection(Text):
1191+
__slots__ = ()
1192+
11911193
nodeType = Node.CDATA_SECTION_NODE
11921194
nodeName = "#cdata-section"
11931195

@@ -1266,8 +1268,7 @@ def __setstate__(self, state):
12661268
class Identified:
12671269
"""Mix-in class that supports the publicId and systemId attributes."""
12681270

1269-
# XXX this does not work, this is an old-style class
1270-
# __slots__ = 'publicId', 'systemId'
1271+
__slots__ = 'publicId', 'systemId'
12711272

12721273
def _identified_mixin_init(self, publicId, systemId):
12731274
self.publicId = publicId

0 commit comments

Comments
 (0)