Merge pull request #2884 from kajojify/hotkeys-cleanup

Hotkeys cleanup. #2877
This commit is contained in:
Maximilian Hils 2018-02-20 21:45:48 +01:00 committed by GitHub
commit 95c160ac13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 1 additions and 61 deletions

View File

@ -7,10 +7,6 @@ from mitmproxy import contentviews
class ViewSwapCase(contentviews.View): class ViewSwapCase(contentviews.View):
name = "swapcase" 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"] content_types = ["text/plain"]
def __call__(self, data, **metadata) -> contentviews.TViewResult: def __call__(self, data, **metadata) -> contentviews.TViewResult:

View File

@ -16,7 +16,6 @@ parameters are passed as the ``query`` keyword argument.
import traceback import traceback
from typing import Dict, Optional # noqa from typing import Dict, Optional # noqa
from typing import List # noqa from typing import List # noqa
from typing import Tuple # noqa
from mitmproxy import exceptions from mitmproxy import exceptions
from mitmproxy.net import http 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] views = [] # type: List[View]
content_types_map = {} # type: Dict[str, List[View]] content_types_map = {} # type: Dict[str, List[View]]
view_prompts = [] # type: List[Tuple[str, str]]
def get(name: str) -> Optional[View]: def get(name: str) -> Optional[View]:
@ -39,32 +37,18 @@ def get(name: str) -> Optional[View]:
return None 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: def add(view: View) -> None:
# TODO: auto-select a different name (append an integer?) # TODO: auto-select a different name (append an integer?)
for i in views: for i in views:
if i.name == view.name: if i.name == view.name:
raise exceptions.ContentViewException("Duplicate view: " + 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) views.append(view)
for ct in view.content_types: for ct in view.content_types:
l = content_types_map.setdefault(ct, []) l = content_types_map.setdefault(ct, [])
l.append(view) l.append(view)
view_prompts.append(view.prompt)
def remove(view: View) -> None: def remove(view: View) -> None:
for ct in view.content_types: for ct in view.content_types:
@ -74,7 +58,6 @@ def remove(view: View) -> None:
if not len(l): if not len(l):
del content_types_map[ct] del content_types_map[ct]
view_prompts.remove(view.prompt)
views.remove(view) views.remove(view)
@ -178,6 +161,5 @@ add(protobuf.ViewProtobuf())
__all__ = [ __all__ = [
"View", "VIEW_CUTOFF", "KEY_MAX", "format_text", "format_dict", "TViewResult", "View", "VIEW_CUTOFF", "KEY_MAX", "format_text", "format_dict", "TViewResult",
"get", "get_by_shortcut", "add", "remove", "get", "add", "remove", "get_content_view", "get_message_content_view",
"get_content_view", "get_message_content_view",
] ]

View File

@ -6,7 +6,6 @@ from . import base
class ViewAuto(base.View): class ViewAuto(base.View):
name = "Auto" name = "Auto"
prompt = ("auto", "a")
def __call__(self, data, **metadata): def __call__(self, data, **metadata):
headers = metadata.get("headers", {}) headers = metadata.get("headers", {})

View File

@ -12,7 +12,6 @@ TViewResult = typing.Tuple[str, typing.Iterator[TViewLine]]
class View: class View:
name = None # type: str name = None # type: str
prompt = None # type: typing.Tuple[str,str]
content_types = [] # type: typing.List[str] content_types = [] # type: typing.List[str]
def __call__(self, data: bytes, **metadata) -> TViewResult: def __call__(self, data: bytes, **metadata) -> TViewResult:

View File

@ -50,7 +50,6 @@ def beautify(data: str, indent: str = " "):
class ViewCSS(base.View): class ViewCSS(base.View):
name = "CSS" name = "CSS"
prompt = ("css", "c")
content_types = [ content_types = [
"text/css" "text/css"
] ]

View File

@ -4,7 +4,6 @@ from . import base
class ViewHex(base.View): class ViewHex(base.View):
name = "Hex" name = "Hex"
prompt = ("hex", "e")
@staticmethod @staticmethod
def _format(data): def _format(data):

View File

