Mercurial > hg > RequestDumpster
view requestdumpster/dumpster.py @ 6:aa19f80caa63
more stubbing
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Wed, 01 Jul 2015 08:42:12 -0700 |
parents | afa7a874d28e |
children | 83c51f45b82d |
line wrap: on
line source
#!/usr/bin/env python """ dump HTTP requests """ # imports import optparse import os import sys import time import wsgiref # module globals __all__ = ['RequestDumpster'] class RequestDumpster(object): """WSGI interface to dump HTTP requests""" def __init__(self, directory=None): if directory is not None and not os.path.isdir(directory): raise Exception("Not a directory") self.directory = directory def __call__(self, environ, start_response): """WSGI""" def main(args=sys.argv[1:]): """CLI""" # parse command line arguments parser = optparse.OptionParser(description=__doc__) parser.add_option('-p', '--port', dest='port', type='int', default=9555, help="port to serve on") parser.add_option('-d', '--directory', dest='directory', help="directory to output requests to") options = parser.parse_args() # instantiate WSGI app app = RequestDumpster(directory=options.directory) # construct url url = 'http://localhost:{port}/'.format(port=options.port) # serve some web server = simple_server.make_server(host=host, port=int(port), app=app) server.serve_forever() if __name__ == '__main__': main()