示例#1
0
 async def coro():
     async with anyio.create_task_group() as tg:
         manager = PluginManager(tg,
                                 "distmqtt.test.plugins",
                                 context=None)
         await call_coro(manager)
         plugin = manager.get_plugin("event_plugin")
         self.assertTrue(plugin.object.test_coro)
示例#2
0
 async def coro():
     async with anyio.create_task_group() as tg:
         manager = PluginManager(tg,
                                 "distmqtt.test.plugins",
                                 context=None)
         ret = await call_coro(manager)
         plugin = manager.get_plugin("event_plugin")
         self.assertEqual(ret[plugin], "TEST")
示例#3
0
 async def coro():
     async with anyio.create_task_group() as tg:
         manager = PluginManager(tg,
                                 "distmqtt.test.plugins",
                                 context=None)
         ret = await call_coro(manager)
         self.assertTrue(len(ret) == 0)
示例#4
0
    def __init__(self,
                 tg: anyio.abc.TaskGroup,
                 client_id=None,
                 config=None,
                 codec=None):
        self.logger = logging.getLogger(__name__)
        self.config = copy.deepcopy(_defaults)
        if config is not None:
            self.config.update(config)
        if client_id is not None:
            self.client_id = client_id
        else:
            from distmqtt.utils import gen_client_id

            self.client_id = gen_client_id()
            self.logger.debug("Using generated client ID : %s", self.client_id)

        self.session = None
        self._tg = tg
        self._handler = None
        self._disconnect_task = None
        self._connected_state = anyio.create_event()
        self._no_more_connections = anyio.create_event()
        self.extra_headers = {}
        self.codec = get_codec(codec, config=self.config)

        self._subscriptions = None

        # Init plugins manager
        context = ClientContext(self.config)
        self.plugins_manager = PluginManager(tg, "distmqtt.client.plugins",
                                             context)
        self.client_task = None
示例#5
0
 async def runner():
     async with anyio.create_task_group() as tg:
         self.plugin_manager = PluginManager(tg, "distmqtt.test.plugins", context=None)
         server = await anyio.create_tcp_listener(local_port=PORT, local_host="127.0.0.1")
         try:
             await tg.spawn(server.serve, partial(self.listener_, server_mock))
             async with await anyio.connect_tcp("127.0.0.1", PORT) as conn:
                 sr = adapt(conn)
                 await test_coro(sr)
                 await tg.cancel_scope.cancel()
         finally:
             await server.aclose()
示例#6
0
 async def coro():
     async with anyio.create_task_group() as tg:
         manager = PluginManager(tg,
                                 "distmqtt.test.plugins",
                                 context=None)
         self.assertTrue(len(manager._plugins) > 0)