Browser API Reference¶
Interfaces¶
Browser Interfaces
-
interface
zope.publisher.interfaces.browser.
IBrowserApplicationRequest
[source]¶ Extends:
zope.publisher.interfaces.http.IHTTPApplicationRequest
Browser-specific requests
-
__getitem__
(key)¶ 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 <a href=”http://hoohoo.ncsa.uiuc.edu/cgi/env.html“>specified</a> in the <a href=”http://hoohoo.ncsa.uiuc.edu/cgi/interface.html“>CGI specification</a>
Cookies
These are the cookie data, if present.
Form data
Form data are searched before cookies, which are searched before environmental data.
-
form
¶ 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.
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.
Implementation¶
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.
-
zope.publisher.browser.
start_of_header_search
()¶ 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.
-
zope.publisher.browser.
base_re_search
()¶ 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.
-
zope.publisher.browser.
isRelative
()¶ match(string[, pos[, endpos]]) –> match object or None. Matches zero or more characters at the beginning of the string
-
zope.publisher.browser.
get_converter
()¶ 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.
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
-
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 'context' >>> view.request 'request'
>>> view.__parent__ 'context' >>> view.__parent__ = "parent" >>> view.__parent__ '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) True
>>> page.browserDefault(request) == (page, ()) True
>>> page.publishTraverse(request, 'bob') Traceback (most recent call last): ... NotFound: Object: <zope.publisher.browser.MyPage object at ...>, name: 'bob'
>>> page.request is request True
>>> page.context is context True
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.