Skip to content

Instantly share code, notes, and snippets.

@yuuichi-fujioka
Created April 15, 2013 02:14
Show Gist options
  • Save yuuichi-fujioka/5385221 to your computer and use it in GitHub Desktop.
Save yuuichi-fujioka/5385221 to your computer and use it in GitHub Desktop.
wsgi and mapper routing
from wsgiref import simple_server
from routes.mapper import Mapper
mapper = Mapper()
mapper.connect(None, '/Hoge/:id', action='hoge', conditions={'method':'GET'})
mapper.connect(None, '/Hoge/:id', action='detail', conditions={'method':'GET'})
mapper.connect(None, '/Hoge/:id', action='update', conditions={'method':'POST'})
def app(environ, start_response):
url = environ['PATH_INFO']
status = mapper.match(uri, environ)
if status is None:
start_response('404 Not Found', [('Content-Type', 'text/plain')])
return "Not Found"
else:
start_response('200 OK', [('Content-Type', 'text/plain')])
return status
if __name__ == '__main__':
server = simple_server.make_server('', 8080, app)
server.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment