Skip to content

Commit

Permalink
Merge pull request mitmproxy#2742 from mhils/dataviewer-fix-edit
Browse files Browse the repository at this point in the history
Dataviewer: disable (broken) edit
  • Loading branch information
mhils authored Jan 4, 2018
2 parents 3858048 + 11429bf commit c6cd087
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 75 deletions.
67 changes: 0 additions & 67 deletions mitmproxy/tools/console/grideditor/col.py

This file was deleted.

2 changes: 1 addition & 1 deletion mitmproxy/tools/console/grideditor/col_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def Edit(self, data):
return TEdit(data, self.encoding_args)

def blank(self):
return u""
return ""


# This is the same for both edit and display.
Expand Down
33 changes: 33 additions & 0 deletions mitmproxy/tools/console/grideditor/col_viewany.py
Original file line number Diff line number Diff line change
@@ -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
25 changes: 18 additions & 7 deletions mitmproxy/tools/console/grideditor/editors.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -67,7 +68,6 @@ def set_data(self, vals, flow):

class PathEditor(base.FocusEditor):
# TODO: Next row on enter?

title = "Edit Path Components"
columns = [
col_text.Column("Component"),
Expand Down Expand Up @@ -175,11 +175,22 @@ def is_error(self, col, val):
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):
Expand Down

0 comments on commit c6cd087

Please sign in to comment.