from wheezy.http import HTTPResponse
from wheezy.http import WSGIApplication
from wheezy.routing import url
from wheezy.web.handlers import BaseHandler
from wheezy.web.middleware import bootstrap_defaults
from wheezy.web.middleware import path_routing_middleware_factory

class PingHandler(BaseHandler):

    def get(self):
        response = HTTPResponse()
        response.write('pong')
        return response

def ping(request):
    response = HTTPResponse()
    response.write('poong')
    return response

all_urls = [
    url('', PingHandler, name='default'),
    url('ping', ping, name='ping')
]

options = {}

main = WSGIApplication(
    middleware=[
        bootstrap_defaults(url_mapping=all_urls),
        path_routing_middleware_factory
    ],
    options=options
)

if __name__ == '__main__':
    from wsgiref.simple_server import make_server
    try:
        print('Visit http://localhost:8081/')
        make_server('', 8081, main).serve_forever()
    except KeyboardInterrupt:
        pass
    print('\nThanks!')

