Пример #1
0
 def __init__(self, **kwargs):
     for k, v in kwargs.items():
         setattr(self, k, v)
     self.ready = asyncio.Future(loop=self.loop)
     self.started = asyncio.Future(loop=self.loop)
     self.closed = asyncio.Future(loop=self.loop)
     self.timeout_handle = None
Пример #2
0
 def callDCCFTU(self, *args, **kwargs):
     bot = self.callFTU()
     self.future = asyncio.Future(loop=self.loop)
     bot.protocol.transport.get_extra_info = get_extra_info
     self.manager = manager = bot.dcc
     self.server = manager.create(*args, **kwargs)
     self.server.ready.add_done_callback(self.created)
Пример #3
0
def main():
    loop = asyncio.get_event_loop()

    # run a test server
    server = IrcServer.from_config(
        dict(
            loop=loop,
            servername='test',
            includes=['irc3d.plugins.core'],
        ))
    server.run(forever=False)

    end_chat = asyncio.Future()

    cfg = dict(
        host='localhost',
        port=6667,
        nick='sender',
        includes=['irc3.plugins.dcc', __name__],
        loop=loop,
        end_chat=end_chat,
    )
    # this bot will send the file
    sender = irc3.IrcBot.from_config(cfg)
    sender.run(forever=False)

    def f():
        # this bot will receive the file
        receiver.run(forever=False)

    # assume receiver is created *after* sender
    receiver = irc3.IrcBot.from_config(cfg, nick='receiver')
    loop.call_later(.2, receiver.run, False)

    loop.run_until_complete(end_chat)
Пример #4
0
def test_reconn(irc3_bot_factory):
    cfg = {'verbose': True, 'debug': True, 'port': 49137}
    bot = irc3_bot_factory(includes=[__name__], **cfg)
    cfg['loop'] = bot.loop
    server = irc3d.IrcServer.from_config(cfg)

    P.ready = asyncio.Future(loop=bot.loop)
    assert len(P.connections_made) == 0

    server.run(forever=False)
    bot.run(forever=False)

    yield from P.ready
    P.ready = asyncio.Future(loop=bot.loop)

    assert len(P.connections_made) == 1

    for uid, client in server.clients.items():
        client.transport.close()
        print(uid, client)
    yield from P.ready
    P.ready = asyncio.Future(loop=bot.loop)

    assert len(P.connections_made) == 2
Пример #5
0
    def bootstrapIrc3(self):
        # Create the asyncio loop
        loop = asyncio.get_event_loop()
        end_callback = asyncio.Future()

        # Save the end method to be called after posting the message
        self.config['end_callback'] = end_callback
        self.config['includes'] = [__name__]

        # Create the bot and run it once
        sender = irc3.IrcBot.from_config(self.config)
        sender.run(forever=False)

        # Set the asyncio resolve Future
        loop.run_until_complete(end_callback)
Пример #6
0
    def test_async_event(self):
        loop = asyncio.new_event_loop()
        future = asyncio.Future(loop=loop)

        @asyncio.coroutine
        def e(ctx, **kwargs):
            ctx.privmsg('#irc3', 'async')
            future.set_result(ctx)

        bot = self.callFTU(loop=loop)

        e = irc3.utils.wraps_with_context(e, bot)
        bot.attach_events(irc3.event(irc3.rfc.PRIVMSG, e))

        bot.dispatch(':g!g@g PRIVMSG #irc3 :async')

        loop.run_until_complete(future)
        assert future.result() is bot
Пример #7
0
    def test_callable(self):
        loop = asyncio.new_event_loop()
        bot = self.callFTU(loop=loop)
        bot.include(__name__)
        plugin = bot.get_plugin(cron.Crons)

        results = []

        f = asyncio.Future(loop=loop)

        def complete(future):
            results.append(future.result())
            if len(results) == 2:
                f.set_result(results)

        for c in plugin:
            asyncio. async (c.next(), loop=loop).add_done_callback(complete)

        loop.run_until_complete(f)
        assert results == [bot, bot]
Пример #8
0
 def callDCCFTU(self, *args, **kwargs):
     self.bot = self.callFTU()
     self.bot.protocol.transport.get_extra_info = get_extra_info
     self.bot.dispatch(':%s PRIVMSG irc3 :!chat' % self.mask)
     self.future = asyncio.Future(loop=self.loop)
     self.loop.call_later(.1, self.created)