Esempio n. 1
0
 def test_ask_shutdown(self):
     q = queue.Queue()
     done = Event()
     done.set()
     channel = controller.Channel(q, done)
     with tutils.raises(Kill):
         channel.ask("test", Mock(name="test_ask_shutdown"))
Esempio n. 2
0
 def test_tell(self):
     q = queue.Queue()
     channel = controller.Channel(q, Event())
     m = Mock(name="test_tell")
     channel.tell("test", m)
     assert q.get() == ("test", m)
     assert m.reply
Esempio n. 3
0
 def __init__(self, opts, server):
     self.options = opts or options.Options()
     self.addons = addonmanager.AddonManager(self)
     self.event_queue = queue.Queue()
     self.should_exit = threading.Event()
     self.server = server
     channel = controller.Channel(self.event_queue, self.should_exit)
     server.set_channel(channel)
Esempio n. 4
0
 def __init__(self, config, flow, event_queue, should_exit):
     """
         event_queue can be a queue or None, if no scripthooks should be
         processed.
     """
     self.config, self.flow = config, flow
     if event_queue:
         self.channel = controller.Channel(event_queue, should_exit)
     else:
         self.channel = None
     super(RequestReplayThread, self).__init__()
Esempio n. 5
0
 def __init__(self, config, f, event_queue, should_exit):
     """
         event_queue can be a queue or None, if no scripthooks should be
         processed.
     """
     self.config, self.f = config, f
     f.live = True
     if event_queue:
         self.channel = controller.Channel(event_queue, should_exit)
     else:
         self.channel = None
     super().__init__("RequestReplay (%s)" % f.request.url)
Esempio n. 6
0
    def test_ask_simple(self):
        q = queue.Queue()

        def reply():
            m, obj = q.get()
            assert m == "test"
            obj.reply.send(42)

        Thread(target=reply).start()

        channel = controller.Channel(q, Event())
        assert channel.ask("test", Mock()) == 42
Esempio n. 7
0
 def __init__(self, opts: options.Options, f: http.HTTPFlow,
              event_queue: typing.Optional[queue.Queue],
              should_exit: threading.Event) -> None:
     """
         event_queue can be a queue or None, if no scripthooks should be
         processed.
     """
     self.options = opts
     self.f = f
     f.live = True
     if event_queue:
         self.channel = controller.Channel(event_queue, should_exit)
     else:
         self.channel = None
     super().__init__("RequestReplay (%s)" % f.request.url)
Esempio n. 8
0
    def __init__(self, opts):
        self.event_queue = asyncio.Queue()
        self.should_exit = threading.Event()
        self.channel = controller.Channel(
            asyncio.get_event_loop(),
            self.event_queue,
            self.should_exit,
        )
        asyncio.ensure_future(self.main())
        asyncio.ensure_future(self.tick())

        self.options = opts or options.Options()  # type: options.Options
        self.commands = command.CommandManager(self)
        self.addons = addonmanager.AddonManager(self)
        self._server = None
        self.first_tick = True
        self.waiting_flows = []
Esempio n. 9
0
    def __init__(self, opts):
        self.should_exit = threading.Event()
        self.channel = controller.Channel(
            self,
            asyncio.get_event_loop(),
            self.should_exit,
        )

        self.options: options.Options = opts or options.Options()
        self.commands = command.CommandManager(self)
        self.addons = addonmanager.AddonManager(self)
        self._server = None
        self.waiting_flows = []
        self.log = log.Log(self)

        mitmproxy_ctx.master = self
        mitmproxy_ctx.log = self.log
        mitmproxy_ctx.options = self.options
Esempio n. 10
0
 def server(self, server):
     server.set_channel(
         controller.Channel(self.event_queue, self.should_exit)
     )
     self._server = server