mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 16:17:49 +00:00
Merge pull request #2742 from mhils/dataviewer-fix-edit
Dataviewer: disable (broken) edit
This commit is contained in:
commit
c6cd0872ea
@ -1,67 +0,0 @@
|
||||
import typing
|
||||
|
||||
import urwid
|
||||
|
||||
from mitmproxy.tools.console import signals
|
||||
from mitmproxy.tools.console.grideditor import base
|
||||
from mitmproxy.utils import strutils
|
||||
|
||||
strbytes = typing.Union[str, bytes]
|
||||
|
||||
|
||||
class Column(base.Column):
|
||||
def Display(self, data):
|
||||
return Display(data)
|
||||
|
||||
def Edit(self, data):
|
||||
return Edit(data)
|
||||
|
||||
def blank(self):
|
||||
return ""
|
||||
|
||||
def keypress(self, key, editor):
|
||||
if key in ["m_select"]:
|
||||
editor.walker.start_edit()
|
||||
else:
|
||||
return key
|
||||
|
||||
|
||||
class Display(base.Cell):
|
||||
def __init__(self, data: strbytes) -> None:
|
||||
self.data = data
|
||||
if isinstance(data, bytes):
|
||||
escaped = strutils.bytes_to_escaped_str(data)
|
||||
else:
|
||||
escaped = data.encode()
|
||||
w = urwid.Text(escaped, wrap="any")
|
||||
super().__init__(w)
|
||||
|
||||
def get_data(self) -> strbytes:
|
||||
return self.data
|
||||
|
||||
|
||||
class Edit(base.Cell):
|
||||
def __init__(self, data: strbytes) -> None:
|
||||
if isinstance(data, bytes):
|
||||
escaped = strutils.bytes_to_escaped_str(data)
|
||||
else:
|
||||
escaped = data.encode()
|
||||
self.type = type(data) # type: typing.Type
|
||||
w = urwid.Edit(edit_text=escaped, wrap="any", multiline=True)
|
||||
w = urwid.AttrWrap(w, "editfield")
|
||||
super().__init__(w)
|
||||
|
||||
def get_data(self) -> strbytes:
|
||||
txt = self._w.get_text()[0].strip()
|
||||
try:
|
||||
if self.type == bytes:
|
||||
return strutils.escaped_str_to_bytes(txt)
|
||||
else:
|
||||
return txt.decode()
|
||||
except ValueError:
|
||||
signals.status_message.send(
|
||||
self,
|
||||
message="Invalid Python-style string encoding.",
|
||||
expire=1000
|
||||
)
|
||||
raise
|
@ -21,7 +21,7 @@ class Column(col_bytes.Column):
|
||||
return TEdit(data, self.encoding_args)
|
||||
|
||||
def blank(self):
|
||||
return u""
|
||||
return ""
|
||||
|
||||
|
||||
# This is the same for both edit and display.
|
||||
|
33
mitmproxy/tools/console/grideditor/col_viewany.py
Normal file
33
mitmproxy/tools/console/grideditor/col_viewany.py
Normal file
@ -0,0 +1,33 @@
|
||||
"""
|
||||
A display-only column that displays any data type.
|
||||
"""
|
||||
|
||||
import typing
|
||||
|
||||
import urwid
|
||||
from mitmproxy.tools.console.grideditor import base
|
||||
from mitmproxy.utils import strutils
|
||||
|
||||
|
||||
class Column(base.Column):
|
||||
def Display(self, data):
|
||||
return Display(data)
|
||||
|
||||
Edit = Display
|
||||
|
||||
def blank(self):
|
||||
return ""
|
||||
|
||||
|
||||
class Display(base.Cell):
|
||||
def __init__(self, data: typing.Any) -> None:
|
||||
self.data = data
|
||||
if isinstance(data, bytes):
|
||||
data = strutils.bytes_to_escaped_str(data)
|
||||
if not isinstance(data, str):
|
||||
data = repr(data)
|
||||
w = urwid.Text(data, wrap="any")
|
||||
super().__init__(w)
|
||||
|
||||
def get_data(self) -> typing.Any:
|
||||
return self.data
|
@ -1,13 +1,14 @@
|
||||
import typing
|
||||
|
||||
from mitmproxy import exceptions
|
||||
from mitmproxy.net.http import Headers
|
||||
from mitmproxy.tools.console import layoutwidget
|
||||
from mitmproxy.tools.console import signals
|
||||
from mitmproxy.tools.console.grideditor import base
|
||||
from mitmproxy.tools.console.grideditor import col
|
||||
from mitmproxy.tools.console.grideditor import col_text
|
||||
from mitmproxy.tools.console.grideditor import col_bytes
|
||||
from mitmproxy.tools.console.grideditor import col_subgrid
|
||||
from mitmproxy.tools.console import signals
|
||||
from mitmproxy.net.http import Headers
|
||||
from mitmproxy.tools.console.grideditor import col_text
|
||||
from mitmproxy.tools.console.grideditor import col_viewany
|
||||
|
||||
|
||||
class QueryEditor(base.FocusEditor):
|
||||
@ -67,7 +68,6 @@ class RequestFormEditor(base.FocusEditor):
|
||||
|
||||
class PathEditor(base.FocusEditor):
|
||||
# TODO: Next row on enter?
|
||||
|
||||
title = "Edit Path Components"
|
||||
columns = [
|
||||
col_text.Column("Component"),
|
||||
@ -175,11 +175,22 @@ class OptionsEditor(base.GridEditor, layoutwidget.LayoutWidget):
|
||||
class DataViewer(base.GridEditor, layoutwidget.LayoutWidget):
|
||||
title = None # type: str
|
||||
|
||||
def __init__(self, master, vals):
|
||||
def __init__(
|
||||
self,
|
||||
master,
|
||||
vals: typing.Union[
|
||||
typing.List[typing.List[typing.Any]],
|
||||
typing.List[typing.Any],
|
||||
str,
|
||||
]) -> None:
|
||||
if vals:
|
||||
# Whatever vals is, make it a list of rows containing lists of column values.
|
||||
if isinstance(vals, str):
|
||||
vals = [vals]
|
||||
if not isinstance(vals[0], list):
|
||||
vals = [[i] for i in vals]
|
||||
self.columns = [col.Column("")] * len(vals[0])
|
||||
|
||||
self.columns = [col_viewany.Column("")] * len(vals[0])
|
||||
super().__init__(master, vals, self.callback)
|
||||
|
||||
def callback(self, vals):
|
||||
|
Loading…
Reference in New Issue
Block a user