aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2018-04-02 15:47:23 +1200
committerAldo Cortesi <aldo@nullcube.com>2018-04-02 16:41:49 +1200
commit14f461c5d59e95e84658ea43567b3ca9f7d0a108 (patch)
tree1e76216ac2a1a86c237dee2e1ed89cba87224cb1
parent1f33c1c1a54e466f903cc69a2e086d699515cad8 (diff)
downloadmitmproxy-14f461c5d59e95e84658ea43567b3ca9f7d0a108.tar.gz
mitmproxy-14f461c5d59e95e84658ea43567b3ca9f7d0a108.tar.bz2
mitmproxy-14f461c5d59e95e84658ea43567b3ca9f7d0a108.zip
asyncio: cleanup and lint
Also fix a racy websocket test.
-rw-r--r--mitmproxy/addons/termstatus.py1
-rw-r--r--mitmproxy/master.py5
-rw-r--r--mitmproxy/tools/web/master.py1
-rw-r--r--test/mitmproxy/proxy/protocol/test_websocket.py7
-rw-r--r--test/mitmproxy/test_flow.py2
5 files changed, 10 insertions, 6 deletions
diff --git a/mitmproxy/addons/termstatus.py b/mitmproxy/addons/termstatus.py
index 3801f320..c3c91283 100644
--- a/mitmproxy/addons/termstatus.py
+++ b/mitmproxy/addons/termstatus.py
@@ -1,4 +1,3 @@
-import sys
from mitmproxy import ctx
from mitmproxy.utils import human
diff --git a/mitmproxy/master.py b/mitmproxy/master.py
index 022590d4..372bb289 100644
--- a/mitmproxy/master.py
+++ b/mitmproxy/master.py
@@ -85,7 +85,8 @@ class Master:
mitmproxy_ctx.log = None
mitmproxy_ctx.options = None
- def tell(self, mtype, m):
+ # This is a vestigial function that will go away in a refactor very soon
+ def tell(self, mtype, m): # pragma: no cover
m.reply = controller.DummyReply()
self.event_queue.put((mtype, m))
@@ -106,7 +107,7 @@ class Master:
mtype, obj = await self.event_queue.get()
except RuntimeError:
return
- if mtype not in eventsequence.Events:
+ if mtype not in eventsequence.Events: # pragma: no cover
raise exceptions.ControlException("Unknown event %s" % repr(mtype))
self.addons.handle_lifecycle(mtype, obj)
self.event_queue.task_done()
diff --git a/mitmproxy/tools/web/master.py b/mitmproxy/tools/web/master.py
index 843190e0..b7eddcce 100644
--- a/mitmproxy/tools/web/master.py
+++ b/mitmproxy/tools/web/master.py
@@ -3,7 +3,6 @@ import webbrowser
import tornado.httpserver
import tornado.ioloop
from tornado.platform.asyncio import AsyncIOMainLoop
-import asyncio
from mitmproxy import addons
from mitmproxy import log
diff --git a/test/mitmproxy/proxy/protocol/test_websocket.py b/test/mitmproxy/proxy/protocol/test_websocket.py
index 014490b7..f64f500c 100644
--- a/test/mitmproxy/proxy/protocol/test_websocket.py
+++ b/test/mitmproxy/proxy/protocol/test_websocket.py
@@ -331,7 +331,12 @@ class TestPong(_WebSocketTest):
assert frame.header.opcode == websockets.OPCODE.PONG
assert frame.payload == b'foobar'
- assert self.master.has_log("Pong Received from server", "info")
+ for i in range(20):
+ if self.master.has_log("Pong Received from server", "info"):
+ break
+ time.sleep(0.01)
+ else:
+ raise AssertionError("No pong seen")
class TestClose(_WebSocketTest):
diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py
index 9f1fb213..4042de5b 100644
--- a/test/mitmproxy/test_flow.py
+++ b/test/mitmproxy/test_flow.py
@@ -7,7 +7,7 @@ import mitmproxy.io
from mitmproxy import flowfilter
from mitmproxy import options
from mitmproxy.io import tnetstring
-from mitmproxy.exceptions import FlowReadException, ReplayException, ControlException
+from mitmproxy.exceptions import FlowReadException, ReplayException
from mitmproxy import flow
from mitmproxy import http
from mitmproxy.net import http as net_http