diff --git a/libmproxy/console/common.py b/libmproxy/console/common.py index 3e6e5ccc5..3ba89f8e4 100644 --- a/libmproxy/console/common.py +++ b/libmproxy/console/common.py @@ -3,7 +3,10 @@ import urwid import urwid.util from .. import utils from ..protocol.http import CONTENT_MISSING - +try: + import pyperclip +except: + pyperclip = False VIEW_LIST = 0 VIEW_FLOW = 1 @@ -161,6 +164,21 @@ def raw_format_flow(f, focus, extended, padding): pile.append(urwid.Columns(resp, dividechars=1)) return urwid.Pile(pile) +def server_copy_response( k, response, statusbar): + if pyperclip: + if k == "c": + try: + pyperclip.copy(response.get_decoded_content()) + except TypeError: + statusbar.message("Content is binary or can be converted to text") + elif k == "h": + try: + pyperclip.copy(str(response.headers)) + except TypeError: + statusbar.message("Error converting headers to text") + else: + statusbar.message("No clipboard support on your system, sorry.") + class FlowCache: @utils.LRUCache(200) diff --git a/libmproxy/console/flowlist.py b/libmproxy/console/flowlist.py index d611dc6e1..2dc20544c 100644 --- a/libmproxy/console/flowlist.py +++ b/libmproxy/console/flowlist.py @@ -1,10 +1,6 @@ from __future__ import absolute_import import urwid from . import common -try: - import pyperclip -except: - pyperclip = False def _mkhelp(): text = [] @@ -141,20 +137,6 @@ class ConnectionItem(common.WWrap): self.state.last_saveload, self.master.server_playback_path ) - def server_copy_response(self, k): - if pyperclip: - if k == "c": - try: - pyperclip.copy(self.flow.response.get_decoded_content()) - except TypeError: - self.master.statusbar.message("Content is binary or can be converted to text") - elif k == "h": - try: - pyperclip.copy(str(self.flow.response.headers)) - except TypeError: - self.master.statusbar.message("Error converting headers to text") - else: - self.master.statusbar.message("No clipboard support on your system, sorry.") def keypress(self, (maxcol,), key): key = common.shortcuts(key) @@ -228,7 +210,9 @@ class ConnectionItem(common.WWrap): ("content", "c"), ("headers", "h"), ), - self.server_copy_response, + common.server_copy_response, + self.flow.response, + self.master.statusbar ) else: return key diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index 667a74074..abca2ed63 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -4,10 +4,7 @@ import urwid from . import common, grideditor, contentview from .. import utils, flow, controller from ..protocol.http import HTTPResponse, CONTENT_MISSING, decoded -try: - import pyperclip -except: - pyperclip = False + class SearchError(Exception): pass @@ -652,21 +649,6 @@ class FlowView(common.WWrap): ) self.master.refresh_flow(self.flow) - def server_copy_response(self, k): - if pyperclip: - if k == "c": - try: - pyperclip.copy(self.flow.response.get_decoded_content()) - except TypeError: - self.master.statusbar.message("Content is binary or can be converted to text") - elif k == "h": - try: - pyperclip.copy(str(self.flow.response.headers)) - except TypeError: - self.master.statusbar.message("Error converting headers to text") - else: - self.master.statusbar.message("No clipboard support on your system, sorry.") - def delete_body(self, t): if t == "m": val = CONTENT_MISSING @@ -777,7 +759,9 @@ class FlowView(common.WWrap): ("content", "c"), ("headers", "h"), ), - self.server_copy_response, + common.server_copy_response, + self.flow.response, + self.master.statusbar ) elif key == "m": p = list(contentview.view_prompts)