Repository: aio-libs/aiohttp-sse

Issue:
Fix compatibility with aiohttp master
Library is not compatible with aiohttp master (https://travis-ci.org/aio-libs/aiohttp-sse/jobs/331709276), next major release will break everything. I think we need to fix compatibility before aiohttp release.

Comments:

Patch:
diff --git a/.travis.yml b/.travis.yml
index 49b063f..10058c7 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -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:
diff --git a/CHANGES.txt b/CHANGES.txt
index a7ffcb4..ca1f384 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,6 +1,11 @@
 CHANGES
 =======
 
+2.0 (Undefined)
+---------------
+* Drop aiohttp < 3 support
+* ``EventSourceResponse.send`` is now a coroutine.
+
 1.1.0 (2017-08-21)
 ------------------
 
diff --git a/README.rst b/README.rst
index c67dd49..71bdb1f 100644
--- a/README.rst
+++ b/README.rst
@@ -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
 
 
@@ -94,7 +94,7 @@ Requirements
 ------------
 
 * Python_ 3.5+
-* aiohttp_
+* aiohttp_ 3+
 
 
 License
diff --git a/aiohttp_sse/__init__.py b/aiohttp_sse/__init__.py
index df11645..4beab3a 100644
--- a/aiohttp_sse/__init__.py
+++ b/aiohttp_sse/__init__.py
@@ -63,7 +63,7 @@ class EventSourceResponse(StreamResponse):
             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.
@@ -94,7 +94,7 @@ class EventSourceResponse(StreamResponse):
             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,
@@ -142,7 +142,7 @@ class EventSourceResponse(StreamResponse):
         # 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
diff --git a/requirements-dev.txt b/requirements-dev.txt
index 3e57ae0..79bb795 100644
--- a/requirements-dev.txt
+++ b/requirements-dev.txt
@@ -1,6 +1,6 @@
 -e .
 flake8==3.5.0
-ipdb==0.10.3
+ipdb==0.11
 pytest==3.4.0
 pytest-asyncio==0.8.0
 pytest-cov==2.5.1
diff --git a/setup.py b/setup.py
index d257a03..de8d2fb 100644
--- a/setup.py
+++ b/setup.py
@@ -38,7 +38,7 @@ def read_version():
     return finder.version
 
 
-install_requires = ['aiohttp>=2.0']
+install_requires = ['aiohttp>=3.0']
 
 
 setup(name='aiohttp-sse',
diff --git a/tox.ini b/tox.ini
index a8c0eae..0c271a7 100644
--- a/tox.ini
+++ b/tox.ini
@@ -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}


Test patch:
diff --git a/tests/test_sse.py b/tests/test_sse.py
index 03b4716..b1a6faf 100644
--- a/tests/test_sse.py
+++ b/tests/test_sse.py
@@ -18,10 +18,10 @@ async def test_func(loop, unused_tcp_port, with_sse_response, session):
         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
@@ -67,7 +67,7 @@ async def test_wait_stop_streaming(loop, unused_tcp_port, session):
         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
@@ -107,8 +107,8 @@ async def test_retry(loop, unused_tcp_port, session):
         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
@@ -175,7 +175,7 @@ async def test_ping(loop, unused_tcp_port, session):
         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
@@ -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()