[Python-checkins] cpython: xml.dom.minidom: add more __slots__ to limit resource usage.
florent.xicluna
python-checkins at python.org
Mon Mar 5 12:37:38 CET 2012
http://hg.python.org/cpython/rev/49c5511b234a
changeset: 75418:49c5511b234a
user: Florent Xicluna <florent.xicluna at gmail.com>
date: Mon Mar 05 12:37:02 2012 +0100
summary:
xml.dom.minidom: add more __slots__ to limit resource usage.
files:
Lib/xml/dom/__init__.py | 1 +
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
--- a/Lib/xml/dom/__init__.py
+++ b/Lib/xml/dom/__init__.py
@@ -17,6 +17,7 @@
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
--- a/Lib/xml/dom/minidom.py
+++ b/Lib/xml/dom/minidom.py
@@ -62,10 +62,7 @@
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 @@
"""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 @@
class Text(CharacterData):
+ __slots__ = ()
+
nodeType = Node.TEXT_NODE
nodeName = "#text"
attributes = None
@@ -1188,6 +1188,8 @@
class CDATASection(Text):
+ __slots__ = ()
+
nodeType = Node.CDATA_SECTION_NODE
nodeName = "#cdata-section"
@@ -1266,8 +1268,7 @@
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
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list