nti.site.subscribers module

Subscribers for traversal events to ensure that the the proper site is installed, including respecting global registered components.

Caution

zope.site.site.threadSiteSubscriber() also exists and is configured by some packages like zope.app.publication. Care must be used to ensure that it is not configured in place of our own threadSiteSubscriber().

nti.site.subscribers.new_local_site_dispatcher(event)[source]

Dispatches just like an object event, that way we can do things based on the type of the site manager.

Note that if the containing ISite is (re)moved, an ObjectEvent will be fired for (sitemanager, site-event); that is, you subscribe to the site manager and the object moved event, but the event will have the ISite as the object property.

nti.site.subscribers.threadSiteSubscriber(new_site, _event)[source]

Set the current zope.component.hooks site to the new_site object found during traversal, being careful to maintain any previously installed host (site-name) configurations as lower priority than the new site.

Sites encountered during traversal are expected to have the main application site (e.g., nti.dataserver) in their base chain so we have access to its configuration and persistent utilities. This implies that sites encountered during traversal are either synthetic (generated by a traversal adapter to use some particular IComponents) or themselves persistent.

Because of this, when we encounter the root or dataserver folders as sites, we take no action (unless there is no site presently installed; in that case we install them).

We expect that something else takes care of clearing the site.

Important

Clearing the site is important, especially if the site was persistent. You can use a subscriber to “end request” style events or otherwise make it part of request lifecycle. When that’s not possible, please do so manually.

Changed in version 2.3.0: Always install the new_site if there is no current site. Previously, if new_site provided IMainApplicationFolder or zope.site.interfaces.IRootFolder, it was always ignored.

No longer raises a LocationError if an unknown type of site is encountered. Instead, simply installs it, replacing the current site.