Jesse Andrews | 6416407 | 2011-11-05 22:15:50 -0700 | [diff] [blame^] | 1 | import sys |
| 2 | from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler |
| 3 | from SimpleHTTPServer import SimpleHTTPRequestHandler |
| 4 | |
| 5 | def main(host, port, HandlerClass = SimpleHTTPRequestHandler, |
| 6 | ServerClass = HTTPServer, protocol="HTTP/1.0"): |
| 7 | """simple http server that listens on a give address:port""" |
| 8 | |
| 9 | server_address = (host, port) |
| 10 | |
| 11 | HandlerClass.protocol_version = protocol |
| 12 | httpd = ServerClass(server_address, HandlerClass) |
| 13 | |
| 14 | sa = httpd.socket.getsockname() |
| 15 | print "Serving HTTP on", sa[0], "port", sa[1], "..." |
| 16 | httpd.serve_forever() |
| 17 | |
| 18 | if __name__ == '__main__': |
| 19 | if sys.argv[1:]: |
| 20 | address = sys.argv[1] |
| 21 | else: |
| 22 | address = '0.0.0.0' |
| 23 | if ':' in address: |
| 24 | host, port = address.split(':') |
| 25 | else: |
| 26 | host = address |
| 27 | port = 8080 |
| 28 | |
| 29 | main(host, int(port)) |