Created
April 15, 2013 02:14
-
-
Save yuuichi-fujioka/5385221 to your computer and use it in GitHub Desktop.
wsgi and mapper routing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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