Garanin Michael wrote:

My app setup code do follow step:
1) create simple AppSite (as ISite) in top
2) create local-utility object, for example PAU = PluggableAuthentication() 3) AppSite['PAU'] = PAU 4) registration the PAU in AppSite/++etc++site/default.

In other words: local-utility object location in top/mysite, but
registration in top/mysite/++etc++site/default.
Q: It's work, but is it legal?
IMO it makes sense that the default site folder is invoked if a local utility is added to a site.

We use the following helper function for the local utility additon and registration:

from import zapi
from import INameChooser
from import ActiveStatus
from import ISite
from import UtilityRegistration

def addLocalUtility(site, name, iface, utility, package='default'):
   """Add a utility to a site

   The utility is added to the package and activated.
   This assumes the site has already a Utility Service.
   # preconditions
   if not ISite.providedBy(site):
       raise TypeError('ISite required.')

   # get site manager and site management folder
   sitemanager = site.getSiteManager()
   default = sitemanager[package]

   # add utility to site management folder
   chooser = INameChooser(default)
   folder_name = chooser.chooseName(utility.__name__, utility)
   default[folder_name] = utility

   # create service registration
   path = zapi.getPath(utility)
   registration = UtilityRegistration(name, iface, utility)
   key = default.registrationManager.addRegistration(registration)
zapi.traverse(default.registrationManager, key).status = ActiveStatus
   return zapi.traverse(sitemanager, path)


Zope3-dev mailing list

Reply via email to