2014-03-10 21:36:47 +00:00
|
|
|
from __future__ import absolute_import
|
2014-01-18 23:43:58 +00:00
|
|
|
import os, sys, copy
|
2012-02-07 03:39:37 +00:00
|
|
|
import urwid
|
2014-03-10 21:36:47 +00:00
|
|
|
from . import common, grideditor, contentview
|
2013-06-08 23:14:34 +00:00
|
|
|
from .. import utils, flow, controller
|
2014-12-23 22:14:55 +00:00
|
|
|
from ..protocol.http import HTTPResponse, CONTENT_MISSING, decoded
|
2015-01-14 15:36:19 +00:00
|
|
|
import pyperclip
|
2014-01-19 00:23:38 +00:00
|
|
|
|
|
|
|
class SearchError(Exception): pass
|
|
|
|
|
|
|
|
|
2012-02-08 08:47:39 +00:00
|
|
|
def _mkhelp():
|
|
|
|
text = []
|
|
|
|
keys = [
|
2012-02-20 23:42:43 +00:00
|
|
|
("A", "accept all intercepted flows"),
|
|
|
|
("a", "accept this intercepted flow"),
|
2012-02-08 08:47:39 +00:00
|
|
|
("b", "save request/response body"),
|
2012-02-09 04:00:37 +00:00
|
|
|
("d", "delete flow"),
|
2012-02-18 11:32:20 +00:00
|
|
|
("D", "duplicate flow"),
|
2012-02-08 08:47:39 +00:00
|
|
|
("e", "edit request/response"),
|
2012-04-08 08:16:25 +00:00
|
|
|
("f", "load full body data"),
|
2015-01-14 15:36:19 +00:00
|
|
|
("g", "copy response(content/headers) to clipboard"),
|
2012-04-01 22:30:35 +00:00
|
|
|
("m", "change body display mode for this entity"),
|
2012-02-08 09:28:15 +00:00
|
|
|
(None,
|
2012-04-01 22:30:35 +00:00
|
|
|
common.highlight_key("automatic", "a") +
|
|
|
|
[("text", ": automatic detection")]
|
2012-02-08 09:28:15 +00:00
|
|
|
),
|
|
|
|
(None,
|
2013-04-16 21:54:34 +00:00
|
|
|
common.highlight_key("hex", "e") +
|
2012-04-01 22:30:35 +00:00
|
|
|
[("text", ": Hex")]
|
2012-03-19 19:35:20 +00:00
|
|
|
),
|
|
|
|
(None,
|
2013-04-16 21:54:34 +00:00
|
|
|
common.highlight_key("html", "h") +
|
|
|
|
[("text", ": HTML")]
|
|
|
|
),
|
|
|
|
(None,
|
2012-03-25 22:39:25 +00:00
|
|
|
common.highlight_key("image", "i") +
|
|
|
|
[("text", ": Image")]
|
|
|
|
),
|
|
|
|
(None,
|
|
|
|
common.highlight_key("javascript", "j") +
|
|
|
|
[("text", ": JavaScript")]
|
|
|
|
),
|
|
|
|
(None,
|
|
|
|
common.highlight_key("json", "s") +
|
|
|
|
[("text", ": JSON")]
|
2012-03-19 19:35:20 +00:00
|
|
|
),
|
2012-03-19 22:11:53 +00:00
|
|
|
(None,
|
|
|
|
common.highlight_key("urlencoded", "u") +
|
2012-03-25 22:39:25 +00:00
|
|
|
[("text", ": URL-encoded data")]
|
2012-03-19 22:11:53 +00:00
|
|
|
),
|
2012-04-01 22:30:35 +00:00
|
|
|
(None,
|
|
|
|
common.highlight_key("raw", "r") +
|
|
|
|
[("text", ": raw data")]
|
|
|
|
),
|
2012-03-19 19:35:20 +00:00
|
|
|
(None,
|
|
|
|
common.highlight_key("xml", "x") +
|
2012-03-25 22:39:25 +00:00
|
|
|
[("text", ": XML")]
|
2012-03-19 19:35:20 +00:00
|
|
|
),
|
2012-04-01 22:30:35 +00:00
|
|
|
("M", "change default body display mode"),
|
|
|
|
("p", "previous flow"),
|
|
|
|
("r", "replay request"),
|
2012-02-18 01:45:22 +00:00
|
|
|
("V", "revert changes to request"),
|
2012-02-08 08:47:39 +00:00
|
|
|
("v", "view body in external viewer"),
|
2012-02-08 09:55:48 +00:00
|
|
|
("w", "save all flows matching current limit"),
|
|
|
|
("W", "save this flow"),
|
2012-05-16 06:16:44 +00:00
|
|
|
("x", "delete body"),
|
2012-04-02 23:10:25 +00:00
|
|
|
("X", "view flow details"),
|
2012-02-08 08:47:39 +00:00
|
|
|
("z", "encode/decode a request/response"),
|
|
|
|
("tab", "toggle request/response view"),
|
|
|
|
("space", "next flow"),
|
2012-02-08 09:28:15 +00:00
|
|
|
("|", "run script on this flow"),
|
2013-12-26 04:26:51 +00:00
|
|
|
("/", "search in response body (case sensitive)"),
|
2014-02-22 03:36:35 +00:00
|
|
|
("n", "repeat search forward"),
|
|
|
|
("N", "repeat search backwards"),
|
2012-02-08 08:47:39 +00:00
|
|
|
]
|
|
|
|
text.extend(common.format_keyvals(keys, key="key", val="text", indent=4))
|
|
|
|
return text
|
|
|
|
help_context = _mkhelp()
|
|
|
|
|
2012-03-22 01:57:57 +00:00
|
|
|
footer = [
|
|
|
|
('heading_key', "?"), ":help ",
|
|
|
|
('heading_key', "q"), ":back ",
|
|
|
|
]
|
2012-02-08 08:47:39 +00:00
|
|
|
|
2012-02-07 03:39:37 +00:00
|
|
|
|
2012-03-19 22:11:53 +00:00
|
|
|
class FlowViewHeader(common.WWrap):
|
2012-02-07 03:39:37 +00:00
|
|
|
def __init__(self, master, f):
|
|
|
|
self.master, self.flow = master, f
|
2013-03-17 04:31:35 +00:00
|
|
|
self.w = common.format_flow(f, False, extended=True, padding=0, hostheader=self.master.showhost)
|
2012-02-07 03:39:37 +00:00
|
|
|
|
2012-02-20 23:42:43 +00:00
|
|
|
def refresh_flow(self, f):
|
2012-02-07 03:39:37 +00:00
|
|
|
if f == self.flow:
|
2013-03-17 04:31:35 +00:00
|
|
|
self.w = common.format_flow(f, False, extended=True, padding=0, hostheader=self.master.showhost)
|
2012-02-07 03:39:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CallbackCache:
|
2014-01-18 23:43:58 +00:00
|
|
|
@utils.LRUCache(200)
|
2012-03-24 22:18:33 +00:00
|
|
|
def _callback(self, method, *args, **kwargs):
|
|
|
|
return getattr(self.obj, method)(*args, **kwargs)
|
|
|
|
|
2012-02-07 03:39:37 +00:00
|
|
|
def callback(self, obj, method, *args, **kwargs):
|
2012-03-24 22:18:33 +00:00
|
|
|
# obj varies!
|
|
|
|
self.obj = obj
|
|
|
|
return self._callback(method, *args, **kwargs)
|
2012-02-07 03:39:37 +00:00
|
|
|
cache = CallbackCache()
|
|
|
|
|
|
|
|
|
2012-03-19 22:11:53 +00:00
|
|
|
class FlowView(common.WWrap):
|
2012-02-07 03:39:37 +00:00
|
|
|
REQ = 0
|
|
|
|
RESP = 1
|
2012-02-08 20:38:11 +00:00
|
|
|
method_options = [
|
2012-02-07 03:39:37 +00:00
|
|
|
("get", "g"),
|
|
|
|
("post", "p"),
|
|
|
|
("put", "u"),
|
|
|
|
("head", "h"),
|
|
|
|
("trace", "t"),
|
|
|
|
("delete", "d"),
|
|
|
|
("options", "o"),
|
2012-02-08 20:38:11 +00:00
|
|
|
("edit raw", "e"),
|
2012-02-07 03:39:37 +00:00
|
|
|
]
|
2013-12-25 03:50:29 +00:00
|
|
|
|
2013-12-25 03:57:54 +00:00
|
|
|
highlight_color = "focusfield"
|
2013-12-25 03:50:29 +00:00
|
|
|
|
2012-02-07 03:39:37 +00:00
|
|
|
def __init__(self, master, state, flow):
|
|
|
|
self.master, self.state, self.flow = master, state, flow
|
2013-12-25 03:50:29 +00:00
|
|
|
self.last_displayed_body = None
|
2012-03-25 22:28:52 +00:00
|
|
|
if self.state.view_flow_mode == common.VIEW_FLOW_RESPONSE:
|
2012-02-07 03:39:37 +00:00
|
|
|
self.view_response()
|
|
|
|
else:
|
|
|
|
self.view_request()
|
|
|
|
|
2012-04-08 07:23:05 +00:00
|
|
|
def _cached_content_view(self, viewmode, hdrItems, content, limit):
|
2012-08-18 05:42:40 +00:00
|
|
|
return contentview.get_content_view(viewmode, hdrItems, content, limit, self.master.add_event)
|
2012-04-01 23:01:38 +00:00
|
|
|
|
2013-12-26 04:04:18 +00:00
|
|
|
def content_view(self, viewmode, conn):
|
2012-04-08 07:23:05 +00:00
|
|
|
full = self.state.get_flow_setting(
|
|
|
|
self.flow,
|
|
|
|
(self.state.view_flow_mode, "fullcontents"),
|
|
|
|
False
|
|
|
|
)
|
|
|
|
if full:
|
|
|
|
limit = sys.maxint
|
|
|
|
else:
|
|
|
|
limit = contentview.VIEW_CUTOFF
|
2013-12-25 03:50:29 +00:00
|
|
|
description, text_objects = cache.callback(
|
2012-04-01 23:01:38 +00:00
|
|
|
self, "_cached_content_view",
|
|
|
|
viewmode,
|
|
|
|
tuple(tuple(i) for i in conn.headers.lst),
|
|
|
|
conn.content,
|
2012-04-08 07:23:05 +00:00
|
|
|
limit
|
2012-04-01 23:01:38 +00:00
|
|
|
)
|
2013-12-26 04:04:18 +00:00
|
|
|
return (description, text_objects)
|
|
|
|
|
|
|
|
def cont_view_handle_missing(self, conn, viewmode):
|
2014-03-09 20:59:53 +00:00
|
|
|
if conn.content == CONTENT_MISSING:
|
2014-07-25 16:47:48 +00:00
|
|
|
msg, body = "", [urwid.Text([("error", "[content missing]")])]
|
2013-12-26 04:04:18 +00:00
|
|
|
else:
|
|
|
|
msg, body = self.content_view(viewmode, conn)
|
2013-12-24 01:28:20 +00:00
|
|
|
|
2013-12-26 04:04:18 +00:00
|
|
|
return (msg, body)
|
2013-12-24 01:28:20 +00:00
|
|
|
|
2013-12-26 04:04:18 +00:00
|
|
|
def viewmode_get(self, override):
|
|
|
|
return self.state.default_body_view if override is None else override
|
|
|
|
|
|
|
|
def override_get(self):
|
|
|
|
return self.state.get_flow_setting(self.flow,
|
|
|
|
(self.state.view_flow_mode, "prettyview"))
|
|
|
|
|
|
|
|
def conn_text_raw(self, conn):
|
|
|
|
"""
|
|
|
|
Based on a request/response, conn, returns the elements for
|
|
|
|
display.
|
|
|
|
"""
|
|
|
|
headers = common.format_keyvals(
|
2012-04-01 23:01:38 +00:00
|
|
|
[(h+":", v) for (h, v) in conn.headers.lst],
|
2012-02-07 03:39:37 +00:00
|
|
|
key = "header",
|
|
|
|
val = "text"
|
|
|
|
)
|
2014-09-18 01:56:35 +00:00
|
|
|
override = self.override_get()
|
|
|
|
viewmode = self.viewmode_get(override)
|
|
|
|
msg, body = self.cont_view_handle_missing(conn, viewmode)
|
2013-12-26 04:04:18 +00:00
|
|
|
return headers, msg, body
|
2012-04-01 23:10:55 +00:00
|
|
|
|
2013-12-26 04:04:18 +00:00
|
|
|
def conn_text_merge(self, headers, msg, body):
|
|
|
|
"""
|
|
|
|
Grabs what is returned by conn_text_raw and merges them all
|
|
|
|
toghether, mainly used by conn_text and search
|
|
|
|
"""
|
|
|
|
override = self.override_get()
|
|
|
|
viewmode = self.viewmode_get(override)
|
|
|
|
|
|
|
|
cols = [urwid.Text(
|
|
|
|
[
|
|
|
|
("heading", msg),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|
|
|
|
if override is not None:
|
|
|
|
cols.append(urwid.Text([
|
|
|
|
" ",
|
|
|
|
('heading', "["),
|
|
|
|
('heading_key', "m"),
|
|
|
|
('heading', (":%s]"%viewmode.name)),
|
|
|
|
],
|
|
|
|
align="right"
|
2012-04-01 23:10:55 +00:00
|
|
|
)
|
2013-12-26 04:04:18 +00:00
|
|
|
)
|
2013-12-24 01:28:20 +00:00
|
|
|
|
2013-12-26 04:04:18 +00:00
|
|
|
title = urwid.AttrWrap(urwid.Columns(cols), "heading")
|
|
|
|
headers.append(title)
|
|
|
|
headers.extend(body)
|
2013-12-24 01:28:20 +00:00
|
|
|
|
2013-12-26 04:04:18 +00:00
|
|
|
return headers
|
2013-12-25 03:50:29 +00:00
|
|
|
|
2013-12-26 04:04:18 +00:00
|
|
|
def conn_text(self, conn):
|
|
|
|
"""
|
|
|
|
Same as conn_text_raw, but returns result wrapped in a listbox ready for usage.
|
|
|
|
"""
|
|
|
|
headers, msg, body = self.conn_text_raw(conn)
|
|
|
|
merged = self.conn_text_merge(headers, msg, body)
|
|
|
|
return urwid.ListBox(merged)
|
2012-02-07 03:39:37 +00:00
|
|
|
|
2012-02-18 05:48:08 +00:00
|
|
|
def _tab(self, content, attr):
|
2012-02-07 03:39:37 +00:00
|
|
|
p = urwid.Text(content)
|
|
|
|
p = urwid.Padding(p, align="left", width=("relative", 100))
|
|
|
|
p = urwid.AttrWrap(p, attr)
|
|
|
|
return p
|
|
|
|
|
|
|
|
def wrap_body(self, active, body):
|
|
|
|
parts = []
|
|
|
|
|
2014-12-23 19:33:42 +00:00
|
|
|
if self.flow.intercepted and not self.flow.reply.acked and not self.flow.response:
|
2012-02-18 05:48:08 +00:00
|
|
|
qt = "Request intercepted"
|
2012-02-07 03:39:37 +00:00
|
|
|
else:
|
|
|
|
qt = "Request"
|
|
|
|
if active == common.VIEW_FLOW_REQUEST:
|
2012-02-18 05:48:08 +00:00
|
|
|
parts.append(self._tab(qt, "heading"))
|
2012-02-07 03:39:37 +00:00
|
|
|
else:
|
2012-02-18 05:48:08 +00:00
|
|
|
parts.append(self._tab(qt, "heading_inactive"))
|
2012-02-07 03:39:37 +00:00
|
|
|
|
2014-12-23 19:33:42 +00:00
|
|
|
if self.flow.intercepted and not self.flow.reply.acked and self.flow.response:
|
2012-02-18 05:48:08 +00:00
|
|
|
st = "Response intercepted"
|
2012-02-07 03:39:37 +00:00
|
|
|
else:
|
|
|
|
st = "Response"
|
|
|
|
if active == common.VIEW_FLOW_RESPONSE:
|
2012-02-18 05:48:08 +00:00
|
|
|
parts.append(self._tab(st, "heading"))
|
2012-02-07 03:39:37 +00:00
|
|
|
else:
|
2012-02-18 05:48:08 +00:00
|
|
|
parts.append(self._tab(st, "heading_inactive"))
|
2012-02-07 03:39:37 +00:00
|
|
|
|
2012-02-18 05:48:08 +00:00
|
|
|
h = urwid.Columns(parts)
|
2012-02-07 03:39:37 +00:00
|
|
|
f = urwid.Frame(
|
|
|
|
body,
|
|
|
|
header=h
|
|
|
|
)
|
|
|
|
return f
|
|
|
|
|
2014-02-22 05:04:56 +00:00
|
|
|
def search_wrapped_around(self, last_find_line, last_search_index, backwards):
|
2013-12-26 04:04:18 +00:00
|
|
|
"""
|
|
|
|
returns true if search wrapped around the bottom.
|
|
|
|
"""
|
|
|
|
|
|
|
|
current_find_line = self.state.get_flow_setting(self.flow,
|
|
|
|
"last_find_line")
|
|
|
|
current_search_index = self.state.get_flow_setting(self.flow,
|
|
|
|
"last_search_index")
|
|
|
|
|
2014-02-22 05:04:56 +00:00
|
|
|
if not backwards:
|
|
|
|
message = "search hit BOTTOM, continuing at TOP"
|
|
|
|
if current_find_line <= last_find_line:
|
|
|
|
return True, message
|
|
|
|
elif current_find_line == last_find_line:
|
|
|
|
if current_search_index <= last_search_index:
|
|
|
|
return True, message
|
|
|
|
else:
|
|
|
|
message = "search hit TOP, continuing at BOTTOM"
|
|
|
|
if current_find_line >= last_find_line:
|
|
|
|
return True, message
|
|
|
|
elif current_find_line == last_find_line:
|
|
|
|
if current_search_index >= last_search_index:
|
|
|
|
return True, message
|
2013-12-26 04:04:18 +00:00
|
|
|
|
2014-02-22 05:04:56 +00:00
|
|
|
return False, ""
|
2013-12-26 04:04:18 +00:00
|
|
|
|
2014-02-22 02:00:10 +00:00
|
|
|
def search_again(self, backwards=False):
|
|
|
|
"""
|
|
|
|
runs the previous search again, forwards or backwards.
|
|
|
|
"""
|
|
|
|
last_search_string = self.state.get_flow_setting(self.flow, "last_search_string")
|
|
|
|
if last_search_string:
|
|
|
|
message = self.search(last_search_string, backwards)
|
|
|
|
if message:
|
|
|
|
self.master.statusbar.message(message)
|
|
|
|
else:
|
2014-02-22 05:04:56 +00:00
|
|
|
message = "no previous searches have been made"
|
|
|
|
self.master.statusbar.message(message)
|
|
|
|
|
|
|
|
return message
|
2014-02-22 02:00:10 +00:00
|
|
|
|
|
|
|
def search(self, search_string, backwards=False):
|
2013-12-26 04:04:18 +00:00
|
|
|
"""
|
|
|
|
similar to view_response or view_request, but instead of just
|
|
|
|
displaying the conn, it highlights a word that the user is
|
|
|
|
searching for and handles all the logic surrounding that.
|
|
|
|
"""
|
2013-12-25 03:50:29 +00:00
|
|
|
|
2014-04-07 12:40:01 +00:00
|
|
|
if not search_string:
|
2013-12-25 03:50:29 +00:00
|
|
|
search_string = self.state.get_flow_setting(self.flow,
|
|
|
|
"last_search_string")
|
2014-04-07 12:40:01 +00:00
|
|
|
if not search_string:
|
|
|
|
return
|
2013-12-25 03:50:29 +00:00
|
|
|
|
2013-12-24 01:28:20 +00:00
|
|
|
if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
|
|
|
text = self.flow.request
|
|
|
|
const = common.VIEW_FLOW_REQUEST
|
|
|
|
else:
|
|
|
|
text = self.flow.response
|
|
|
|
const = common.VIEW_FLOW_RESPONSE
|
|
|
|
if not self.flow.response:
|
|
|
|
return "no response to search in"
|
|
|
|
|
2013-12-26 04:04:18 +00:00
|
|
|
last_find_line = self.state.get_flow_setting(self.flow,
|
|
|
|
"last_find_line")
|
|
|
|
last_search_index = self.state.get_flow_setting(self.flow,
|
|
|
|
"last_search_index")
|
|
|
|
|
|
|
|
# generate the body, highlight the words and get focus
|
|
|
|
headers, msg, body = self.conn_text_raw(text)
|
2014-01-19 00:23:38 +00:00
|
|
|
try:
|
2014-02-22 02:00:10 +00:00
|
|
|
body, focus_position = self.search_highlight_text(body, search_string, backwards=backwards)
|
2014-01-19 00:23:38 +00:00
|
|
|
except SearchError:
|
|
|
|
return "Search not supported in this view."
|
2013-12-26 04:04:18 +00:00
|
|
|
|
|
|
|
if focus_position == None:
|
|
|
|
# no results found.
|
|
|
|
return "no matches for '%s'" % search_string
|
2013-12-24 01:28:20 +00:00
|
|
|
|
2013-12-26 04:04:18 +00:00
|
|
|
# UI stuff.
|
|
|
|
merged = self.conn_text_merge(headers, msg, body)
|
|
|
|
list_box = urwid.ListBox(merged)
|
|
|
|
list_box.set_focus(focus_position + 2)
|
|
|
|
self.w = self.wrap_body(const, list_box)
|
2013-12-24 01:28:20 +00:00
|
|
|
self.master.statusbar.redraw()
|
|
|
|
|
2013-12-26 04:04:18 +00:00
|
|
|
self.last_displayed_body = list_box
|
|
|
|
|
2014-02-22 05:04:56 +00:00
|
|
|
wrapped, wrapped_message = self.search_wrapped_around(last_find_line, last_search_index, backwards)
|
|
|
|
|
|
|
|
if wrapped:
|
|
|
|
return wrapped_message
|
2013-12-26 04:04:18 +00:00
|
|
|
|
2013-12-24 01:28:20 +00:00
|
|
|
def search_get_start(self, search_string):
|
2013-12-26 09:18:34 +00:00
|
|
|
start_line = 0
|
|
|
|
start_index = 0
|
2013-12-24 01:28:20 +00:00
|
|
|
last_search_string = self.state.get_flow_setting(self.flow, "last_search_string")
|
|
|
|
if search_string == last_search_string:
|
2013-12-25 03:50:29 +00:00
|
|
|
start_line = self.state.get_flow_setting(self.flow, "last_find_line")
|
2013-12-24 01:28:20 +00:00
|
|
|
start_index = self.state.get_flow_setting(self.flow,
|
2013-12-26 08:53:04 +00:00
|
|
|
"last_search_index")
|
|
|
|
|
2013-12-26 09:18:34 +00:00
|
|
|
if start_index == None:
|
2013-12-26 08:53:04 +00:00
|
|
|
start_index = 0
|
2013-12-26 09:18:34 +00:00
|
|
|
else:
|
|
|
|
start_index += len(search_string)
|
|
|
|
|
|
|
|
if start_line == None:
|
|
|
|
start_line = 0
|
|
|
|
|
2013-12-24 01:28:20 +00:00
|
|
|
else:
|
|
|
|
self.state.add_flow_setting(self.flow, "last_search_string",
|
|
|
|
search_string)
|
|
|
|
|
2013-12-25 03:50:29 +00:00
|
|
|
return (start_line, start_index)
|
2013-12-24 01:28:20 +00:00
|
|
|
|
2014-02-22 02:32:35 +00:00
|
|
|
def search_get_range(self, len_text_objects, start_line, backwards):
|
|
|
|
if not backwards:
|
2014-02-22 03:32:22 +00:00
|
|
|
loop_range = xrange(start_line, len_text_objects)
|
2014-02-22 02:32:35 +00:00
|
|
|
else:
|
2014-02-22 03:32:22 +00:00
|
|
|
loop_range = xrange(start_line, -1, -1)
|
2014-02-22 02:32:35 +00:00
|
|
|
|
|
|
|
return loop_range
|
|
|
|
|
2014-02-22 04:15:37 +00:00
|
|
|
def search_find(self, text, search_string, start_index, backwards):
|
|
|
|
if backwards == False:
|
|
|
|
find_index = text.find(search_string, start_index)
|
|
|
|
else:
|
|
|
|
if start_index != 0:
|
|
|
|
start_index -= len(search_string)
|
|
|
|
else:
|
|
|
|
start_index = None
|
|
|
|
|
|
|
|
find_index = text.rfind(search_string, 0, start_index)
|
|
|
|
|
|
|
|
return find_index
|
|
|
|
|
2014-02-22 02:00:10 +00:00
|
|
|
def search_highlight_text(self, text_objects, search_string, looping = False, backwards = False):
|
2013-12-25 03:50:29 +00:00
|
|
|
start_line, start_index = self.search_get_start(search_string)
|
|
|
|
i = start_line
|
2013-12-24 01:28:20 +00:00
|
|
|
|
2013-12-25 03:50:29 +00:00
|
|
|
found = False
|
2014-01-18 23:43:58 +00:00
|
|
|
text_objects = copy.deepcopy(text_objects)
|
2014-02-22 03:32:22 +00:00
|
|
|
loop_range = self.search_get_range(len(text_objects), start_line, backwards)
|
|
|
|
for i in loop_range:
|
2014-02-22 02:32:35 +00:00
|
|
|
text_object = text_objects[i]
|
2013-12-25 03:50:29 +00:00
|
|
|
|
2014-01-19 00:23:38 +00:00
|
|
|
try:
|
|
|
|
text, style = text_object.get_text()
|
|
|
|
except AttributeError:
|
|
|
|
raise SearchError()
|
2014-02-22 02:00:10 +00:00
|
|
|
|
2014-02-22 04:15:37 +00:00
|
|
|
if i != start_line:
|
|
|
|
start_index = 0
|
2014-02-22 02:00:10 +00:00
|
|
|
|
2014-02-22 04:15:37 +00:00
|
|
|
find_index = self.search_find(text, search_string, start_index, backwards)
|
2014-02-22 02:00:10 +00:00
|
|
|
|
2013-12-25 03:50:29 +00:00
|
|
|
if find_index != -1:
|
2014-02-22 02:00:10 +00:00
|
|
|
new_text = self.search_highlight_object(text, find_index, search_string)
|
|
|
|
text_objects[i] = new_text
|
2013-12-25 03:50:29 +00:00
|
|
|
|
2014-02-22 04:15:37 +00:00
|
|
|
found = True
|
2013-12-25 03:50:29 +00:00
|
|
|
self.state.add_flow_setting(self.flow, "last_search_index",
|
|
|
|
find_index)
|
|
|
|
self.state.add_flow_setting(self.flow, "last_find_line", i)
|
|
|
|
|
|
|
|
break
|
|
|
|
|
2014-02-22 02:00:10 +00:00
|
|
|
# handle search WRAP
|
2013-12-25 03:50:29 +00:00
|
|
|
if found:
|
|
|
|
focus_pos = i
|
|
|
|
else :
|
2014-02-22 04:15:37 +00:00
|
|
|
if looping:
|
2013-12-26 04:04:18 +00:00
|
|
|
focus_pos = None
|
|
|
|
else:
|
2014-02-22 04:15:37 +00:00
|
|
|
if not backwards:
|
|
|
|
self.state.add_flow_setting(self.flow, "last_search_index", 0)
|
|
|
|
self.state.add_flow_setting(self.flow, "last_find_line", 0)
|
|
|
|
else:
|
|
|
|
self.state.add_flow_setting(self.flow, "last_search_index", None)
|
|
|
|
self.state.add_flow_setting(self.flow, "last_find_line", len(text_objects) - 1)
|
|
|
|
|
2014-02-22 03:32:22 +00:00
|
|
|
text_objects, focus_pos = self.search_highlight_text(text_objects,
|
|
|
|
search_string, looping=True, backwards=backwards)
|
2013-12-25 03:50:29 +00:00
|
|
|
|
|
|
|
return text_objects, focus_pos
|
2013-12-24 01:28:20 +00:00
|
|
|
|
2014-02-22 02:00:10 +00:00
|
|
|
def search_highlight_object(self, text_object, find_index, search_string):
|
|
|
|
"""
|
|
|
|
just a little abstraction
|
|
|
|
"""
|
|
|
|
before = text_object[:find_index]
|
|
|
|
after = text_object[find_index+len(search_string):]
|
|
|
|
|
|
|
|
new_text = urwid.Text(
|
|
|
|
[
|
|
|
|
before,
|
|
|
|
(self.highlight_color, search_string),
|
|
|
|
after,
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
return new_text
|
|
|
|
|
2012-02-07 03:39:37 +00:00
|
|
|
def view_request(self):
|
|
|
|
self.state.view_flow_mode = common.VIEW_FLOW_REQUEST
|
2012-04-01 23:10:55 +00:00
|
|
|
body = self.conn_text(self.flow.request)
|
2012-02-07 03:39:37 +00:00
|
|
|
self.w = self.wrap_body(common.VIEW_FLOW_REQUEST, body)
|
2012-02-18 05:48:08 +00:00
|
|
|
self.master.statusbar.redraw()
|
2012-02-07 03:39:37 +00:00
|
|
|
|
|
|
|
def view_response(self):
|
|
|
|
self.state.view_flow_mode = common.VIEW_FLOW_RESPONSE
|
|
|
|
if self.flow.response:
|
2012-04-01 23:10:55 +00:00
|
|
|
body = self.conn_text(self.flow.response)
|
2012-02-07 03:39:37 +00:00
|
|
|
else:
|
|
|
|
body = urwid.ListBox(
|
|
|
|
[
|
|
|
|
urwid.Text(""),
|
|
|
|
urwid.Text(
|
|
|
|
[
|
|
|
|
("highlight", "No response. Press "),
|
|
|
|
("key", "e"),
|
|
|
|
("highlight", " and edit any aspect to add one."),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
self.w = self.wrap_body(common.VIEW_FLOW_RESPONSE, body)
|
2012-02-18 05:48:08 +00:00
|
|
|
self.master.statusbar.redraw()
|
2012-02-07 03:39:37 +00:00
|
|
|
|
2012-02-20 23:42:43 +00:00
|
|
|
def refresh_flow(self, c=None):
|
2012-02-07 03:39:37 +00:00
|
|
|
if c == self.flow:
|
|
|
|
if self.state.view_flow_mode == common.VIEW_FLOW_RESPONSE and self.flow.response:
|
|
|
|
self.view_response()
|
|
|
|
else:
|
|
|
|
self.view_request()
|
|
|
|
|
2012-02-08 20:38:11 +00:00
|
|
|
def set_method_raw(self, m):
|
|
|
|
if m:
|
|
|
|
self.flow.request.method = m
|
2012-02-20 23:42:43 +00:00
|
|
|
self.master.refresh_flow(self.flow)
|
2012-02-08 20:38:11 +00:00
|
|
|
|
2012-02-07 03:39:37 +00:00
|
|
|
def edit_method(self, m):
|
2012-02-08 20:38:11 +00:00
|
|
|
if m == "e":
|
|
|
|
self.master.prompt_edit("Method", self.flow.request.method, self.set_method_raw)
|
|
|
|
else:
|
|
|
|
for i in self.method_options:
|
|
|
|
if i[1] == m:
|
|
|
|
self.flow.request.method = i[0].upper()
|
2012-02-20 23:42:43 +00:00
|
|
|
self.master.refresh_flow(self.flow)
|
2012-02-07 03:39:37 +00:00
|
|
|
|
|
|
|
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):
|
|
|
|
request = self.flow.request
|
2014-09-03 21:44:54 +00:00
|
|
|
try:
|
|
|
|
request.url = str(url)
|
|
|
|
except ValueError:
|
2012-02-07 03:39:37 +00:00
|
|
|
return "Invalid URL."
|
2012-02-20 23:42:43 +00:00
|
|
|
self.master.refresh_flow(self.flow)
|
2012-02-07 03:39:37 +00:00
|
|
|
|
|
|
|
def set_resp_code(self, code):
|
|
|
|
response = self.flow.response
|
|
|
|
try:
|
|
|
|
response.code = int(code)
|
|
|
|
except ValueError:
|
|
|
|
return None
|
|
|
|
import BaseHTTPServer
|
|
|
|
if BaseHTTPServer.BaseHTTPRequestHandler.responses.has_key(int(code)):
|
|
|
|
response.msg = BaseHTTPServer.BaseHTTPRequestHandler.responses[int(code)][0]
|
2012-02-20 23:42:43 +00:00
|
|
|
self.master.refresh_flow(self.flow)
|
2012-02-07 03:39:37 +00:00
|
|
|
|
|
|
|
def set_resp_msg(self, msg):
|
|
|
|
response = self.flow.response
|
|
|
|
response.msg = msg
|
2012-02-20 23:42:43 +00:00
|
|
|
self.master.refresh_flow(self.flow)
|
2012-02-07 03:39:37 +00:00
|
|
|
|
2012-02-08 03:43:11 +00:00
|
|
|
def set_headers(self, lst, conn):
|
2012-04-04 07:46:39 +00:00
|
|
|
conn.headers = flow.ODictCaseless(lst)
|
2012-02-08 03:43:11 +00:00
|
|
|
|
2012-02-09 03:47:32 +00:00
|
|
|
def set_query(self, lst, conn):
|
2014-09-05 13:16:20 +00:00
|
|
|
conn.set_query(flow.ODict(lst))
|
2012-02-09 03:47:32 +00:00
|
|
|
|
2012-08-19 01:15:54 +00:00
|
|
|
def set_path_components(self, lst, conn):
|
2014-09-05 13:16:20 +00:00
|
|
|
conn.set_path_components([i[0] for i in lst])
|
2012-08-19 01:15:54 +00:00
|
|
|
|
2012-02-10 01:35:23 +00:00
|
|
|
def set_form(self, lst, conn):
|
2014-09-05 13:16:20 +00:00
|
|
|
conn.set_form_urlencoded(flow.ODict(lst))
|
2012-02-10 01:35:23 +00:00
|
|
|
|
2012-02-23 03:27:08 +00:00
|
|
|
def edit_form(self, conn):
|
2012-03-18 21:12:06 +00:00
|
|
|
self.master.view_grideditor(
|
2014-09-05 13:16:20 +00:00
|
|
|
grideditor.URLEncodedFormEditor(self.master, conn.get_form_urlencoded().lst, self.set_form, conn)
|
2012-03-18 21:12:06 +00:00
|
|
|
)
|
2012-02-23 03:27:08 +00:00
|
|
|
|
|
|
|
def edit_form_confirm(self, key, conn):
|
|
|
|
if key == "y":
|
|
|
|
self.edit_form(conn)
|
|
|
|
|
2012-02-07 03:39:37 +00:00
|
|
|
def edit(self, part):
|
|
|
|
if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
2014-12-23 22:14:55 +00:00
|
|
|
message = self.flow.request
|
2012-02-07 03:39:37 +00:00
|
|
|
else:
|
|
|
|
if not self.flow.response:
|
2014-03-10 16:01:30 +00:00
|
|
|
self.flow.response = HTTPResponse(
|
2013-06-08 23:14:34 +00:00
|
|
|
self.flow.request.httpversion,
|
2014-12-03 23:29:15 +00:00
|
|
|
200, "OK", flow.ODictCaseless(), ""
|
2013-06-08 23:14:34 +00:00
|
|
|
)
|
|
|
|
self.flow.response.reply = controller.DummyReply()
|
2014-12-23 22:14:55 +00:00
|
|
|
message = self.flow.response
|
2012-02-07 03:39:37 +00:00
|
|
|
|
|
|
|
self.flow.backup()
|
2012-02-09 03:40:31 +00:00
|
|
|
if part == "r":
|
2014-12-23 22:14:55 +00:00
|
|
|
with decoded(message):
|
|
|
|
# Fix an issue caused by some editors when editing a request/response body.
|
|
|
|
# Many editors make it hard to save a file without a terminating newline on the last
|
|
|
|
# line. When editing message bodies, this can cause problems. For now, I just
|
|
|
|
# strip the newlines off the end of the body when we return from an editor.
|
|
|
|
c = self.master.spawn_editor(message.content or "")
|
|
|
|
message.content = c.rstrip("\n")
|
2012-02-10 01:35:23 +00:00
|
|
|
elif part == "f":
|
2014-12-23 22:14:55 +00:00
|
|
|
if not message.get_form_urlencoded() and message.content:
|
2012-02-23 03:27:08 +00:00
|
|
|
self.master.prompt_onekey(
|
|
|
|
"Existing body is not a URL-encoded form. Clear and edit?",
|
|
|
|
[
|
|
|
|
("yes", "y"),
|
|
|
|
("no", "n"),
|
|
|
|
],
|
2012-02-26 21:00:44 +00:00
|
|
|
self.edit_form_confirm,
|
2014-12-23 22:14:55 +00:00
|
|
|
message
|
2012-02-23 03:27:08 +00:00
|
|
|
)
|
|
|
|
else:
|
2014-12-23 22:14:55 +00:00
|
|
|
self.edit_form(message)
|
2012-02-07 03:39:37 +00:00
|
|
|
elif part == "h":
|
2014-12-23 22:14:55 +00:00
|
|
|
self.master.view_grideditor(grideditor.HeaderEditor(self.master, message.headers.lst, self.set_headers, message))
|
2012-08-19 01:15:54 +00:00
|
|
|
elif part == "p":
|
2014-12-23 22:14:55 +00:00
|
|
|
p = message.get_path_components()
|
2012-08-19 01:15:54 +00:00
|
|
|
p = [[i] for i in p]
|
2014-12-23 22:14:55 +00:00
|
|
|
self.master.view_grideditor(grideditor.PathEditor(self.master, p, self.set_path_components, message))
|
2012-02-09 03:47:32 +00:00
|
|
|
elif part == "q":
|
2014-12-23 22:14:55 +00:00
|
|
|
self.master.view_grideditor(grideditor.QueryEditor(self.master, message.get_query().lst, self.set_query, message))
|
2012-02-07 03:39:37 +00:00
|
|
|
elif part == "u" and self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
2014-12-23 22:14:55 +00:00
|
|
|
self.master.prompt_edit("URL", message.url, self.set_url)
|
2012-02-07 03:39:37 +00:00
|
|
|
elif part == "m" and self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
2012-02-08 20:38:11 +00:00
|
|
|
self.master.prompt_onekey("Method", self.method_options, self.edit_method)
|
2012-02-07 03:39:37 +00:00
|
|
|
elif part == "c" and self.state.view_flow_mode == common.VIEW_FLOW_RESPONSE:
|
2014-12-23 22:14:55 +00:00
|
|
|
self.master.prompt_edit("Code", str(message.code), self.set_resp_code)
|
2012-02-07 03:39:37 +00:00
|
|
|
elif part == "m" and self.state.view_flow_mode == common.VIEW_FLOW_RESPONSE:
|
2014-12-23 22:14:55 +00:00
|
|
|
self.master.prompt_edit("Message", message.msg, self.set_resp_msg)
|
2012-02-20 23:42:43 +00:00
|
|
|
self.master.refresh_flow(self.flow)
|
2012-02-07 03:39:37 +00:00
|
|
|
|
2012-02-08 01:07:17 +00:00
|
|
|
def _view_nextprev_flow(self, np, flow):
|
|
|
|
try:
|
|
|
|
idx = self.state.view.index(flow)
|
|
|
|
except IndexError:
|
|
|
|
return
|
|
|
|
if np == "next":
|
|
|
|
new_flow, new_idx = self.state.get_next(idx)
|
|
|
|
else:
|
|
|
|
new_flow, new_idx = self.state.get_prev(idx)
|
2013-07-28 06:00:49 +00:00
|
|
|
if new_flow is None:
|
2012-03-27 21:21:48 +00:00
|
|
|
self.master.statusbar.message("No more flows!")
|
2012-02-08 01:07:17 +00:00
|
|
|
return
|
|
|
|
self.master.view_flow(new_flow)
|
|
|
|
|
|
|
|
def view_next_flow(self, flow):
|
|
|
|
return self._view_nextprev_flow("next", flow)
|
|
|
|
|
|
|
|
def view_prev_flow(self, flow):
|
|
|
|
return self._view_nextprev_flow("prev", flow)
|
|
|
|
|
2012-04-01 22:30:35 +00:00
|
|
|
def change_this_display_mode(self, t):
|
2014-11-10 16:35:28 +00:00
|
|
|
self.state.add_flow_setting(
|
|
|
|
self.flow,
|
|
|
|
(self.state.view_flow_mode, "prettyview"),
|
|
|
|
contentview.get_by_shortcut(t)
|
|
|
|
)
|
2012-03-19 22:11:53 +00:00
|
|
|
self.master.refresh_flow(self.flow)
|
|
|
|
|
2015-01-14 15:36:19 +00:00
|
|
|
def server_copy_response(self, k):
|
|
|
|
if k == "c":
|
|
|
|
try:
|
|
|
|
pyperclip.copy(self.flow.response_content())
|
|
|
|
except TypeError:
|
|
|
|
self.master.statusbar.message("Content is binary or can be converted to text")
|
|
|
|
elif k == "h":
|
|
|
|
try:
|
|
|
|
pyperclip.copy(self.flow.response_headers())
|
|
|
|
except TypeError:
|
|
|
|
self.master.statusbar.message("Error converting headers to text")
|
|
|
|
|
2012-05-16 06:16:44 +00:00
|
|
|
def delete_body(self, t):
|
|
|
|
if t == "m":
|
2014-03-09 20:59:53 +00:00
|
|
|
val = CONTENT_MISSING
|
2012-05-16 06:16:44 +00:00
|
|
|
else:
|
|
|
|
val = None
|
|
|
|
if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
|
|
|
self.flow.request.content = val
|
|
|
|
else:
|
|
|
|
self.flow.response.content = val
|
|
|
|
self.master.refresh_flow(self.flow)
|
|
|
|
|
2012-02-07 03:39:37 +00:00
|
|
|
def keypress(self, size, key):
|
|
|
|
if key == " ":
|
2012-02-08 01:07:17 +00:00
|
|
|
self.view_next_flow(self.flow)
|
2012-03-27 21:21:48 +00:00
|
|
|
return
|
2012-02-07 03:39:37 +00:00
|
|
|
|
|
|
|
key = common.shortcuts(key)
|
|
|
|
if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
|
|
|
conn = self.flow.request
|
|
|
|
else:
|
|
|
|
conn = self.flow.response
|
|
|
|
|
|
|
|
if key == "q":
|
2012-02-20 23:42:43 +00:00
|
|
|
self.master.view_flowlist()
|
2012-02-07 03:39:37 +00:00
|
|
|
key = None
|
|
|
|
elif key == "tab":
|
|
|
|
if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
|
|
|
self.view_response()
|
|
|
|
else:
|
|
|
|
self.view_request()
|
|
|
|
elif key in ("up", "down", "page up", "page down"):
|
|
|
|
# Why doesn't this just work??
|
2012-02-10 22:31:57 +00:00
|
|
|
self.w.keypress(size, key)
|
2012-02-07 03:39:37 +00:00
|
|
|
elif key == "a":
|
2014-12-23 19:33:42 +00:00
|
|
|
self.flow.accept_intercept(self.master)
|
2012-02-07 03:39:37 +00:00
|
|
|
self.master.view_flow(self.flow)
|
|
|
|
elif key == "A":
|
|
|
|
self.master.accept_all()
|
|
|
|
self.master.view_flow(self.flow)
|
2012-04-08 07:23:05 +00:00
|
|
|
elif key == "b":
|
|
|
|
if conn:
|
|
|
|
if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
|
|
|
self.master.path_prompt(
|
|
|
|
"Save request body: ",
|
|
|
|
self.state.last_saveload,
|
|
|
|
self.save_body
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
self.master.path_prompt(
|
|
|
|
"Save response body: ",
|
|
|
|
self.state.last_saveload,
|
|
|
|
self.save_body
|
|
|
|
)
|
2012-02-09 04:00:37 +00:00
|
|
|
elif key == "d":
|
|
|
|
if self.state.flow_count() == 1:
|
2012-02-20 23:42:43 +00:00
|
|
|
self.master.view_flowlist()
|
2012-02-09 04:00:37 +00:00
|
|
|
elif self.state.view.index(self.flow) == len(self.state.view)-1:
|
|
|
|
self.view_prev_flow(self.flow)
|
|
|
|
else:
|
|
|
|
self.view_next_flow(self.flow)
|
|
|
|
f = self.flow
|
|
|
|
f.kill(self.master)
|
|
|
|
self.state.delete_flow(f)
|
2012-02-18 11:32:20 +00:00
|
|
|
elif key == "D":
|
|
|
|
f = self.master.duplicate_flow(self.flow)
|
|
|
|
self.master.view_flow(f)
|
|
|
|
self.master.statusbar.message("Duplicated.")
|
2012-02-07 03:39:37 +00:00
|
|
|
elif key == "e":
|
|
|
|
if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
|
|
|
self.master.prompt_onekey(
|
|
|
|
"Edit request",
|
|
|
|
(
|
2012-02-09 03:47:32 +00:00
|
|
|
("query", "q"),
|
2012-08-19 01:15:54 +00:00
|
|
|
("path", "p"),
|
2012-02-09 03:47:32 +00:00
|
|
|
("url", "u"),
|
2012-02-07 03:39:37 +00:00
|
|
|
("header", "h"),
|
2012-08-19 01:15:54 +00:00
|
|
|
("form", "f"),
|
2012-02-09 03:40:31 +00:00
|
|
|
("raw body", "r"),
|
2012-02-07 03:39:37 +00:00
|
|
|
("method", "m"),
|
|
|
|
),
|
|
|
|
self.edit
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
self.master.prompt_onekey(
|
|
|
|
"Edit response",
|
|
|
|
(
|
|
|
|
("code", "c"),
|
|
|
|
("message", "m"),
|
|
|
|
("header", "h"),
|
2012-02-09 03:40:31 +00:00
|
|
|
("raw body", "r"),
|
2012-02-07 03:39:37 +00:00
|
|
|
),
|
|
|
|
self.edit
|
|
|
|
)
|
|
|
|
key = None
|
2012-04-08 07:23:05 +00:00
|
|
|
elif key == "f":
|
|
|
|
self.master.statusbar.message("Loading all body data...")
|
|
|
|
self.state.add_flow_setting(
|
|
|
|
self.flow,
|
|
|
|
(self.state.view_flow_mode, "fullcontents"),
|
|
|
|
True
|
|
|
|
)
|
|
|
|
self.master.refresh_flow(self.flow)
|
|
|
|
self.master.statusbar.message("")
|
2015-01-14 15:36:19 +00:00
|
|
|
elif key == "g":
|
|
|
|
self.master.prompt_onekey(
|
|
|
|
"Copy Response",
|
|
|
|
(
|
|
|
|
("content", "c"),
|
|
|
|
("headers", "h"),
|
|
|
|
),
|
|
|
|
self.server_copy_response,
|
|
|
|
)
|
2012-02-08 09:28:15 +00:00
|
|
|
elif key == "m":
|
2012-08-18 05:08:17 +00:00
|
|
|
p = list(contentview.view_prompts)
|
2014-11-07 16:01:58 +00:00
|
|
|
p.insert(0, ("Clear", "C"))
|
2012-02-08 09:28:15 +00:00
|
|
|
self.master.prompt_onekey(
|
2012-04-01 22:30:35 +00:00
|
|
|
"Display mode",
|
2012-04-01 23:16:20 +00:00
|
|
|
p,
|
2012-04-01 22:30:35 +00:00
|
|
|
self.change_this_display_mode
|
2012-02-08 09:28:15 +00:00
|
|
|
)
|
|
|
|
key = None
|
2012-04-01 22:30:35 +00:00
|
|
|
elif key == "p":
|
|
|
|
self.view_prev_flow(self.flow)
|
|
|
|
elif key == "r":
|
|
|
|
r = self.master.replay_request(self.flow)
|
|
|
|
if r:
|
|
|
|
self.master.statusbar.message(r)
|
|
|
|
self.master.refresh_flow(self.flow)
|
2012-02-18 01:45:22 +00:00
|
|
|
elif key == "V":
|
2012-04-03 21:47:57 +00:00
|
|
|
if not self.flow.modified():
|
|
|
|
self.master.statusbar.message("Flow not modified.")
|
|
|
|
return
|
2012-02-07 03:39:37 +00:00
|
|
|
self.state.revert(self.flow)
|
2012-02-20 23:42:43 +00:00
|
|
|
self.master.refresh_flow(self.flow)
|
2012-04-03 21:47:57 +00:00
|
|
|
self.master.statusbar.message("Reverted.")
|
2012-02-07 03:39:37 +00:00
|
|
|
elif key == "W":
|
|
|
|
self.master.path_prompt(
|
|
|
|
"Save this flow: ",
|
|
|
|
self.state.last_saveload,
|
|
|
|
self.master.save_one_flow,
|
|
|
|
self.flow
|
|
|
|
)
|
|
|
|
elif key == "v":
|
|
|
|
if conn and conn.content:
|
|
|
|
t = conn.headers["content-type"] or [None]
|
|
|
|
t = t[0]
|
2012-12-05 20:58:29 +00:00
|
|
|
if os.environ.has_key("EDITOR") or os.environ.has_key("PAGER"):
|
|
|
|
self.master.spawn_external_viewer(conn.content, t)
|
|
|
|
else:
|
|
|
|
self.master.statusbar.message("Error! Set $EDITOR or $PAGER.")
|
2012-02-07 03:39:37 +00:00
|
|
|
elif key == "|":
|
|
|
|
self.master.path_prompt(
|
|
|
|
"Send flow to script: ", self.state.last_script,
|
|
|
|
self.master.run_script_once, self.flow
|
|
|
|
)
|
2012-05-16 06:16:44 +00:00
|
|
|
elif key == "x":
|
|
|
|
self.master.prompt_onekey(
|
|
|
|
"Delete body",
|
|
|
|
(
|
|
|
|
("completely", "c"),
|
|
|
|
("mark as missing", "m"),
|
|
|
|
),
|
|
|
|
self.delete_body
|
|
|
|
)
|
|
|
|
key = None
|
2012-04-02 23:10:25 +00:00
|
|
|
elif key == "X":
|
|
|
|
self.master.view_flowdetails(self.flow)
|
2012-02-07 03:39:37 +00:00
|
|
|
elif key == "z":
|
|
|
|
if conn:
|
2012-04-03 21:47:57 +00:00
|
|
|
self.flow.backup()
|
2012-08-18 06:14:30 +00:00
|
|
|
e = conn.headers.get_first("content-encoding", "identity")
|
|
|
|
if e != "identity":
|
2013-07-29 06:14:11 +00:00
|
|
|
if not conn.decode():
|
|
|
|
self.master.statusbar.message("Could not decode - invalid data?")
|
2012-02-07 03:39:37 +00:00
|
|
|
else:
|
|
|
|
self.master.prompt_onekey(
|
|
|
|
"Select encoding: ",
|
|
|
|
(
|
|
|
|
("gzip", "z"),
|
|
|
|
("deflate", "d"),
|
|
|
|
),
|
|
|
|
self.encode_callback,
|
|
|
|
conn
|
|
|
|
)
|
2012-02-20 23:42:43 +00:00
|
|
|
self.master.refresh_flow(self.flow)
|
2013-12-24 01:28:20 +00:00
|
|
|
elif key == "/":
|
2013-12-25 03:50:29 +00:00
|
|
|
last_search_string = self.state.get_flow_setting(self.flow, "last_search_string")
|
2013-12-26 04:16:26 +00:00
|
|
|
search_prompt = "Search body ["+last_search_string+"]: " if last_search_string else "Search body: "
|
2013-12-25 03:50:29 +00:00
|
|
|
self.master.prompt(search_prompt,
|
|
|
|
None,
|
2013-12-24 01:28:20 +00:00
|
|
|
self.search)
|
2013-12-26 04:16:26 +00:00
|
|
|
elif key == "n":
|
2014-02-22 02:00:10 +00:00
|
|
|
self.search_again(backwards=False)
|
|
|
|
elif key == "N":
|
|
|
|
self.search_again(backwards=True)
|
2012-02-08 09:28:15 +00:00
|
|
|
else:
|
|
|
|
return key
|
2012-02-07 03:39:37 +00:00
|
|
|
|
|
|
|
def encode_callback(self, key, conn):
|
|
|
|
encoding_map = {
|
|
|
|
"z": "gzip",
|
|
|
|
"d": "deflate",
|
|
|
|
}
|
|
|
|
conn.encode(encoding_map[key])
|
2012-02-20 23:42:43 +00:00
|
|
|
self.master.refresh_flow(self.flow)
|