diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2015-04-17 12:54:29 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2015-04-17 12:54:29 +1200 |
commit | e963a9da4887268b03ceecf55086674121047056 (patch) | |
tree | caee7ccf3d8c6d83ad50ac571ebb3a2c8a53f313 /libmproxy/console/grideditor.py | |
parent | 7abaf3c3626a68a23233c3dc759ade32068f0462 (diff) | |
download | mitmproxy-e963a9da4887268b03ceecf55086674121047056.tar.gz mitmproxy-e963a9da4887268b03ceecf55086674121047056.tar.bz2 mitmproxy-e963a9da4887268b03ceecf55086674121047056.zip |
console: suport unary attributes
Attributes with no value are treated as unary, e.g. "Secure" rather than
"Secure=". If you really want to have an empty attribute value you can
edit the header directly.
Behind the scenes, restructure GridEditor to know about data conversion
in and out of the editor.
Diffstat (limited to 'libmproxy/console/grideditor.py')
-rw-r--r-- | libmproxy/console/grideditor.py | 63 |
1 files changed, 58 insertions, 5 deletions
diff --git a/libmproxy/console/grideditor.py b/libmproxy/console/grideditor.py index e406fbaf..e5e64403 100644 --- a/libmproxy/console/grideditor.py +++ b/libmproxy/console/grideditor.py @@ -7,7 +7,7 @@ import urwid from . import common, signals from .. import utils, filt, script -from netlib import http_uastrings, http_cookies +from netlib import http_uastrings, http_cookies, odict FOOTER = [ @@ -231,8 +231,10 @@ class GridWalker(urwid.ListWalker): def _insert(self, pos): self.focus = pos self.lst.insert( - self.focus, [ - [c.blank() for c in self.editor.columns], set([])] + self.focus, + [ + [c.blank() for c in self.editor.columns], set([]) + ] ) self.focus_col = 0 self.start_edit() @@ -318,7 +320,7 @@ class GridEditor(urwid.WidgetWrap): columns = None def __init__(self, master, value, callback, *cb_args, **cb_kwargs): - value = copy.deepcopy(value) + value = self.data_in(copy.deepcopy(value)) self.master, self.value, self.callback = master, value, callback self.cb_args, self.cb_kwargs = cb_args, cb_kwargs @@ -410,7 +412,7 @@ class GridEditor(urwid.WidgetWrap): for i in self.walker.lst: if not i[1] and any([x for x in i[0]]): res.append(i[0]) - self.callback(res, *self.cb_args, **self.cb_kwargs) + self.callback(self.data_out(res), *self.cb_args, **self.cb_kwargs) signals.pop_view_state.send(self) elif key in ["h", "left"]: self.walker.left() @@ -427,6 +429,19 @@ class GridEditor(urwid.WidgetWrap): elif column.keypress(key, self) and not self.handle_key(key): return self._w.keypress(size, key) + def data_out(self, data): + """ + Called on raw list data, before data is returned through the + callback. + """ + return data + + def data_in(self, data): + """ + Called to prepare provided data. + """ + return data + def is_error(self, col, val): """ Return False, or a string error message. @@ -597,6 +612,12 @@ class PathEditor(GridEditor): TextColumn("Component"), ] + def data_in(self, data): + return [[i] for i in data] + + def data_out(self, data): + return [i[0] for i in data] + class ScriptEditor(GridEditor): title = "Editing scripts" @@ -623,6 +644,12 @@ class HostPatternEditor(GridEditor): except re.error as e: return "Invalid regex: %s" % str(e) + def data_in(self, data): + return [[i] for i in data] + + def data_out(self, data): + return [i[0] for i in data] + class CookieEditor(GridEditor): title = "Editing request Cookie header" @@ -639,6 +666,15 @@ class CookieAttributeEditor(GridEditor): TextColumn("Value"), ] + def data_out(self, data): + ret = [] + for i in data: + if not i[1]: + ret.append([i[0], None]) + else: + ret.append(i) + return ret + class SetCookieEditor(GridEditor): title = "Editing response SetCookie header" @@ -647,3 +683,20 @@ class SetCookieEditor(GridEditor): TextColumn("Value"), SubgridColumn("Attributes", CookieAttributeEditor), ] + + def data_in(self, data): + flattened = [] + for k, v in data.items(): + flattened.append([k, v[0], v[1].lst]) + return flattened + + def data_out(self, data): + vals = [] + for i in data: + vals.append( + [ + i[0], + [i[1], odict.ODictCaseless(i[2])] + ] + ) + return odict.ODict(vals) |