Exemple #1
0
def Console():
    try:
        print(Options.banner)
        input("\n\tI'm not responsible for any consequence of the use of this tool, press ENTER to continue.")
        Form.Validate()
        if name == 'nt':
            loop = ProactorEventLoop()
        else:
            loop = get_event_loop()
        loop.run_until_complete(Attack())
        loop.close()
    except (KeyboardInterrupt, EOFError):
        Functions.Error("Bye bye.", 1)
Exemple #2
0
def main() -> None:
    """Main program.

    Parse arguments, set up event loop, run crawler, print report.
    """
    args = ARGS.parse_args()
    if not args.roots:
        print('Use --help for command line help')
        return

    log = Logger(args.level)

    if args.iocp:
        if sys.platform == 'win32':
            from asyncio import ProactorEventLoop
            loop = ProactorEventLoop()  # type: ignore
            asyncio.set_event_loop(loop)
        else:
            assert False
    elif args.select:
        loop = asyncio.SelectorEventLoop()  # type: ignore
        asyncio.set_event_loop(loop)
    else:
        loop = asyncio.get_event_loop()  # type: ignore

    roots = {fix_url(root) for root in args.roots}

    crawler = Crawler(
        log,
        roots,
        exclude=args.exclude,
        strict=args.strict,
        max_redirect=args.max_redirect,
        max_tries=args.max_tries,
        max_tasks=args.max_tasks,
        max_pool=args.max_pool,
    )
    try:
        loop.run_until_complete(crawler.crawl())  # Crawler gonna crawl.
    except KeyboardInterrupt:
        sys.stderr.flush()
        print('\nInterrupted\n')
    finally:
        crawler.report()
        crawler.close()
        loop.close()
def aiohttp_client_fx(db_fx: MongoClient, loop: ProactorEventLoop,
                      aiohttp_client: Callable[[Any], Any]) -> Any:
    app = web.Application()
    app.router.add_routes(urls)

    app['MONGO_DB']: database.Database = db_fx
    app['TOKEN_EXPIRE'] = int(environ.get('TOKEN_EXPIRE', 5))

    return loop.run_until_complete(aiohttp_client(app))
Exemple #4
0
def main() -> None:
    """Main program.

    Parse arguments, set up event loop, run crawler, print report.
    """
    args = ARGS.parse_args()
    if not args.roots:
        print('Use --help for command line help')
        return

    log = Logger(args.level)

    if args.iocp:
        if sys.platform == 'win32':
            from asyncio import ProactorEventLoop
            loop = ProactorEventLoop()  # type: ignore
            asyncio.set_event_loop(loop)
        else:
            assert False
    elif args.select:
        loop = asyncio.SelectorEventLoop()  # type: ignore
        asyncio.set_event_loop(loop)
    else:
        loop = asyncio.get_event_loop()

    roots = {fix_url(root) for root in args.roots}

    crawler = Crawler(log,
                      roots, exclude=args.exclude,
                      strict=args.strict,
                      max_redirect=args.max_redirect,
                      max_tries=args.max_tries,
                      max_tasks=args.max_tasks,
                      max_pool=args.max_pool,
                      )
    try:
        loop.run_until_complete(crawler.crawl())  # Crawler gonna crawl.
    except KeyboardInterrupt:
        sys.stderr.flush()
        print('\nInterrupted\n')
    finally:
        crawler.report()
        crawler.close()
        loop.close()
