From 574b22a62ab080a09c1b63bc363784f5089805fe Mon Sep 17 00:00:00 2001 From: Luiz Menezes Date: Thu, 4 Aug 2016 18:12:28 -0300 Subject: [PATCH] remove async/await from aiohttp_stubs to support python 3.4 --- .travis.yml | 1 + vcr/stubs/aiohttp_stubs.py | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 30545e2f..1ff60437 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,7 @@ matrix: allow_failures: - env: TOX_SUFFIX="boto" - env: TOX_SUFFIX="boto3" + - env: TOX_SUFFIX="aiohttp" exclude: - env: TOX_SUFFIX="boto" python: 3.3 diff --git a/vcr/stubs/aiohttp_stubs.py b/vcr/stubs/aiohttp_stubs.py index d4832609..6fa074e4 100644 --- a/vcr/stubs/aiohttp_stubs.py +++ b/vcr/stubs/aiohttp_stubs.py @@ -1,6 +1,7 @@ '''Stubs for aiohttp HTTP clients''' from __future__ import absolute_import +import asyncio import functools import json @@ -11,20 +12,24 @@ class MockClientResponse(ClientResponse): # TODO: get encoding from header - async def json(self, *, encoding='utf-8', loads=json.loads): + @asyncio.coroutine + def json(self, *, encoding='utf-8', loads=json.loads): return loads(self.content.decode(encoding)) - async def text(self, encoding='utf-8'): + @asyncio.coroutine + def text(self, encoding='utf-8'): return self.content.decode(encoding) - async def release(self): + @asyncio.coroutine + def release(self): pass def vcr_request(cassette, real_request): @functools.wraps(real_request) - async def new_request(self, method, url, **kwargs): + @asyncio.coroutine + def new_request(self, method, url, **kwargs): headers = kwargs.get('headers') headers = self._prepare_headers(headers) data = kwargs.get('data') @@ -53,7 +58,7 @@ async def new_request(self, method, url, **kwargs): response.close() return response - response = await real_request(self, method, url, **kwargs) + response = yield from real_request(self, method, url, **kwargs) vcr_response = { 'status': { @@ -61,7 +66,7 @@ async def new_request(self, method, url, **kwargs): 'message': response.reason, }, 'headers': dict(response.headers), - 'body': {'string': await response.text()}, + 'body': {'string': (yield from response.text())}, 'url': response.url, } cassette.append(vcr_request, vcr_response)