| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2012 Google Inc. All Rights Reserved. | 2 # Copyright 2012 Google Inc. All Rights Reserved. |
| 3 # | 3 # |
| 4 # Licensed under the Apache License, Version 2.0 (the "License"); | 4 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 # you may not use this file except in compliance with the License. | 5 # you may not use this file except in compliance with the License. |
| 6 # You may obtain a copy of the License at | 6 # You may obtain a copy of the License at |
| 7 # | 7 # |
| 8 # http://www.apache.org/licenses/LICENSE-2.0 | 8 # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 # | 9 # |
| 10 # Unless required by applicable law or agreed to in writing, software | 10 # Unless required by applicable law or agreed to in writing, software |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 class DetailedHTTPSResponse(DetailedHTTPResponse): | 179 class DetailedHTTPSResponse(DetailedHTTPResponse): |
| 180 """Preserve details relevant to replaying SSL responses.""" | 180 """Preserve details relevant to replaying SSL responses.""" |
| 181 pass | 181 pass |
| 182 | 182 |
| 183 | 183 |
| 184 class DetailedHTTPSConnection(httplib.HTTPSConnection): | 184 class DetailedHTTPSConnection(httplib.HTTPSConnection): |
| 185 """Preserve details relevant to replaying SSL connections.""" | 185 """Preserve details relevant to replaying SSL connections.""" |
| 186 response_class = DetailedHTTPSResponse | 186 response_class = DetailedHTTPSResponse |
| 187 | 187 |
| 188 def __init__(self, host, port): | 188 def __init__(self, host, port): |
| 189 httplib.HTTPSConnection.__init__( | 189 # https://www.python.org/dev/peps/pep-0476/#opting-out |
| 190 self, host=host, port=port, context=ssl._create_unverified_context()) | 190 if hasattr(ssl, '_create_unverified_context'): |
| 191 httplib.HTTPSConnection.__init__( |
| 192 self, host=host, port=port, context=ssl._create_unverified_context()) |
| 193 else: |
| 194 httplib.HTTPSConnection.__init__(self, host=host, port=port) |
| 191 | 195 |
| 192 | 196 |
| 193 class RealHttpFetch(object): | 197 class RealHttpFetch(object): |
| 194 | 198 |
| 195 def __init__(self, real_dns_lookup): | 199 def __init__(self, real_dns_lookup): |
| 196 """Initialize RealHttpFetch. | 200 """Initialize RealHttpFetch. |
| 197 | 201 |
| 198 Args: | 202 Args: |
| 199 real_dns_lookup: a function that resolves a host to an IP. | 203 real_dns_lookup: a function that resolves a host to an IP. |
| 200 """ | 204 """ |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 self.fetch = self.record_fetch | 492 self.fetch = self.record_fetch |
| 489 self.is_record_mode = True | 493 self.is_record_mode = True |
| 490 | 494 |
| 491 def SetReplayMode(self): | 495 def SetReplayMode(self): |
| 492 self.fetch = self.replay_fetch | 496 self.fetch = self.replay_fetch |
| 493 self.is_record_mode = False | 497 self.is_record_mode = False |
| 494 | 498 |
| 495 def __call__(self, *args, **kwargs): | 499 def __call__(self, *args, **kwargs): |
| 496 """Forward calls to Replay/Record fetch functions depending on mode.""" | 500 """Forward calls to Replay/Record fetch functions depending on mode.""" |
| 497 return self.fetch(*args, **kwargs) | 501 return self.fetch(*args, **kwargs) |
| OLD | NEW |