Skip to content

Commit 950920f

Browse files
authored
Merge pull request #74 from ticosax/aiothttp-3
Compatibility with next major version of aiohttp
2 parents 279494f + 0b01113 commit 950920f

File tree

7 files changed

+27
-22
lines changed

7 files changed

+27
-22
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ language: python
33
matrix:
44
include:
55
- python: 3.5
6-
env: TOXENV=py35-aiohttp-2
6+
env: TOXENV=py35-aiohttp-3
77
- python: 3.5
88
env: TOXENV=py35-aiohttp-master
99
- python: 3.6
10-
env: TOXENV=py36-aiohttp-2
10+
env: TOXENV=py36-aiohttp-3
1111
- python: 3.6
1212
env: TOXENV=py36-aiohttp-master
1313
allow_failures:

CHANGES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGES
22
=======
33

4+
2.0 (Undefined)
5+
---------------
6+
* Drop aiohttp < 3 support
7+
* ``EventSourceResponse.send`` is now a coroutine.
8+
49
1.1.0 (2017-08-21)
510
------------------
611

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Example
5050
for i in range(0, 100):
5151
print('foo')
5252
await asyncio.sleep(1, loop=loop)
53-
resp.send('foo {}'.format(i))
53+
await resp.send('foo {}'.format(i))
5454
return resp
5555
5656
@@ -94,7 +94,7 @@ Requirements
9494
------------
9595

9696
* Python_ 3.5+
97-
* aiohttp_
97+
* aiohttp_ 3+
9898

9999

100100
License

aiohttp_sse/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ async def prepare(self, request):
6363
self.enable_chunked_encoding()
6464
return writer
6565

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

9696
buffer.write(b'\r\n')
97-
self.write(buffer.getvalue())
97+
await self.write(buffer.getvalue())
9898

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

147147
async def __aenter__(self):
148148
return self

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def read_version():
3838
return finder.version
3939

4040

41-
install_requires = ['aiohttp>=2.0']
41+
install_requires = ['aiohttp>=3.0']
4242

4343

4444
setup(name='aiohttp-sse',

tests/test_sse.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ async def func(request):
1818
else:
1919
resp = EventSourceResponse(headers={'X-SSE': 'aiohttp_sse'})
2020
await resp.prepare(request)
21-
resp.send('foo')
22-
resp.send('foo', event='bar')
23-
resp.send('foo', event='bar', id='xyz')
24-
resp.send('foo', event='bar', id='xyz', retry=1)
21+
await resp.send('foo')
22+
await resp.send('foo', event='bar')
23+
await resp.send('foo', event='bar', id='xyz')
24+
await resp.send('foo', event='bar', id='xyz', retry=1)
2525
resp.stop_streaming()
2626
await resp.wait()
2727
return resp
@@ -67,7 +67,7 @@ async def func(request):
6767
app = request.app
6868
resp = EventSourceResponse()
6969
await resp.prepare(request)
70-
resp.send('foo', event='bar', id='xyz', retry=1)
70+
await resp.send('foo', event='bar', id='xyz', retry=1)
7171
app['socket'].append(resp)
7272
await resp.wait()
7373
return resp
@@ -107,8 +107,8 @@ async def func(request):
107107
resp = EventSourceResponse()
108108
await resp.prepare(request)
109109
with pytest.raises(TypeError):
110-
resp.send('foo', retry='one')
111-
resp.send('foo', retry=1)
110+
await resp.send('foo', retry='one')
111+
await resp.send('foo', retry=1)
112112
resp.stop_streaming()
113113
await resp.wait()
114114
return resp
@@ -175,7 +175,7 @@ async def func(request):
175175
resp = EventSourceResponse()
176176
resp.ping_interval = 1
177177
await resp.prepare(request)
178-
resp.send('foo')
178+
await resp.send('foo')
179179
app['socket'].append(resp)
180180
await resp.wait()
181181
return resp
@@ -213,10 +213,10 @@ async def test_context_manager(loop, unused_tcp_port, session):
213213
async def func(request):
214214
h = {'X-SSE': 'aiohttp_sse'}
215215
async with sse_response(request, headers=h) as sse:
216-
sse.send('foo')
217-
sse.send('foo', event='bar')
218-
sse.send('foo', event='bar', id='xyz')
219-
sse.send('foo', event='bar', id='xyz', retry=1)
216+
await sse.send('foo')
217+
await sse.send('foo', event='bar')
218+
await sse.send('foo', event='bar', id='xyz')
219+
await sse.send('foo', event='bar', id='xyz', retry=1)
220220
return sse
221221

222222
app = web.Application()

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[tox]
2-
envlist = py{35,36}-aiohttp-{2,master}
2+
envlist = py{35,36}-aiohttp-{3,master}
33

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

0 commit comments

Comments
 (0)