[Zope3-checkins] CVS: Products3/xmldom - core.py:1.6
Steve Alexander
steve@cat-box.net
Sat, 14 Jun 2003 08:59:18 -0400
Update of /cvs-repository/Products3/xmldom
In directory cvs.zope.org:/tmp/cvs-serv17097
Modified Files:
core.py
Log Message:
Converted ContextAware base classes into ContextAwareDescriptors() class
advice.
=== Products3/xmldom/core.py 1.5 => 1.6 ===
--- Products3/xmldom/core.py:1.5 Sat Jun 7 14:52:59 2003
+++ Products3/xmldom/core.py Sat Jun 14 08:59:18 2003
@@ -17,8 +17,9 @@
import string
import xml.dom
-from zope.context import ContextAware, ContextProperty, getWrapperContext,\
- getWrapperContainer, getbaseobject, ContainmentIterator
+from zope.context import ContextProperty, ContainmentIterator
+from zope.context import ContextAwareDescriptors
+from zope.context import getWrapperContext, getWrapperContainer, getbaseobject
from zope.context.wrapper import setcontext
from zope.app.context import ContextWrapper
@@ -113,14 +114,14 @@
class DOMProperty(ContextProperty):
_readonly = 0
-
+
def __init__(self, getter, setter=None):
if setter is not None:
super(DOMProperty, self).__init__(getter, setter)
else:
self._readonly = 1
super(DOMProperty, self).__init__(getter)
-
+
def __set__(self, inst, value):
readonly = getattr(inst, '_readonly', False)
if readonly:
@@ -132,12 +133,14 @@
raise xml.dom.NoModificationAllowedErr(
"read-only attribute")
super(DOMProperty, self).__set__(inst, value)
-
+
class _Dummy:
pass
-class DOMImplementation(ContextAware):
+class DOMImplementation:
+ ContextAwareDescriptors()
+
def hasFeature(self, feature, version):
feature = (feature.lower(), version)
return feature in _SUPPORTED_FEATURES
@@ -166,7 +169,9 @@
theDOMImplementation = DOMImplementation()
-class Node(ContextAware):
+class Node:
+ ContextAwareDescriptors()
+
ELEMENT_NODE = 1
ATTRIBUTE_NODE = 2
TEXT_NODE = 3
@@ -717,7 +722,7 @@
node = node.parentNode
-class Parentless(ContextAware):
+class Parentless:
"""Node mixin that doesn't have a parent node."""
def _get_parentNode(self):
@@ -736,13 +741,14 @@
return [None, None]
-class Childless(ContextAware):
+class Childless:
"""Node mixin that doesn't allow child nodes.
This ensures safety when used as a base class for node types that
should never have children of their own, and allows slightly
faster response for some methods.
"""
+ ContextAwareDescriptors()
_allowed_child_types = ()
@@ -774,11 +780,12 @@
return
-class TextualContent(ContextAware):
+class TextualContent:
"""Mixin class defining the recursive support for textContent
needed for some types of container nodes.
"""
# DOM Level 3 (working draft, 5 June 2001)
+ ContextAwareDescriptors()
def _get_textContent(self):
L = []
@@ -798,7 +805,9 @@
return ''
textContent = DOMProperty(_get_textContent)
-class Document(ContextAware, Parentless, TextualContent, Node):
+class Document(Parentless, TextualContent, Node):
+ ContextAwareDescriptors()
+
_nodeName = "#document"
_nodeType = Node.DOCUMENT_NODE
@@ -1152,7 +1161,8 @@
nsURI, localName, list)
-class DocumentFragment(ContextAware, Parentless, TextualContent, Node):
+class DocumentFragment(Parentless, TextualContent, Node):
+ ContextAwareDescriptors()
_nodeName = "#document-fragment"
_nodeType = Node.DOCUMENT_FRAGMENT_NODE
_parentNode = None
@@ -1202,7 +1212,8 @@
# Element _attribute members can be shared with Attr nodes; see comment
# at the Attr class.
-class Element(ContextAware, TextualContent, Node):
+class Element(TextualContent, Node):
+ ContextAwareDescriptors()
_nodeType = Node.ELEMENT_NODE
_allowed_child_types = (Node.ELEMENT_NODE,
@@ -1537,7 +1548,7 @@
return oldAttr
-class ChildNodeList(ContextAware):
+class ChildNodeList:
"""NodeList implementation that provides the children of a single node.
This is returned by Node.childNodes and Node._get_childNodes().
@@ -1545,6 +1556,8 @@
the document contents.
"""
+ ContextAwareDescriptors()
+
def __init__(self, parent):
self._parent = parent
@@ -1605,7 +1618,7 @@
raise ValueError, "NodeList.index(x): x not in sequence"
-class SimpleNodeList(ContextAware):
+class SimpleNodeList:
"""NodeList implementation that contains pre-wrapped nodes.
This is returned by the getElementsByTagName() and
@@ -1613,6 +1626,8 @@
It cannot be used to mutate the document contents.
"""
+ ContextAwareDescriptors()
+
def __init__(self, list=None):
if list is None:
list = []
@@ -1682,7 +1697,9 @@
raise ValueError, "NodeList.index(x): x not in sequence"
-class CharacterData(ContextAware, Childless, Node):
+class CharacterData(Childless, Node):
+ ContextAwareDescriptors()
+
def __init__(self, data):
self._in_tree = 0
self._data = data
@@ -1760,7 +1777,9 @@
textContent = DOMProperty(_get_textContent)
-class Text(ContextAware, CharacterData):
+class Text(CharacterData):
+ ContextAwareDescriptors()
+
_nodeName = "#text"
_nodeType = Node.TEXT_NODE
@@ -1794,7 +1813,9 @@
return self.isWhitespaceInElementContent
-class Comment(ContextAware, CharacterData):
+class Comment(CharacterData):
+ ContextAwareDescriptors()
+
_nodeName = "#comment"
_nodeType = Node.COMMENT_NODE
@@ -1810,7 +1831,9 @@
# list with a single text node, the attr node shares this reference. Similarly
# for setAttributeNode. We could stay with the string in many cases at the
# cost of complexity.
-class Attr(ContextAware, Parentless, Node):
+class Attr(Parentless, Node):
+ ContextAwareDescriptors()
+
_nodeType = Node.ATTRIBUTE_NODE
_in_tree = 0
@@ -1961,14 +1984,16 @@
and self._item is other._item)
-class MapFromParent(ContextAware):
+class MapFromParent:
"""
Baseclass for a NamedNodeMap that works by extracting information
from a parent.
Must be subclassed to determine what we're looking for and returning.
"""
+ ContextAwareDescriptors()
+
_readonly = 0
-
+
def __init__(self, parent):
self._parent = parent
# subclass must set _parentListName
@@ -2111,11 +2136,12 @@
-class AttributeMap(ContextAware, MapFromParent):
+class AttributeMap(MapFromParent):
"""NamedNodeMap that works on the attribute structure.
This doesn't do anything about the namespace declarations.
"""
+ ContextAwareDescriptors()
_parentListName = '_attributes'