Kaydet (Commit) 14aa280d authored tarafından Martin v. Löwis's avatar Martin v. Löwis

Use __slots__ throughout instead of __dict__, to reduce the memory usage.

üst 32ac92cd
...@@ -283,27 +283,23 @@ class ExpatBuilder: ...@@ -283,27 +283,23 @@ class ExpatBuilder:
elif childNodes and childNodes[-1].nodeType == TEXT_NODE: elif childNodes and childNodes[-1].nodeType == TEXT_NODE:
node = childNodes[-1] node = childNodes[-1]
value = node.data + data value = node.data + data
d = node.__dict__ node.data = value
d['data'] = d['nodeValue'] = value
return return
else: else:
node = minidom.Text() node = minidom.Text()
d = node.__dict__ node.data = data
d['data'] = d['nodeValue'] = data node.ownerDocument = self.document
d['ownerDocument'] = self.document
_append_child(self.curNode, node) _append_child(self.curNode, node)
def character_data_handler(self, data): def character_data_handler(self, data):
childNodes = self.curNode.childNodes childNodes = self.curNode.childNodes
if childNodes and childNodes[-1].nodeType == TEXT_NODE: if childNodes and childNodes[-1].nodeType == TEXT_NODE:
node = childNodes[-1] node = childNodes[-1]
d = node.__dict__ node.data = node.data + data
d['data'] = d['nodeValue'] = node.data + data
return return
node = minidom.Text() node = minidom.Text()
d = node.__dict__ node.data = node.data + data
d['data'] = d['nodeValue'] = node.data + data node.ownerDocument = self.document
d['ownerDocument'] = self.document
_append_child(self.curNode, node) _append_child(self.curNode, node)
def entity_decl_handler(self, entityName, is_parameter_entity, value, def entity_decl_handler(self, entityName, is_parameter_entity, value,
...@@ -363,11 +359,8 @@ class ExpatBuilder: ...@@ -363,11 +359,8 @@ class ExpatBuilder:
a = minidom.Attr(attributes[i], EMPTY_NAMESPACE, a = minidom.Attr(attributes[i], EMPTY_NAMESPACE,
None, EMPTY_PREFIX) None, EMPTY_PREFIX)
value = attributes[i+1] value = attributes[i+1]
d = a.childNodes[0].__dict__ a.value = value
d['data'] = d['nodeValue'] = value a.ownerDocument = self.document
d = a.__dict__
d['value'] = d['nodeValue'] = value
d['ownerDocument'] = self.document
_set_attribute_node(node, a) _set_attribute_node(node, a)
if node is not self.document.documentElement: if node is not self.document.documentElement:
...@@ -761,11 +754,8 @@ class Namespaces: ...@@ -761,11 +754,8 @@ class Namespaces:
else: else:
a = minidom.Attr("xmlns", XMLNS_NAMESPACE, a = minidom.Attr("xmlns", XMLNS_NAMESPACE,
"xmlns", EMPTY_PREFIX) "xmlns", EMPTY_PREFIX)
d = a.childNodes[0].__dict__ a.value = uri
d['data'] = d['nodeValue'] = uri a.ownerDocuemnt = self.document
d = a.__dict__
d['value'] = d['nodeValue'] = uri
d['ownerDocument'] = self.document
_set_attribute_node(node, a) _set_attribute_node(node, a)
del self._ns_ordered_prefixes[:] del self._ns_ordered_prefixes[:]
...@@ -785,12 +775,9 @@ class Namespaces: ...@@ -785,12 +775,9 @@ class Namespaces:
aname, EMPTY_PREFIX) aname, EMPTY_PREFIX)
_attrs[aname] = a _attrs[aname] = a
_attrsNS[(EMPTY_NAMESPACE, aname)] = a _attrsNS[(EMPTY_NAMESPACE, aname)] = a
d = a.childNodes[0].__dict__ a.ownerDocument = self.document
d['data'] = d['nodeValue'] = value a.value = value
d = a.__dict__ a.ownerElement = node
d['ownerDocument'] = self.document
d['value'] = d['nodeValue'] = value
d['ownerElement'] = node
if __debug__: if __debug__:
# This only adds some asserts to the original # This only adds some asserts to the original
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment