class Node(xml.dom.Node): def __init__(self,n): self.this = _cODP.new_ODPNode(n) self.thisown=1 def __setattr__(self,attr,value): if (attr in ["nodeName", "nodeType", "parentNode", "childNodes", "firstChild", "lastChild", "previousSibling", "nextSibling", "attributes", "ownerDocument"]): raise "Node.%s is read only"%attr if attr == "nodeValue": raise xml.dom.NoModificationAllowedErr,"Node.nodeValue is read only" self.__dict__[attr]=value _get_methods_={ "nodeName" :_cODP.ODPNode_getNodeName, "nodeValue" :_cODP.ODPNode_getNodeValue, "nodeType" :_cODP.ODPNode_getNodeType, "parentNode" :lambda x:_ntype(_cODP.ODPNode_getParentNode(x)), "childNodes" :lambda x: NodeList(_cODP.ODPNode_getChildNodes(x)), "firstChild" :lambda x:_ntype(_cODP.ODPNode_getFirstChild(x)), "lastChild" :lambda x:_ntype(_cODP.ODPNode_getLastChild(x)), "previousSibling":lambda x:_ntype(_cODP.ODPNode_getPreviousSibling(x)), "nextSibling" :lambda x:_ntype(_cODP.ODPNode_getNextSibling(x)), "attributes" :lambda x: AttributeList(_cODP.ODPNode_getAttributes(x)), "ownerDocument" :lambda x:_ntype(_cODP.ODPNode_getOwnerDocument(x)) } def __getattr__(self,name): method = self._get_methods_.get(name,None) if (method): return method(self.this) raise AttributeError,name def __nonzero__(self): return 1 def insertBefore(self, newChild, refChild): raise xml.dom.NoModificationAllowedErr,"Node.insertBefore not supported" def appendChild(self, node): raise xml.dom.NoModificationAllowedErr,"Node.appendChild not supported" def replaceChild(self, newChild, oldChild): raise xml.dom.NoModificationAllowedErr,"Node.replaceChild not supported" def removeChild(self, oldChild): raise xml.dom.NoModificationAllowedErr,"Node.removeChild not supported" def cloneNode(self, deep): raise xml.dom.NotSupportedErr,"Node.cloneNode not supported"
class Attr(Node): def __init__(self,n): self.this = _cODP.new_ODPAttr(n) self.thisown=1 _get_methods_={ "nodeName" :_cODP.ODPNode_getNodeName, "nodeValue" :_cODP.ODPNode_getNodeValue, "nodeType" :_cODP.ODPNode_getNodeType, "parentNode" :lambda x:_ntype(_cODP.ODPNode_getParentNode(x)), "childNodes" :lambda x: NodeList(_cODP.ODPNode_getChildNodes(x)), "firstChild" :lambda x:_ntype(_cODP.ODPNode_getFirstChild(x)), "lastChild" :lambda x:_ntype(_cODP.ODPNode_getLastChild(x)), "previousSibling":lambda x:_ntype(_cODP.ODPNode_getPreviousSibling(x)), "nextSibling" :lambda x:_ntype(_cODP.ODPNode_getNextSibling(x)), "attributes" :lambda x: AttributeList(_cODP.ODPNode_getAttributes(x)), "ownerDocument" :lambda x:_ntype(_cODP.ODPNode_getOwnerDocument(x)), "name" : _cODP.ODPAttr_getName, "specified" : _cODP.ODPAttr_getSpecified, "value" : _cODP.ODPAttr_getValue, } def __setattr__(self,attr,value): if (attr in ["name", "specified", "nodeName", "nodeType", "parentNode", "childNodes", "firstChild", "lastChild", "previousSibling", "nextSibling", "attributes", "ownerDocument"]): raise "Attr.%s is read only"%attr if attr in ["nodeValue","value"]: raise xml.dom.NoModificationAllowedErr,"Attr.%s is read only"%attr self.__dict__[attr]=value def __getattr__(self,name): method = self._get_methods_.get(name,None) if (method): return method(self.this) raise AttributeError,name
class ProcessingInstruction(Node): def __init__(self, node): self.this = _cODP.new_ODPProcessingInstruction(node) self.thisown = 1 _get_methods_={ "nodeName" :_cODP.ODPNode_getNodeName, "nodeValue" :_cODP.ODPNode_getNodeValue, "nodeType" :_cODP.ODPNode_getNodeType, "parentNode" :lambda x:_ntype(_cODP.ODPNode_getParentNode(x)), "childNodes" :lambda x: NodeList(_cODP.ODPNode_getChildNodes(x)), "firstChild" :lambda x:_ntype(_cODP.ODPNode_getFirstChild(x)), "lastChild" :lambda x:_ntype(_cODP.ODPNode_getLastChild(x)), "previousSibling":lambda x:_ntype(_cODP.ODPNode_getPreviousSibling(x)), "nextSibling" :lambda x:_ntype(_cODP.ODPNode_getNextSibling(x)), "attributes" :lambda x: AttributeList(_cODP.ODPNode_getAttributes(x)), "ownerDocument" :lambda x:_ntype(_cODP.ODPNode_getOwnerDocument(x)), "length" :_cODP.ODPCharacterData_getLength, "target" :lambda x:split(x.getNodeName())[0], "data" :lambda x:join(split(x.getNodeName())[1:]) } def __setattr__(self,attr,value): if (attr in ["target", "nodeName", "nodeType", "parentNode", "childNodes", "firstChild", "lastChild", "previousSibling", "nextSibling", "attributes", "ownerDocument"]): raise "ProcessingInstruction.%s is read only"%attr if attr in ["nodeValue","data"]: raise xml.dom.NoModificationAllowedErr,"ProcessingInstruction.%s is read only"%attr self.__dict__[attr]=value def __getattr__(self,name): method = self._get_methods_.get(name,None) if (method): return method(self.this) raise AttributeError,name
class Document(Node): doctype=None implementation=DOMImplementation() def __init__(self,n): self.this = n self.thisown=1 _get_methods_={ "nodeName" :_cODP.ODPNode_getNodeName, "nodeValue" :_cODP.ODPNode_getNodeValue, "nodeType" :_cODP.ODPNode_getNodeType, "parentNode" :lambda x:_ntype(_cODP.ODPNode_getParentNode(x)), "childNodes" :lambda x: NodeList(_cODP.ODPNode_getChildNodes(x)), "firstChild" :lambda x:_ntype(_cODP.ODPNode_getFirstChild(x)), "lastChild" :lambda x:_ntype(_cODP.ODPNode_getLastChild(x)), "previousSibling" :lambda x:_ntype(_cODP.ODPNode_getPreviousSibling(x)), "nextSibling" :lambda x:_ntype(_cODP.ODPNode_getNextSibling(x)), "attributes" :lambda x: AttributeList(_cODP.ODPNode_getAttributes(x)), "ownerDocument" :lambda x:_ntype(_cODP.ODPNode_getOwnerDocument(x)), "documentElement" :lambda x:_ntype(_cODP.ODPDocument_getDocumentElement(x)), } def __setattr__(self,attr,value): if (attr in ["documentElement" "nodeName", "nodeType", "parentNode", "childNodes", "firstChild", "lastChild", "previousSibling", "nextSibling", "attributes", "ownerDocument"]): raise "Document.%s is read only"%attr if attr == "nodeValue": raise xml.dom.NoModificationAllowedErr,"Node.nodeValue is read only" self.__dict__[attr]=value def __getattr__(self,name): method = self._get_methods_.get(name,None) if (method): return method(self.this) raise AttributeError,name def createDocumentFragment(self): raise xml.dom.NotSupportedErr,"Document.createDocumentFragment not supported" def createElement(self, tagName): raise xml.dom.NotSupportedErr,"Document.createElement not supported" def createTextNode(self, data): raise xml.dom.NotSupportedErr,"Document.createTextNode not supported" def createCDATASection(self, data): raise xml.dom.NotSupportedErr,"Document.createCDATASection not supported" def createComment(self, data): raise xml.dom.NotSupportedErr,"Document.createComment not supported" def createProcessingInstruction(self, target, data): raise xml.dom.NotSupportedErr,"Document.createProcessingInstruction not supported" def createAttribute(self, qName): raise xml.dom.NotSupportedErr,"Document.createAttribute not supported" def getElementsByTagName(self, name): return NodeList(_cODP.ODPDocument_getElementsByTagName(self.this,name))
class CharacterData(Node): def __init__(self, node): self.this = _cODP.new_ODPCharacterData(node) self.thisown = 1 _get_methods_={ "nodeName" :_cODP.ODPNode_getNodeName, "nodeValue" :_cODP.ODPNode_getNodeValue, "nodeType" :_cODP.ODPNode_getNodeType, "parentNode" :lambda x:_ntype(_cODP.ODPNode_getParentNode(x)), "childNodes" :lambda x: NodeList(_cODP.ODPNode_getChildNodes(x)), "firstChild" :lambda x:_ntype(_cODP.ODPNode_getFirstChild(x)), "lastChild" :lambda x:_ntype(_cODP.ODPNode_getLastChild(x)), "previousSibling":lambda x:_ntype(_cODP.ODPNode_getPreviousSibling(x)), "nextSibling" :lambda x:_ntype(_cODP.ODPNode_getNextSibling(x)), "attributes" :lambda x: AttributeList(_cODP.ODPNode_getAttributes(x)), "ownerDocument" :lambda x:_ntype(_cODP.ODPNode_getOwnerDocument(x)), "length" :_cODP.ODPCharacterData_getLength, "data" :_cODP.ODPCharacterData_getData, } def __repr__(self): return "<DOM %s node>" % (self.__class__.__name__) def __setattr__(self,attr,value): if (attr in ["length" "nodeName", "nodeType", "parentNode", "childNodes", "firstChild", "lastChild", "previousSibling", "nextSibling", "attributes", "ownerDocument"]): raise "Node.%s is read only"%attr if attr in ["nodeValue","data"]: raise xml.dom.NoModificationAllowedErr,"CharacterData.%s is read only"%attr self.__dict__[attr]=value def __getattr__(self,name): method = self._get_methods_.get(name,None) if (method): return method(self.this) raise AttributeError,name def __len__(self): return _cODP.ODPCharacterData_getLength(self.this) def __str__(self): return _cODP.ODPCharacterData_getData(self.this) def substringData(self, offset, count): if offset < 0: raise xml.dom.IndexSizeErr("offset is negative") if offset >= len(self): raise xml.dom.IndexSizeErr("offset out of range") if count < 0: raise xml.dom.IndexSizeErr("count is negative") return _cODP.ODPCharacterData_substringData(self.this,offset,count) def appendData(self, arg): raise xml.dom.NoModificationAllowedErr,"CharacterData.appendData not supported" def insertData(self, offset, arg): raise xml.dom.NoModificationAllowedErr,"CharacterData.insertData not supported" def deleteData(self, offset, count): raise xml.dom.NoModificationAllowedErr,"CharacterData.deleteData not supported" def replaceData(self, offset, count, arg): raise xml.dom.NoModificationAllowedErr,"CharacterData.replaceData not supported"
class Element(Node): def __init__(self, node): self.this = _cODP.new_ODPElement(node) self.thisown = 1 _get_methods_={ "nodeName" :_cODP.ODPNode_getNodeName, "nodeValue" :_cODP.ODPNode_getNodeValue, "nodeType" :_cODP.ODPNode_getNodeType, "parentNode" :lambda x:_ntype(_cODP.ODPNode_getParentNode(x)), "childNodes" :lambda x: NodeList(_cODP.ODPNode_getChildNodes(x)), "firstChild" :lambda x:_ntype(_cODP.ODPNode_getFirstChild(x)), "lastChild" :lambda x:_ntype(_cODP.ODPNode_getLastChild(x)), "previousSibling":lambda x:_ntype(_cODP.ODPNode_getPreviousSibling(x)), "nextSibling" :lambda x:_ntype(_cODP.ODPNode_getNextSibling(x)), "attributes" :lambda x: AttributeList(_cODP.ODPNode_getAttributes(x)), "ownerDocument" :lambda x:_ntype(_cODP.ODPNode_getOwnerDocument(x)), "tagName" :_cODP.ODPElement_getTagName, } def __setattr__(self,attr,value): if (attr in ["tagName", "nodeName", "nodeType", "parentNode", "childNodes", "firstChild", "lastChild", "previousSibling", "nextSibling", "attributes", "ownerDocument"]): raise "Element.%s is read only"%attr if attr == "nodeValue": raise xml.dom.NoModificationAllowedErr,"Element.nodeValue is read only" self.__dict__[attr]=value def __getattr__(self,name): method = self._get_methods_.get(name,None) if (method): return method(self.this) raise AttributeError,name def cloneNode(self, deep): raise xml.dom.NotSupportedErr,"Element.cloneNode not supported" def getAttribute(self, attrname): return _cODP.ODPElement_getAttribute(self.this,attrname) def setAttribute(self, attname, value): raise xml.dom.NoModificationAllowedErr,"Element.setAttribute not supported" def getAttributeNode(self, attrname): return _ntype(_cODP.ODPElement_getAttributeNode(self.this,attrname)) def setAttributeNode(self, attr): raise xml.dom.NoModificationAllowedErr,"Element.setAttributeNode not supported" def removeAttribute(self, name): raise xml.dom.NoModificationAllowedErr,"Element.removeAttribute not supported" def removeAttributeNode(self, node): raise xml.dom.NoModificationAllowedErr,"Element.removeAttributeNode not supported" def hasAttribute(self, name): return _cODP.ODPElement_getAttribute(self.this,name) is not None def getElementsByTagName(self, name): return NodeList(_cODP.ODPElement_getElementsByTagName(self.this,name)) def __repr__(self): return "<DOM Element: %s at %s>" % (self.tagName, id(self)) def hasAttributes(self): raise "write me!"
def getFirstChild(self): return _cODP.ODPNode_getFirstChild(self)
class Node: ELEMENT_NODE = 1 ATTRIBUTE_NODE = 2 TEXT_NODE = 3 CDATA_SECTION_NODE = 4 ENTITY_REFERENCE_NODE = 5 ENTITY_NODE = 6 PROCESSING_INSTRUCTION_NODE = 7 COMMENT_NODE = 8 DOCUMENT_NODE = 9 DOCUMENT_TYPE_NODE = 10 DOCUMENT_FRAGMENT_NODE = 11 NOTATION_NODE = 12 def __init__(self, n): self.this = _cODP.new_ODPNode(n) self.thisown = 1 def __setattr__(self, attr, value): if (attr in [ "nodeName", "nodeType", "parentNode", "childNodes", "firstChild", "lastChild", "previousSibling", "nextSibling", "attributes", "ownerDocument" ]): raise "Node.%s is read only" % attr if attr == "nodeValue": raise xml.dom.NoModificationAllowedErr, "Node.nodeValue is read only" self.__dict__[attr] = value _get_methods_ = { "nodeName": _cODP.ODPNode_getNodeName, "nodeValue": _cODP.ODPNode_getNodeValue, "nodeType": _cODP.ODPNode_getNodeType, "parentNode": lambda x: _ntype(_cODP.ODPNode_getParentNode(x)), "childNodes": lambda x: NodeList(_cODP.ODPNode_getChildNodes(x)), "firstChild": lambda x: _ntype(_cODP.ODPNode_getFirstChild(x)), "lastChild": lambda x: _ntype(_cODP.ODPNode_getLastChild(x)), "previousSibling": lambda x: _ntype(_cODP.ODPNode_getPreviousSibling(x)), "nextSibling": lambda x: _ntype(_cODP.ODPNode_getNextSibling(x)), "attributes": lambda x: AttributeList(_cODP.ODPNode_getAttributes(x)), "ownerDocument": lambda x: _ntype(_cODP.ODPNode_getOwnerDocument(x)) } def __getattr__(self, name): method = self._get_methods_.get(name, None) if (method): return method(self.this) raise AttributeError, name def __nonzero__(self): return 1 def insertBefore(self, newChild, refChild): raise xml.dom.NoModificationAllowedErr, "Node.insertBefore not supported" def appendChild(self, node): raise xml.dom.NoModificationAllowedErr, "Node.appendChild not supported" def replaceChild(self, newChild, oldChild): raise xml.dom.NoModificationAllowedErr, "Node.replaceChild not supported" def removeChild(self, oldChild): raise xml.dom.NoModificationAllowedErr, "Node.removeChild not supported" def cloneNode(self, deep): raise xml.dom.NotSupportedErr, "Node.cloneNode not supported"