[Zope] Making a self written module available to Zope

Paul Winkler pw_lists at slinkp.com
Fri Jan 21 11:38:01 EST 2005


On Sat, Jan 22, 2005 at 12:19:11AM +0800, Hong Yaun wrote:
> If I have a self-written module/package which contains some module level 
> methods, how can I make it available for use in the rest of Zope (e.g. 
> in page templates, python script objects etc.)?
> 
> Because it is just some utility functions, like the zope built-in 
> sequence module, I don't want to register them as a zope class with all 
> the manage* methods and create zope object from that. And I want the 
> module to be initialized once, upon the start of zope or refresh of 
> product maybe, to read some configuration file on the file system. 
> What's the simplest way to achieve this?

a trivial example:

# this is Products/MyFunctions/__init__.py

from AccessControl import ModuleSecurityInfo

def trivialFunc():
   return True 

def anotherFunc():
   return False

ModuleSecurityInfo('Products.MyFunctions').declarePublic(
    'trivialFunc', 'anotherFunc'
    ) 

# EOF

Note that you cannot declare module-level functions
protected by a particular permission; you can only declare 
them public.
See lib/python/AccessControl/SecurityInfo.py.

You may also find AccessControl.allow_module() useful.
It's defined in that same file.

-- 

Paul Winkler
http://www.slinkp.com


More information about the Zope mailing list