async def rtm_start(self): self.service.logger.debug("Connecting to Slack RTM websocket...") rtm = await self.api_call('rtm.start') if not rtm or 'url' not in rtm: self.service.enabled = False logger.error("{0}: Could not start Slack RTM session".format( self.service.id)) return False async with aiohttp.ClientSession() as session: async with session.ws_connect(rtm['url']) as ws: self.socket = ws async for msg in ws: try: self.service.logger.debug("{0}".format(msg.data)) j = json.loads(msg.data) await self.service.receive(j) if j['type'] == 'message' and j['text'] == 'break': self.service.logger.debug("Break caught.") raise aiohttp.EofStream() if j['type'] == 'message' and j['text'] == 'bp': self.service.logger.debug("Break caught.") except aiohttp.EofStream: self.service.logger.info( "Disconnected from Slack RTM stream.") return
def write_eof(self): self.write(EOF_MARKER) try: self.writer.throw(aiohttp.EofStream()) except StopIteration: pass return self.transport.drain()
def test_http_payload_parser_eof(self): msg = protocol.RawRequestMessage('GET', '/', (1, 1), [], None, None) out = aiohttp.DataQueue() buf = aiohttp.ParserBuffer() p = protocol.HttpPayloadParser(msg, readall=True)(out, buf) next(p) p.send(b'data') p.send(b'line') self.assertRaises(aiohttp.EofStream, p.throw, aiohttp.EofStream()) self.assertEqual(b'dataline', b''.join(out._buffer))
def test_http_payload_parser_eof(self): msg = protocol.RawRequestMessage('GET', '/', (1, 1), CIMultiDict(), None, None) out = aiohttp.FlowControlDataQueue(self.stream) buf = aiohttp.ParserBuffer() p = protocol.HttpPayloadParser(msg, readall=True)(out, buf) next(p) p.send(b'data') p.send(b'line') self.assertRaises(StopIteration, p.throw, aiohttp.EofStream()) self.assertEqual(b'dataline', b''.join(d for d, _ in out._buffer))
def test_http_request_parser_eof(self): # HttpRequestParser does fail on EofStream() out = aiohttp.FlowControlDataQueue(self.stream) buf = aiohttp.ParserBuffer() p = protocol.HttpRequestParser()(out, buf) next(p) p.send(b'get /path HTTP/1.1\r\n') try: p.throw(aiohttp.EofStream()) except aiohttp.EofStream: pass self.assertFalse(out._buffer)
def test_parse_eof_payload(self): out = aiohttp.FlowControlDataQueue(self.stream) buf = aiohttp.ParserBuffer() p = protocol.HttpPayloadParser(None).parse_eof_payload(out, buf) next(p) p.send(b'data') try: p.throw(aiohttp.EofStream()) except StopIteration: pass self.assertEqual([(bytearray(b'data'), 4)], list(out._buffer))
def test_parse_eof_payload(self): out = aiohttp.DataQueue() buf = aiohttp.ParserBuffer() p = protocol.HttpPayloadParser(None).parse_eof_payload(out, buf) next(p) p.send(b'data') try: p.throw(aiohttp.EofStream()) except aiohttp.EofStream: pass self.assertEqual([b'data'], list(out._buffer))
def test_http_response_parser_bad_status_line_eof(self): out = aiohttp.FlowControlDataQueue(self.stream) buf = aiohttp.ParserBuffer() p = protocol.HttpResponseParser()(out, buf) next(p) self.assertRaises(aiohttp.EofStream, p.throw, aiohttp.EofStream())
def write_eof(self): self.write(EOF_MARKER) try: self.writer.throw(aiohttp.EofStream()) except StopIteration: pass
def test_http_response_parser_bad_status_line_eof(self): out = aiohttp.DataQueue() buf = aiohttp.ParserBuffer() p = protocol.HttpResponseParser()(out, buf) next(p) self.assertRaises(errors.BadStatusLine, p.throw, aiohttp.EofStream())