[Zope-dev] Patching Zope Products .. next Question

Ulrich Eck ueck@net-labs.de
Thu, 12 Jul 2001 14:03:41 +0200


> Would this approach be appropriate?
>
> http://dev.zope.org/Members/Caseman/Dynamic_HotFix_News/Dynamic_Hotfix
>
>

> You can hotpatch the __bases__ attribute of the derived class.
>
>

ok .. I tried several different versions of patching ..

1st Try: Created a new class in the patch that subclassed the ZPatterns-Stuff directly:
############################
### CMFCore.PortalFolder ###
############################

import CMFCore

class PortalFolder( CustomizerFolder, CMFCore.PortalFolder.PortalFolder):
    """
        Implements portal content management, but not UI details.
    """
    meta_type = 'Portal Folder'
    portal_type = 'Folder'


    def __init__( self, id, title='' ):
        CustomizerFolder.__init__(self,id)
        self.id = id
        self.title = title


CMFCore.PortalFolder.PortalFolder = PortalFolder
InitializeClass(CMFCore.PortalFolder.PortalFolder)

This works fine except the DataSkin-derived classes don't show up in
the CustomizerFolder for customization (they're not properly initialized)

2nd Try: modify __bases__ directly ..

############################
### CMFCore.PortalFolder ###
############################

def PortalFolder__init__( self, id, title='' ):
    CustomizerFolder.__init__(self,id)
    self.id = id
    self.title = title


import Products.CMFCore.PortalFolder
Products.CMFCore.PortalFolder.PortalFolder.__bases__ = tuple((CustomizerFolder,) +
Products.CMFCore.PortalFolder.PortalFolder.__bases__)
# the next line works only if i use the im_func
# otherwise i get this error:
# Error Type: TypeError
# Error Value: unbound Python method must be called with PlugInContainer 1st argument
Products.CMFCore.PortalFolder.PortalFolder.__init__ = PortalFolder__init__.im_func

InitializeClass(Products.CMFCore.PortalFolder.PortalFolder)

this one doesn't do anything ...

do you see the failure .. have a hint what I'm doing wrong ???

thanks for your patience

Ulrich Eck
net-labs