@ -15,7 +15,6 @@ imghdr.tests.append(test_ico)
class ViewImage(base.View): class ViewImage(base.View):
name = "Image" name = "Image"
prompt = ("image", "i")
# there is also a fallback in the auto view for image/*. # there is also a fallback in the auto view for image/*.
content_types = [ content_types = [

View File

@ -46,7 +46,6 @@ def beautify(data):
class ViewJavaScript(base.View): class ViewJavaScript(base.View):
name = "JavaScript" name = "JavaScript"
prompt = ("javascript", "j")
content_types = [ content_types = [
"application/x-javascript", "application/x-javascript",
"application/javascript", "application/javascript",

View File

@ -15,7 +15,6 @@ def pretty_json(s: bytes) -> Optional[bytes]:
class ViewJSON(base.View): class ViewJSON(base.View):
name = "JSON" name = "JSON"
prompt = ("json", "s")
content_types = [ content_types = [
"application/json", "application/json",
"application/vnd.api+json" "application/vnd.api+json"

View File

@ -5,7 +5,6 @@ from . import base
class ViewMultipart(base.View): class ViewMultipart(base.View):
name = "Multipart Form" name = "Multipart Form"
prompt = ("multipart", "m")
content_types = ["multipart/form-data"] content_types = ["multipart/form-data"]
@staticmethod @staticmethod

View File

@ -66,7 +66,6 @@ class ViewProtobuf(base.View):
""" """
name = "Protocol Buffer" name = "Protocol Buffer"
prompt = ("protobuf", "p")
content_types = [ content_types = [
"application/x-protobuf", "application/x-protobuf",
"application/x-protobuffer", "application/x-protobuffer",

View File

@ -5,7 +5,6 @@ from . import base
class ViewQuery(base.View): class ViewQuery(base.View):
name = "Query" name = "Query"
prompt = ("query", "q")
def __call__(self, data, **metadata): def __call__(self, data, **metadata):
query = metadata.get("query") query = metadata.get("query")

View File

@ -6,7 +6,6 @@ from . import base
class ViewRaw(base.View): class ViewRaw(base.View):
name = "Raw" name = "Raw"
prompt = ("raw", "r")
def __call__(self, data, **metadata): def __call__(self, data, **metadata):
return "Raw", base.format_text(strutils.bytes_to_escaped_str(data, True)) return "Raw", base.format_text(strutils.bytes_to_escaped_str(data, True))

View File

@ -5,7 +5,6 @@ from . import base
class ViewURLEncoded(base.View): class ViewURLEncoded(base.View):
name = "URL-encoded" name = "URL-encoded"
prompt = ("urlencoded", "u")
content_types = ["application/x-www-form-urlencoded"] content_types = ["application/x-www-form-urlencoded"]
def __call__(self, data, **metadata): def __call__(self, data, **metadata):

View File

@ -4,7 +4,6 @@ from . import base
class ViewWBXML(base.View): class ViewWBXML(base.View):
name = "WBXML" name = "WBXML"
prompt = ("wbxml", "w")
content_types = [ content_types = [
"application/vnd.wap.wbxml", "application/vnd.wap.wbxml",
"application/vnd.ms-sync.wbxml" "application/vnd.ms-sync.wbxml"

View File

@ -214,7 +214,6 @@ def format_xml(tokens: Iterable[Token]) -> str:
class ViewXmlHtml(base.View): class ViewXmlHtml(base.View):
name = "XML/HTML" name = "XML/HTML"
prompt = ("xml/html", "x")
content_types = ["text/xml", "text/html"] content_types = ["text/xml", "text/html"]
def __call__(self, data, **metadata): def __call__(self, data, **metadata):

View File

@ -10,17 +10,6 @@ from mitmproxy.utils import human
# Detect Windows Subsystem for Linux # Detect Windows Subsystem for Linux
IS_WSL = "Microsoft" in platform.platform() 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): def is_keypress(k):
""" """

View File

@ -9,7 +9,6 @@ from mitmproxy.test import tutils
class TestContentView(contentviews.View): class TestContentView(contentviews.View):
name = "test" name = "test"
prompt = ("test", "t")
content_types = ["test/123"] content_types = ["test/123"]
@ -22,13 +21,6 @@ def test_add_remove():
with pytest.raises(ContentViewException, match="Duplicate view"): with pytest.raises(ContentViewException, match="Duplicate view"):
contentviews.add(tcv) 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) contentviews.remove(tcv)
assert tcv not in contentviews.views assert tcv not in contentviews.views
@ -86,8 +78,3 @@ def test_get_message_content_view():
r.content = None r.content = None
desc, lines, err = contentviews.get_message_content_view("raw", r) desc, lines, err = contentviews.get_message_content_view("raw", r)
assert list(lines) == [[("error", "content missing")]] assert list(lines) == [[("error", "content missing")]]
def test_get_by_shortcut():
assert contentviews.get_by_shortcut("s")
assert not contentviews.get_by_shortcut("b")