1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-08 16:53:23 +00:00

Format project with black (#467)

Format with line length 110 to match flake8

make black part of linting check

Update travis spec for updated black requirements

Add diff output for black on failure

update changelog
This commit is contained in:
Josh Peak
2019-08-24 11:36:35 +10:00
committed by GitHub
parent 75969de601
commit 7caf29735a
70 changed files with 2000 additions and 2217 deletions

View File

@@ -1,4 +1,4 @@
'''Stubs for tornado HTTP clients'''
"""Stubs for tornado HTTP clients"""
from __future__ import absolute_import
import functools
@@ -12,20 +12,19 @@ from vcr.request import Request
def vcr_fetch_impl(cassette, real_fetch_impl):
@functools.wraps(real_fetch_impl)
def new_fetch_impl(self, request, callback):
headers = request.headers.copy()
if request.user_agent:
headers.setdefault('User-Agent', request.user_agent)
headers.setdefault("User-Agent", request.user_agent)
# TODO body_producer, header_callback, and streaming_callback are not
# yet supported.
unsupported_call = (
getattr(request, 'body_producer', None) is not None or
request.header_callback is not None or
request.streaming_callback is not None
getattr(request, "body_producer", None) is not None
or request.header_callback is not None
or request.streaming_callback is not None
)
if unsupported_call:
response = HTTPResponse(
@@ -40,18 +39,13 @@ def vcr_fetch_impl(cassette, real_fetch_impl):
)
return callback(response)
vcr_request = Request(
request.method,
request.url,
request.body,
headers,
)
vcr_request = Request(request.method, request.url, request.body, headers)
if cassette.can_play_response_for(vcr_request):
vcr_response = cassette.play_response(vcr_request)
headers = httputil.HTTPHeaders()
recorded_headers = vcr_response['headers']
recorded_headers = vcr_response["headers"]
if isinstance(recorded_headers, dict):
recorded_headers = recorded_headers.items()
for k, vs in recorded_headers:
@@ -59,43 +53,34 @@ def vcr_fetch_impl(cassette, real_fetch_impl):
headers.add(k, v)
response = HTTPResponse(
request,
code=vcr_response['status']['code'],
reason=vcr_response['status']['message'],
code=vcr_response["status"]["code"],
reason=vcr_response["status"]["message"],
headers=headers,
buffer=BytesIO(vcr_response['body']['string']),
effective_url=vcr_response.get('url'),
buffer=BytesIO(vcr_response["body"]["string"]),
effective_url=vcr_response.get("url"),
request_time=self.io_loop.time() - request.start_time,
)
return callback(response)
else:
if cassette.write_protected and cassette.filter_request(
vcr_request
):
if cassette.write_protected and cassette.filter_request(vcr_request):
response = HTTPResponse(
request,
599,
error=CannotOverwriteExistingCassetteException(
cassette=cassette,
failed_request=vcr_request
cassette=cassette, failed_request=vcr_request
),
request_time=self.io_loop.time() - request.start_time,
)
return callback(response)
def new_callback(response):
headers = [
(k, response.headers.get_list(k))
for k in response.headers.keys()
]
headers = [(k, response.headers.get_list(k)) for k in response.headers.keys()]
vcr_response = {
'status': {
'code': response.code,
'message': response.reason,
},
'headers': headers,
'body': {'string': response.body},
'url': response.effective_url,
"status": {"code": response.code, "message": response.reason},
"headers": headers,
"body": {"string": response.body},
"url": response.effective_url,
}
cassette.append(vcr_request, vcr_response)
return callback(response)