Beispiel #1
0
    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()
Beispiel #2
0
 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
Beispiel #3
0
 def func(request):
     app = request.app
     resp = EventSourceResponse()
     yield from resp.prepare(request)
     resp.send('foo', event='bar', id='xyz', retry=1)
     app['socket'].append(resp)
     yield from resp.wait()
     return resp
Beispiel #4
0
 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
Beispiel #5
0
 def func(request):
     app = request.app
     resp = EventSourceResponse()
     resp.ping_interval = 1
     yield from resp.prepare(request)
     resp.send('foo')
     app['socket'].append(resp)
     yield from resp.wait()
     return resp
Beispiel #6
0
def test_wait_stop_streaming_errors():
    response = EventSourceResponse()
    with pytest.raises(RuntimeError) as ctx:
        yield from 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'
Beispiel #7
0
 def func(request):
     resp = EventSourceResponse()
     yield from resp.prepare(request)
     with pytest.raises(TypeError):
         resp.send('foo', retry='one')
     resp.send('foo', retry=1)
     resp.stop_streaming()
     yield from resp.wait()
     return resp
Beispiel #8
0
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
Beispiel #9
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'})
         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
Beispiel #10
0
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
Beispiel #11
0
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
Beispiel #12
0
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