[Zope3-checkins] CVS: zopeproducts/xmldom - core.py:1.8 xmlextended.py:1.3

Philipp von Weitershausen philikon@philikon.de
Thu, 19 Jun 2003 16:43:43 -0400


Update of /cvs-repository/zopeproducts/xmldom
In directory cvs.zope.org:/tmp/cvs-serv7087

Modified Files:
	core.py xmlextended.py 
Log Message:
Use True and False instead of 1 and 0 where applicable, especially where
the DOM API promises boolean values.


=== zopeproducts/xmldom/core.py 1.7 => 1.8 ===
--- zopeproducts/xmldom/core.py:1.7	Thu Jun 19 14:56:20 2003
+++ zopeproducts/xmldom/core.py	Thu Jun 19 16:43:42 2003
@@ -53,7 +53,7 @@
                 raise xml.dom.NamespaceErr("malformed qualified name")
             if not uri:
                 raise xml.dom.NamespaceErr("no namespace URI for prefix")
-        return 1
+        return True
     else:
         raise xml.dom.InvalidCharacterErr()
 
@@ -118,13 +118,13 @@
 # then we avoid a level of indirection when used in a ContextAware class.
 class DOMProperty(ContextProperty):
 
-    _readonly = 0
+    _readonly = False
 
     def __init__(self, getter, setter=None):
         if setter is not None:
             super(DOMProperty, self).__init__(getter, setter)
         else:
-            self._readonly = 1
+            self._readonly = True
             super(DOMProperty, self).__init__(getter)
 
     def __set__(self, inst, value):
@@ -208,13 +208,13 @@
     TREE_POSITION_UNORDERED = 6
     
     _children = ()
-    _in_tree = 1
+    _in_tree = True
     _v_sibling_map = None
 
     _prefix = _localName = None
     _nodeValue = None
     _namespaceURI = None
-    _readonly = 0
+    _readonly = False
     
     def _check_if_ancestor(self, node):
         "Helper function that raises if node is self or an ancestor of self."
@@ -536,7 +536,7 @@
         else:
             raise xml.dom.NotFoundErr()
 
-        child._in_tree = 0
+        child._in_tree = False
         return oldChild
 
     def replaceChild(self, newChild, oldChild):
