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):
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:

View File

@ -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",
]

View File

@ -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", {})

View File

@ -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:

View File

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

View File

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

View File

@ -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 = [

View File

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

View File

@ -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"

View File

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

View File

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

View File

@ -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")

View File

@ -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))

View File

@ -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):

View File

@ -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"

View File

@ -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):

View File

@ -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):
"""

View File

@ -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")