extracted server_copy_response to common

This commit is contained in:
Marcelo Glezer 2015-01-15 09:36:59 -03:00
parent 0a2d2d9390
commit b77cd1af60
3 changed files with 26 additions and 40 deletions

View File

@ -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)

View File

@ -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

View File

@ -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)