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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d1067d921e97 initial import of lxml middleware
k0s <k0scist@gmail.com>
parents:
diff changeset
1 from webob import Response
d1067d921e97 initial import of lxml middleware
k0s <k0scist@gmail.com>
parents:
diff changeset
2 from lxml import etree
d1067d921e97 initial import of lxml middleware
k0s <k0scist@gmail.com>
parents:
diff changeset
3 from lxmlmiddleware.middleware import LXMLMiddleware
d1067d921e97 initial import of lxml middleware
k0s <k0scist@gmail.com>
parents:
diff changeset
4 from paste.httpexceptions import HTTPExceptionHandler
d1067d921e97 initial import of lxml middleware
k0s <k0scist@gmail.com>
parents:
diff changeset
5
d1067d921e97 initial import of lxml middleware
k0s <k0scist@gmail.com>
parents:
diff changeset
6 def example_app(environ, start_response):
d1067d921e97 initial import of lxml middleware
k0s <k0scist@gmail.com>
parents:
diff changeset
7 return Response('<html><body>Hello, world!</body></html>')(environ, start_response)
d1067d921e97 initial import of lxml middleware
k0s <k0scist@gmail.com>
parents:
diff changeset
8
d1067d921e97 initial import of lxml middleware
k0s <k0scist@gmail.com>
parents:
diff changeset
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
d1067d921e97 initial import of lxml middleware
k0s <k0scist@gmail.com>
parents:
diff changeset
11 tree.append(etree.XML('<div><i>How are you doing?</i></div>'))
d1067d921e97 initial import of lxml middleware
k0s <k0scist@gmail.com>
parents:
diff changeset
12 return tree
d1067d921e97 initial import of lxml middleware
k0s <k0scist@gmail.com>
parents:
diff changeset
13
d1067d921e97 initial import of lxml middleware
k0s <k0scist@gmail.com>
parents:
diff changeset
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
d1067d921e97 initial import of lxml middleware
k0s <k0scist@gmail.com>
parents:
diff changeset
16 tree.append(etree.XML("<div><b>I'm doing find, thank you!</b></div>"))
d1067d921e97 initial import of lxml middleware
k0s <k0scist@gmail.com>
parents:
diff changeset
17 return tree
d1067d921e97 initial import of lxml middleware
k0s <k0scist@gmail.com>
parents:
diff changeset
18
d1067d921e97 initial import of lxml middleware
k0s <k0scist@gmail.com>
parents:
diff changeset
19 def factory(global_conf, **app_conf):
d1067d921e97 initial import of lxml middleware
k0s <k0scist@gmail.com>
parents:
diff changeset
20 """create a webob view and wrap it in middleware"""
d1067d921e97 initial import of lxml middleware
k0s <k0scist@gmail.com>
parents:
diff changeset
21 return HTTPExceptionHandler(ExampleMiddleware2(ExampleMiddleware(example_app)))
d1067d921e97 initial import of lxml middleware
k0s <k0scist@gmail.com>
parents:
diff changeset
22