| LEFT | RIGHT | 
|   1 #!/usr/bin/env python3 |   1 #!/usr/bin/env python3 | 
|   2  |   2  | 
|   3 import argparse |   3 import argparse | 
|   4 import re |   4 import re | 
|   5 import sys |   5 import sys | 
|   6 import threading |   6 import threading | 
|   7 import traceback |   7 import traceback | 
|   8  |   8  | 
|   9 from http.server import BaseHTTPRequestHandler, HTTPServer |   9 from http.server import BaseHTTPRequestHandler, HTTPServer | 
|  10 from string import Template |  10 from string import Template | 
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  65                         default=8000, type=int, |  65                         default=8000, type=int, | 
|  66                         nargs='?', |  66                         nargs='?', | 
|  67                         help='Port to use [default: 8000]') |  67                         help='Port to use [default: 8000]') | 
|  68     parser.add_argument('--response', action='store', |  68     parser.add_argument('--response', action='store', | 
|  69                         type=str, nargs='?', default='OK', |  69                         type=str, nargs='?', default='OK', | 
|  70                         help='The response send to the client') |  70                         help='The response send to the client') | 
|  71     parser.add_argument('--format', action='store', |  71     parser.add_argument('--format', action='store', | 
|  72                         type=str, nargs='?', |  72                         type=str, nargs='?', | 
|  73                         default=DEFAULT_LOG, |  73                         default=DEFAULT_LOG, | 
|  74                         help='Format of the log ouput') |  74                         help='Format of the log ouput') | 
 |  75     parser.add_argument('--address', action='store', | 
 |  76                         type=str, nargs='?', | 
 |  77                         default='127.0.0.1', | 
 |  78                         help='Address to listen on [default: 127.0.0.1]') | 
|  75     parser.add_argument('output', action='store', |  79     parser.add_argument('output', action='store', | 
|  76                         type=str, nargs='?', default='-', |  80                         type=str, nargs='?', default='-', | 
|  77                         help='The file where the logs will be written') |  81                         help='The file where the logs will be written') | 
|  78     args = parser.parse_args() |  82     args = parser.parse_args() | 
|  79     if args.output and args.output != '-': |  83     if args.output and args.output != '-': | 
|  80         fh = open(args.output, 'a') |  84         fh = open(args.output, 'a') | 
|  81     else: |  85     else: | 
|  82         fh = open(sys.stdout.fileno(), 'w', closefd=False) |  86         fh = open(sys.stdout.fileno(), 'w', closefd=False) | 
|  83     try: |  87     try: | 
|  84         Handler.output = fh |  88         Handler.output = fh | 
|  85         Handler.format = args.format |  89         Handler.format = args.format | 
|  86         Handler.response = args.response |  90         Handler.response = args.response | 
|  87         server_address = ('127.0.0.1', args.port) |  91         server_address = (args.address, args.port) | 
|  88         httpd = HTTPServer(server_address, Handler) |  92         httpd = HTTPServer(server_address, Handler) | 
|  89         httpd.serve_forever() |  93         httpd.serve_forever() | 
|  90     finally: |  94     finally: | 
|  91         fh.close() |  95         fh.close() | 
| LEFT | RIGHT |