| 1 |
import cherrypy |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 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 |
|
|---|
| 20 |
cherrypy.wsgi.changecase = cherrypy.WSGIMiddleware(ChangeCase) |
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 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 |
|
|---|
| 33 |
|
|---|
| 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) |
|---|