diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2012-03-05 11:37:02 (GMT) |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2012-03-05 11:37:02 (GMT) |
commit | 8cf4b51fa4954393450f02cb38a5e60847eab8e5 (patch) | |
tree | 77d0865d17f9a2eec34df91d7129236396bc08a5 /Lib | |
parent | 6c75301eb6892170dcbea634b3be5cfa179c3d2e (diff) | |
download | cpython-8cf4b51fa4954393450f02cb38a5e60847eab8e5.zip cpython-8cf4b51fa4954393450f02cb38a5e60847eab8e5.tar.gz cpython-8cf4b51fa4954393450f02cb38a5e60847eab8e5.tar.bz2 |
xml.dom.minidom: add more __slots__ to limit resource usage.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/xml/dom/__init__.py | 1 | ||||
-rw-r--r-- | Lib/xml/dom/minidom.py | 13 |
2 files changed, 8 insertions, 6 deletions
diff --git a/Lib/xml/dom/__init__.py b/Lib/xml/dom/__init__.py index 4401bdf..97cf9a6 100644 --- a/Lib/xml/dom/__init__.py +++ b/Lib/xml/dom/__init__.py @@ -17,6 +17,7 @@ pulldom -- DOM builder supporting on-demand tree-building for selected class Node: """Class giving the NodeType constants.""" + __slots__ = () # DOM implementations may use this as a base class for their own # Node implementations. If they don't, the constants defined here diff --git a/Lib/xml/dom/minidom.py b/Lib/xml/dom/minidom.py index 3de8a4d..275e20c 100644 --- a/Lib/xml/dom/minidom.py +++ b/Lib/xml/dom/minidom.py @@ -62,10 +62,7 @@ class Node(xml.dom.Node): return writer.stream.getvalue() def hasChildNodes(self): - if self.childNodes: - return True - else: - return False + return bool(self.childNodes) def _get_childNodes(self): return self.childNodes @@ -930,6 +927,7 @@ class Childless: """Mixin that makes childless-ness easy to implement and avoids the complexity of the Node methods that deal with children. """ + __slots__ = () attributes = None childNodes = EmptyNodeList() @@ -1067,6 +1065,8 @@ defproperty(CharacterData, "length", doc="Length of the string data.") class Text(CharacterData): + __slots__ = () + nodeType = Node.TEXT_NODE nodeName = "#text" attributes = None @@ -1188,6 +1188,8 @@ class Comment(CharacterData): class CDATASection(Text): + __slots__ = () + nodeType = Node.CDATA_SECTION_NODE nodeName = "#cdata-section" @@ -1266,8 +1268,7 @@ defproperty(ReadOnlySequentialNamedNodeMap, "length", class Identified: """Mix-in class that supports the publicId and systemId attributes.""" - # XXX this does not work, this is an old-style class - # __slots__ = 'publicId', 'systemId' + __slots__ = 'publicId', 'systemId' def _identified_mixin_init(self, publicId, systemId): self.publicId = publicId |