martinblech/mimerender — pull request #22 by ericfrederich (2013-06-05 23:27:37+00:00)
Title: Add wsgi support

I added some support for bare wsgi applications.
Usage should be clear but here is a working example anyway:

```python
#!/usr/bin/env python
import wsgiref
import mimerender
import json

mimerender = mimerender.WSGIMimeRender()

render_xml = lambda message: '%s'%message
render_json = lambda **args: json.dumps(args)
render_html = lambda message: '

%s

'%message
render_txt = lambda message: message

@mimerender(
default = 'html',
html = render_html,
xml = render_xml,
json = render_json,
txt = render_txt
)
def hello_world(environ, start_response):
start_response('200 OK', [
# ('Content-Type', 'text/html'),
])
return {'message': 'Hello. World!'}

if __name__ == '__main__':
from wsgiref.simple_server import make_server
srv = make_server('localhost', 8080, hello_world)
srv.serve_forever()
```