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

I added some support for bare wsgi applications.
Usage should be clear but below is a working example anyway.
Please ignore prior merge request for same enhancement.
This one seems cleaner.

```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', [])
return {'message': 'Hello. World!'}

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