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 subclassingzope.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 forz3c.form
comes from looking at whatpyramid_zope_request
does.-
environment
¶ Alias for
environ
-
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 thezope.traversing.api
machinery instead of (only) dictionary lookups. This provides is with the flexibility of thezope.traversing.interfaces.ITraversable
adapter pattern, plus the support of namespace lookups (zope.traversing.namespace.nsParse()
andzope.traversing.namespace.namespaceLookup()
).As this object traverses, it fires
IBeforeTraverseEvent
events. If you either load the configuration fromzope.app.publication
or manually enable thezope.site.site.threadSiteSubscriber
to subscribe to this event, then any Zope site managers found along the way will be made the current site.
-
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 fromIDefaultBrowserLayer
to Interface. We connect the two by making the pyramid request implement the right thing.
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 defaultzope.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 usinginteraction_from_request()
), and then adapts the interaction into anIPrincipal
(probably usingprincipal_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.