mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 09:13:23 +00:00
pep8 cleanup
This commit is contained in:
@@ -5,7 +5,12 @@ try:
|
||||
except ImportError:
|
||||
pass
|
||||
import six
|
||||
from six.moves.http_client import HTTPConnection, HTTPSConnection, HTTPMessage, HTTPResponse
|
||||
from six.moves.http_client import (
|
||||
HTTPConnection,
|
||||
HTTPSConnection,
|
||||
HTTPMessage,
|
||||
HTTPResponse,
|
||||
)
|
||||
from six import BytesIO
|
||||
from vcr.request import Request
|
||||
from vcr.errors import CannotOverwriteExistingCassetteException
|
||||
@@ -32,6 +37,7 @@ def parse_headers(header_list):
|
||||
headers = b"".join(header_list) + b"\r\n"
|
||||
return compat.get_httpmessage(headers)
|
||||
|
||||
|
||||
class VCRHTTPResponse(HTTPResponse):
|
||||
"""
|
||||
Stub reponse class that gets returned instead of a HTTPResponse
|
||||
@@ -51,9 +57,9 @@ class VCRHTTPResponse(HTTPResponse):
|
||||
|
||||
@property
|
||||
def closed(self):
|
||||
# in python3, I can't change the value of self.closed. So I'm twiddling
|
||||
# self._closed and using this property to shadow the real self.closed
|
||||
# from the superclass
|
||||
# in python3, I can't change the value of self.closed. So I'
|
||||
# twiddling self._closed and using this property to shadow the real
|
||||
# self.closed from the superclas
|
||||
return self._closed
|
||||
|
||||
def read(self, *args, **kwargs):
|
||||
@@ -206,8 +212,8 @@ class VCRConnection:
|
||||
self.cassette.rewound:
|
||||
# We already have a response we are going to play, don't
|
||||
# actually connect
|
||||
return
|
||||
|
||||
return
|
||||
|
||||
if self.cassette.write_protected:
|
||||
# Cassette is write-protected, don't actually connect
|
||||
return
|
||||
|
||||
@@ -12,6 +12,7 @@ The python3 http.client api moved some stuff around, so this is an abstraction
|
||||
layer that tries to cope with this move.
|
||||
"""
|
||||
|
||||
|
||||
def get_header(message, name):
|
||||
if six.PY3:
|
||||
return message.getallmatchingheaders(name)
|
||||
@@ -34,6 +35,7 @@ def get_headers(response):
|
||||
else:
|
||||
return response.msg.headers
|
||||
|
||||
|
||||
def get_httpmessage(headers):
|
||||
if six.PY3:
|
||||
return http.client.parse_headers(BytesIO(headers))
|
||||
|
||||
@@ -13,7 +13,9 @@ class VCRHTTPConnectionWithTimeout(VCRHTTPConnection,
|
||||
HTTPConnection.__init__.'''
|
||||
|
||||
# Delete the keyword arguments that HTTPConnection would not recognize
|
||||
safe_keys = set(('host', 'port', 'strict', 'timeout', 'source_address'))
|
||||
safe_keys = set(
|
||||
('host', 'port', 'strict', 'timeout', 'source_address')
|
||||
)
|
||||
unknown_keys = set(kwargs.keys()) - safe_keys
|
||||
safe_kwargs = kwargs.copy()
|
||||
for kw in unknown_keys:
|
||||
@@ -31,8 +33,15 @@ class VCRHTTPSConnectionWithTimeout(VCRHTTPSConnection,
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
# Delete the keyword arguments that HTTPSConnection would not recognize
|
||||
safe_keys = set(('host', 'port', 'key_file', 'cert_file', 'strict',
|
||||
'timeout', 'source_address'))
|
||||
safe_keys = set((
|
||||
'host',
|
||||
'port',
|
||||
'key_file',
|
||||
'cert_file',
|
||||
'strict',
|
||||
'timeout',
|
||||
'source_address',
|
||||
))
|
||||
unknown_keys = set(kwargs.keys()) - safe_keys
|
||||
safe_kwargs = kwargs.copy()
|
||||
for kw in unknown_keys:
|
||||
@@ -46,7 +55,7 @@ class VCRHTTPSConnectionWithTimeout(VCRHTTPSConnection,
|
||||
self.ca_certs = None
|
||||
else:
|
||||
self.ca_certs = kwargs['ca_certs']
|
||||
|
||||
|
||||
self.disable_ssl_certificate_validation = kwargs.pop(
|
||||
'disable_ssl_certificate_validation', None)
|
||||
VCRHTTPSConnection.__init__(self, *args, **safe_kwargs)
|
||||
|
||||
Reference in New Issue
Block a user