Multiple inheritance and tree data structure problems
Hi, I'm developing a Zope product, ServiceProduct, that behaves as a Node in a Tree data structure. The class hierachy is the following [<--- : extends ; <- - - : implements] Base <---Tree <- - -TreeImpl Base <---- TreeNode <- - - TreeNodeImpl Base <---- Service Implicit,Persistent,RoleManager,ObjectManager,PropertyManager,Item <---- ProductBase ProductBase, TreeNodeImpl<---- ServiceProduct TreeNode<- - - ServiceProduct Service<- - - ServiceProduct So, when I create an new instance of ServiceProduct using the ZMI I found a problem with the constructor. The error message is "unbound method __init__() must be called with instance as first argument" and the code is def __init__(self, id): ProductBase.__init__(self,id,'') try: TreeNodeImpl.__init__(self,id) except Exception, e: print 'Problems with TreeNodeImpl constructor', e # do TreeNodeImpl initialization here if fails self.setNombre( id ) self.parentNode = None self.children = [] self.tree = None I hope that doing the TreeNodeImpl initialization in the except clause will solve this problem. Then, I add child ServiceProduct objects to the tree hierarchy but it seems that the references between parent and child objects change when new calls to the object are done (I use a DTML page for displaying hierarchy info). Even worse, the ProductBase has a method hashCode that shows instance info def hashCode(self): id = str( self ) id = id.replace( '<', '_') id = id.replace( '>', '_') id = id.replace( ' ', '_') return id returns two different results when is called from a DTML page, (sometimes the first and other times the second), BUT I have created only one instance of the object. Finally, I have tested the TreeImpl, TreeNodeImpl outside Zope and it works without any problems. Any idea of where is the problem? The 'constructor problem' is related to the 'references losing' problem? Any help with will be apreciated. Best regards, Manu
take a look at http://debian.acm.ndsu.nodak.edu/doc/python-extclass/ExtensionClass.html search for 'inheritedAttribute' Manuel_Montejo@apb.es wrote:
Hi,
I'm developing a Zope product, ServiceProduct, that behaves as a Node in a Tree data structure.
The class hierachy is the following [<--- : extends ; <- - - : implements]
Base <---Tree <- - -TreeImpl Base <---- TreeNode <- - - TreeNodeImpl Base <---- Service
Implicit,Persistent,RoleManager,ObjectManager,PropertyManager,Item <---- ProductBase ProductBase, TreeNodeImpl<---- ServiceProduct TreeNode<- - - ServiceProduct Service<- - - ServiceProduct
So, when I create an new instance of ServiceProduct using the ZMI I found a problem with the constructor. The error message is "unbound method __init__() must be called with instance as first argument" and the code is
def __init__(self, id): ProductBase.__init__(self,id,'') try: TreeNodeImpl.__init__(self,id) except Exception, e: print 'Problems with TreeNodeImpl constructor', e # do TreeNodeImpl initialization here if fails self.setNombre( id ) self.parentNode = None self.children = [] self.tree = None
I hope that doing the TreeNodeImpl initialization in the except clause will solve this problem.
Then, I add child ServiceProduct objects to the tree hierarchy but it seems that the references between parent and child objects change when new calls to the object are done (I use a DTML page for displaying hierarchy info).
Even worse, the ProductBase has a method hashCode that shows instance info
def hashCode(self): id = str( self ) id = id.replace( '<', '_') id = id.replace( '>', '_') id = id.replace( ' ', '_') return id
returns two different results when is called from a DTML page, (sometimes the first and other times the second), BUT I have created only one instance of the object.
Finally, I have tested the TreeImpl, TreeNodeImpl outside Zope and it works without any problems.
Any idea of where is the problem? The 'constructor problem' is related to the 'references losing' problem? Any help with will be apreciated.
Best regards,
Manu
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (2)
-
Manuel_Montejoļ¼ apb.es -
peter sabaini