OLD | NEW |
1 # Copyright 2012 The Chromium Authors. All rights reserved. | 1 # Copyright 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Start and stop Web Page Replay. | 5 """Start and stop Web Page Replay. |
6 | 6 |
7 Of the public module names, the following one is key: | 7 Of the public module names, the following one is key: |
8 ReplayServer: a class to start/stop Web Page Replay. | 8 ReplayServer: a class to start/stop Web Page Replay. |
9 """ | 9 """ |
10 | 10 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 elif not self.https_port and m.group('protocol') == 'HTTPS': | 170 elif not self.https_port and m.group('protocol') == 'HTTPS': |
171 self.https_port = int(m.group('port')) | 171 self.https_port = int(m.group('port')) |
172 elif not self.dns_port and m.group('protocol') == 'DNS': | 172 elif not self.dns_port and m.group('protocol') == 'DNS': |
173 self.dns_port = int(m.group('port')) | 173 self.dns_port = int(m.group('port')) |
174 | 174 |
175 # Try to connect to the WPR ports. | 175 # Try to connect to the WPR ports. |
176 if self.http_port and self.https_port: | 176 if self.http_port and self.https_port: |
177 try: | 177 try: |
178 up_url = '%s://%s:%s/web-page-replay-generate-200' | 178 up_url = '%s://%s:%s/web-page-replay-generate-200' |
179 http_up_url = up_url % ('http', self._replay_host, self.http_port) | 179 http_up_url = up_url % ('http', self._replay_host, self.http_port) |
180 https_up_url = up_url % ('https', self._replay_host, self.https_port) | 180 if (200 == urllib.urlopen(http_up_url, None, {}).getcode()): |
181 if (200 == urllib.urlopen(http_up_url, None, {}).getcode() and | |
182 200 == urllib.urlopen(https_up_url, None, {}).getcode()): | |
183 return True | 181 return True |
184 except IOError: | 182 except IOError: |
185 pass | 183 pass |
186 return False | 184 return False |
187 | 185 |
188 def StartServer(self): | 186 def StartServer(self): |
189 """Start Web Page Replay and verify that it started. | 187 """Start Web Page Replay and verify that it started. |
190 | 188 |
191 Raises: | 189 Raises: |
192 ReplayNotStartedError: if Replay start-up fails. | 190 ReplayNotStartedError: if Replay start-up fails. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 self.replay_process.wait() | 238 self.replay_process.wait() |
241 | 239 |
242 def __enter__(self): | 240 def __enter__(self): |
243 """Add support for with-statement.""" | 241 """Add support for with-statement.""" |
244 self.StartServer() | 242 self.StartServer() |
245 return self | 243 return self |
246 | 244 |
247 def __exit__(self, unused_exc_type, unused_exc_val, unused_exc_tb): | 245 def __exit__(self, unused_exc_type, unused_exc_val, unused_exc_tb): |
248 """Add support for with-statement.""" | 246 """Add support for with-statement.""" |
249 self.StopServer() | 247 self.StopServer() |
OLD | NEW |