Example #1
0
 def test_to_stream(self):
     variable_header = PacketIdVariableHeader(10)
     payload = UnubscribePayload(['a/b', 'c/d'])
     publish = UnsubscribePacket(variable_header=variable_header,
                                 payload=payload)
     out = publish.to_bytes()
     self.assertEqual(out, b'\xa2\x0c\x00\n\x00\x03a/b\x00\x03c/d')
Example #2
0
 def test_from_stream(self):
     data = b'\xa2\x0c\x00\n\x00\x03a/b\x00\x03c/d'
     stream = BufferReader(data)
     message = self.loop.run_until_complete(
         UnsubscribePacket.from_stream(stream))
     self.assertEqual(message.payload.topics[0], 'a/b')
     self.assertEqual(message.payload.topics[1], 'c/d')
Example #3
0
 def test_from_stream(self):
     data = b'\xa2\x0c\x00\n\x00\x03a/b\x00\x03c/d'
     stream = asyncio.StreamReader(loop=self.loop)
     stream.feed_data(data)
     stream.feed_eof()
     message = self.loop.run_until_complete(UnsubscribePacket.from_stream(stream))
     self.assertEqual(message.payload.topics[0], 'a/b')
     self.assertEqual(message.payload.topics[1], 'c/d')
Example #4
0
    def mqtt_unsubscribe(self, topics, packet_id):
        """

        :param topics: array of topics ['/a/b', ...]
        :return:
        """
        unsubscribe = UnsubscribePacket.build(topics, packet_id)
        yield from self._send_packet(unsubscribe)
        waiter = futures.Future(loop=self._loop)
        self._unsubscriptions_waiter[unsubscribe.variable_header.packet_id] = waiter
        yield from waiter
        del self._unsubscriptions_waiter[unsubscribe.variable_header.packet_id]
Example #5
0
    def mqtt_unsubscribe(self, topics, packet_id):
        """

        :param topics: array of topics ['/a/b', ...]
        :return:
        """
        unsubscribe = UnsubscribePacket.build(topics, packet_id)
        yield from self._send_packet(unsubscribe)
        waiter = futures.Future(loop=self._loop)
        self._unsubscriptions_waiter[unsubscribe.variable_header.packet_id] = waiter
        yield from waiter
        del self._unsubscriptions_waiter[unsubscribe.variable_header.packet_id]
Example #6
0
    async def mqtt_unsubscribe(self, topics, packet_id):
        """

        :param topics: array of topics ['/a/b', ...]
        :return:
        """
        waiter = Future()
        self._unsubscriptions_waiter[packet_id] = waiter
        try:
            unsubscribe = UnsubscribePacket.build(topics, packet_id)
            await self._send_packet(unsubscribe)

            await waiter.get()
        finally:
            del self._unsubscriptions_waiter[packet_id]
Example #7
0
    def mqtt_unsubscribe(self, topics, packet_id):
        """

        :param topics: array of topics ['/a/b', ...]
        :return:
        """

        def acknowledged_predicate():
            if self.subscriptions[unsubscribe.variable_header.packet_id].state == "acknowledged":
                return True
            else:
                return False

        unsubscribe = UnsubscribePacket.build(topics, packet_id)
        yield from self.outgoing_queue.put(unsubscribe)
        subscription = UnSubscription(unsubscribe.variable_header.packet_id, topics)
        subscription.unsubscribe()
        self.subscriptions[unsubscribe.variable_header.packet_id] = subscription
        self.subscriptions[unsubscribe.variable_header.packet_id] = subscription
        yield from self._subscriptions_changed.acquire()
        yield from self._subscriptions_changed.wait_for(acknowledged_predicate)
        subscription = self.subscriptions.pop(unsubscribe.variable_header.packet_id)
        self._subscriptions_changed.release()
        return subscription
Example #8
0
 def test_to_stream(self):
     variable_header = PacketIdVariableHeader(10)
     payload = UnubscribePayload(['a/b', 'c/d'])
     publish = UnsubscribePacket(variable_header=variable_header, payload=payload)
     out = publish.to_bytes()
     self.assertEqual(out, b'\xa2\x0c\x00\n\x00\x03a/b\x00\x03c/d')
Example #9
0
 def test_from_stream(self):
     data = b'\xa2\x0c\x00\n\x00\x03a/b\x00\x03c/d'
     stream = BufferReader(data)
     message = self.loop.run_until_complete(UnsubscribePacket.from_stream(stream))
     self.assertEqual(message.payload.topics[0], 'a/b')
     self.assertEqual(message.payload.topics[1], 'c/d')