Beispiel #1
0
 async def emitter():
     yield SSEvent(data=b'ketchup')
     yield SSEvent(data=b'mustard', event='condiment')
     yield SSEvent(data=b'mayo', event='condiment', event_id='1234')
     yield SSEvent(data=b'onions', event='topping', event_id='5678', retry=100)
     yield SSEvent(text='guacamole \u1F951', retry=100, comment='Serve with chips.')
     yield SSEvent(json={'condiment': 'salsa'}, retry=100)
Beispiel #2
0
Datei: hub.py Projekt: wsz/falcon
    async def events(self):
        try:
            yield SSEvent(text='SSE CONNECTED')

            while True:
                try:
                    event = await asyncio.wait_for(self._queue.get(),
                                                   timeout=self.POLL_TIMEOUT)
                    yield event
                except asyncio.TimeoutError:
                    # NOTE(vytas): Keep the connection alive.
                    yield None
        finally:
            # TODO(vytas): Is there a more elegant way to detect a disconnect?
            self._done = True
Beispiel #3
0
 async def emitter():
     for event in [
             SSEvent(data=b'ketchup'),
             SSEvent(data=b'mustard', event='condiment'),
             SSEvent(data=b'mayo',
                     event='condiment',
                     event_id='1234'),
             SSEvent(data=b'onions',
                     event='topping',
                     event_id='5678',
                     retry=100),
             SSEvent(text='guacamole \u1F951',
                     retry=100,
                     comment='Serve with chips.'),
             SSEvent(json={'condiment': 'salsa'}, retry=100),
     ]:
         yield event
         await asyncio.sleep(0.001)
Beispiel #4
0
Datei: hub.py Projekt: wsz/falcon
 async def enqueue(self, message):
     event = SSEvent(text=message, event_id=str(uuid.uuid4()))
     await self._queue.put(event)
Beispiel #5
0
 async def emitter():
     yield SSEvent()
Beispiel #6
0
def test_invalid_event_values():
    with pytest.raises(TypeError):
        SSEvent(data='notbytes')

    with pytest.raises(TypeError):
        SSEvent(data=12345)

    with pytest.raises(TypeError):
        SSEvent(data=0)

    with pytest.raises(TypeError):
        SSEvent(text=b'notbytes')

    with pytest.raises(TypeError):
        SSEvent(text=23455)

    with pytest.raises(TypeError):
        SSEvent(text=0)

    with pytest.raises(TypeError):
        SSEvent(json=set()).serialize()

    with pytest.raises(TypeError):
        SSEvent(event=b'name')

    with pytest.raises(TypeError):
        SSEvent(event=1234)

    with pytest.raises(TypeError):
        SSEvent(event=0)

    with pytest.raises(TypeError):
        SSEvent(event_id=b'idbytes')

    with pytest.raises(TypeError):
        SSEvent(event_id=52085)

    with pytest.raises(TypeError):
        SSEvent(event_id=0)

    with pytest.raises(TypeError):
        SSEvent(retry='5808.25')

    with pytest.raises(TypeError):
        SSEvent(retry='')

    with pytest.raises(TypeError):
        SSEvent(retry=5808.25)

    with pytest.raises(TypeError):
        SSEvent(comment=b'somebytes')

    with pytest.raises(TypeError):
        SSEvent(comment=1234)

    with pytest.raises(TypeError):
        SSEvent(comment=0)
Beispiel #7
0
 async def emitter():
     yield SSEvent(json={'foo': 'bar'})
     yield SSEvent(json={'bar': 'baz'})
Beispiel #8
0
 async def emitter():
     while True:
         yield SSEvent(data=b'whassup')
         await asyncio.sleep(0.01)