diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-08-25 13:13:16 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-08-25 13:13:16 +1200 |
commit | 514e19b17215ae6d5a785cfd22370eea5a132c38 (patch) | |
tree | 13972c43b8122d6ce88a21793ff0ff73d527089e /libmproxy/console | |
parent | c6d1fe9e593ba1e4801a1a8126e833aae69fec5e (diff) | |
download | mitmproxy-514e19b17215ae6d5a785cfd22370eea5a132c38.tar.gz mitmproxy-514e19b17215ae6d5a785cfd22370eea5a132c38.tar.bz2 mitmproxy-514e19b17215ae6d5a785cfd22370eea5a132c38.zip |
Do away with explicit encodings, and display an error message for invalid values.
Diffstat (limited to 'libmproxy/console')
-rw-r--r-- | libmproxy/console/grideditor.py | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/libmproxy/console/grideditor.py b/libmproxy/console/grideditor.py index f34e6122..d1df2f2e 100644 --- a/libmproxy/console/grideditor.py +++ b/libmproxy/console/grideditor.py @@ -149,10 +149,12 @@ class GridWalker(urwid.ListWalker): self.editor.master.statusbar.message("Invalid Python-style string encoding.", 1000) return errors = self.lst[self.focus][1] - if self.editor.is_error(self.focus_col, val): - errors.add(self.focus_col) - elif self.editor.encode(val) is None: + + emsg = self.editor.is_error(self.focus_col, val) + if emsg: + self.editor.master.statusbar.message(emsg, 1000) errors.add(self.focus_col) + row = list(self.lst[self.focus][0]) row[self.focus_col] = val self.lst[self.focus] = [tuple(row), errors] @@ -239,7 +241,6 @@ class GridEditor(common.WWrap): title = None columns = None headings = None - encoding = None def __init__(self, master, value, callback, *cb_args, **cb_kwargs): value = copy.deepcopy(value) self.master, self.value, self.callback = master, value, callback @@ -324,10 +325,7 @@ class GridEditor(common.WWrap): res = [] for i in self.walker.lst: if not i[1] and any([x.strip() for x in i[0]]): - v = i[0] - if self.encoding: - v = [self.encode(x) for x in v] - res.append(v) + res.append(i[0]) self.callback(res, *self.cb_args, **self.cb_kwargs) self.master.pop_view() elif key in ["h", "left"]: @@ -357,6 +355,9 @@ class GridEditor(common.WWrap): return self.w.keypress(size, key) def is_error(self, col, val): + """ + Return False, or a string error message. + """ return False @@ -364,21 +365,18 @@ class QueryEditor(GridEditor): title = "Editing query" columns = 2 headings = ("Key", "Value") - encoding = "ascii" class HeaderEditor(GridEditor): title = "Editing headers" columns = 2 headings = ("Key", "Value") - encoding = "ascii" class URLEncodedFormEditor(GridEditor): title = "Editing URL-encoded form" columns = 2 headings = ("Key", "Value") - encoding = "ascii" class ReplaceEditor(GridEditor): @@ -388,12 +386,12 @@ class ReplaceEditor(GridEditor): def is_error(self, col, val): if col == 0: if not filt.parse(val): - return True + return "Invalid filter specification." elif col == 1: try: re.compile(val) except re.error: - return True + return "Invalid regular expression." return False @@ -404,7 +402,7 @@ class SetHeadersEditor(GridEditor): def is_error(self, col, val): if col == 0: if not filt.parse(val): - return True + return "Invalid filter specification" return False @@ -412,5 +410,4 @@ class PathEditor(GridEditor): title = "Editing URL path components" columns = 1 headings = ("Component",) - encoding = "ascii" |