##// END OF EJS Templates
py3: re-implement the BaseHTTPServer.test() function...
Pulkit Goyal -
r29565:143d21a7 default
parent child Browse files
Show More
@@ -15,6 +15,7 b' Any help will be greatly appreciated. '
15 __version__ = "0.2.1"
15 __version__ = "0.2.1"
16
16
17 import BaseHTTPServer
17 import BaseHTTPServer
18 import optparse
18 import os
19 import os
19 import select
20 import select
20 import socket
21 import socket
@@ -143,6 +144,19 b' class ThreadingHTTPServer (socketserver.'
143 a.write(str(os.getpid()) + "\n")
144 a.write(str(os.getpid()) + "\n")
144 a.close()
145 a.close()
145
146
147 def runserver(port=8000, bind=""):
148 server_address = (bind, port)
149 ProxyHandler.protocol_version = "HTTP/1.0"
150 httpd = ThreadingHTTPServer(server_address, ProxyHandler)
151 sa = httpd.socket.getsockname()
152 print("Serving HTTP on", sa[0], "port", sa[1], "...")
153 try:
154 httpd.serve_forever()
155 except KeyboardInterrupt:
156 print("\nKeyboard interrupt received, exiting.")
157 httpd.server_close()
158 sys.exit(0)
159
146 if __name__ == '__main__':
160 if __name__ == '__main__':
147 argv = sys.argv
161 argv = sys.argv
148 if argv[1:] and argv[1] in ('-h', '--help'):
162 if argv[1:] and argv[1] in ('-h', '--help'):
@@ -158,4 +172,13 b" if __name__ == '__main__':"
158 del argv[2:]
172 del argv[2:]
159 else:
173 else:
160 print("Any clients will be served...")
174 print("Any clients will be served...")
161 BaseHTTPServer.test(ProxyHandler, ThreadingHTTPServer)
175
176 parser = optparse.OptionParser()
177 parser.add_option('-b', '--bind', metavar='ADDRESS',
178 help='Specify alternate bind address '
179 '[default: all interfaces]', default='')
180 (options, args) = parser.parse_args()
181 port = 8000
182 if len(args) == 1:
183 port = int(args[0])
184 runserver(port, options.bind)
General Comments 0
You need to be logged in to leave comments. Login now