OLD | NEW |
1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
2 # Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2010 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 """This is a simple HTTP server used for testing Chrome. | 6 """This is a simple HTTP server used for testing Chrome. |
7 | 7 |
8 It supports several test URLs, as specified by the handlers in TestPageHandler. | 8 It supports several test URLs, as specified by the handlers in TestPageHandler. |
9 It defaults to living on localhost:8888. | 9 It defaults to living on localhost:8888. |
10 It can use https if you specify the flag --https=CERT where CERT is the path | 10 It can use https if you specify the flag --https=CERT where CERT is the path |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 self.server.waitForDownload = False | 569 self.server.waitForDownload = False |
570 self.send_response(200) | 570 self.send_response(200) |
571 self.send_header('Content-type', 'text/html') | 571 self.send_header('Content-type', 'text/html') |
572 self.send_header('Cache-Control', 'max-age=0') | 572 self.send_header('Cache-Control', 'max-age=0') |
573 self.end_headers() | 573 self.end_headers() |
574 return True | 574 return True |
575 | 575 |
576 def _ReplaceFileData(self, data, query_parameters): | 576 def _ReplaceFileData(self, data, query_parameters): |
577 """Replaces matching substrings in a file. | 577 """Replaces matching substrings in a file. |
578 | 578 |
579 If the 'replace_orig' and 'replace_new' URL query parameters are present, | 579 If the 'replace_text' URL query parameter is present, it is expected to be |
580 a new string is returned with all occasions of the 'replace_orig' value | 580 of the form old_text:new_text, which indicates that any old_text strings in |
581 replaced by the 'replace_new' value. | 581 the file are replaced with new_text. Multiple 'replace_text' parameters may |
| 582 be specified. |
582 | 583 |
583 If the parameters are not present, |data| is returned. | 584 If the parameters are not present, |data| is returned. |
584 """ | 585 """ |
585 query_dict = cgi.parse_qs(query_parameters) | 586 query_dict = cgi.parse_qs(query_parameters) |
586 orig_values = query_dict.get('replace_orig', []) | 587 replace_text_values = query_dict.get('replace_text', []) |
587 new_values = query_dict.get('replace_new', []) | 588 for replace_text_value in replace_text_values: |
588 if not orig_values or not new_values: | 589 replace_text_args = replace_text_value.split(':') |
589 return data | 590 if len(replace_text_args) != 2: |
590 orig_value = orig_values[0] | 591 raise ValueError( |
591 new_value = new_values[0] | 592 'replace_text must be of form old_text:new_text. Actual value: %s' % |
592 return data.replace(orig_value, new_value) | 593 replace_text_value) |
| 594 old_text_b64, new_text_b64 = replace_text_args |
| 595 old_text = base64.urlsafe_b64decode(old_text_b64) |
| 596 new_text = base64.urlsafe_b64decode(new_text_b64) |
| 597 data = data.replace(old_text, new_text) |
| 598 return data |
593 | 599 |
594 def FileHandler(self): | 600 def FileHandler(self): |
595 """This handler sends the contents of the requested file. Wow, it's like | 601 """This handler sends the contents of the requested file. Wow, it's like |
596 a real webserver!""" | 602 a real webserver!""" |
597 | 603 |
598 prefix = self.server.file_root_url | 604 prefix = self.server.file_root_url |
599 if not self.path.startswith(prefix): | 605 if not self.path.startswith(prefix): |
600 return False | 606 return False |
601 | 607 |
602 # Consume a request body if present. | 608 # Consume a request body if present. |
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1274 'option may appear multiple times, indicating ' | 1280 'option may appear multiple times, indicating ' |
1275 'multiple algorithms should be enabled.'); | 1281 'multiple algorithms should be enabled.'); |
1276 option_parser.add_option('', '--file-root-url', default='/files/', | 1282 option_parser.add_option('', '--file-root-url', default='/files/', |
1277 help='Specify a root URL for files served.') | 1283 help='Specify a root URL for files served.') |
1278 option_parser.add_option('', '--startup-pipe', type='int', | 1284 option_parser.add_option('', '--startup-pipe', type='int', |
1279 dest='startup_pipe', | 1285 dest='startup_pipe', |
1280 help='File handle of pipe to parent process') | 1286 help='File handle of pipe to parent process') |
1281 options, args = option_parser.parse_args() | 1287 options, args = option_parser.parse_args() |
1282 | 1288 |
1283 sys.exit(main(options, args)) | 1289 sys.exit(main(options, args)) |
OLD | NEW |