コード例 #1
0
ファイル: test_sse.py プロジェクト: hairychris/aiohttp-sse
    def test_wait_stop_streaming_errors(self):
        response = EventSourceResponse()
        with self.assertRaisesRegex(RuntimeError, 'Response is not started'):
            response.wait()

        with self.assertRaisesRegex(RuntimeError, 'Response is not started'):
            response.stop_streaming()
コード例 #2
0
ファイル: test_sse.py プロジェクト: EvieePy/aiohttp-sse
 async def func(request):
     app = request.app
     resp = EventSourceResponse()
     await resp.prepare(request)
     resp.send('foo', event='bar', id='xyz', retry=1)
     app['socket'].append(resp)
     await resp.wait()
     return resp
コード例 #3
0
ファイル: test_sse.py プロジェクト: pidoorrr/aiohttp-sse
 async def func(request):
     resp = EventSourceResponse()
     await resp.prepare(request)
     with pytest.raises(TypeError):
         await resp.send('foo', retry='one')
     await resp.send('foo', retry=1)
     resp.stop_streaming()
     await resp.wait()
     return resp
コード例 #4
0
ファイル: test_sse.py プロジェクト: EvieePy/aiohttp-sse
async def test_wait_stop_streaming_errors():
    response = EventSourceResponse()
    with pytest.raises(RuntimeError) as ctx:
        await response.wait()
    assert str(ctx.value) == 'Response is not started'

    with pytest.raises(RuntimeError) as ctx:
        response.stop_streaming()
    assert str(ctx.value) == 'Response is not started'
コード例 #5
0
ファイル: test_sse.py プロジェクト: EvieePy/aiohttp-sse
 async def func(request):
     app = request.app
     resp = EventSourceResponse()
     resp.ping_interval = 1
     await resp.prepare(request)
     resp.send('foo')
     app['socket'].append(resp)
     await resp.wait()
     return resp
コード例 #6
0
ファイル: test_sse.py プロジェクト: hairychris/aiohttp-sse
    def test_ping_property(self):
        response = EventSourceResponse()
        default = response.DEFAULT_PING_INTERVAL
        self.assertEqual(response.ping_interval, default)
        response.ping_interval = 25
        self.assertEqual(response.ping_interval, 25)
        with self.assertRaisesRegex(TypeError, 'ping interval'):
            response.ping_interval = 'ten'

        with self.assertRaises(ValueError):
            response.ping_interval = -42
コード例 #7
0
 async def wrapped(request):
     response = EventSourceResponse(headers={'X-SSE': 'aiohttp_sse'})
     await response.prepare(request)
     while True:
         temp = await co_func()
         data = {'value': temp, 'time': datetime.now().isoformat()}
         await response.send(data=json.dumps(data), event=event_name)
         await asyncio.sleep(period)
     response.stop_streaming()
     await response.wait()
     return response
コード例 #8
0
ファイル: test_sse.py プロジェクト: EvieePy/aiohttp-sse
def test_ping_property(loop):
    response = EventSourceResponse()
    default = response.DEFAULT_PING_INTERVAL
    assert response.ping_interval == default
    response.ping_interval = 25
    assert response.ping_interval == 25
    with pytest.raises(TypeError) as ctx:
        response.ping_interval = 'ten'

    assert str(ctx.value) == 'ping interval must be int'

    with pytest.raises(ValueError):
        response.ping_interval = -42
コード例 #9
0
ファイル: chat_oldstyle.py プロジェクト: rutsky/aiohttp-sse
def subscribe(request):
    response = EventSourceResponse()
    response.start(request)
    app = request.app

    print('Someone joined.')
    request.app['sockets'].add(response)
    try:
        yield from response.wait()
    except Exception as e:
        app['sockets'].remove(response)
        raise e

    return response
コード例 #10
0
ファイル: chat.py プロジェクト: hairychris/aiohttp-sse
def subscribe(request):
    response = EventSourceResponse()
    response.start(request)
    app = request.app

    print("Someone joined.")
    request.app["sockets"].add(response)
    try:
        yield from response.wait()
    except Exception as e:
        app["sockets"].remove(response)
        raise e

    return response
