[Zope] creating a python function callable within zope

kapil thangavelu kthangavelu@earthlink.net
Fri, 2 Aug 2002 09:33:11 -0700


a better/easier approach would be to separate the function  into a utility 
module in your product and make it accessible from python scripts and zpt 
using the RestricedImport functionality, 

as an example i have this in a utility product's init method

from AccessControl import ModuleSecurityInfo
 
from MyUtilModule import func1, func2
 
security = ModuleSecurityInfo()
 
security.declarePublic('func1',
                       'func2')
 
security.apply(globals())

another example is the cmf core's utils module

this will make it accessible to python scripts and zpt.

-kapil

On Friday 02 August 2002 01:41 pm, Steve Nicholson wrote:
> I have created a python based zope product for the cmf which is working
> ok. I would like to create a function that belongs in the same .py file
> as the product class but the function will not be a method of a class
> instance. I want to be able to call this function from anywher within
> zope to do something related to the product class but not an instance of
> that class. I assume the function "def function( self ): etc..." is
> placed outside of the class statement in the .py file but I cannot work
> out what I need to do to be able to call it in zope, or if it's possible
> or wise to do. At the moment I have this function written in a zope
> "python script". Or am I supposed to make it an external method?
>
> Hope that makes sense as I'm still trying to get my head around this
> class,instance,method,function thing!
> Any ideas or help on where I am going wrong would be much appreciated.
>
> (Running zope 2.5.1 / python 2.1.3 / win2000)
> Thanks
> Steve.
>
>
> _______________________________________________
> 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 )