diff options
| -rw-r--r-- | examples/har_dump.py | 2 | ||||
| -rw-r--r-- | mitmproxy/flow.py | 1 | ||||
| -rw-r--r-- | mitmproxy/tools/console/common.py | 7 | ||||
| -rw-r--r-- | mitmproxy/tools/console/flowview.py | 24 | ||||
| -rw-r--r-- | mitmproxy/tools/main.py | 23 | ||||
| -rw-r--r-- | test/mitmproxy/test_flow.py | 1 | ||||
| -rw-r--r-- | test/mitmproxy/test_utils_lrucache.py | 34 | 
7 files changed, 29 insertions, 63 deletions
| diff --git a/examples/har_dump.py b/examples/har_dump.py index efcf9d74..ab7bf1e1 100644 --- a/examples/har_dump.py +++ b/examples/har_dump.py @@ -140,7 +140,7 @@ def response(flow):              for a, b in flow.request.urlencoded_form.items(multi=True)          ]          entry["request"]["postData"] = { -            "mimeType": flow.request.headers.get("Content-Type", "").split(";")[0], +            "mimeType": flow.request.headers.get("Content-Type", ""),              "text": flow.request.get_text(strict=False),              "params": params          } diff --git a/mitmproxy/flow.py b/mitmproxy/flow.py index 2fb7ace0..a23abf5f 100644 --- a/mitmproxy/flow.py +++ b/mitmproxy/flow.py @@ -165,7 +165,6 @@ class Flow(stateobject.StateObject):              self.reply.take()          self.reply.kill(force=True)          self.reply.commit() -        master.error(self)      def intercept(self, master):          """ diff --git a/mitmproxy/tools/console/common.py b/mitmproxy/tools/console/common.py index 90dce5ae..78860702 100644 --- a/mitmproxy/tools/console/common.py +++ b/mitmproxy/tools/console/common.py @@ -7,7 +7,7 @@ import urwid  import urwid.util  import mitmproxy.net -from mitmproxy.utils import lrucache +from functools import lru_cache  from mitmproxy.tools.console import signals  from mitmproxy import export  from mitmproxy.utils import human @@ -325,9 +325,8 @@ def export_to_clip_or_file(key, scope, flow, writer):              else:  # other keys                  writer(exporter(flow)) -flowcache = lrucache.LRUCache(800) - +@lru_cache(maxsize=800)  def raw_format_flow(f):      f = dict(f)      pile = [] @@ -458,4 +457,4 @@ def format_flow(f, focus, extended=False, hostheader=False, max_url_len=False):          else:              d["resp_ctype"] = "" -    return flowcache.get(raw_format_flow, tuple(sorted(d.items()))) +    return raw_format_flow(tuple(sorted(d.items()))) diff --git a/mitmproxy/tools/console/flowview.py b/mitmproxy/tools/console/flowview.py index 4e886ee4..18947327 100644 --- a/mitmproxy/tools/console/flowview.py +++ b/mitmproxy/tools/console/flowview.py @@ -8,7 +8,6 @@ from typing import Optional, Union  # noqa  from mitmproxy import contentviews  from mitmproxy import http -from mitmproxy.utils import lrucache  from mitmproxy.tools.console import common  from mitmproxy.tools.console import flowdetailview  from mitmproxy.tools.console import grideditor @@ -18,6 +17,7 @@ from mitmproxy.tools.console import tabs  from mitmproxy import export  from mitmproxy.net.http import Headers  from mitmproxy.net.http import status_codes +from functools import lru_cache  class SearchError(Exception): @@ -120,9 +120,6 @@ class FlowViewHeader(urwid.WidgetWrap):                  hostheader=self.master.options.showhost              ) - -cache = lrucache.LRUCache(200) -  TAB_REQ = 0  TAB_RESP = 1 @@ -193,15 +190,14 @@ class FlowView(tabs.Tabs):                  message.headers.fields,                  getattr(message, "path", None),              )) -            return cache.get( -                # We move message into this partial function as it is not hashable. -                lambda *args: self._get_content_view(message, *args), -                viewmode, -                limit, -                flow_modify_cache_invalidation -            ) - -    def _get_content_view(self, message, viewmode, max_lines, _): +            # we need to pass the message off-band because it's not hashable +            self._get_content_view_message = message +            return self._get_content_view(viewmode, limit, flow_modify_cache_invalidation) + +    @lru_cache(maxsize=200) +    def _get_content_view(self, viewmode, max_lines, _): +        message = self._get_content_view_message +        self._get_content_view_message = None          description, lines, error = contentviews.get_message_content_view(              viewmode, message          ) @@ -480,7 +476,7 @@ class FlowView(tabs.Tabs):          else:              new_flow, new_idx = self.state.get_prev(idx)          if new_flow is None: -            signals.status_message.send(message="No more flows!") +            signals.status_message.send(message="No more flows")          else:              signals.pop_view_state.send(self)              self.master.view_flow(new_flow, self.tab_offset) diff --git a/mitmproxy/tools/main.py b/mitmproxy/tools/main.py index 9fce9234..f88bee6c 100644 --- a/mitmproxy/tools/main.py +++ b/mitmproxy/tools/main.py @@ -1,13 +1,20 @@ -import os -import signal +from __future__ import print_function  # this is here for the version check to work on Python 2.  import sys -from mitmproxy.tools import cmdline -from mitmproxy import exceptions -from mitmproxy.proxy import config -from mitmproxy.proxy import server -from mitmproxy.utils import version_check -from mitmproxy.utils import debug +if sys.version_info < (3, 5): +    print("#" * 49, file=sys.stderr) +    print("# mitmproxy only supports Python 3.5 and above! #", file=sys.stderr) +    print("#" * 49, file=sys.stderr) + +import os  # noqa +import signal  # noqa + +from mitmproxy.tools import cmdline  # noqa +from mitmproxy import exceptions  # noqa +from mitmproxy.proxy import config  # noqa +from mitmproxy.proxy import server  # noqa +from mitmproxy.utils import version_check  # noqa +from mitmproxy.utils import debug  # noqa  def assert_utf8_env(): diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py index d16bb6dd..ed15a766 100644 --- a/test/mitmproxy/test_flow.py +++ b/test/mitmproxy/test_flow.py @@ -104,7 +104,6 @@ class TestHTTPFlow:          assert f.killable          f.kill(fm)          assert not f.killable -        assert fm.error.called          assert f.reply.value == Kill      def test_killall(self): diff --git a/test/mitmproxy/test_utils_lrucache.py b/test/mitmproxy/test_utils_lrucache.py deleted file mode 100644 index 07b96b4d..00000000 --- a/test/mitmproxy/test_utils_lrucache.py +++ /dev/null @@ -1,34 +0,0 @@ -from mitmproxy.utils import lrucache - - -def test_LRUCache(): -    cache = lrucache.LRUCache(2) - -    class Foo: -        ran = False - -        def gen(self, x): -            self.ran = True -            return x -    f = Foo() - -    assert not f.ran -    assert cache.get(f.gen, 1) == 1 -    assert f.ran -    f.ran = False -    assert cache.get(f.gen, 1) == 1 -    assert not f.ran - -    f.ran = False -    assert cache.get(f.gen, 1) == 1 -    assert not f.ran -    assert cache.get(f.gen, 2) == 2 -    assert cache.get(f.gen, 3) == 3 -    assert f.ran - -    f.ran = False -    assert cache.get(f.gen, 1) == 1 -    assert f.ran - -    assert len(cache.cacheList) == 2 -    assert len(cache.cache) == 2 | 
