def p(self, *args): parser = MockParser() opts = options.Options() cmdline.common_options(parser, opts) args = parser.parse_args(args=args) main.process_options(parser, opts, args) pconf = config.ProxyConfig(opts) return parser, pconf
def p(self, *args): parser = MockParser() opts = options.Options() cmdline.common_options(parser, opts) args = parser.parse_args(args=args) pconf = main.process_options(parser, opts, args) return parser, pconf
def mitmmonitor(args=None): # pragma: no cover import monitor version_check.check_pyopenssl_version() parser = cmdline.monitor() args = parser.parse_args(args) try: monitor_options = options.Options() monitor_options.load_paths(args.conf) monitor_options.merge(cmdline.get_common_options(args)) server = process_options(parser, monitor_options, args) m = monitor.master.MonitorMaster(monitor_options, server) except exceptions.OptionsError as e: sys.exit(1) try: m.run() except (KeyboardInterrupt, RuntimeError): pass
def test_common(): parser = argparse.ArgumentParser() opts = options.Options() cmdline.common_options(parser, opts) args = parser.parse_args(args=[]) main.process_options(parser, opts, args)
def test_common(): parser = argparse.ArgumentParser() opts = options.Options() cmdline.common_options(parser, opts) args = parser.parse_args(args=[]) assert main.process_options(parser, opts, args)
def my_run( master, opts, make_parser: typing.Callable[[options.Options], argparse.ArgumentParser], arguments: typing.Sequence[str], extra: typing.Callable[[typing.Any], dict] = None ) -> master.Master: # pragma: no cover """ extra: Extra argument processing callable which returns a dict of options. """ debug.register_info_dumpers() parser = make_parser(opts) # To make migration from 2.x to 3.0 bearable. if "-R" in sys.argv and sys.argv[sys.argv.index("-R") + 1].startswith("http"): print("-R is used for specifying replacements.\n" "To use mitmproxy in reverse mode please use --mode reverse:SPEC instead") try: args = parser.parse_args(arguments) except SystemExit: arg_check.check() sys.exit(1) try: opts.confdir = args.confdir optmanager.load_paths( opts, os.path.join(opts.confdir, OPTIONS_FILE_NAME), ) pconf = process_options(parser, opts, args) #server: typing.Any = None if pconf.options.server: try: server = proxy.server.ProxyServer(pconf) except exceptions.ServerException as v: print(str(v), file=sys.stderr) sys.exit(1) else: server = proxy.server.DummyServer(pconf) master.server = server if args.options: print(optmanager.dump_defaults(opts)) sys.exit(0) if args.commands: master.commands.dump() sys.exit(0) opts.set(*args.setoptions, defer=True) if extra: opts.update(**extra(args)) loop = asyncio.get_event_loop() for signame in ('SIGINT', 'SIGTERM'): try: loop.add_signal_handler(getattr(signal, signame), master.shutdown) except NotImplementedError: # Not supported on Windows pass # Make sure that we catch KeyboardInterrupts on Windows. # https://stackoverflow.com/a/36925722/934719 if os.name == "nt": async def wakeup(): while True: await asyncio.sleep(0.2) asyncio.ensure_future(wakeup()) master.run() except exceptions.OptionsError as e: print("%s: %s" % (sys.argv[0], e), file=sys.stderr) sys.exit(1) except (KeyboardInterrupt, RuntimeError) as e: pass return master