Skip to content

Commit

Permalink
remove async/await from aiohttp_stubs to support python 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
lamenezes committed Aug 10, 2016
1 parent 1167b9e commit 574b22a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions vcr/stubs/aiohttp_stubs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'''Stubs for aiohttp HTTP clients'''
from __future__ import absolute_import

import asyncio
import functools
import json

Expand All @@ -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')
Expand Down Expand Up @@ -53,15 +58,15 @@ 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': {
'code': response.status,
'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)
Expand Down

0 comments on commit 574b22a

Please sign in to comment.