API Reference

nti.app.pyramid_zope

DOCUMENT ME.

nti.app.pyramid_zope.request

Partial support for making a Pyramid request/response object pair work more like a Zope request.

Partially based on ideas from pyramid_zope_request

class PyramidZopeRequestProxy(base)[source]

Bases: zope.proxy.decorator.SpecificationDecoratorBase

Makes a Pyramid IRequest object look like a Zope request for purposes of rendering. The existing interfaces (IRequest) are preserved.

Changes to a proxy, including annotations, are persistent, and will be reflected if the same pyramid request is proxied again later (unlike pyramid_zope_request, which takes the approach of subclassing zope.publisher.base.BaseRequest and overriding certain methods to call through to pyramid, but not things like annotations.)

Note

Most of this behaviour is added from reverse-engineering what existing zope code, most notably z3c.table.table uses. Some additional support for z3c.form comes from looking at what pyramid_zope_request does.

environment

Alias for environ

form[source]

Process inputs into the form object.

See also: https://github.com/zopefoundation/pyramid_zope_request/blob/master/src/pyramid_zope_request/__init__.py#L78

getApplicationURL(depth=0, path_only=False)[source]

Like getURL, zope.publisher uses traversed names here instead of working on the url of the request. This implementation works off the request, which will potentially yield different results. What’s this gonna break?

getURL(level=0, path_only=False)[source]

zope.publisher uses traversed names here instead of working on the url of the request. This implementation works off the request, which will potentially yield different results. What’s this gonna break?

nti.app.pyramid_zope.traversal

Support for resource tree traversal.

class ZopeResourceTreeTraverser(root)[source]

Bases: pyramid.traversal.ResourceTreeTraverser

A pyramid.interfaces.ITraverser based on pyramid’s default traverser, but modified to use the zope.traversing.api machinery instead of (only) dictionary lookups. This provides is with the flexibility of the zope.traversing.interfaces.ITraversable adapter pattern, plus the support of namespace lookups (zope.traversing.namespace.nsParse() and zope.traversing.namespace.namespaceLookup()).

As this object traverses, it fires IBeforeTraverseEvent events. If you either load the configuration from zope.app.publication or manually enable the zope.site.site.threadSiteSubscriber to subscribe to this event, then any Zope site managers found along the way will be made the current site.

__call__(request)[source]

See pyramid.interfaces.ITraversar.__call__().

__init__(root)[source]

Initialize self. See help(type(self)) for accurate signature.

class resource(context, request)[source]

Bases: zope.traversing.namespace.resource

Handles resource lookup in a way compatible with zope.browserresource. This package registers resources as named adapters from IDefaultBrowserLayer to Interface. We connect the two by making the pyramid request implement the right thing.

__init__(context, request)[source]

Initialize self. See help(type(self)) for accurate signature.

nti.app.pyramid_zope.security

Integrations for zope.security and zope.authentication.

Many of these are adapters registered automatically by this package’s configure.zcml.

In plain Zope3, the zope.publisher.interfaces.IRequest is an zope.security.interfaces.IParticipation for the request’s principal (or the unauthenticated or fallback unauthenticated principal). That request is defined to be the first participation in the interaction by zope.app.publication.zopepublication (right after authentication and right before traversal).

Pyramid’s request is not a participation, and Pyramid doesn’t establish an interaction either. Something else (typically a tween like TODO: Copy Tween) does that. These adapters will work only after that is done.

interaction_from_request(request: IRequest) → IInteraction[source]

Find the IInteraction for the request.

The request is adapted to IInteractionManagement (using the default zope.security.management for a thread-local interaction if there is no specific adapter registered), and the current interaction is returned.

This is registered as an adapter on the Pyramid IRequest interface; to provide a more specific policy, register an adapter on the concrete class.

Raises:zope.security.interfaces.NoInteraction – If there is no interaction.

See also

zope.security.interfaces.IInteractionManagement

principal_from_interaction(interaction: IInteraction) → IPrincipal[source]

Find the primary IPrincipal for the interaction. The primary principal is the principal of the first participation.

principal_from_request(request: IRequest) → IPrincipal[source]

Find the primary IPrincipal for the request.

First adapts the request into an IInteraction (probably using interaction_from_request()), and then adapts the interaction into an IPrincipal (probably using principal_from_interaction()). If there is no interaction, the unauthenticated principal is returned.

This is registered as an adapter on the Pyramid IRequest interface; to provide a more specific policy, register an adapter on the concrete class.