Skip to content

Commit

Permalink
Merge pull request #74 from ticosax/aiothttp-3
Browse files Browse the repository at this point in the history
Compatibility with next major version of aiohttp
  • Loading branch information
ticosax authored Feb 19, 2018
2 parents 279494f + 0b01113 commit 950920f
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ language: python
matrix:
include:
- python: 3.5
env: TOXENV=py35-aiohttp-2
env: TOXENV=py35-aiohttp-3
- python: 3.5
env: TOXENV=py35-aiohttp-master
- python: 3.6
env: TOXENV=py36-aiohttp-2
env: TOXENV=py36-aiohttp-3
- python: 3.6
env: TOXENV=py36-aiohttp-master
allow_failures:
Expand Down
5 changes: 5 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGES
=======

2.0 (Undefined)
---------------
* Drop aiohttp < 3 support
* ``EventSourceResponse.send`` is now a coroutine.

1.1.0 (2017-08-21)
------------------

Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Example
for i in range(0, 100):
print('foo')
await asyncio.sleep(1, loop=loop)
resp.send('foo {}'.format(i))
await resp.send('foo {}'.format(i))
return resp
Expand Down Expand Up @@ -94,7 +94,7 @@ Requirements
------------

* Python_ 3.5+
* aiohttp_
* aiohttp_ 3+


License
Expand Down
6 changes: 3 additions & 3 deletions aiohttp_sse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async def prepare(self, request):
self.enable_chunked_encoding()
return writer

def send(self, data, id=None, event=None, retry=None):
async def send(self, data, id=None, event=None, retry=None):
"""Send data using EventSource protocol
:param str data: The data field for the message.
Expand Down Expand Up @@ -94,7 +94,7 @@ def send(self, data, id=None, event=None, retry=None):
buffer.write('retry: {0}\r\n'.format(retry).encode('utf-8'))

buffer.write(b'\r\n')
self.write(buffer.getvalue())
await self.write(buffer.getvalue())

async def wait(self):
"""EventSourceResponse object is used for streaming data to the client,
Expand Down Expand Up @@ -142,7 +142,7 @@ async def _ping(self):
# as ping message.
while True:
await asyncio.sleep(self._ping_interval, loop=self._loop)
self.write(b': ping\r\n\r\n')
await self.write(b': ping\r\n\r\n')

async def __aenter__(self):
return self
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def read_version():
return finder.version


install_requires = ['aiohttp>=2.0']
install_requires = ['aiohttp>=3.0']


setup(name='aiohttp-sse',
Expand Down
24 changes: 12 additions & 12 deletions tests/test_sse.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ async def func(request):
else:
resp = EventSourceResponse(headers={'X-SSE': 'aiohttp_sse'})
await resp.prepare(request)
resp.send('foo')
resp.send('foo', event='bar')
resp.send('foo', event='bar', id='xyz')
resp.send('foo', event='bar', id='xyz', retry=1)
await resp.send('foo')
await resp.send('foo', event='bar')
await resp.send('foo', event='bar', id='xyz')
await resp.send('foo', event='bar', id='xyz', retry=1)
resp.stop_streaming()
await resp.wait()
return resp
Expand Down Expand Up @@ -67,7 +67,7 @@ async def func(request):
app = request.app
resp = EventSourceResponse()
await resp.prepare(request)
resp.send('foo', event='bar', id='xyz', retry=1)
await resp.send('foo', event='bar', id='xyz', retry=1)
app['socket'].append(resp)
await resp.wait()
return resp
Expand Down Expand Up @@ -107,8 +107,8 @@ async def func(request):
resp = EventSourceResponse()
await resp.prepare(request)
with pytest.raises(TypeError):
resp.send('foo', retry='one')
resp.send('foo', retry=1)
await resp.send('foo', retry='one')
await resp.send('foo', retry=1)
resp.stop_streaming()
await resp.wait()
return resp
Expand Down Expand Up @@ -175,7 +175,7 @@ async def func(request):
resp = EventSourceResponse()
resp.ping_interval = 1
await resp.prepare(request)
resp.send('foo')
await resp.send('foo')
app['socket'].append(resp)
await resp.wait()
return resp
Expand Down Expand Up @@ -213,10 +213,10 @@ async def test_context_manager(loop, unused_tcp_port, session):
async def func(request):
h = {'X-SSE': 'aiohttp_sse'}
async with sse_response(request, headers=h) as sse:
sse.send('foo')
sse.send('foo', event='bar')
sse.send('foo', event='bar', id='xyz')
sse.send('foo', event='bar', id='xyz', retry=1)
await sse.send('foo')
await sse.send('foo', event='bar')
await sse.send('foo', event='bar', id='xyz')
await sse.send('foo', event='bar', id='xyz', retry=1)
return sse

app = web.Application()
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[tox]
envlist = py{35,36}-aiohttp-{2,master}
envlist = py{35,36}-aiohttp-{3,master}

[testenv]
deps =
-rrequirements-dev.txt
aiohttp-2: aiohttp>=2,<3
aiohttp-3: aiohttp>=3,<4
aiohttp-master: https://github.com/aio-libs/aiohttp/archive/master.zip
commands =
pytest -sv tests/ --cov=aiohttp_sse --cov-report=html {posargs}

0 comments on commit 950920f

Please sign in to comment.