Base API Reference


Interfaces for the publisher.

interface zope.publisher.interfaces.IPublishingException[source]

Extends: zope.interface.common.interfaces.IException

An exception that occurs during publication.

exception zope.publisher.interfaces.PublishingException[source]

Bases: exceptions.Exception

Default implementation of IPublishingException.

interface zope.publisher.interfaces.ITraversalException[source]

Extends: zope.publisher.interfaces.IPublishingException

An exception that occurs during publication traversal.

exception zope.publisher.interfaces.TraversalException[source]

Bases: zope.publisher.interfaces.PublishingException

Default implementation of ITraversalException.

interface zope.publisher.interfaces.INotFound[source]

Extends: zope.interface.common.interfaces.ILookupError, zope.publisher.interfaces.ITraversalException

The object we want to traverse to cannot be found.


Returns the object that was being traversed.


Returns the name that was being traversed.

exception zope.publisher.interfaces.NotFound(ob, name, request=None)[source]

Bases: exceptions.LookupError, zope.publisher.interfaces.TraversalException

Default implementation of INotFound.

interface zope.publisher.interfaces.IDebugError[source]

Extends: zope.publisher.interfaces.ITraversalException

A debug error.


Returns the object being traversed.


Returns the debug message.

exception zope.publisher.interfaces.DebugError(ob, message)[source]

Bases: zope.publisher.interfaces.TraversalException

Default implementation of IDebugError.

interface zope.publisher.interfaces.IBadRequest[source]

Extends: zope.publisher.interfaces.IPublishingException

The request is bad.


Returns the error message.

exception zope.publisher.interfaces.BadRequest(message)[source]

Bases: zope.publisher.interfaces.PublishingException

Default implementation of IBadRequest.

interface zope.publisher.interfaces.IRedirect[source]

Extends: zope.publisher.interfaces.IPublishingException

An exception that redirects the client.


Returns the location.


Returns the trusted value.

exception zope.publisher.interfaces.Redirect(location, trusted=False)[source]

Bases: zope.publisher.interfaces.PublishingException

Default implementation of IRedirect.

interface zope.publisher.interfaces.IRetry[source]

Extends: zope.publisher.interfaces.IPublishingException

An exception that indicates a request should be retried.


Returns the original exception object.

exception zope.publisher.interfaces.Retry(orig_exc=None)[source]

Bases: zope.publisher.interfaces.PublishingException

Default implementation of IRetry.

orig_exc must be a 3-tuple as returned from sys.exc_info() …

or None.

interface zope.publisher.interfaces.IExceptionSideEffects[source]

An exception caught by the publisher is adapted to this so that it can have persistent side-effects.

__call__(obj, request, exc_info)

Effect persistent side-effects.

Arguments are:
obj context-wrapped object that was published request the request exc_info the exception info being handled
interface zope.publisher.interfaces.IPublishTraverse[source]

Traversal for the specific purpose of publishing.

publishTraverse(request, name)

Lookup a name

The ‘request’ argument is the publisher request object. The ‘name’ argument is the name that is to be looked up; it must be an ASCII string or Unicode object.

If a lookup is not possible, raise a NotFound error.

This method should return an object having the specified name and self as parent. The method can use the request to determine the correct object.

interface zope.publisher.interfaces.IPublisher[source]

An object that can publish.


Publish a request

The request must be an IPublisherRequest.

interface zope.publisher.interfaces.IResponse[source]

Interface used by the publsher


Sets the response result value.


Handles an exception.

This method is intended only as a convenience for the publication object. The publication object can choose to handle exceptions by calling this method. The publication object can also choose not to call this method at all.

Implementations set the reponse body.


Called when the exception handler bombs.

Should report back to the client that an internal error occurred.


Reset the output result.

Reset the response by nullifying already set variables.


Returns a retry response

Returns a response suitable for repeating the publication attempt.

interface zope.publisher.interfaces.IPublication[source]

Object publication framework.

The responsibility of publication objects is to provide application hooks for the publishing process. This allows application-specific tasks, such as connecting to databases, managing transactions, and setting security contexts to be invoked during the publishing process.


Pre-traversal hook.

