How to use the aioconsole.code function in aioconsole

To help you get started, we’ve selected a few aioconsole examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vxgmichel / aioconsole / aioconsole / events.py View on Github external
"""Provide an interactive event loop class."""

import asyncio
import functools

from . import code
from . import compat
from . import server


class InteractiveEventLoop(asyncio.SelectorEventLoop):
    """Event loop running a python console."""

    console_class = code.AsynchronousConsole

    def __init__(self, *, selector=None, locals=None, banner=None, serve=None,
                 prompt_control=None):
        self.console = None
        self.console_task = None
        self.console_server = None
        super().__init__(selector=selector)
        # Factory
        self.factory = lambda streams: self.console_class(
            streams, locals=locals, prompt_control=prompt_control, loop=self)
        # Local console
        if serve is None:
            self.console = self.factory(None)
            coro = self.console.interact(
                banner, stop=True, handle_sigint=True)
            self.console_task = asyncio.ensure_future(coro, loop=self)
github vxgmichel / aioconsole / aioconsole / command.py View on Github external
"""Provide an asynchronous equivalent to the python console."""

import sys
import random
import asyncio
import argparse
import shlex

from . import code


class AsynchronousCli(code.AsynchronousConsole):

    def __init__(self, commands, streams=None, *, prog=None,
                 prompt_control=None, loop=None):
        super().__init__(
            streams=streams, prompt_control=prompt_control, loop=loop)
        self.prog = prog
        self.commands = dict(commands)
        self.commands['help'] = (
            self.help_command,
            argparse.ArgumentParser(
                description='Display the help message.'))
        self.commands['list'] = (
            self.list_command,
            argparse.ArgumentParser(
                description='Display the command list.'))
        self.commands['exit'] = (
github vxgmichel / aioconsole / aioconsole / server.py View on Github external
    factory = lambda streams: code.AsynchronousConsole(
        streams, locals, filename, prompt_control=prompt_control)
    server = yield from start_interactive_server(
github vxgmichel / aioconsole / aioconsole / server.py View on Github external
def start_interactive_server(factory=code.AsynchronousConsole,
                             host='localhost', port=8000, banner=None,
                             *, loop=None):
    callback = lambda reader, writer: handle_connect(
        reader, writer, factory, banner)
    server = yield from asyncio.start_server(callback, host, port, loop=loop)
    return server