| 83 | 1 #!/usr/bin/env python | 
|  | 2 | 
|  | 3 """ | 
|  | 4 web handler for {{project}} | 
|  | 5 """ | 
|  | 6 | 
| 217 | 7 # imports | 
|  | 8 import argparse | 
|  | 9 import sys | 
| 118 | 10 from webob import Request, Response, exc | 
| 217 | 11 from wsgiref import simple_server | 
| 83 | 12 | 
|  | 13 class Handler(object): | 
| 217 | 14     """WSGI HTTP Handler""" | 
| 83 | 15 | 
|  | 16     def __init__(self, **kw): | 
|  | 17         pass | 
|  | 18 | 
|  | 19     def __call__(self, environ, start_response): | 
|  | 20         request = Request(environ) | 
|  | 21         response = Response(content_type='text/plain', | 
|  | 22                             body="{{project}}") | 
|  | 23         return response(environ, start_response) | 
|  | 24 | 
| 217 | 25 def main(args=sys.argv[1:]): | 
|  | 26     """CLI""" | 
|  | 27 | 
|  | 28     # parse command line | 
|  | 29     parser = argparse.ArgumentParser(description=__doc__) | 
|  | 30     parser.add_argument('-p', '--port', dest='port', | 
|  | 31                         type=int, default=8080, | 
|  | 32                         help="port to serve on") | 
|  | 33     options = parser.parse_arguments(args) | 
|  | 34 | 
|  | 35     # instantiate WSGI handler | 
| 83 | 36     app = Handler() | 
| 217 | 37 | 
|  | 38     # serve it (Warning! Single threaded!) | 
|  | 39     server = simple_server.make_server(host='0.0.0.0', | 
|  | 40                                        port=options.port | 
|  | 41                                        app=app) | 
|  | 42     try: | 
|  | 43         server.serve_forever() | 
|  | 44     except KeyboardInterrupt: | 
|  | 45         pass | 
|  | 46 | 
|  | 47 if __name__ == '__main__': | 
|  | 48     main() |