Exemple #5
0
def broker(ctx, in_connect, in_bind, out_connect, out_bind):
    loop = LoopClass()
    context = azmq.Context(loop=loop)
    in_socket = context.socket(azmq.PULL)
    out_socket = context.socket(azmq.PUSH)

    if in_connect:
        click.echo("Incoming connecting to %s." % in_connect, err=True)
        in_socket.connect(in_connect)
    else:
        click.echo("Incoming binding on %s." % in_bind, err=True)
        in_socket.bind(in_bind)

    if out_connect:
        click.echo("Outgoing connecting to %s." % out_connect, err=True)
        out_socket.connect(out_connect)
    else:
        click.echo("Outgoing binding on %s." % out_bind, err=True)
        out_socket.bind(out_bind)

    async def run(context, in_socket, out_socket):
        click.echo("Broker started.", err=True)

        try:
            while True:
                msg = await in_socket.recv_multipart()
                await out_socket.send_multipart(msg)
        finally:
            click.echo("Broker stopped.", err=True)

    task = asyncio.ensure_future(
        run(context, in_socket, out_socket),
        loop=loop,
    )

    with allow_interruption((loop, context.close)):
        loop.run_until_complete(context.wait_closed())

    loop.close()
Exemple #6
0
def broker(ctx, in_connect, in_bind, out_connect, out_bind):
    loop = LoopClass()
    context = azmq.Context(loop=loop)
    in_socket = context.socket(azmq.PULL)
    out_socket = context.socket(azmq.PUSH)

    if in_connect:
        click.echo("Incoming connecting to %s." % in_connect, err=True)
        in_socket.connect(in_connect)
    else:
        click.echo("Incoming binding on %s." % in_bind, err=True)
        in_socket.bind(in_bind)

    if out_connect:
        click.echo("Outgoing connecting to %s." % out_connect, err=True)
        out_socket.connect(out_connect)
    else:
        click.echo("Outgoing binding on %s." % out_bind, err=True)
        out_socket.bind(out_bind)

    async def run(context, in_socket, out_socket):
        click.echo("Broker started.", err=True)

        try:
            while True:
                msg = await in_socket.recv_multipart()
                await out_socket.send_multipart(msg)
        finally:
            click.echo("Broker stopped.", err=True)

    task = asyncio.ensure_future(
        run(context, in_socket, out_socket),
        loop=loop,
    )

    with allow_interruption((loop, context.close)):
        loop.run_until_complete(context.wait_closed())

    loop.close()
Exemple #7
0
        """ Application main window close action """
        for queue in all_tasks():
            queue.cancel()


class Canvas(FigureCanvas):
    """  """
    def __init__(self, parent):
        fig = Figure()
        fig.patch.set_facecolor(parent.palette().color(QPalette.Background).name())

        FigureCanvas.__init__(self, fig)
        self.setParent(parent)

        self.ax = self.figure.add_subplot(111, projection='polar')


if __name__ == '__main__':
    _application = QApplication(argv)

    _loop = ProactorEventLoop()
    set_event_loop(_loop)

    _ui = ApplicationUI()
    _ui.show()

    try:
        _loop.run_until_complete(_processing(_application))
    except CancelledError:
        exit(0)
Exemple #8
0
async def main(slave_path: str) -> None:
    tasks = [run_controller(slave_path) for idx in range(5)]
    await gather(*tasks)


if __name__ == "__main__":

    slave_path = get_params().slavePath

    try:
        if slave_path and not isfile(slave_path):

            raise FileNotFoundError(
                "ERROR: '--slavePath' parameter is not a file."
                f" Bad path: {slave_path}")

    except FileNotFoundError as error:

        print(error)
        exit(2)

    # Need to change eventloop for windows to run asyncio subprocesses
    if platform == "win32":
        loop = ProactorEventLoop()
        set_event_loop(loop)
        loop.run_until_complete(main(slave_path))
        loop.close()
    else:
        run(main(slave_path))
                for graph in config.graph_types:
                    for idx, signal in enumerate(
                            getattr(config, graph + '_output')):
                        signal_curve = getattr(self, signal + '_curve')
                        signal_data = getattr(self, signal + '_data')
                        signal_color = getattr(config, graph + '_color')
                        signal_data.append(int(''.join(clear_data[signal]),
                                               16))
                        signal_curve.setData(signal_data,
                                             pen=mkPen(
                                                 width=1.5,
                                                 color=signal_color[idx]))

            await sleep(1)


