示例#1
0
    def run(self):
        if not sys.stdout.isatty():
            print("Error: mitmproxy's console interface requires a tty. "
                  "Please run mitmproxy in an interactive shell environment.", file=sys.stderr)
            sys.exit(1)

        self.ui = window.Screen()
        self.ui.set_terminal_properties(256)
        self.set_palette(self.options, None)
        self.options.subscribe(
            self.set_palette,
            ["console_palette", "console_palette_transparent"]
        )
        self.loop = urwid.MainLoop(
            urwid.SolidFill("x"),
            event_loop=urwid.AsyncioEventLoop(loop=asyncio.get_event_loop()),
            screen = self.ui,
            handle_mouse = self.options.console_mouse,
        )
        self.window = window.Window(self)
        self.loop.widget = self.window
        self.window.refresh()

        if self.start_err:
            def display_err(*_):
                self.sig_add_log(None, self.start_err)
                self.start_err = None
            self.loop.set_alarm_in(0.01, display_err)

        super().run_loop(self.loop.run)
示例#2
0
文件: master.py 项目: opt9/mitmproxy
    def run(self):
        if not sys.stdout.isatty():
            print(
                "Error: mitmproxy's console interface requires a tty. "
                "Please run mitmproxy in an interactive shell environment.",
                file=sys.stderr)
            sys.exit(1)

        self.ui = window.Screen()
        self.ui.set_terminal_properties(256)
        self.set_palette(self.options, None)
        self.options.subscribe(
            self.set_palette,
            ["console_palette", "console_palette_transparent"])
        self.loop = urwid.MainLoop(
            urwid.SolidFill("x"),
            event_loop=urwid.AsyncioEventLoop(loop=asyncio.get_event_loop()),
            screen=self.ui,
            handle_mouse=self.options.console_mouse,
        )

        self.window = window.Window(self)
        self.loop.widget = self.window
        self.window.refresh()

        if self.start_err:

            def display_err(*_):
                self.sig_add_log(None, self.start_err)
                self.start_err = None

            self.loop.set_alarm_in(0.01, display_err)

        self.start()
        try:
            self.loop.run()
        except Exception:
            self.loop.stop()
            sys.stdout.flush()
            print(traceback.format_exc(), file=sys.stderr)
            print("mitmproxy has crashed!", file=sys.stderr)
            print("Please lodge a bug report at:", file=sys.stderr)
            print("\thttps://github.com/mitmproxy/mitmproxy", file=sys.stderr)
            print("Shutting down...", file=sys.stderr)
        finally:
            sys.stderr.flush()
            super().shutdown()
        self.addons.trigger("done")
示例#3
0
    async def running(self) -> None:
        if not sys.stdout.isatty():
            print(
                "Error: mitmproxy's console interface requires a tty. "
                "Please run mitmproxy in an interactive shell environment.",
                file=sys.stderr)
            sys.exit(1)

        if os.name != "nt" and "utf" not in urwid.detected_encoding.lower():
            print(
                f"mitmproxy expects a UTF-8 console environment, not {urwid.detected_encoding!r}. "
                f"Set your LANG environment variable to something like en_US.UTF-8.",
                file=sys.stderr)
            # Experimental (04/2022): We just don't exit here and see if/how that affects users.
            # sys.exit(1)
        urwid.set_encoding("utf8")

        signals.call_in.connect(self.sig_call_in)
        self.ui = window.Screen()
        self.ui.set_terminal_properties(256)
        self.set_palette(self.options, None)
        self.options.subscribe(
            self.set_palette,
            ["console_palette", "console_palette_transparent"])

        loop = asyncio.get_running_loop()
        if isinstance(loop, getattr(asyncio, "ProactorEventLoop", tuple())):
            patch_tornado()
            # fix for https://bugs.python.org/issue37373
            loop = AddThreadSelectorEventLoop(loop)  # type: ignore
        self.loop = urwid.MainLoop(
            urwid.SolidFill("x"),
            event_loop=urwid.AsyncioEventLoop(loop=loop),
            screen=self.ui,
            handle_mouse=self.options.console_mouse,
        )
        self.window = window.Window(self)
        self.loop.widget = self.window
        self.window.refresh()

        self.loop.start()

        await super().running()
示例#4
0
    def run(self):
        if not sys.stdout.isatty():
            print(
                "Error: mitmproxy's console interface requires a tty. "
                "Please run mitmproxy in an interactive shell environment.",
                file=sys.stderr)
            sys.exit(1)

        signals.call_in.connect(self.sig_call_in)
        self.ui = window.Screen()
        self.ui.set_terminal_properties(256)
        self.set_palette(self.options, None)
        self.options.subscribe(
            self.set_palette,
            ["console_palette", "console_palette_transparent"])
        loop = asyncio.get_event_loop()
        if isinstance(loop, getattr(asyncio, "ProactorEventLoop", tuple())):
            # fix for https://bugs.python.org/issue37373
            loop = AddThreadSelectorEventLoop(loop)
        self.loop = urwid.MainLoop(
            urwid.SolidFill("x"),
            event_loop=urwid.AsyncioEventLoop(loop=loop),
            screen=self.ui,
            handle_mouse=self.options.console_mouse,
        )
        self.window = window.Window(self)
        self.loop.widget = self.window
        self.window.refresh()

        if self.start_err:

            def display_err(*_):
                self.sig_add_log(None, self.start_err)
                self.start_err = None

            self.loop.set_alarm_in(0.01, display_err)

        super().run_loop(self.loop.run)