## ## Example Zope product that monkey patches the IssueTrackerProduct ## #----------------------------------------------------------------------------- # the usual suspects # # python import os, sys, re # Zope from zLOG import LOG, INFO # our big brother from Products.IssueTrackerProduct import IssueTracker # NB: If we write IssueTracker.IssueTracker # we mean . #----------------------------------------------------------------------------- # Now, let's test if we should go ahead with this at all # # assume that we won't be able to do it do_patch = False # Let's only go ahead with this if the issuetracker # version is above 0.6.4 itpversion = IssueTracker.__version__ major, minor, tiny = [int(number) for number in itpversion.split('.')] if minor >= 6: if tiny >= 4: do_patch = True #----------------------------------------------------------------------------- # We write our own functions that are (to us) vastly superior to those of the # default IssueTrackerProduct # from quotes import quotes as quotesdict from random import shuffle quoteslist = quotesdict.values() # copied and modified from IssueTracker.py around line 500 def showSignature_Quote(self): """ our own custom signature function """ shuffle(quoteslist) return quoteslist[0] #----------------------------------------------------------------------------- # Finally, do the actual monkey patch # if do_patch: # add a new attribute to the class which happens to be # an overwriting. You can add more functions to the class # too if you need to. IssueTracker.IssueTracker.showSignature = showSignature_Quote LOG("ExampleITPMonkey", INFO, "IssueTrackerProduct patched")