used save_body from common when b key is pressed

This commit is contained in:
Marcelo Glezer 2015-01-15 12:57:00 -03:00
parent affb57ed08
commit 7ba7d64bac
2 changed files with 18 additions and 31 deletions

View File

@ -166,7 +166,7 @@ def raw_format_flow(f, focus, extended, padding):
return urwid.Pile(pile) return urwid.Pile(pile)
## common save body parts ## common save body parts
def _save_body(path, master, state, content): def save_body(path, master, state, content):
if not path: if not path:
return return
state.last_saveload = path state.last_saveload = path
@ -178,12 +178,12 @@ def _save_body(path, master, state, content):
except IOError, v: except IOError, v:
master.statusbar.message(v.strerror) master.statusbar.message(v.strerror)
def save_body(k, master, state, content): def ask_save_body(k, master, state, content):
if k == "y": if k == "y":
master.path_prompt( master.path_prompt(
"Save response body: ", "Save response body: ",
state.last_saveload, state.last_saveload,
_save_body, save_body,
master, master,
state, state,
content, content,
@ -202,7 +202,7 @@ def server_copy_response( k, master, state, response):
("yes", "y"), ("yes", "y"),
("no", "n"), ("no", "n"),
), ),
save_body, ask_save_body,
master, master,
state, state,
response.get_decoded_content(), response.get_decoded_content(),

View File

@ -508,22 +508,6 @@ class FlowView(common.WWrap):
self.flow.request.method = i[0].upper() self.flow.request.method = i[0].upper()
self.master.refresh_flow(self.flow) self.master.refresh_flow(self.flow)
def save_body(self, path):
if not path:
return
self.state.last_saveload = path
if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
c = self.flow.request
else:
c = self.flow.response
path = os.path.expanduser(path)
try:
f = file(path, "wb")
f.write(str(c.content))
f.close()
except IOError, v:
self.master.statusbar.message(v.strerror)
def set_url(self, url): def set_url(self, url):
request = self.flow.request request = self.flow.request
try: try:
@ -691,17 +675,20 @@ class FlowView(common.WWrap):
elif key == "b": elif key == "b":
if conn: if conn:
if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST: if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
self.master.path_prompt( msg = "Save request body: "
"Save request body: ", content = self.flow.request.content
self.state.last_saveload, else:
self.save_body msg = "Save response body: "
) content = self.flow.response.content
else:
self.master.path_prompt( self.master.path_prompt(
"Save response body: ", msg,
self.state.last_saveload, self.state.last_saveload,
self.save_body common.save_body,
) self.master,
self.state,
content,
)
elif key == "d": elif key == "d":
if self.state.flow_count() == 1: if self.state.flow_count() == 1:
self.master.view_flowlist() self.master.view_flowlist()