コード例 #11
0
ファイル: test_sse.py プロジェクト: pidoorrr/aiohttp-sse
 async def func(request):
     if with_sse_response:
         resp = await sse_response(request,
                                   headers={'X-SSE': 'aiohttp_sse'})
     else:
         resp = EventSourceResponse(headers={'X-SSE': 'aiohttp_sse'})
         await resp.prepare(request)
     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
コード例 #12
0
ファイル: __main__.py プロジェクト: MartijnBraam/drush-queued
def eventsource(request):
    response = EventSourceResponse()
    response.start(request)

    global sockets
    sockets.add(response)
    logging.debug('User joined eventsource. (now {} clients)'.format(len(sockets)))

    try:
        yield from response.wait()
    except Exception as e:
        sockets.remove(response)
        logging.debug("User left eventsource ({} clients left)".format(len(sockets)))
        raise e

    return response
コード例 #13
0
ファイル: simple_oldstyle.py プロジェクト: rutsky/aiohttp-sse
def hello(request):
    resp = EventSourceResponse()
    resp.start(request)
    for i in range(0, 100):
        print('foo')
        yield from asyncio.sleep(1, loop=loop)
        resp.send('foo {}'.format(i))
    resp.stop_streaming()
    return resp
コード例 #14
0
    async def stream(self, request):
        response = EventSourceResponse(headers={'X-SSE': 'aiohttp_sse'})
        await response.prepare(request)

        while True:
            # Wait for a new event to send
            event = await self._queue.get()
            event_name = event[0]
            data = event[1]

            await response.send(data=json.dumps(data),
                                event=event_name,
                                id=datetime.now().isoformat())

        response.stop_streaming()
        await response.wait()
        return response
コード例 #15
0
ファイル: test_sse.py プロジェクト: hairychris/aiohttp-sse
 def func(request):
     resp = EventSourceResponse()
     resp.start(request)
     with self.assertRaises(TypeError):
         resp.send('foo', retry='one')
     resp.send('foo', retry=1)
     return resp
コード例 #16
0
ファイル: __main__.py プロジェクト: MartijnBraam/drush-queued
def eventsource(request):
    response = EventSourceResponse()
    response.start(request)

    global sockets
    sockets.add(response)
    logging.debug('User joined eventsource. (now {} clients)'.format(
        len(sockets)))

    try:
        yield from response.wait()
    except Exception as e:
        sockets.remove(response)
        logging.debug("User left eventsource ({} clients left)".format(
            len(sockets)))
        raise e

    return response
コード例 #17
0
ファイル: test_sse.py プロジェクト: hairychris/aiohttp-sse
 def func(request):
     app = request.app
     resp = EventSourceResponse()
     resp.ping_interval = 1
     resp.start(request)
     resp.send('foo')
     app['socket'].append(resp)
     yield from resp.wait()
     return resp
コード例 #18
0
ファイル: test_sse.py プロジェクト: hairychris/aiohttp-sse
 def func(request):
     app = request.app
     resp = EventSourceResponse()
     resp.start(request)
     resp.send('foo', event='bar', id='xyz', retry=1)
     app['socket'].append(resp)
     yield from resp.wait()
     return resp
コード例 #19
0
 def func(request):
     if with_sse_response:
         resp = yield from sse_response(request,
                                        headers={'X-SSE': 'aiohttp_sse'})
     else:
         resp = EventSourceResponse(headers={'X-SSE': 'aiohttp_sse'})
         if with_deprecated_start:
             resp.start(request)
         else:
             yield from 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)
     resp.stop_streaming()
     yield from resp.wait()
     return resp
コード例 #20
0
ファイル: test_sse.py プロジェクト: EvieePy/aiohttp-sse
def test_compression_not_implemented():
    response = EventSourceResponse()
    with pytest.raises(NotImplementedError):
        response.enable_compression()
コード例 #21
0
ファイル: test_sse.py プロジェクト: hairychris/aiohttp-sse
 def test_compression_not_implemented(self):
     response = EventSourceResponse()
     with self.assertRaises(NotImplementedError):
         response.enable_compression()
コード例 #22
0
ファイル: test_sse.py プロジェクト: hairychris/aiohttp-sse
 def func(request):
     resp = EventSourceResponse(headers={'X-SSE': 'aiohttp_sse'})
     resp.start(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)
     return resp