Mercurial > hg > RequestDumpster
comparison requestdumpster/dumpster.py @ 8:eb260393caef
this is about as far as I want to get without webob
| author | Jeff Hammel <k0scist@gmail.com> |
|---|---|
| date | Wed, 16 Dec 2015 10:51:32 -0800 |
| parents | 83c51f45b82d |
| children | db2ab581cedb |
comparison
equal
deleted
inserted
replaced
| 7:83c51f45b82d | 8:eb260393caef |
|---|---|
| 7 # imports | 7 # imports |
| 8 import argparse | 8 import argparse |
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| 11 import time | 11 import time |
| 12 import wsgiref | 12 from wsgiref import simple_server |
| 13 | 13 |
| 14 # module globals | 14 # module globals |
| 15 __all__ = ['RequestDumpster'] | 15 __all__ = ['RequestDumpster'] |
| 16 | 16 |
| 17 class RequestDumpster(object): | 17 class RequestDumpster(object): |
| 23 self.directory = directory | 23 self.directory = directory |
| 24 | 24 |
| 25 def __call__(self, environ, start_response): | 25 def __call__(self, environ, start_response): |
| 26 """WSGI""" | 26 """WSGI""" |
| 27 | 27 |
| 28 body = """{REQUEST_METHOD} {PATH_INFO} {SERVER_PROTOCOL}""".format(**environ) | |
| 29 | |
| 30 start_response('200 OK', [('Content-Type', 'text/plain')]) | |
| 31 return [body] | |
| 28 | 32 |
| 29 def main(args=sys.argv[1:]): | 33 def main(args=sys.argv[1:]): |
| 30 """CLI""" | 34 """CLI""" |
| 31 | 35 |
| 32 # parse command line arguments | 36 # parse command line arguments |
| 43 | 47 |
| 44 # construct url | 48 # construct url |
| 45 url = 'http://localhost:{port}/'.format(port=options.port) | 49 url = 'http://localhost:{port}/'.format(port=options.port) |
| 46 | 50 |
| 47 # serve some web | 51 # serve some web |
| 48 server = simple_server.make_server(host=host, port=int(port), app=app) | 52 host = '127.0.0.1' |
| 53 server = simple_server.make_server(host=host, | |
| 54 port=options.port, | |
| 55 app=app) | |
| 49 print url | 56 print url |
| 50 try: | 57 try: |
| 51 server.serve_forever() | 58 server.serve_forever() |
| 52 except KeyboardInterrupt: | 59 except KeyboardInterrupt: |
| 53 pass | 60 pass |