if __name__ == '__main__':
    app = QApplication(argv)

    # Preparing the main loop
    loop = ProactorEventLoop()
    set_event_loop(loop)

    # Preparing and displaying the GUI
    gui = ProgramUI(loop)
    gui.show()
    try:
        loop.run_until_complete(async_process_subprocess(app))
    except CancelledError:
        pass
Exemple #10
0
def client(ctx, in_connect, in_bind, out_connect, out_bind, count, size):
    in_loop = LoopClass()
    in_context = azmq.Context(loop=in_loop)
    in_socket = in_context.socket(azmq.PULL)

    if in_connect:
        click.echo("Incoming connecting to %s." % in_connect, err=True)
        in_socket.connect(in_connect)
    else:
        click.echo("Incoming binding on %s." % in_bind, err=True)
        in_socket.bind(in_bind)

    out_loop = LoopClass()
    out_context = azmq.Context(loop=out_loop)
    out_socket = out_context.socket(azmq.PUSH)
    out_socket.max_outbox_size = 1

    if out_connect:
        click.echo("Outgoing connecting to %s." % out_connect, err=True)
        out_socket.connect(out_connect)
    else:
        click.echo("Outgoing binding on %s." % out_bind, err=True)
        out_socket.bind(out_bind)

    in_done = asyncio.Event(loop=out_loop)
    out_done = asyncio.Event(loop=in_loop)
    data_lock = threading.Lock()
    data_results = {}

    async def run_sender(context, socket, msg, count):
        # The list of sending times.
        send_times = [None] * count

        async with context:
            # Leave some time for the connection to be established.
            click.echo("Sender started.", err=True)

            try:
                for i in range(count):
                    send_times[i] = perf_counter()
                    await socket.send_multipart(msg)
            finally:
                in_loop.call_soon_threadsafe(out_done.set)
                click.echo("Sender stopping...", err=True)
                await in_done.wait()
                click.echo("Sender stopped.", err=True)

        with data_lock:
            data_results.update({
                'send_times': send_times,
            })

    async def run_receiver(context, socket, msg, count):
        click.echo("Receiver started.", err=True)

        # The list of receiving times.
        receive_times = [None] * count

        async with context:
            try:
                for i in range(count):
                    await socket.recv_multipart()
                    receive_times[i] = perf_counter()
            finally:
                out_loop.call_soon_threadsafe(in_done.set)
                click.echo("Receiver stopping...", err=True)
                await out_done.wait()
                click.echo("Receiver stopped.", err=True)

        with data_lock:
            data_results.update({
                'receive_times': receive_times,
            })

    msg = [b'x' * size]

    out_task = asyncio.ensure_future(
        run_sender(out_context, out_socket, msg, count),
        loop=out_loop,
    )
    in_task = asyncio.ensure_future(
        run_receiver(in_context, in_socket, msg, count),
        loop=in_loop,
    )

    in_thread = threading.Thread(
        target=in_loop.run_until_complete,
        args=(in_context.wait_closed(), ),
    )
    out_thread = threading.Thread(
        target=out_loop.run_until_complete,
        args=(out_context.wait_closed(), ),
    )
    in_thread.start()
    out_thread.start()

    with allow_interruption(
        (in_loop, in_context.close),
        (out_loop, out_context.close),
    ):
        out_thread.join()
        in_thread.join()

    in_loop.run_until_complete(
        asyncio.gather(in_task, return_exceptions=True, loop=in_loop), )
    out_loop.run_until_complete(
        asyncio.gather(out_task, return_exceptions=True, loop=out_loop), )

    in_loop.close()
    out_loop.close()

    click.echo("Computing results...", err=True)
    keys = list(data_results.keys())
    values = zip(*data_results.values())

    for index, value in enumerate(values):
        raw_data = dict(zip(keys, value))
        data = {
            'sent': raw_data['send_times'],
            'received': raw_data['receive_times'],
            'latency': raw_data['receive_times'] - raw_data['send_times'],
            'size': size,
        }
        sys.stdout.write(json.dumps(index))
        sys.stdout.write('\t')
        sys.stdout.write(json.dumps(data))
        sys.stdout.write('\n')

    click.echo("Done computing results.", err=True)
