mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 15:37:45 +00:00
Merge pull request #2884 from kajojify/hotkeys-cleanup
Hotkeys cleanup. #2877
This commit is contained in:
commit
95c160ac13
@ -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:
|
||||
|
@ -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",
|
||||
]
|
||||
|
@ -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", {})
|
||||
|
@ -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:
|
||||
|
@ -50,7 +50,6 @@ def beautify(data: str, indent: str = " "):
|
||||
|
||||
class ViewCSS(base.View):
|
||||
name = "CSS"
|
||||
prompt = ("css", "c")
|
||||
content_types = [
|
||||
"text/css"
|
||||
]
|
||||
|
@ -4,7 +4,6 @@ from . import base
|
||||
|
||||
class ViewHex(base.View):
|
||||
name = "Hex"
|
||||
prompt = ("hex", "e")
|
||||
|
||||
@staticmethod
|
||||
def _format(data):
|
||||
|
@ -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 = [
|
||||
|
@ -46,7 +46,6 @@ def beautify(data):
|
||||
|
||||
class ViewJavaScript(base.View):
|
||||
name = "JavaScript"
|
||||
prompt = ("javascript", "j")
|
||||
content_types = [
|
||||
"application/x-javascript",
|
||||
"application/javascript",
|
||||
|
@ -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"
|
||||
|
@ -5,7 +5,6 @@ from . import base
|
||||
|
||||
class ViewMultipart(base.View):
|
||||
name = "Multipart Form"
|
||||
prompt = ("multipart", "m")
|
||||
content_types = ["multipart/form-data"]
|
||||
|
||||
@staticmethod
|
||||
|
@ -66,7 +66,6 @@ class ViewProtobuf(base.View):
|
||||
"""
|
||||
|
||||
name = "Protocol Buffer"
|
||||
prompt = ("protobuf", "p")
|
||||
content_types = [
|
||||
"application/x-protobuf",
|
||||
"application/x-protobuffer",
|
||||
|
@ -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")
|
||||
|
@ -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))
|
||||
|
@ -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):
|
||||
|
@ -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"
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
"""
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user