mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
Specialize GridEditor into a number of subclasses.
This commit is contained in:
parent
5690e7c399
commit
65e88f49d4
@ -122,7 +122,7 @@ class StatusBar(common.WWrap):
|
||||
if self.master.replacehooks.count():
|
||||
r.append("[")
|
||||
r.append(("heading_key", "R"))
|
||||
r.append("eplace]")
|
||||
r.append("eplacing]")
|
||||
if self.master.client_playback:
|
||||
r.append("[")
|
||||
r.append(("heading_key", "cplayback"))
|
||||
@ -547,8 +547,8 @@ class ConsoleMaster(flow.FlowMaster):
|
||||
self.header = None
|
||||
self.make_view()
|
||||
|
||||
def view_grideditor(self, title, columns, value, callback, *args, **kwargs):
|
||||
self.body = grideditor.GridEditor(self, title, columns, value, callback, *args, **kwargs)
|
||||
def view_grideditor(self, ge):
|
||||
self.body = ge
|
||||
self.header = None
|
||||
self.help_context = grideditor.help_context
|
||||
self.statusbar = StatusBar(self, self.footer_text_help)
|
||||
@ -710,7 +710,9 @@ class ConsoleMaster(flow.FlowMaster):
|
||||
self.view_flowlist()
|
||||
|
||||
def set_replace(self, r):
|
||||
pass
|
||||
self.replacehooks.clear()
|
||||
for i in r:
|
||||
self.replacehooks.add(*i)
|
||||
|
||||
def loop(self):
|
||||
changed = True
|
||||
@ -791,10 +793,11 @@ class ConsoleMaster(flow.FlowMaster):
|
||||
self.sync_list_view()
|
||||
elif k == "R":
|
||||
self.view_grideditor(
|
||||
"Editing replacements",
|
||||
3,
|
||||
self.replacehooks.get_specs(),
|
||||
self.set_replace
|
||||
grideditor.ReplaceEditor(
|
||||
self,
|
||||
self.replacehooks.get_specs(),
|
||||
self.set_replace
|
||||
)
|
||||
)
|
||||
elif k == "s":
|
||||
if self.script:
|
||||
@ -934,3 +937,6 @@ class ConsoleMaster(flow.FlowMaster):
|
||||
self.process_flow(f, r)
|
||||
return f
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
import os, re
|
||||
import urwid
|
||||
import common
|
||||
import common, grideditor
|
||||
from .. import utils, encoding, flow
|
||||
|
||||
def _mkhelp():
|
||||
@ -395,7 +395,9 @@ class ConnectionView(common.WWrap):
|
||||
conn.set_form_urlencoded(flow.ODict(lst))
|
||||
|
||||
def edit_form(self, conn):
|
||||
self.master.view_grideditor("Editing form", 2, conn.get_form_urlencoded().lst, self.set_form, conn)
|
||||
self.master.view_grideditor(
|
||||
grideditor.URLEncodedFormEditor(self.master, conn.get_form_urlencoded().lst, self.set_form, conn)
|
||||
)
|
||||
|
||||
def edit_form_confirm(self, key, conn):
|
||||
if key == "y":
|
||||
@ -427,9 +429,9 @@ class ConnectionView(common.WWrap):
|
||||
else:
|
||||
self.edit_form(conn)
|
||||
elif part == "h":
|
||||
self.master.view_grideditor("Editing headers", 2, conn.headers.lst, self.set_headers, conn)
|
||||
self.master.view_grideditor(grideditor.HeaderEditor(self.master, conn.headers.lst, self.set_headers, conn))
|
||||
elif part == "q":
|
||||
self.master.view_grideditor("Editing query", 2, conn.get_query().lst, self.set_query, conn)
|
||||
self.master.view_grideditor(grideditor.QueryEditor(self.master, conn.get_query().lst, self.set_query, conn))
|
||||
elif part == "u" and self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
||||
self.master.prompt_edit("URL", conn.get_url(), self.set_url)
|
||||
elif part == "m" and self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
||||
|
@ -81,7 +81,7 @@ class GridItem(common.WWrap):
|
||||
)
|
||||
|
||||
fspecs = self.fields[:]
|
||||
fspecs[0] = ("fixed", maxk + 2, fspecs[0])
|
||||
fspecs[0] = ("fixed", maxk + 2, fspecs[0])
|
||||
|
||||
w = urwid.Columns(
|
||||
fspecs,
|
||||
@ -205,12 +205,11 @@ class GridListBox(urwid.ListBox):
|
||||
|
||||
|
||||
class GridEditor(common.WWrap):
|
||||
def __init__(self, master, title, columns, value, callback, *cb_args, **cb_kwargs):
|
||||
def __init__(self, master, value, callback, *cb_args, **cb_kwargs):
|
||||
value = copy.deepcopy(value)
|
||||
self.master, self.title, self.value, self.callback = master, title, value, callback
|
||||
self.columns = columns
|
||||
self.master, self.value, self.callback = master, value, callback
|
||||
self.cb_args, self.cb_kwargs = cb_args, cb_kwargs
|
||||
p = urwid.Text(title)
|
||||
p = urwid.Text(self.title)
|
||||
p = urwid.Padding(p, align="left", width=("relative", 100))
|
||||
p = urwid.AttrWrap(p, "heading")
|
||||
self.walker = GridWalker(self.value, self)
|
||||
@ -273,3 +272,24 @@ class GridEditor(common.WWrap):
|
||||
self.walker.start_edit()
|
||||
else:
|
||||
return self.w.keypress(size, key)
|
||||
|
||||
|
||||
class QueryEditor(GridEditor):
|
||||
title = "Editing query"
|
||||
columns = 2
|
||||
|
||||
|
||||
class HeaderEditor(GridEditor):
|
||||
title = "Editing headers"
|
||||
columns = 2
|
||||
|
||||
|
||||
class URLEncodedFormEditor(GridEditor):
|
||||
title = "Editing URL-encoded form"
|
||||
columns = 2
|
||||
|
||||
|
||||
class ReplaceEditor(GridEditor):
|
||||
title = "Editing replacement patterns"
|
||||
columns = 3
|
||||
|
||||
|
@ -130,6 +130,7 @@ def urlencode(s):
|
||||
"""
|
||||
Takes a list of (key, value) tuples and returns a urlencoded string.
|
||||
"""
|
||||
s = [tuple(i) for i in s]
|
||||
return urllib.urlencode(s, False)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user