nti.site.localutility module

Helpers for working with local utilities.

A local utility is a (persistent) utility registered in a local (persistent) site manager. Local utilities need to be traversable and thus are usually children of the local site manager itself.

nti.site.localutility.install_utility(utility, utility_name, provided, local_site_manager)[source]

Call this to install a local utility. Often you will do this from inside a handler for the registration of another dependent utility (IRegistration).

The utility should be IContained because it will be held inside the site manager.

Parameters:utility_name (str) – The traversal name of the utility, not the component registration name. This currently only handles the default, unnamed registration.
nti.site.localutility.install_utility_on_registration(utility, utility_name, provided, event)[source]

Call this to install a local utility in response to the registration of another object.

The utility should be IContained because it will be held inside the site manager.

Parameters:event – The IRegistered event
nti.site.localutility.queryNextUtility(context, interface, default=None)[source]

Our persistent sites are a mix of persistent and non-persistent bases, with many of them having multiple bases. For example (using the notation: name (bases,) [type]):

example.com (GlobalSiteManager) [global]
Application (GlobalSiteManager) [persistent]
site-root.example.com (Application, example.com) [persistent]
child.example.com (example.com) [global]
site-child.example.com (child.example.com, site-root.example.com) [persistent]

This gives site-child.example.com this (correct) resolution order:

site-child.example.com, child.example.com, site-root.example,com Application, example.com, GSM

However, zope.component.queryNextUtility() only looks in the first base to find a next utility. Therefore, when site-janux.ou.edu asks for a next utility, instead of getting something persistent from site-platform.ou.edu, it instead gets the global non-persistent version from platform.ou.edu.

We don’t generally want to change the resolution order, but we do need to tweak it here for getting next utilities so that we consider persistent things first. Note that this breaks down if we have utilities registered both persistently and non-persistently at the same level.

nti.site.localutility.uninstall_utility_on_unregistration(utility_name, provided, event)[source]

When a dependent object is unregistered, this undoes the work done by install_utility().

Parameters:utility_name (str) – The traversal name of the utility, not the component registration name. This currently only handles the default, unnamed registration.