Mercurial > hg > lxmlmiddleware
annotate lxmlmiddleware/example.py @ 3:ca1f58f5bad4
pass a webob request and response to the manipulate method, API change, bumping version
author | k0s <k0scist@gmail.com> |
---|---|
date | Tue, 26 Jan 2010 22:57:00 -0500 |
parents | d1067d921e97 |
children |
rev | line source |
---|---|
0 | 1 from webob import Response |
2 from lxml import etree | |
3 from lxmlmiddleware.middleware import LXMLMiddleware | |
4 from paste.httpexceptions import HTTPExceptionHandler | |
5 | |
6 def example_app(environ, start_response): | |
7 return Response('<html><body>Hello, world!</body></html>')(environ, start_response) | |
8 | |
9 class ExampleMiddleware(LXMLMiddleware): | |
3
ca1f58f5bad4
pass a webob request and response to the manipulate method, API change, bumping version
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
10 def manipulate(self, request, response, tree): |
0 | 11 tree.append(etree.XML('<div><i>How are you doing?</i></div>')) |
12 return tree | |
13 | |
14 class ExampleMiddleware2(LXMLMiddleware): | |
3
ca1f58f5bad4
pass a webob request and response to the manipulate method, API change, bumping version
k0s <k0scist@gmail.com>
parents:
0
diff
changeset
|
15 def manipulate(self, request, response, tree): |
0 | 16 tree.append(etree.XML("<div><b>I'm doing find, thank you!</b></div>")) |
17 return tree | |
18 | |
19 def factory(global_conf, **app_conf): | |
20 """create a webob view and wrap it in middleware""" | |
21 return HTTPExceptionHandler(ExampleMiddleware2(ExampleMiddleware(example_app))) | |
22 |