OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """A tiny web server. | 6 """A tiny web server. |
7 | 7 |
8 This is intended to be used for testing, and only run from within the examples | 8 This is intended to be used for testing, and only run from within the examples |
9 directory. | 9 directory. |
10 """ | 10 """ |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 | 60 |
61 # An HTTP server that will quit when |is_running| is set to False. We also use | 61 # An HTTP server that will quit when |is_running| is set to False. We also use |
62 # SocketServer.ThreadingMixIn in order to handle requests asynchronously for | 62 # SocketServer.ThreadingMixIn in order to handle requests asynchronously for |
63 # faster responses. | 63 # faster responses. |
64 class QuittableHTTPServer(SocketServer.ThreadingMixIn, | 64 class QuittableHTTPServer(SocketServer.ThreadingMixIn, |
65 BaseHTTPServer.HTTPServer): | 65 BaseHTTPServer.HTTPServer): |
66 def serve_forever(self, timeout=0.5): | 66 def serve_forever(self, timeout=0.5): |
67 self.is_running = True | 67 self.is_running = True |
68 self.timeout = timeout | 68 self.timeout = timeout |
69 while self.is_running: | 69 while self.is_running: |
70 sys.stderr.flush() | |
noelallen1
2012/07/26 21:11:04
Should be harmless, but I would expect stderr to b
| |
71 sys.stdout.flush() | |
70 self.handle_request() | 72 self.handle_request() |
71 | 73 |
72 def shutdown(self): | 74 def shutdown(self): |
73 self.is_running = False | 75 self.is_running = False |
74 return 1 | 76 return 1 |
75 | 77 |
76 | 78 |
77 # "Safely" split a string at |sep| into a [key, value] pair. If |sep| does not | 79 # "Safely" split a string at |sep| into a [key, value] pair. If |sep| does not |
78 # exist in |str|, then the entire |str| is the key and the value is set to an | 80 # exist in |str|, then the entire |str| is the key and the value is set to an |
79 # empty string. | 81 # empty string. |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 parser.print_help() | 205 parser.print_help() |
204 elif len(args) == 2: | 206 elif len(args) == 2: |
205 Run((SERVER_HOST, int(args[1]))) | 207 Run((SERVER_HOST, int(args[1]))) |
206 else: | 208 else: |
207 Run((SERVER_HOST, SERVER_PORT)) | 209 Run((SERVER_HOST, SERVER_PORT)) |
208 return 0 | 210 return 0 |
209 | 211 |
210 | 212 |
211 if __name__ == '__main__': | 213 if __name__ == '__main__': |
212 sys.exit(main()) | 214 sys.exit(main()) |
OLD | NEW |