Skip to content

Commit

Permalink
Merge pull request #89 from achimnol/upgrade-to-aiohttp-v3
Browse files Browse the repository at this point in the history
Upgrade to aiohttp v3 series and drop support for v1
  • Loading branch information
pnuckowski committed Feb 17, 2018
2 parents 09a94e6 + ce9d779 commit fe0d834
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 46 deletions.
45 changes: 18 additions & 27 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,6 @@ language: python

matrix:
include:
- python: 3.4
env: TOXENV=py34-aiohttp10
- python: 3.4
env: TOXENV=py34-aiohttp12
- python: 3.4
env: TOXENV=py34-aiohttp13
- python: 3.4
env: TOXENV=py34-aiohttp20
- python: 3.4
env: TOXENV=py34-aiohttp21
- python: 3.4
env: TOXENV=py34-aiohttp22
- python: 3.4
env: TOXENV=py34-aiohttp23

- python: 3.5
env: TOXENV=py35-aiohttp10
- python: 3.5
env: TOXENV=py35-aiohttp11
- python: 3.5
env: TOXENV=py35-aiohttp12
- python: 3.5
env: TOXENV=py35-aiohttp13
- python: 3.5
env: TOXENV=py35-aiohttp20
- python: 3.5
Expand All @@ -36,12 +13,26 @@ matrix:
env: TOXENV=py35-aiohttp22
- python: 3.5
env: TOXENV=py35-aiohttp23
# - python: 3.5
# env: TOXENV=py35-aiohttpmaster

- python: 3.5
env: TOXENV=py35-aiohttp30

- python: 3.6
env: TOXENV=py36-aiohttp20
- python: 3.6
env: TOXENV=py36-aiohttp21
- python: 3.6
env: TOXENV=py36-aiohttp22
- python: 3.6
env: TOXENV=py36-aiohttp23
- python: 3.6
env: TOXENV=py36-aiohttp30
# - python: 3.6
# env: TOXENV=py36-aiohttpmaster
#

- python: 3.6
env: TOXENV=flake8
- python: 3.5
- python: 3.6
env: TOXENV=coverage

# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
Expand Down
13 changes: 12 additions & 1 deletion aioresponses/compat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from aiohttp import __version__ as aiohttp_version
from aiohttp import __version__ as aiohttp_version, StreamReader
from typing import Optional
from urllib.parse import urlsplit, urlencode, SplitResult, urlunsplit

Expand All @@ -15,6 +15,17 @@ class URL(str):
yarl_available = False


if int(aiohttp_version.split('.')[0]) >= 3:
from aiohttp.client_proto import ResponseHandler

def stream_reader():
protocol = ResponseHandler()
return StreamReader(protocol)
else:
def stream_reader():
return StreamReader()


__all__ = ['URL', 'merge_url_params']


Expand Down
15 changes: 7 additions & 8 deletions aioresponses/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from urllib.parse import urlparse, parse_qsl, urlencode

from aiohttp import (
hdrs, ClientResponse, ClientConnectionError, StreamReader, client
hdrs, ClientResponse, ClientConnectionError, client
)
from collections import namedtuple
from functools import wraps
from multidict import CIMultiDict

from .compat import URL, merge_url_params
from .compat import URL, merge_url_params, stream_reader


class UrlResponse(object):
Expand Down Expand Up @@ -61,7 +61,7 @@ def build_response(self) -> Union[ClientResponse, Exception]:
self.resp.headers.update(self.headers)
self.resp.raw_headers = self._build_raw_headers(self.resp.headers)
self.resp.status = self.status
self.resp.content = StreamReader()
self.resp.content = stream_reader()
self.resp.content.feed_data(self.body)
self.resp.content.feed_eof()

Expand Down Expand Up @@ -190,17 +190,16 @@ def match(self, method: str, url: str) -> 'ClientResponse':
raise resp
return resp

@asyncio.coroutine
def _request_mock(self, orig_self: client.ClientSession,
method: str, url: str, *args: Tuple,
**kwargs: Dict) -> 'ClientResponse':
async def _request_mock(self, orig_self: client.ClientSession,
method: str, url: str, *args: Tuple,
**kwargs: Dict) -> 'ClientResponse':
"""Return mocked response object or raise connection error."""

url = merge_url_params(url, kwargs.get('params'))

for prefix in self._passthrough:
if str(url).startswith(prefix):
return (yield from self.patcher.temp_original(
return (await self.patcher.temp_original(
orig_self, method, url, *args, **kwargs
))

Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ classifier =
License :: OSI Approved :: MIT License
Natural Language :: English
Programming Language :: Python :: 3
Programming Language :: Python :: 3.4
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6

[files]
packages =
Expand All @@ -29,4 +29,4 @@ source-dir = docs/source
universal = 1

[flake8]
exclude = docs
exclude = docs
13 changes: 5 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
envlist =
flake8,
coverage,
py34-aiohttp{10,11,12,13,20,21,22,23}
py35-aiohttp{10,11,12,13,20,21,22,23}
py35-aiohttp{20,21,22,23,30}
py36-aiohttp{20,21,22,23,30}
skipsdist=True

[testenv:flake8]
Expand All @@ -17,20 +17,17 @@ setenv =
PYTHONPATH = {toxinidir}:{toxinidir}/aioresponses

deps =
aiohttp10: aiohttp>=1.0,<1.1
aiohttp11: aiohttp>=1.1,<1.2
aiohttp12: aiohttp>=1.2,<1.3
aiohttp13: aiohttp>=1.3,<2.0
aiohttp20: aiohttp>=2.0,<2.1
aiohttp21: aiohttp>=2.1,<2.2
aiohttp22: aiohttp>=2.2,<2.3
aiohttp23: aiohttp>=2.3,<2.4
aiohttp30: aiohttp>=3.0,<3.1
aiohttpmaster: https://github.com/KeepSafe/aiohttp/archive/master.tar.gz
-r{toxinidir}/requirements-dev.txt

basepython =
py34: python3.4
py35: python3.5
py36: python3.6

commands = python setup.py test

Expand All @@ -41,4 +38,4 @@ commands = coverage run --source=aioresponses setup.py test
[testenv:cov_html]
basepython = python
deps = aiohttp
commands = nose2 --coverage=aioresponses --coverage-report=html
commands = nose2 --coverage=aioresponses --coverage-report=html

0 comments on commit fe0d834

Please sign in to comment.