Return a Console instance which wraps this `TCOD_Console*` object.
172277
def _from_cdata(cls, cdata: Any, order: str = "C") -> "Console":
        
        if isinstance(cdata, cls):
            return cdata
        self = object.__new__(cls)  # type: Console
        self.console_c = cdata
        self._init_setup_console_data(order)
        return self
1349734
def execute_console_command(frame, thread_id, frame_id, line, buffer_output=True):
    
    console_message = ConsoleMessage()

    interpreter = get_interactive_console(thread_id, frame_id, frame, console_message)
    more, output_messages, error_messages = interpreter.push(line, frame, buffer_output)
    console_message.update_more(more)

    for message in output_messages:
        console_message.add_console_message(CONSOLE_OUTPUT, message)

    for message in error_messages:
        console_message.add_console_message(CONSOLE_ERROR, message)

    return console_message
123780
def get_console_logger():
    
    global __console_logger
    if __console_logger:
        return __console_logger

    logger = logging.getLogger("kkconst")
    logger.setLevel(logging.DEBUG)

    ch = logging.StreamHandler(sys.stdout)
    ch.setLevel(logging.DEBUG)
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    ch.setFormatter(formatter)
    logger.addHandler(ch)

    __console_logger = logger

    return logger
510824
def display_console(self, request):
        """"""
        if 0 not in self.frames:
            if self.console_init_func is None:
                ns = {}
            else:
                ns = dict(self.console_init_func())
            ns.setdefault("app", self.app)
            self.frames[0] = _ConsoleFrame(ns)
        is_trusted = bool(self.check_pin_trust(request.environ))
        return Response(
            render_console_html(secret=self.secret, evalex_trusted=is_trusted),
            mimetype="text/html",
        )
154377
def get_console_output(self, instance_id):
        """"""
        InstanceIDParam = {"InstanceId": instance_id}
        query = self.query_factory(
            action="GetConsoleOutput", creds=self.creds,
            endpoint=self.endpoint, other_params=InstanceIDParam)
        d = query.submit()
        return d.addCallback(self.parser.get_console_output)
173022
def sys_call(cmd):
    
    p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
    return p.stdout.readlines(), p.stderr.readlines()
1131914
def console_main():
    """"""
    cmd = main(check=False)
    if cmd is not None:
        sys.exit(cmd.returncode)
543082
def _start_console(self):
        
        self._remote_pipe = yield from asyncio_open_serial(self._get_pipe_name())
        server = AsyncioTelnetServer(reader=self._remote_pipe,
                                     writer=self._remote_pipe,
                                     binary=True,
                                     echo=True)
        self._telnet_server = yield from asyncio.start_server(server.run, self._manager.port_manager.console_host, self.console)
646014
def console_fill_char(con: tcod.console.Console, arr: Sequence[int]) -> None:
    
    if isinstance(arr, np.ndarray):
        # numpy arrays, use numpy's ctypes functions
        np_array = np.ascontiguousarray(arr, dtype=np.intc)
        carr = ffi.cast("int *", np_array.ctypes.data)
    else:
        # otherwise convert using the ffi module
        carr = ffi.new("int[]", arr)

    lib.TCOD_console_fill_char(_console(con), carr)
839889
def console(self, ttynum=-1, stdinfd=0, stdoutfd=1, stderrfd=2, escape=1):
        

        if not self.running:
            return False

        return _lxc.Container.console(self, ttynum, stdinfd, stdoutfd,
                                      stderrfd, escape)