This is called once before any traversal has been done.


Returns the object where traversal should commence.

callTraversalHooks(request, ob)

Invokes any traversal hooks associated with the object.

This is called before traversing each object. The ob argument is the object that is about to be traversed.

traverseName(request, ob, name)

Traverses to the next object.

Name must be an ASCII string or Unicode object.

afterTraversal(request, ob)

Post-traversal hook.

This is called after all traversal.

callObject(request, ob)

Call the object, returning the result.

For GET/POST this means calling it, but for other methods (including those of WebDAV and FTP) this might mean invoking a method of an adapter.

afterCall(request, ob)

Post-callObject hook (if it was successful).

handleException(object, request, exc_info, retry_allowed=1)

Handle an exception

Either: - sets the body of the response, request.response, or - raises a Retry exception, or - throws another exception, which is a Bad Thing.

endRequest(request, ob)

Do any end-of-request cleanup

interface zope.publisher.interfaces.IPublicationRequest[source]


Interface provided by requests to IPublication objects


The request’s response object

Return an IPublisherResponse for the request.


Release resources held by the request.


Hold a reference to an object until the request is closed.

The object should be an IHeld. If it is an IHeld, its release method will be called when it is released.


Return the request traversal stack

This is a sequence of steps to traverse in reverse order. They will be traversed from last to first.


Change the traversal stack.

See getTraversalStack.


Return the positional arguments given to the request.


Set the principal attribute.

It should be IPrincipal wrapped in its AuthenticationService’s context.

interface zope.publisher.interfaces.IHeld[source]

Object to be held and explicitly released by a request


Release the held object

This is called by a request that holds the IHeld when the request is closed

interface zope.publisher.interfaces.IPublisherRequest[source]

Extends: zope.publisher.interfaces.IPublicationRequest

Request interface use by the publisher

The responsibility of requests is to encapsulate protocol specific details, especially wrt request inputs.

Request objects also serve as “context” objects, providing construction of and access to responses and storage of publication objects.


Check whether the request supports retry

Return a boolean value indicating whether the request can be retried.


Return a retry request

Return a request suitable for repeating the publication attempt.


The request’s publication object

The publication object, an IRequestPublication provides application-specific functionality hooks.


Set the request’s publication object


Traverse from the given object to the published object

The published object is returned.

The following hook methods on the publication will be called:

  • callTraversalHooks is called before each step and after the last step.
  • traverseName to actually do a single traversal

Do any input processing that needs to be done before traversing

This is done after construction to allow the publisher to handle errors that arise.

interface zope.publisher.interfaces.IDebugFlags[source]

Features that support debugging.


Enable ZPT source annotations


Leave TAL markup in rendered page templates

interface zope.publisher.interfaces.IApplicationRequest[source]

Extends: zope.interface.common.mapping.IEnumerableMapping

Features that support application logic


Principal object associated with the request This is a read-only attribute.


The stream that provides the data of the request.

The data returned by the stream will not include any possible header information, which should have been stripped by the server (or previous layer) before.

Also, the body stream might already be read and not return any data. This is commonly done when retrieving the data for the body attribute.

If you access this stream directly to retrieve data, it will not be possible by other parts of the framework to access the data of the request via the body attribute.


Debug flags (see IDebugFlags).


Return request data

The only request data are environment variables.


Request environment data

This is a read-only mapping from variable name to value.


Stores arbitrary application data under package-unique keys.

By “package-unique keys”, we mean keys that are are unique by virtue of including the dotted name of a package as a prefex. A package name is used to limit the authority for picking names for a package to the people using that package.

For example, when implementing annotations for hypothetical request-persistent adapters in a hypothetical zope.persistentadapter package, the key would be (or at least begin with) the following:

interface zope.publisher.interfaces.IRequest[source]

Extends: zope.publisher.interfaces.IPublisherRequest, zope.publisher.interfaces.IPublicationRequest, zope.publisher.interfaces.IApplicationRequest

The basic request contract

interface zope.publisher.interfaces.IRequestEvent[source]

An event which is about or for a request.


The request this event is about.

interface zope.publisher.interfaces.IEndRequestEvent[source]

