This document points out some of the API differences between the Request and Response object, and the objects in other systems.
The Pylons request and response object are based on paste.wsgiwrappers.WSGIRequest and WSGIResponse
There is no concept of defaults in WebOb. In Paste/Pylons these serve as threadlocal settings that control certain policies on the request and response object. In WebOb you should make your own subclasses to control policy (though in many ways simply being explicit elsewhere removes the need for this policy).
There are also many extra methods and attributes on WebOb Request objects.
There are also many extra methods and attributes on WebOb Response objects.
This is a quick summary from reading the Django documentation.
QueryDict is the way Django represents the multi-key dictionary-like objects that are request variables (query string and POST body variables). The equivalent in WebOb is MultiDict.
The MultiDict object has a d.getone(key) method, that raises KeyError if there is not exactly one key. There is a method d.mixed() which returns a version where values are lists if there are multiple values for a list. This is similar to how many cgi-based request forms are represented.
These are generally like webob.exc objects. HttpResponseNotModified is HTTPNotModified; this naming translation generally works.
The CherryPy request object is also used by TurboGears 1.x.
From information from the wiki.
Yaro is a small wrapper around the WSGI environment, much like WebOb in scope.
The WebOb objects have many more methods and attributes. The Yaro Response object is a much smaller subset of WebOb’s Response.
An offshoot of Pocoo, this library is based around WSGI, similar to Paste and Yaro.
This is taken from the wrapper documentation.
You can achieve the same thing through res.body = result, or res.app_iter = result. res.body accepts None, a unicode string (if you have set a charset) or a normal string. res.app_iter only accepts None and an interable. You can’t update all of a response with one call.
Like in Zope, WebOb updates Content-Length. Unlike Zope, it does not automatically calculate a charset.
Some key attributes from the mod_python request object.
util.redirect or req.status = apache.HTTP_MOVED_TEMPORARILY:
from webob.exc import HTTPTemporaryRedirect exc = HTTPTemporaryRedirect(location=url) return exc(environ, start_response)
req.content_type = "application/x-csv" and req.headers_out.add('Content-Disposition', 'attachment;filename=somefile.csv'):
res = req.ResponseClass() res.content_type = 'application/x-csv' res.headers.add('Content-Disposition', 'attachment;filename=somefile.csv') return res(environ, start_response)
The Google App Engine webapp framework uses the WebOb Request object, but does not use its Response object.
The constructor for webapp.Response does not take any arguments. The response is created by the framework, so you don’t use it like return Response(...), instead you use self.response. Also the response object automatically has Cache-Control: no-cache set, while the WebOb response does not set any cache headers.
Besides exposing a .headers attribute (based on wsgiref.headers.Headers) there is no other API for the webapp response object. This means the response lacks:
PHP does not have anything really resembling a request and response object. Instead these are encoded in a set of global objects for the request and functions for the response.
These represent req.POST and req.GET.
PHP uses the variable names to tell whether a variable can hold multiple values. For instance $_POST['name'], which will be an array. In WebOb any variable can have multiple values, and you can get these through req.POST.getall('name').
The files in $_FILES are simply in req.POST in WebOb, as FieldStorage instances.
These are all in req.environ. These are not split up like they are in PHP, it’s all just one dictionary. Everything that would typically be in $_ENV is technically optional, and outside of a couple CGI-standard keys in $_SERVER most of those are also optional, but it is common for WSGI servers to populate the request with similar information as PHP.
This contains the unparsed data in the request body. This is in req.body.
Response headers in PHP are sent with header("Header-Name: value"). In WebOb there is a dictionary in resp.headers that can have values set; the headers aren’t actually sent until you send the response. You can add headers without overwriting (the equivalent of header("...", false)) with resp.headers.add('Header-Name', 'value').
The status in PHP is sent with http_send_status(code). In WebOb this is resp.status = code.
The body in PHP is sent implicitly through the rendering of the PHP body (or with echo or any other functions that send output).