@@ -588,22 +588,22 @@
         but doesn't do all of the child list housekeeping.  Returns true
         if changes were made.
         Works for element child lists and attr child lists."""
-        changed = 0
+        changed = False
         i = 0
         L = []
         for child in children:
             if child.nodeType == Node.TEXT_NODE:
                 if child.data == "":
                     # drop this child
-                    child._in_tree = 0
-                    changed = 1
+                    child._in_tree = False
+                    changed = True
                 elif L and L[-1].nodeType == child.nodeType:
                     # merge this child with previous sibling
                     data = L[-1].data + child.data
                     d = L[-1]
                     d._data = d._nodeValue = data
-                    child.__in_tree = 0
-                    changed = 1
+                    child.__in_tree = False
+                    changed = True
                 else:
                     L.append(child)
             elif (child.nodeType == Node.ELEMENT_NODE
@@ -619,7 +619,7 @@
     def normalize(self):
         if self._readonly:
             raise xml.dom.NoModificationAllowedErr()
-        aChanged = 0
+        aChanged = False
         if hasattr(self, '_attributes'):
             attributes = self._attributes
             for attr in attributes:
@@ -630,7 +630,7 @@
                     child = attrVal[0]
                     if child.nodeType == Node.TEXT_NODE and not child.data:
                         del child
-                        aChanged = 1
+                        aChanged = True
                 else:
                     aChanged = self._mergeChildList(attrVal) or aChanged
         children = self._children
@@ -654,10 +654,10 @@
             self._changed()
 
     def hasAttributes(self):
-        return 0
+        return False
 
     def hasChildNodes(self):
-        return self._children and 1 or 0
+        return self._children and True or False
 
     def isSupported(self, feature, version):
         if self.ownerDocument:
@@ -668,9 +668,9 @@
 
     def cloneNode(self, deep):
         node = getbaseobject(self)
-        clone = node._cloneNode(deep and 1 or 0,
-                                mutable=1, document=self.ownerDocument)
-        clone._in_tree = 0
+        clone = node._cloneNode(deep and True or False,
+                                mutable=True, document=self.ownerDocument)
+        clone._in_tree = False
         clone = ContextWrapper(clone, self)
         return clone
 
@@ -781,7 +781,7 @@
         raise xml.dom.HierarchyRequestErr()
 
     def hasChildNodes(self):
-        return 0
+        return False
 
     def normalize(self):
         return
@@ -824,7 +824,7 @@
                             Node.PROCESSING_INSTRUCTION_NODE)
 
     _doctype = None
-    _in_tree = 0
+    _in_tree = False
     _implementation = theDOMImplementation
 
     def __init__(self, doctype, namespaceURI, qualifiedName):
@@ -881,7 +881,7 @@
     def _hasDocumentElement(self):
         for node in self._children:
             if node.nodeType == Node.ELEMENT_NODE:
-                return 1
+                return True
 
     def appendChild(self, newChild):
         if newChild.nodeType == Node.DOCUMENT_TYPE_NODE:
@@ -1069,8 +1069,9 @@
         if doc.implementation == self.implementation:
             # same implementation, so we're in good shape
             node = getbaseobject(importedNode)
-            clone = node._cloneNode(deep and 1 or 0, mutable=1, document=self)
-            clone._in_tree = 0
+            clone = node._cloneNode(deep and True or False, mutable=True,
+                                    document=self)
+            clone._in_tree = False
             clone = ContextWrapper(clone, self)
             if hasattr(clone, '_set_owner_document'):
                 clone._set_owner_document(self)
@@ -1097,8 +1098,8 @@
     # recommendation is finished.
     _actualEncoding = None
     _encoding = None
-    _standalone = 0
-    _strictErrorChecking = 0
+    _standalone = False
+    _strictErrorChecking = False
     _version = None
 
     # Override the inherited handler for textContent since the
@@ -1122,14 +1123,14 @@
     def _get_standalone(self):
         return self._standalone
     def _set_standalone(self, value):
-        self._standalone = value and 1 or 0
+        self._standalone = value and True or False
         self._changed()
     standalone = DOMProperty(_get_standalone, _set_standalone)
     
     def _get_strictErrorChecking(self):
         return self._strictErrorChecking
     def _set_strictErrorChecking(self, value):
-        self._strictErrorChecking = value and 1 or 0
+        self._strictErrorChecking = value and True or False
         self._changed()
     strictErrorChecking = DOMProperty(_get_strictErrorChecking, _set_strictErrorChecking)
     
@@ -1176,7 +1177,7 @@
     _nodeName = "#document-fragment"
     _nodeType = Node.DOCUMENT_FRAGMENT_NODE
     _parentNode = None
-    _in_tree = 0
+    _in_tree = False
 
     _allowed_child_types = (Node.ELEMENT_NODE,
                             Node.TEXT_NODE,
@@ -1239,7 +1240,7 @@
     _attr_info = ()
 
     def __init__(self, namespaceURI, qualifiedName, stuff=None, element_id=0):
-        self._in_tree = 0
+        self._in_tree = False
         self._element_id = element_id
         self._nodeName = qualifiedName
         self._tagName = qualifiedName
@@ -1326,7 +1327,7 @@
     attributes = DOMProperty(_get_attributes)
 
     def hasAttributes(self):
-        return ((self._attributes or self._attr_info) and 1 or 0)
+        return ((self._attributes or self._attr_info) and True or False)
 
     def getAttribute(self, name):
         for item in self._attributes:
@@ -1390,22 +1391,22 @@
     def hasAttribute(self, name):
         for item in self._attributes:
             if name == item[_ATTR_NAME]:
-                return 1
+                return True
         for item in self._attr_info:
             if name == item[_ATTR_NAME]:
-                return 1
-        return 0
+                return True
+        return False
 
     def hasAttributeNS(self, namespaceURI, localName):
         for item in self._attributes:
             if (  namespaceURI == item[_ATTR_NS]
                   and localName == item[_ATTR_LOCALNAME]):
-                return 1
+                return True
         for item in self._attr_info:
             if (  namespaceURI == item[_ATTR_NS]
                   and localName == item[_ATTR_LOCALNAME]):
-                return 1
-        return 0
+                return True
+        return False
 
     def removeAttribute(self, name):
         if self._readonly:
@@ -1613,14 +1614,14 @@
 ##             raise TypeError, "NodeList has only read-only attributes"
 
     def __nonzero__(self):
-        return self._parent._children and 1 or 0
+        return self._parent._children and True or False
 
     def count(self, value):
         value = getbaseobject(value)
         for node in self._parent._children:
             if node is value:
-                return 1
-        return 0
+                return True
+        return False
 
     def index(self, value):
         children = self._parent._children
@@ -1680,8 +1681,8 @@
         base = getbaseobject(obj)
         for node in self._data:
             if getbaseobject(node) is base:
-                return 1
-        return 0
+                return True
+        return False
 
     def __getitem__(self, i):
         return self._data[i]
@@ -1693,14 +1694,14 @@
         return len(self._data)
 
     def __nonzero__(self):
-        return self._data and 1 or 0
+        return self._data and True or False
 
     def count(self, value):
         value = getbaseobject(value)
         for node in self._data:
             if getbaseobject(node) is value:
-                return 1
-        return 0
+                return True
+        return False
 
     def index(self, value):
         value = getbaseobject(value)
@@ -1716,7 +1717,7 @@
     ContextAwareDescriptors()
 
     def __init__(self, data):
-        self._in_tree = 0
+        self._in_tree = False
         self._data = data
         self._nodeValue = data
 
@@ -1824,7 +1825,7 @@
         return newText
 
     # DOM Level 3 (working draft 01 Sep 2000)
-    isWhitespaceInElementContent = 0
+    isWhitespaceInElementContent = False
     def _get_isWhitespaceInElementContent(self):
         return self.isWhitespaceInElementContent
 
@@ -1854,7 +1855,7 @@
 
     _nodeType = Node.ATTRIBUTE_NODE
 
-    _in_tree = 0
+    _in_tree = False
 
     _allowed_child_types = (Node.TEXT_NODE,
                             Node.ENTITY_REFERENCE_NODE)
@@ -1878,7 +1879,7 @@
             self._localName = None
         # ownerElement arg is for readonlyness, not the OwnerElement attribute
         if ownerElement is not None and ownerElement._readonly:
-            self._readonly = 1 # XXX must be shared in case of removal?
+            self._readonly = True # XXX must be shared in case of removal?
         self._specified = item[_ATTR_SPECIFIED]
 
     def __getstate__(self):
@@ -1887,7 +1888,7 @@
     def __cmp__(self, other):
         if (other.nodeType == Node.ATTRIBUTE_NODE
             and self._item is other._item):
-            return 0
+            return False
         else:
             return cmp(id(getbaseobject(self)), id(getbaseobject(other)))
 
@@ -1901,8 +1902,8 @@
         d = clone.__dict__
         d.update(self.__dict__)
         d['_item'] = item = list(self._item)
-        item[_ATTR_SPECIFIED] = 1
-        d['_specified'] = 1
+        item[_ATTR_SPECIFIED] = True
+        d['_specified'] = True
         if d.has_key('_readonly'):
             del d['_readonly']
         # clone the children
@@ -1942,8 +1943,8 @@
             name = self._item[_ATTR_LOCALNAME]
         self._item[_ATTR_NAME] = name
         if not self._specified:
-            self._specified = 1
-            self._item[_ATTR_SPECIFIED] = 1
+            self._specified = True
+            self._item[_ATTR_SPECIFIED] = True
             self._changed()
     prefix = DOMProperty(_get_prefix, _set_prefix)
     
@@ -2011,7 +2012,7 @@
     implements(INamedNodeMap)
     ContextAwareDescriptors()
 
-    _readonly = 0
+    _readonly = False
 
     def __init__(self, parent):
         self._parent = parent
@@ -2132,8 +2133,8 @@
     def has_key(self, name):
         for item in self._getParentList():
             if self._key_helper(item) == name:
-                return 1
-        return 0
+                return True
+        return False
 
     def items(self):
         L = []
@@ -2177,13 +2178,13 @@
                 key = item[_ATTR_NS], item[_ATTR_LOCALNAME]
             else:
                 key = item[_ATTR_NAME]
-            d[key] = 1
+            d[key] = True
         for item in self._attr_info:
             if item[_ATTR_NS]:
                 key = item[_ATTR_NS], item[_ATTR_LOCALNAME]
             else:
                 key = item[_ATTR_NAME]
-            d[key] = 1
+            d[key] = True
         return len(d)
     __len__ = _get_length
 
@@ -2198,7 +2199,7 @@
                     key = item[_ATTR_NS], item[_ATTR_LOCALNAME]
                 else:
                     key = item[_ATTR_NAME]
-                d[key] = 1
+                d[key] = True
             j = len(d)
             for item in self._attr_info:
                 name = item[_ATTR_NAME]


=== zopeproducts/xmldom/xmlextended.py 1.2 => 1.3 ===
--- zopeproducts/xmldom/xmlextended.py:1.2	Thu Jun 19 14:56:20 2003
+++ zopeproducts/xmldom/xmlextended.py	Thu Jun 19 16:43:42 2003
@@ -50,8 +50,8 @@
     implements(IEntity)
 
     _nodeType = core.Node.ENTITY_NODE
-    _readonly = 1
-    _in_tree = 0
+    _readonly = True
+    _in_tree = False
 
     _allowed_child_types = (core.Node.ELEMENT_NODE,
                             core.Node.PROCESSING_INSTRUCTION_NODE,
@@ -67,7 +67,7 @@
 
     def _cloneNode(self, deep, mutable, document):
         # force children to not to acquire mutability:
-        return core.Node._cloneNode(self, deep, 0, document)
+        return core.Node._cloneNode(self, deep, False, document)
 
     def _get_notationName(self):
         return self._notationName
@@ -103,7 +103,7 @@
     implements(IEntityReference)
 
     _nodeType = core.Node.ENTITY_REFERENCE_NODE
-    _readonly = 1
+    _readonly = True
 
     _allowed_child_types = (core.Node.ELEMENT_NODE,
                             core.Node.PROCESSING_INSTRUCTION_NODE,
@@ -113,7 +113,7 @@
                             core.Node.ENTITY_REFERENCE_NODE)
 
     def __init__(self, name):
-        self._in_tree = 0
+        self._in_tree = False
         self._nodeName = name
 
 
@@ -121,17 +121,17 @@
     implements(INotation)
 
     _nodeType = core.Node.NOTATION_NODE
-    _readonly = 1
+    _readonly = True
 
     def __init__(self, name, publicId, systemId):
         self._identified_mixin_init(publicId, systemId)
         
-        self._in_tree = 0
+        self._in_tree = False
         self._nodeName = name
 
     def _cloneNode(self, deep, mutable, document):
         # force children to not to acquire mutability:
-        return core.Node._cloneNode(self, deep, 0, document)
+        return core.Node._cloneNode(self, deep, False, document)
 
     # DOM Level 3 (working draft, 5 June 2001)
 
@@ -146,7 +146,7 @@
     _nodeType = core.Node.PROCESSING_INSTRUCTION_NODE
 
     def __init__(self, target, data):
-        self._in_tree = 0
+        self._in_tree = False
         self._nodeName = target
         self._target = target
         self._nodeValue = data
@@ -192,7 +192,7 @@
         self._nodeName = qualifiedName
         self._entities = []
         self._notations = []
-        self._in_tree = 0
+        self._in_tree = False
 
     def _get_internalSubset(self):
         return self._internalSubset