Extends: zope.publisher.interfaces.IRequestEvent

An event which gets sent when the publication is ended.

interface zope.publisher.interfaces.IStartRequestEvent[source]

Extends: zope.publisher.interfaces.IRequestEvent

An event which gets sent before publication of a request.

class zope.publisher.interfaces.RequestEvent(request)[source]

Bases: object

Events for requests.

Parameters:request – The request the event is for.
class zope.publisher.interfaces.EndRequestEvent(ob, request)[source]

Bases: zope.publisher.interfaces.RequestEvent

An event which gets sent when the publication is ended

class zope.publisher.interfaces.StartRequestEvent(request)[source]

Bases: zope.publisher.interfaces.RequestEvent

An event send when before publication of a request.

interface zope.publisher.interfaces.ISkinType[source]

Extends: zope.interface.interfaces.IInterface

Base interface for skin types.

interface zope.publisher.interfaces.ISkinnable[source]

A skinnable (request) can provide a skin.

The implementation in BrowserRequest will apply a default skin/layer called IDefaultBrowserLayer if not default skin get registered.

interface zope.publisher.interfaces.IDefaultSkin[source]

Any component providing this interface must be a skin.

This is a marker interface, so that we can register the default skin as an adapter from the presentation type to IDefaultSkin.

interface zope.publisher.interfaces.ISkinChangedEvent[source]

Extends: zope.publisher.interfaces.IRequestEvent

Event that gets triggered when the skin of a request is changed.

interface zope.publisher.interfaces.IDefaultViewName[source]

A string that contains the default view name

A default view name is used to select a view when a user hasn’t specified one.

interface zope.publisher.interfaces.IReRaiseException[source]

An exception that should be reraised, when handled in publisher.

Under some circumstances (for instance if acting in a WSGI pipeline with debugger middleware) certain exceptions occuring while publishing should be handled by the Zope machinery and never reach the ‘outside world’.

Adapters providing this interface for a certain exception type which also return False when being called, indicate by this that the exception should not be reraised during publishing.

This makes it possible, for instance, to authenticate with basic-auth when a debugger middleware is used and IUnauthorized is raised.


Return True if an exception should be re-raised


Base implementations of the Publisher objects

Specifically, ‘BaseRequest’, ‘BaseResponse’, and ‘DefaultPublication’ are specified here.

class zope.publisher.base.BaseResponse[source]

Bases: object

Base Response Class


See IPublisherResponse


See IPublisherResponse


See IPublisherResponse


See IPublisherResponse


See IPublisherResponse

class zope.publisher.base.DebugFlags[source]

Bases: object

Debugging flags.

class zope.publisher.base.BaseRequest(body_instream, environ, response=None, positional=None)[source]

Bases: object

Represents a publishing request.

This object provides access to request data. Request data may vary depending on the protocol used.

Request objects are created by the object publisher and will be passed to published objects through the argument name, REQUEST.

The request object is a mapping object that represents a collection of variable to value mappings.


See IPublisherRequest.


See IPublisherRequest.


See IPublisherRequest.


See IPublisherRequest.


See IPublisherRequest.


See IPublisherRequest.


See IPublicationRequest.


See IPublicationRequest.


See IPublicationRequest.


See IPublicationRequest.


See IPublicationRequest.


See zope.publisher.interfaces.IApplicationRequest.


See Interface.Common.Mapping.IEnumerableMapping.


See Interface.Common.Mapping.IEnumerableMapping.


See Interface.Common.Mapping.IEnumerableMapping.

get(key, default=None)[source]

See Interface.Common.Mapping.IReadMapping.


See Interface.Common.Mapping.IReadMapping.

class zope.publisher.base.TestRequest(path, body_instream=None, environ=None)[source]

Bases: zope.publisher.base.BaseRequest

class zope.publisher.base.DefaultPublication(app)[source]

Bases: object

A stub publication.

This works just like Zope2’s ZPublisher. It rejects any name starting with an underscore and any objects (specifically: method) that doesn’t have a docstring.

class zope.publisher.base.TestPublication(app)[source]

Bases: zope.publisher.base.DefaultPublication