Exemple #11
0
def client(ctx, in_connect, in_bind, out_connect, out_bind, count, size):
    in_loop = LoopClass()
    in_context = azmq.Context(loop=in_loop)
    in_socket = in_context.socket(azmq.PULL)

    if in_connect:
        click.echo("Incoming connecting to %s." % in_connect, err=True)
        in_socket.connect(in_connect)
    else:
        click.echo("Incoming binding on %s." % in_bind, err=True)
        in_socket.bind(in_bind)

    out_loop = LoopClass()
    out_context = azmq.Context(loop=out_loop)
    out_socket = out_context.socket(azmq.PUSH)
    out_socket.max_outbox_size = 1

    if out_connect:
        click.echo("Outgoing connecting to %s." % out_connect, err=True)
        out_socket.connect(out_connect)
    else:
        click.echo("Outgoing binding on %s." % out_bind, err=True)
        out_socket.bind(out_bind)

    in_done = asyncio.Event(loop=out_loop)
    out_done = asyncio.Event(loop=in_loop)
    data_lock = threading.Lock()
    data_results = {}

    async def run_sender(context, socket, msg, count):
        # The list of sending times.
        send_times = [None] * count

        async with context:
            # Leave some time for the connection to be established.
            click.echo("Sender started.", err=True)

            try:
                for i in range(count):
                    send_times[i] = perf_counter()
                    await socket.send_multipart(msg)
            finally:
                in_loop.call_soon_threadsafe(out_done.set)
                click.echo("Sender stopping...", err=True)
                await in_done.wait()
                click.echo("Sender stopped.", err=True)

        with data_lock:
            data_results.update({
                'send_times': send_times,
            })

    async def run_receiver(context, socket, msg, count):
        click.echo("Receiver started.", err=True)

        # The list of receiving times.
        receive_times = [None] * count

        async with context:
            try:
                for i in range(count):
                    await socket.recv_multipart()
                    receive_times[i] = perf_counter()
            finally:
                out_loop.call_soon_threadsafe(in_done.set)
                click.echo("Receiver stopping...", err=True)
                await out_done.wait()
                click.echo("Receiver stopped.", err=True)

        with data_lock:
            data_results.update({
                'receive_times': receive_times,
            })

    msg = [b'x' * size]

    out_task = asyncio.ensure_future(
        run_sender(out_context, out_socket, msg, count),
        loop=out_loop,
    )
    in_task = asyncio.ensure_future(
        run_receiver(in_context, in_socket, msg, count),
        loop=in_loop,
    )

    in_thread = threading.Thread(
        target=in_loop.run_until_complete,
        args=(in_context.wait_closed(),),
    )
    out_thread = threading.Thread(
        target=out_loop.run_until_complete,
        args=(out_context.wait_closed(),),
    )
    in_thread.start()
    out_thread.start()

    with allow_interruption(
        (in_loop, in_context.close),
        (out_loop, out_context.close),
    ):
        out_thread.join()
        in_thread.join()

    in_loop.run_until_complete(
        asyncio.gather(in_task, return_exceptions=True, loop=in_loop),
    )
    out_loop.run_until_complete(
        asyncio.gather(out_task, return_exceptions=True, loop=out_loop),
    )

    in_loop.close()
    out_loop.close()

    click.echo("Computing results...", err=True)
    keys = list(data_results.keys())
    values = zip(*data_results.values())

    for index, value in enumerate(values):
        raw_data = dict(zip(keys, value))
        data = {
            'sent': raw_data['send_times'],
            'received': raw_data['receive_times'],
            'latency': raw_data['receive_times'] - raw_data['send_times'],
            'size': size,
        }
        sys.stdout.write(json.dumps(index))
        sys.stdout.write('\t')
        sys.stdout.write(json.dumps(data))
        sys.stdout.write('\n')

    click.echo("Done computing results.", err=True)