nti.site.site module

Implementations of sites and helpers for working with sites.

class nti.site.site.BTreeLocalAdapterRegistry(bases=())[source]

Bases: zope.site.site._LocalAdapterRegistry

A persistent adapter registry that can switch its internal data structures to be more persistent friendly when they get large.

Caution

This registry doesn’t support registrations on bare classes. This is because the Implements and Provides objects returned on bare classes do not support comparison or equality and hence cannot be used in BTrees. (They only hash and compare equal to themselves; within the same process this works out because of aggressive caching on class objects.) Registering a utility to provide a bare class is quite hard to do, in any case. Registering adapters to require bare classes is easier but generally not a best practice.

Changed in version 3.0.0: No longer converts any data structures as part of mutating this object. Instead, uses the support from zope.interface 5.3 and zope.component 5.0 to specify the data types to use as they are created on demand.

Existing persistent registries must have the rebuild() method called on them as part of a migration. The best way to do that would be through the rebuild() method on their containing BTreeLocalSiteManager.

btree_family = <BTree family using 64 bits. Supports signed integer values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 and maximum unsigned integer value 18,446,744,073,709,551,615.>

The family for the provided map. Defaults to 64-bit maps. I.e., long.

class nti.site.site.BTreeLocalSiteManager(site, default_folder=True)[source]

Bases: nti.site.site.BTreePersistentComponents, zope.site.site.LocalSiteManager

Persistent local site manager that will be friendly to ZODB when they get large.

Caution

This registry doesn’t support bare class registrations. See BTreeLocalAdapterRegistry for details.

Changed in version 3.0.0: No longer attempts to change the class of the adapters and utilities objects when reading old pickles.

Instead, you must call this object’s rebuild() method as part of a migration. This method will call rebuild() on the adapters and utilities objects, and also reset the __bases__ of this object (to its current bases). The order (leaves first or roots first) shouldn’t matter, as long as all registries in an inheritance hierarchy are committed in a single transaction.

If we detect old versions of the class that haven’t been migrated, we log an error.

rebuild()[source]
class nti.site.site.BTreePersistentComponents(name='', bases=())[source]

Bases: zope.component.persistentregistry.PersistentComponents

Persistent components that will be friendly to ZODB when they get large.

Note that despite the name, this class is not Persistent, only its internal components are.

Caution

This registry doesn’t support bare class registrations. See BTreeLocalAdapterRegistry for details.

btree_family = <BTree family using 64 bits. Supports signed integer values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 and maximum unsigned integer value 18,446,744,073,709,551,615.>
btree_threshold = 30

The size at which we will switch from maps to BTrees for registered adapters and registered utilities (individually). This defaults to the maximum size of a BTree bucket before it splits. Thus, when we do this, we will wind up with at least two persistent objects.

registerAdapter(*args, **kwargs)[source]
registerUtility(*args, **kwargs)[source]
class nti.site.site.SiteMapping(**kw)[source]

Bases: nti.schema.schema.SchemaConfigured

Maps one site to another.

:raises a SiteNotFoundError object if no site found

get_target_site()[source]

Returns the target site as defined by this mapping.

source_site_name

Computed attributes based on schema fields

Field properties provide default values, data validation and error messages based on data found in field meta-data.

Note that FieldProperties cannot be used with slots. They can only be used for attributes stored in instance dictionaries.

target_site_name

Computed attributes based on schema fields

Field properties provide default values, data validation and error messages based on data found in field meta-data.

Note that FieldProperties cannot be used with slots. They can only be used for attributes stored in instance dictionaries.

exception nti.site.site.WrongRegistrationTypeError[source]

Bases: exceptions.TypeError

Raised if an adapter registration is of the wrong type.

Changed in version 1.0.1: This is no longer raised by this package.

nti.site.site.find_site_components(site_names, check_alternate=False)[source]

Return an (global, registered) IComponents implementation named for the first virtual site found in the sequence of site_names. If no such components can be found, returns none.

nti.site.site.get_alternate_site_name(site_name)[source]

Check for a configured ISiteMapping

nti.site.site.get_component_hierarchy(site=None)[source]
nti.site.site.get_component_hierarchy_names(site=None, reverse=False)[source]
nti.site.site.get_site_for_site_names(site_names, site=None)[source]

Return an ISite implementation named for the first virtual site found in the sequence of site_names.

First, we’ll attempt to find the registered persistent site; either given by the site name or redirected by a registered ISiteMapping pointing to a persistent site. Otherwise, we’ll look for a site without the ISiteMapping lookup.

We’ll then look a registered persistent site having the same name as the registered global components found for site_names, then that site will be used. Otherwise, if there is only a registered global components, a non-persistent site that incorporates those components in the lookup order while still incorporating the current (or provided) site will be returned.

If no such site or components can be found, returns the fallback site (the current or provided site).

Parameters:
  • site_names – Sequence of strings giving the virtual host names to use.
  • site – If given, this will be the fallback site (and site manager). If not given, then the currently installed site will be used.

Changed in version 1.2.0: Look for a ISiteMapping registration to map a non-persistent site to a persistent site.

Changed in version 1.3.0: Prioritize ISiteMapping so that persistent sites can be mapped to other persistent sites.