aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/master.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2017-03-16 15:51:21 +1300
committerGitHub <noreply@github.com>2017-03-16 15:51:21 +1300
commit1e6c51c69831679681b964c2f431ad578a30d475 (patch)
tree3301af21683545f35bcd83a09e360eee08286793 /mitmproxy/master.py
parentdadefaecdba902d60767736152470ff25c4147fe (diff)
parent228a22b3c044b23bd75e4558778722bf3f44cf24 (diff)
downloadmitmproxy-1e6c51c69831679681b964c2f431ad578a30d475.tar.gz
mitmproxy-1e6c51c69831679681b964c2f431ad578a30d475.tar.bz2
mitmproxy-1e6c51c69831679681b964c2f431ad578a30d475.zip
Merge pull request #2152 from cortesi/readfile
Extract flow reading into addons
Diffstat (limited to 'mitmproxy/master.py')
-rw-r--r--mitmproxy/master.py38
1 files changed, 3 insertions, 35 deletions
diff --git a/mitmproxy/master.py b/mitmproxy/master.py
index 57d47394..887a9240 100644
--- a/mitmproxy/master.py
+++ b/mitmproxy/master.py
@@ -1,8 +1,6 @@
-import os
import threading
import contextlib
import queue
-import sys
from mitmproxy import addonmanager
from mitmproxy import options
@@ -12,7 +10,6 @@ from mitmproxy import exceptions
from mitmproxy import connections
from mitmproxy import http
from mitmproxy import log
-from mitmproxy import io
from mitmproxy.proxy.protocol import http_replay
from mitmproxy.types import basethread
@@ -67,8 +64,7 @@ class Master:
"""
level: debug, info, warn, error
"""
- with self.handlecontext():
- self.addons("log", log.LogEntry(e, level))
+ self.addons.trigger("log", log.LogEntry(e, level))
def start(self):
self.should_exit.clear()
@@ -88,9 +84,8 @@ class Master:
def tick(self, timeout):
if self.first_tick:
self.first_tick = False
- self.addons.invoke_all_with_context("running")
- with self.handlecontext():
- self.addons("tick")
+ self.addons.trigger("running")
+ self.addons.trigger("tick")
changed = False
try:
mtype, obj = self.event_queue.get(timeout=timeout)
@@ -150,33 +145,6 @@ class Master:
for e, o in eventsequence.iterate(f):
getattr(self, e)(o)
- def load_flows(self, fr: io.FlowReader) -> int:
- """
- Load flows from a FlowReader object.
- """
- cnt = 0
- for i in fr.stream():
- cnt += 1
- self.load_flow(i)
- return cnt
-
- def load_flows_file(self, path: str) -> int:
- path = os.path.expanduser(path)
- try:
- if path == "-":
- try:
- sys.stdin.buffer.read(0)
- except Exception as e:
- raise IOError("Cannot read from stdin: {}".format(e))
- freader = io.FlowReader(sys.stdin.buffer)
- return self.load_flows(freader)
- else:
- with open(path, "rb") as f:
- freader = io.FlowReader(f)
- return self.load_flows(freader)
- except IOError as v:
- raise exceptions.FlowReadException(v.strerror)
-
def replay_request(
self,
f: http.HTTPFlow,