Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Ticket #559: test.py

Line 
1 import cherrypy
2
3 # my middleware
4 class ChangeCase(object):
5     def __init__(self, app, to=None):
6         self.app = app
7         self.to = to
8
9     def __call__(self, environ, start_response):
10         response_iter = self.app(environ, start_response)
11         response_string = ''.join(response_iter)
12         if self.to == "upper":
13             return [response_string.upper()]
14         elif self.to == "lower":
15             return [response_string.lower()]
16         else:
17             return [response_string]
18
19 # register my middleware
20 cherrypy.wsgi.changecase = cherrypy.WSGIMiddleware(ChangeCase)
21
22 # my application
23 class Root(object):
24     def index(self):
25         return "HeLlO WoRlD!"
26     index.exposed = True
27
28 global_conf = {
29     'log.screen': True,
30 }
31
32 # configure the middleware_pipeline and middleware options
33 # for my application
34 root_conf = {
35     '/': {
36         'wsgi.middleware_pipeline': ['changecase'],
37         'wsgi.changecase.to': 'upper',
38     }
39 }
40
41 cherrypy.config.update(global_conf)
42 cherrypy.quickstart(Root(), script_name='/', conf=root_conf)

Hosted by WebFaction

Log in as guest/cpguest to create tickets