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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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', | 75 parser.add_argument('--address', action='store', |
76 type=str, nargs='?', | 76 type=str, nargs='?', |
77 default='127.0.01', | 77 default='127.0.0.1', |
78 help='Address to listen on [default: 127.0.0.1]') | 78 help='Address to listen on [default: 127.0.0.1]') |
79 parser.add_argument('output', action='store', | 79 parser.add_argument('output', action='store', |
80 type=str, nargs='?', default='-', | 80 type=str, nargs='?', default='-', |
81 help='The file where the logs will be written') | 81 help='The file where the logs will be written') |
82 args = parser.parse_args() | 82 args = parser.parse_args() |
83 if args.output and args.output != '-': | 83 if args.output and args.output != '-': |
84 fh = open(args.output, 'a') | 84 fh = open(args.output, 'a') |
85 else: | 85 else: |
86 fh = open(sys.stdout.fileno(), 'w', closefd=False) | 86 fh = open(sys.stdout.fileno(), 'w', closefd=False) |
87 try: | 87 try: |
88 Handler.output = fh | 88 Handler.output = fh |
89 Handler.format = args.format | 89 Handler.format = args.format |
90 Handler.response = args.response | 90 Handler.response = args.response |
91 server_address = (args.address, args.port) | 91 server_address = (args.address, args.port) |
92 httpd = HTTPServer(server_address, Handler) | 92 httpd = HTTPServer(server_address, Handler) |
93 httpd.serve_forever() | 93 httpd.serve_forever() |
94 finally: | 94 finally: |
95 fh.close() | 95 fh.close() |
LEFT | RIGHT |