aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mitmproxy/command.py6
-rw-r--r--mitmproxy/tools/console/consoleaddons.py25
-rw-r--r--mitmproxy/tools/console/defaultkeys.py14
-rw-r--r--setup.py2
-rw-r--r--test/mitmproxy/test_command.py19
5 files changed, 43 insertions, 23 deletions
diff --git a/mitmproxy/command.py b/mitmproxy/command.py
index 22c2376b..c86d9792 100644
--- a/mitmproxy/command.py
+++ b/mitmproxy/command.py
@@ -110,7 +110,7 @@ class Arg(str):
pass
-def typename(t: type, ret: bool) -> str:
+def typename(t: type) -> str:
"""
Translates a type to an explanatory string. If ret is True, we're
looking at a return type, else we're looking at a parameter type.
@@ -153,13 +153,13 @@ class Command:
self.returntype = sig.return_annotation
def paramnames(self) -> typing.Sequence[str]:
- v = [typename(i, False) for i in self.paramtypes]
+ v = [typename(i) for i in self.paramtypes]
if self.has_positional:
v[-1] = "*" + v[-1]
return v
def retname(self) -> str:
- return typename(self.returntype, True) if self.returntype else ""
+ return typename(self.returntype) if self.returntype else ""
def signature_help(self) -> str:
params = " ".join(self.paramnames())
diff --git a/mitmproxy/tools/console/consoleaddons.py b/mitmproxy/tools/console/consoleaddons.py
index 61e107f4..453e9e1c 100644
--- a/mitmproxy/tools/console/consoleaddons.py
+++ b/mitmproxy/tools/console/consoleaddons.py
@@ -1,3 +1,4 @@
+import csv
import typing
from mitmproxy import ctx
@@ -402,21 +403,35 @@ class ConsoleAddon:
"""
self._grideditor().cmd_delete()
- @command.command("console.grideditor.readfile")
- def grideditor_readfile(self, path: command.Path) -> None:
+ @command.command("console.grideditor.load")
+ def grideditor_load(self, path: command.Path) -> None:
"""
Read a file into the currrent cell.
"""
self._grideditor().cmd_read_file(path)
- @command.command("console.grideditor.readfile_escaped")
- def grideditor_readfile_escaped(self, path: command.Path) -> None:
+ @command.command("console.grideditor.load_escaped")
+ def grideditor_load_escaped(self, path: command.Path) -> None:
"""
- Read a file containing a Python-style escaped stringinto the
+ Read a file containing a Python-style escaped string into the
currrent cell.
"""
self._grideditor().cmd_read_file_escaped(path)
+ @command.command("console.grideditor.save")
+ def grideditor_save(self, path: command.Path) -> None:
+ """
+ Save data to file as a CSV.
+ """
+ rows = self._grideditor().value
+ with open(path, "w", newline='', encoding="utf8") as fp:
+ writer = csv.writer(fp)
+ for row in rows:
+ writer.writerow(
+ [strutils.always_str(x) or "" for x in row] # type: ignore
+ )
+ ctx.log.alert("Saved %s rows as CSV." % (len(rows)))
+
@command.command("console.grideditor.editor")
def grideditor_editor(self) -> None:
"""
diff --git a/mitmproxy/tools/console/defaultkeys.py b/mitmproxy/tools/console/defaultkeys.py
index 7920225b..0fdec10c 100644
--- a/mitmproxy/tools/console/defaultkeys.py
+++ b/mitmproxy/tools/console/defaultkeys.py
@@ -145,17 +145,23 @@ def map(km):
km.add("d", "console.grideditor.delete", ["grideditor"], "Delete this row")
km.add(
"r",
- "console.command console.grideditor.readfile",
+ "console.command console.grideditor.load",
["grideditor"],
- "Read unescaped data from file"
+ "Read unescaped data into the current cell from file"
)
km.add(
"R",
- "console.command console.grideditor.readfile_escaped",
+ "console.command console.grideditor.load_escaped",
["grideditor"],
- "Read a Python-style escaped string from file"
+ "Load a Python-style escaped string into the current cell from file"
)
km.add("e", "console.grideditor.editor", ["grideditor"], "Edit in external editor")
+ km.add(
+ "w",
+ "console.command console.grideditor.save ",
+ ["grideditor"],
+ "Save data to file as CSV"
+ )
km.add("z", "eventstore.clear", ["eventlog"], "Clear")
diff --git a/setup.py b/setup.py
index 4f824ddf..cfda3071 100644
--- a/setup.py
+++ b/setup.py
@@ -64,7 +64,7 @@ setup(
"brotlipy>=0.5.1, <0.8",
"certifi>=2015.11.20.1", # no semver here - this should always be on the last release!
"click>=6.2, <7",
- "cryptography>=2.0,<2.2",
+ "cryptography>=2.1.4,<2.2",
'h11>=0.7.0,<0.8',
"h2>=3.0, <4",
"hyperframe>=5.0, <6",
diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py
index 47680c99..50ad3d55 100644
--- a/test/mitmproxy/test_command.py
+++ b/test/mitmproxy/test_command.py
@@ -151,19 +151,18 @@ def test_simple():
def test_typename():
- assert command.typename(str, True) == "str"
- assert command.typename(typing.Sequence[flow.Flow], True) == "[flow]"
- assert command.typename(typing.Sequence[flow.Flow], False) == "[flow]"
+ assert command.typename(str) == "str"
+ assert command.typename(typing.Sequence[flow.Flow]) == "[flow]"
- assert command.typename(command.Cuts, True) == "[cuts]"
- assert command.typename(typing.Sequence[command.Cut], False) == "[cut]"
+ assert command.typename(command.Cuts) == "[cuts]"
+ assert command.typename(typing.Sequence[command.Cut]) == "[cut]"
- assert command.typename(flow.Flow, False) == "flow"
- assert command.typename(typing.Sequence[str], False) == "[str]"
+ assert command.typename(flow.Flow) == "flow"
+ assert command.typename(typing.Sequence[str]) == "[str]"
- assert command.typename(command.Choice("foo"), False) == "choice"
- assert command.typename(command.Path, False) == "path"
- assert command.typename(command.Cmd, False) == "cmd"
+ assert command.typename(command.Choice("foo")) == "choice"
+ assert command.typename(command.Path) == "path"
+ assert command.typename(command.Cmd) == "cmd"
class DummyConsole: