| Left: | ||
| Right: |
| 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 parser.add_argument('--response', action='store', | 65 parser.add_argument('--response', action='store', |
| 66 type=str, nargs='?', default='OK', | 66 type=str, nargs='?', default='OK', |
| 67 help='The response send to the client') | 67 help='The response send to the client') |
| 68 parser.add_argument('--format', action='store', | 68 parser.add_argument('--format', action='store', |
| 69 type=str, nargs='?', | 69 type=str, nargs='?', |
| 70 default=DEFAULT_LOG, | 70 default=DEFAULT_LOG, |
| 71 help='Format of the log ouput') | 71 help='Format of the log ouput') |
| 72 parser.add_argument('output', action='store', | 72 parser.add_argument('output', action='store', |
| 73 type=str, nargs='?', default='-', | 73 type=str, nargs='?', default='-', |
| 74 help='The file where the logs will be written') | 74 help='The file where the logs will be written') |
| 75 args = parser.parse_args() | |
| 76 if args.output and args.output != '-': | |
| 77 fh = open(args.output, 'a') | |
| 78 else: | |
| 79 fh = open(sys.stdout.fileno(), 'w', closefd=False) | |
| 75 try: | 80 try: |
| 76 args = parser.parse_args() | |
| 77 if args.output and args.output != '-': | |
| 78 fh = open(args.output, 'a') | |
| 79 else: | |
| 80 fh = open(sys.stdout.fileno(), 'w', closefd=False) | |
| 81 Handler.output = fh | 81 Handler.output = fh |
| 82 Handler.format = args.format | 82 Handler.format = args.format |
| 83 Handler.response = args.response | 83 Handler.response = args.response |
| 84 server_address = ('', args.port) | 84 server_address = ('', args.port) |
| 85 httpd = HTTPServer(server_address, Handler) | 85 httpd = HTTPServer(server_address, Handler) |
| 86 httpd.serve_forever() | 86 httpd.serve_forever() |
| 87 except: | 87 finally: |
|
mathias
2017/08/21 07:37:42
Shouldn't this be `finally`?
f.lopez
2017/08/21 19:54:12
Done.
| |
| 88 fh.close() | 88 fh.close() |
| LEFT | RIGHT |