Mercurial > hg > RequestDumpster
comparison requestdumpster/dumpster.py @ 5:afa7a874d28e
dumpster;
| author | Jeff Hammel <k0scist@gmail.com> |
|---|---|
| date | Tue, 30 Jun 2015 18:10:15 -0700 |
| parents | f2f983b76090 |
| children | aa19f80caa63 |
comparison
equal
deleted
inserted
replaced
| 4:297f50637d4e | 5:afa7a874d28e |
|---|---|
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| 11 import time | 11 import time |
| 12 import wsgiref | 12 import wsgiref |
| 13 | 13 |
| 14 # module globals | |
| 15 __all__ = ['RequestDumpster'] | |
| 16 | |
| 14 class RequestDumpster(object): | 17 class RequestDumpster(object): |
| 18 """WSGI interface to dump HTTP requests""" | |
| 15 | 19 |
| 16 def __init__(self, directory=None): | 20 def __init__(self, directory=None): |
| 17 if directory is not None and not os.path.isdir(directory): | 21 if directory is not None and not os.path.isdir(directory): |
| 18 raise Exception("Not a directory") | 22 raise Exception("Not a directory") |
| 19 self.directory = directory | 23 self.directory = directory |
| 20 | 24 |
| 21 | |
| 22 def __call__(self, environ, start_response): | 25 def __call__(self, environ, start_response): |
| 23 """WSGI""" | 26 """WSGI""" |
| 27 | |
| 24 | 28 |
| 25 def main(args=sys.argv[1:]): | 29 def main(args=sys.argv[1:]): |
| 26 """CLI""" | 30 """CLI""" |
| 27 | 31 |
| 28 # parse command line arguments | 32 # parse command line arguments |
| 29 parser = optparse.OptionParser(description=__doc__) | 33 parser = optparse.OptionParser(description=__doc__) |
| 30 parser.add_option('-p', '--port', dest='port', | 34 parser.add_option('-p', '--port', dest='port', |
| 31 type='int', default=9555, | 35 type='int', default=9555, |
| 32 help="port to serve on") | 36 help="port to serve on") |
| 37 parser.add_option('-d', '--directory', dest='directory', | |
| 38 help="directory to output requests to") | |
| 33 options = parser.parse_args() | 39 options = parser.parse_args() |
| 34 | 40 |
| 41 # instantiate WSGI app | |
| 42 app = | |
| 43 | |
| 35 # construct url | 44 # construct url |
| 36 url = 'http://localhost:{port}/'.format(port=options.port) | 45 url = 'http://localhost:{port}/'.format(port=options.port) |
| 37 | 46 |
| 38 if __name__ == '__main__': | 47 if __name__ == '__main__': |
| 39 main() | 48 main() |