33580
def ConsoleLogHandler(loggerRef='', handler=None, level=logging.DEBUG, color=None):
    """"""
    if isinstance(loggerRef, logging.Logger):
        pass

    elif isinstance(loggerRef, str):
        # check for root
        if not loggerRef:
            loggerRef = _log

        # check for a valid logger name
        elif loggerRef not in logging.Logger.manager.loggerDict:
            raise RuntimeError("not a valid logger name: %r" % (loggerRef,))

        # get the logger
        loggerRef = logging.getLogger(loggerRef)

    else:
        raise RuntimeError("not a valid logger reference: %r" % (loggerRef,))

    # see if this (or its parent) is a module level logger
    if hasattr(loggerRef, 'globs'):
        loggerRef.globs['_debug'] += 1
    elif hasattr(loggerRef.parent, 'globs'):
        loggerRef.parent.globs['_debug'] += 1

    # make a handler if one wasn't provided
    if not handler:
        handler = logging.StreamHandler()
        handler.setLevel(level)

    # use our formatter
    handler.setFormatter(LoggingFormatter(color))

    # add it to the logger
    loggerRef.addHandler(handler)

    # make sure the logger has at least this level
    loggerRef.setLevel(level)
340557
def get_logger(cls):
        '''
        
        '''
        if KittyObject._logger is None:
            logger = logging.getLogger('kitty')
            logger.setLevel(logging.INFO)
            consolehandler = logging.StreamHandler()
            console_format = logging.Formatter('[%(levelname)-8s][%(module)s.%(funcName)s] %(message)s')
            consolehandler.setFormatter(console_format)
            logger.addHandler(consolehandler)
            if not os.path.exists('./kittylogs'):
                os.mkdir('./kittylogs')
            filehandler = logging.FileHandler(KittyObject.log_file_name)
            file_format = logging.Formatter('[%(asctime)s] [%(levelname)s] [%(module)s.%(funcName)s] -> %(message)s')
            filehandler.setFormatter(file_format)
            logger.addHandler(filehandler)
            KittyObject._logger = logger
        return KittyObject._logger
239985
def wrap_existing_process(self, pid, stdout_read_fd, stderr_read_fd, port=None):
        
        stdout_read_file = os.fdopen(stdout_read_fd, 'rb')
        stderr_read_file = os.fdopen(stderr_read_fd, 'rb')
        stdout_streams, stderr_streams = self._get_stdout_stderr_streams()
        self._stdout_tee = io_wrap.Tee(stdout_read_file, *stdout_streams)
        self._stderr_tee = io_wrap.Tee(stderr_read_file, *stderr_streams)

        self.proc = Process(pid)
        self._run.pid = pid
        logger.info("wrapping existing process %i" % pid)

        try:
            self.init_run()
        except LaunchError as e:
            logger.exception("catostrophic launch error")
            wandb.termerror(str(e))
            util.sentry_exc(e)
            self._socket.launch_error()
            return

        if io_wrap.SIGWINCH_HANDLER is not None:
            # SIGWINCH_HANDLER (maybe) gets set in self.init_run()
            io_wrap.SIGWINCH_HANDLER.add_fd(stdout_read_fd)
            io_wrap.SIGWINCH_HANDLER.add_fd(stderr_read_fd)

        # Signal the main process that we're all hooked up
        logger.info("informing user process we are ready to proceed")
        self._socket.ready()

        self._sync_etc(headless=True)
584045
def find_console_handler(logger):
    """"""
    for handler in logger.handlers:
        if (isinstance(handler, logging.StreamHandler) and
                handler.stream == sys.stderr):
            return handler
1054982
def getch(self):
        
        return NotImplemented
        fno = stdout.fileno()
        mode = self.termios.tcgetattr(fno)
        try:
            self.tty.setraw(fno, self.termios.TCSANOW)
            ch = self.read(1)
        finally:
            self.termios.tcsetattr(fno, self.termios.TCSANOW, mode)
        return ch
150602
def interactive_console(self):
        
        if not self.running():
            raise RuntimeError('VM %s is not running' % self._libvirt_.name)
        virsh_command = [
            "virsh",
            "-c",
            config.get('libvirt_url'),
            "console",
            self._libvirt_name(),
        ]
        return utils.run_interactive_command(command=virsh_command, )
109477
def console_from_xp(filename: str) -> tcod.console.Console:
    """"""
    return tcod.console.Console._from_cdata(
        lib.TCOD_console_from_xp(filename.encode("utf-8"))
    )