Browser API Reference


Browser Interfaces

interface zope.publisher.interfaces.browser.IBrowserApplicationRequest[source]

Extends: zope.publisher.interfaces.http.IHTTPApplicationRequest

Browser-specific requests


Return Browser request data

Request data are retrieved from one of:

  • Environment variables

    These variables include input headers, server data, and other request-related data. The variable names are as specified in the CGI specification.

  • Cookies

    These are the cookie data, if present.

  • Form data

Form data are searched before cookies, which are searched before environmental data.


Form data

This is a read-only mapping from name to form value for the name.

interface zope.publisher.interfaces.browser.IBrowserPublication[source]

Extends: zope.publisher.interfaces.IPublication

Object publication framework.

getDefaultTraversal(request, ob)

Get the default published object for the request

Allows a default view to be added to traversal. Returns (ob, steps_reversed).

interface zope.publisher.interfaces.browser.IBrowserRequest[source]

Extends: zope.publisher.interfaces.http.IHTTPRequest, zope.publisher.interfaces.ISkinnable

Browser-specific Request functionality.

Note that the browser is special in many ways, since it exposes the Request object to the end-developer.

interface zope.publisher.interfaces.browser.IBrowserPublisher[source]

Extends: zope.publisher.interfaces.IPublishTraverse

A type of IPublishTraverse that also supports default objects.


Provide the default object

The default object is expressed as a (possibly different) object and/or additional traversal steps.

Returns an object and a sequence of names. If the sequence of names is not empty, then a traversal step is made for each name. After the publisher gets to the end of the sequence, it will call browserDefault on the last traversed object.

Normal usage is to return self for object and a default view name.

The publisher calls this method at the end of each traversal path. If a non-empty sequence of names is returned, the publisher will traverse those names and call browserDefault again at the end.

Note that if additional traversal steps are indicated (via a nonempty sequence of names), then the publisher will try to adjust the base href.

interface zope.publisher.interfaces.browser.IBrowserPage[source]

Extends: zope.browser.interfaces.IBrowserView, zope.publisher.interfaces.browser.IBrowserPublisher

Browser page

__call__(*args, **kw)

Compute a response body

interface zope.publisher.interfaces.browser.IBrowserSkinType[source]

Extends: zope.publisher.interfaces.ISkinType

A skin is a set of layers.

interface zope.publisher.interfaces.browser.IDefaultBrowserLayer[source]

Extends: zope.publisher.interfaces.browser.IBrowserRequest

The default layer.


Browser-specific Publisher classes

Here we define the specific ‘BrowserRequest’ and ‘BrowserResponse’ class. The big improvement of the ‘BrowserRequest’ to ‘HTTPRequest’ is that is can handle HTML form data and convert them into a Python-native format. Even file data is packaged into a nice, Python-friendly ‘FileUpload’ object.

search(string[, pos[, endpos]]) –> match object or None. Scan through string looking for a match, and return a corresponding match object instance. Return None if no position in the string matches.

search(string[, pos[, endpos]]) –> match object or None. Scan through string looking for a match, and return a corresponding match object instance. Return None if no position in the string matches.


match(string[, pos[, endpos]]) –> match object or None. Matches zero or more characters at the beginning of the string


D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.

zope.publisher.browser.registerTypeConverter(field_type, converter, replace=False)[source]

Add a custom type converter to the registry.

o If ‘replace’ is not true, raise a KeyError if a converter is
already registered for ‘field_type’.
class zope.publisher.browser.BrowserRequest(body_instream, environ, response=None)[source]

Bases: zope.publisher.http.HTTPRequest


See IPublisherRequest


See IPublisherRequest.


See Interface.Common.Mapping.IEnumerableMapping

get(key, default=None)[source]

See Interface.Common.Mapping.IReadMapping

class zope.publisher.browser.FileUpload(aFieldStorage)[source]

Bases: object

File upload objects

File upload objects are used to represent file-uploaded data.

File upload objects can be used just like files.

In addition, they have a ‘headers’ attribute that is a dictionary containing the file-upload headers, and a ‘filename’ attribute containing the name of the uploaded file.

class zope.publisher.browser.RedirectingBrowserRequest(body_instream, environ, response=None)[source]

Bases: zope.publisher.browser.BrowserRequest

Browser requests that redirect when the actual and effective URLs differ

class zope.publisher.browser.TestRequest(body_instream=None, environ=None, form=None, skin=None, **kw)[source]

Bases: zope.publisher.browser.BrowserRequest

Browser request with a constructor convenient for testing

class zope.publisher.browser.BrowserResponse[source]

Bases: zope.publisher.http.HTTPResponse

Browser response

redirect(location, status=None, trusted=False)[source]

Causes a redirection without raising an error


See IResponse


Try to determine whether str is HTML or not.

exception zope.publisher.browser.NotCompatibleAdapterError[source]

Bases: exceptions.Exception

Adapter not compatible with zope.i18n.interfaces.IModifiableBrowserLanguages has been used.

class zope.publisher.browser.BrowserView(context, request)[source]

Bases: zope.location.location.Location

Browser View.

>>> view = BrowserView("context", "request")
>>> view.context
>>> view.request
>>> view.__parent__
>>> view.__parent__ = "parent"
>>> view.__parent__
class zope.publisher.browser.BrowserPage(context, request)[source]

Bases: zope.publisher.browser.BrowserView

Browser page

To create a page, which is an object that is published as a page, you need to provide an object that:

  • has a __call__ method and that
  • provides IBrowserPublisher, and
  • if ZPT is going to be used, then your object should also provide request and context attributes.

The BrowserPage base class provides a standard constructor and a simple implementation of IBrowserPublisher:

>>> class MyPage(BrowserPage):
...     pass
>>> request = TestRequest()
>>> context = object()
>>> page = MyPage(context, request)
>>> from zope.publisher.interfaces.browser import IBrowserPublisher
>>> IBrowserPublisher.providedBy(page)
>>> page.browserDefault(request) == (page, ())
>>> page.publishTraverse(request, 'bob') # doctest: +ELLIPSIS
Traceback (most recent call last):
NotFound: Object: <zope.publisher.browser.MyPage object at ...>, name: 'bob'
>>> page.request is request
>>> page.context is context

But it doesn’t supply a __call__ method:

>>> page()
Traceback (most recent call last):
NotImplementedError: Subclasses should override __call__ to provide a response body

It is the subclass’ responsibility to do that.