diff --git a/examples/simple/custom_contentview.py b/examples/simple/custom_contentview.py index b958bdcea..77d324740 100644 --- a/examples/simple/custom_contentview.py +++ b/examples/simple/custom_contentview.py @@ -7,10 +7,6 @@ from mitmproxy import contentviews class ViewSwapCase(contentviews.View): name = "swapcase" - - # We don't have a good solution for the keyboard shortcut yet - - # you manually need to find a free letter. Contributions welcome :) - prompt = ("swap case text", "z") content_types = ["text/plain"] def __call__(self, data, **metadata) -> contentviews.TViewResult: diff --git a/mitmproxy/contentviews/__init__.py b/mitmproxy/contentviews/__init__.py index f696f669e..069dca082 100644 --- a/mitmproxy/contentviews/__init__.py +++ b/mitmproxy/contentviews/__init__.py @@ -16,7 +16,6 @@ parameters are passed as the ``query`` keyword argument. import traceback from typing import Dict, Optional # noqa from typing import List # noqa -from typing import Tuple # noqa from mitmproxy import exceptions from mitmproxy.net import http @@ -29,7 +28,6 @@ from .base import View, VIEW_CUTOFF, KEY_MAX, format_text, format_dict, TViewRes views = [] # type: List[View] content_types_map = {} # type: Dict[str, List[View]] -view_prompts = [] # type: List[Tuple[str, str]] def get(name: str) -> Optional[View]: @@ -39,32 +37,18 @@ def get(name: str) -> Optional[View]: return None -def get_by_shortcut(c: str) -> Optional[View]: - for i in views: - if i.prompt[1] == c: - return i - return None - - def add(view: View) -> None: # TODO: auto-select a different name (append an integer?) for i in views: if i.name == view.name: raise exceptions.ContentViewException("Duplicate view: " + view.name) - # TODO: the UI should auto-prompt for a replacement shortcut - for prompt in view_prompts: - if prompt[1] == view.prompt[1]: - raise exceptions.ContentViewException("Duplicate view shortcut: " + view.prompt[1]) - views.append(view) for ct in view.content_types: l = content_types_map.setdefault(ct, []) l.append(view) - view_prompts.append(view.prompt) - def remove(view: View) -> None: for ct in view.content_types: @@ -74,7 +58,6 @@ def remove(view: View) -> None: if not len(l): del content_types_map[ct] - view_prompts.remove(view.prompt) views.remove(view) @@ -178,6 +161,5 @@ add(protobuf.ViewProtobuf()) __all__ = [ "View", "VIEW_CUTOFF", "KEY_MAX", "format_text", "format_dict", "TViewResult", - "get", "get_by_shortcut", "add", "remove", - "get_content_view", "get_message_content_view", + "get", "add", "remove", "get_content_view", "get_message_content_view", ] diff --git a/mitmproxy/contentviews/auto.py b/mitmproxy/contentviews/auto.py index d46a1bd3e..92d7c1f59 100644 --- a/mitmproxy/contentviews/auto.py +++ b/mitmproxy/contentviews/auto.py @@ -6,7 +6,6 @@ from . import base class ViewAuto(base.View): name = "Auto" - prompt = ("auto", "a") def __call__(self, data, **metadata): headers = metadata.get("headers", {}) diff --git a/mitmproxy/contentviews/base.py b/mitmproxy/contentviews/base.py index dbaa6cccf..19fc2b1b7 100644 --- a/mitmproxy/contentviews/base.py +++ b/mitmproxy/contentviews/base.py @@ -12,7 +12,6 @@ TViewResult = typing.Tuple[str, typing.Iterator[TViewLine]] class View: name = None # type: str - prompt = None # type: typing.Tuple[str,str] content_types = [] # type: typing.List[str] def __call__(self, data: bytes, **metadata) -> TViewResult: diff --git a/mitmproxy/contentviews/css.py b/mitmproxy/contentviews/css.py index 30a583da5..cbe8ce620 100644 --- a/mitmproxy/contentviews/css.py +++ b/mitmproxy/contentviews/css.py @@ -50,7 +50,6 @@ def beautify(data: str, indent: str = " "): class ViewCSS(base.View): name = "CSS" - prompt = ("css", "c") content_types = [ "text/css" ] diff --git a/mitmproxy/contentviews/hex.py b/mitmproxy/contentviews/hex.py index 6251a8f30..f88bf80c5 100644 --- a/mitmproxy/contentviews/hex.py +++ b/mitmproxy/contentviews/hex.py @@ -4,7 +4,6 @@ from . import base class ViewHex(base.View): name = "Hex" - prompt = ("hex", "e") @staticmethod def _format(data): diff --git a/mitmproxy/contentviews/image/view.py b/mitmproxy/contentviews/image/view.py index fde9b39d6..f6c37067c 100644 --- a/mitmproxy/contentviews/image/view.py +++ b/mitmproxy/contentviews/image/view.py @@ -15,7 +15,6 @@ imghdr.tests.append(test_ico) class ViewImage(base.View): name = "Image" - prompt = ("image", "i") # there is also a fallback in the auto view for image/*. content_types = [ diff --git a/mitmproxy/contentviews/javascript.py b/mitmproxy/contentviews/javascript.py index 1d671fe68..1440ea5d1 100644 --- a/mitmproxy/contentviews/javascript.py +++ b/mitmproxy/contentviews/javascript.py @@ -46,7 +46,6 @@ def beautify(data): class ViewJavaScript(base.View): name = "JavaScript" - prompt = ("javascript", "j") content_types = [ "application/x-javascript", "application/javascript", diff --git a/mitmproxy/contentviews/json.py b/mitmproxy/contentviews/json.py index de7f1093c..e045bbb07 100644 --- a/mitmproxy/contentviews/json.py +++ b/mitmproxy/contentviews/json.py @@ -15,7 +15,6 @@ def pretty_json(s: bytes) -> Optional[bytes]: class ViewJSON(base.View): name = "JSON" - prompt = ("json", "s") content_types = [ "application/json", "application/vnd.api+json" diff --git a/mitmproxy/contentviews/multipart.py b/mitmproxy/contentviews/multipart.py index be3dc1357..e122df599 100644 --- a/mitmproxy/contentviews/multipart.py +++ b/mitmproxy/contentviews/multipart.py @@ -5,7 +5,6 @@ from . import base class ViewMultipart(base.View): name = "Multipart Form" - prompt = ("multipart", "m") content_types = ["multipart/form-data"] @staticmethod diff --git a/mitmproxy/contentviews/protobuf.py b/mitmproxy/contentviews/protobuf.py index abd3985a6..50f8dcede 100644 --- a/mitmproxy/contentviews/protobuf.py +++ b/mitmproxy/contentviews/protobuf.py @@ -66,7 +66,6 @@ class ViewProtobuf(base.View): """ name = "Protocol Buffer" - prompt = ("protobuf", "p") content_types = [ "application/x-protobuf", "application/x-protobuffer", diff --git a/mitmproxy/contentviews/query.py b/mitmproxy/contentviews/query.py index 93f478294..4896624bb 100644 --- a/mitmproxy/contentviews/query.py +++ b/mitmproxy/contentviews/query.py @@ -5,7 +5,6 @@ from . import base class ViewQuery(base.View): name = "Query" - prompt = ("query", "q") def __call__(self, data, **metadata): query = metadata.get("query") diff --git a/mitmproxy/contentviews/raw.py b/mitmproxy/contentviews/raw.py index dcc53aa7c..300e70bb1 100644 --- a/mitmproxy/contentviews/raw.py +++ b/mitmproxy/contentviews/raw.py @@ -6,7 +6,6 @@ from . import base class ViewRaw(base.View): name = "Raw" - prompt = ("raw", "r") def __call__(self, data, **metadata): return "Raw", base.format_text(strutils.bytes_to_escaped_str(data, True)) diff --git a/mitmproxy/contentviews/urlencoded.py b/mitmproxy/contentviews/urlencoded.py index a24f342a7..371a160e9 100644 --- a/mitmproxy/contentviews/urlencoded.py +++ b/mitmproxy/contentviews/urlencoded.py @@ -5,7 +5,6 @@ from . import base class ViewURLEncoded(base.View): name = "URL-encoded" - prompt = ("urlencoded", "u") content_types = ["application/x-www-form-urlencoded"] def __call__(self, data, **metadata): diff --git a/mitmproxy/contentviews/wbxml.py b/mitmproxy/contentviews/wbxml.py index d626e188a..b33f4ce89 100644 --- a/mitmproxy/contentviews/wbxml.py +++ b/mitmproxy/contentviews/wbxml.py @@ -4,7 +4,6 @@ from . import base class ViewWBXML(base.View): name = "WBXML" - prompt = ("wbxml", "w") content_types = [ "application/vnd.wap.wbxml", "application/vnd.ms-sync.wbxml" diff --git a/mitmproxy/contentviews/xml_html.py b/mitmproxy/contentviews/xml_html.py index 62fb939fd..292290c73 100644 --- a/mitmproxy/contentviews/xml_html.py +++ b/mitmproxy/contentviews/xml_html.py @@ -214,7 +214,6 @@ def format_xml(tokens: Iterable[Token]) -> str: class ViewXmlHtml(base.View): name = "XML/HTML" - prompt = ("xml/html", "x") content_types = ["text/xml", "text/html"] def __call__(self, data, **metadata): diff --git a/mitmproxy/tools/console/common.py b/mitmproxy/tools/console/common.py index 8a8427995..72282015b 100644 --- a/mitmproxy/tools/console/common.py +++ b/mitmproxy/tools/console/common.py @@ -10,17 +10,6 @@ from mitmproxy.utils import human # Detect Windows Subsystem for Linux IS_WSL = "Microsoft" in platform.platform() -METHOD_OPTIONS = [ - ("get", "g"), - ("post", "p"), - ("put", "u"), - ("head", "h"), - ("trace", "t"), - ("delete", "d"), - ("options", "o"), - ("edit raw", "e"), -] - def is_keypress(k): """ diff --git a/test/mitmproxy/contentviews/test_api.py b/test/mitmproxy/contentviews/test_api.py index c072c86ff..3fc06d7c8 100644 --- a/test/mitmproxy/contentviews/test_api.py +++ b/test/mitmproxy/contentviews/test_api.py @@ -9,7 +9,6 @@ from mitmproxy.test import tutils class TestContentView(contentviews.View): name = "test" - prompt = ("test", "t") content_types = ["test/123"] @@ -22,13 +21,6 @@ def test_add_remove(): with pytest.raises(ContentViewException, match="Duplicate view"): contentviews.add(tcv) - tcv2 = TestContentView() - tcv2.name = "test2" - tcv2.prompt = ("test2", "t") - # Same shortcut doesn't work either. - with pytest.raises(ContentViewException, match="Duplicate view shortcut"): - contentviews.add(tcv2) - contentviews.remove(tcv) assert tcv not in contentviews.views @@ -86,8 +78,3 @@ def test_get_message_content_view(): r.content = None desc, lines, err = contentviews.get_message_content_view("raw", r) assert list(lines) == [[("error", "content missing")]] - - -def test_get_by_shortcut(): - assert contentviews.get_by_shortcut("s") - assert not contentviews.get_by_shortcut("b")