From f8b4c7bd446af846bfba01658df51800da44c933 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 12 Aug 2021 10:19:49 +0200 Subject: [PATCH] add raw `export` command --- mitmproxy/addons/export.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/mitmproxy/addons/export.py b/mitmproxy/addons/export.py index bbca3af66..10c530623 100644 --- a/mitmproxy/addons/export.py +++ b/mitmproxy/addons/export.py @@ -182,12 +182,18 @@ class Export: """ Export a flow to the system clipboard. """ + try: + pyperclip.copy(self.export_str(format, f)) + except pyperclip.PyperclipException as e: + ctx.log.error(str(e)) + + @command.command("export") + def export_str(self, format: str, f: flow.Flow) -> str: + """ + Export a flow and return the result. + """ if format not in formats: raise exceptions.CommandError("No such export format: %s" % format) func = formats[format] - val = strutils.always_str(func(f), "utf8", "backslashreplace") - try: - pyperclip.copy(val) - except pyperclip.PyperclipException as e: - ctx.log.error(str(e)) + return strutils.always_str(func(f), "utf8", "backslashreplace")